diff --git a/api/api.lua b/api/api.lua index 25dcfd47..76813016 100644 --- a/api/api.lua +++ b/api/api.lua @@ -98,6 +98,22 @@ function pfUI.api.GetItemLinkByName(name) end end +-- [ Abbreviate ] +-- Abbreviates a number from 1234 to 1.23k +-- 'number' [number] the number that should be abbreviated +-- 'returns: [string] the abbreviated value +function pfUI.api.Abbreviate(number) + if pfUI_config.unitframes.abbrevnum == "1" then + if number > 1000000 then + return pfUI.api.round(number/1000000,2) .. "m" + elseif number > 1000 then + return pfUI.api.round(number/1000,2) .. "k" + end + end + + return number +end + -- [ hooksecurefunc ] -- Hooks a global function and injects custom code -- 'name' [string] name of the function that shold be hooked diff --git a/api/config.lua b/api/config.lua index b246ec66..ea1e97d1 100644 --- a/api/config.lua +++ b/api/config.lua @@ -79,6 +79,7 @@ function pfUI:LoadConfig() pfUI:UpdateConfig("unitframes", nil, "rangecheck", "0") pfUI:UpdateConfig("unitframes", nil, "rangechecki", ".5") pfUI:UpdateConfig("unitframes", nil, "combosize", "6") + pfUI:UpdateConfig("unitframes", nil, "abbrevnum", "1") pfUI:UpdateConfig("unitframes", nil, "show_hots", "0") pfUI:UpdateConfig("unitframes", nil, "all_hots", "0") diff --git a/api/unitframes.lua b/api/unitframes.lua index fe6dd477..e8c21022 100644 --- a/api/unitframes.lua +++ b/api/unitframes.lua @@ -1231,15 +1231,15 @@ function pfUI.uf:GetStatusValue(unit, pos) elseif config == "health" then if unit.label == "target" and MobHealth3 then local hp, hpmax = MobHealth3:GetUnitHealth(unit.label) - return unit:GetColor("health") .. hp + return unit:GetColor("health") .. pfUI.api.Abbreviate(hp) end - return unit:GetColor("health") .. UnitHealth(unitstr) + return unit:GetColor("health") .. pfUI.api.Abbreviate(UnitHealth(unitstr)) elseif config == "healthmax" then if unit.label == "target" and MobHealth3 then local hp, hpmax = MobHealth3:GetUnitHealth(unit.label) - return unit:GetColor("health") .. hpmax + return unit:GetColor("health") .. pfUI.api.Abbreviate(hpmax) end - return unit:GetColor("health") .. UnitHealthMax(unitstr) + return unit:GetColor("health") .. pfUI.api.Abbreviate(UnitHealthMax(unitstr)) elseif config == "healthperc" then return unit:GetColor("health") .. ceil(UnitHealth(unitstr) / UnitHealthMax(unitstr) * 100) elseif config == "healthmiss" then @@ -1247,38 +1247,39 @@ function pfUI.uf:GetStatusValue(unit, pos) if health == 0 then return "" else - return unit:GetColor("health") .. health + return unit:GetColor("health") .. pfUI.api.Abbreviate(health) end elseif config == "healthdyn" then if UnitHealth(unitstr) ~= UnitHealthMax(unitstr) then if unit.label == "target" and MobHealth3 then local hp, hpmax = MobHealth3:GetUnitHealth(unit.label) - return unit:GetColor("health") .. hp .. " - " .. ceil(hp / hpmax * 100) .. "%" + return unit:GetColor("health") .. pfUI.api.Abbreviate(hp) .. " - " .. ceil(hp / hpmax * 100) .. "%" end - return unit:GetColor("health") .. UnitHealth(unitstr) .. " - " .. ceil(UnitHealth(unitstr) / UnitHealthMax(unitstr) * 100) .. "%" + return unit:GetColor("health") .. pfUI.api.Abbreviate(UnitHealth(unitstr)) .. " - " .. ceil(UnitHealth(unitstr) / UnitHealthMax(unitstr) * 100) .. "%" else - return unit:GetColor("health") .. UnitHealth(unitstr) + return unit:GetColor("health") .. pfUI.api.Abbreviate(UnitHealth(unitstr)) end -- mana/power/focus elseif config == "power" then - return unit:GetColor("power") .. UnitMana(unitstr) + return unit:GetColor("power") .. pfUI.api.Abbreviate(UnitMana(unitstr)) elseif config == "powermax" then - return unit:GetColor("power") .. UnitManaMax(unitstr) + return unit:GetColor("power") .. pfUI.api.Abbreviate(UnitManaMax(unitstr)) elseif config == "powerperc" then - return unit:GetColor("power") .. ceil(UnitMana(unitstr) / UnitManaMax(unitstr) * 100) + local perc = UnitManaMax(unitstr) > 0 and ceil(UnitMana(unitstr) / UnitManaMax(unitstr) * 100) or 0 + return unit:GetColor("power") .. perc elseif config == "powermiss" then local power = ceil(UnitMana(unitstr) - UnitManaMax(unitstr)) if power == 0 then return "" else - return unit:GetColor("power") .. power + return unit:GetColor("power") .. pfUI.api.Abbreviate(power) end elseif config == "powerdyn" then if UnitMana(unitstr) ~= UnitManaMax(unitstr) then - return unit:GetColor("power") .. UnitMana(unitstr) .. " - " .. ceil(UnitMana(unitstr) / UnitManaMax(unitstr) * 100) .. "%" + return unit:GetColor("power") .. pfUI.api.Abbreviate(UnitMana(unitstr)) .. " - " .. ceil(UnitMana(unitstr) / UnitManaMax(unitstr) * 100) .. "%" else - return unit:GetColor("power") .. UnitMana(unitstr) + return unit:GetColor("power") .. pfUI.api.Abbreviate(UnitMana(unitstr)) end else return "" diff --git a/modules/gui.lua b/modules/gui.lua index d7e226f8..72f8dacf 100644 --- a/modules/gui.lua +++ b/modules/gui.lua @@ -896,6 +896,7 @@ pfUI:RegisterModule("gui", function () pfUI.gui:CreateConfig(pfUI.gui.uf, "Aggressive 40y-Range Check (Will break stuff)", C.unitframes, "rangecheck", "checkbox") pfUI.gui:CreateConfig(pfUI.gui.uf, "40y-Range Check Interval", C.unitframes, "rangechecki") pfUI.gui:CreateConfig(pfUI.gui.uf, "Combopoint Size", C.unitframes, "combosize") + pfUI.gui:CreateConfig(pfUI.gui.uf, "Abbreviate Numbers (4200 -> 4.2k)", C.unitframes, "abbrevnum", "checkbox") pfUI.gui:CreateConfig(pfUI.gui.uf, "Buff- And Debuff Indicators", nil, nil, "header") pfUI.gui:CreateConfig(pfUI.gui.uf, "Show Hots as Buff Indicators", C.unitframes, "show_hots", "checkbox")