WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Need help with WorldMapDataProvider (https://www.wowinterface.com/forums/showthread.php?t=58048)

oldZifnab 06-13-20 01:47 AM

Need help with WorldMapDataProvider
 
3 Attachment(s)
Hi, I am trying to extend my AddOn with Icons on the Zone Maps, but... when I last did this Kind of stuff (around BC times), the WorldMap was a simple Frame like any other and Nothing with data Providers and all this.
So I tried to figure it out but it doesn't Show me any Icon.
Can anyone push me the Right way?

Here is the sample code I wrote to understand how all this works:

WorldmapSample.xml:
Code:

<Ui xmlns="http://www.blizzard.com/wow/ui/">
        <Script file="WorldmapSample.lua"/>

        <Frame name="WorldmapSamplePinTemplate" hidden="false" enableMouse="true" mixin="WorldmapSamplePinMixin" virtual="true">
                <Size x="12" y="12"/>
                <Layers><Layer level="OVERLAY"><Texture parentKey="texture" setAllPoints="true"></Texture></Layer></Layers>
        </Frame>
</Ui>

WorldmapSample.lua:
Code:

local Me=CreateFrame("Frame","WorldmapSampleFrame")
local pins={}
Me.WorldMapDataProvider = CreateFromMixins(MapCanvasDataProviderMixin)
WorldmapSamplePinMixin = CreateFromMixins(MapCanvasPinMixin)
WorldMapFrame:AddDataProvider(Me.WorldMapDataProvider)
print("WorldmapSample loaded")

-- WORLDMAP REMOVE DATA
function Me.WorldMapDataProvider:RemoveAllData()
        self:GetMap():RemoveAllPinsByTemplate("WorldmapSamplePinTemplate")
        wipe(pins)
        print("wiped pins")
end

-- WORLDMAP REFRESH DATA
function Me.WorldMapDataProvider:RefreshAllData()
        self:RemoveAllData()
        local mapid = self:GetMap():GetMapID()
        if mapid then
                local pin=self:GetMap():AcquirePin("WorldmapSamplePinTemplate", mapid, 50,50)
                table.insert(pins, pin)               
        end
end

-- WORLDMAP PIN MIXIN : ON LOAD
function WorldmapSamplePinMixin:OnLoad()
        self:UseFrameLevelType("PIN_FRAME_LEVEL_AREA_POI")
        self:SetScalingLimits(1, 1.0, 1.2)
end

-- WORLDMAP PIN MIXIN : ON ACQUIRED
function WorldmapSamplePinMixin:OnAcquired(mapid, x,y)
        self:SetPosition(x, y)
        self:SetBackdrop(nil)
        self.texture:SetTexture("Interface/AddOns/WorldmapSample/unknown.tga")
        self:SetSize(12,12)
        self.texture:SetTexCoord(0, 1, 0, 1)
        self.texture:SetVertexColor(1, 1, 1, 1)       
        self:EnableMouse(true)
        self:Show()
        print("added pin at "..x.."/"..y.." to map "..mapid)
end

-- WORLDMAP PIN MIXIN : ON MOUSE EVENTS
function WorldmapSamplePinMixin:OnMouseEnter() print("Mouse Enter") end
function WorldmapSamplePinMixin:OnMouseLeave() print("Mouse Leave") end
function WorldmapSamplePinMixin:OnClick(button) print("Mouse Click") end

In Addition there is of Course a file "unknown.tga" in the WordmapSample Directory.

What happens is: I see the debug message telling me "added pin at 50/50 to map <id>"
So the OnAcquired function gets called. But I don't see the Icon on the Zone map.
Can anyone tell me what I'm doing wrong?

myrroddin 06-13-20 10:46 AM

Either straight up use HereBeDragons or check out its code to see how it is done: https://www.wowace.com/projects/herebedragons

oldZifnab 06-14-20 03:38 AM

Thanks for this hint, I checked HBD but... it has its own Management of minimap and worldmap Pins that would collide with my own management. My minimap Management is already working and deeply integrated in all my other Code. Wouldn't like to throw that all away.
I also tried to get through the HBD Code and understand how it is working… but down to the essentials (which is: just put one pin to the current map), I only found one difference and inserted this (I tried to display the Icon directly using the pin instead of adding a Frame to the pin). but it still doesn't show up on the map.
I must misunderstand something, but I don't get it...

oldZifnab 06-14-20 05:39 AM

Hi, got it now… the only error on my Code was to use x/y coordinates from 0 to 100 instead of 0 to 1.
So, where I placed at 50/50, I should have placed at 0.5/0.5.

DahkCeles 06-14-20 08:59 AM

I studied your code for a solid 15 minutes, comparing it to mine to spot the difference. I never thought to check the x/y coord. lol


All times are GMT -6. The time now is 12:44 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI