aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-09 18:50:26 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-09 18:50:26 +0100
commit5a9af30efab8de12bb7b7431d47cbd4741274b82 (patch)
tree57e9f65db51d03968f4b635be2ca39fe9e55a23e /src/main
parente03ba746fa0ab6258fcd5e6855d1590b0ba6f5c9 (diff)
downloadskyhanni-5a9af30efab8de12bb7b7431d47cbd4741274b82.tar.gz
skyhanni-5a9af30efab8de12bb7b7431d47cbd4741274b82.tar.bz2
skyhanni-5a9af30efab8de12bb7b7431d47cbd4741274b82.zip
Added cooldown to no longer spam the reset current session button of trackers.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt60
1 files changed, 36 insertions, 24 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
index d1b783f7e..e80f93edf 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
@@ -6,9 +6,11 @@ import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.renderables.Renderable
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiInventory
+import kotlin.time.Duration.Companion.seconds
class SkyHanniTracker<Data : TrackerData>(
private val name: String,
@@ -20,6 +22,7 @@ class SkyHanniTracker<Data : TrackerData>(
private var displayMode = DisplayMode.TOTAL
private val currentSessions = mutableMapOf<Storage.ProfileSpecific, Data>()
private var display = emptyList<List<Any>>()
+ private var sessionResetTime = SimpleTimeMark.farPast()
fun isInventoryOpen() = inventoryOpen
@@ -51,37 +54,46 @@ class SkyHanniTracker<Data : TrackerData>(
}
fun update() {
- display = currentDisplay()?.let {
- val list = drawDisplay(it).toMutableList()
+ display = buildFinalDisplay()
+ }
+
+ private fun buildFinalDisplay(): List<List<Any>> {
+ val data = currentDisplay() ?: return emptyList()
+
+ return drawDisplay(data).toMutableList().also {
if (inventoryOpen) {
- list.add(1, LorenzUtils.buildSelector<DisplayMode>(
- "§7Display Mode: ",
- getName = { type -> type.displayName },
- isCurrent = { it == displayMode },
- onChange = {
- displayMode = it
- update()
- }
- ))
+ it.add(1, buildDisplayModeView())
}
if (inventoryOpen && displayMode == DisplayMode.SESSION) {
- list.addAsSingletonList(
- Renderable.clickAndHover(
- "§cReset session!",
- listOf(
- "§cThis will reset your",
- "§ccurrent session of",
- "§c$name"
- ),
- ) {
- reset(DisplayMode.SESSION, "§e[SkyHanni] Reset this session of $name!")
- })
+ it.addAsSingletonList(buildSessionResetButton())
}
+ }
+ }
- list
- } ?: emptyList()
+ private fun buildSessionResetButton() = Renderable.clickAndHover(
+ "§cReset session!",
+ listOf(
+ "§cThis will reset your",
+ "§ccurrent session of",
+ "§c$name"
+ ),
+ ) {
+ if (sessionResetTime.passedSince() > 3.seconds) {
+ reset(DisplayMode.SESSION, "§e[SkyHanni] Reset this session of $name!")
+ sessionResetTime = SimpleTimeMark.now()
+ }
}
+ private fun buildDisplayModeView() = LorenzUtils.buildSelector<DisplayMode>(
+ "§7Display Mode: ",
+ getName = { type -> type.displayName },
+ isCurrent = { it == displayMode },
+ onChange = {
+ displayMode = it
+ update()
+ }
+ )
+
private fun currentDisplay() = getSharedTracker()?.get(displayMode)
private fun getSharedTracker(): SharedTracker<Data>? {