Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion EllesmereUINameplates/EllesmereUINameplates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ local UnitCastingInfo, UnitChannelInfo = UnitCastingInfo, UnitChannelInfo
local GetTime = GetTime
local C_NamePlate = C_NamePlate
local GetRaidTargetIndex, SetRaidTargetIconTexture = GetRaidTargetIndex, SetRaidTargetIconTexture
local GetCreatureDifficultyColor = GetCreatureDifficultyColor
local C_CVar, NamePlateConstants, Enum = C_CVar, NamePlateConstants, Enum
local function GetFont()
if EllesmereUI and EllesmereUI.GetFontPath then
Expand Down Expand Up @@ -94,6 +95,8 @@ local defaults = {
textSlotRight = "healthPercent",
textSlotLeft = "none",
textSlotCenter = "none",
showLevel = true,
levelDifficultyColor = true,
showTargetArrows = false,
targetArrowScale = 1.0,
showClassPower = false,
Expand Down Expand Up @@ -413,6 +416,28 @@ local function FormatCombinedHealth(element, pctText, numText)
return ""
end

-- Build a colored level prefix string for a unit, or nil if disabled.
local function GetLevelPrefix(unit)
local db = EllesmereUINameplatesDB or defaults
if not db.showLevel then return nil end
local level = UnitLevel(unit)
if not level or level <= 0 and level ~= -1 then return nil end
local levelStr, lr, lg, lb
if level == -1 then
levelStr = "??"
lr, lg, lb = 1, 0, 0
else
levelStr = tostring(level)
if db.levelDifficultyColor and GetCreatureDifficultyColor then
local color = GetCreatureDifficultyColor(level)
lr, lg, lb = color.r, color.g, color.b
else
lr, lg, lb = 1, 0.82, 0
end
end
return string.format("|cff%02x%02x%02x%s|r", lr * 255, lg * 255, lb * 255, levelStr)
end

-- Estimate pixel width of health text for a given element type.
-- We can't read actual rendered widths (WoW secret values), so we use
-- flat pixel assumptions based on typical worst-case rendered widths.
Expand Down Expand Up @@ -3199,6 +3224,10 @@ function NameplateFrame:UpdateName()
end
local name = UnitName(unit)
if type(name) == "string" then
local levelPrefix = GetLevelPrefix(unit)
if levelPrefix then
name = levelPrefix .. " " .. name
end
self.name:SetText(name)
end
end
Expand Down Expand Up @@ -3250,9 +3279,10 @@ end
function NameplateFrame:UpdateNameWidth()
local barW = GetHealthBarWidth()
local nameSlot = FindSlotForElement("enemyName")
local levelExtra = ((EllesmereUINameplatesDB or defaults).showLevel) and 25 or 0
if nameSlot == "textSlotTop" then
-- Above the bar: full bar width minus raid marker if shown
local nameW = barW
local nameW = barW + levelExtra
local rmPos = GetRaidMarkerPos()
if rmPos ~= "none" and self.raidFrame:IsShown() then
nameW = nameW - 2 * (GetRaidMarkerSize() - 2) - 7
Expand Down Expand Up @@ -4494,6 +4524,7 @@ do

-- Store preset keys so the login handler can use them (set once, never changes)
ns._displayPresetKeys = {
"showLevel", "levelDifficultyColor",
"borderStyle", "borderColor", "targetGlowStyle", "showTargetArrows",
"showClassPower", "classPowerPos", "classPowerYOffset", "classPowerXOffset", "classPowerScale",
"classPowerClassColors", "classPowerCustomColor", "classPowerGap",
Expand Down