diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-12-26 17:15:28 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-12-26 17:15:28 +0100 |
commit | dea252c20bef556b4747b15b2d031c5ee31571e6 (patch) | |
tree | 9874dff09b54a559109bdcae95b94ea454cdeb97 /src/main/java/at | |
parent | 8f132d5ef584f31475421faf7a1ce673e63afa2d (diff) | |
download | skyhanni-dea252c20bef556b4747b15b2d031c5ee31571e6.tar.gz skyhanni-dea252c20bef556b4747b15b2d031c5ee31571e6.tar.bz2 skyhanni-dea252c20bef556b4747b15b2d031c5ee31571e6.zip |
Rift time now updates correctly in wizard tower and instantly updates the format when toggling max time or percentage.
Diffstat (limited to 'src/main/java/at')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftTimerConfig.java | 5 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt | 44 |
2 files changed, 32 insertions, 17 deletions
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<Boolean> maxTime = Property.of(true); @Expose @ConfigOption(name = "Percentage", desc = "Show percentage.") @ConfigEditorBoolean - public boolean percentage = true; + public Property<Boolean> 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<String>() private var maxTime = 0L + private var currentTime = 0L private var latestTime = 0L private val changes = mutableMapOf<Long, String>() @@ -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" @@ -85,6 +87,18 @@ class RiftTimer { } @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + LorenzUtils.onToggle( + config.percentage, + config.maxTime, + ) { + if (isEnabled()) { + update() + } + } + } + + @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { if (!isEnabled()) return if (LorenzUtils.skyBlockArea == "Mirrorverse") return |