From 1d27f7bed38d46f9db78cd39ec472187796f4cf8 Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat, 23 May 2026 02:56:00 -0500 Subject: [PATCH] class color cleanup --- api/api.lua | 16 ++--------- api/ui-widgets.lua | 6 ++-- api/unitframes.lua | 52 +++++++++++----------------------- modules/actionbar.lua | 3 +- modules/afkcam.lua | 2 +- modules/buff.lua | 14 ++------- modules/chat.lua | 15 ++++------ modules/mapcolors.lua | 5 ++-- modules/nameplates.lua | 10 ++++--- modules/thirdparty-vanilla.lua | 2 +- 10 files changed, 40 insertions(+), 85 deletions(-) diff --git a/api/api.lua b/api/api.lua index 7cf64cd5..4ba98367 100644 --- a/api/api.lua +++ b/api/api.lua @@ -220,13 +220,8 @@ end -- return: [table] string, r, g, b function pfUI.api.GetUnitColor(unitstr) local _, class = UnitClass(unitstr) - - local r, g, b = .8, .8, .8 - if RAID_CLASS_COLORS[class] then - r, g, b = RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b - end - - return pfUI.api.rgbhex(r,g,b), r, g, b + local classColor = RAID_CLASS_COLORS[class] + return classColor:GenerateHexColorMarkup(), classColor:GetRGB() end -- [ strvertical ] @@ -1011,12 +1006,7 @@ function pfUI.api.rgbhex(r, g, b, a) end if _r and _g and _b and _a then - -- limit values to 0-1 - _r = _r + 0 > 1 and 1 or _r + 0 - _g = _g + 0 > 1 and 1 or _g + 0 - _b = _b + 0 > 1 and 1 or _b + 0 - _a = _a + 0 > 1 and 1 or _a + 0 - return string.format("|c%02x%02x%02x%02x", _a*255, _r*255, _g*255, _b*255) + return CreateColor(_r, _g, _b, _a):GenerateHexColorMarkup() end return "" diff --git a/api/ui-widgets.lua b/api/ui-widgets.lua index cdbe01ce..a37a32ab 100644 --- a/api/ui-widgets.lua +++ b/api/ui-widgets.lua @@ -608,8 +608,7 @@ function pfUI.api.SetHighlight(frame, cr, cg, cb) if not frame then return end if not cr or not cg or not cb then local _, class = UnitClass("player") - local color = RAID_CLASS_COLORS[class] - cr, cg, cb = color.r , color.g, color.b + cr, cg, cb = GetClassColor(class) end frame.cr, frame.cg, frame.cb = cr, cg, cb, ca @@ -656,8 +655,7 @@ function pfUI.api.SkinButton(button, cr, cg, cb, icon, disableHighlight) if not b then return end if not cr or not cg or not cb then local _, class = UnitClass("player") - local color = RAID_CLASS_COLORS[class] - cr, cg, cb = color.r , color.g, color.b + cr, cg, cb = GetClassColor(class) end pfUI.api.CreateBackdrop(b, nil, true) b:SetNormalTexture("") diff --git a/api/unitframes.lua b/api/unitframes.lua index f7a7dc9d..242abf15 100644 --- a/api/unitframes.lua +++ b/api/unitframes.lua @@ -1938,13 +1938,6 @@ function pfUI.uf:RefreshIndicators(unit) end end -local pfDebuffColors = { - ["Magic"] = { 0.1, 0.7, 0.8, 1 }, - ["Poison"] = { 0.2, 0.7, 0.3, 1 }, - ["Curse"] = { 0.6, 0.2, 0.6, 1 }, - ["Disease"] = { 0.9, 0.7, 0.2, 1 } -} - function pfUI.uf:RefreshUnit(unit, component) -- break early on misconfigured UF's if not unit.label then return end @@ -2086,11 +2079,8 @@ function pfUI.uf:RefreshUnit(unit, component) unit.debuffs[i].texture:SetTexture(texture) - local r,g,b = DebuffTypeColor.none.r,DebuffTypeColor.none.g,DebuffTypeColor.none.b - if dtype and DebuffTypeColor[dtype] then - r,g,b = DebuffTypeColor[dtype].r,DebuffTypeColor[dtype].g,DebuffTypeColor[dtype].b - end - unit.debuffs[i].backdrop:SetBackdropBorderColor(r,g,b,1) + local dispelColor = C_UnitAuras.GetAuraDispelTypeColor(dtype or "") + unit.debuffs[i].backdrop:SetBackdropBorderColor(dispelColor:GetRGBA()) if texture then unit.debuffs[i]:Show() @@ -2177,16 +2167,17 @@ function pfUI.uf:RefreshUnit(unit, component) indicator[debuff].tex:SetAllPoints(indicator[debuff]) if indicator.size ~= indicator[debuff].size or disptype ~= indicator[debuff].disp then + local dispelColor = C_UnitAuras.GetAuraDispelTypeColor(debuff) if disptype == "4" then indicator[debuff].tex:SetTexture(pfUI.media["img:"..debuff]) - indicator[debuff].tex:SetVertexColor(unpack(pfDebuffColors[debuff])) + indicator[debuff].tex:SetVertexColor(dispelColor:GetRGBA()) indicator[debuff].tex:Show() indicator[debuff]:ClearAllPoints() indicator[debuff]:SetHeight(size) indicator[debuff]:SetWidth(size) indicator[debuff]:SetBackdrop(nil) elseif disptype == "3" then - indicator[debuff].tex:SetTexture(unpack(pfDebuffColors[debuff])) + indicator[debuff].tex:SetTexture(dispelColor:GetRGBA()) indicator[debuff].tex:SetVertexColor(1,1,1,1) indicator[debuff].tex:Show() indicator[debuff]:ClearAllPoints() @@ -2197,9 +2188,9 @@ function pfUI.uf:RefreshUnit(unit, component) indicator[debuff].tex:Hide() indicator[debuff]:SetAllPoints(unit.hp.bar) indicator[debuff]:SetBackdrop(glow) - indicator[debuff]:SetBackdropBorderColor(unpack(pfDebuffColors[debuff])) + indicator[debuff]:SetBackdropBorderColor(dispelColor:GetRGBA()) elseif disptype == "1" then - indicator[debuff].tex:SetTexture(unpack(pfDebuffColors[debuff])) + indicator[debuff].tex:SetTexture(dispelColor:GetRGBA()) indicator[debuff].tex:SetVertexColor(1,1,1,1) indicator[debuff].tex:Show() indicator[debuff]:SetAllPoints(unit.hp.bar) @@ -2415,9 +2406,7 @@ function pfUI.uf:RefreshUnit(unit, component) custom_active = true elseif custom == "0" then if UnitIsPlayer(unitstr) then - local _, class = UnitClass(unitstr) - local color = RAID_CLASS_COLORS[class] - if color then r, g, b = color.r, color.g, color.b end + _, r, g, b = GetUnitColor(unitstr) elseif unit.label == "pet" then local happiness = GetPetHappiness() if happiness == 1 then @@ -3106,10 +3095,7 @@ function pfUI.uf.GetColor(self, preset) if preset == "unit" and config["classcolor"] == "1" then if UnitIsPlayer(unitstr) then - local _, class = UnitClass(unitstr) - if RAID_CLASS_COLORS[class] then - r, g, b = RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b - end + _, r, g, b = GetUnitColor(unitstr) elseif self.label == "pet" then local happiness = GetPetHappiness() if happiness == 1 then @@ -3125,15 +3111,11 @@ function pfUI.uf.GetColor(self, preset) end elseif preset == "class" and config["classcolor"] == "1" then - local _, class = UnitClass(unitstr) - if RAID_CLASS_COLORS[class] then - r, g, b = RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b - end + _, r, g, b = GetUnitColor(unitstr) elseif preset == "reaction" and config["classcolor"] == "1" then - r = UnitReactionColor[UnitReaction(unitstr, "player")].r - g = UnitReactionColor[UnitReaction(unitstr, "player")].g - b = UnitReactionColor[UnitReaction(unitstr, "player")].b + local color = UnitReactionColor[UnitReaction(unitstr, "player")] + r, g, b = color.r, color.g, color.b elseif preset == "health" and config["healthcolor"] == "1" then -- O(1) Nampower lookup for health gradient color @@ -3156,13 +3138,11 @@ function pfUI.uf.GetColor(self, preset) end elseif preset == "power" and config["powercolor"] == "1" then - r = ManaBarColor[UnitPowerType(unitstr)].r - g = ManaBarColor[UnitPowerType(unitstr)].g - b = ManaBarColor[UnitPowerType(unitstr)].b + local color = ManaBarColor[UnitPowerType(unitstr)] + r, g, b = color.r, color.g, color.b elseif preset == "level" and config["levelcolor"] == "1" then - r = GetDifficultyColor(UnitLevel(unitstr)).r - g = GetDifficultyColor(UnitLevel(unitstr)).g - b = GetDifficultyColor(UnitLevel(unitstr)).b + local color = GetDifficultyColor(UnitLevel(unitstr)) + r, g, b = color.r, color.g, color.b end if C.unitframes.pastel == "1" then diff --git a/modules/actionbar.lua b/modules/actionbar.lua index cd044ff2..bf69b4ff 100644 --- a/modules/actionbar.lua +++ b/modules/actionbar.lua @@ -1,7 +1,6 @@ pfUI:RegisterModule("actionbar", "vanilla", function () local _, class = UnitClass("player") - local color = RAID_CLASS_COLORS[class] - local cr, cg, cb = color.r , color.g, color.b + local _, cr, cg, cb = GetUnitColor('player') local er, eg, eb, ea = GetStringColor(pfUI_config.appearance.border.color) local backdrop_highlight = { edgeFile = pfUI.media["img:glow"], edgeSize = 8 } diff --git a/modules/afkcam.lua b/modules/afkcam.lua index 83764da8..0a87602a 100644 --- a/modules/afkcam.lua +++ b/modules/afkcam.lua @@ -64,7 +64,7 @@ pfUI:RegisterModule("afkcam", "vanilla:tbc", function () local class = GetUnitData(arg2 or "") local author, msg if class and class ~= UNKNOWN then - local class_color = rgbhex(RAID_CLASS_COLORS[class]) + local class_color = RAID_CLASS_COLORS[class]:GenerateHexColorMarkup() author = string.format("%s%s|r",class_color,arg2) else author = arg2 diff --git a/modules/buff.lua b/modules/buff.lua index 8dadf1fb..ddff3637 100644 --- a/modules/buff.lua +++ b/modules/buff.lua @@ -63,18 +63,8 @@ pfUI:RegisterModule("buff", "vanilla:tbc", function () buff.texture:SetTexture(aura.icon) if buff.btype == "HARMFUL" then - local dtype = aura.dispelName - if dtype == "Magic" then - buff.backdrop:SetBackdropBorderColor(0,1,1,1) - elseif dtype == "Poison" then - buff.backdrop:SetBackdropBorderColor(0,1,0,1) - elseif dtype == "Curse" then - buff.backdrop:SetBackdropBorderColor(1,0,1,1) - elseif dtype == "Disease" then - buff.backdrop:SetBackdropBorderColor(1,1,0,1) - else - buff.backdrop:SetBackdropBorderColor(1,0,0,1) - end + local dispelColor = C_UnitAuras.GetAuraDispelTypeColor(aura.dispelName) + buff.backdrop:SetBackdropBorderColor(dispelColor:GetRGBA()) else buff.backdrop:SetBackdropBorderColor(br,bg,bb,ba) end diff --git a/modules/chat.lua b/modules/chat.lua index d112bb71..accf0a27 100644 --- a/modules/chat.lua +++ b/modules/chat.lua @@ -758,20 +758,17 @@ pfUI:RegisterModule("chat", "vanilla:tbc", function () local real, _ = strsplit(":", name) local color = unknowncolorhex local match = false - local class - local guid = GetCurrentChatGUID() - if guid then - _, class = GetPlayerInfoByGUID(guid) - end - if not class then - _, class = C_PlayerCache.GetPlayerInfoByName(real) - end + local _, class = C_PlayerCache.GetPlayerInfoByName(real) + -- local guid = GetCurrentChatGUID() + -- if guid then + -- _, class = GetPlayerInfoByGUID(guid) + -- end if not class then class = GetUnitData(real) end if class then if class ~= UNKNOWN then - color = rgbhex(RAID_CLASS_COLORS[class]) + color = "|c" .. RAID_CLASS_COLORS[class].colorStr match = true end elseif C.chat.text.whosearchunknown == "1" then diff --git a/modules/mapcolors.lua b/modules/mapcolors.lua index ed62a5e0..edf64c08 100644 --- a/modules/mapcolors.lua +++ b/modules/mapcolors.lua @@ -34,9 +34,8 @@ pfUI:RegisterModule("mapcolors", function () local function GetTextureColor(frame) if UnitExists(frame.unit) then - local _, class = UnitClass(frame.unit) - local color = RAID_CLASS_COLORS[class] - return color.r, color.g, color.b + local _, r, g, b = GetUnitColor(frame.unit) + return r, g, b else return .5, 1, .5 end diff --git a/modules/nameplates.lua b/modules/nameplates.lua index 37d1eda0..0da625f2 100644 --- a/modules/nameplates.lua +++ b/modules/nameplates.lua @@ -1269,10 +1269,12 @@ end local r, g, b, a = unpack(unitcolors[unittype]) - if unittype == "ENEMY_PLAYER" and C.nameplates["enemyclassc"] == "1" and class and RAID_CLASS_COLORS[class] then - r, g, b, a = RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b, 1 - elseif unittype == "FRIENDLY_PLAYER" and C.nameplates["friendclassc"] == "1" and class and RAID_CLASS_COLORS[class] then - r, g, b, a = RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b, 1 + if class then + if unittype == "ENEMY_PLAYER" and C.nameplates["enemyclassc"] == "1" then + r, g, b, a = RAID_CLASS_COLORS[class]:GetRGBA() + elseif unittype == "FRIENDLY_PLAYER" and C.nameplates["friendclassc"] == "1" then + r, g, b, a = RAID_CLASS_COLORS[class]:GetRGBA() + end end if unitstr and UnitIsTapped(unitstr) and not UnitIsTappedByPlayer(unitstr) then diff --git a/modules/thirdparty-vanilla.lua b/modules/thirdparty-vanilla.lua index 4cd82fec..c1695116 100644 --- a/modules/thirdparty-vanilla.lua +++ b/modules/thirdparty-vanilla.lua @@ -533,7 +533,7 @@ pfUI:RegisterModule("thirdparty-vanilla", "vanilla", function() hooksecurefunc("WIM_InitClassProps", function() for class in pairs(RAID_CLASS_COLORS) do local wimclass = _G[format("WIM_LOCALIZED_%s",class)] - local colorstr = rgbhex(RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b, RAID_CLASS_COLORS[class].a) + local colorstr = "|c" .. RAID_CLASS_COLORS[class].colorStr _G.WIM_ClassColors[wimclass] = gsub(colorstr, "^|cff", "") end end)