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() Code:
function WorldMapTrackingOptionsButtonMixin:OnSelection(value, checked) I was trying to do... Code:
hooksecurefunc(WorldMapTrackingOptionsButtonMixin, "InitializeDropDown", function(self) here_add_my_new_option end) 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! |
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:
|
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).
|
That looks promising, I'm going to give it a try.
Thank you very much! ;) |
Quote:
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