From c38c6fdb373dddb4cb09df28b5f94b7a8a86b091 Mon Sep 17 00:00:00 2001 From: Zidras <10605951+Zidras@users.noreply.github.com> Date: Wed, 11 Sep 2024 09:31:57 +0100 Subject: [PATCH] PVP: add class color to flag carrier --- DBM-PvP/PvPGeneral.lua | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/DBM-PvP/PvPGeneral.lua b/DBM-PvP/PvPGeneral.lua index 618c1c9b..8b69e1d1 100644 --- a/DBM-PvP/PvPGeneral.lua +++ b/DBM-PvP/PvPGeneral.lua @@ -4,7 +4,7 @@ local L = mod:GetLocalizedStrings() local DBM = DBM local AceTimer = LibStub("AceTimer-3.0") -mod:SetRevision("20220827002800") +mod:SetRevision("20240910182741") mod:SetZone(DBM_DISABLE_ZONE_DETECTION) mod:RegisterEvents( @@ -35,7 +35,7 @@ do end -- Utility functions -local format, strsplit = string.format, strsplit +local format, strfind, strsplit = string.format, strfind, strsplit local hooksecurefunc = hooksecurefunc local IsActiveBattlefieldArena, FauxScrollFrame_GetOffset, GetBattlefieldScore, GetNumBattlefieldScores, GetUnitName, UnitFactionGroup, UnitName = IsActiveBattlefieldArena, FauxScrollFrame_GetOffset, GetBattlefieldScore, GetNumBattlefieldScores, GetUnitName, UnitFactionGroup, UnitName local MAX_WORLDSTATE_SCORE_BUTTONS, CUSTOM_CLASS_COLORS, RAID_CLASS_COLORS = MAX_WORLDSTATE_SCORE_BUTTONS, CUSTOM_CLASS_COLORS, RAID_CLASS_COLORS @@ -237,13 +237,36 @@ local function HideFlagDisplay() end end +local function colorizeFlagName(name) +-- if not mod.Options.ColorByClass then return name end + local classUpper + for i = 1, GetNumBattlefieldScores() do + local nameScoreboard, _, _, _, _, _, _, _, _, classToken = GetBattlefieldScore(i) + local noRealmName = strsplit("-", nameScoreboard) -- remove realm name, since Flag msg events never contain realm name + if noRealmName == name then + classUpper = classToken + break + end + end + if classUpper then + if CUSTOM_CLASS_COLORS then + local classTextColor = CUSTOM_CLASS_COLORS[classUpper] + local hexClassColor = format("ff%02X%02X%02X", 255 * classTextColor.r, 255 * classTextColor.g, 255 * classTextColor.b) + name = format("|c%s%s|r", hexClassColor, name) + else + name = format("|c%s%s|r", RAID_CLASS_COLORS[classUpper].colorStr, name) + end + end + return name +end + local function UpdateFlagDisplay() if flagFrame1Text and flagFrame2Text then if allyFlag then if GetCurrentMapAreaID() == 483 then -- EotS - flagFrame1Text:SetText(L.Flag..": "..allyFlag) + flagFrame1Text:SetText(L.Flag..": "..colorizeFlagName(allyFlag)) else - flagFrame1Text:SetText(allyFlag) + flagFrame1Text:SetText(colorizeFlagName(allyFlag)) end flagButton1:SetAttribute("macrotext", "/targetexact "..allyFlag) else @@ -253,9 +276,9 @@ local function UpdateFlagDisplay() if hordeFlag then if GetCurrentMapAreaID() == 483 then -- EotS - flagFrame2Text:SetText(L.Flag..": "..hordeFlag) + flagFrame2Text:SetText(L.Flag..": "..colorizeFlagName(hordeFlag)) else - flagFrame2Text:SetText(hordeFlag) + flagFrame2Text:SetText(colorizeFlagName(hordeFlag)) end flagButton2:SetAttribute("macrotext", "/targetexact "..hordeFlag) else