Commit d919e379 authored by Blazeflack's avatar Blazeflack

Updated ShortValue function and added support for append/prepend text

Reference: #8
parent aa72c74d
......@@ -48,16 +48,18 @@ local textFormatStylesNoDecimal = {
local shortValueFormat
local function ShortValue(number, noDecimal)
shortValueFormat = (noDecimal and "%.0f%s" or "%.1f%s")
shortValueFormat = (noDecimal and "%.0f%s" or format("%%.%df", E.db.general.decimalLength or 1))
if E.db.general.numberPrefixStyle == "METRIC" then
if abs(number) >= 1e9 then
if abs(v) >= 1e12 then
return format("%.1f%s", number / 1e12, "T")
elseif abs(number) >= 1e9 then
return format("%.1f%s", number / 1e9, "G")
elseif abs(number) >= 1e6 then
return format("%.1f%s", number / 1e6, "M")
elseif abs(number) >= 1e3 then
return format(shortValueFormat, number / 1e3, "k")
else
return format("%d", number)
return format("%.0f", number)
end
elseif E.db.general.numberPrefixStyle == "CHINESE" then
if abs(number) >= 1e8 then
......@@ -65,17 +67,41 @@ local function ShortValue(number, noDecimal)
elseif abs(number) >= 1e4 then
return format("%.1f%s", number / 1e4, "W")
else
return format("%d", number)
return format("%.0f", number)
end
elseif E.db.general.numberPrefixStyle == "KOREAN" then
if abs(v) >= 1e8 then
return format("%.1f%s", number / 1e8, "억")
elseif abs(number) >= 1e4 then
return format("%.1f%s", number / 1e4, "만")
elseif abs(number) >= 1e3 then
return format(shortValueFormat, number / 1e3, "천")
else
return format("%.0f", number)
end
elseif E.db.general.numberPrefixStyle == "GERMAN" then
if abs(v) >= 1e12 then
return format("%.1f%s", number / 1e12, "Bio")
elseif abs(number) >= 1e9 then
return format("%.1f%s", number / 1e9, "Mrd")
elseif abs(number) >= 1e6 then
return format("%.1f%s", number / 1e6, "Mio")
elseif abs(number) >= 1e3 then
return format(shortValueFormat, number / 1e3, "Tsd")
else
return format("%.0f", number)
end
else
if abs(number) >= 1e9 then
if abs(number) >= 1e12 then
return format("%.1f%s", number / 1e12, "T")
elseif abs(number) >= 1e9 then
return format("%.1f%s", number / 1e9, "B")
elseif abs(number) >= 1e6 then
return format("%.1f%s", number / 1e6, "M")
elseif abs(number) >= 1e3 then
return format(shortValueFormat, number / 1e3, "K")
else
return format("%d", number)
return format("%.0f", number)
end
end
end
......@@ -97,7 +123,7 @@ local function GetFormattedText(min, max, style, noDecimal)
if style == "DEFICIT" then
local deficit = max - min
if deficit <= 0 then
return ""
return nil
else
return format(chosenFormat, ShortValue(deficit, noDecimal))
end
......@@ -123,7 +149,7 @@ end
--]]
ElvUF.Tags.Events["num:targeting"] = "UNIT_TARGET PLAYER_TARGET_CHANGED GROUP_ROSTER_UPDATE"
ElvUF.Tags.Methods["num:targeting"] = function(unit)
if not IsInGroup() then return "" end
if not IsInGroup() then return nil end
local targetedByNum = 0
--Count the amount of other people targeting the unit
......@@ -139,7 +165,7 @@ ElvUF.Tags.Methods["num:targeting"] = function(unit)
targetedByNum = targetedByNum + 1
end
return (targetedByNum > 0 and targetedByNum or "")
return (targetedByNum > 0 and targetedByNum or nil)
end
ElvUF.Tags.Events["health:percent:hidefull"] = "UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH UNIT_CONNECTION"
......@@ -148,9 +174,7 @@ ElvUF.Tags.Methods["health:percent:hidefull"] = function(unit)
local deficit = max - min
local String
if deficit <= 0 then
String = ""
else
if not (deficit <= 0) then
String = GetFormattedText(min, max, "PERCENT", true)
end
......@@ -163,9 +187,7 @@ ElvUF.Tags.Methods["health:current:hidefull"] = function(unit)
local deficit = max - min
local String
if deficit <= 0 then
String = ""
else
if not (deficit <= 0) then
String = GetFormattedText(min, max, "CURRENT", true)
end
......@@ -178,9 +200,7 @@ ElvUF.Tags.Methods["health:current-percent:hidefull"] = function(unit)
local deficit = max - min
local String
if deficit <= 0 then
String = ""
else
if not (deficit <= 0) then
String = GetFormattedText(min, max, "CURRENT_PERCENT", true)
end
......@@ -193,9 +213,7 @@ ElvUF.Tags.Methods["health:percent:hidedead"] = function(unit)
local deficit = max - min
local String
if (min == 0) or (UnitIsGhost(unit)) then
String = ""
else
if not ((min == 0) or (UnitIsGhost(unit))) then
String = GetFormattedText(min, max, "PERCENT", true)
end
......@@ -208,9 +226,7 @@ ElvUF.Tags.Methods["health:current:hidedead"] = function(unit)
local deficit = max - min
local String
if (min == 0) or (UnitIsGhost(unit)) then
String = ""
else
if not ((min == 0) or (UnitIsGhost(unit))) then
String = GetFormattedText(min, max, "CURRENT", true)
end
......@@ -223,9 +239,7 @@ ElvUF.Tags.Methods["health:current-percent:hidedead"] = function(unit)
local deficit = max - min
local String
if (min == 0) or (UnitIsGhost(unit)) then
String = ""
else
if not ((min == 0) or (UnitIsGhost(unit))) then
String = GetFormattedText(min, max, "CURRENT_PERCENT", true)
end
......@@ -238,9 +252,7 @@ ElvUF.Tags.Methods["health:percent:hidefull:hidedead"] = function(unit)
local deficit = max - min
local String
if (deficit <= 0) or (min == 0) or (UnitIsGhost(unit)) then
String = ""
else
if not ((deficit <= 0) or (min == 0) or (UnitIsGhost(unit))) then
String = GetFormattedText(min, max, "PERCENT", true)
end
......@@ -253,9 +265,7 @@ ElvUF.Tags.Methods["health:current:hidefull:hidedead"] = function(unit)
local deficit = max - min
local String
if (deficit <= 0) or (min == 0) or (UnitIsGhost(unit)) then
String = ""
else
if not ((deficit <= 0) or (min == 0) or (UnitIsGhost(unit))) then
String = GetFormattedText(min, max, "CURRENT", true)
end
......@@ -268,9 +278,7 @@ ElvUF.Tags.Methods["health:current-percent:hidefull:hidedead"] = function(unit)
local deficit = max - min
local String
if (deficit <= 0) or (min == 0) or (UnitIsGhost(unit)) then
String = ""
else
if not ((deficit <= 0) or (min == 0) or (UnitIsGhost(unit))) then
String = GetFormattedText(min, max, "CURRENT_PERCENT", true)
end
......@@ -284,9 +292,7 @@ ElvUF.Tags.Methods["power:percent:hidefull"] = function(unit)
local deficit = max - min
local String
if deficit <= 0 then
String = ""
else
if not (deficit <= 0) then
String = GetFormattedText(min, max, "PERCENT", true)
end
......@@ -300,9 +306,7 @@ ElvUF.Tags.Methods["power:current:hidefull"] = function(unit)
local deficit = max - min
local String
if deficit <= 0 then
String = ""
else
if not (deficit <= 0) then
String = GetFormattedText(min, max, "CURRENT", true)
end
......@@ -316,9 +320,7 @@ ElvUF.Tags.Methods["power:current-percent:hidefull"] = function(unit)
local deficit = max - min
local String
if deficit <= 0 then
String = ""
else
if not (deficit <= 0) then
String = GetFormattedText(min, max, "CURRENT_PERCENT", true)
end
......@@ -331,9 +333,7 @@ ElvUF.Tags.Methods["power:percent:hidezero"] = function(unit)
local min, max = UnitPower(unit, pType), UnitPowerMax(unit, pType)
local String
if min <= 0 then
String = ""
else
if not (min <= 0) then
String = GetFormattedText(min, max, "PERCENT", true)
end
......@@ -346,9 +346,7 @@ ElvUF.Tags.Methods["power:current:hidezero"] = function(unit)
local min, max = UnitPower(unit, pType), UnitPowerMax(unit, pType)
local String
if min <= 0 then
String = ""
else
if not (min <= 0) then
String = GetFormattedText(min, max, "CURRENT", true)
end
......@@ -361,9 +359,7 @@ ElvUF.Tags.Methods["power:current-percent:hidezero"] = function(unit)
local min, max = UnitPower(unit, pType), UnitPowerMax(unit, pType)
local String
if min <= 0 then
String = ""
else
if not (min <= 0) then
String = GetFormattedText(min, max, "CURRENT_PERCENT", true)
end
......@@ -377,9 +373,7 @@ ElvUF.Tags.Methods["power:percent:hidefull:hidezero"] = function(unit)
local deficit = max - min
local String
if (deficit <= 0 or min <= 0) then
String = ""
else
if not (deficit <= 0 or min <= 0) then
String = GetFormattedText(min, max, "PERCENT", true)
end
......@@ -393,9 +387,7 @@ ElvUF.Tags.Methods["power:current:hidefull:hidezero"] = function(unit)
local deficit = max - min
local String
if (deficit <= 0 or min <= 0) then
String = ""
else
if not (deficit <= 0 or min <= 0) then
String = GetFormattedText(min, max, "CURRENT", true)
end
......@@ -409,9 +401,7 @@ ElvUF.Tags.Methods["power:current-percent:hidefull:hidezero"] = function(unit)
local deficit = max - min
local String
if (deficit <= 0 or min <= 0) then
String = ""
else
if not ((deficit <= 0 or min <= 0)) then
String = GetFormattedText(min, max, "CURRENT_PERCENT", true)
end
......@@ -425,9 +415,7 @@ ElvUF.Tags.Methods["power:percent:hidedead"] = function(unit)
local deficit = max - min
local String
if (min == 0) or (UnitIsGhost(unit) or UnitIsDead(unit)) then
String = ""
else
if not ((min == 0) or (UnitIsGhost(unit) or UnitIsDead(unit))) then
String = GetFormattedText(min, max, "PERCENT", true)
end
......@@ -441,9 +429,7 @@ ElvUF.Tags.Methods["power:current:hidedead"] = function(unit)
local deficit = max - min
local String
if (min == 0) or (UnitIsGhost(unit) or UnitIsDead(unit)) then
String = ""
else
if not ((min == 0) or (UnitIsGhost(unit) or UnitIsDead(unit))) then
String = GetFormattedText(min, max, "CURRENT", true)
end
......@@ -457,9 +443,7 @@ ElvUF.Tags.Methods["power:current-percent:hidedead"] = function(unit)
local deficit = max - min
local String
if (min == 0) or (UnitIsGhost(unit) or UnitIsDead(unit)) then
String = ""
else
if not ((min == 0) or (UnitIsGhost(unit) or UnitIsDead(unit))) then
String = GetFormattedText(min, max, "CURRENT_PERCENT", true)
end
......@@ -473,9 +457,7 @@ ElvUF.Tags.Methods["power:percent:hidefull:hidedead"] = function(unit)
local deficit = max - min
local String
if (deficit <= 0) or (min == 0) or (UnitIsGhost(unit) or UnitIsDead(unit)) then
String = ""
else
if not ((deficit <= 0) or (min == 0) or (UnitIsGhost(unit) or UnitIsDead(unit))) then
String = GetFormattedText(min, max, "PERCENT", true)
end
......@@ -489,9 +471,7 @@ ElvUF.Tags.Methods["power:current:hidefull:hidedead"] = function(unit)
local deficit = max - min
local String
if (deficit <= 0) or (min == 0) or (UnitIsGhost(unit) or UnitIsDead(unit)) then
String = ""
else
if not ((deficit <= 0) or (min == 0) or (UnitIsGhost(unit) or UnitIsDead(unit))) then
String = GetFormattedText(min, max, "CURRENT", true)
end
......@@ -505,9 +485,7 @@ ElvUF.Tags.Methods["power:current-percent:hidefull:hidedead"] = function(unit)
local deficit = max - min
local String
if (deficit <= 0) or (min == 0) or (UnitIsGhost(unit) or UnitIsDead(unit)) then
String = ""
else
if not ((deficit <= 0) or (min == 0) or (UnitIsGhost(unit) or UnitIsDead(unit))) then
String = GetFormattedText(min, max, "CURRENT_PERCENT", true)
end
......@@ -595,7 +573,7 @@ end
ElvUF.Tags.Events['faction:icon'] = 'UNIT_NAME_UPDATE'
ElvUF.Tags.Methods['faction:icon'] = function(unit)
local faction = UnitFactionGroup(unit)
local str = ""
local str
if faction == "Alliance" then
str = "|TInterface\\AddOns\\ElvUI_CustomTags\\media\\Alliance:0:0:0:-1|t"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment