Quantcast What EVENT fires when UI elements are ready? - WoWInterface
Thread Tools Display Modes
07-23-19, 06:17 PM   #1
LudiusMaximus
A Flamescale Wyrmkin
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 107
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)
  Reply With Quote
07-23-19, 06:38 PM   #2
Kanegasi
An Onyxian Warder
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 369
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.
  Reply With Quote
07-24-19, 04:13 PM   #3
LudiusMaximus
A Flamescale Wyrmkin
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 107
Cool, thanks!

ADDON_LOADED with Blizzard_TimeManager works perfectly!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » What EVENT fires when UI elements are ready?

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