mirror of
https://github.com/brues-code/pfUI.git
synced 2026-09-21 23:26:56 +00:00
Cache player color codes and use full ARGB hex
Replace the cfgColorToHex function with a memoized table. The table caches the color code for each config string on first use. Build the code with C_ColorUtil.GenerateTextColorCode instead of string.format. Change the spell-school colors and the format strings to 8-character ARGB hex with the |c prefix.
This commit is contained in:
+15
-12
@@ -39,17 +39,20 @@ pfUI:RegisterModule("player", function ()
|
|||||||
playerFrame.isSpellCaster = myclass ~= "WARRIOR" and myclass ~= "ROGUE" and myclass ~= "HUNTER"
|
playerFrame.isSpellCaster = myclass ~= "WARRIOR" and myclass ~= "ROGUE" and myclass ~= "HUNTER"
|
||||||
|
|
||||||
-- Convert "r,g,b,a" config color string to a 6-char hex string, or nil if unset
|
-- Convert "r,g,b,a" config color string to a 6-char hex string, or nil if unset
|
||||||
local function cfgColorToHex(colorStr)
|
local cfgColorToHexTable = setmetatable({}, {
|
||||||
if not colorStr or colorStr == "" then return nil end
|
__index = function (t, colorStr)
|
||||||
local r, g, b = GetStringColor(colorStr)
|
if not colorStr or colorStr == "" then return nil end
|
||||||
r, g, b = tonumber(r), tonumber(g), tonumber(b)
|
local r, g, b = GetStringColor(colorStr)
|
||||||
if not r or not g or not b then return nil end
|
if not r or not g or not b then return nil end
|
||||||
return string.format("%02X%02X%02X", r * 255, g * 255, b * 255)
|
local hex = C_ColorUtil.GenerateTextColorCode({ r=r, g = g, b=b})
|
||||||
end
|
rawset(t, colorStr, hex)
|
||||||
|
return hex
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
-- SP school colors indexed by GetSpellBonusDamage's 1-based school order
|
-- SP school colors indexed by GetSpellBonusDamage's 1-based school order
|
||||||
-- (1=phys, 2=holy, 3=fire, 4=nature, 5=frost, 6=shadow, 7=arcane)
|
-- (1=phys, 2=holy, 3=fire, 4=nature, 5=frost, 6=shadow, 7=arcane)
|
||||||
local spColors = { "FFFFFF", "FFFF80", "FF8000", "4DFF4D", "80FFFF", "9482C9", "FFFFFF" }
|
local spColors = { "FFFFFFFF", "FFFFFF80", "FFFF8000", "FF4DFF4D", "FF80FFFF", "FF9482C9", "FFFFFFFF" }
|
||||||
|
|
||||||
-- Default SP school per class used as tiebreaker when multiple schools are equal
|
-- Default SP school per class used as tiebreaker when multiple schools are equal
|
||||||
local spDefaultSchool = {
|
local spDefaultSchool = {
|
||||||
@@ -81,8 +84,8 @@ pfUI:RegisterModule("player", function ()
|
|||||||
local text = ""
|
local text = ""
|
||||||
|
|
||||||
if showHaste and isSpellCaster and haste then
|
if showHaste and isSpellCaster and haste then
|
||||||
local hasteHex = cfgColorToHex(cfg.display_haste_color) or "FFFFFF"
|
local hasteHex = cfgColorToHexTable[cfg.display_haste_color] or "FFFFFFFF"
|
||||||
text = string.format("|cff%s%.1f%%|r", hasteHex, haste)
|
text = string.format("|c%s%.1f%%|r", hasteHex, haste)
|
||||||
end
|
end
|
||||||
|
|
||||||
if showSP and isSpellCaster then
|
if showSP and isSpellCaster then
|
||||||
@@ -97,9 +100,9 @@ pfUI:RegisterModule("player", function ()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if maxSP > 0 then
|
if maxSP > 0 then
|
||||||
local spHex = (cfg.display_sp_color_override == "1" and cfgColorToHex(cfg.display_sp_color)) or maxColor
|
local spHex = (cfg.display_sp_color_override == "1" and cfgColorToHexTable[cfg.display_sp_color]) or maxColor
|
||||||
if text ~= "" then text = text .. " " end
|
if text ~= "" then text = text .. " " end
|
||||||
text = text .. string.format("|cff%s+%d SP|r", spHex, maxSP)
|
text = text .. string.format("|c%s+%d SP|r", spHex, maxSP)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user