From b9c0aaa585a913d5c139c8e5aa7437925b1acfa2 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Thu, 4 Apr 2024 20:31:39 +0200 Subject: Improvement: Anita and SkyMart highlight (#1118) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 ++ .../features/inventory/ChestValueConfig.java | 6 ---- .../skyhanni/data/HighlightOnHoverSlot.kt | 36 ++++++++++++++++++++++ .../skyhanni/features/garden/AnitaMedalProfit.kt | 8 ++--- .../garden/inventory/SkyMartCopperPrice.kt | 12 ++++---- .../skyhanni/features/inventory/ChestValue.kt | 25 ++------------- .../rift/everywhere/motes/ShowMotesNpcSellPrice.kt | 21 +------------ .../hannibal2/skyhanni/utils/DisplayTableEntry.kt | 3 +- .../at/hannibal2/skyhanni/utils/LorenzUtils.kt | 8 +++-- .../skyhanni/utils/renderables/Renderable.kt | 13 ++++---- 10 files changed, 65 insertions(+), 69 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/data/HighlightOnHoverSlot.kt (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index f322f0424..31ebf5420 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -27,6 +27,7 @@ import at.hannibal2.skyhanni.data.GardenCropMilestonesCommunityFix import at.hannibal2.skyhanni.data.GardenCropUpgrades import at.hannibal2.skyhanni.data.GuiEditManager import at.hannibal2.skyhanni.data.GuildAPI +import at.hannibal2.skyhanni.data.HighlightOnHoverSlot import at.hannibal2.skyhanni.data.HypixelData import at.hannibal2.skyhanni.data.ItemAddManager import at.hannibal2.skyhanni.data.ItemClickData @@ -505,6 +506,7 @@ class SkyHanniMod { loadModule(DataWatcherAPI()) loadModule(CollectionAPI) loadModule(FarmingContestAPI) + loadModule(HighlightOnHoverSlot) loadModule(FriendAPI) loadModule(PartyAPI) loadModule(GuildAPI) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/ChestValueConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/ChestValueConfig.java index d3924f458..6b03a442a 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/ChestValueConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/ChestValueConfig.java @@ -5,7 +5,6 @@ import at.hannibal2.skyhanni.config.HasLegacyId; import at.hannibal2.skyhanni.config.core.config.Position; import com.google.gson.annotations.Expose; import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; -import io.github.moulberry.moulconfig.annotations.ConfigEditorColour; import io.github.moulberry.moulconfig.annotations.ConfigEditorDropdown; import io.github.moulberry.moulconfig.annotations.ConfigEditorSlider; import io.github.moulberry.moulconfig.annotations.ConfigOption; @@ -48,11 +47,6 @@ public class ChestValueConfig { @FeatureToggle public boolean enableHighlight = true; - @Expose - @ConfigOption(name = "Highlight Color", desc = "Choose the highlight color.") - @ConfigEditorColour - public String highlightColor = "0:249:0:255:88"; - @Expose @ConfigOption(name = "Sorting Type", desc = "Price sorting type.") @ConfigEditorDropdown diff --git a/src/main/java/at/hannibal2/skyhanni/data/HighlightOnHoverSlot.kt b/src/main/java/at/hannibal2/skyhanni/data/HighlightOnHoverSlot.kt new file mode 100644 index 000000000..9e99fdbae --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/HighlightOnHoverSlot.kt @@ -0,0 +1,36 @@ +package at.hannibal2.skyhanni.data + +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryOpenEvent +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RenderUtils.highlight +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +object HighlightOnHoverSlot { + val currentSlots = mutableMapOf, List>() + + @SubscribeEvent + fun onInventoryOpen(event: InventoryOpenEvent) { + currentSlots.clear() + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + currentSlots.clear() + } + + @SubscribeEvent(priority = EventPriority.LOW) + fun onDrawBackground(event: GuiContainerEvent.BackgroundDrawnEvent) { + if (!LorenzUtils.inSkyBlock) return + val list = currentSlots.flatMapTo(mutableSetOf()) { it.value } + for (slot in InventoryUtils.getItemsInOpenChest()) { + if (slot.slotNumber in list) { + slot highlight LorenzColor.GREEN + } + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt index 298717720..84ca5b235 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt @@ -57,9 +57,9 @@ class AnitaMedalProfit { inInventory = true val table = mutableListOf() - for ((_, item) in event.inventoryItems) { + for ((slot, item) in event.inventoryItems) { try { - readItem(item, table) + readItem(slot, item, table) } catch (e: Throwable) { ErrorManager.logErrorWithData( e, "Error in AnitaMedalProfit while reading item '${item.itemName}'", @@ -76,7 +76,7 @@ class AnitaMedalProfit { display = newList } - private fun readItem(item: ItemStack, table: MutableList) { + private fun readItem(slot: Int, item: ItemStack, table: MutableList) { val itemName = getItemName(item) ?: return if (itemName == " ") return if (itemName == "§cClose") return @@ -108,7 +108,7 @@ class AnitaMedalProfit { "§7Material cost: §6${NumberUtil.format(fullCost)} ", "§7Final profit: §6${profitFormat} ", ) - table.add(DisplayTableEntry(itemName, "$color$profitFormat", profit, internalName, hover)) + table.add(DisplayTableEntry(itemName, "$color$profitFormat", profit, internalName, hover, highlightsOnHoverSlots = listOf(slot))) } private fun getItemName(item: ItemStack): String? { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt index 69c551d74..9e5ec780c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt @@ -64,23 +64,23 @@ class SkyMartCopperPrice { inInventory = true val table = mutableListOf() - for (stack in event.inventoryItems.values) { - val lore = stack.getLore() - val otherItemsPrice = stack.loreCosts().sumOf { it.getPrice() }.takeIf { it != -1.0 } + for ((slot, item) in event.inventoryItems) { + val lore = item.getLore() + val otherItemsPrice = item.loreCosts().sumOf { it.getPrice() }.takeIf { it != -1.0 } for (line in lore) { val copper = copperPattern.matchMatcher(line) { group("amount").formatInt() } ?: continue - val internalName = stack.getInternalName() + val internalName = item.getInternalName() val lowestBin = internalName.getPriceOrNull() ?: continue val profit = lowestBin - (otherItemsPrice ?: 0.0) val factor = profit / copper val perFormat = NumberUtil.format(factor) - val itemName = stack.itemName + val itemName = item.itemName val hover = buildList { add(itemName) add("") @@ -93,7 +93,7 @@ class SkyMartCopperPrice { add("§7Copper amount: §c${copper.addSeparators()} ") add("§7Profit per copper: §6${perFormat} ") } - table.add(DisplayTableEntry("$itemName§f:", "§6§l$perFormat", factor, internalName, hover)) + table.add(DisplayTableEntry("$itemName§f:", "§6§l$perFormat", factor, internalName, hover, highlightsOnHoverSlots = listOf(slot))) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/ChestValue.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/ChestValue.kt index 381f46dca..f0b1418ba 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/ChestValue.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ChestValue.kt @@ -5,7 +5,6 @@ import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.config.features.inventory.ChestValueConfig.NumberFormatEntry import at.hannibal2.skyhanni.config.features.inventory.ChestValueConfig.SortingTypeEntry import at.hannibal2.skyhanni.data.IslandType -import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryOpenEvent @@ -23,18 +22,14 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems -import at.hannibal2.skyhanni.utils.SpecialColour import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.renderables.Renderable import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.init.Items import net.minecraft.item.ItemStack -import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.awt.Color class ChestValue { @@ -82,22 +77,6 @@ class ChestValue { @SubscribeEvent fun onInventoryClose(event: InventoryCloseEvent) { chestItems.clear() - Renderable.list.clear() - } - - @SubscribeEvent(priority = EventPriority.LOW) - fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { - if (!isEnabled()) return - if (!config.enableHighlight) return - if (inInventory) { - for ((_, indexes) in Renderable.list) { - for (slot in InventoryUtils.getItemsInOpenChest()) { - if (indexes.contains(slot.slotIndex)) { - slot highlight Color(SpecialColour.specialToChromaRGB(config.highlightColor), true) - } - } - } - } } private fun update() { @@ -141,7 +120,7 @@ class ChestValue { text, tips, stack = stack, - indexes = index + highlightsOnHoverSlots = if (config.enableHighlight) index else emptyList() ) add(" §7- ") if (config.showStacks) add(stack) @@ -156,7 +135,7 @@ class ChestValue { SortingTypeEntry.DESCENDING -> chestItems.values.sortedByDescending { it.total } SortingTypeEntry.ASCENDING -> chestItems.values.sortedBy { it.total } else -> chestItems.values.sortedByDescending { it.total } - }.toMutableList() + } private fun addButton(newDisplay: MutableList>) { newDisplay.addButton("§7Sorted By: ", diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/ShowMotesNpcSellPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/ShowMotesNpcSellPrice.kt index 98649093d..88269a643 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/ShowMotesNpcSellPrice.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/ShowMotesNpcSellPrice.kt @@ -2,7 +2,6 @@ package at.hannibal2.skyhanni.features.rift.everywhere.motes import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.config.features.rift.motes.RiftInventoryValueConfig.NumberFormatEntry -import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent @@ -16,18 +15,15 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.ConfigUtils import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector import at.hannibal2.skyhanni.utils.NEUInternalName 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.RenderUtils.highlight import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.renderables.Renderable import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern -import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class ShowMotesNpcSellPrice { @@ -63,20 +59,6 @@ class ShowMotesNpcSellPrice { processItems() } - @SubscribeEvent(priority = EventPriority.LOW) - fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { - if (!isInventoryValueEnabled()) return - val name = InventoryUtils.openInventoryName() - if (!name.contains("Rift Storage")) return - for ((_, indexes) in Renderable.list) { - for (slot in InventoryUtils.getItemsInOpenChest()) { - if (indexes.contains(slot.slotIndex)) { - slot highlight LorenzColor.GREEN - } - } - } - } - @SubscribeEvent fun onTooltip(event: LorenzToolTipEvent) { if (!isShowPriceEnabled()) return @@ -109,7 +91,6 @@ class ShowMotesNpcSellPrice { itemMap.clear() slotList.clear() inInventory = false - Renderable.list.clear() } private fun processItems() { @@ -165,7 +146,7 @@ class ShowMotesNpcSellPrice { add("") add("§6Total value: §d$price coins") } - add(Renderable.hoverTips("§6${stack.displayName}: §b$price", tips, indexes = index, stack = stack)) + add(Renderable.hoverTips("§6${stack.displayName}: §b$price", tips, highlightsOnHoverSlots = index, stack = stack)) }) } val total = itemMap.values.fold(0.0) { acc, pair -> acc + pair.second }.formatPrice() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/DisplayTableEntry.kt b/src/main/java/at/hannibal2/skyhanni/utils/DisplayTableEntry.kt index d78a32f31..be190e92c 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/DisplayTableEntry.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/DisplayTableEntry.kt @@ -5,5 +5,6 @@ class DisplayTableEntry( val right: String, val sort: Double, val item: NEUInternalName, - val hover: List, + val hover: List = emptyList(), + val highlightsOnHoverSlots: List = emptyList(), ) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 861530a58..740c6acaf 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -186,9 +186,13 @@ object LorenzUtils { displayName += " " } - val hover = entry.hover + val renderable = Renderable.hoverTips( + "$displayName ${entry.right}", + tips = entry.hover, + highlightsOnHoverSlots = entry.highlightsOnHoverSlots + ) entry.item.getItemStackOrNull()?.let { - add(listOf(it, Renderable.hoverTips("$displayName ${entry.right}", tips = hover))) + add(listOf(it, renderable)) } } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt index 30b595186..410a00cc8 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.utils.renderables import at.hannibal2.skyhanni.config.core.config.gui.GuiPositionEditor import at.hannibal2.skyhanni.config.features.skillprogress.SkillProgressBarConfig +import at.hannibal2.skyhanni.data.HighlightOnHoverSlot import at.hannibal2.skyhanni.data.ToolTipData import at.hannibal2.skyhanni.features.chroma.ChromaShaderManager import at.hannibal2.skyhanni.features.chroma.ChromaType @@ -48,7 +49,6 @@ interface Renderable { companion object { val logger = LorenzLogger("debug/renderable") - val list = mutableMapOf, List>() var currentRenderPassMousePosition: Pair? = null set @@ -142,7 +142,7 @@ interface Renderable { fun hoverTips( content: Any, tips: List, - indexes: List = listOf(), + highlightsOnHoverSlots: List = listOf(), stack: ItemStack? = null, color: LorenzColor? = null, bypassChecks: Boolean = false, @@ -162,10 +162,11 @@ interface Renderable { override fun render(posX: Int, posY: Int) { render.render(posX, posY) + val pair = Pair(posX, posY) if (isHovered(posX, posY)) { if (condition() && shouldAllowLink(true, bypassChecks)) { onHover.invoke() - list[Pair(posX, posY)] = indexes + HighlightOnHoverSlot.currentSlots[pair] = highlightsOnHoverSlots GlStateManager.pushMatrix() GlStateManager.translate(0F, 0F, 400F) @@ -182,9 +183,7 @@ interface Renderable { GlStateManager.popMatrix() } } else { - if (list.contains(Pair(posX, posY))) { - list.remove(Pair(posX, posY)) - } + HighlightOnHoverSlot.currentSlots.remove(pair) } } } @@ -375,7 +374,7 @@ interface Renderable { width: Int = 182, height: Int = 5, horizontalAlign: HorizontalAlignment = HorizontalAlignment.LEFT, - verticalAlign: VerticalAlignment = VerticalAlignment.TOP + verticalAlign: VerticalAlignment = VerticalAlignment.TOP, ) = object : Renderable { override val width = width override val height = height -- cgit