View Single Post
09-17-20, 08:15 PM   #2
DahkCeles
A Cliff Giant
 
DahkCeles's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2020
Posts: 73
If you are trying to build an overlay over the entire map frame (its borders, UI elements, etc.), then something like this might help:

Lua Code:
  1. local function myFunction()
  2.   local isMaximized = WorldMapFrame:IsMaximized()
  3.   -- do something
  4. end
  5.  
  6. hooksecurefunc(WorldMapFrame.BorderFrame.MaximizeMinimizeFrame, "Maximize", myFunction)
  7. hooksecurefunc(WorldMapFrame.BorderFrame.MaximizeMinimizeFrame, "Minimize", myFunction)


If you are trying to build something on the map canvas itself which appears at an x/y coordinate and can be dragged to another x/y coordinate, then you should take a look at MapCanvas_DataProviderBase.lua.

Lua Code:
  1. MyAddonSavedVariables = { }
  2.  
  3. MyPinMixin = CreateFromMixins(MapCanvasPinMixin)
  4.  
  5. MyPinMixin:OnAcquired(id, x, y)
  6.     self:SetPosition(x,y)
  7.     self.id = id
  8. end
  9.  
  10. MyPinMixin:OnLoad()
  11.     -- placeholder appearance for testing
  12.     self:SetSize(20, 20)
  13.     self.texture = self:CreateTexture(nil, "ARTWORK")
  14.     self.texture:SetTexture("Interface\\RaidFrame\\UI-RaidFrame-Threat")
  15.     self.texture:SetAllPoints()
  16.  
  17.     -- draggable to a new map coordinate
  18.     self:RegisterForDrag("RightButton")
  19.     self:HookScript("OnDragEnd", function()
  20.         local x, y = self:GetMap():GetNormalizedCursorPosition()
  21.         x = x and Clamp(x, 0.05, 0.95) or 0.5  -- stay a little inside the box
  22.         y = y and Clamp(y, 0.05, 0.95) or 0.5
  23.         MyAddonSavedVariables[self.id]["x"] = x
  24.         MyAddonSavedVariables[self.id]["y"] = y
  25.         self:SetPosition(x,y)
  26.     end)
  27. end
  28.  
  29. MyDataProvider = CreateFromMixins(MapCanvasDataProviderMixin)
  30.  
  31. MyDataProvider:RefreshAllData()
  32.     self:RemoveAllData()
  33.     for id, coords in ipairs(MyAddonSavedVariables) do
  34.         self:GetMap():AcquirePin("MyPinTemplate", id, coords.x, coords.y)
  35.     end
  36. end
  37.  
  38. WorldMapFrame:AddDataProvider(MyDataProvider)
  39.  
  40.  
  41. -- placeholder just to create a single pin for testing
  42. local listener = CreateFrame("Frame")
  43. listener:RegisterEvent("PLAYER_LOGIN")
  44. listener:SetScript("OnEvent", function()
  45.     if #MyAddonSavedVariables == 0 then
  46.         tinsert(MyAddonSavedVariables, {0.5, 0.5})
  47.     end
  48. end)

XML Code:
  1. <Ui>
  2.     <Frame name="MyPinTemplate" mixin="MyPinMixin" virtual="true"></Frame>
  3. </Ui>

toc Code:
  1. ## SavedVariables: MyAddonSavedVariables

Disclaimer: I just quickly wrote this together by taking snippets of a much longer file. I'm probably missing something to make it work.
  Reply With Quote