diff --git a/api/config.lua b/api/config.lua index 3e2754c6..42ba6b5a 100644 --- a/api/config.lua +++ b/api/config.lua @@ -178,6 +178,7 @@ function pfUI:LoadConfig() pfUI:UpdateConfig("appearance", "worldmap", "mapreveal_color", ".4,.4,.4,1") pfUI:UpdateConfig("appearance", "worldmap", "mapexploration", "0") pfUI:UpdateConfig("appearance", "worldmap", "groupcircles", "3") + pfUI:UpdateConfig("appearance", "worldmap", "colornames", "1") pfUI:UpdateConfig("loot", nil, "autoresize", "1") pfUI:UpdateConfig("loot", nil, "autopickup", "1") diff --git a/env/translations_deDE.lua b/env/translations_deDE.lua index 191e01b0..a5248892 100644 --- a/env/translations_deDE.lua +++ b/env/translations_deDE.lua @@ -119,6 +119,7 @@ pfUI_translation["deDE"] = { ["Close"] = nil, ["Color Buff Stacks"] = nil, ["Color Debuff Stacks"] = nil, + ["Colorize player name on WorldMap and BattlefieldMinimap"] = nil, ["Colorize Unknown Classes"] = nil, ["Colors"] = nil, ["Combat"] = nil, diff --git a/env/translations_enUS.lua b/env/translations_enUS.lua index d1d88092..3a427106 100644 --- a/env/translations_enUS.lua +++ b/env/translations_enUS.lua @@ -119,6 +119,7 @@ pfUI_translation["enUS"] = { ["Close"] = nil, ["Color Buff Stacks"] = nil, ["Color Debuff Stacks"] = nil, + ["Colorize player name on WorldMap and BattlefieldMinimap"] = nil, ["Colorize Unknown Classes"] = nil, ["Colors"] = nil, ["Combat"] = nil, diff --git a/env/translations_esES.lua b/env/translations_esES.lua index 407d492b..3fcce592 100644 --- a/env/translations_esES.lua +++ b/env/translations_esES.lua @@ -119,6 +119,7 @@ pfUI_translation["esES"] = { ["Close"] = "Cerrar", ["Color Buff Stacks"] = "Colorear pilas de beneficios", ["Color Debuff Stacks"] = "Colorear pilas de perjuicios", + ["Colorize player name on WorldMap and BattlefieldMinimap"] = nil, ["Colorize Unknown Classes"] = "Colorear clases desconocidas", ["Colors"] = "Colores", ["Combat"] = "Combate", diff --git a/env/translations_frFR.lua b/env/translations_frFR.lua index 2b2f5b33..5e5e061e 100644 --- a/env/translations_frFR.lua +++ b/env/translations_frFR.lua @@ -119,6 +119,7 @@ pfUI_translation["frFR"] = { ["Close"] = "Fermer", ["Color Buff Stacks"] = "Couleur des l'empilements des Améliorations", ["Color Debuff Stacks"] = "Couleur de l'empilements de Affaiblissements", + ["Colorize player name on WorldMap and BattlefieldMinimap"] = nil, ["Colorize Unknown Classes"] = "Colorie les classes inconnues", ["Colors"] = "Couleurs", ["Combat"] = "Combat", diff --git a/env/translations_koKR.lua b/env/translations_koKR.lua index 34e1fb93..49564c91 100644 --- a/env/translations_koKR.lua +++ b/env/translations_koKR.lua @@ -119,6 +119,7 @@ pfUI_translation["koKR"] = { ["Close"] = "닫기", ["Color Buff Stacks"] = nil, ["Color Debuff Stacks"] = nil, + ["Colorize player name on WorldMap and BattlefieldMinimap"] = nil, ["Colorize Unknown Classes"] = nil, ["Colors"] = nil, ["Combat"] = "전투", diff --git a/env/translations_ruRU.lua b/env/translations_ruRU.lua index 962ef158..73a044fa 100644 --- a/env/translations_ruRU.lua +++ b/env/translations_ruRU.lua @@ -119,6 +119,7 @@ pfUI_translation["ruRU"] = { ["Close"] = "Закрыть", ["Color Buff Stacks"] = "Цвет стаков баффа", ["Color Debuff Stacks"] = "Цвет стаков дебаффа", + ["Colorize player name on WorldMap and BattlefieldMinimap"] = "Раскрасить имена игроков на карте мира и миникарте поля боя", ["Colorize Unknown Classes"] = "Раскрасить неизвестные классы", ["Colors"] = "Цвета по умолчанию", ["Combat"] = "Бой", diff --git a/env/translations_zhCN.lua b/env/translations_zhCN.lua index 9122ad53..da4a4369 100644 --- a/env/translations_zhCN.lua +++ b/env/translations_zhCN.lua @@ -119,6 +119,7 @@ pfUI_translation["zhCN"] = { ["Close"] = "关闭", ["Color Buff Stacks"] = "Buff堆叠颜色", ["Color Debuff Stacks"] = "Debuff堆叠颜色", + ["Colorize player name on WorldMap and BattlefieldMinimap"] = nil, ["Colorize Unknown Classes"] = "有色未知职业", ["Colors"] = "颜色", ["Combat"] = "战斗报警", diff --git a/env/translations_zhTW.lua b/env/translations_zhTW.lua index 20a44ad0..d6c4b45e 100644 --- a/env/translations_zhTW.lua +++ b/env/translations_zhTW.lua @@ -119,6 +119,7 @@ pfUI_translation["zhTW"] = { ["Close"] = "關閉", ["Color Buff Stacks"] = nil, ["Color Debuff Stacks"] = nil, + ["Colorize player name on WorldMap and BattlefieldMinimap"] = nil, ["Colorize Unknown Classes"] = "未知職業色彩", ["Colors"] = nil, ["Combat"] = "戰鬥報警", diff --git a/modules/gui.lua b/modules/gui.lua index f3b49419..5387e644 100644 --- a/modules/gui.lua +++ b/modules/gui.lua @@ -1518,6 +1518,7 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function () CreateConfig(U["mapreveal"], T["Map Reveal Color"], C.appearance.worldmap, "mapreveal_color", "color") CreateConfig(U["mapreveal"], T["Map Exploration Points"], C.appearance.worldmap, "mapexploration", "checkbox") CreateConfig(U["mapcolors"], T["Map Group/Raid Circle Size"], C.appearance.worldmap, "groupcircles", "dropdown", pfUI.gui.dropdowns.mapcircle) + CreateConfig(U["mapcolors"], T["Colorize player name on WorldMap and BattlefieldMinimap"], C.appearance.worldmap, "colornames", "checkbox") CreateConfig(U["map"], T["Map Tooltip Scale"], C.appearance.worldmap, "tooltipsize", "dropdown", pfUI.gui.dropdowns.maptooltip) CreateConfig(nil) -- spacer CreateConfig(nil, T["Enable Frame Shadow"], C.appearance.border, "shadow", "checkbox") diff --git a/modules/mapcolors.lua b/modules/mapcolors.lua index d012d5e6..aa9bf19c 100644 --- a/modules/mapcolors.lua +++ b/modules/mapcolors.lua @@ -1,93 +1,152 @@ -- adds class colored circles on world and battlefield map pfUI:RegisterModule("mapcolors", function () - pfUI.mapcolors = CreateFrame("Frame", nil, UIParent) - pfUI.mapcolors:SetScript("OnUpdate", function() - -- throttle to to one item per .1 second - if ( this.tick or 1) > GetTime() then return else this.tick = GetTime() + .1 end - - local frame, icon - - -- initialize all button names - if not this.buttons then - this.buttons = {} - - for i = 1, 4 do - icon = string.format("WorldMapParty%d", i) - this.buttons[icon] = string.format("party%d", i) - end - - for i = 1, 4 do - icon = string.format("BattlefieldMinimapParty%d", i) - this.buttons[icon] = string.format("party%d", i) - end - - for i = 1, 40 do - icon = string.format("BattlefieldMinimapRaid%d", i) - this.buttons[icon] = string.format("raid%d", i) - end - - for i = 1, 40 do - icon = string.format("WorldMapRaid%d", i) - this.buttons[icon] = string.format("raid%d", i) - end + local button_cache = {} + local function Initialize(unit_button_name) + local texture_size = tonumber(C.appearance.worldmap.groupcircles) + for i=1, MAX_PARTY_MEMBERS do + local frame_name = unit_button_name.."Party"..i + local frame = _G[frame_name] + frame.icon = _G[frame_name.."Icon"] + frame.icon:SetTexture(pfUI.media["img:circleparty"]) + frame.icon:SetVertexColor(.5, 1, .5) + SetAllPointsOffset(frame.icon, frame, texture_size, -texture_size) + -- populate cache to default values + button_cache[frame_name] = { + r = .5, g = 1, b = .5 + } end - - -- update all available buttons - local ingroup - for name, unitstr in pairs(this.buttons) do - frame = _G[name] - - if frame and UnitExists(unitstr) then - icon = _G[name.."Icon"] - icon:SetTexture() - - -- create icon if not yet existing - if not frame.pfIcon then - frame.pfIcon = frame:CreateTexture(nil, "OVERLAY") - SetAllPointsOffset(frame.pfIcon, frame, this.size, -this.size) - end - - -- check if unit is in same group - ingroup = nil - for i=1,5 do -- check if unit is in group - if UnitName(string.format("party%d", i)) == UnitName(unitstr) then - ingroup = true + for i=1, MAX_RAID_MEMBERS do + local frame_name = unit_button_name.."Raid"..i + local frame = _G[frame_name] + frame.icon = _G[frame_name.."Icon"] + frame.icon:SetTexture(pfUI.media["img:circleraid"]) + frame.icon:SetVertexColor(.5, 1, .5) + SetAllPointsOffset(frame.icon, frame, texture_size, -texture_size) + -- populate cache to default values + button_cache[frame_name] = { + inParty = false, + r = .5, g = 1, b = .5 + } + end + end + 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 + else + return .5, 1, .5 + end + end + local function UpdateTexture(frame, inParty) + print('UpdateTexture', frame:GetName(), frame.unit, UnitName(frame.unit), UnitClass(frame.unit), inParty) + if inParty then + frame.icon:SetTexture(pfUI.media["img:circleparty"]) + else + frame.icon:SetTexture(pfUI.media["img:circleraid"]) + end + end + local function UpdateTextureColor(frame, r, g, b) + print('UpdateTextureColor', frame:GetName(), frame.unit, UnitName(frame.unit), UnitClass(frame.unit), r, g, b) + frame.icon:SetVertexColor(r, g, b) + end + local function UpdateUnitFrames(unit_button_name) + if GetNumRaidMembers() > 0 then + for i=1, MAX_RAID_MEMBERS do + local frame_name = unit_button_name.."Raid"..i + local frame = _G[frame_name] + local cache = button_cache[frame_name] + if frame.unit then + local inParty = UnitInParty(frame.unit) + if inParty ~= cache.inParty then + cache.inParty = inParty + UpdateTexture(frame, cache.inParty) + end + local r, g, b = GetTextureColor(frame) + if r ~= cache.r or g ~= cache.g or b ~= cache.b then + cache.r, cache.g, cache.b = r, g, b + UpdateTextureColor(frame, cache.r, cache.g, cache.b) end end - - -- update texture according to raid/group state - if ingroup and frame.pfIcon.ingroup ~= "PARTY" then - frame.pfIcon:SetTexture(pfUI.media["img:circleparty"]) - frame.pfIcon.ingroup = "PARTY" - elseif not ingroup and frame.pfIcon.ingroup ~= "RAID" then - frame.pfIcon:SetTexture(pfUI.media["img:circleraid"]) - frame.pfIcon.ingroup = "RAID" - end - - -- detect unit class and set color - local _, class = UnitClass(unitstr) - local color = RAID_CLASS_COLORS[class] - if color then - frame.pfIcon:SetVertexColor(color.r, color.g, color.b) - else - frame.pfIcon:SetVertexColor(.5,1,.5) + end + elseif GetNumPartyMembers() > 0 then + for i=1, MAX_PARTY_MEMBERS do + local frame_name = unit_button_name.."Party"..i + local frame = _G[frame_name] + local cache = button_cache[frame_name] + if frame.unit then + local r, g, b = GetTextureColor(frame) + if r ~= cache.r or g ~= cache.g or b ~= cache.b then + cache.r, cache.g, cache.b = r, g, b + UpdateTextureColor(frame, cache.r, cache.g, cache.b) + end end end end - end) - - pfUI.mapcolors.UpdateConfig = function() - pfUI.mapcolors.size = tonumber(C.appearance.worldmap.groupcircles) - - if not pfUI.mapcolors.buttons then return end - for name, unitstr in pairs(pfUI.mapcolors.buttons) do - frame = _G[name] - - if frame and frame.pfIcon then - SetAllPointsOffset(frame.pfIcon, frame, pfUI.mapcolors.size, -pfUI.mapcolors.size) + end + local function ColorizeName(frame) + local _, class = UnitClass(frame.unit) + local color = RAID_CLASS_COLORS[class] + frame.name = frame.name or UnitName(frame.unit) + frame.name = '|c'..color.colorStr..frame.name..'|r' + end + local function UpdateUnitColors(unit_button_name, tooltip) + local tooltipText = "" + if unit_button_name == 'WorldMap' then + -- Check player + if MouseIsOver(WorldMapPlayer) then + ColorizeName(WorldMapPlayer) + tooltipText = WorldMapPlayer.name + end + end + -- Check party + for i=1, MAX_PARTY_MEMBERS do + local frame = _G[unit_button_name.."Party"..i] + if frame:IsVisible() and MouseIsOver(frame) then + ColorizeName(frame) + tooltipText = tooltipText.."\n"..frame.name + end + end + --Check Raid + for i=1, MAX_RAID_MEMBERS do + local frame = _G[unit_button_name.."Raid"..i] + if frame:IsVisible() and MouseIsOver(frame) then + ColorizeName(frame) + tooltipText = tooltipText.."\n"..frame.name end end + tooltip:SetText(tooltipText) + tooltip:Show() end - pfUI.mapcolors:UpdateConfig() + -- WorldMap + Initialize('WorldMap') + hooksecurefunc('WorldMapButton_OnUpdate', function() + -- throttle to to one item per 1 second + if ( this.tick or .5) > GetTime() then return else this.tick = GetTime() + .5 end + UpdateUnitFrames('WorldMap') + end) + if C.appearance.worldmap.colornames == "1" then + hooksecurefunc('WorldMapUnit_OnEnter', function() + -- throttle to to one item per 1 second + if ( this.tick or .5) > GetTime() then return else this.tick = GetTime() + .5 end + UpdateUnitColors('WorldMap', WorldMapTooltip) + end) + end + -- BattlefieldMinimap + HookAddonOrVariable("Blizzard_BattlefieldMinimap", function() + Initialize('BattlefieldMinimap') + hooksecurefunc('BattlefieldMinimap_OnUpdate', function() + -- throttle to to one item per 1 second + if ( this.tick or .5) > GetTime() then return else this.tick = GetTime() + .5 end + UpdateUnitFrames('BattlefieldMinimap') + end) + if C.appearance.worldmap.colornames == "1" then + hooksecurefunc('BattlefieldMinimapUnit_OnEnter', function() + -- throttle to to one item per 1 second + if ( this.tick or .5) > GetTime() then return else this.tick = GetTime() + .5 end + UpdateUnitColors('BattlefieldMinimap', GameTooltip) + end) + end + end) end)