aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/tracker
diff options
context:
space:
mode:
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)
+ }
}