diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-07 21:20:32 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-07 21:20:32 +0100 |
commit | ae84c3c74b346057bd6de389fa27094bec6ca9c0 (patch) | |
tree | a45bdea7b2351c3531db113a0f991d2ad7988849 /src/main/java | |
parent | f3fda2930fcada44f9dba2edbaaeeb0b72cbf325 (diff) | |
download | skyhanni-ae84c3c74b346057bd6de389fa27094bec6ca9c0.tar.gz skyhanni-ae84c3c74b346057bd6de389fa27094bec6ca9c0.tar.bz2 skyhanni-ae84c3c74b346057bd6de389fa27094bec6ca9c0.zip |
added function renderDisplay to SkyHanniTracker, removed code duplication
Diffstat (limited to 'src/main/java')
3 files changed, 32 insertions, 41 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerDropTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerDropTracker.kt index bc4655bbe..659a6cc17 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerDropTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerDropTracker.kt @@ -14,19 +14,15 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.addOrPut import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker import at.hannibal2.skyhanni.utils.tracker.TrackerData import com.google.gson.annotations.Expose -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.inventory.GuiInventory import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object DicerDropTracker { private var display = emptyList<List<Any>>() private val itemDrops = mutableListOf<ItemDrop>() private val config get() = SkyHanniMod.feature.garden.dicerCounters - private var inventoryOpen = false private val tracker = SkyHanniTracker("Dicer Drop Tracker", Data(), { it.garden.dicerDropTracker }) { update() } class Data : TrackerData() { @@ -89,13 +85,13 @@ object DicerDropTracker { val cropInHand = cropInHand ?: return@buildList val items = storage.drops.getOrPut(cropInHand) { mutableMapOf() } addAsSingletonList("§7Dicer Drop Tracker for $toolName§7:") - tracker.addDisplayModeToggle(this, inventoryOpen) + tracker.addDisplayModeToggle(this) for ((rarity, amount) in items.sortedDesc()) { val displayName = rarity.displayName addAsSingletonList(" §7- §e${amount.addSeparators()}x $displayName") } - tracker.addSessionResetButton(this, inventoryOpen) + tracker.addSessionResetButton(this) } private var cropInHand: CropType? = null @@ -123,12 +119,7 @@ object DicerDropTracker { fun onRenderOverlay(event: GuiRenderEvent) { if (!isEnabled()) return - val currentlyOpen = Minecraft.getMinecraft().currentScreen is GuiInventory - if (inventoryOpen != currentlyOpen) { - inventoryOpen = currentlyOpen - update() - } - config.pos.renderStringsAndItems(display, posLabel = "Dicer Drop Tracker") + tracker.renderDisplay(config.pos, display) } class ItemDrop(val crop: CropType, val rarity: DropRarity, val pattern: Regex) diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt index 82e9e05b7..f5c56cc9a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt @@ -13,15 +13,10 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.afterChange import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber -import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.utils.tracker.DisplayMode import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker import at.hannibal2.skyhanni.utils.tracker.TrackerData -import at.hannibal2.skyhanni.utils.tracker.TrackerUtils import com.google.gson.annotations.Expose -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.inventory.GuiInventory import net.minecraft.entity.boss.BossStatus import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.concurrent.fixedRateTimer @@ -44,7 +39,6 @@ object PowderTracker { private val chestInfo = ResourceInfo(0L, 0L, 0, 0.0, mutableListOf()) private var doublePowder = false private var powderTimer = "" - private var inventoryOpen = false private val gemstones = listOf( "Ruby" to "§c", "Sapphire" to "§b", @@ -84,18 +78,9 @@ object PowderTracker { fun onRenderOverlay(event: GuiRenderEvent) { if (!isEnabled()) return - val currentlyOpen = Minecraft.getMinecraft().currentScreen is GuiInventory - if (inventoryOpen != currentlyOpen) { - inventoryOpen = currentlyOpen - saveAndUpdate() - } - if (config.onlyWhenPowderGrinding && !isGrinding) return - config.position.renderStringsAndItems( - display, - posLabel = "Powder Chest Tracker" - ) + tracker.renderDisplay(config.position, display) } @SubscribeEvent @@ -206,18 +191,12 @@ object PowderTracker { add(map[index]) } - if (inventoryOpen && TrackerUtils.currentDisplayMode == DisplayMode.CURRENT) { - tracker.addSessionResetButton(this, inventoryOpen) - } + tracker.addSessionResetButton(this) } private fun drawDisplay() = buildList<List<Any>> { addAsSingletonList("§b§lPowder Tracker") - if (inventoryOpen) { - tracker.addDisplayModeToggle(this, inventoryOpen = true) - } else { - addAsSingletonList("") - } + tracker.addDisplayModeToggle(this, closedText = "") val display = tracker.currentDisplay() ?: return@buildList 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) + } } |