From c1fbdfa1a64aad2dca124663be97b45b22f477b8 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 9 Jan 2024 14:37:55 +0700 Subject: [PATCH] Get rid of slot provider interface --- .../mc/otm/client/screen/MatteryScreen.kt | 6 +-- .../otm/client/screen/panels/EditablePanel.kt | 48 +------------------ .../screen/panels/slot/FoldableSlotPanel.kt | 8 +--- .../client/screen/panels/slot/SlotPanel.kt | 7 ++- .../compat/jei/Panel2ClickableIngredient.kt | 2 +- 5 files changed, 11 insertions(+), 60 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/MatteryScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/MatteryScreen.kt index d202792dd..5de69287f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/MatteryScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/MatteryScreen.kt @@ -623,10 +623,10 @@ abstract class MatteryScreen(menu: T, inventory: Inventory, tit val yFloat = y.toFloat() for (panel in panels) { - val (status, slot) = panel.findSlot(xFloat, yFloat) + val (findPanel, interrupt) = panel.panelOfTypeUnderCursor>(xFloat, yFloat) - if (status) { - return slot + if (interrupt) { + return findPanel?.slot } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt index 0ae78b18e..8d951de0e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt @@ -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) } -interface ISlotPanel { - val slot: S -} - data class Rect2f(val x: Float, val y: Float, val width: Float, val height: Float) { fun toIntRect(): Rect2i { return Rect2i(x.roundToInt(), y.roundToInt(), width.roundToInt(), height.roundToInt()) @@ -972,46 +968,6 @@ open class EditablePanel @JvmOverloads constructor( } } - fun findSlot(mouseX: Float, mouseY: Float): Pair { - 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(val panel: T?, val interrupt: Boolean) { constructor(panel: T) : this(panel, true) @@ -1029,8 +985,8 @@ open class EditablePanel @JvmOverloads constructor( } } - inline fun panelOfTypeUnderCursor(mouseX: Float, mouseY: Float, ignoreMouseInputLock: Boolean = false): T? { - return panelOfTypeUnderCursor(mouseX, mouseY, ignoreMouseInputLock) { it is T }.panel + inline fun panelOfTypeUnderCursor(mouseX: Float, mouseY: Float, ignoreMouseInputLock: Boolean = false): PanelOfTypeResult { + return panelOfTypeUnderCursor(mouseX, mouseY, ignoreMouseInputLock) { it is T } } fun panelOfTypeUnderCursor(mouseX: Float, mouseY: Float, ignoreMouseInputLock: Boolean, tester: Predicate>): PanelOfTypeResult { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/slot/FoldableSlotPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/slot/FoldableSlotPanel.kt index a74d550bb..fc326f9e0 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/slot/FoldableSlotPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/slot/FoldableSlotPanel.kt @@ -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.Dock import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel -import ru.dbotthepony.mc.otm.client.screen.panels.ISlotPanel -open class FoldableSlotPanel, out T : Slot> @JvmOverloads constructor( +open class FoldableSlotPanel, out T : Slot>( screen: S, parent: EditablePanel<*>?, val mainSlot: SlotPanel, @@ -17,7 +16,7 @@ open class FoldableSlotPanel, out T : Slot> @JvmOverloa y: Float = 0f, width: Float = AbstractSlotPanel.SIZE, height: Float = AbstractSlotPanel.SIZE, -) : EditablePanel(screen, parent, x, y, width, height), ISlotPanel { +) : EditablePanel(screen, parent, x, y, width, height) { init { mainSlot.parent = this mainSlot.dock = Dock.FILL @@ -72,9 +71,6 @@ open class FoldableSlotPanel, out T : Slot> @JvmOverloa } } - override val slot: T - get() = mainSlot.slot - var hoveringSince: SystemTime? = null protected set var hoverPanel: HoverPanel? = null diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/slot/SlotPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/slot/SlotPanel.kt index 41da7dc50..f081dde43 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/slot/SlotPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/slot/SlotPanel.kt @@ -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.screen.MatteryScreen import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel -import ru.dbotthepony.mc.otm.client.screen.panels.ISlotPanel import javax.annotation.Nonnull import kotlin.math.roundToInt -open class SlotPanel, out T : Slot> @JvmOverloads constructor( +open class SlotPanel, out T : Slot>( screen: S, parent: EditablePanel<*>?, - final override val slot: T, + val slot: T, x: Float = 0f, y: Float = 0f, width: Float = SIZE, height: Float = SIZE, -) : AbstractSlotPanel(screen, parent, x, y, width, height), ISlotPanel { +) : AbstractSlotPanel(screen, parent, x, y, width, height) { override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean { screen.returnSlot = slot return true diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/compat/jei/Panel2ClickableIngredient.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/compat/jei/Panel2ClickableIngredient.kt index f61e9e81d..5188eabc8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/compat/jei/Panel2ClickableIngredient.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/compat/jei/Panel2ClickableIngredient.kt @@ -21,7 +21,7 @@ class Panel2ClickableIngredient

, T>(val panel: P, val ingre inline fun , T : Any> find(mouseX: Double, mouseY: Double, type: IIngredientType, source: Collection>, noinline provider: (P) -> T): Optional> { return source .stream() - .map { it.panelOfTypeUnderCursor

(mouseX.toFloat(), mouseY.toFloat(), ignoreMouseInputLock = true) } + .map { it.panelOfTypeUnderCursor

(mouseX.toFloat(), mouseY.toFloat(), ignoreMouseInputLock = true).panel } .filterNotNull() .findAny() .flatMap { a -> JEIPlugin.helpers.ingredientManager.createTypedIngredient(type, provider(a)).map { a to it } }