unitframes: option to abbreviate unit names

This commit is contained in:
shagu
2022-07-16 12:15:14 +02:00
parent 7a9f0e39d3
commit 50836a3cd0
3 changed files with 32 additions and 6 deletions
+1
View File
@@ -211,6 +211,7 @@ function pfUI:LoadConfig()
pfUI:UpdateConfig("unitframes", nil, "rangechecki", "4")
pfUI:UpdateConfig("unitframes", nil, "combosize", "6")
pfUI:UpdateConfig("unitframes", nil, "abbrevnum", "1")
pfUI:UpdateConfig("unitframes", nil, "abbrevname", "1")
pfUI:UpdateConfig("unitframes", nil, "selfingroup", "0")
pfUI:UpdateConfig("unitframes", nil, "selfinraid", "0")
+30 -6
View File
@@ -2280,6 +2280,28 @@ function pfUI.uf:SetupBuffIndicators(config)
return indicators
end
local function abbrevname(t)
return string.sub(t,1,1)..". "
end
function pfUI.uf:GetNameString(unitstr)
local name = UnitName(unitstr)
local abbrev = pfUI_config.unitframes.abbrevname == "1" or nil
local size = 20
-- first try to only abbreviate the first word
if abbrev and name and strlen(name) > size then
name = string.gsub(name, "^(%S+) ", abbrevname)
end
-- abbreviate all if it still doesn't fit
if abbrev and name and strlen(name) > size then
name = string.gsub(name, "(%S+) ", abbrevname)
end
return name
end
function pfUI.uf:GetLevelString(unitstr)
local level = UnitLevel(unitstr)
if level == -1 then level = "??" end
@@ -2321,15 +2343,17 @@ function pfUI.uf:GetStatusValue(unit, pos)
end
if config == "unit" then
local name = unit:GetColor("unit") .. UnitName(unitstr)
local name = unit:GetColor("unit") .. pfUI.uf:GetNameString(unitstr)
local level = unit:GetColor("level") .. pfUI.uf:GetLevelString(unitstr)
return level .. " " .. name
elseif config == "unitrev" then
local name = unit:GetColor("unit") .. UnitName(unitstr)
local name = unit:GetColor("unit") .. pfUI.uf:GetNameString(unitstr)
local level = unit:GetColor("level") .. pfUI.uf:GetLevelString(unitstr)
return name .. " " .. level
elseif config == "name" then
return unit:GetColor("unit") .. UnitName(unitstr)
return unit:GetColor("unit") .. pfUI.uf:GetNameString(unitstr)
elseif config == "nameshort" then
return unit:GetColor("unit") .. strsub(UnitName(unitstr), 0, 3)
elseif config == "level" then
@@ -2368,7 +2392,7 @@ function pfUI.uf:GetStatusValue(unit, pos)
if UnitIsDead(unitstr) then
return unit:GetColor("health") .. DEAD
elseif health == 0 then
return unit:GetColor("unit") .. UnitName(unitstr)
return unit:GetColor("unit") .. pfUI.uf:GetNameString(unitstr)
else
return unit:GetColor("health") .. pfUI.api.Abbreviate(health)
end
@@ -2377,9 +2401,9 @@ function pfUI.uf:GetStatusValue(unit, pos)
if UnitIsDead(unitstr) then
return unit:GetColor("health") .. DEAD
elseif health == 0 then
return unit:GetColor("unit") .. UnitName(unitstr)
return unit:GetColor("unit") .. pfUI.uf:GetNameString(unitstr)
else
return unit:GetColor("unit") .. UnitName(unitstr) .. "\n" .. unit:GetColor("health") .. pfUI.api.Abbreviate(-health)
return unit:GetColor("unit") .. pfUI.uf:GetNameString(unitstr) .. "\n" .. unit:GetColor("health") .. pfUI.api.Abbreviate(-health)
end
elseif config == "shortnamehealth" then
local health = ceil(rhp - rhpmax)
+1
View File
@@ -1589,6 +1589,7 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function ()
CreateConfig(nil, T["Show Resting"], C.unitframes.player, "showRest", "checkbox")
CreateConfig(nil, T["Enable Energy Ticks"], C.unitframes.player, "energy", "checkbox")
CreateConfig(nil, T["Enable Mana Ticks"], C.unitframes.player, "manatick", "checkbox")
CreateConfig(nil, T["Abbreviate Unit Names"], C.unitframes, "abbrevname", "checkbox")
CreateConfig(U[c], T["Font Options"], nil, nil, "header")
CreateConfig(nil, T["Unit Frame Text Font"], C.global, "font_unit", "dropdown", pfUI.gui.dropdowns.fonts)