Go to Page... |
|
Thread Tools | Display Modes |
|
08-19-18, 04:25 PM | #1 |
How can I hooksecurefunc with colon like this: "MainMenuBarMixin:OnShow"
I spend so much time trying to figure it out by myself, but unfortunately no luck.
This is blizard code mainMenuBar.lua: Code:
local MAINMENU_SLIDETIME = 0.30; local MAINMENU_GONEYPOS = 130; --Distance off screen for MainMenuBar to be completely hidden local MAINMENU_XPOS = 0; MAIN_MENU_BAR_MARGIN = 75; -- number of art pixels on one side, used by UIParent_ManageFramePositions. It's not the art's full size, don't care about the gryphon's tail. MainMenuBarMixin = { }; function MainMenuBarMixin:OnStatusBarsUpdated() self:SetPositionForStatusBars(); end function MainMenuBarMixin:OnLoad() self:RegisterEvent("ACTIONBAR_PAGE_CHANGED"); self:RegisterEvent("CURRENCY_DISPLAY_UPDATE"); self:RegisterEvent("UNIT_LEVEL"); self:RegisterEvent("PLAYER_ENTERING_WORLD"); self:RegisterEvent("TRIAL_STATUS_UPDATE"); self:RegisterEvent("DISPLAY_SIZE_CHANGED"); self:RegisterEvent("UI_SCALE_CHANGED"); CreateFrame("FRAME", "StatusTrackingBarManager", self, "StatusTrackingBarManagerTemplate"); MAX_PLAYER_LEVEL = MAX_PLAYER_LEVEL_TABLE[GetExpansionLevel()]; self.state = "player"; MainMenuBarArtFrame.PageNumber:SetText(GetActionBarPage()); MicroButtonAndBagsBar:SetFrameLevel(self:GetFrameLevel()+2); end function MainMenuBarMixin:OnShow() UpdateMicroButtonsParent(MainMenuBarArtFrame); MoveMicroButtons("BOTTOMLEFT", MicroButtonAndBagsBar, "BOTTOMLEFT", 6, 3, false); end function MainMenuBarMixin:SetYOffset(yOffset) self.yOffset = yOffset; end function MainMenuBarMixin:GetYOffset() return self.yOffset; end function MainMenuBarMixin:SetPositionForStatusBars() MainMenuBar:ClearAllPoints(); MainMenuBarArtFrame.LeftEndCap:ClearAllPoints(); MainMenuBarArtFrame.RightEndCap:ClearAllPoints(); if ( StatusTrackingBarManager:GetNumberVisibleBars() == 2 ) then self:SetYOffset(17); MainMenuBarArtFrame.LeftEndCap:SetPoint("BOTTOMLEFT", MainMenuBar, -98, -17); MainMenuBarArtFrame.RightEndCap:SetPoint("BOTTOMRIGHT", MainMenuBar, 98, -17); elseif ( StatusTrackingBarManager:GetNumberVisibleBars() == 1 ) then self:SetYOffset(14); MainMenuBarArtFrame.LeftEndCap:SetPoint("BOTTOMLEFT", MainMenuBar, -98, -14); MainMenuBarArtFrame.RightEndCap:SetPoint("BOTTOMRIGHT", MainMenuBar, 98, -14); else self:SetYOffset(0); MainMenuBarArtFrame.LeftEndCap:SetPoint("BOTTOMLEFT", MainMenuBar, -98, 0); MainMenuBarArtFrame.RightEndCap:SetPoint("BOTTOMRIGHT", MainMenuBar, 98, 0); end if ( IsPlayerInWorld() ) then UIParent_ManageFramePositions(); end end Code:
local function Test() print("test") end hooksecurefunc(MainMenuBarMixin, "SetPositionForStatusBars", Test); |
|
08-19-18, 04:36 PM | #2 |
Anything with "mixin" in it's name isn't actually used directly, so if you were to hook that function, the hook won't get called. You'll need to hook the actual method on the frame that uses the mixin.
Mixins are a template of methods that frames then inherit. Blizzard gives frames a mixin template in two ways: calling frame = CreateFromMixins(mixin) or in xml using the mixin="" attribute. In this case, MainMenuBar gets its methods from MainMenuBar.xml: XML Code:
You should be able to do this: Lua Code:
__________________
|
|
08-19-18, 04:53 PM | #3 | |
Kanegasi you saved my day! Thank you very much for explanation. I hope this thread will be helpful for all beginners or coming back modders. Very appreciate your help. I think it's new thing from Legion maybe, don't remember mixins in Pandaria-Warlords of Draenor. |
||
08-19-18, 07:39 PM | #4 | |
It's interesting to me that you would say that, because this works for me: lua Code:
Maybe it depends on the mixin? idk |
||
08-19-18, 10:35 PM | #5 |
It depends on 1) when the mixin is created 2) when the function is hooked and 3) when the frame has the mixin applied.
In Ammako's case, ExpBarMixin is created and is applied to a template in the frame xml, before any addon gets loaded. The template however is not used for instantiating a frame until PLAYER_ENTERING_WOLRD fires, which is typically after most addons are loaded. As such, any hooks applied to the mixin before PLAYER_ENTERING_WOLRD fires will propagate the the new frame. In Nikita's case, MainMenuBarMixin is created and immediately used in the creation of MainMenuBar. This means there is no allowance for any hooks to be made and applied via the mixin. Last edited by Gethe : 08-19-18 at 10:39 PM. |
|
08-21-18, 06:17 PM | #6 | |
For example, I tried to hook some functions like function PlayerTalentFrame_UpdateSpecFrame(self, spec) from Blizzard_TalentUI.lua: Lua Code:
Lua Code:
At the same time, for example: Lua Code:
Can't understand why this happens, and will appreciate any advises how to hook functions with "funxtionX is not a function" error. |
||
08-21-18, 06:24 PM | #7 | |
|
||
WoWInterface » Developer Discussions » Lua/XML Help » How can I hooksecurefunc with colon like this: "MainMenuBarMixin:OnShow" |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Switch to Linear Mode |
Hybrid Mode |
Switch to Threaded Mode |
|
|