aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/kotlin/features/inventory/storageoverlay/StorageOverlay.kt1
-rw-r--r--src/main/kotlin/features/inventory/storageoverlay/StorageOverlayCustom.kt1
-rw-r--r--src/main/kotlin/features/inventory/storageoverlay/StorageOverlayScreen.kt10
-rw-r--r--src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt18
-rw-r--r--translations/en_us.json2
5 files changed, 27 insertions, 5 deletions
diff --git a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlay.kt b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlay.kt
index 89450fe..988a7c8 100644
--- a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlay.kt
+++ b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlay.kt
@@ -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 }
diff --git a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayCustom.kt b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayCustom.kt
index 81f058e..e4d4e42 100644
--- a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayCustom.kt
+++ b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayCustom.kt
@@ -18,6 +18,7 @@ class StorageOverlayCustom(
) : CustomGui() {
override fun onVoluntaryExit(): Boolean {
overview.isExiting = true
+ StorageOverlayScreen.resetScroll()
return super.onVoluntaryExit()
}
diff --git a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayScreen.kt b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayScreen.kt
index 72ee1c5..267799d 100644
--- a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayScreen.kt
+++ b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlayScreen.kt
@@ -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()
}
diff --git a/src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt b/src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt
index 9112fab..3462d3d 100644
--- a/src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt
+++ b/src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt
@@ -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
diff --git a/translations/en_us.json b/translations/en_us.json
index 5d3a2f2..e50864e 100644
--- a/translations/en_us.json
+++ b/translations/en_us.json
@@ -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",