diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExopackInventoryScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExopackInventoryScreen.kt index c6816f8e6..e199b8e5b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExopackInventoryScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ExopackInventoryScreen.kt @@ -286,16 +286,12 @@ class ExopackInventoryScreen(menu: ExopackInventoryMenu) : MatteryScreen( + screen: S, + parent: EditablePanel<*>? = null, +) : EditablePanel(screen, parent, 0f, 0f, 18f, 18f) { + private val grid = GridPanel(screen, this, columns = 1, rows = 1) + private val buttons = ArrayList>() + + init { + grid.dock = Dock.FILL + grid.layout = GridPanel.Layout.TOP_LEFT + } + + private inner class MainButton : ButtonPanel(screen, grid, width = 18f, height = 18f) { + init { + dockMargin = DockProperty.left(1f) + childrenOrder = -100 + tooltips.add(QuickMoveInput.Mode.RESTOCK_WITH_MOVE.textToStorage) + tooltips.add(TextComponent("")) + tooltips.add(TranslatableComponent("otm.gui.quickmove_hint").withStyle(ChatFormatting.GRAY)) + } + + override var isDisabled: Boolean + get() = minecraft.player!!.isSpectator + set(value) {} + + override val icon: IGUIRenderable + get() = Widgets18.RESTOCK_WITH_MOVE_TO_STORAGE + + override fun test(value: Int): Boolean { + return value == InputConstants.MOUSE_BUTTON_LEFT || value == InputConstants.MOUSE_BUTTON_RIGHT + } + + override fun onClick(mouseButton: Int) { + if (mouseButton == InputConstants.MOUSE_BUTTON_LEFT) { + PacketDistributor.sendToServer(QuickStackPacket(QuickMoveInput.Mode.RESTOCK_WITH_MOVE, true)) + } else { + buttons.forEach { it.visible = !it.visible } + + if (buttons[0].visible) { + grid.columns = 2 + grid.rows = 3 + } else { + grid.columns = 1 + grid.rows = 1 + } + + this@QuickStackControlsPanel.sizeToContents() + } + } + } + + override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean { + return false + } + + override fun sizeToContents() { + val oldWidth = width + val oldHeight = height + super.sizeToContents() + + if (parent == null && dockNear == null) { + when (dock) { + Dock.LEFT -> x -= width - oldWidth + Dock.TOP -> y -= height - oldHeight + else -> {} // do nothing + } + } + } + + override fun onParented(parent: EditablePanel<*>) { + super.onParented(parent) + + dockNear = null + } + + var dockNear: EditablePanel<*>? = null + + override fun tickInner() { + super.tickInner() + + val dockNear = dockNear + + if (dockNear != null && parent == null && dock != Dock.NONE && dock != Dock.FILL) { + x = dockNear.absoluteX + y = dockNear.absoluteY + + when (dock) { + Dock.LEFT -> { + x -= width + dockMargin.right + y += dockMargin.top + } + + Dock.RIGHT -> { + x += width + dockMargin.left + y += dockMargin.top + } + + Dock.TOP -> { + y -= height + dockMargin.bottom + x += dockMargin.left + } + + Dock.BOTTOM -> { + y += height + dockMargin.top + x += dockMargin.left + } + + else -> throw RuntimeException("you w0t m8?") + } + } + } + + init { + for ((i, mode) in QuickMoveInput.Mode.entries.withIndex()) { + val button = ButtonPanel.square18( + screen, grid, + mode.iconFromStorage, + onPress = IntConsumer { PacketDistributor.sendToServer(QuickStackPacket(mode, false)) }) + + button.childrenOrder = QuickMoveInput.Mode.entries.size + i + button.dockMargin = DockProperty.left(1f) + button.visible = false + button.tooltips.add(mode.textFromStorage) + buttons.add(button) + } + + for ((i, mode) in QuickMoveInput.Mode.entries.filter { it != QuickMoveInput.Mode.RESTOCK_WITH_MOVE }.withIndex()) { + val button = ButtonPanel.square18( + screen, grid, + mode.iconToStorage, + onPress = IntConsumer { PacketDistributor.sendToServer(QuickStackPacket(mode, true)) }) + + button.childrenOrder = i + 1 + button.dockMargin = DockProperty.left(1f) + button.visible = false + button.tooltips.add(mode.textToStorage) + buttons.add(button) + } + + MainButton() + } +}