From cfc760103dc914d5b7456e9cffe06d30f396e029 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Tue, 7 Nov 2023 23:07:53 +0100 Subject: code cleanup and better wording --- .../skyhanni/utils/tracker/SkyHanniTracker.kt | 40 ++++++++++++++---- .../skyhanni/utils/tracker/TrackerUtils.kt | 48 ---------------------- 2 files changed, 32 insertions(+), 56 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt (limited to 'src/main/java') 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 8af683b16..6d0fcedb6 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt @@ -3,9 +3,11 @@ package at.hannibal2.skyhanni.utils.tracker import at.hannibal2.skyhanni.config.Storage import at.hannibal2.skyhanni.config.core.config.Position import at.hannibal2.skyhanni.data.ProfileStorageData +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems -import at.hannibal2.skyhanni.utils.tracker.TrackerUtils.addSessionResetButton +import at.hannibal2.skyhanni.utils.renderables.Renderable import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiInventory @@ -26,11 +28,19 @@ class SkyHanniTracker( } fun addSessionResetButton(list: MutableList>) { - if (inventoryOpen && displayMode == DisplayMode.SESSION) { - list.addSessionResetButton(name, getSharedTracker()) { - update() - } - } + if (!inventoryOpen || displayMode != DisplayMode.SESSION) return + + 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!") + }) } fun addDisplayModeToggle(list: MutableList>) { @@ -50,9 +60,15 @@ class SkyHanniTracker( fun currentDisplay() = getSharedTracker()?.get(displayMode) fun resetCommand(args: Array, command: String) { - TrackerUtils.resetCommand(name, command, args, getSharedTracker()) { - update() + if (args.size == 1 && args[0].lowercase() == "confirm") { + reset(DisplayMode.TOTAL, "§e[SkyHanni] Reset total $name!") + return } + + LorenzUtils.clickableChat( + "§e[SkyHanni] Are you sure you want to reset your total $name? Click here to confirm.", + "$command confirm" + ) } fun modify(modifyFunction: (Data) -> Unit) { @@ -68,4 +84,12 @@ class SkyHanniTracker( position.renderStringsAndItems(display, posLabel = name) } + + private fun reset(displayMode: DisplayMode, message: String) { + getSharedTracker()?.get(displayMode)?.let { + it.reset() + LorenzUtils.chat(message) + update() + } + } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt deleted file mode 100644 index 77074a4b6..000000000 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt +++ /dev/null @@ -1,48 +0,0 @@ -package at.hannibal2.skyhanni.utils.tracker - -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList -import at.hannibal2.skyhanni.utils.renderables.Renderable - -object TrackerUtils { - - fun MutableList>.addSessionResetButton(name: String, data: SharedTracker<*>?, update: () -> Unit) { - addAsSingletonList( - Renderable.clickAndHover( - "§cReset session!", - listOf( - "§cThis will reset your", - "§ccurrent session for", - "§c$name" - ), - ) { - data?.get(DisplayMode.SESSION)?.let { - reset(it) { - update() - } - } - }) - } - - fun resetCommand(name: String, command: String, args: Array, data: SharedTracker<*>?, update: () -> Unit) { - if (args.size == 1 && args[0].lowercase() == "confirm") { - reset(data?.get(DisplayMode.TOTAL)) { - update() - LorenzUtils.chat("§e[SkyHanni] You reset your $name data!") - } - return - } - - LorenzUtils.clickableChat( - "§e[SkyHanni] Are you sure you want to reset all your $name data? Click here to confirm.", - "$command confirm" - ) - } - - private fun reset(data: TrackerData?, update: () -> Unit) { - data?.let { - it.reset() - update() - } - } -} -- cgit