feat: Option to save scroll position in storage overlay

This commit is contained in:
Emily Lovegrove
2025-07-08 16:38:51 +01:00
committed by Linnea Gräf
parent a698e71714
commit 11e34b0b4b
5 changed files with 27 additions and 5 deletions

View File

@@ -41,6 +41,7 @@ object StorageOverlay : FirmamentFeature {
}
val columns by integer("rows", 1, 10) { 3 }
val height by integer("height", 80, 3000) { 3 * 18 * 6 }
val retainScroll by toggle("retain-scroll") { true }
val scrollSpeed by integer("scroll-speed", 1, 50) { 10 }
val inverseScroll by toggle("inverse-scroll") { false }
val padding by integer("padding", 1, 20) { 5 }

View File

@@ -18,6 +18,7 @@ class StorageOverlayCustom(
) : CustomGui() {
override fun onVoluntaryExit(): Boolean {
overview.isExiting = true
StorageOverlayScreen.resetScroll()
return super.onVoluntaryExit()
}

View File

@@ -60,10 +60,16 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
val CONTROL_WIDTH = 70
val CONTROL_BACKGROUND_WIDTH = CONTROL_WIDTH + CONTROL_X_INSET + 1
val CONTROL_HEIGHT = 50
var scroll: Float = 0F
var lastRenderedInnerHeight = 0
fun resetScroll() {
if (!StorageOverlay.TConfig.retainScroll) scroll = 0F
}
}
var isExiting: Boolean = false
var scroll: Float = 0F
var pageWidthCount = StorageOverlay.TConfig.columns
inner class Measurements {
@@ -86,7 +92,6 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
var measurements = Measurements()
var lastRenderedInnerHeight = 0
public override fun init() {
super.init()
pageWidthCount = StorageOverlay.TConfig.columns
@@ -123,6 +128,7 @@ class StorageOverlayScreen : Screen(Text.literal("")) {
override fun close() {
isExiting = true
resetScroll()
super.close()
}

View File

@@ -22,13 +22,23 @@ class StorageOverviewScreen() : Screen(Text.empty()) {
Items.GRAY_DYE
)
val pageWidth get() = 19 * 9
var scroll = 0
var lastRenderedHeight = 0
}
val content = StorageOverlay.Data.data ?: StorageData()
var isClosing = false
var scroll = 0
var lastRenderedHeight = 0
override fun init() {
super.init()
scroll = scroll.coerceAtMost(getMaxScroll()).coerceAtLeast(0)
}
override fun close() {
if (!StorageOverlay.TConfig.retainScroll) scroll = 0
super.close()
}
override fun render(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
super.render(context, mouseX, mouseY, delta)
@@ -88,10 +98,12 @@ class StorageOverviewScreen() : Screen(Text.empty()) {
): Boolean {
scroll =
(scroll + StorageOverlay.adjustScrollSpeed(verticalAmount)).toInt()
.coerceAtMost(lastRenderedHeight - height + 2 * StorageOverlay.config.margin).coerceAtLeast(0)
.coerceAtMost(getMaxScroll()).coerceAtLeast(0)
return true
}
private fun getMaxScroll() = lastRenderedHeight - height + 2 * StorageOverlay.config.margin
private fun renderStoragePage(context: DrawContext, page: StorageData.StorageInventory, mouseX: Int, mouseY: Int) {
context.drawText(MC.font, page.title, 2, 2, -1, true)
val inventory = page.inventory

View File

@@ -375,6 +375,8 @@
"firmament.config.storage-overlay.outline-active-page.description": "Put a border around the selected storage page in the storage overlay.",
"firmament.config.storage-overlay.padding": "Padding",
"firmament.config.storage-overlay.padding.description": "Padding inside of the storage overview.",
"firmament.config.storage-overlay.retain-scroll": "Retain Scroll Position",
"firmament.config.storage-overlay.retain-scroll.description": "Retain scroll position when closing storage overlay and overview.",
"firmament.config.storage-overlay.rows": "Columns",
"firmament.config.storage-overlay.rows.description": "Max columns used by the storage overlay and overview.",
"firmament.config.storage-overlay.scroll-speed": "Scroll Speed",