1
1
-- 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
27
18
28
19
-- 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 , ...)
33
21
if cmd == ' version' then
34
- print (L .Version :format (self .db .global .addonVersion ))
22
+ print (L .Version :format (Addon .db .global .addonVersion ))
35
23
else
36
- self :ShowOptionsFrame ()
24
+ Addon :ShowOptionsFrame ()
37
25
end
38
26
end
39
27
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'
48
30
49
- self .frame :UnregisterEvent (event )
31
+ -- watch for subsequent events
32
+ EventRegistry :RegisterFrameEventAndCallback (" PLAYER_ENTERING_WORLD" , Addon .PLAYER_ENTERING_WORLD , Addon )
50
33
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
54
36
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 )
61
43
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
68
46
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 )
71
55
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' )
78
58
end
79
59
80
60
-- utility methods
81
61
function Addon :ShowOptionsFrame ()
82
- if self : IsConfigAddonEnabled () and C_AddOns .LoadAddOn (CONFIG_ADDON ) then
62
+ if C_AddOns .LoadAddOn (CONFIG_ADDON ) then
83
63
local dialog = LibStub (' AceConfigDialog-3.0' )
84
64
85
- dialog :Open (ADDON )
86
- dialog :SelectGroup (ADDON , " themes" , DEFAULT )
65
+ dialog :Open (AddonName )
66
+ dialog :SelectGroup (AddonName , " themes" , DEFAULT )
87
67
88
68
return true
89
69
end
90
70
91
71
return false
92
72
end
93
73
94
- function Addon :IsConfigAddonEnabled ()
95
- return C_AddOns .GetAddOnEnableState (CONFIG_ADDON , UnitName (' player' )) > 0
96
- end
97
-
98
74
function Addon :CreateHiddenFrame (...)
99
75
local f = CreateFrame (... )
100
76
@@ -121,8 +97,5 @@ function Addon:GetButtonIcon(frame)
121
97
end
122
98
end
123
99
124
- Addon :OnLoad ()
125
-
126
100
-- exports
127
- _G [ADDON ] = Addon
128
- _G [ADDON .. ' _Launch' ] = function () Addon :ShowOptionsFrame () end
101
+ _G [AddonName ] = Addon
0 commit comments