diff options
5 files changed, 60 insertions, 39 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/SkyMartConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/SkyMartConfig.java index 604166dc9..ccf3854f4 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/SkyMartConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/SkyMartConfig.java @@ -15,11 +15,6 @@ public class SkyMartConfig { public boolean copperPrice = false; @Expose - @ConfigOption(name = "Advanced Stats", desc = "Show the BIN price and copper price for every item.") - @ConfigEditorBoolean - public boolean copperPriceAdvancedStats = false; - - @Expose @ConfigOption(name = "Item Scale", desc = "Change the size of the items.") @ConfigEditorSlider(minValue = 0.3f, maxValue = 5, minStep = 0.1f) public double itemScale = 1.7; 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 c1df32a98..298717720 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt @@ -7,13 +7,14 @@ import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.DisplayTableEntry import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.fillTable import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getPrice @@ -55,7 +56,7 @@ class AnitaMedalProfit { inInventory = true - val table = mutableMapOf<Pair<String, String>, Pair<Double, NEUInternalName>>() + val table = mutableListOf<DisplayTableEntry>() for ((_, item) in event.inventoryItems) { try { readItem(item, table) @@ -71,11 +72,11 @@ class AnitaMedalProfit { val newList = mutableListOf<List<Any>>() newList.addAsSingletonList("§eMedal Profit") - LorenzUtils.fillTable(newList, table) + newList.fillTable(table) display = newList } - private fun readItem(item: ItemStack, table: MutableMap<Pair<String, String>, Pair<Double, NEUInternalName>>) { + private fun readItem(item: ItemStack, table: MutableList<DisplayTableEntry>) { val itemName = getItemName(item) ?: return if (itemName == " ") return if (itemName == "§cClose") return @@ -96,9 +97,18 @@ class AnitaMedalProfit { if (itemPrice < 0) return val profit = itemPrice - fullCost - val format = NumberUtil.format(profit) + val profitFormat = NumberUtil.format(profit) val color = if (profit > 0) "§6" else "§c" - table[Pair(itemName, "$color$format")] = Pair(profit, internalName) + + val hover = listOf( + itemName, + "", + "§7Item price: §6${NumberUtil.format(itemPrice)} ", + // TODO add more exact material cost breakdown + "§7Material cost: §6${NumberUtil.format(fullCost)} ", + "§7Final profit: §6${profitFormat} ", + ) + table.add(DisplayTableEntry(itemName, "$color$profitFormat", profit, internalName, hover)) } 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 d27401e44..f9dd5b8a7 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 @@ -6,14 +6,16 @@ import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.DisplayTableEntry import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.itemName -import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.fillTable import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher @@ -61,36 +63,43 @@ class SkyMartCopperPrice { if (event.inventoryName != "SkyMart") return inInventory = true - val table = mutableMapOf<Pair<String, String>, Pair<Double, NEUInternalName>>() + val table = mutableListOf<DisplayTableEntry>() for (stack in event.inventoryItems.values) { val lore = stack.getLore() - val otherItemsPrice = stack.loreCosts().sumOf { it.getPrice() } + val otherItemsPrice = stack.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 lowestBin = internalName.getPriceOrNull() ?: continue - val profit = lowestBin - otherItemsPrice + val profit = lowestBin - (otherItemsPrice ?: 0.0) - val amount = copperPattern.matchMatcher(line) { - group("amount").formatInt() - } ?: continue - val factor = profit / amount + val factor = profit / copper val perFormat = NumberUtil.format(factor) - val priceFormat = NumberUtil.format(profit) - val amountFormat = NumberUtil.format(amount) - - val name = stack.itemName - val advancedStats = if (config.copperPriceAdvancedStats) { - " §7(§6$priceFormat §7/ §c$amountFormat Copper§7)" - } else "" - val pair = Pair("$name§f:", "§6§l$perFormat$advancedStats") - table[pair] = Pair(factor, internalName) + + val itemName = stack.itemName + val hover = buildList { + add(itemName) + add("") + add("§7Item price: §6${NumberUtil.format(lowestBin)} ") + otherItemsPrice?.let { + add("§7Additional cost: §6${NumberUtil.format(it)} ") + } + add("§7Profit per purchase: §6${NumberUtil.format(profit)} ") + add("") + add("§7Copper amount: §c${copper.addSeparators()} ") + add("§7Profit per copper: §6${perFormat} ") + } + table.add(DisplayTableEntry("$itemName§f:", "§6§l$perFormat", factor, internalName, hover)) } } val newList = mutableListOf<List<Any>>() newList.addAsSingletonList("§eCoins per Copper§f:") - LorenzUtils.fillTable(newList, table) + newList.fillTable(table) display = newList } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/DisplayTableEntry.kt b/src/main/java/at/hannibal2/skyhanni/utils/DisplayTableEntry.kt new file mode 100644 index 000000000..d78a32f31 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/DisplayTableEntry.kt @@ -0,0 +1,9 @@ +package at.hannibal2.skyhanni.utils + +class DisplayTableEntry( + val left: String, + val right: String, + val sort: Double, + val item: NEUInternalName, + val hover: List<String>, +) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 7df997f0d..a2788a6fa 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -10,7 +10,6 @@ import at.hannibal2.skyhanni.features.dungeon.DungeonAPI import at.hannibal2.skyhanni.mixins.transformers.AccessorGuiEditSign import at.hannibal2.skyhanni.test.TestBingo import at.hannibal2.skyhanni.utils.ChatUtils.lastButtonClicked -import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators @@ -157,21 +156,20 @@ object LorenzUtils { fun getPlayerName(): String = Minecraft.getMinecraft().thePlayer.name - // (key -> value) -> (sorting value -> key item icon) - fun fillTable(list: MutableList<List<Any>>, data: MutableMap<Pair<String, String>, Pair<Double, NEUInternalName>>) { - val keys = data.mapValues { (_, v) -> v.first }.sortedDesc().keys + fun MutableList<List<Any>>.fillTable(data: List<DisplayTableEntry>) { + val sorted = data.sortedByDescending { it.sort } val renderer = Minecraft.getMinecraft().fontRendererObj - val longest = keys.map { it.first }.maxOfOrNull { renderer.getStringWidth(it.removeColor()) } ?: 0 + val longest = sorted.maxOfOrNull { renderer.getStringWidth(it.left.removeColor()) } ?: 0 - for (pair in keys) { - val (name, second) = pair - var displayName = name + for (entry in sorted) { + var displayName = entry.left while (renderer.getStringWidth(displayName.removeColor()) < longest) { displayName += " " } - data[pair]!!.second.getItemStackOrNull()?.let { - list.add(listOf(it, "$displayName $second")) + val hover = entry.hover + entry.item.getItemStackOrNull()?.let { + add(listOf(it, Renderable.hoverTips("$displayName ${entry.right}", tips = hover))) } } } |