-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUFO.lua
More file actions
executable file
·414 lines (341 loc) · 16.8 KB
/
UFO.lua
File metadata and controls
executable file
·414 lines (341 loc) · 16.8 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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
-- UFO.lua
-- addon lifecycle methods, coordination between submodules, etc.
-------------------------------------------------------------------------------
-- Module Loading
-------------------------------------------------------------------------------
---@class Ufo -- IntelliJ-EmmyLua annotation
---@field myTitle string Ufo.toc Title
---@field iconTexture string Ufo.toc IconTexture
---@field devMode boolean unlocks developer switches and levers for debugging
---@field thatWasMeThatDidThatMacro boolean flag used to stop event handler responses to UFO actions related to macros
---@field droppedPlaceholderOntoActionBar boolean flag used to stop event handler responses to UFO actions related to drag and drop
---@field pickedUpBtn ButtonDef data for the UFO button on the mouse cursor
---@field germLock Event flag to lock out any simultaneous germ events
---@field hasShitCalmedTheFuckDown boolean all the loading sequences and initialization chaos is done and the Bliz APIs will provide reliable info (HA!)
---@type Ufo
local ADDON_NAME, Ufo = ...
Ufo.Wormhole() -- Lua voodoo magic that replaces the current Global namespace with the Ufo object
ufoType = "UFO_BASE"
zebug = Zebug:new(Z_VOLUME_GLOBAL_OVERRIDE or Zebug.INFO) -- will be used by everyone in the Wormhole unless they override
local zebug = Zebug:new(Z_VOLUME_GLOBAL_OVERRIDE or Zebug.TRACE)
time = GetTimePreciseSec -- fuck whole second bullshit
-- Purely to satisfy my IDE
DB = Ufo.DB
L10N = Ufo.L10N
Zebug = Ufo.Zebug
Event = Ufo.Event
-------------------------------------------------------------------------------
-- Data
-------------------------------------------------------------------------------
local isUfoInitialized = false
local eventChaosPreviousCheckMoment = time()
local eventChaosDurationTolerance = 0.5
-------------------------------------------------------------------------------
-- Util funcs
-------------------------------------------------------------------------------
function isEventChaosChilledOut()
print (string.format("%.4f <- time :-)", time()))
local elapsed = time() - eventChaosPreviousCheckMoment
eventChaosPreviousCheckMoment = time()
return elapsed > eventChaosDurationTolerance
end
function calmTheFuckDown()
Ufo.hasShitCalmedTheFuckDown = false
C_Timer.After(1, function() Ufo.hasShitCalmedTheFuckDown = true end)
end
-------------------------------------------------------------------------------
-- Event Handlers
-------------------------------------------------------------------------------
local EventHandlers = { }
function EventHandlers:PLAYER_ENTERING_WORLD(eName, n, isInitialLogin, isReloadingUi)
zebug.info:mSkull():name("handler"):newEvent("Ufo", eName, n):run(function(event)
initalizeAddonStuff(event)
GermCommander:initializeAllSlots(event)
end)
end
local ASSISTED_COMBAT = "assistedcombat"
-- respond to the user dragging and dropping UFO proxies onto action bars.
-- We don't care about any other action bar events.
-- Germ:handleReceiveDrag() handles: spells/items/etc/UFOs onto UFOs already on the action bars
function EventHandlers:ACTIONBAR_SLOT_CHANGED(eName, n, btnSlotIndex)
if not Ufo.hasShitCalmedTheFuckDown then return end
-- ignore all Single Button Assist SPAM. bugfix #72
local _, _, subType = GetActionInfo(btnSlotIndex)
if subType == ASSISTED_COMBAT then
-- zebug.warn:event(eName):name("handler"):print("ignoring ASSISTED_COMBAT")
return Throttler.RUN_IMMEDIATELY
end
if Ufo.germLock then
local btnInSlot = BlizActionBarButtonHelper:get(btnSlotIndex, eName)
zebug.info:event(Ufo.germLock):name("handler"):print("LOCKED - ignoring", eName, "caused by",btnInSlot)
return
end
local myVolume = Ufo:getEventVolume(eName)
zebug.info:mSquare():name("handler"):newEvent("Ufo", eName, n, myVolume):run(function(event)
Ufo.germLock = event
GermCommander:addOrRemoveSomeUfoDueToAnActionBarSlotChangedEvent(btnSlotIndex, event)
Ufo.germLock = nil
end, "btnSlotIndex", btnSlotIndex)
end
EventHandlers.ACTIONBAR_SLOT_CHANGED = Throttler:throttleAndNoQueue(0.125, "Ufo:ACTIONBAR_SLOT_CHANGED", EventHandlers.ACTIONBAR_SLOT_CHANGED)
function EventHandlers:ACTIVE_TALENT_GROUP_CHANGED(eName, n, unreliableSpecId)
if not Ufo.hasShitCalmedTheFuckDown then return end
zebug.info:mCircle():name("handler"):newEvent("Ufo", eName, n):run(function(event)
local hasChanged = not Spec:hasCurrentSpecBeenApplied()
zebug.info:name("handler"):event(event):print("An event reports a spec change. Provided specId", unreliableSpecId, "previously applied spec was",Spec:getAppliedSpec(), "spec is now", Spec:getSpecId(), "hasChanged",hasChanged)
if hasChanged then
zebug.info:name("handler"):event(event):print("Applying...")
GermCommander:changeSpec(event)
else
zebug.info:name("handler"):event(event):print("Erroneous or duplicate event. Ignoring. KTHXBAI!")
end
end)
Spec:flagCurrentSpecAsHasBeenApplied()
end
function EventHandlers:SPELLS_CHANGED(eventName, n)
if not Ufo.hasShitCalmedTheFuckDown then return end
zebug.info:mCircle():name("handler"):newEvent("Ufo", eventName, n):run(function(event)
GermCommander:notifyAllGermsWithSpells(event)
end)
end
-- sometimes SPELLS_CHANGED fires off only once. Sometimes multiple times.
-- Sometimes before the API accurately reports if the (un)learned spell is actually (un)known.
-- So, yet again, fuck you very, VERY hard, Bliz.
-- Can't risk ignoring / throttling the spam of events.
EventHandlers.SPELLS_CHANGED = Throttler:throttle(1.5, "Ufo:SPELLS_CHANGED", EventHandlers.SPELLS_CHANGED)
--[[
function EventHandlers:EDIT_MODE_LAYOUTS_UPDATED(eName, n, layoutInfo, reconcileLayouts)
zebug.info:mCircle():name("handler"):newEvent("Ufo", eName, n):run(function(event)
--GermCommander:changeSpec(event)
zebug:dumpy("layoutInfo",layoutInfo)
end)
end
]]
-- TODO when action bars change direction update their UFOs to match.
EventRegistry:RegisterCallback("EditMode.Exit", function()
zebug.info:mark(Mark.INFO):name("handler"):newEvent("Ufo", "EditMode.Exit"):run(function(event)
end)
end, "UFO")
function EventHandlers:UPDATE_MACROS(eName, n)
if not Ufo.hasShitCalmedTheFuckDown then return end
zebug.info:mCircle():name("handler"):newEvent("Ufo", eName, n):run(function(event)
UfoProxy:syncMyId()
if Ufo.thatWasMeThatDidThatMacro then
-- the event was caused by an action of this addon and as such we shall ignore it
zebug.trace:newEvent("Ufo", eName, n):name("handler"):print("ignoring internally triggered event that was caused by", Ufo.thatWasMeThatDidThatMacro)
Ufo.thatWasMeThatDidThatMacro = nil
return
else
MacroShitShow:analyzeMacroUpdate(event)
end
end)
end
function EventHandlers:UNIT_INVENTORY_CHANGED(eName, n, id)
if not Ufo.hasShitCalmedTheFuckDown then return end
-- only care about events that affect the player
zebug.info:mDiamond():name("handler"):newEvent("Ufo", eName, n):run(function(event)
if id == "player" then
GermCommander:notifyAllGermsWithItems(event)
else
zebug.info:mDiamond():name("handler"):print("ignoring not player id", id)
end
end)
end
-- an absolute shitstorm of UNIT_INVENTORY_CHANGED and BAG_UPDATE vomit happens during the loading screen, so throttle this motherfucker
EventHandlers.UNIT_INVENTORY_CHANGED = Throttler:throttleAndNoQueue(1.0, "Ufo:BAG_UPDATE", EventHandlers.UNIT_INVENTORY_CHANGED)
--[[
function EventHandlers:UPDATE_VEHICLE_ACTIONBAR(eName, n)
if not Ufo.hasShitCalmedTheFuckDown then return end
--if isInCombatLockdownQuiet("Ignoring event UPDATE_VEHICLE_ACTIONBAR because it") then return end
local event = Event:new("Ufo", eName, n)
zebug.info:mSquare():name(eName):newEvent("Ufo", eName, n):run(function(event)
GermCommander:handleEventPetChanged(event)
end)
end
]]
function EventHandlers:UPDATE_BINDINGS(eName, n)
if not Ufo.hasShitCalmedTheFuckDown then return end
zebug.trace:newEvent("Ufo", eName, n):print("bound!")
--if isInCombatLockdownQuiet("Ignoring event UPDATE_BINDINGS because it") then return end
--GermCommander:updateAll()
end
function EventHandlers:PLAYER_LOGIN(eName, n)
zebug.trace:mMoon():newEvent("Ufo", eName, n):print("Welcome!")
end
---@param eName string "CURSOR_CHANGED"
---@param eCount number how many CURSOR_CHANGED events have happened
---@param newCursorType number see Enum.UICursorType
---@param oldCursorType number see Enum.UICursorType
---@param oldCursorVirtualID any who the fuck knows
function EventHandlers:CURSOR_CHANGED(eName, eCount, isCursorEmpty, newCursorType, oldCursorType, oldCursorVirtualID)
--print("EventHandlers:CURSOR_CHANGED... isCursorEmpty",isCursorEmpty, "eName", eName, "eventCounter", eCount, "newCursorType",newCursorType, "oldCursorType",oldCursorType, "oldCursorVirtualID",oldCursorVirtualID )
eCount = eCount or "NO-EVENT-COUNTER"
--[[
if not isCursorEmpty then
local e = Event:new(self, eName, eCount, zebug.INFO)
local b = ButtonDef:getFromCursor(e)
zebug.warn:event(e):owner(b):print("isUsable",b:isUsable(e))
end
]]
zebug.trace
:name("handler")
:newEvent("Ufo", Cursor:nameMakerForCursorChanged(isCursorEmpty), eCount, Zebug.trace)
:run(function(event)
GermCommander:forEachActiveGerm(Germ.maybeRegisterForClicksDependingOnCursorIsEmpty, event)
Cursor:clearCache(event)
UfoProxy:delayedAsyncDeleteProxyIfNotOnCursor(event)
--Placeholder:doNotLetUserDragMe(event) -- this is more trouble than it's worth.
end)
end
function EventHandlers:SPELL_UPDATE_COOLDOWN(eName, n, spellID, baseSpellID, category, startRecoveryCategory)
if not Ufo.hasShitCalmedTheFuckDown then return end
zebug.info:mark(Mark.DPS):name("SPELL_UPDATE_COOLDOWN"):newEvent("Ufo", eName, n):run(function(event)
local spellInfo = spellID and C_Spell.GetSpellInfo(spellID)
local name = spellInfo and spellInfo.name or "UnKnOwN"
zebug.info:name("SPELL_UPDATE_COOLDOWN"):event(event):print("spellID",spellID, "spell name", name --[[, "baseSpellID",baseSpellID, "eName",eName, "n",n]])
GermCommander:forEachActiveGerm(Germ.render, event)
end)
end
EventHandlers.SPELL_UPDATE_COOLDOWN = Throttler:throttleAndNoQueue(0.1, "Ufo:SPELL_UPDATE_COOLDOWN", EventHandlers.SPELL_UPDATE_COOLDOWN)
function EventHandlers:SPELL_UPDATE_USABLE(eName, n)
EventHandlers:SPELL_UPDATE_COOLDOWN(eName, n, nil)
end
EventHandlers.SPELL_UPDATE_CHARGES = EventHandlers.SPELL_UPDATE_USABLE
-------------------------------------------------------------------------------
-- Event related methods - TODO: use these?
-------------------------------------------------------------------------------
-- support dynamically (de)activating DEBUG output in real time for individual events
function Ufo:getEventVolume(eventName)
return Ufo.devMode and Config.opts.devTool.eventVolume[eventName] or nil
end
function Ufo:setEventVolume(eventName, volume)
Config.opts.devTool.eventVolume[eventName] = volume or nil
end
-- set a semaphore so other code can decide to respond to the resulting UPDATE_MACROS event
-- TODO: if set during a Zebug:runEvent() AND the provided event arg is the same one being used by runEvent() then it will auto-erase it at the end of runEvent() ... todo: move to Zebug?
function Ufo:setEventSemaphore(semaphoreName, event)
self.semaphores = self.semaphores or {}
self.semaphores[semaphoreName] = event
end
function Ufo:isThereAnEventSemaphore(semaphoreName)
if not self.semaphores then return end
return self.semaphores[semaphoreName]
end
function Ufo:setEventSemaphore(semaphoreName, event)
if not self.semaphores then return end
self.semaphores[semaphoreName] = event
end
-------------------------------------------------------------------------------
-- Handlers for ADDON_LOADED of Other Addons
-------------------------------------------------------------------------------
local HandlersForAddonLoadedEvents = {}
function HandlersForAddonLoadedEvents:Blizzard_PlayerSpells(name)
--v11 Bliz moved the spell book into its own internal, load-on-demand addon
zebug.trace:name("listener"):print("Heard addon load: Blizzard_PlayerSpells")
Catalog:createToggleButton(PlayerSpellsFrame)
end
function HandlersForAddonLoadedEvents:Blizzard_Collections(name)
zebug.trace:name("listener"):print("Heard addon load: Blizzard_Collections")
Catalog:createToggleButton(CollectionsJournal)
end
function HandlersForAddonLoadedEvents:Blizzard_MacroUI(name)
zebug.trace:name("listener"):print("Heard addon load: Blizzard_MacroUI")
Catalog:createToggleButton(MacroFrame)
MacroShitShow:init()
end
function HandlersForAddonLoadedEvents:Blizzard_ProfessionsBook(name)
zebug.trace:name("listener"):print("Heard addon load: Blizzard_ProfessionsBook")
Catalog:createToggleButton(ProfessionsBookFrame)
end
function HandlersForAddonLoadedEvents:LargerMacroIconSelection(name)
zebug.trace:name("listener"):print("Heard addon load: LargerMacroIconSelection")
supportLargerMacroIconSelection()
end
function HandlersForAddonLoadedEvents:UFO(name)
zebug.trace:name("listener"):print("Heard addon load", name)
end
-------------------------------------------------------------------------------
-- Debugger tools
-------------------------------------------------------------------------------
function dumpIfUnderMousePointer()
Ufo.devMode = true
local didOutput
zebug.warn:mark(Mark.QUEST):newEvent("Ufo","debug"):run(function(event)
local foci = GetMouseFoci()
for i, frame in ipairs(foci) do
if UfoMixIn:isA(frame) then
didOutput = true
local name = frame:GetName()
zebug.warn:event(event):name("debug"):owner(frame):print("the mouse is pointing at",name)
if frame.printDebugDetails then frame:printDebugDetails(event) end
end
end
if not didOutput then
zebug.warn:event(event):print("Point at a UFO first then issue this command. Dev Mode now disabled.")
Ufo.devMode = false
end
end)
end
-------------------------------------------------------------------------------
-- Config for Slash Commands aka "/ufo"
-------------------------------------------------------------------------------
local slashFuncs = {
[L10N.SLASH_CMD_CONFIG] = {
desc = L10N.SLASH_DESC_CONFIG,
fnc = Config.toggle,
},
[L10N.SLASH_CMD_OPEN] = {
desc = L10N.SLASH_DESC_OPEN,
fnc = Catalog.open,
},
[L10N.SLASH_CMD_SNAPSHOT_SAVE] = {
desc = L10N.SLASH_DESC_SNAPSHOT_SAVE,
fnc = DB.snapshotSave,
},
[L10N.SLASH_CMD_SNAPSHOT_LOAD] = {
desc = L10N.SLASH_DESC_SNAPSHOT_LOAD,
fnc = DB.snapshotLoad,
},
debug = {
desc = "examine the UFO under the mouse pointer",
fnc = dumpIfUnderMousePointer,
},
}
-------------------------------------------------------------------------------
-- Addon Lifecycle
-------------------------------------------------------------------------------
-- called by PLAYER_ENTERING_WORLD
function initalizeAddonStuff(event)
if isUfoInitialized then return end
Ufo.myTitle = C_AddOns.GetAddOnMetadata(ADDON_NAME, "Title")
Ufo.iconTexture = C_AddOns.GetAddOnMetadata(ADDON_NAME, "IconTexture")
Ufo.version = C_AddOns.GetAddOnMetadata(ADDON_NAME, "Version")
Ufo.versionMsg = L10N.VERSION .. ": " .. Ufo.version
DB:initializeFlyouts()
DB:initializePlacements()
DB:initializeOptsMemory()
Config:migrateToCurrentVersion()
Config:initializeOptionsMenu(EventHandlers)
SecEnv:loadConfigOptions()
MacroShitShow:init()
UfoProxy:init()
ThirdPartyAddonSupport:detectSupportedAddons()
registerSlashCmd("ufo", slashFuncs)
Catalog:definePopupDialogWindow()
ButtonDef:registerToolTipRecorder()
-- check to see if the usually on-demand Bliz windows have already been loaded (by some other addon)
Catalog:createToggleButtonIfWeCan(SpellBookFrame) -- support WoW v10
Catalog:createToggleButtonIfWeCan(PlayerSpellsFrame)
Catalog:createToggleButtonIfWeCan(CollectionsJournal)
Catalog:createToggleButtonIfWeCan(MacroFrame)
Catalog:createToggleButtonIfWeCan(ProfessionsBookFrame)
IconPicker:init()
msgUserOrNot(L10N.LOADED, Ufo.versionMsg)
-- flags to wait out the chaos happening when the UI first loads / reloads.
isUfoInitialized = true
calmTheFuckDown()
end
-------------------------------------------------------------------------------
-- OK, Go for it!
-------------------------------------------------------------------------------
BlizGlobalEventsListener:register(Ufo, EventHandlers, HandlersForAddonLoadedEvents)