aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/tracker
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-07 21:20:32 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-07 21:20:32 +0100
commitae84c3c74b346057bd6de389fa27094bec6ca9c0 (patch)
treea45bdea7b2351c3531db113a0f991d2ad7988849 /src/main/java/at/hannibal2/skyhanni/utils/tracker
parentf3fda2930fcada44f9dba2edbaaeeb0b72cbf325 (diff)
downloadskyhanni-ae84c3c74b346057bd6de389fa27094bec6ca9c0.tar.gz
skyhanni-ae84c3c74b346057bd6de389fa27094bec6ca9c0.tar.bz2
skyhanni-ae84c3c74b346057bd6de389fa27094bec6ca9c0.zip
added function renderDisplay to SkyHanniTracker, removed code duplication
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/tracker')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt31
1 files changed, 26 insertions, 5 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 5e9181447..a63a47706 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
@@ -1,23 +1,30 @@
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.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
class SkyHanniTracker<Data : TrackerData>(
- val name: String,
+ private val name: String,
private val currentSessionData: Data,
- val getStorage: (Storage.ProfileSpecific) -> Data,
- val update: () -> Unit,
+ private val getStorage: (Storage.ProfileSpecific) -> Data,
+ private val update: () -> Unit,
) {
+ private var inventoryOpen = false
+
private fun getSharedTracker(): SharedTracker<Data>? {
val profileSpecific = ProfileStorageData.profileSpecific ?: return null
return SharedTracker(getStorage(profileSpecific), currentSessionData)
}
- fun addSessionResetButton(list: MutableList<List<Any>>, inventoryOpen: Boolean) {
+ fun addSessionResetButton(list: MutableList<List<Any>>) {
if (inventoryOpen && TrackerUtils.currentDisplayMode == DisplayMode.CURRENT) {
list.addSessionResetButton(name, getSharedTracker()) {
update()
@@ -25,11 +32,15 @@ class SkyHanniTracker<Data : TrackerData>(
}
}
- fun addDisplayModeToggle(list: MutableList<List<Any>>, inventoryOpen: Boolean) {
+ fun addDisplayModeToggle(list: MutableList<List<Any>>, closedText: String? = null) {
if (inventoryOpen) {
list.addDisplayModeToggle {
update()
}
+ } else {
+ closedText?.let {
+ list.addAsSingletonList(it)
+ }
}
}
@@ -44,4 +55,14 @@ class SkyHanniTracker<Data : TrackerData>(
fun modify(modifyFunction: (Data) -> Unit) {
getSharedTracker()?.modify(modifyFunction)
}
+
+ fun renderDisplay(position: Position, display: List<List<Any>>) {
+ val currentlyOpen = Minecraft.getMinecraft().currentScreen is GuiInventory
+ if (inventoryOpen != currentlyOpen) {
+ inventoryOpen = currentlyOpen
+ update()
+ }
+
+ position.renderStringsAndItems(display, posLabel = name)
+ }
}