11-- code to drive the addon
2- local ADDON , Addon = ...
3- local CONFIG_ADDON = ADDON .. ' _Config'
4- local L = LibStub (' AceLocale-3.0' ):GetLocale (ADDON )
5-
6- function Addon :OnLoad ()
7- -- create and setup options frame and event loader
8- local frame = self :CreateHiddenFrame (' Frame' )
9-
10- -- setup an event handler
11- frame :SetScript (
12- ' OnEvent' ,
13- function (_ , event , ...)
14- local func = self [event ]
15- if type (func ) == ' function' then
16- func (self , event , ... )
17- end
18- end
19- )
20-
21- frame :RegisterEvent (' ADDON_LOADED' )
22- frame :RegisterEvent (' PLAYER_ENTERING_WORLD' )
23- frame :RegisterEvent (' PLAYER_LOGIN' )
24- frame :RegisterEvent (' PLAYER_LOGOUT' )
25-
26- self .frame = frame
2+ local AddonName , Addon = ...
3+ local CONFIG_ADDON = AddonName .. ' _Config'
4+ local L = LibStub (' AceLocale-3.0' ):GetLocale (AddonName )
5+
6+ EventUtil .ContinueOnAddOnLoaded (AddonName , function (addonName )
7+ Addon :InitializeDB ()
8+ Addon .Cooldown :SetupHooks ()
9+
10+ -- setup addon compartment button
11+ if AddonCompartmentFrame then
12+ AddonCompartmentFrame :RegisterAddon {
13+ text = C_AddOns .GetAddOnMetadata (addonName , " Title" ),
14+ icon = C_AddOns .GetAddOnMetadata (addonName , " IconTexture" ),
15+ func = function () Addon :ShowOptionsFrame () end ,
16+ }
17+ end
2718
2819 -- setup slash commands
29- _G [(' SLASH_%s1' ):format (ADDON )] = (' /%s' ):format (ADDON :lower ())
30- _G [(' SLASH_%s2' ):format (ADDON )] = ' /occ'
31-
32- SlashCmdList [ADDON ] = function (cmd , ...)
20+ SlashCmdList [AddonName ] = function (cmd , ...)
3321 if cmd == ' version' then
34- print (L .Version :format (self .db .global .addonVersion ))
22+ print (L .Version :format (Addon .db .global .addonVersion ))
3523 else
36- self :ShowOptionsFrame ()
24+ Addon :ShowOptionsFrame ()
3725 end
3826 end
3927
40- self .OnLoad = nil
41- end
42-
43- -- events
44- function Addon :ADDON_LOADED (event , addonName )
45- if ADDON ~= addonName then
46- return
47- end
28+ SLASH_OmniCC1 = ' /omnicc'
29+ SLASH_OmniCC2 = ' /occ'
4830
49- self .frame :UnregisterEvent (event )
31+ -- watch for subsequent events
32+ EventRegistry :RegisterFrameEventAndCallback (" PLAYER_ENTERING_WORLD" , Addon .PLAYER_ENTERING_WORLD , Addon )
5033
51- self :InitializeDB ()
52- self .Cooldown :SetupHooks ()
53- end
34+ EventUtil .RegisterOnceFrameEventAndCallback (" PLAYER_LOGIN" , function ()
35+ if not Addon .db .global .disableBlizzardCooldownText then return end
5436
55- function Addon : PLAYER_ENTERING_WORLD ()
56- self . Timer : ForActive ( ' Update ' )
57- end
58-
59- function Addon : PLAYER_LOGIN ()
60- if not self . db . global . disableBlizzardCooldownText then return end
37+ -- disable and preserve the user's blizzard cooldown count setting
38+ Addon . countdownForCooldowns = GetCVar ( ' countdownForCooldowns ' )
39+ if Addon . countdownForCooldowns ~= ' 0 ' then
40+ SetCVar ( ' countdownForCooldowns ' , ' 0 ' )
41+ end
42+ end )
6143
62- -- disable and preserve the user's blizzard cooldown count setting
63- self .countdownForCooldowns = GetCVar (' countdownForCooldowns' )
64- if self .countdownForCooldowns ~= ' 0' then
65- SetCVar (' countdownForCooldowns' , ' 0' )
66- end
67- end
44+ EventUtil .RegisterOnceFrameEventAndCallback (" PLAYER_LOGOUT" , function ()
45+ if not Addon .db .global .disableBlizzardCooldownText then return end
6846
69- function Addon :PLAYER_LOGOUT ()
70- if not self .db .global .disableBlizzardCooldownText then return end
47+ -- return the setting to whatever it was originally on logout
48+ -- so that the user can uninstall omnicc and go back to what they had
49+ local countdownForCooldowns = GetCVar (' countdownForCooldowns' )
50+ if Addon .countdownForCooldowns ~= countdownForCooldowns then
51+ SetCVar (' countdownForCooldowns' , Addon .countdownForCooldowns )
52+ end
53+ end )
54+ end )
7155
72- -- return the setting to whatever it was originally on logout
73- -- so that the user can uninstall omnicc and go back to what they had
74- local countdownForCooldowns = GetCVar (' countdownForCooldowns' )
75- if self .countdownForCooldowns ~= countdownForCooldowns then
76- SetCVar (' countdownForCooldowns' , self .countdownForCooldowns )
77- end
56+ function Addon :PLAYER_ENTERING_WORLD ()
57+ self .Timer :ForActive (' Update' )
7858end
7959
8060-- utility methods
8161function Addon :ShowOptionsFrame ()
82- if self : IsConfigAddonEnabled () and C_AddOns .LoadAddOn (CONFIG_ADDON ) then
62+ if C_AddOns .LoadAddOn (CONFIG_ADDON ) then
8363 local dialog = LibStub (' AceConfigDialog-3.0' )
8464
85- dialog :Open (ADDON )
86- dialog :SelectGroup (ADDON , " themes" , DEFAULT )
65+ dialog :Open (AddonName )
66+ dialog :SelectGroup (AddonName , " themes" , DEFAULT )
8767
8868 return true
8969 end
9070
9171 return false
9272end
9373
94- function Addon :IsConfigAddonEnabled ()
95- return C_AddOns .GetAddOnEnableState (CONFIG_ADDON , UnitName (' player' )) > 0
96- end
97-
9874function Addon :CreateHiddenFrame (...)
9975 local f = CreateFrame (... )
10076
@@ -121,8 +97,5 @@ function Addon:GetButtonIcon(frame)
12197 end
12298end
12399
124- Addon :OnLoad ()
125-
126100-- exports
127- _G [ADDON ] = Addon
128- _G [ADDON .. ' _Launch' ] = function () Addon :ShowOptionsFrame () end
101+ _G [AddonName ] = Addon
0 commit comments