View Single Post
08-01-14, 04:42 AM   #1
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
replacing map blips

I have a small function that intends to bring back old cartographer-style world map blips - with embedded group #s and colour changes when the unit is in specific conditions like combat or AFK.

Lua Code:
  1. --
  2.     local blippadding = 5
  3.     --
  4.  
  5.     local frame = CreateFrame("Frame", nil, WorldMapFrame)
  6.     local frequency = .5 -- how often to update blips (while in group when map shown)
  7.     local timer = frequency
  8.     frame:Hide()
  9.  
  10.     frame:SetScript("OnUpdate", function(self, elapsed)
  11.         timer = timer + elapsed
  12.         if (timer > frequency) then
  13.             timer = 0
  14.             local groupSize = GetNumGroupMembers()
  15.             local groupUnit = IsInRaid() and "Raid" or "Party"
  16.            
  17.             if (groupSize > 0) then
  18.                 for i = 1, groupSize do
  19.                     local blip = _G["WorldMap"..groupUnit..i]
  20.                     local blipoverlay = blip:CreateTexture(nil, "OVERLAY")
  21.                     blipoverlay:SetDrawLayer("OVERLAY", 7)
  22.                     blipoverlay:SetPoint("TOPLEFT", blip.icon, -blippadding, blippadding)
  23.                     blipoverlay:SetPoint("BOTTOMRIGHT", blip.icon, blippadding, -blippadding)
  24.                    
  25.                     if blip and blip.unit and blip:IsVisible() then
  26.                         local _, class = UnitClass(blip.unit)
  27.                         local _, _, subgroup = GetRaidRosterInfo(i)
  28.                        
  29.                         if not blip.skinned then
  30.                             if (UnitInRaid(blip.unit)) then
  31.                                 blipoverlay:SetTexture(format("Interface\\AddOns\\WorldMapForModernists\\blips\\raid%d", subgroup))
  32.                             else
  33.                                 blipoverlay:SetTexture("Interface\\AddOns\\WorldMapForModernists\\blips\\party")
  34.                             end
  35.                             blip.skinned = true
  36.                        end
  37.                        
  38.                        if (blip.skinned) then
  39.                             -- color the texture
  40.                             local color = CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS[class]
  41.                             -- by class
  42.                             if color then
  43.                                 blipoverlay:SetVertexColor(color.r, color.g, color.b)
  44.                             -- fallback
  45.                             else
  46.                                 blipoverlay:SetVertexColor(103/255, 103/255, 103/255)
  47.                             end
  48.                        
  49.                             if (GetTime() % 1 < .5) then
  50.                                 -- combat (flashing)
  51.                                 if UnitAffectingCombat(blip.unit) then
  52.                                     blipoverlay:SetVertexColor(1, 0, 0)
  53.                                 -- dead (flashing)
  54.                                 elseif UnitIsDeadOrGhost(blip.unit) then
  55.                                     blipoverlay:SetVertexColor(.2, .2, .2)
  56.                                 -- AFK (flashing)
  57.                                 elseif UnitIsAFK(blip.unit) then
  58.                                     blipoverlay:SetVertexColor(255/255, 206/255, 206/255)
  59.                                 end
  60.                             end
  61.                         end
  62.                     end
  63.                 end
  64.             end
  65.         end
  66.     end)
  67.  
  68.     frame:SetScript("OnEvent",function(self,event)
  69.         timer = frequency
  70.         self:SetShown(IsInGroup())
  71.     end)
  72.    
  73.     frame:RegisterEvent("GROUP_ROSTER_UPDATE")
  74.     frame:RegisterEvent("WORLD_MAP_UPDATE")

the colour updates currently won't update like this. If I remove the blip.skinned check on line 25 then it does update as intended, but I assume that's because it's creating a new texture on every pass which is understandably a very bad thing. I recognise that this is probably written very badly, so what do I need to do to make this work?
  Reply With Quote