mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-24 21:10:49 +00:00
Merge chat class color and player level passes into one loop
This commit is contained in:
+33
-39
@@ -815,60 +815,54 @@ pfUI:RegisterModule("chat", function ()
|
|||||||
text = pfUI.chat:HandleLink(text)
|
text = pfUI.chat:HandleLink(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- display class colors if already indexed
|
-- display class colors and player levels if already indexed
|
||||||
if C.chat.text.classcolor == "1" then
|
local classcolor = C.chat.text.classcolor == "1"
|
||||||
|
local playerlevel = C.chat.text.playerlevel == "1"
|
||||||
|
if classcolor or playerlevel then
|
||||||
-- the engine name-queries a chat sender before the event fires,
|
-- the engine name-queries a chat sender before the event fires,
|
||||||
-- so the sender's GUID always resolves; other names in the text
|
-- so the sender's GUID always resolves; other names in the text
|
||||||
-- fall back to the name-keyed lookups
|
-- fall back to the name-keyed lookups
|
||||||
local _, senderClass, senderRace, senderSex
|
local _, senderClass, senderRace, senderSex
|
||||||
if guid and guid ~= "" then
|
if classcolor and guid and guid ~= "" then
|
||||||
_, senderClass, _, senderRace, senderSex = GetPlayerInfoByGUID(guid)
|
_, senderClass, _, senderRace, senderSex = GetPlayerInfoByGUID(guid)
|
||||||
end
|
end
|
||||||
|
|
||||||
for name in gfind(text, "|Hplayer:(.-)|h") do
|
for name in gfind(text, "|Hplayer:(.-)|h") do
|
||||||
local real, _ = strsplit(":", name)
|
local real, _ = strsplit(":", name)
|
||||||
local color = unknowncolorhex
|
local color, icon = "", ""
|
||||||
local match = false
|
|
||||||
local class, raceKey, sex
|
|
||||||
if senderClass and real == sender then
|
|
||||||
class, raceKey, sex = senderClass, senderRace, senderSex
|
|
||||||
else
|
|
||||||
_, class, _, raceKey, sex = C_PlayerCache.GetPlayerInfoByName(real)
|
|
||||||
end
|
|
||||||
if not class then
|
|
||||||
class = GetUnitInfo(real)
|
|
||||||
end
|
|
||||||
if class and class ~= UNKNOWN then
|
|
||||||
color = "|c" .. PFUI_CLASS_COLORS[class].colorStr
|
|
||||||
match = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if C.chat.text.tintunknown == "1" or match then
|
if classcolor then
|
||||||
local icon = ""
|
local class, raceKey, sex
|
||||||
if match and C.chat.text.playericons == "1" then
|
if senderClass and real == sender then
|
||||||
icon = GetFactionIcon(raceKey) .. GetRaceIcon(raceKey, sex)
|
class, raceKey, sex = senderClass, senderRace, senderSex
|
||||||
|
else
|
||||||
|
_, class, _, raceKey, sex = C_PlayerCache.GetPlayerInfoByName(real)
|
||||||
|
end
|
||||||
|
if not class then
|
||||||
|
class = GetUnitInfo(real)
|
||||||
|
end
|
||||||
|
if class and class ~= UNKNOWN then
|
||||||
|
color = "|c" .. PFUI_CLASS_COLORS[class].colorStr
|
||||||
|
if C.chat.text.playericons == "1" then
|
||||||
|
icon = GetFactionIcon(raceKey) .. GetRaceIcon(raceKey, sex)
|
||||||
|
end
|
||||||
|
elseif C.chat.text.tintunknown == "1" then
|
||||||
|
color = unknowncolorhex
|
||||||
end
|
end
|
||||||
text = string.gsub(text, "|Hplayer:"..name.."|h%["..real.."%]|h(.-:-)",
|
|
||||||
left..icon..color.."|Hplayer:"..name.."|h" .. color .. real .. "|h|r"..right.."%1")
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- display player levels if available
|
|
||||||
if C.chat.text.playerlevel == "1" then
|
|
||||||
for name in gfind(text, "|Hplayer:(.-)|h") do
|
|
||||||
local real, _ = strsplit(":", name)
|
|
||||||
local level = GetPlayerLevel(real)
|
|
||||||
|
|
||||||
|
local suffix = ""
|
||||||
|
local level = playerlevel and GetPlayerLevel(real)
|
||||||
if level and level > 0 then
|
if level and level > 0 then
|
||||||
local levelcolor = rgbhex(GetDifficultyColor(level))
|
suffix = " " .. rgbhex(GetDifficultyColor(level)) .. level .. "|r"
|
||||||
-- Add level after the player name, before the closing bracket
|
elseif level then
|
||||||
text = string.gsub(text, "(|Hplayer:" .. name .. "|h.-|h|r)" .. right,
|
|
||||||
"%1 " .. levelcolor .. level .. "|r" .. right)
|
|
||||||
elseif level and level <= 0 then
|
|
||||||
-- Show ?? for unknown levels (e.g. -1 from UnitLevel)
|
-- Show ?? for unknown levels (e.g. -1 from UnitLevel)
|
||||||
text = string.gsub(text, "(|Hplayer:" .. name .. "|h.-|h|r)" .. right,
|
suffix = " |cffff0000??|r"
|
||||||
"%1 |cffff0000??|r" .. right)
|
end
|
||||||
|
|
||||||
|
if color ~= "" or suffix ~= "" then
|
||||||
|
text = string.gsub(text, "|Hplayer:"..name.."|h%["..real.."%]|h(.-:-)",
|
||||||
|
left..icon..color.."|Hplayer:"..name.."|h" .. color .. real .. "|h|r"..suffix..right.."%1")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user