Merge pull request #2207 from Leftn/dev
Added customisation options for decimal and thousands separators
This commit is contained in:
@@ -71,7 +71,7 @@ function CalcBreakdownClass:SetBreakdownData(displayData, pinned)
|
||||
section.width = 0
|
||||
for _, line in ipairs(section.lines) do
|
||||
local _, num = string.gsub(line, "%d%d%d%d", "") -- count how many commas will be added
|
||||
if main.showThousandsCalcs and num > 0 then
|
||||
if main.showThousandsSeparators and num > 0 then
|
||||
section.width = m_max(section.width, DrawStringWidth(section.textSize, "VAR", line) + 8 + (4 * num))
|
||||
else
|
||||
section.width = m_max(section.width, DrawStringWidth(section.textSize, "VAR", line) + 8)
|
||||
@@ -85,7 +85,7 @@ function CalcBreakdownClass:SetBreakdownData(displayData, pinned)
|
||||
for _, row in pairs(section.rowList) do
|
||||
if row[col.key] then
|
||||
local _, num = string.gsub(row[col.key], "%d%d%d%d", "") -- count how many commas will be added
|
||||
if main.showThousandsCalcs and num > 0 then
|
||||
if main.showThousandsSeparators and num > 0 then
|
||||
col.width = m_max(col.width or 0, DrawStringWidth(16, "VAR", col.label) + 6, DrawStringWidth(12, "VAR", row[col.key]) + 6 + (4 * num))
|
||||
else
|
||||
col.width = m_max(col.width or 0, DrawStringWidth(16, "VAR", col.label) + 6, DrawStringWidth(12, "VAR", row[col.key]) + 6)
|
||||
@@ -537,14 +537,12 @@ function CalcBreakdownClass:DrawBreakdownTable(viewPort, x, y, section)
|
||||
local _, alpha = string.gsub(row[col.key], "%a", " ") -- counts letters in the string
|
||||
local _, notes = string.gsub(row[col.key], " to ", " ") -- counts " to " in the string
|
||||
local _, paren = string.gsub(row[col.key], "%b()", " ") -- counts parenthesis in the string
|
||||
if main.showThousandsCalcs and (alpha == 0 or notes > 0 or paren > 0) and col.right then
|
||||
if (alpha == 0 or notes > 0 or paren > 0) and col.right then
|
||||
DrawString(col.x + col.width - 4, rowY + 1, "RIGHT_X", 12, "VAR", "^7"..formatNumSep(tostring(row[col.key])))
|
||||
elseif col.right then
|
||||
DrawString(col.x + col.width - 4, rowY + 1, "RIGHT_X", 12, "VAR", "^7"..row[col.key])
|
||||
elseif main.showThousandsCalcs and (alpha == 0 or notes > 0 or paren > 0) then
|
||||
elseif (alpha == 0 or notes > 0 or paren > 0) then
|
||||
DrawString(col.x, rowY + 1, "LEFT", 12, "VAR", "^7"..formatNumSep(tostring(row[col.key])))
|
||||
else
|
||||
DrawString(col.x, rowY + 1, "LEFT", 12, "VAR", "^7"..row[col.key])
|
||||
DrawString(col.x, rowY + 1, "LEFT", 12, "VAR", "^7"..tostring(row[col.key]))
|
||||
end
|
||||
local ttFunc = row[col.key.."Tooltip"]
|
||||
local ttNode = row[col.key.."Node"]
|
||||
@@ -675,11 +673,7 @@ function CalcBreakdownClass:Draw(viewPort)
|
||||
for i, line in ipairs(section.lines) do
|
||||
SetDrawColor(1, 1, 1)
|
||||
local _, dec = string.gsub(line, "%.%d%d.", " ") -- counts decimals with 2 or more digits
|
||||
if main.showThousandsCalcs and dec == 0 then
|
||||
DrawString(x + 4, lineY, "LEFT", section.textSize, "VAR", formatNumSep(line))
|
||||
else
|
||||
DrawString(x + 4, lineY, "LEFT", section.textSize, "VAR", line)
|
||||
end
|
||||
DrawString(x + 4, lineY, "LEFT", section.textSize, "VAR", formatNumSep(line))
|
||||
lineY = lineY + section.textSize
|
||||
end
|
||||
elseif section.type == "TABLE" then
|
||||
|
||||
@@ -156,11 +156,7 @@ function CalcSectionClass:UpdatePos()
|
||||
end
|
||||
|
||||
function CalcSectionClass:FormatVal(val, p)
|
||||
if main.showThousandsCalcs then
|
||||
return formatNumSep(tostring(round(val, p)))
|
||||
else
|
||||
return round(val, p)
|
||||
end
|
||||
return formatNumSep(tostring(round(val, p)))
|
||||
end
|
||||
|
||||
function CalcSectionClass:FormatStr(str, actor, colData)
|
||||
|
||||
@@ -661,9 +661,7 @@ function TreeTabClass:ShowPowerReport()
|
||||
local nodePower = (node.power.singleStat or 0) * ((displayStat.pc or displayStat.mod) and 100 or 1)
|
||||
local nodePowerStr = s_format("%"..displayStat.fmt, nodePower)
|
||||
|
||||
if main.showThousandsCalcs then
|
||||
nodePowerStr = formatNumSep(nodePowerStr)
|
||||
end
|
||||
nodePowerStr = formatNumSep(nodePowerStr)
|
||||
|
||||
if (nodePower > 0 and not displayStat.lowerIsBetter) or (nodePower < 0 and displayStat.lowerIsBetter) then
|
||||
nodePowerStr = colorCodes.POSITIVE .. nodePowerStr
|
||||
@@ -691,9 +689,7 @@ function TreeTabClass:ShowPowerReport()
|
||||
local nodePower = (node.power.singleStat or 0) * ((displayStat.pc or displayStat.mod) and 100 or 1)
|
||||
local nodePowerStr = s_format("%"..displayStat.fmt, nodePower)
|
||||
|
||||
if main.showThousandsCalcs then
|
||||
nodePowerStr = formatNumSep(nodePowerStr)
|
||||
end
|
||||
nodePowerStr = formatNumSep(nodePowerStr)
|
||||
|
||||
if (nodePower > 0 and not displayStat.lowerIsBetter) or (nodePower < 0 and displayStat.lowerIsBetter) then
|
||||
nodePowerStr = colorCodes.POSITIVE .. nodePowerStr
|
||||
|
||||
@@ -811,7 +811,13 @@ function buildMode:OnFrame(inputEvents)
|
||||
self.calcsTab:BuildOutput()
|
||||
self:RefreshStatList()
|
||||
end
|
||||
if main.showThousandsSidebar ~= self.lastShowThousandsSidebar then
|
||||
if main.showThousandsSeparators ~= self.lastShowThousandsSeparators then
|
||||
self:RefreshStatList()
|
||||
end
|
||||
if main.thousandsSeparator ~= self.lastShowThousandsSeparator then
|
||||
self:RefreshStatList()
|
||||
end
|
||||
if main.decimalSeparator ~= self.lastShowDecimalSeparator then
|
||||
self:RefreshStatList()
|
||||
end
|
||||
if main.showTitlebarName ~= self.lastShowTitlebarName then
|
||||
@@ -1094,12 +1100,12 @@ function buildMode:FormatStat(statData, statVal)
|
||||
local val = statVal * ((statData.pc or statData.mod) and 100 or 1) - (statData.mod and 100 or 0)
|
||||
local color = (statVal >= 0 and "^7" or colorCodes.NEGATIVE)
|
||||
local valStr = s_format("%"..statData.fmt, val)
|
||||
if main.showThousandsSidebar then
|
||||
valStr = color .. formatNumSep(valStr)
|
||||
else
|
||||
valStr = color .. valStr
|
||||
end
|
||||
self.lastShowThousandsSidebar = main.showThousandsSidebar
|
||||
valStr:gsub("%.", main.decimalSeparator)
|
||||
valStr = color .. formatNumSep(valStr)
|
||||
|
||||
self.lastShowThousandsSeparators = main.showThousandsSeparators
|
||||
self.lastShowThousandsSeparator = main.thousandsSeparator
|
||||
self.lastShowDecimalSeparator = main.decimalSeparator
|
||||
self.lastShowTitlebarName = main.showTitlebarName
|
||||
return valStr
|
||||
end
|
||||
@@ -1168,9 +1174,9 @@ function buildMode:CompareStatList(tooltip, statList, actor, baseOutput, compare
|
||||
local color = ((statData.lowerIsBetter and diff < 0) or (not statData.lowerIsBetter and diff > 0)) and colorCodes.POSITIVE or colorCodes.NEGATIVE
|
||||
local val = diff * ((statData.pc or statData.mod) and 100 or 1)
|
||||
local valStr = s_format("%+"..statData.fmt, val) -- Can't use self:FormatStat, because it doesn't have %+. Adding that would have complicated a simple function
|
||||
if main.showThousandsCalcs then
|
||||
valStr = formatNumSep(valStr)
|
||||
end
|
||||
|
||||
valStr = formatNumSep(valStr)
|
||||
|
||||
local line = string.format("%s%s %s", color, valStr, statData.label)
|
||||
local pcPerPt = ""
|
||||
if statData.compPercent and statVal1 ~= 0 and statVal2 ~= 0 then
|
||||
|
||||
@@ -484,10 +484,26 @@ end
|
||||
|
||||
-- Formats "1234.56" -> "1,234.5"
|
||||
function formatNumSep(str)
|
||||
return str:gsub("(%d*)(%d%.?)", function(s, e)
|
||||
return s:reverse():gsub("(%d%d)(%d)","%1,%2"):reverse()..e
|
||||
end)
|
||||
return string.gsub(str, "(-?%d+%.?%d+)", function(m)
|
||||
local x, y, minus, integer, fraction = m:find("(-?)(%d+)(%.?%d*)")
|
||||
if 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
|
||||
-- Don't use patterns here because thousandsSeparator can be a pattern control character, and will crash if used
|
||||
if main.thousandsSeparator ~= "" then
|
||||
local thousandsSeparator = string.find(integer, main.thousandsSeparator, 1, 2)
|
||||
if thousandsSeparator and thousandsSeparator == 1 then
|
||||
integer = integer:sub(2)
|
||||
end
|
||||
end
|
||||
else
|
||||
integer = integer:reverse():gsub("(%d%d%d)", "%1"):reverse()
|
||||
end
|
||||
return minus..integer..fraction:gsub("%.", main.decimalSeparator)
|
||||
end)
|
||||
end
|
||||
|
||||
function getFormatNumSep(dec)
|
||||
return function(val)
|
||||
return formatNumSep(val, dec)
|
||||
|
||||
@@ -199,8 +199,9 @@ the "Releases" section of the GitHub page.]])
|
||||
|
||||
self.buildSortMode = "NAME"
|
||||
self.nodePowerTheme = "RED/BLUE"
|
||||
self.showThousandsSidebar = true
|
||||
self.showThousandsCalcs = true
|
||||
self.showThousandsSeparators = true
|
||||
self.thousandsSeparator = ","
|
||||
self.decimalSeparator = "."
|
||||
self.showTitlebarName = true
|
||||
|
||||
local ignoreBuild = self:LoadPastebinBuild()
|
||||
@@ -482,12 +483,22 @@ function main:LoadSettings(ignoreBuild)
|
||||
if node.attrib.nodePowerTheme then
|
||||
self.nodePowerTheme = node.attrib.nodePowerTheme
|
||||
end
|
||||
if node.attrib.showThousandsSidebar then
|
||||
self.showThousandsSidebar = node.attrib.showThousandsSidebar == "true"
|
||||
end -- else leave at default
|
||||
-- In order to preserve users' settings through renameing/merging this variable, we have this if statement to use the first found setting
|
||||
-- Once the user has closed PoB once, they will be using the new `showThousandsSeparator` variable name, so after some time, this statement may be removed
|
||||
if node.attrib.showThousandsCalcs then
|
||||
self.showThousandsCalcs = node.attrib.showThousandsCalcs == "true"
|
||||
end -- else leave at default
|
||||
self.showThousandsSeparators = node.attrib.showThousandsCalcs == "true"
|
||||
elseif node.attrib.showThousandsSidebar then
|
||||
self.showThousandsSeparators = node.attrib.showThousandsSidebar == "true"
|
||||
end
|
||||
if node.attrib.showThousandsSeparators then
|
||||
self.showThousandsSeparators = node.attrib.showThousandsSeparators == "true"
|
||||
end
|
||||
if node.attrib.thousandsSeparator then
|
||||
self.thousandsSeparator = node.attrib.thousandsSeparator
|
||||
end
|
||||
if node.attrib.decimalSeparator then
|
||||
self.decimalSeparator = node.attrib.decimalSeparator
|
||||
end
|
||||
if node.attrib.showTitlebarName then
|
||||
self.showTitlebarName = node.attrib.showTitlebarName == "true"
|
||||
end
|
||||
@@ -533,8 +544,9 @@ function main:SaveSettings()
|
||||
proxyURL = launch.proxyURL,
|
||||
buildPath = (self.buildPath ~= self.defaultBuildPath and self.buildPath or nil),
|
||||
nodePowerTheme = self.nodePowerTheme,
|
||||
showThousandsSidebar = tostring(self.showThousandsSidebar),
|
||||
showThousandsCalcs = tostring(self.showThousandsCalcs),
|
||||
showThousandsSeparators = tostring(self.showThousandsSeparators),
|
||||
thousandsSeparator = self.thousandsSeparator,
|
||||
decimalSeparator = self.decimalSeparator,
|
||||
showTitlebarName = tostring(self.showTitlebarName),
|
||||
} })
|
||||
local res, errMsg = common.xml.SaveXMLFile(setXML, self.userPath.."Settings.xml")
|
||||
@@ -574,24 +586,32 @@ function main:OpenOptionsPopup()
|
||||
controls.nodePowerThemeLabel = new("LabelControl", {"RIGHT",controls.nodePowerTheme,"LEFT"}, -4, 0, 0, 16, "^7Node Power colours:")
|
||||
controls.nodePowerTheme.tooltipText = "Changes the colour scheme used for the node power display on the passive tree."
|
||||
controls.nodePowerTheme:SelByValue(self.nodePowerTheme, "theme")
|
||||
controls.thousandsLabel = new("LabelControl", {"TOPRIGHT",nil,"TOPLEFT"}, 210, 94, 0, 16, "^7Show thousands separators in:")
|
||||
controls.thousandsSidebar = new("CheckBoxControl", {"TOPLEFT",nil,"TOPLEFT"}, 280, 92, 20, "Sidebar:", function(state)
|
||||
self.showThousandsSidebar = state
|
||||
controls.separatorLabel = new("LabelControl", {"TOPRIGHT",nil,"TOPLEFT"}, 210, 94, 0, 16, "^7Show thousands separators:")
|
||||
controls.thousandsSeparators = new("CheckBoxControl", {"TOPLEFT",nil,"TOPLEFT"}, 280, 92, 20, nil, function(state)
|
||||
self.showThousandsSeparators = state
|
||||
end)
|
||||
controls.thousandsSidebar.state = self.showThousandsSidebar
|
||||
controls.thousandsCalcs = new("CheckBoxControl", {"TOPLEFT",nil,"TOPLEFT"}, 380, 92, 20, "Calcs tab:", function(state)
|
||||
self.showThousandsCalcs = state
|
||||
controls.thousandsSeparators.state = self.showThousandsSeparators
|
||||
|
||||
controls.thousandsSeparator = new("EditControl", {"TOPLEFT",nil,"TOPLEFT"}, 280, 116, 20, 20, self.thousandsSeparator, nil, "%%^", 1, function(buf)
|
||||
self.thousandsSeparator = buf
|
||||
end)
|
||||
controls.thousandsCalcs.state = self.showThousandsCalcs
|
||||
controls.titlebarName = new("CheckBoxControl", {"TOPLEFT",nil,"TOPLEFT"}, 230, 116, 20, "Show build name in window title:", function(state)
|
||||
controls.thousandsSeparatorLabel = new("LabelControl", {"TOPRIGHT",nil,"TOPLEFT"}, 210, 116, 92, 16, "Thousands Separator:")
|
||||
|
||||
controls.decimalSeparator = new("EditControl", {"TOPLEFT",nil,"TOPLEFT"}, 280, 138, 20, 20, self.decimalSeparator, nil, "%%^", 1, function(buf)
|
||||
self.decimalSeparator = buf
|
||||
end)
|
||||
controls.decimalSeparatorLabel = new("LabelControl", {"TOPRIGHT",nil,"TOPLEFT"}, 210, 138, 92, 16, "Decimal Separator:")
|
||||
|
||||
controls.titlebarName = new("CheckBoxControl", {"TOPLEFT",nil,"TOPLEFT"}, 230, 160, 20, "Show build name in window title:", function(state)
|
||||
self.showTitlebarName = state
|
||||
end)
|
||||
controls.titlebarName.state = self.showTitlebarName
|
||||
local initialNodePowerTheme = self.nodePowerTheme
|
||||
local initialThousandsSidebar = self.showThousandsSidebar
|
||||
local initialThousandsCalcs = self.showThousandsCalcs
|
||||
local initialThousandsSeparatorDisplay = self.showThousandsSeparators
|
||||
local initialTitlebarName = self.showTitlebarName
|
||||
controls.save = new("ButtonControl", nil, -45, 144, 80, 20, "Save", function()
|
||||
local initialThousandsSeparator = self.thousandsSeparator
|
||||
local initialDecimalSeparator = self.decimalSeparator
|
||||
controls.save = new("ButtonControl", nil, -45, 182, 80, 20, "Save", function()
|
||||
if controls.proxyURL.buf:match("%w") then
|
||||
launch.proxyURL = controls.proxyType.list[controls.proxyType.selIndex].scheme .. "://" .. controls.proxyURL.buf
|
||||
else
|
||||
@@ -610,14 +630,15 @@ function main:OpenOptionsPopup()
|
||||
end
|
||||
main:ClosePopup()
|
||||
end)
|
||||
controls.cancel = new("ButtonControl", nil, 45, 144, 80, 20, "Cancel", function()
|
||||
controls.cancel = new("ButtonControl", nil, 45, 182, 80, 20, "Cancel", function()
|
||||
self.nodePowerTheme = initialNodePowerTheme
|
||||
self.showThousandsSidebar = initialThousandsSidebar
|
||||
self.showThousandsCalcs = initialThousandsCalcs
|
||||
self.showThousandsSeparators = initialThousandsSeparatorDisplay
|
||||
self.thousandsSeparator = initialThousandsSeparator
|
||||
self.decimalSeparator = initialDecimalSeparator
|
||||
self.showTitlebarName = initialTitlebarName
|
||||
main:ClosePopup()
|
||||
end)
|
||||
self:OpenPopup(450, 174, "Options", controls, "save", nil, "cancel")
|
||||
self:OpenPopup(450, 218, "Options", controls, "save", nil, "cancel")
|
||||
end
|
||||
|
||||
function main:OpenUpdatePopup()
|
||||
@@ -952,4 +973,4 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
return main
|
||||
return main
|
||||
|
||||
Reference in New Issue
Block a user