-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGridCore.lua
More file actions
323 lines (260 loc) · 7.25 KB
/
GridCore.lua
File metadata and controls
323 lines (260 loc) · 7.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
-- GridCore.lua
-- insert boilerplate here
--{{{ Libraries
local Compost = AceLibrary("Compost-2.0")
local RL = AceLibrary("RosterLib-2.0")
local L = AceLibrary("AceLocale-2.2"):new("Grid")
--}}}
--{{{ Grid
--{{{ Initialization
Grid = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceDB-2.0", "AceDebug-2.0", "AceModuleCore-2.0", "AceConsole-2.0", "FuBarPlugin-2.0")
Grid:SetModuleMixins("AceDebug-2.0", "AceEvent-2.0", "AceModuleCore-2.0")
Grid:RegisterDB("GridEnhancedDB")
Grid.debugFrame = ChatFrame2
Grid.isTBC = string.find(GetBuildInfo(), "^2%.")
--{{{ AceOptions table
Grid.options = {
type = "group",
handler = Grid,
args = {
[L["debug"]] = {
type = "group",
name = L["Debugging"],
desc = L["Module debugging menu."],
args = {},
},
},
}
--}}}
--{{{ AceDB defaults
Grid.defaults = {
debug = false,
}
--}}}
--{{{ FuBar settings
Grid.name = "Grid"
Grid.hasIcon = true
Grid.defaultMinimapPosition = 240
Grid.cannotDetachTooltip = true
Grid.independentProfile = true
Grid.defaultPosition = "RIGHT"
Grid.hideWithoutStandby = true
Grid.OnMenuRequest = Grid.options
Grid.enhanced = true
--}}}
--}}}
--{{{ Module prototype
Grid.modulePrototype.core = Grid
function Grid.modulePrototype:OnInitialize()
self.debugFrame = Grid.debugFrame
self.debugging = self.db.profile.debug
self:Debug("OnInitialize")
self.core:AddModuleDebugMenu(self)
self:RegisterModules()
self:RegisterEvent("ADDON_LOADED")
end
function Grid.modulePrototype:OnEnable()
self:EnableModules()
end
function Grid.modulePrototype:OnDisable()
self:DisableModules()
end
function Grid.modulePrototype:Reset()
self.debugging = self.db.profile.debug
self:Debug("Reset")
self:ResetModules()
end
function Grid.modulePrototype:RegisterModules()
for name,module in self:IterateModules() do
self:RegisterModule(name, module)
end
end
function Grid.modulePrototype:RegisterModule(name, module)
self:Debug("Registering "..name)
if not module.db then
self.core:RegisterDefaults(name, "profile", module.defaultDB or {})
module.db = self.core:AcquireDBNamespace(name)
end
if module.options == nil then
module.options = {
type = "group",
name = (module.menuName or module.name),
desc = "Options for ".. module.name,
args = {},
}
end
if module.extraOptions then
for name, option in pairs(module.extraOptions) do
module.options.args[name] = option
end
end
if module.options then
self.options.args[name] = module.options
end
self.core:AddModuleDebugMenu(module)
end
function Grid.modulePrototype:EnableModules()
for name,module in self:IterateModules() do
self:ToggleModuleActive(module, true)
end
end
function Grid.modulePrototype:DisableModules()
for name,module in self:IterateModules() do
self:ToggleModuleActive(module, false)
end
end
function Grid.modulePrototype:ResetModules()
for name,module in self:IterateModules() do
module:Reset()
end
end
function Grid.modulePrototype:ADDON_LOADED(addon)
local name = GetAddOnMetadata(addon, "X-".. self.name .. "Module")
if not name then return end
local module = getglobal(name)
if not module or not module.name then return end
module.external = true
self:RegisterModule(module.name, module)
end
--}}}
function Grid:OnInitialize()
self:RegisterDefaults('profile', Grid.defaults )
self:RegisterChatCommand({'/grid','/gr'}, self.options )
-- we need to save debugging state over sessions :(
self.debugging = self.db.profile.debug
self:AddModuleDebugMenu(self)
self:EnableClickCasting()
self:RegisterModules()
-- rename FuBar menu to avoid confusion
-- this should be added to FuBarPlugin btw.
if not FuBar then
self.OnMenuRequest.args.hide.guiName = "Hide minimap icon"
self.OnMenuRequest.args.hide.desc = "Hide minimap icon"
end
self:RegisterEvent("ADDON_LOADED")
end
function Grid:OnEnable()
self:RegisterEvent("RosterLib_RosterChanged")
self:EnableModules()
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:TriggerEvent("Grid_UpdateSort")
end
function Grid:OnDisable()
self:Debug("OnDisable")
self:DisableModules()
end
function Grid:OnProfileEnable()
self.debugging = self.db.profile.debug
self:Debug("Loaded profile", "(", self:GetProfile(),")")
self:ResetModules()
end
-- only for WoW 1.x
function Grid:EnableClickCasting()
if Clique and Clique.OnClick and not GridCustomClick then
GridCustomClick = function (button, unit)
Clique:OnClick(button, unit)
end
end
end
function Grid:RegisterModules()
for name,module in self:IterateModules() do
self:RegisterModule(name, module)
end
end
function Grid:RegisterModule(name, module)
self:Debug("Registering "..name)
if not module.db then
self:RegisterDefaults(name, "profile", module.defaultDB or {})
module.db = self:AcquireDBNamespace(name)
end
if module.options then
self.options.args[name] = module.options
end
self:AddModuleDebugMenu(module)
end
function Grid:AddModuleDebugMenu(module)
local debugMenu = Grid.options.args.debug
debugMenu.args[module.name] = {
type = "toggle",
name = module.name,
desc = L["Toggle debugging for "].. module.name ..".",
get = function ()
return module.db.profile.debug
end,
set = function (v)
module.db.profile.debug = v
module.debugging = v
end,
}
end
function Grid:EnableModules()
for name,module in self:IterateModules() do
self:ToggleModuleActive(module, true)
end
end
function Grid:DisableModules()
for name,module in self:IterateModules() do
self:ToggleModuleActive(module, false)
end
end
function Grid:ResetModules()
for name,module in self:IterateModules() do
module.db = self:AcquireDBNamespace(name)
module:Reset()
end
end
--{{{ Event handlers
function Grid:RosterLib_RosterChanged(tbl)
local needsUpdate = false
local name, u
-- as this event is also triggered on pet events, we need to skip these first
for name,u in pairs(tbl) do
-- don't attempt to update frames if it's only a pet that died
if u.class ~= "PET" and u.oldclass ~= "PET" then
-- we need to update the frames
needsUpdate = true
if not u.name then
self:Debug("UnitLeft "..(u.oldname))
self:TriggerEvent("Grid_UnitLeft", u.oldname)
elseif not u.oldname then
self:Debug("UnitJoined "..(u.name))
self:TriggerEvent("Grid_UnitJoined", u.name, u.unitid)
else
self:TriggerEvent("Grid_UnitChanged", u.name, u.unitid)
end
end
end
if needsUpdate then
-- queue update for after leaving combat
-- not that anything is actually registered for Grid_UpdateSort anymore
if Grid.inCombat and Grid.isTBC then
Grid.rosterNeedsUpdate = true
else
self:TriggerEvent("Grid_UpdateSort")
end
end
end
function Grid:PLAYER_REGEN_DISABLED()
Grid.inCombat = true
self:Debug("Entering combat")
end
function Grid:PLAYER_REGEN_ENABLED()
Grid.inCombat = false
self:Debug("Leaving combat")
if Grid.rosterNeedsUpdate then
self:Debug("Left combat, updating roster")
Grid.rosterNeedsUpdate = false
self:TriggerEvent("Grid_UpdateSort")
end
end
function Grid:ADDON_LOADED(addon)
local name = GetAddOnMetadata(addon, "X-".. self.name .. "Module")
if not name then return end
local module = getglobal(name)
if not module or not module.name then return end
module.external = true
self:RegisterModule(module.name, module)
end
--}}}
--}}}