From e93dd76b0ff0dc52a0455023486d385730aed0fc Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Thu, 18 Jan 2024 20:46:11 +0100 Subject: Return to storage overlay after viewing a page --- .../inventory/storageoverlay/StorageOverlay.kt | 18 ++++++++++++++++++ .../inventory/storageoverlay/StorageOverlayScreen.kt | 1 + 2 files changed, 19 insertions(+) (limited to 'src/main/kotlin/moe/nea/firmament/features') 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 cb8a8d8..b0ebea6 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 @@ -8,10 +8,12 @@ package moe.nea.firmament.features.inventory.storageoverlay import java.util.* import kotlinx.serialization.serializer +import net.minecraft.client.gui.screen.Screen import moe.nea.firmament.events.ScreenChangeEvent import moe.nea.firmament.events.TickEvent import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.gui.config.ManagedConfig +import moe.nea.firmament.util.ScreenUtil.setScreenLater import moe.nea.firmament.util.data.ProfileSpecificDataHolder object StorageOverlay : FirmamentFeature { @@ -33,9 +35,25 @@ object StorageOverlay : FirmamentFeature { override val config: TConfig get() = TConfig + var lastStorageOverlay: Screen? = null + var shouldReturnToStorageOverlayFrom: Screen? = null + var shouldReturnToStorageOverlay: Screen? = null var currentHandler: StorageBackingHandle? = StorageBackingHandle.None override fun onLoad() { + ScreenChangeEvent.subscribe { + if (lastStorageOverlay != null && it.new != null) { + shouldReturnToStorageOverlay = lastStorageOverlay + shouldReturnToStorageOverlayFrom = it.new + lastStorageOverlay = null + } else if (it.old === shouldReturnToStorageOverlayFrom) { + if (shouldReturnToStorageOverlay != null && it.new == null) + setScreenLater(shouldReturnToStorageOverlay) + shouldReturnToStorageOverlay = null + shouldReturnToStorageOverlayFrom = null + } + } + ScreenChangeEvent.subscribe { event -> currentHandler = StorageBackingHandle.fromScreen(event.new) if (event.old is StorageOverlayScreen && !event.old.isClosing) { 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 d00a3a1..e0cd3c8 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 @@ -91,6 +91,7 @@ class StorageOverlayScreen() : Screen(Text.empty()) { val ry = mouseY - y if (rx in (0.0..pageWidth.toDouble()) && ry in (0.0..getStorePageHeight(p).toDouble())) { close() + StorageOverlay.lastStorageOverlay = this k.navigateTo() return true } -- cgit