From 807e96f4e623d3e78c53cc9e59a46e23f8131fa7 Mon Sep 17 00:00:00 2001 From: Dennis Braun Date: Wed, 18 Mar 2026 09:08:15 +0100 Subject: [PATCH 1/2] Add enemy level display on nameplates Show unit level as a colored prefix before the enemy name, using WoW's GetCreatureDifficultyColor for difficulty-based coloring (gray/green/yellow/orange/red). Bosses show as "??". Controlled via two new settings: - showLevel (default: true) - levelDifficultyColor (default: true) --- .../EllesmereUINameplates.lua | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/EllesmereUINameplates/EllesmereUINameplates.lua b/EllesmereUINameplates/EllesmereUINameplates.lua index b043895a..8a018737 100644 --- a/EllesmereUINameplates/EllesmereUINameplates.lua +++ b/EllesmereUINameplates/EllesmereUINameplates.lua @@ -94,6 +94,8 @@ local defaults = { textSlotRight = "healthPercent", textSlotLeft = "none", textSlotCenter = "none", + showLevel = true, + levelDifficultyColor = true, showTargetArrows = false, targetArrowScale = 1.0, showClassPower = false, @@ -413,6 +415,22 @@ 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) + local levelStr = level == -1 and "??" or tostring(level) + local lr, lg, lb + 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 + 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. @@ -3199,6 +3217,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 @@ -4494,6 +4516,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", From 1dc8d288c6e2071929cd8dbf133b1dec787bc063 Mon Sep 17 00:00:00 2001 From: Dennis Braun Date: Wed, 18 Mar 2026 09:22:42 +0100 Subject: [PATCH 2/2] Fix level display: boss color, width compensation, edge cases - Boss (level -1): hardcode red instead of passing -1 to GetCreatureDifficultyColor which misinterprets it as low level - Skip level display for critters/level-0 units (level <= 0) - Add 25px width compensation in UpdateNameWidth when showLevel is enabled to prevent name truncation - Cache GetCreatureDifficultyColor at file scope for consistency --- .../EllesmereUINameplates.lua | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/EllesmereUINameplates/EllesmereUINameplates.lua b/EllesmereUINameplates/EllesmereUINameplates.lua index 8a018737..b6110a03 100644 --- a/EllesmereUINameplates/EllesmereUINameplates.lua +++ b/EllesmereUINameplates/EllesmereUINameplates.lua @@ -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 @@ -420,13 +421,19 @@ local function GetLevelPrefix(unit) local db = EllesmereUINameplatesDB or defaults if not db.showLevel then return nil end local level = UnitLevel(unit) - local levelStr = level == -1 and "??" or tostring(level) - local lr, lg, lb - if db.levelDifficultyColor and GetCreatureDifficultyColor then - local color = GetCreatureDifficultyColor(level) - lr, lg, lb = color.r, color.g, color.b + 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 - lr, lg, lb = 1, 0.82, 0 + 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 @@ -3272,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