From dea252c20bef556b4747b15b2d031c5ee31571e6 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Tue, 26 Dec 2023 17:15:28 +0100 Subject: Rift time now updates correctly in wizard tower and instantly updates the format when toggling max time or percentage. --- .../config/features/rift/RiftTimerConfig.java | 5 ++- .../skyhanni/features/rift/everywhere/RiftTimer.kt | 44 ++++++++++++++-------- 2 files changed, 32 insertions(+), 17 deletions(-) (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftTimerConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftTimerConfig.java index f1c7f32dd..9a8851150 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftTimerConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftTimerConfig.java @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.config.core.config.Position; import com.google.gson.annotations.Expose; import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; import io.github.moulberry.moulconfig.annotations.ConfigOption; +import io.github.moulberry.moulconfig.observer.Property; public class RiftTimerConfig { @@ -17,12 +18,12 @@ public class RiftTimerConfig { @Expose @ConfigOption(name = "Max Time", desc = "Show max time.") @ConfigEditorBoolean - public boolean maxTime = true; + public Property maxTime = Property.of(true); @Expose @ConfigOption(name = "Percentage", desc = "Show percentage.") @ConfigEditorBoolean - public boolean percentage = true; + public Property percentage = Property.of(true); @Expose public Position timerPosition = new Position(10, 10, false, true); diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt index 7858132f4..6c62b0097 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.features.rift.everywhere +import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzActionBarEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent @@ -18,6 +19,7 @@ class RiftTimer { private var display = emptyList() private var maxTime = 0L + private var currentTime = 0L private var latestTime = 0L private val changes = mutableMapOf() @@ -26,42 +28,42 @@ class RiftTimer { display = emptyList() maxTime = 0 latestTime = 0 + currentTime = 0 } @SubscribeEvent fun onActionBar(event: LorenzActionBarEvent) { if (!isEnabled()) return - for (entry in event.message.split(" ")) { pattern.matchMatcher(entry) { val color = group("color") + val newTime = getTime(group("time")) if (color == "7") { - val currentTime = getTime(group("time")) - if (currentTime > maxTime) { - maxTime = currentTime - update(currentTime) + if (newTime > maxTime) { + maxTime = newTime } - return } - update(getTime(group("time"))) + currentTime = newTime + update() } } } private fun getTime(time: String) = TimeUtils.getMillis(time.replace("m", "m ")) - private fun update(currentTime: Long) { - if (currentTime == latestTime) return - val diff = (currentTime - latestTime) + 1000 - latestTime = currentTime - if (latestTime != maxTime) { - addDiff(diff) + private fun update() { + if (currentTime != latestTime) { + val diff = (currentTime - latestTime) + 1000 + latestTime = currentTime + if (latestTime != maxTime) { + addDiff(diff) + } } val currentFormat = TimeUtils.formatDuration(currentTime) val percentage = LorenzUtils.formatPercentage(currentTime.toDouble() / maxTime) - val percentageFormat = if (config.percentage) " §7($percentage)" else "" - val maxTimeFormat = if (config.maxTime) "§7/§b" + TimeUtils.formatDuration(maxTime) else "" + val percentageFormat = if (config.percentage.get()) " §7($percentage)" else "" + val maxTimeFormat = if (config.maxTime.get()) "§7/§b" + TimeUtils.formatDuration(maxTime) else "" val color = if (currentTime <= 60_000) "§c" else if (currentTime <= 60_000 * 5) "§e" else "§b" val firstLine = "§eRift Timer: $color$currentFormat$maxTimeFormat$percentageFormat" @@ -84,6 +86,18 @@ class RiftTimer { changes[System.currentTimeMillis()] = diffFormat } + @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + LorenzUtils.onToggle( + config.percentage, + config.maxTime, + ) { + if (isEnabled()) { + update() + } + } + } + @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { if (!isEnabled()) return -- cgit