diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-25 03:21:38 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-25 03:21:38 +0100 |
commit | e47a2877bbb0550a1852889e0398f45bc20c0881 (patch) | |
tree | b191552e878d9f00274c4ac987abc7a2696a72c0 /src/main/java | |
parent | f142d7f2483247f541a24625af3f5789f3ee1ae6 (diff) | |
download | skyhanni-e47a2877bbb0550a1852889e0398f45bc20c0881.tar.gz skyhanni-e47a2877bbb0550a1852889e0398f45bc20c0881.tar.bz2 skyhanni-e47a2877bbb0550a1852889e0398f45bc20c0881.zip |
moved item draw logic from item tracker data to SkyHanni item tracker
Diffstat (limited to 'src/main/java')
4 files changed, 105 insertions, 111 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt index 674269c8d..a6e8c2477 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt @@ -10,7 +10,6 @@ import at.hannibal2.skyhanni.utils.DelayedRun import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.addButton -import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NumberUtil @@ -121,18 +120,7 @@ object FishingProfitTracker { { it in items } } - var profit = 0.0 - val map = mutableMapOf<Renderable, Long>() - for ((internalName, itemProfit) in data.items) { - if (!filter(internalName)) continue - - val price = data.drawItem(tracker, itemProfit, internalName, map) - profit += price - } - - for (text in map.sortedDesc().keys) { - addAsSingletonList(text) - } + val profit = tracker.drawItems(data, filter, this) val fishedCount = data.totalCatchAmount addAsSingletonList( diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt index d71172eb3..938441d95 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt @@ -14,7 +14,6 @@ import at.hannibal2.skyhanni.events.SlayerQuestCompleteEvent import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList -import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators @@ -170,25 +169,19 @@ object SlayerProfitTracker { val tracker = getTracker() ?: return@buildList addAsSingletonList("§e§l$itemLogCategory Profit Tracker") - var profit = 0.0 - val map = mutableMapOf<Renderable, Long>() - for ((internalName, itemProfit) in itemLog.items) { - profit += itemLog.drawItem(tracker, itemProfit, internalName, map) - } + var profit = tracker.drawItems(itemLog, { true }, this) val slayerSpawnCost = itemLog.slayerSpawnCost if (slayerSpawnCost != 0L) { val mobKillCoinsFormat = NumberUtil.format(slayerSpawnCost) - map[Renderable.hoverTips( - " §7Slayer Spawn Costs: §c$mobKillCoinsFormat", - listOf("§7You paid §c$mobKillCoinsFormat §7in total", "§7for starting the slayer quests.") - )] = slayerSpawnCost + addAsSingletonList( + Renderable.hoverTips( + " §7Slayer Spawn Costs: §c$mobKillCoinsFormat", + listOf("§7You paid §c$mobKillCoinsFormat §7in total", "§7for starting the slayer quests.") + ) + ) profit += slayerSpawnCost } - for (text in map.sortedDesc().keys) { - addAsSingletonList(text) - } - val slayerCompletedCount = itemLog.slayerCompletedCount addAsSingletonList( Renderable.hoverTips( diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/ItemTrackerData.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/ItemTrackerData.kt index 985706a38..d515dd401 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/ItemTrackerData.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/ItemTrackerData.kt @@ -1,30 +1,14 @@ package at.hannibal2.skyhanni.utils.tracker import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.utils.ItemUtils.nameWithEnchantment -import at.hannibal2.skyhanni.utils.KeyboardManager -import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName -import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName -import at.hannibal2.skyhanni.utils.NEUItems.getItemStack -import at.hannibal2.skyhanni.utils.NumberUtil -import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.SimpleTimeMark -import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import at.hannibal2.skyhanni.utils.renderables.Renderable import com.google.gson.annotations.Expose -import kotlin.time.Duration.Companion.seconds abstract class ItemTrackerData : TrackerData() { private val config get() = SkyHanniMod.feature.misc.tracker - private var lastClickDelay = 0L - - companion object { - val SKYBLOCK_COIN by lazy { "SKYBLOCK_COIN".asInternalName() } - } - abstract fun resetItems() abstract fun getDescription(timesGained: Long): List<String> @@ -46,73 +30,6 @@ abstract class ItemTrackerData : TrackerData() { item.lastTimeUpdated = SimpleTimeMark.now() } - fun drawItem( - tracker: SkyHanniItemTracker<out ItemTrackerData>, - item: TrackedItem, - internalName: NEUInternalName, - map: MutableMap<Renderable, Long> - ): Long { - val amount = item.totalAmount - - val pricePer = if (internalName == SKYBLOCK_COIN) 1.0 else getCustomPricePer(internalName) - - val price = (pricePer * amount).toLong() - val displayAmount = if (internalName == SKYBLOCK_COIN) item.timesGained else amount - - var name = if (internalName == SKYBLOCK_COIN) { - "§6Coins" - } else { - internalName.getItemStack().nameWithEnchantment ?: error("no name for $internalName") - } - val priceFormat = NumberUtil.format(price) - val hidden = item.hidden - - val newDrop = item.lastTimeUpdated.passedSince() < 10.seconds && config.showRecentDrops - val numberColor = if (newDrop) "§a§l" else "§7" - - if (hidden) { - name = "§8§m" + name.removeColor(keepFormatting = true).replace("§r", "") - } - - val text = " $numberColor${displayAmount.addSeparators()}x $name§7: §6$priceFormat" - val (displayName, lore) = if (internalName == SKYBLOCK_COIN) { - getCoinFormat(item, numberColor) - } else text to buildLore(item, hidden, newDrop) - - val renderable = if (tracker.isInventoryOpen()) Renderable.clickAndHover(displayName, lore) { - if (System.currentTimeMillis() > lastClickDelay + 150) { - if (KeyboardManager.isControlKeyDown()) { - items.remove(internalName) - LorenzUtils.chat("§e[SkyHanni] Removed ${if (internalName == SKYBLOCK_COIN) "§6Coins" else internalName.getItemStack().nameWithEnchantment} §efrom Fishing Frofit Tracker.") - lastClickDelay = System.currentTimeMillis() + 500 - } else { - item.hidden = !hidden - lastClickDelay = System.currentTimeMillis() - } - tracker.update() - } - } else Renderable.string(displayName) - if (tracker.isInventoryOpen() || !hidden) { - map[renderable] = price - } - return price - } - - private fun buildLore( - item: TrackedItem, - hidden: Boolean, - newDrop: Boolean - ) = buildList { - addAll(getDescription(item.timesGained)) - add("") - if (newDrop) { - add("§aYou caught this item recently.") - add("") - } - add("§eClick to " + (if (hidden) "show" else "hide") + "!") - add("§eControl + Click to remove this item!") - } - @Expose var items: MutableMap<NEUInternalName, TrackedItem> = HashMap() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt index 8059123fb..3c33a408a 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt @@ -2,8 +2,20 @@ package at.hannibal2.skyhanni.utils.tracker import at.hannibal2.skyhanni.config.Storage import at.hannibal2.skyhanni.test.PriceSource +import at.hannibal2.skyhanni.utils.ItemUtils.nameWithEnchantment +import at.hannibal2.skyhanni.utils.KeyboardManager +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.LorenzUtils.sortedDesc import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.NEUItems.getItemStack +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.renderables.Renderable +import kotlin.time.Duration.Companion.seconds class SkyHanniItemTracker<Data : ItemTrackerData>( name: String, @@ -12,8 +24,14 @@ class SkyHanniItemTracker<Data : ItemTrackerData>( drawDisplay: (Data) -> List<List<Any>>, ) : SkyHanniTracker<Data>(name, createNewSession, getStorage, drawDisplay) { + companion object { + val SKYBLOCK_COIN by lazy { "SKYBLOCK_COIN".asInternalName() } + } + + private var lastClickDelay = 0L + fun addCoins(coins: Int) { - addItem(ItemTrackerData.SKYBLOCK_COIN, coins) + addItem(SKYBLOCK_COIN, coins) } fun addItem(internalName: NEUInternalName, stackSize: Int) { @@ -34,6 +52,84 @@ class SkyHanniItemTracker<Data : ItemTrackerData>( } ) } + } + fun drawItems( + data: Data, + filter: (NEUInternalName) -> Boolean, + lists: MutableList<List<Any>> + ): Double { + var profit = 0.0 + val map = mutableMapOf<Renderable, Long>() + for ((internalName, itemProfit) in data.items) { + if (!filter(internalName)) continue + + val amount = itemProfit.totalAmount + val pricePer = + if (internalName == SKYBLOCK_COIN) 1.0 else data.getCustomPricePer(internalName) + val price = (pricePer * amount).toLong() + val displayAmount = if (internalName == SKYBLOCK_COIN) itemProfit.timesGained else amount + var name = if (internalName == SKYBLOCK_COIN) { + "§6Coins" + } else { + internalName.getItemStack().nameWithEnchantment ?: error("no name for $internalName") + } + val priceFormat = NumberUtil.format(price) + val hidden = itemProfit.hidden + val newDrop = itemProfit.lastTimeUpdated.passedSince() < 10.seconds && config.showRecentDrops + val numberColor = if (newDrop) "§a§l" else "§7" + if (hidden) { + name = "§8§m" + name.removeColor(keepFormatting = true).replace("§r", "") + } + val text = " $numberColor${displayAmount.addSeparators()}x $name§7: §6$priceFormat" + val (displayName, lore) = if (internalName == SKYBLOCK_COIN) { + data.getCoinFormat(itemProfit, numberColor) + } else text to buildLore(data, itemProfit, hidden, newDrop) + val renderable = if (isInventoryOpen()) Renderable.clickAndHover(displayName, lore) { + if (System.currentTimeMillis() > lastClickDelay + 150) { + if (KeyboardManager.isControlKeyDown()) { + data.items.remove(internalName) + val abc = if (internalName == SKYBLOCK_COIN) { + "§6Coins" + } else { + internalName.getItemStack().nameWithEnchantment + } + LorenzUtils.chat("§e[SkyHanni] Removed $abc §efrom Fishing Frofit Tracker.") + lastClickDelay = System.currentTimeMillis() + 500 + } else { + itemProfit.hidden = !hidden + + lastClickDelay = System.currentTimeMillis() + } + update() + } + } else Renderable.string(displayName) + if (isInventoryOpen() || !hidden) { + map[renderable] = price + } + profit += price + } + + for (text in map.sortedDesc().keys) { + lists.addAsSingletonList(text) + } + return profit } + + private fun buildLore( + data: Data, + item: ItemTrackerData.TrackedItem, + hidden: Boolean, + newDrop: Boolean + ) = buildList { + addAll(data.getDescription(item.timesGained)) + add("") + if (newDrop) { + add("§aYou caught this item recently.") + add("") + } + add("§eClick to " + (if (hidden) "show" else "hide") + "!") + add("§eControl + Click to remove this item!") + } + } |