Re-opening GUIs no longer evaporate scrollbar due to already scrolled slots
Fixes #150
This commit is contained in:
parent
d3e2b1928a
commit
0cc753e035
@ -31,6 +31,7 @@ import ru.dbotthepony.mc.otm.core.integerDivisionUp
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||
import ru.dbotthepony.mc.otm.network.MenuNetworkChannel
|
||||
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
|
||||
import java.util.WeakHashMap
|
||||
import java.util.function.Consumer
|
||||
|
||||
fun onMovementInputUpdate(event: MovementInputUpdateEvent) {
|
||||
@ -115,6 +116,9 @@ private class InventoryScrollbarPanel<S : Screen>(screen: S, matteryPlayer: Matt
|
||||
}, isSlim = true
|
||||
)
|
||||
|
||||
private data class ScreenScrollbarConfig(val x: Float, val y: Float, val height: Float)
|
||||
private val foundScreenConfigurations = WeakHashMap<AbstractContainerScreen<*>, ScreenScrollbarConfig>()
|
||||
|
||||
private fun exosuitInventoryLogic(screen: Screen, addListener: (GuiEventListener) -> Unit) {
|
||||
val player = minecraft.player ?: return
|
||||
val matteryPlayer = player.matteryPlayer ?: return
|
||||
@ -127,6 +131,7 @@ private fun exosuitInventoryLogic(screen: Screen, addListener: (GuiEventListener
|
||||
return
|
||||
}
|
||||
|
||||
val existingConfig = foundScreenConfigurations[screen]
|
||||
val foundInventorySlots = Int2ObjectArrayMap<Slot>()
|
||||
|
||||
for (slot in screen.menu.slots) {
|
||||
@ -135,12 +140,22 @@ private fun exosuitInventoryLogic(screen: Screen, addListener: (GuiEventListener
|
||||
}
|
||||
}
|
||||
|
||||
var passed = true
|
||||
|
||||
for (i in 9 .. 35) {
|
||||
if (i !in foundInventorySlots) {
|
||||
if (existingConfig == null) {
|
||||
return
|
||||
} else {
|
||||
passed = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val config: ScreenScrollbarConfig
|
||||
|
||||
if (passed) {
|
||||
val mostTop = foundInventorySlots.values
|
||||
.stream()
|
||||
.min { o1, o2 -> o1.y.compareTo(o2.y) }
|
||||
@ -156,13 +171,20 @@ private fun exosuitInventoryLogic(screen: Screen, addListener: (GuiEventListener
|
||||
.max { o1, o2 -> o1.x.compareTo(o2.x) }
|
||||
.get().x.toFloat() + 26f
|
||||
|
||||
config = ScreenScrollbarConfig(mostLeft + screen.guiLeft - 9f, mostTop + screen.guiTop - 1f, mostBottom - mostTop + AbstractSlotPanel.SIZE)
|
||||
foundScreenConfigurations[screen] = config
|
||||
} else if (existingConfig != null) {
|
||||
config = existingConfig
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
val findScrollbar = (screen.renderables.firstOrNull { it is Panel2Widget<*, *> && it.panel is InventoryScrollbarPanel } as Panel2Widget<*, *>?)?.panel as InventoryScrollbarPanel?
|
||||
val scrollbar = findScrollbar ?: InventoryScrollbarPanel(screen, matteryPlayer)
|
||||
|
||||
// HOW
|
||||
scrollbar.x = mostLeft + screen.guiLeft - 9f
|
||||
scrollbar.y = mostTop + screen.guiTop - 1f
|
||||
scrollbar.height = mostBottom - mostTop + AbstractSlotPanel.SIZE
|
||||
scrollbar.x = config.x
|
||||
scrollbar.y = config.y
|
||||
scrollbar.height = config.height
|
||||
|
||||
if (findScrollbar == null) {
|
||||
val widget = Panel2Widget(scrollbar)
|
||||
|
Loading…
Reference in New Issue
Block a user