Skip to content

Commit

Permalink
mapcolors: remove unnecessary function call
Browse files Browse the repository at this point in the history
- add line breaks between function definitions
- remove debug output and misleading comments
  • Loading branch information
shagu committed Jun 7, 2024
1 parent f5dcfa6 commit cecc334
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions modules/mapcolors.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand All @@ -29,6 +31,7 @@ pfUI:RegisterModule("mapcolors", function ()
}
end
end

local function GetTextureColor(frame)
if UnitExists(frame.unit) then
local _, class = UnitClass(frame.unit)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -78,72 +78,77 @@ 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
ColorizeName(frame)
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
ColorizeName(frame)
tooltipText = tooltipText.."\n"..frame.name
end
end

tooltip:SetText(tooltipText)
tooltip:Show()
end

-- 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)
Expand Down

0 comments on commit cecc334

Please sign in to comment.