Get rid of slot provider interface
This commit is contained in:
parent
3a813d4353
commit
c1fbdfa1a6
@ -623,10 +623,10 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
|||||||
val yFloat = y.toFloat()
|
val yFloat = y.toFloat()
|
||||||
|
|
||||||
for (panel in panels) {
|
for (panel in panels) {
|
||||||
val (status, slot) = panel.findSlot(xFloat, yFloat)
|
val (findPanel, interrupt) = panel.panelOfTypeUnderCursor<SlotPanel<*, *>>(xFloat, yFloat)
|
||||||
|
|
||||||
if (status) {
|
if (interrupt) {
|
||||||
return slot
|
return findPanel?.slot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,10 +52,6 @@ enum class DockResizeMode(val changeWidth: Boolean, val changeHeight: Boolean) {
|
|||||||
ALL(true, true), NONE(false, false), WIDTH(true, false), HEIGHT(false, true)
|
ALL(true, true), NONE(false, false), WIDTH(true, false), HEIGHT(false, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ISlotPanel<out S : Slot> {
|
|
||||||
val slot: S
|
|
||||||
}
|
|
||||||
|
|
||||||
data class Rect2f(val x: Float, val y: Float, val width: Float, val height: Float) {
|
data class Rect2f(val x: Float, val y: Float, val width: Float, val height: Float) {
|
||||||
fun toIntRect(): Rect2i {
|
fun toIntRect(): Rect2i {
|
||||||
return Rect2i(x.roundToInt(), y.roundToInt(), width.roundToInt(), height.roundToInt())
|
return Rect2i(x.roundToInt(), y.roundToInt(), width.roundToInt(), height.roundToInt())
|
||||||
@ -972,46 +968,6 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findSlot(mouseX: Float, mouseY: Float): Pair<Boolean, Slot?> {
|
|
||||||
if (!isVisible()) {
|
|
||||||
return false to null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!acceptMouseInput) {
|
|
||||||
return (mouseX >= absoluteX &&
|
|
||||||
mouseX <= absoluteX + width &&
|
|
||||||
mouseY >= absoluteY &&
|
|
||||||
mouseY <= absoluteY + height) to null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (grabMouseInput && this is ISlotPanel<*>) {
|
|
||||||
return true to this.slot
|
|
||||||
}
|
|
||||||
|
|
||||||
for (child in visibleChildrenInternal) {
|
|
||||||
val (status, slot) = child.findSlot(mouseX, mouseY)
|
|
||||||
|
|
||||||
if (status) {
|
|
||||||
return true to slot
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
mouseX >= absoluteX &&
|
|
||||||
mouseX <= absoluteX + width &&
|
|
||||||
mouseY >= absoluteY &&
|
|
||||||
mouseY <= absoluteY + height
|
|
||||||
) {
|
|
||||||
if (this is ISlotPanel<*>) {
|
|
||||||
return true to this.slot
|
|
||||||
}
|
|
||||||
|
|
||||||
return true to null
|
|
||||||
}
|
|
||||||
|
|
||||||
return false to null
|
|
||||||
}
|
|
||||||
|
|
||||||
data class PanelOfTypeResult<T>(val panel: T?, val interrupt: Boolean) {
|
data class PanelOfTypeResult<T>(val panel: T?, val interrupt: Boolean) {
|
||||||
constructor(panel: T) : this(panel, true)
|
constructor(panel: T) : this(panel, true)
|
||||||
|
|
||||||
@ -1029,8 +985,8 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified T> panelOfTypeUnderCursor(mouseX: Float, mouseY: Float, ignoreMouseInputLock: Boolean = false): T? {
|
inline fun <reified T> panelOfTypeUnderCursor(mouseX: Float, mouseY: Float, ignoreMouseInputLock: Boolean = false): PanelOfTypeResult<T> {
|
||||||
return panelOfTypeUnderCursor<T>(mouseX, mouseY, ignoreMouseInputLock) { it is T }.panel
|
return panelOfTypeUnderCursor<T>(mouseX, mouseY, ignoreMouseInputLock) { it is T }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> panelOfTypeUnderCursor(mouseX: Float, mouseY: Float, ignoreMouseInputLock: Boolean, tester: Predicate<EditablePanel<*>>): PanelOfTypeResult<T> {
|
fun <T> panelOfTypeUnderCursor(mouseX: Float, mouseY: Float, ignoreMouseInputLock: Boolean, tester: Predicate<EditablePanel<*>>): PanelOfTypeResult<T> {
|
||||||
|
@ -6,9 +6,8 @@ import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
|||||||
import ru.dbotthepony.mc.otm.client.screen.panels.util.BackgroundPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.util.BackgroundPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.Dock
|
import ru.dbotthepony.mc.otm.client.screen.panels.Dock
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.ISlotPanel
|
|
||||||
|
|
||||||
open class FoldableSlotPanel<out S : MatteryScreen<*>, out T : Slot> @JvmOverloads constructor(
|
open class FoldableSlotPanel<out S : MatteryScreen<*>, out T : Slot>(
|
||||||
screen: S,
|
screen: S,
|
||||||
parent: EditablePanel<*>?,
|
parent: EditablePanel<*>?,
|
||||||
val mainSlot: SlotPanel<S, T>,
|
val mainSlot: SlotPanel<S, T>,
|
||||||
@ -17,7 +16,7 @@ open class FoldableSlotPanel<out S : MatteryScreen<*>, out T : Slot> @JvmOverloa
|
|||||||
y: Float = 0f,
|
y: Float = 0f,
|
||||||
width: Float = AbstractSlotPanel.SIZE,
|
width: Float = AbstractSlotPanel.SIZE,
|
||||||
height: Float = AbstractSlotPanel.SIZE,
|
height: Float = AbstractSlotPanel.SIZE,
|
||||||
) : EditablePanel<S>(screen, parent, x, y, width, height), ISlotPanel<T> {
|
) : EditablePanel<S>(screen, parent, x, y, width, height) {
|
||||||
init {
|
init {
|
||||||
mainSlot.parent = this
|
mainSlot.parent = this
|
||||||
mainSlot.dock = Dock.FILL
|
mainSlot.dock = Dock.FILL
|
||||||
@ -72,9 +71,6 @@ open class FoldableSlotPanel<out S : MatteryScreen<*>, out T : Slot> @JvmOverloa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val slot: T
|
|
||||||
get() = mainSlot.slot
|
|
||||||
|
|
||||||
var hoveringSince: SystemTime? = null
|
var hoveringSince: SystemTime? = null
|
||||||
protected set
|
protected set
|
||||||
var hoverPanel: HoverPanel? = null
|
var hoverPanel: HoverPanel? = null
|
||||||
|
@ -13,19 +13,18 @@ import ru.dbotthepony.mc.otm.client.minecraft
|
|||||||
import ru.dbotthepony.mc.otm.client.render.Widgets18
|
import ru.dbotthepony.mc.otm.client.render.Widgets18
|
||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.ISlotPanel
|
|
||||||
import javax.annotation.Nonnull
|
import javax.annotation.Nonnull
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
open class SlotPanel<out S : MatteryScreen<*>, out T : Slot> @JvmOverloads constructor(
|
open class SlotPanel<out S : MatteryScreen<*>, out T : Slot>(
|
||||||
screen: S,
|
screen: S,
|
||||||
parent: EditablePanel<*>?,
|
parent: EditablePanel<*>?,
|
||||||
final override val slot: T,
|
val slot: T,
|
||||||
x: Float = 0f,
|
x: Float = 0f,
|
||||||
y: Float = 0f,
|
y: Float = 0f,
|
||||||
width: Float = SIZE,
|
width: Float = SIZE,
|
||||||
height: Float = SIZE,
|
height: Float = SIZE,
|
||||||
) : AbstractSlotPanel<S>(screen, parent, x, y, width, height), ISlotPanel<T> {
|
) : AbstractSlotPanel<S>(screen, parent, x, y, width, height) {
|
||||||
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
||||||
screen.returnSlot = slot
|
screen.returnSlot = slot
|
||||||
return true
|
return true
|
||||||
|
@ -21,7 +21,7 @@ class Panel2ClickableIngredient<P : EditablePanel<*>, T>(val panel: P, val ingre
|
|||||||
inline fun <reified P : EditablePanel<*>, T : Any> find(mouseX: Double, mouseY: Double, type: IIngredientType<T>, source: Collection<EditablePanel<*>>, noinline provider: (P) -> T): Optional<IClickableIngredient<*>> {
|
inline fun <reified P : EditablePanel<*>, T : Any> find(mouseX: Double, mouseY: Double, type: IIngredientType<T>, source: Collection<EditablePanel<*>>, noinline provider: (P) -> T): Optional<IClickableIngredient<*>> {
|
||||||
return source
|
return source
|
||||||
.stream()
|
.stream()
|
||||||
.map { it.panelOfTypeUnderCursor<P>(mouseX.toFloat(), mouseY.toFloat(), ignoreMouseInputLock = true) }
|
.map { it.panelOfTypeUnderCursor<P>(mouseX.toFloat(), mouseY.toFloat(), ignoreMouseInputLock = true).panel }
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
.findAny()
|
.findAny()
|
||||||
.flatMap { a -> JEIPlugin.helpers.ingredientManager.createTypedIngredient(type, provider(a)).map { a to it } }
|
.flatMap { a -> JEIPlugin.helpers.ingredientManager.createTypedIngredient(type, provider(a)).map { a to it } }
|
||||||
|
Loading…
Reference in New Issue
Block a user