diff --git a/api/api.lua b/api/api.lua index a6f9cf2f..faa12971 100644 --- a/api/api.lua +++ b/api/api.lua @@ -262,6 +262,45 @@ function pfUI.api.GetUnitColor(unitstr) return classColor:GenerateHexColorMarkup(), classColor:GetRGB() end +-- [ GetRaceIcon ] +-- Builds an inline race icon texture from the shared races atlas. +-- 'raceKey' [string] englishRace key (e.g. "NightElf") +-- 'sex' [int] unit sex (3 = female) +-- return: [string] inline texture escape, or an empty string +function pfUI.api.GetRaceIcon(raceKey, sex) + if not raceKey then return "" end + local gender = sex == 3 and "FEMALE" or "MALE" + local coords = RACE_ICON_TCOORDS[strupper(raceKey) .. "_" .. gender] + if not coords then return "" end + return string.format( + "|TInterface\\Glues\\CharacterCreate\\UI-CharacterCreate-Races:0:0:0:0:512:512:%d:%d:%d:%d|t", + coords[1] * 512, coords[2] * 512, coords[3] * 512, coords[4] * 512) +end + +-- inline faction emblems (cropped from the target-frame PvP banners) +local FACTION_ICON = { + Alliance = "|TInterface\\TargetingFrame\\UI-PVP-Alliance:0:0:0:0:64:64:5:37:3:35|t", + Horde = "|TInterface\\TargetingFrame\\UI-PVP-Horde:0:0:0:0:64:64:5:37:3:35|t", +} + +-- [ GetFactionIcon ] +-- Resolves an inline faction emblem from the englishRace key stored in L["race"]. +-- 'raceKey' [string] englishRace key (e.g. "Orc") +-- return: [string] inline texture escape, or an empty string +function pfUI.api.GetFactionIcon(raceKey) + local info = raceKey and L["race"][raceKey] + if not info then return "" end + return FACTION_ICON[info.faction] or "" +end + +-- [ GetPlayerRaceIcons ] +-- Returns the faction and race emblems of the player character. +-- return: [string] both inline textures, or an empty string +function pfUI.api.GetPlayerRaceIcons() + local _, raceKey = UnitRace("player") + return pfUI.api.GetFactionIcon(raceKey) .. pfUI.api.GetRaceIcon(raceKey, UnitSex("player")) +end + -- [ strvertical ] -- Creates vertical text using linebreaks. Multibyte char friendly. -- 'str' [string] String to columnize. diff --git a/api/config.lua b/api/config.lua index d5f67302..7e917a07 100644 --- a/api/config.lua +++ b/api/config.lua @@ -817,6 +817,7 @@ function pfUI:LoadConfig() pfUI:UpdateConfig("chat", "text", "playerlinks", "1") pfUI:UpdateConfig("chat", "text", "detecturl", "1") pfUI:UpdateConfig("chat", "text", "classcolor", "1") + pfUI:UpdateConfig("chat", "text", "playericons", "0") pfUI:UpdateConfig("chat", "text", "whosearchunknown", "0") pfUI:UpdateConfig("chat", "text", "playerlevel", "0") pfUI:UpdateConfig("chat", "left", "width", "380") diff --git a/env/tables.lua b/env/tables.lua index 3b129c48..be913f73 100644 --- a/env/tables.lua +++ b/env/tables.lua @@ -12,6 +12,33 @@ CLASS_ICON_TCOORDS = CLASS_ICON_TCOORDS or { ["GM"] = {0.5, 0.73828125, 0.5, .75}, } +-- race icons live in Interface\Glues\CharacterCreate\UI-CharacterCreate-Races +-- keyed by RACEKEY_GENDER (englishRace .. sex); mirrors the GlueXML table, +-- which isn't loaded in-world. includes the Turtle-specific BloodElf/Goblin. +RACE_ICON_TCOORDS = RACE_ICON_TCOORDS or { + ["HUMAN_MALE"] = {0, 0.125, 0, 0.25}, + ["DWARF_MALE"] = {0.125, 0.25, 0, 0.25}, + ["GNOME_MALE"] = {0.25, 0.375, 0, 0.25}, + ["NIGHTELF_MALE"] = {0.375, 0.5, 0, 0.25}, + ["TAUREN_MALE"] = {0, 0.125, 0.25, 0.5}, + ["SCOURGE_MALE"] = {0.125, 0.25, 0.25, 0.5}, + ["TROLL_MALE"] = {0.25, 0.375, 0.25, 0.5}, + ["ORC_MALE"] = {0.375, 0.5, 0.25, 0.5}, + ["BLOODELF_MALE"] = {0.5, 0.625, 0.25, 0.5}, + ["GOBLIN_MALE"] = {0.5, 0.625, 0, 0.25}, + + ["HUMAN_FEMALE"] = {0, 0.125, 0.5, 0.75}, + ["DWARF_FEMALE"] = {0.125, 0.25, 0.5, 0.75}, + ["GNOME_FEMALE"] = {0.25, 0.375, 0.5, 0.75}, + ["NIGHTELF_FEMALE"] = {0.375, 0.5, 0.5, 0.75}, + ["TAUREN_FEMALE"] = {0, 0.125, 0.75, 1.0}, + ["SCOURGE_FEMALE"] = {0.125, 0.25, 0.75, 1.0}, + ["TROLL_FEMALE"] = {0.25, 0.375, 0.75, 1.0}, + ["ORC_FEMALE"] = {0.375, 0.5, 0.75, 1.0}, + ["BLOODELF_FEMALE"] = {0.5, 0.625, 0.75, 1.0}, + ["GOBLIN_FEMALE"] = {0.5, 0.625, 0.5, 0.75}, +} + -- barlength = {[formfactor]={cols, rows}} pfGridmath = { [1] = {{1,1}}, diff --git a/modules/chat.lua b/modules/chat.lua index 79c96799..0781b4b2 100644 --- a/modules/chat.lua +++ b/modules/chat.lua @@ -827,7 +827,7 @@ pfUI:RegisterModule("chat", function () local real, _ = strsplit(":", name) local color = unknowncolorhex local match = false - local _, class = C_PlayerCache.GetPlayerInfoByName(real) + local _, class, _, raceKey, sex = C_PlayerCache.GetPlayerInfoByName(real) -- local guid = GetCurrentChatGUID() -- if guid then -- _, class = GetPlayerInfoByGUID(guid) @@ -845,8 +845,12 @@ pfUI:RegisterModule("chat", function () end if C.chat.text.tintunknown == "1" or match then + local icon = "" + if match and C.chat.text.playericons == "1" then + icon = GetFactionIcon(raceKey) .. GetRaceIcon(raceKey, sex) + end text = string.gsub(text, "|Hplayer:"..name.."|h%["..real.."%]|h(.-:-)", - left..color.."|Hplayer:"..name.."|h" .. color .. real .. "|h|r"..right.."%1") + left..icon..color.."|Hplayer:"..name.."|h" .. color .. real .. "|h|r"..right.."%1") end end end diff --git a/modules/gui.lua b/modules/gui.lua index 6ccdb426..7ebe729a 100644 --- a/modules/gui.lua +++ b/modules/gui.lua @@ -2867,6 +2867,7 @@ pfUI:RegisterModule("gui", function () CreateConfig(nil, T["Generate Playerlinks"], C.chat.text, "playerlinks", "checkbox") CreateConfig(nil, T["Enable URL Detection"], C.chat.text, "detecturl", "checkbox") CreateConfig(nil, T["Enable Class Colors"], C.chat.text, "classcolor", "checkbox") + CreateConfig(nil, T["Show Faction & Race Icons"] .. " " .. GetPlayerRaceIcons(), C.chat.text, "playericons", "checkbox") CreateConfig(nil, T["Enable Player Levels"], C.chat.text, "playerlevel", "checkbox") CreateConfig(nil, T["Who Search Unknown Classes (|cffffaaaaExperimental|r)"], C.chat.text, "whosearchunknown", "checkbox") CreateConfig(nil, T["Colorize Unknown Classes"], C.chat.text, "tintunknown", "checkbox")