WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Hook mixin or override template (https://www.wowinterface.com/forums/showthread.php?t=56515)

maqjav 08-09-18 04:15 AM

Hook mixin or override template
 
Hello.

I'm trying to do something... I think simple, which is to add a new option to the DropDownMenu that appears on the world map.

That button uses the Template "WorldMapTrackingOptionsButtonTemplate", which uses the mixin "WorldMapTrackingOptionsButtonMixin".
This mixin has the method:
Code:

WorldMapTrackingOptionsButtonMixin:InitializeDropDown()
where they initialize the dropDownMenu, and the method:
Code:

function WorldMapTrackingOptionsButtonMixin:OnSelection(value, checked)
where they do whatever they have to do after toggling the options.

I was trying to do...
Code:

hooksecurefunc(WorldMapTrackingOptionsButtonMixin, "InitializeDropDown", function(self) here_add_my_new_option end)
but this doesn't work, because this method is invoked on the event "WorldMapTrackingOptionsButtonMixin:OnLoad()", which, if I'm not wrong, is invoked before my addon is even loaded (right?).

I know that with the last Map API I can add a new overlay to the map and insert my own button, but having this one I didn't want to overload the map with more stuff.

Ideas of how to achieve this?

Thanks!

p3lim 08-09-18 05:46 AM

Mixins are just tables that gets its methods copied to the frame, so on the WorldMapTrackingOptionsButtonTemplate every method of WorldMapTrackingOptionsButtonMixin gets copied. See the Lua implementation of Mixin in Pools.lua on how mixins are basically just copied over.

To hook into whatever uses WorldMapTrackingOptionsButtonTemplate you'll need to see where it's used, not how it's defined. That would be on line 205 in Blizzard_WorldMap.lua.

It's added as an overlay frame, which is its own system (WorldMapFrame:AddOverlayFrame). A frame is created using the template, then added to WorldMapFrame.overlayFrames.

To get the frame you'll need to iterate over that table and use some unique identifying part of the template to find it, like one of its methods or textures (like in the example below).

Lua Code:
  1. for _, overlayFrame in next, WorldMapFrame.overlayFrames do
  2.     if(overlayFrame.Border and overlayFrame.Border:GetTexture() == 'Interface\\Minimap\\MiniMap-TrackingBorder') then
  3.         hooksecurefunc(overlayFrame, 'InitializeDropDown', myFunction)
  4.         break
  5.     end
  6. end

p3lim 08-09-18 05:53 AM

If you still don't get your buttons to show, then just re-initialize the dropdown after hooking (simplest way is just to call overlayFrame:OnLoad() after the hook).

maqjav 08-09-18 07:59 AM

That looks promising, I'm going to give it a try.
Thank you very much! ;)

maqjav 08-09-18 09:29 AM

Quote:

Originally Posted by maqjav (Post 329414)
That looks promising, I'm going to give it a try.
Thank you very much! ;)


I just tried your code and it works perfect! Actually the method InitializeDropDown is invoked after loading my addon, so I can inyect my code just like you suggested.

Thanks again!


All times are GMT -6. The time now is 03:03 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI