WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   What EVENT fires when UI elements are ready? (https://www.wowinterface.com/forums/showthread.php?t=57305)

LudiusMaximus 07-23-19 06:17 PM

What EVENT fires when UI elements are ready?
 
Code:

TimeManagerClockButton:SetScript("OnClick", function (self, button)
  print("Do some stuff.")
  TimeManagerClockButton_OnClick(self)
end)

This in the beginning of my addon does not work, because TimeManagerClockButton is not yet known.

The following works, but is PLAYER_ENTERING_WORLD really the proper event to use?

Code:

local startupFrame = CreateFrame("Frame")
startupFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
startupFrame:SetScript("OnEvent", function(self, event, ...)
 
  TimeManagerClockButton:SetScript("OnClick", function (self, button)
    print("Do some stuff.")
    TimeManagerClockButton_OnClick(self)
  end)
 
end)


Kanegasi 07-23-19 06:38 PM

Blizzard_TimeManager.toc sets the time manager as LoadOnDemand, so it is not loaded initially.

UIParent attempts to load it twice, early if an alarm is enabled, then a second time at PLAYER_LOGIN:

Lua Code:
  1. function UIParent_OnEvent(self, event, ...)
  2.    
  3.     ...
  4.    
  5.     elseif ( event == "VARIABLES_LOADED" ) then
  6.    
  7.     ...
  8.    
  9.         if ( not TimeManagerFrame and GetCVar("timeMgrAlarmEnabled") == "1" ) then
  10.             -- We have to load the time manager here if the alarm is enabled because the alarm can go off
  11.             -- even if the clock is not shown. WorldFrame_OnUpdate handles alarm checking while the clock
  12.             -- is hidden.
  13.             TimeManager_LoadUI();
  14.         end
  15.    
  16.     ...
  17.    
  18.     elseif ( event == "PLAYER_LOGIN" ) then
  19.         TimeManager_LoadUI();

If it still somehow didn't load, TimeManager_LoadUI() is called when /stopwatch is used.

Since it should load at PLAYER_LOGIN, I suggest watching ADDON_LOADED like the Stopwatch does:

Lua Code:
  1. function StopwatchFrame_OnEvent(self, event, ...)
  2.     if ( event == "ADDON_LOADED" ) then
  3.         local name = ...;
  4.         if ( name == "Blizzard_TimeManager" ) then

Or just force it with TimeManager_LoadUI() a frame before your code.

LudiusMaximus 07-24-19 04:13 PM

Cool, thanks!

ADDON_LOADED with Blizzard_TimeManager works perfectly!


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

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