From f143f2fd998c4e2263cc9ea659c4cbab7aa6bf8e Mon Sep 17 00:00:00 2001 From: catgirlseraid <77941535+catgirlseraid@users.noreply.github.com> Date: Fri, 19 Jul 2024 17:50:05 +1200 Subject: [PATCH] Add coins to itempickup list, add option for formatting, add option for display alignment --- .../inventory/ItemPickupLogConfig.java | 24 +++++- .../features/inventory/ItemPickupLog.kt | 83 +++++++++++++------ .../hannibal2/skyhanni/utils/RenderUtils.kt | 2 +- 3 files changed, 80 insertions(+), 29 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/ItemPickupLogConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/ItemPickupLogConfig.java index 63a5b61f0e06..13f6b1932325 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/ItemPickupLogConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/ItemPickupLogConfig.java @@ -2,8 +2,10 @@ import at.hannibal2.skyhanni.config.FeatureToggle; import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.utils.RenderUtils; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider; import io.github.notenoughupdates.moulconfig.annotations.ConfigLink; import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; @@ -22,15 +24,33 @@ public class ItemPickupLogConfig { public boolean compactLines = true; @Expose - @ConfigOption(name = "Show Item Icon", desc = "Show the item icon next to the item name") + @ConfigOption(name = "Compact Numbers", desc = "Compact the amounts added and removed.") + @ConfigEditorBoolean + public boolean shorten = false; + + @Expose + @ConfigOption(name = "Show Item Icon", desc = "Show the item icon next to the item name.") @ConfigEditorBoolean public boolean showItemIcon = true; @Expose - @ConfigOption(name = "Sacks", desc = "Also show items added and removed from stacks") + @ConfigOption(name = "Sacks", desc = "Show items added and removed from stacks.") @ConfigEditorBoolean public boolean sack = true; + @Expose + @ConfigOption(name = "Coins", desc = "Show coins added and removed from purse.") + @ConfigEditorBoolean + public boolean coins = false; + + @Expose + @ConfigOption( + name = "Alignment", + desc = "How the item pickup log should be aligned. §d:3" + ) + @ConfigEditorDropdown + public RenderUtils.VerticalAlignment alignment = RenderUtils.VerticalAlignment.TOP; + @Expose @ConfigOption( name = "Expire After", diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemPickupLog.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemPickupLog.kt index 05a92a5870bf..10a0ea4bf652 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemPickupLog.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemPickupLog.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent +import at.hannibal2.skyhanni.events.PurseChangeEvent import at.hannibal2.skyhanni.events.SackChangeEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.CollectionUtils.addItemStack @@ -12,14 +13,18 @@ import at.hannibal2.skyhanni.utils.ItemNameResolver import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getItemRarityOrNull 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.addSeparators -import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables +import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat +import at.hannibal2.skyhanni.utils.RenderUtils +import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getExtraAttributes import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.renderables.Renderable +import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXYAligned import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.client.Minecraft import net.minecraft.item.ItemStack @@ -32,10 +37,12 @@ import kotlin.time.Duration.Companion.seconds object ItemPickupLog { private val config get() = SkyHanniMod.feature.inventory.itemPickupLogConfig + private val coinIcon = "COIN_TALISMAN".asInternalName() + private var itemList = mutableMapOf>() private var itemsAddedToInventory = mutableMapOf() private var itemsRemovedFromInventory = mutableMapOf() - private val display = mutableListOf() + private var display: Renderable = Renderable.string("") private val patternGroup = RepoPattern.group("itempickuplog") private val shopPattern by patternGroup.pattern( @@ -46,7 +53,7 @@ object ItemPickupLog { @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent) { if (!isEnabled()) return - config.pos.renderRenderables(display, posLabel = "Item Pickup Log Display") + config.pos.renderRenderable(display, posLabel = "Item Pickup Log Display") } @SubscribeEvent @@ -58,17 +65,24 @@ object ItemPickupLog { } @SubscribeEvent - fun onStackChange(event: SackChangeEvent) { - if (!isEnabled() && !config.sack) return + fun onSackChange(event: SackChangeEvent) { + if (!isEnabled() || !config.sack) return event.sackChanges.forEach { val itemStack = (it.internalName.getItemStack()) - val item = UpdatedItem(itemStack.displayName, it.delta.absoluteValue) + val item = UpdatedItem(itemStack.displayName, it.delta.absoluteValue.toLong(), it.internalName) updateItem(itemStack.hash(), item, itemStack, it.delta < 0) } } + @SubscribeEvent + fun onPurseChange(event: PurseChangeEvent) { + if (!isEnabled() || !config.coins || !worldChangeCooldown()) return + + updateItem(0, UpdatedItem("§6Coins", event.coins.absoluteValue.toLong(), coinIcon), coinIcon.getItemStack(), event.coins < 0) + } + @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (!isEnabled()) return @@ -102,26 +116,26 @@ object ItemPickupLog { } } - if (LorenzUtils.lastWorldSwitch.passedSince() < 2.seconds) return + if (!worldChangeCooldown()) return oldItemList.forEach { if (!itemList.containsKey(it.key)) { - val item = UpdatedItem(it.value.first.displayName, it.value.second) + val item = UpdatedItem(it.value.first.displayName, it.value.second.toLong(), it.value.first.getInternalNameOrNull()) updateItem(it.key, item, it.value.first, true) } else if (it.value.second > itemList[it.key]!!.second) { val amount = (it.value.second - itemList[it.key]?.second!!) - val item = UpdatedItem(it.value.first.displayName, amount) + val item = UpdatedItem(it.value.first.displayName, amount.toLong(), it.value.first.getInternalNameOrNull()) updateItem(it.key, item, it.value.first, true) } } itemList.forEach { if (!oldItemList.containsKey(it.key)) { - val item = UpdatedItem(it.value.first.displayName, it.value.second) + val item = UpdatedItem(it.value.first.displayName, it.value.second.toLong(), it.value.first.getInternalNameOrNull()) updateItem(it.key, item, it.value.first, false) } else if (it.value.second > oldItemList[it.key]!!.second) { val amount = (it.value.second - oldItemList[it.key]?.second!!) - val item = UpdatedItem(it.value.first.displayName, amount) + val item = UpdatedItem(it.value.first.displayName, amount.toLong(), it.value.first.getInternalNameOrNull()) updateItem(it.key, item, it.value.first, false) } } @@ -185,10 +199,10 @@ object ItemPickupLog { } } - private data class UpdatedItem(val name: String, var amount: Int) { + private data class UpdatedItem(val name: String, var amount: Long, val neuInternalName: NEUInternalName?) { var time = SimpleTimeMark.now() - fun updateAmount(change: Int) { + fun updateAmount(change: Long) { amount += change time = SimpleTimeMark.now() } @@ -198,15 +212,16 @@ object ItemPickupLog { private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled - private fun renderList(prefix: String, amount: Int, name: String): Renderable { + private fun renderList(prefix: String, amount: Long, name: String, itemIcon: NEUInternalName?): Renderable { return if (config.showItemIcon) { Renderable.horizontalContainer( buildList { - add(Renderable.string("${prefix}${amount.addSeparators()}")) - ItemNameResolver.getInternalNameOrNull(name)?.let { - addItemStack( - it, - ) + val formattedAmount = if (config.shorten) amount.shortFormat() else amount.addSeparators() + add(Renderable.string("${prefix}${formattedAmount}")) + if (itemIcon != null) { + addItemStack(itemIcon) + } else { + ItemNameResolver.getInternalNameOrNull(name)?.let { addItemStack(it) } } add(Renderable.string(name)) }, @@ -216,10 +231,14 @@ object ItemPickupLog { } } + private fun worldChangeCooldown(): Boolean { + return LorenzUtils.lastWorldSwitch.passedSince() > 2.seconds + } + private fun updateDisplay() { if (!isEnabled()) return - display.clear() + val display = mutableListOf() itemsAddedToInventory.values.removeIf { it.isExpired() } itemsRemovedFromInventory.values.removeIf { it.isExpired() } @@ -238,9 +257,9 @@ object ItemPickupLog { val currentTotalValue = item.value.amount - it.amount if (currentTotalValue > 0) { - display.add(renderList("§a+", currentTotalValue, item.value.name)) + display.add(renderList("§a+", currentTotalValue, item.value.name, item.value.neuInternalName)) } else if (currentTotalValue < 0) { - display.add(renderList("§c", currentTotalValue, item.value.name)) + display.add(renderList("§c", currentTotalValue, item.value.name, item.value.neuInternalName)) } else { itemsAddedToInventory.remove(item.key) itemsRemovedFromInventory.remove(item.key) @@ -249,21 +268,33 @@ object ItemPickupLog { iterator.remove() } } else { - display.add(renderList("§a+", item.value.amount, item.value.name)) + display.add(renderList("§a+", item.value.amount, item.value.name, item.value.neuInternalName)) } } } else { for (item in addedItemsToNoLongerShow) { - display.add(renderList("§a+", item.value.amount, item.value.name)) + display.add(renderList("§a+", item.value.amount, item.value.name, item.value.neuInternalName)) removedItemsToNoLongerShow[item.key]?.let { - display.add(renderList("§c-", it.amount, it.name)) + display.add(renderList("§c-", it.amount, it.name, it.neuInternalName)) removedItemsToNoLongerShow.remove(item.key) } } } for (item in removedItemsToNoLongerShow) { - display.add(renderList("§c-", item.value.amount, item.value.name)) + display.add(renderList("§c-", item.value.amount, item.value.name, item.value.neuInternalName)) + } + val renderable = Renderable.verticalContainer(display, verticalAlign = config.alignment) + this.display = object : Renderable { + override val width: Int = renderable.width + override val height: Int = renderable.height + override val horizontalAlign: RenderUtils.HorizontalAlignment = renderable.horizontalAlign + override val verticalAlign: RenderUtils.VerticalAlignment = renderable.verticalAlign + + override fun render(posX: Int, posY: Int) { + renderable.renderXYAligned(posX, posY, 0, 0) + } + } } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index 1f389e51b766..5a55c2f4e43f 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -639,7 +639,7 @@ object RenderUtils { renderable.render(0, 0) } GlStateManager.popMatrix() - if (addToGuiManager) GuiEditManager.add(this, posLabel, renderable.width, 0) + if (addToGuiManager) GuiEditManager.add(this, posLabel, renderable.width, renderable.height) } /**