diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/QuickStackControlsPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/QuickStackControlsPanel.kt index aa09cac38..2381c1cc4 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/QuickStackControlsPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/QuickStackControlsPanel.kt @@ -24,7 +24,7 @@ class QuickStackControlsPanel( init { grid.dock = Dock.FILL - grid.layout = GridPanel.Layout.TOP_LEFT + grid.layout = GridPanel.Layout.TOP_RIGHT } private inner class MainButton : ButtonPanel(screen, grid, width = 18f, height = 18f) { @@ -70,31 +70,7 @@ class QuickStackControlsPanel( 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() - + private fun moveToDockedParent() { val dockNear = dockNear if (dockNear != null && parent == null && dock != Dock.NONE && dock != Dock.FILL) { @@ -127,6 +103,41 @@ class QuickStackControlsPanel( } } + 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 + } + } else { + moveToDockedParent() + } + } + + override fun onParented(parent: EditablePanel<*>) { + super.onParented(parent) + + dockNear = null + } + + var dockNear: EditablePanel<*>? = null + set(value) { + if (field != value) { + field = value + moveToDockedParent() + } + } + + override fun tickInner() { + super.tickInner() + moveToDockedParent() + } + init { for ((i, mode) in QuickMoveInput.Mode.entries.withIndex()) { val button = ButtonPanel.square18( @@ -147,7 +158,7 @@ class QuickStackControlsPanel( mode.iconToStorage, onPress = IntConsumer { PacketDistributor.sendToServer(QuickStackPacket(mode, true)) }) - button.childrenOrder = i + 1 + button.childrenOrder = i button.dockMargin = DockProperty.left(1f) button.visible = false button.tooltips.add(mode.textToStorage)