Fixes for quick stack controls

This commit is contained in:
DBotThePony 2025-03-21 15:19:07 +07:00
parent 2547478914
commit 07e0c73479
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -24,7 +24,7 @@ class QuickStackControlsPanel<out S : Screen>(
init {
grid.dock = Dock.FILL
grid.layout = GridPanel.Layout.TOP_LEFT
grid.layout = GridPanel.Layout.TOP_RIGHT
}
private inner class MainButton : ButtonPanel<S>(screen, grid, width = 18f, height = 18f) {
@ -70,31 +70,7 @@ class QuickStackControlsPanel<out S : Screen>(
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<out S : Screen>(
}
}
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<out S : Screen>(
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)