From e96bef23200e4767269271388a5c88f6d4e6457e Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Mon, 15 Jul 2024 16:04:10 +0200 Subject: Add always open storage overlay option --- .../features/inventory/storageoverlay/StorageOverlay.kt | 6 +++--- .../inventory/storageoverlay/StorageOverlayScreen.kt | 15 ++------------- .../inventory/storageoverlay/StorageOverviewScreen.kt | 4 ++-- src/main/resources/assets/firmament/lang/en_us.json | 3 ++- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverlay.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverlay.kt index 777cbe9..c1ac993 100644 --- a/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverlay.kt +++ b/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverlay.kt @@ -14,7 +14,6 @@ import net.minecraft.client.gui.screen.ingame.HandledScreen import net.minecraft.entity.player.PlayerInventory import net.minecraft.item.Items import net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket -import net.minecraft.text.Text import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.ScreenChangeEvent import moe.nea.firmament.events.SlotClickEvent @@ -34,7 +33,8 @@ object StorageOverlay : FirmamentFeature { get() = "storage-overlay" object TConfig : ManagedConfig(identifier) { - val rows by integer("rows", 1, 5) { 3 } + val alwaysReplace by toggle("always-replace") { true } + val columns by integer("rows", 1, 10) { 3 } val scrollSpeed by integer("scroll-speed", 1, 50) { 10 } val inverseScroll by toggle("inverse-scroll") { false } val padding by integer("padding", 1, 20) { 5 } @@ -105,7 +105,7 @@ object StorageOverlay : FirmamentFeature { screen.customGui = StorageOverlayCustom( currentHandler ?: return, screen, - storageOverlayScreen ?: return) + storageOverlayScreen ?: (if (TConfig.alwaysReplace) StorageOverlayScreen() else return)) } fun rememberContent(handler: StorageBackingHandle?) { diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverlayScreen.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverlayScreen.kt index ac89f8c..c371eb4 100644 --- a/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverlayScreen.kt +++ b/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverlayScreen.kt @@ -33,22 +33,11 @@ class StorageOverlayScreen : Screen(Text.literal("")) { val MAIN_INVENTORY_Y = 9 val SCROLL_BAR_WIDTH = 8 val SCROLL_BAR_HEIGHT = 16 - - @Subscribe - fun onCommand(event: CommandEvent.SubCommand) { - event.subcommand("teststorage") { - executes { - ScreenUtil.setScreenLater(StorageOverlayScreen()) - MC.sendCommand("ec") - 0 - } - } - } } var isExiting: Boolean = false var scroll: Float = 0F - var pageWidthCount = StorageOverlay.TConfig.rows + var pageWidthCount = StorageOverlay.TConfig.columns inner class Measurements { val innerScrollPanelWidth = PAGE_WIDTH * pageWidthCount + (pageWidthCount - 1) * PADDING @@ -66,7 +55,7 @@ class StorageOverlayScreen : Screen(Text.literal("")) { var lastRenderedInnerHeight = 0 override fun init() { super.init() - pageWidthCount = StorageOverlay.TConfig.rows + pageWidthCount = StorageOverlay.TConfig.columns .coerceAtMost((width - PADDING) / (PAGE_WIDTH + PADDING)) .coerceAtLeast(1) measurements = Measurements() diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverviewScreen.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverviewScreen.kt index dc2bd48..fb77ff2 100644 --- a/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverviewScreen.kt +++ b/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverviewScreen.kt @@ -51,7 +51,7 @@ class StorageOverviewScreen() : Screen(Text.empty()) { var currentMaxHeight = StorageOverlay.config.margin - StorageOverlay.config.padding - scroll var totalHeight = -currentMaxHeight content.storageInventories.onEachIndexed { index, (key, value) -> - val pageX = (index % StorageOverlay.config.rows) + val pageX = (index % StorageOverlay.config.columns) if (pageX == 0) { currentMaxHeight += StorageOverlay.config.padding offsetY += currentMaxHeight @@ -59,7 +59,7 @@ class StorageOverviewScreen() : Screen(Text.empty()) { currentMaxHeight = 0 } val xPosition = - width / 2 - (StorageOverlay.config.rows * (pageWidth + StorageOverlay.config.padding) - StorageOverlay.config.padding) / 2 + pageX * (pageWidth + StorageOverlay.config.padding) + width / 2 - (StorageOverlay.config.columns * (pageWidth + StorageOverlay.config.padding) - StorageOverlay.config.padding) / 2 + pageX * (pageWidth + StorageOverlay.config.padding) onEach(Pair(key, value), xPosition, offsetY) val height = getStorePageHeight(value) currentMaxHeight = max(currentMaxHeight, height) diff --git a/src/main/resources/assets/firmament/lang/en_us.json b/src/main/resources/assets/firmament/lang/en_us.json index a635517..adba8e7 100644 --- a/src/main/resources/assets/firmament/lang/en_us.json +++ b/src/main/resources/assets/firmament/lang/en_us.json @@ -126,7 +126,8 @@ "firmament.config.save-cursor-position.tolerance": "Tolerance", "firmament.config.save-cursor-position": "Save Cursor Position", "firmament.config.storage-overlay": "Storage Overlay", - "firmament.config.storage-overlay.rows": "Rows", + "firmament.config.storage-overlay.rows": "Columns", + "firmament.config.storage-overlay.always-replace": "Always Open Overlay", "firmament.config.storage-overlay.padding": "Padding", "firmament.config.storage-overlay.scroll-speed": "Scroll Speed", "firmament.config.storage-overlay.inverse-scroll": "Invert Scroll", -- cgit