Quantcast Hook mixin or override template - WoWInterface
Thread Tools Display Modes
08-09-18, 04:15 AM   #1
maqjav
An Aku'mai Servant
Join Date: Feb 2012
Posts: 38
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!
  Reply With Quote
08-09-18, 05:46 AM   #2
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,676
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
  Reply With Quote
08-09-18, 05:53 AM   #3
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,676
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).
  Reply With Quote
08-09-18, 07:59 AM   #4
maqjav
An Aku'mai Servant
Join Date: Feb 2012
Posts: 38
That looks promising, I'm going to give it a try.
Thank you very much!
  Reply With Quote
08-09-18, 09:29 AM   #5
maqjav
An Aku'mai Servant
Join Date: Feb 2012
Posts: 38
Originally Posted by maqjav View Post
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!
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Hook mixin or override template

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