From d375262cb82d603e8f2be84ef3755829b62955ca Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Sun, 12 May 2024 00:53:45 +0200 Subject: Improvement: sh gui 20s (#1768) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../java/at/hannibal2/skyhanni/data/GuiEditManager.kt | 15 ++++++--------- .../java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt | 4 ++-- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt b/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt index 7519662a7..765a51e95 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt @@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.isRancherSign import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.ReflectionUtils.getPropertiesWithType import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.TimeLimitedCache import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer import net.minecraft.client.Minecraft @@ -26,6 +27,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.UUID import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.minutes +import kotlin.time.Duration.Companion.seconds class GuiEditManager { @@ -50,8 +52,6 @@ class GuiEditManager { @SubscribeEvent(priority = EventPriority.LOWEST) fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { - latestPositions = currentPositions.toMap() - currentPositions.clear() GlStateManager.color(1f, 1f, 1f, 1f) GlStateManager.enableBlend() GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) @@ -67,8 +67,7 @@ class GuiEditManager { companion object { - var currentPositions = mutableMapOf() - private var latestPositions = mapOf() + private var currentPositions = TimeLimitedCache(15.seconds) private var currentBorderSize = mutableMapOf>() private var lastMovedGui: String? = null @@ -79,10 +78,8 @@ class GuiEditManager { name = if (posLabel == "none") "none " + UUID.randomUUID() else posLabel position.internalName = name } - if (!currentPositions.containsKey(name)) { - currentPositions[name] = position - currentBorderSize[posLabel] = Pair(x, y) - } + currentPositions.put(name, position) + currentBorderSize[posLabel] = Pair(x, y) } private var lastHotkeyReminded = SimpleTimeMark.farPast() @@ -90,7 +87,7 @@ class GuiEditManager { @JvmStatic fun openGuiPositionEditor(hotkeyReminder: Boolean) { SkyHanniMod.screenToOpen = GuiPositionEditor( - latestPositions.values.toList(), + currentPositions.values().toList(), 2, Minecraft.getMinecraft().currentScreen as? GuiContainer ) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt index 9f29b9ff1..d903ada07 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt @@ -15,9 +15,9 @@ class TimeLimitedCache(expireAfterWrite: Duration) { fun clear() = cache.invalidateAll() - fun values(): MutableCollection = cache.asMap().values + fun values(): Collection = cache.asMap().values - fun keys(): MutableSet = cache.asMap().keys + fun keys(): Set = cache.asMap().keys fun containsKey(key: K): Boolean = cache.getIfPresent(key) != null } -- cgit