View Single Post
04-12-20, 08:53 AM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Here's my take on it. I would suggest trying to insert custom pins in the MapCanvas system, but I haven't dug around it ever since it was implemented. There isn't a way to delete UI objects without a logout or UI reload, so you have to create a pool of them by storing them in a table you grab from. There's no reason to loop through and hide the icons OnHide. The "cleanup" is handled with the next OnShow.

Lua Code:
  1. local IconTextures={};--    Table to store our textures
  2.  
  3. local function MapTest_UpdateIcons()
  4.     local numshow=(amount_to_be_decided);
  5.  
  6.     local textureindex=1;-- We increment this when we grab a texture
  7.     for index=1,numshow do
  8.         if (logic_to_be_decided) then
  9.             local icon=IconTextures[textureindex];--    Fetch texture from table
  10.             if not icon then--  Texture not created yet (We don't want gaps in the table or it'll mess with the table length operation we use later)
  11.                 icon=WorldMapDetailFrame:CreateTexture(nil,"OVERLAY");
  12.                 icon:SetTexture("Interface\\AddOns\\MapTest\\AvailableQuestIcon.blp");
  13.                 icon:SetSize(16,16);
  14.  
  15.                 IconTextures[textureindex]=icon;--  Store in table
  16.             end
  17.  
  18.             local width,height=WorldMapDetailFrame:GetSize();
  19.             icon:SetPoint("CENTER",WorldMapDetailFrame,"TOPLEFT",(XPos/100)*width,(YPos/100)*height);-- Move to coordinates
  20.             icon:Show();--  Show texture
  21.  
  22.             textureindex=textureindex+1;--  Increment index
  23.         end
  24.     end
  25.  
  26.     for index=textureindex,#IconTextures do--   Iterate through icons we haven't updated yet (textureindex will point to the first unused in the list, doesn't run if there are no unused textures (start > end))
  27.         IconTextures[index]:Hide();--   Hide them
  28.     end
  29. end
  30.  
  31. WorldMapFrame:HookScript("OnShow",MapTest_UpdateIcons);--   Map Opened
  32. WorldMapFrame:HookScript("OnSizeChanged",MapTest_UpdateIcons);--    Map Resized
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-12-20 at 08:58 AM.
  Reply With Quote