From 3fd0e2bf09c5de630df610786e2e4c58f8cccd24 Mon Sep 17 00:00:00 2001 From: HiZe_ Date: Wed, 11 Oct 2023 10:24:32 +0200 Subject: Update: Sack Display (#550) Added button to change Price and Number format #550 --- .../java/at/hannibal2/skyhanni/data/SackAPI.kt | 6 ++-- .../skyhanni/features/inventory/SackDisplay.kt | 34 ++++++++++++++++++++-- 2 files changed, 34 insertions(+), 6 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt index 6ba933e40..64bebee7e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt @@ -84,8 +84,8 @@ object SackAPI { else null } - private fun NEUInternalName.sackPrice(stored: String): Long = when (sackDisplayConfig.priceFrom) { - 0 -> (getPrice(true) * stored.formatNumber()).toLong().let { if (it < 0) 0 else it } + private fun NEUInternalName.sackPrice(stored: String) = when (sackDisplayConfig.priceFrom) { + 0 -> (getPrice(true) * stored.formatNumber()).toLong().let { if (it < 0) 0L else it } 1 -> try { val npcPrice = getNpcPriceOrNull() ?: 0.0 @@ -94,7 +94,7 @@ object SackAPI { 0L } - else -> 0 + else -> 0L } fun getSacksData(savingSacks: Boolean) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt index 92c60bad5..0b8231879 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.features.bazaar.BazaarApi 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.addSelector import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUItems.getItemStack @@ -98,9 +99,15 @@ object SackDisplay { config.sortingType = it.ordinal update(false) }) - + newDisplay.addButton( + prefix = "§7Number format: ", + getName = NumberFormat.entries[config.numberFormat].DisplayName, + onChange = { + config.numberFormat = (config.numberFormat + 1) % 3 + update(false) + } + ) if (config.showPrice) { - newDisplay.addAsSingletonList("§cTotal price: §6${format(totalPrice)}") newDisplay.addSelector(" ", getName = { type -> type.displayName }, isCurrent = { it.ordinal == config.priceFrom }, @@ -108,6 +115,15 @@ object SackDisplay { config.priceFrom = it.ordinal update(false) }) + newDisplay.addButton( + prefix = "§7Price Format: ", + getName = PriceFormat.entries[config.priceFormat].displayName, + onChange = { + config.priceFormat = (config.priceFormat + 1) % 2 + update(false) + } + ) + newDisplay.addAsSingletonList("§cTotal price: §6${format(totalPrice)}") } } @@ -135,7 +151,7 @@ object SackDisplay { BazaarApi.searchForBazaarItem(name.dropLast(1)) }) { !NEUItems.neuHasFocus() }) add(" ($rough-§a$flawed-§9$fine-§5$flawless)") - val price = (roughprice + flawedprice + fineprice + flawlessprice) + val price = roughprice + flawedprice + fineprice + flawlessprice totalPrice += price if (config.showPrice && price != 0L) add(" §7(§6${format(price)}§7)") }) @@ -162,4 +178,16 @@ object SackDisplay { NPC("Npc Price"), ; } + + enum class PriceFormat(val displayName: String) { + FORMATED("Formatted"), + UNFORMATED("Unformatted") + ; + } + + enum class NumberFormat(val DisplayName: String) { + DEFAULT("Default"), + FORMATTED("Formatted"), + UNFORMATTED("Unformatted") + } } \ No newline at end of file -- cgit