From d185886d492c33a10e77f2e0dc488343393fb162 Mon Sep 17 00:00:00 2001 From: Regisle Date: Sat, 7 Sep 2024 19:22:25 +0930 Subject: [PATCH] Reduced Precision Number Display --- src/Modules/Build.lua | 4 ++++ src/Modules/Common.lua | 17 ++++++++++++++++- src/Modules/Main.lua | 12 ++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Modules/Build.lua b/src/Modules/Build.lua index 87cfb0d0d9..7af969f857 100644 --- a/src/Modules/Build.lua +++ b/src/Modules/Build.lua @@ -1104,6 +1104,9 @@ function buildMode:OnFrame(inputEvents) if main.thousandsSeparator ~= self.lastShowThousandsSeparator then self:RefreshStatList() end + if main.lowerPrecisionDisplay ~= self.lastLowerPrecisionDisplay then + self:RefreshStatList() + end if main.decimalSeparator ~= self.lastShowDecimalSeparator then self:RefreshStatList() end @@ -1464,6 +1467,7 @@ function buildMode:FormatStat(statData, statVal, overCapStatVal, colorOverride) end self.lastShowThousandsSeparators = main.showThousandsSeparators self.lastShowThousandsSeparator = main.thousandsSeparator + self.lastLowerPrecisionDisplay = main.lowerPrecisionDisplay self.lastShowDecimalSeparator = main.decimalSeparator self.lastShowTitlebarName = main.showTitlebarName return valStr diff --git a/src/Modules/Common.lua b/src/Modules/Common.lua index 270e653d95..236b36131a 100644 --- a/src/Modules/Common.lua +++ b/src/Modules/Common.lua @@ -656,7 +656,22 @@ function formatNumSep(str) return m end local x, y, minus, integer, fraction = str:find("(-?)(%d+)(%.?%d*)") - if main.showThousandsSeparators then + if main.lowerPrecisionDisplay and #integer > 3 then + if fraction == "" then + fraction = "."..integer:sub(-2) + else + fraction = "."..integer:sub(-#(fraction or " ") + 1) + end + if #integer > 12 then + return colour..minus..integer:sub(1, #integer - 12)..fraction:gsub("%.", main.decimalSeparator).." T" + elseif #integer > 9 then + return colour..minus..integer:sub(1, #integer - 9)..fraction:gsub("%.", main.decimalSeparator).." B" + elseif #integer > 6 then + return colour..minus..integer:sub(1, #integer - 6)..fraction:gsub("%.", main.decimalSeparator).." M" + else + return colour..minus..integer:sub(1, #integer - 3)..fraction:gsub("%.", main.decimalSeparator).." k" + end + elseif main.showThousandsSeparators then integer = integer:reverse():gsub("(%d%d%d)", "%1"..main.thousandsSeparator):reverse() -- There will be leading separators if the number of digits are divisible by 3 -- This checks for their presence and removes them diff --git a/src/Modules/Main.lua b/src/Modules/Main.lua index a3c93a0bea..838622bc6e 100644 --- a/src/Modules/Main.lua +++ b/src/Modules/Main.lua @@ -96,6 +96,7 @@ function main:Init() self.showThousandsSeparators = true self.edgeSearchHighlight = true self.thousandsSeparator = "," + self.lowerPrecisionDisplay = false self.decimalSeparator = "." self.defaultItemAffixQuality = 0.5 self.showTitlebarName = true @@ -575,6 +576,9 @@ function main:LoadSettings(ignoreBuild) if node.attrib.thousandsSeparator then self.thousandsSeparator = node.attrib.thousandsSeparator end + if node.attrib.lowerPrecisionDisplay then + self.lowerPrecisionDisplay = node.attrib.lowerPrecisionDisplay == "true" + end if node.attrib.decimalSeparator then self.decimalSeparator = node.attrib.decimalSeparator end @@ -714,6 +718,7 @@ function main:SaveSettings() colorHighlight = self.colorHighlight, showThousandsSeparators = tostring(self.showThousandsSeparators), thousandsSeparator = self.thousandsSeparator, + lowerPrecisionDisplay = tostring(self.lowerPrecisionDisplay), decimalSeparator = self.decimalSeparator, showTitlebarName = tostring(self.showTitlebarName), betaTest = tostring(self.betaTest), @@ -921,6 +926,12 @@ function main:OpenOptionsPopup() end) controls.thousandsSeparatorLabel = new("LabelControl", { "RIGHT", controls.thousandsSeparator, "LEFT" }, { defaultLabelSpacingPx, 0, 92, 16 }, "^7Thousands separator:") + nextRow() + controls.lowerPrecisionDisplay = new("CheckBoxControl", { "TOPLEFT", nil, "TOPLEFT"}, { defaultLabelPlacementX, currentY, 20 }, "^7Reduce Display Precision:", function(state) + self.lowerPrecisionDisplay = state + end) + controls.lowerPrecisionDisplay.state = self.lowerPrecisionDisplay + nextRow() controls.decimalSeparator = new("EditControl", { "TOPLEFT", nil, "TOPLEFT" }, { defaultLabelPlacementX, currentY, 30, 20 }, self.decimalSeparator, nil, "%w", 1, function(buf) self.decimalSeparator = buf @@ -995,6 +1006,7 @@ function main:OpenOptionsPopup() local initialThousandsSeparatorDisplay = self.showThousandsSeparators local initialTitlebarName = self.showTitlebarName local initialThousandsSeparator = self.thousandsSeparator + local initialLowerPrecisionDisplay = self.lowerPrecisionDisplay local initialDecimalSeparator = self.decimalSeparator local initialBetaTest = self.betaTest local initialEdgeSearchHighlight = self.edgeSearchHighlight