Skip to content

Commit

Permalink
nameplates: abbreviate unit names if option is set
Browse files Browse the repository at this point in the history
  • Loading branch information
shagu committed Sep 3, 2024
1 parent b8d23a0 commit b00dc9e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modules/gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function ()
CreateConfig(nil, T["Highlight Settings That Require Reload"], C.gui, "reloadmarker", "checkbox")
CreateConfig(nil, T["Show Incompatible Config Entries"], C.gui, "showdisabled", "checkbox")
CreateConfig(nil, T["Abbreviate Numbers (4200 -> 4.2k)"], C.unitframes, "abbrevnum", "checkbox")
CreateConfig(nil, T["Abbreviate Unit Names"], C.unitframes, "abbrevname", "checkbox")
CreateConfig(nil, T["Health Point Estimation"], nil, nil, "header")
CreateConfig(nil, T["Estimate Enemy Health Points"], C.global, "libhealth", "checkbox")
CreateConfig(nil, T["Threshold To Trust Health Estimation"], C.global, "libhealth_hit", "dropdown", pfUI.gui.dropdowns.uf_rangecheckinterval)
Expand Down Expand Up @@ -1591,7 +1592,6 @@ 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(nil, T["Detect Enemy Buffs"], C.unitframes, "buffdetect", "checkbox", nil, nil, nil, nil, "vanilla" )

CreateConfig(U[c], T["Font Options"], nil, nil, "header")
Expand Down
24 changes: 23 additions & 1 deletion modules/nameplates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,28 @@ pfUI:RegisterModule("nameplates", "vanilla:tbc", function ()
return nil
end

local function abbrevname(t)
return string.sub(t,1,1)..". "
end

local function GetNameString(name)
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


local function GetUnitType(red, green, blue)
if red > .9 and green < .2 and blue < .2 then
return "ENEMY_NPC"
Expand Down Expand Up @@ -613,7 +635,7 @@ pfUI:RegisterModule("nameplates", "vanilla:tbc", function ()
plate.totem:Hide()
end

plate.name:SetText(name)
plate.name:SetText(GetNameString(name))
plate.level:SetText(string.format("%s%s", level, (elitestrings[elite] or "")))

if guild and C.nameplates.showguildname == "1" then
Expand Down

0 comments on commit b00dc9e

Please sign in to comment.