Final improvements to quick stack controls
This commit is contained in:
parent
f16b003cdf
commit
a6361f10f2
@ -286,12 +286,7 @@ class ExopackInventoryScreen(menu: ExopackInventoryMenu) : MatteryScreen<Exopack
|
|||||||
|
|
||||||
EffectListPanel(this, frame, menu.player, x - 56f, gridHeight = 6).tick()
|
EffectListPanel(this, frame, menu.player, x - 56f, gridHeight = 6).tick()
|
||||||
|
|
||||||
val quickStack = QuickStackControlsPanel(this)
|
QuickStackControlsPanel(this, frame, x = -19f, y = 96f + 18f)
|
||||||
quickStack.dockNear = frame
|
|
||||||
quickStack.dockTop = 96f
|
|
||||||
quickStack.dock = Dock.LEFT
|
|
||||||
|
|
||||||
addPanel(quickStack)
|
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,21 @@ import java.util.function.IntConsumer
|
|||||||
class QuickStackControlsPanel<out S : Screen>(
|
class QuickStackControlsPanel<out S : Screen>(
|
||||||
screen: S,
|
screen: S,
|
||||||
parent: EditablePanel<*>? = null,
|
parent: EditablePanel<*>? = null,
|
||||||
) : EditablePanel<S>(screen, parent, 0f, 0f, 18f, 18f) {
|
x: Float = 0f,
|
||||||
|
y: Float = 0f
|
||||||
|
) : EditablePanel<S>(screen, parent, x, y, 18f, 18f) {
|
||||||
private val grid = GridPanel(screen, this, columns = 1, rows = 1)
|
private val grid = GridPanel(screen, this, columns = 1, rows = 1)
|
||||||
private val buttons = ArrayList<ButtonPanel<S>>()
|
private val buttons = ArrayList<ButtonPanel<S>>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
grid.dock = Dock.FILL
|
grid.dock = Dock.FILL
|
||||||
grid.layout = GridPanel.Layout.TOP_RIGHT
|
grid.layout = GridPanel.Layout.TOP_RIGHT
|
||||||
|
grid.columnMajorOrder = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class MainButton : ButtonPanel<S>(screen, grid, width = 18f, height = 18f) {
|
private inner class MainButton : ButtonPanel<S>(screen, grid, width = 18f, height = 18f) {
|
||||||
init {
|
init {
|
||||||
dockMargin = DockProperty.left(1f)
|
dockMargin = DockProperty.bottom(1f)
|
||||||
childrenOrder = -100
|
childrenOrder = -100
|
||||||
tooltips.add(QuickMoveInput.Mode.RESTOCK_WITH_MOVE.textToStorage)
|
tooltips.add(QuickMoveInput.Mode.RESTOCK_WITH_MOVE.textToStorage)
|
||||||
tooltips.add(TextComponent(""))
|
tooltips.add(TextComponent(""))
|
||||||
@ -70,72 +73,10 @@ class QuickStackControlsPanel<out S : Screen>(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun moveToDockedParent() {
|
|
||||||
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?")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun sizeToContents() {
|
override fun sizeToContents() {
|
||||||
val oldWidth = width
|
val oldWidth = width
|
||||||
val oldHeight = height
|
|
||||||
super.sizeToContents()
|
super.sizeToContents()
|
||||||
|
x -= width - oldWidth
|
||||||
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 {
|
init {
|
||||||
@ -146,7 +87,7 @@ class QuickStackControlsPanel<out S : Screen>(
|
|||||||
onPress = IntConsumer { PacketDistributor.sendToServer(QuickStackPacket(mode, false)) })
|
onPress = IntConsumer { PacketDistributor.sendToServer(QuickStackPacket(mode, false)) })
|
||||||
|
|
||||||
button.childrenOrder = QuickMoveInput.Mode.entries.size + i
|
button.childrenOrder = QuickMoveInput.Mode.entries.size + i
|
||||||
button.dockMargin = DockProperty.left(1f)
|
button.dockMargin = DockProperty.bottomRight(1f)
|
||||||
button.visible = false
|
button.visible = false
|
||||||
button.tooltips.add(mode.textFromStorage)
|
button.tooltips.add(mode.textFromStorage)
|
||||||
buttons.add(button)
|
buttons.add(button)
|
||||||
@ -159,7 +100,7 @@ class QuickStackControlsPanel<out S : Screen>(
|
|||||||
onPress = IntConsumer { PacketDistributor.sendToServer(QuickStackPacket(mode, true)) })
|
onPress = IntConsumer { PacketDistributor.sendToServer(QuickStackPacket(mode, true)) })
|
||||||
|
|
||||||
button.childrenOrder = i
|
button.childrenOrder = i
|
||||||
button.dockMargin = DockProperty.left(1f)
|
button.dockMargin = DockProperty.bottom(1f)
|
||||||
button.visible = false
|
button.visible = false
|
||||||
button.tooltips.add(mode.textToStorage)
|
button.tooltips.add(mode.textToStorage)
|
||||||
buttons.add(button)
|
buttons.add(button)
|
||||||
|
Loading…
Reference in New Issue
Block a user