diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-07 22:58:44 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-07 22:58:44 +0100 |
commit | 0f278dbc298769b47fd1c8eb58588aafbdcfb619 (patch) | |
tree | 8716474eaa2318619c209c267dc1b7b2628c37d6 /src/main/java/at/hannibal2/skyhanni/utils | |
parent | fccea080f5b8eaf561e83dc62b84a3cd5ded5a8f (diff) | |
download | skyhanni-0f278dbc298769b47fd1c8eb58588aafbdcfb619.tar.gz skyhanni-0f278dbc298769b47fd1c8eb58588aafbdcfb619.tar.bz2 skyhanni-0f278dbc298769b47fd1c8eb58588aafbdcfb619.zip |
save displayMode per tracker and code cleanup
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt | 26 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt | 14 |
2 files changed, 14 insertions, 26 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 e1b4c42ad..8af683b16 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,8 @@ 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.addAsSingletonList +import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems -import at.hannibal2.skyhanni.utils.tracker.TrackerUtils.addDisplayModeToggle import at.hannibal2.skyhanni.utils.tracker.TrackerUtils.addSessionResetButton import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiInventory @@ -17,6 +16,7 @@ class SkyHanniTracker<Data : TrackerData>( private val update: () -> Unit, ) { private var inventoryOpen = false + private var displayMode = DisplayMode.TOTAL fun isInventoryOpen() = inventoryOpen @@ -26,26 +26,28 @@ class SkyHanniTracker<Data : TrackerData>( } fun addSessionResetButton(list: MutableList<List<Any>>) { - if (inventoryOpen && TrackerUtils.currentDisplayMode == DisplayMode.SESSION) { + if (inventoryOpen && displayMode == DisplayMode.SESSION) { list.addSessionResetButton(name, getSharedTracker()) { update() } } } - fun addDisplayModeToggle(list: MutableList<List<Any>>, closedText: String? = null) { - if (inventoryOpen) { - list.addDisplayModeToggle { + fun addDisplayModeToggle(list: MutableList<List<Any>>) { + if (!inventoryOpen) return + + list.addSelector<DisplayMode>( + "§7Display Mode: ", + getName = { type -> type.displayName }, + isCurrent = { it == displayMode }, + onChange = { + displayMode = it update() } - } else { - closedText?.let { - list.addAsSingletonList(it) - } - } + ) } - fun currentDisplay() = getSharedTracker()?.get(TrackerUtils.currentDisplayMode) + fun currentDisplay() = getSharedTracker()?.get(displayMode) fun resetCommand(args: Array<String>, command: String) { TrackerUtils.resetCommand(name, command, args, getSharedTracker()) { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt index ec527c9e5..77074a4b6 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt @@ -2,23 +2,9 @@ package at.hannibal2.skyhanni.utils.tracker 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.renderables.Renderable object TrackerUtils { - var currentDisplayMode = DisplayMode.TOTAL - - fun MutableList<List<Any>>.addDisplayModeToggle(update: () -> Unit) { - addSelector<DisplayMode>( - "§7Display Mode: ", - getName = { type -> type.displayName }, - isCurrent = { it == currentDisplayMode }, - onChange = { - currentDisplayMode = it - update() - } - ) - } fun MutableList<List<Any>>.addSessionResetButton(name: String, data: SharedTracker<*>?, update: () -> Unit) { addAsSingletonList( |