aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-09 18:39:30 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-09 18:39:30 +0100
commite03ba746fa0ab6258fcd5e6855d1590b0ba6f5c9 (patch)
tree2de4b40f7e7466e52e5d1b16eb8a45c3d5f4eabe /src/main/java/at/hannibal2/skyhanni/utils
parentd2d6162ce5830099418e85b69f02b958625ad6a7 (diff)
downloadskyhanni-e03ba746fa0ab6258fcd5e6855d1590b0ba6f5c9.tar.gz
skyhanni-e03ba746fa0ab6258fcd5e6855d1590b0ba6f5c9.tar.bz2
skyhanni-e03ba746fa0ab6258fcd5e6855d1590b0ba6f5c9.zip
SkyHanniTracker now handles the display list as well.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt37
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt73
2 files changed, 60 insertions, 50 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index e6bc74e06..4f0704ead 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -334,22 +334,29 @@ object LorenzUtils {
isCurrent: (T) -> Boolean,
crossinline onChange: (T) -> Unit,
) {
- add(buildList {
- add(prefix)
- for (entry in enumValues<T>()) {
- val display = getName(entry)
- if (isCurrent(entry)) {
- add("§a[$display]")
- } else {
- add("§e[")
- add(Renderable.link("§e$display") {
- onChange(entry)
- })
- add("§e]")
- }
- add(" ")
+ add(buildSelector<T>(prefix, getName, isCurrent, onChange))
+ }
+
+ inline fun <reified T : Enum<T>> buildSelector(
+ prefix: String,
+ getName: (T) -> String,
+ isCurrent: (T) -> Boolean,
+ crossinline onChange: (T) -> Unit
+ ) = buildList {
+ add(prefix)
+ for (entry in enumValues<T>()) {
+ val display = getName(entry)
+ if (isCurrent(entry)) {
+ add("§a[$display]")
+ } else {
+ add("§e[")
+ add(Renderable.link("§e$display") {
+ onChange(entry)
+ })
+ add("§e]")
}
- })
+ add(" ")
+ }
}
inline fun MutableList<List<Any>>.addButton(
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 ec0fc4848..d1b783f7e 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
@@ -5,7 +5,6 @@ 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.renderables.Renderable
import net.minecraft.client.Minecraft
@@ -15,46 +14,15 @@ class SkyHanniTracker<Data : TrackerData>(
private val name: String,
private val createNewSession: () -> Data,
private val getStorage: (Storage.ProfileSpecific) -> Data,
- private val update: () -> Unit,
+ private val drawDisplay: (Data) -> List<List<Any>>,
) {
private var inventoryOpen = false
private var displayMode = DisplayMode.TOTAL
private val currentSessions = mutableMapOf<Storage.ProfileSpecific, Data>()
+ private var display = emptyList<List<Any>>()
fun isInventoryOpen() = inventoryOpen
- fun addSessionResetButton(list: MutableList<List<Any>>) {
- 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<List<Any>>) {
- if (!inventoryOpen) return
-
- list.addSelector<DisplayMode>(
- "§7Display Mode: ",
- getName = { type -> type.displayName },
- isCurrent = { it == displayMode },
- onChange = {
- displayMode = it
- update()
- }
- )
- }
-
- fun currentDisplay() = getSharedTracker()?.get(displayMode)
-
fun resetCommand(args: Array<String>, command: String) {
if (args.size == 1 && args[0].lowercase() == "confirm") {
reset(DisplayMode.TOTAL, "§e[SkyHanni] Reset total $name!")
@@ -69,9 +37,10 @@ class SkyHanniTracker<Data : TrackerData>(
fun modify(modifyFunction: (Data) -> Unit) {
getSharedTracker()?.modify(modifyFunction)
+ update()
}
- fun renderDisplay(position: Position, display: List<List<Any>>) {
+ fun renderDisplay(position: Position) {
val currentlyOpen = Minecraft.getMinecraft().currentScreen is GuiInventory
if (inventoryOpen != currentlyOpen) {
inventoryOpen = currentlyOpen
@@ -81,6 +50,40 @@ class SkyHanniTracker<Data : TrackerData>(
position.renderStringsAndItems(display, posLabel = name)
}
+ fun update() {
+ display = currentDisplay()?.let {
+ val list = drawDisplay(it).toMutableList()
+ if (inventoryOpen) {
+ list.add(1, LorenzUtils.buildSelector<DisplayMode>(
+ "§7Display Mode: ",
+ getName = { type -> type.displayName },
+ isCurrent = { it == displayMode },
+ onChange = {
+ displayMode = it
+ update()
+ }
+ ))
+ }
+ 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!")
+ })
+ }
+
+ list
+ } ?: emptyList()
+ }
+
+ private fun currentDisplay() = getSharedTracker()?.get(displayMode)
+
private fun getSharedTracker(): SharedTracker<Data>? {
val profileSpecific = ProfileStorageData.profileSpecific ?: return null
return SharedTracker(getStorage(profileSpecific), getCurrentSession(profileSpecific))