Skip to content

Commit

Permalink
Formatting Changes
Browse files Browse the repository at this point in the history
More changes for the health formatting.
  • Loading branch information
Grimsbain committed Dec 4, 2024
1 parent e6a75ec commit 68ba0ff
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 68 deletions.
86 changes: 46 additions & 40 deletions Core/Functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,65 +54,71 @@ function nPlates:RGBToHex(r, g, b)
return RGBToColorCode(r, g, b)
end

local AbbreviateLargeNumbers = AbbreviateLargeNumbers
local AbbreviateNumbers = AbbreviateNumbers
local gameLocale = GetLocale()
if gameLocale == "koKR" or gameLocale == "zhCN" or gameLocale == "zhTW" then
-- Work around https://github.com/Stanzilla/WoWUIBugs/issues/515

local NUMBER_ABBREVIATION_DATA_FIXED={
[1]={
breakpoint = 10000 * 10000,
significandDivisor = 10000 * 10000,
abbreviation = SECOND_NUMBER_CAP_NO_SPACE,
fractionDivisor = 1
},
[2]={
breakpoint = 1000 * 10000,
significandDivisor = 1000 * 10000,
abbreviation = SECOND_NUMBER_CAP_NO_SPACE,
fractionDivisor = 10
},
[3]={
breakpoint = 10000,
significandDivisor = 1000,
abbreviation = FIRST_NUMBER_CAP_NO_SPACE,
fractionDivisor = 10
-- Work around https://github.com/Stanzilla/WoWUIBugs/issues/515

AbbreviateLargeNumbers = function(value)
local strLen = strlen(value);
local retString = value;
if ( strLen >= 11 ) then
retString = string.sub(value, 1, -8)..SECOND_NUMBER_CAP;
elseif ( strLen >= 9 ) then
retString = string.sub(value, 1, -9).."."..string.sub(value, -8, -7)..SECOND_NUMBER_CAP;
elseif ( strLen >= 7 ) then
retString = string.sub(value, 1, -5)..FIRST_NUMBER_CAP;
elseif (strLen > 3 ) then
retString = BreakUpLargeNumbers(value);
end
return retString;
end

local NUMBER_ABBREVIATION_DATA_FIXED = {
[1] = {
breakpoint = 10000 * 10000,
significandDivisor = 10000 * 10000,
abbreviation = SECOND_NUMBER_CAP_NO_SPACE,
fractionDivisor = 1
},
[2] = {
breakpoint = 1000 * 10000,
significandDivisor = 1000 * 10000,
abbreviation = SECOND_NUMBER_CAP_NO_SPACE,
fractionDivisor = 10
},
[3] = {
breakpoint = 10000,
significandDivisor = 1000,
abbreviation = FIRST_NUMBER_CAP_NO_SPACE,
fractionDivisor = 10
}
}
}

AbbreviateNumbers = function(value)
for i, data in ipairs(NUMBER_ABBREVIATION_DATA_FIXED) do
if value >= data.breakpoint then
local finalValue = math.floor(value / data.significandDivisor) / data.fractionDivisor;
return finalValue .. data.abbreviation;
if ( value >= data.breakpoint ) then
-- local finalValue = math.floor(value / data.significandDivisor) / data.fractionDivisor;
-- return finalValue .. data.abbreviation;
local finalValue = (value / data.significandDivisor) / data.fractionDivisor;
return string.format("%.2f %s", finalValue, data.abbreviation)
end
end

return tostring(value);
end
end

-- if ( number < 1e3 ) then
-- return math.floor(number)
-- elseif ( number >= 1e12 ) then
-- return string.format("%.3ft", number / 1e12)
-- elseif ( number >= 1e9 ) then
-- return string.format("%.3fb", number / 1e9)
-- elseif ( number >= 1e6 ) then
-- return string.format("%.2fm", number / 1e6)
-- elseif ( number >= 1e3 ) then
-- return string.format("%.1fk", number / 1e3)
-- end

function nPlates:FormatValue(number)
if type(number) == "string" then number = tonumber(number) end
function nPlates:FormatValue(value)
if type(value) == "string" then value = tonumber(value) end

local style = self:GetOption("FormattingStyle")

if ( style == "Short" ) then
return AbbreviateLargeNumbers(Round(number))
return AbbreviateLargeNumbers(value)
else
return AbbreviateNumbers(number)
return AbbreviateNumbers(value)
end
end

Expand Down
4 changes: 4 additions & 0 deletions Core/Localization.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ L.TankMode = "Tank Mode"
L.TankOptionsLabel = "Tank Options"
L.WhiteSelectionColor = "White Selection Color"

L.FormattingStyle = "Formatting Style"
L.AbbreviateNumbers = "Abbreviate Numbers"
L.AbbreviateLargeNumbers = "Abbreviate Large Numbers"

local CURRENT_LOCALE = GetLocale()
if CURRENT_LOCALE == "enUS" then return end

Expand Down
81 changes: 53 additions & 28 deletions Core/Settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ nPlates.defaultOptions = {
["ExecuteValue"] = 35,
["ExecuteColor"] = { r = 0, g = 71/255, b = 126/255},
["CurrentHealthOption"] = "HealthDisabled",
["FormattingStyle"] = "Short",
["HideFriendly"] = false,
["SmallStacking"] = false,
["DontClamp"] = false,
Expand All @@ -32,7 +33,7 @@ function nPlatesConfigMixin:OnLoad()

self.prevControl = nil
self.controls = {}
self.profileBackup = {}
-- self.profileBackup = {}

self.name = C_AddOns.GetAddOnMetadata(addon, "Title")
self.version = C_AddOns.GetAddOnMetadata(addon, "Version")
Expand All @@ -43,40 +44,40 @@ function nPlatesConfigMixin:OnLoad()
end

function nPlatesConfigMixin:OnEvent(event, ...)
if ( event == "VARIABLES_LOADED") then
if ( event == "VARIABLES_LOADED" ) then
self:Init()
self:SaveProfileBackup()
-- self:SaveProfileBackup()
self:UnregisterEvent(event)
end
end

function nPlatesConfigMixin:SaveProfileBackup()
self.profileBackup = CopyTable(nPlatesDB)
end
-- function nPlatesConfigMixin:SaveProfileBackup()
-- self.profileBackup = CopyTable(nPlatesDB)
-- end

function nPlatesConfigMixin:OnCommit()
for _, control in pairs(self.controls) do
if ( self:ShouldUpdate(control) ) then
self.profileBackup[control.optionName] = control:GetValue()
end
end
end
-- function nPlatesConfigMixin:OnCommit()
-- for _, control in pairs(self.controls) do
-- if ( self:ShouldUpdate(control) ) then
-- self.profileBackup[control.optionName] = control:GetValue()
-- end
-- end
-- end

function nPlatesConfigMixin:ShouldUpdate(control)
local oldValue = self.profileBackup[control.optionName]
local value = control:GetValue()
-- function nPlatesConfigMixin:ShouldUpdate(control)
-- local oldValue = self.profileBackup[control.optionName]
-- local value = control:GetValue()

return oldValue ~= value
end
-- return oldValue ~= value
-- end

function nPlatesConfigMixin:CancelChanges()
for _, control in pairs(self.controls) do
if ( self:ShouldUpdate(control) ) then
nPlatesDB[control.optionName] = self.profileBackup[control.optionName]
control:Update()
end
end
end
-- function nPlatesConfigMixin:CancelChanges()
-- for _, control in pairs(self.controls) do
-- if ( self:ShouldUpdate(control) ) then
-- nPlatesDB[control.optionName] = self.profileBackup[control.optionName]
-- control:Update()
-- end
-- end
-- end

function nPlatesConfigMixin:OnDefault()
for _, control in pairs(self.controls) do
Expand Down Expand Up @@ -249,6 +250,18 @@ function nPlatesConfigMixin:Init()
["PercentHealth"] = L.PercentHealth,
},
},
{
type = "Dropdown",
name = "FormattingStyle",
parent = self,
label = L.FormattingStyle,
optionName = "FormattingStyle",
updateAll = true,
optionsTable = {
["Short"] = L.AbbreviateNumbers,
["Long"] = L.AbbreviateLargeNumbers,
},
},
{
type = "CheckBox",
name = "SmallStacking",
Expand Down Expand Up @@ -389,7 +402,7 @@ function nPlatesConfigMixin:Init()
},
}

local Wrath_UIControls = {
local Classic_UIControls = {
{
type = "Label",
name = "NameOptions",
Expand Down Expand Up @@ -543,6 +556,18 @@ function nPlatesConfigMixin:Init()
["PercentHealth"] = L.PercentHealth,
},
},
{
type = "Dropdown",
name = "FormattingStyle",
parent = self,
label = L.FormattingStyle,
optionName = "FormattingStyle",
updateAll = true,
optionsTable = {
["Short"] = L.AbbreviateNumbers,
["Long"] = L.AbbreviateLargeNumbers,
},
},
{
type = "CheckBox",
name = "SmallStacking",
Expand Down Expand Up @@ -682,7 +707,7 @@ function nPlatesConfigMixin:Init()
},
}

local UIControls = nPlates:IsRetail() and Retail_UIControls or Wrath_UIControls
local UIControls = nPlates:IsRetail() and Retail_UIControls or Classic_UIControls

for _, control in pairs(UIControls) do
if ( control.type == "Label" ) then
Expand Down

0 comments on commit 68ba0ff

Please sign in to comment.