Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduced Precision Number Display #8291

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Modules/Build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,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
Expand Down Expand Up @@ -1678,6 +1681,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
Expand Down
17 changes: 16 additions & 1 deletion src/Modules/Common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/Modules/Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -920,6 +925,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
Expand Down Expand Up @@ -994,6 +1005,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
Expand Down
Loading