diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-06-14 15:56:08 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-06-14 15:56:08 +0200 |
commit | 34e2d19a32f36ddef298668788447aed01c62703 (patch) | |
tree | 65db564add674443a43bf65e71091e9d965f117a /src/main/java/at/hannibal2/skyhanni/utils | |
parent | a996d8150ef2367e7c839f3565d60bdb68d2125d (diff) | |
download | skyhanni-34e2d19a32f36ddef298668788447aed01c62703.tar.gz skyhanni-34e2d19a32f36ddef298668788447aed01c62703.tar.bz2 skyhanni-34e2d19a32f36ddef298668788447aed01c62703.zip |
fixing and using shortFormat()
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt | 16 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt | 9 |
2 files changed, 16 insertions, 9 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt index 742bc3654..1ee34699c 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt @@ -36,19 +36,25 @@ object NumberUtil { ) ) + @Deprecated("outdated", ReplaceWith("value.shortFormat(preciseBillions)")) + fun format(value: Number, preciseBillions: Boolean = false): String = value.shortFormat(preciseBillions) + + // 1234 -> 1.2k + fun Number.shortFormat(preciseBillions: Boolean = false): String { + return compactFormat(this, preciseBillions) + } + /** * This code was modified and taken under CC BY-SA 3.0 license * @link https://stackoverflow.com/a/30661479 * @author assylias */ - - @JvmStatic - fun format(value: Number, preciseBillions: Boolean = false): String { + private fun compactFormat(value: Number, preciseBillions: Boolean = false): String { @Suppress("NAME_SHADOWING") val value = value.toLong() // Long.MIN_VALUE == -Long.MIN_VALUE, so we need an adjustment here - if (value == Long.MIN_VALUE) return format(Long.MIN_VALUE + 1, preciseBillions) - if (value < 0) return "-" + format(-value, preciseBillions) + if (value == Long.MIN_VALUE) return compactFormat(Long.MIN_VALUE + 1, preciseBillions) + if (value < 0) return "-" + compactFormat(-value, preciseBillions) if (value < 1000) return value.toString() // deal with small numbers 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 57595c1c1..f7bafb7f3 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt @@ -13,8 +13,8 @@ import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector import at.hannibal2.skyhanni.utils.NEUInternalName -import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.renderables.Renderable import kotlin.time.Duration.Companion.seconds @@ -106,7 +106,7 @@ class SkyHanniItemTracker<Data : ItemTrackerData>( internalName.itemName } - val priceFormat = NumberUtil.format(price) + val priceFormat = price.shortFormat() val hidden = itemProfit.hidden val newDrop = itemProfit.lastTimeUpdated.passedSince() < 10.seconds && config.showRecentDrops val numberColor = if (newDrop) "§a§l" else "§7" @@ -127,7 +127,8 @@ class SkyHanniItemTracker<Data : ItemTrackerData>( } val lore = buildLore(data, itemProfit, hidden, newDrop, internalName) - val renderable = if (isInventoryOpen()) Renderable.clickAndHover(displayName, lore, + val renderable = if (isInventoryOpen()) Renderable.clickAndHover( + displayName, lore, onClick = { if (KeyboardManager.isModifierKeyDown()) { data.items.remove(internalName) @@ -183,7 +184,7 @@ class SkyHanniItemTracker<Data : ItemTrackerData>( val tips = if (totalAmount > 0) { val profitPerCatch = profit / totalAmount - val profitPerCatchFormat = NumberUtil.format(profitPerCatch) + val profitPerCatchFormat = profitPerCatch.shortFormat() listOf("§7Profit per $action: $profitPrefix$profitPerCatchFormat") } else emptyList() |