WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   I need an event that occurs later than PLAYER_ENTERING_WORLD (https://www.wowinterface.com/forums/showthread.php?t=58129)

Lev 08-02-20 01:24 AM

I need an event that occurs later than PLAYER_ENTERING_WORLD
 
Not sure how many people use Communities at all, but there's an annoying bug where community chat can be hidden when you log in. To fix this in-game, you can open your Chat Channels list and click the box next to the community chat channel to hide it, and then click it again to reshow it.

With this knowledge, I found ChatFrame_RemoveChannel and ChatFrame_AddChannel serve the same purpose as clicking that box in the chat channel UI.
Code:

ChatFrame_RemoveChannel(DEFAULT_CHAT_FRAME, "Community:XXXXXXX:1")
ChatFrame_AddChannel(DEFAULT_CHAT_FRAME, "Community:XXXXXXX:1")
(the XXXXXXX is a string of numbers that's basically the community's ID,
not sure if I should post that here)

I can run these in-game via /script and it fixes the chat bug. I've been having an issue automating it though, because the chat doesn't seem to bug out until after loading into WoW. I can run RemoveChannel on the PLAYER_LOGIN event perfectly fine, but AddChannel seems to need a delay. PLAYER_ENTERING_WORLD is too soon and it doesn't work. The *only* solution that has worked is using a 20 second timer after PLAYER_ENTERING_WORLD, but that probably isn't a consistent solution if I share this addon with my community. Does anyone have any ideas?

Code:

local frame=CreateFrame("Frame");
frame:RegisterEvent("PLAYER_LOGIN");
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:SetScript("OnEvent",function(self,event,...)
    if (event=="PLAYER_LOGIN") then
    ChatFrame_RemoveChannel(DEFAULT_CHAT_FRAME, "Community:XXXXXXX:1")
    elseif (event=="PLAYER_ENTERING_WORLD") then
    C_Timer.After(20, function() ChatFrame_AddChannel(DEFAULT_CHAT_FRAME, "Community:XXXXXXX:1") end)
    frame:UnregisterAllEvents()
    end
end)


glupikreten 08-02-20 01:48 AM

I'm new to lua and wow lua so im trying to get a grasp at how things work and what is life cycle of an addon(s)...

I struggled with this also and havent found any solution besides delaying my functions also... For me workd 10 sec... i guess that depends on speed of computer.. how fast can load shit.. dunno in what time counter starts.. is it after loading all addons.. or that one particulary.. or after loading all addons and some blizzard event... i just noticed that sometimes my function fires after 5-6 seconds image appears on mz screen.. sometimes its 8-9...

I'd like better solution aswell :)

Still im puzzled how to reposition, set height/width of combat frame... all others work as espected except that one... well i guess in time :)

Fizzlemizz 08-02-20 10:02 AM

Possibly UPDATE_CHAT_WINDOWS

Kanegasi 08-02-20 01:48 PM

The addon Blizzard_Communities is LoadOnDemand. Out of all actions in the UI that load it, the one that usually gets it first is when your chat channel list updates in FrameXML\ChannelList.lua:101

Lua Code:
  1. function ChannelListMixin:Update()
  2.  
  3. ...
  4.  
  5.     -- Then add community streams
  6.     local clubs = C_Club.GetSubscribedClubs();
  7.  
  8.     Communities_LoadUI(); -- here
  9.     CommunitiesFrame.CommunitiesList:PredictFavorites(clubs);
  10.     CommunitiesUtil.SortClubs(clubs);
  11.  
  12. ...
  13.  
  14. end

The event you want is ADDON_LOADED after force-loading Communities at login:

Lua Code:
  1. local frame=CreateFrame("frame")
  2. frame:RegisterEvent("ADDON_LOADED")
  3. frame:RegisterEvent("PLAYER_LOGIN")
  4. frame:SetScript("OnEvent",function(self,event,arg1)
  5.     if event=="ADDON_LOADED" and arg1=="Blizzard_Communities" then
  6.         ChatFrame_AddChannel(DEFAULT_CHAT_FRAME,"Community:XXXXXXX:1")
  7.     elseif event=="PLAYER_LOGIN" then
  8.         Communities_LoadUI()
  9.     end
  10. end)

You don't need to call ChatFrame_RemoveChannel. It's possible that the act of toggling the community loads Communities and for some reason Blizzard doesn't load Communities appropriately at login.


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

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI