Quantcast
World map overlay frame and SetMovable - WoWInterface
Thread Tools Display Modes
09-13-20, 12:18 AM   #1
maqjav
A Cyclonian
Join Date: Feb 2012
Posts: 49
World map overlay frame and SetMovable

Hello.

I'm adding a new overlay frame to my world map that contains one frame.
I'm trying to allow the user to move this frame on drag and drop.

The problem I'm finding is that if the frame is not movable, whenever I minimize/maximize the world map my frame adapts to the world map container correcly remaining in the correct position, but as soon as I make it movable, the frame detaches from the world map and it doesn't adapt anymore, so if in the maximized version it appears in the top right corner of the map, in the minimize version it appears on top of my minimap.

Is it posible to keep my frame inside the world map and maintain the last position while maximized/minimized?

This is my code:

Code:
WorldMapFrame:AddOverlayFrame("MyTemplate", "FRAME", "CENTER", WorldMapFrame:GetCanvasContainer(), "TOP", 0, 0);

MyTemplateMixin = { };

function MyTemplateMixin:OnLoad() 
  self.MyFrame:SetMovable(true)
  self.MyFrame:RegisterForDrag("LeftButton")
  self.MyFrame:SetScript("OnDragStart", function(self)
    self:StartMoving()
  end)
  
  self.MyFrame:SetScript("OnDragStop", function(self)
    self:StopMovingOrSizing()
  end)
end

function MyTemplateMixin:Refresh()

end

MyFrameMixin = { }

function MyFrameMixin:OnMouseEnter()

end

function MyFrameMixin:OnMouseLeave()

end
And my template:
Code:
<?xml version="1.0"?>
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/..\FrameXML\UI.xsd">

  <Script file="MyTemplateMixin.lua"/>

  <Frame name="MyTemplate" frameStrata="HIGH" mixin="MyTemplateMixin" virtual="true">
    <Size x="175" y="32" />
	<Frames>
    	   <Frame parentKey="MyFrame" mixin="MyFrameMixin">
		<Size>
		   <AbsDimension x="175" y="32"></AbsDimension>
		</Size>
		<Anchors>
		   <Anchor point="CENTER"/>
		</Anchors>
		<Layers>
		   <Layer level="BACKGROUND">
			<Texture file="Interface\ChatFrame\UI-ChatInputBorder-Left">
				<Size>
					<AbsDimension x="75" y="32"></AbsDimension>
				</Size>
				<Anchors>
					<Anchor point="LEFT">
						<Offset>
							<AbsDimension x="-15" y="0"></AbsDimension>
						</Offset>
					</Anchor>
				</Anchors>
			</Texture>
		</Layer>
	</Layers>
	<Scripts>
	  	<OnEnter method="OnMouseEnter"/>
	  	<OnLeave method="OnMouseLeave"/>
	</Scripts>
      </Frame>
    </Frames>
    <Scripts>
      <OnLoad method="OnLoad" />
    </Scripts>
  </Frame>

</Ui>
Thanks.
  Reply With Quote
09-17-20, 08:15 PM   #2
DahkCeles
A Fallenroot Satyr
 
DahkCeles's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2020
Posts: 23
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

WoWInterface » Developer Discussions » Lua/XML Help » World map overlay frame and SetMovable

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off