Skip to content

Commit

Permalink
add GroupIcons module
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevcairiel committed Dec 15, 2007
1 parent a0898fb commit 3646e97
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 0 deletions.
Binary file added Artwork/Group1.tga
Binary file not shown.
Binary file added Artwork/Group2.tga
Binary file not shown.
Binary file added Artwork/Group3.tga
Binary file not shown.
Binary file added Artwork/Group4.tga
Binary file not shown.
Binary file added Artwork/Group5.tga
Binary file not shown.
Binary file added Artwork/Group6.tga
Binary file not shown.
Binary file added Artwork/Group7.tga
Binary file not shown.
Binary file added Artwork/Group8.tga
Binary file not shown.
Binary file added Artwork/Normal.tga
Binary file not shown.
131 changes: 131 additions & 0 deletions GroupIcons.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
-- GroupIcons Module for Mapster
-- Idea/Concept/Artwork taken from Cartographer
local Mapster = LibStub("AceAddon-3.0"):GetAddon("Mapster")
local GroupIcons = Mapster:NewModule("GroupIcons", "AceEvent-3.0", "AceTimer-3.0")

local fmt = string.format
local strsub = string.sub
local RAID_CLASS_COLORS = RAID_CLASS_COLORS
local _G = _G

local path = "Interface\\AddOns\\Mapster\\Artwork\\"

local FixUnit, FixWorldMapUnits, FixBattlefieldUnits, UpdateUnitIcon

function GroupIcons:OnEnable()
self:RegisterEvent("PARTY_MEMBERS_UPDATE", "Update")
self:RegisterEvent("RAID_ROSTER_UPDATE", "Update")
self:RegisterEvent("ADDON_LOADED", function(event, addon)
if addon == "Blizzard_BattlefieldMinimap" then
FixBattlefieldUnits(true)
self:Update()
end
end)
self:RegisterEvent("WORLD_MAP_UPDATE", function()
if GetNumRaidMembers() > 0 then
GroupIcons:ScheduleRepeatingTimer("Update", 0.5)
else
GroupIcons:Update()
end
end)

FixWorldMapUnits(true)
end

function GroupIcons:OnDisable()
FixWorldMapUnits(false)
FixBattlefieldUnits(false)
end

function FixUnit(unit, state, isNormal)
local frame = _G[unit]
local icon = _G[unit.."Icon"]
if state then
frame:SetScript("OnUpdate", nil)
if isNormal then
icon:SetTexture(path .. "Normal")
end
else
frame:SetScript("OnUpdate", MapUnit_OnUpdate)
icon:SetVertexColor(1, 1, 1)
icon:SetTexture("Interface\\WorldMap\\WorldMapPartyIcon")
end
end

function FixWorldMapUnits(state)
for i = 1, 4 do
FixUnit(fmt("WorldMapParty%d", i), state, true)
end
for i = 1,40 do
FixUnit(fmt("WorldMapRaid%d", i), state)
end
end

function FixBattlefieldUnits(state)
if BattlefieldMinimap then
for i = 1, 40 do
FixUnit(fmt("BattlefieldMinimapRaid%d", i), state)
end
end
end

function UpdateUnitIcon(tex, unit, flash, isRaid)
local _, fileName = UnitClass(unit)
if isRaid then
local _, _, subgroup = GetRaidRosterInfo(strsub(unit, 5)+0)
if not subgroup or not fileName then return end
tex:SetTexture(fmt("%sGroup%d", path, subgroup))
end
local t = RAID_CLASS_COLORS[fileName]
if flash then
if UnitAffectingCombat(unit) then
-- red flash for units in combat
tex:SetVertexColor(0.8, 0, 0)
elseif UnitIsDeadOrGhost(unit) then
-- dark grey flash for dead units
tex:SetVertexColor(0.2, 0.2, 0.2)
elseif MapUnit_IsInactive(unit) then
-- flash in that blizzard color for inactive units (added in 2.3 iirc)
tex:SetVertexColor(0.5, 0.2, 0)
end
elseif t then -- no flash, set class color
tex:SetVertexColor(t.r, t.g, t.b)
else --fallback grey, you never know what happens
tex:SetVertexColor(0.8, 0.8, 0.8)
end
end

function GroupIcons:Update()
local worldMapShown = WorldMapFrame:IsShown()
local battlefieldMinimapShown = BattlefieldMinimap and BattlefieldMinimap:IsVisible()
if not worldMapShown and not battlefieldMinimapShown then
self:CancelAllTimers()
return
end

local flash = GetTime() % 1 < 0.5

local numRaid = GetNumRaidMembers()
if numRaid > 0 then
for i = 1, numRaid do
local wmUnit = _G[fmt("WorldMapRaid%d", i)].unit
local bmUnit = battlefieldMinimapShown and _G[fmt("BattlefieldMinimapRaid%d", i)].unit
if not (wmUnit or bmUnit) then break end
-- update the world map units
if worldMapShown and wmUnit then
local tex = _G[fmt("WorldMapRaid%dIcon", i)]
UpdateUnitIcon(tex, wmUnit, flash, true)
end
-- update the battlefield minimap units
if bmUnit then
local tex = _G[fmt("BattlefieldMinimapRaid%dIcon", i)]
UpdateUnitIcon(tex, bmUnit, flash, true)
end
end
else
for i = 1, GetNumPartyMembers() do
local tex = _G[fmt("WorldMapParty%dIcon", i)]
UpdateUnitIcon(tex, fmt("party%d", i), flash)
end
end
end
1 change: 1 addition & 0 deletions Mapster.toc
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

Mapster.lua
Coords.lua
GroupIcons.lua

0 comments on commit 3646e97

Please sign in to comment.