Skip to content

Commit

Permalink
Return to storage overlay after viewing a page
Browse files Browse the repository at this point in the history
  • Loading branch information
nea89o committed Jan 18, 2024
1 parent cc8e54b commit e93dd76
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit e93dd76

Please sign in to comment.