diff --git a/modules/mapcolors.lua b/modules/mapcolors.lua index aa9bf19c..ed62a5e0 100644 --- a/modules/mapcolors.lua +++ b/modules/mapcolors.lua @@ -1,6 +1,7 @@ -- adds class colored circles on world and battlefield map pfUI:RegisterModule("mapcolors", function () local button_cache = {} + local function Initialize(unit_button_name) local texture_size = tonumber(C.appearance.worldmap.groupcircles) for i=1, MAX_PARTY_MEMBERS do @@ -15,6 +16,7 @@ pfUI:RegisterModule("mapcolors", function () r = .5, g = 1, b = .5 } end + for i=1, MAX_RAID_MEMBERS do local frame_name = unit_button_name.."Raid"..i local frame = _G[frame_name] @@ -29,6 +31,7 @@ pfUI:RegisterModule("mapcolors", function () } end end + local function GetTextureColor(frame) if UnitExists(frame.unit) then local _, class = UnitClass(frame.unit) @@ -38,18 +41,15 @@ pfUI:RegisterModule("mapcolors", function () 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 @@ -65,7 +65,7 @@ pfUI:RegisterModule("mapcolors", function () 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) + frame.icon:SetVertexColor(cache.r, cache.g, cache.b) end end end @@ -78,28 +78,31 @@ pfUI:RegisterModule("mapcolors", function () 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) + frame.icon:SetVertexColor(cache.r, cache.g, cache.b) end end end end 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 + -- check player if MouseIsOver(WorldMapPlayer) then ColorizeName(WorldMapPlayer) tooltipText = WorldMapPlayer.name end end - -- Check party + + -- check party for i=1, MAX_PARTY_MEMBERS do local frame = _G[unit_button_name.."Party"..i] if frame:IsVisible() and MouseIsOver(frame) then @@ -107,7 +110,8 @@ pfUI:RegisterModule("mapcolors", function () tooltipText = tooltipText.."\n"..frame.name end end - --Check Raid + + --check Raid for i=1, MAX_RAID_MEMBERS do local frame = _G[unit_button_name.."Raid"..i] if frame:IsVisible() and MouseIsOver(frame) then @@ -115,6 +119,7 @@ pfUI:RegisterModule("mapcolors", function () tooltipText = tooltipText.."\n"..frame.name end end + tooltip:SetText(tooltipText) tooltip:Show() end @@ -122,28 +127,28 @@ pfUI:RegisterModule("mapcolors", function () -- 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)