06208b1 - Add global table entries for debug profilers
[wowui.git] / OmaAB / ActionBars.lua
1 -- ActionBars.lua
2 local _;
3 local pairs = pairs;
4 local format = string.format;
5 local ssub = string.sub;
6 local GetActionInfo, GetActionTexture = GetActionInfo, GetActionTexture;
7 local GetActionLossOfControlCooldown = GetActionLossOfControlCooldown;
8 local GetActionCooldown, GetActionCharges = GetActionCooldown, GetActionCharges;
9 local GetActionText, GetBindingKey = GetActionText, GetBindingKey;
10 local IsConsumableAction, IsStackableAction = IsConsumableAction, IsStackableAction;
11 local IsItemAction, GetActionCount = IsItemAction, GetActionCount;
12 local IsSpellOverlayed, GetMacroSpell = IsSpellOverlayed, GetMacroSpell;
13 local IsMounted = IsMounted;
14 local HasAction, IsUsableAction = HasAction, IsUsableAction;
15 local IsCurrentAction, IsAutoRepeatAction = IsCurrentAction, IsAutoRepeatAction;
16 local CreateFrame = CreateFrame;
17 local RegisterStateDriver = RegisterStateDriver;
18 local CooldownFrame_Set, CooldownFrame_Clear = CooldownFrame_Set, CooldownFrame_Clear;
19 local GameTooltip = GameTooltip;
20 local GameTooltip_SetDefaultAnchor = GameTooltip_SetDefaultAnchor;
21 local COOLDOWN_TYPE_LOSS_OF_CONTROL = COOLDOWN_TYPE_LOSS_OF_CONTROL;
22 local COOLDOWN_TYPE_NORMAL = COOLDOWN_TYPE_NORMAL;
23 local CDTexture = "Interface\\Cooldown\\edge";
24 local locCDTexture = "Interface\\Cooldown\\edge-LoC";
25
26 local BUTTONLOCK = true; -- change to lock button dragging
27
28 local settings = {
29     ["Oma1"] = {
30         bar = 1,
31         start = 1,
32         length = 12,
33         columns = 4,
34         size = 40,
35         x = 580,
36         y = 300,
37         nomouse = true,
38     },
39     ["Oma2"] = {
40         bar = 2,
41         start = 13,
42         length = 12,
43         columns = 4,
44         size = 40,
45         x = 580,
46         y = 180,
47         nomouse = true,
48     },
49     ["Oma3"] = {
50         bar = 3,
51         start = 25,
52         length = 12,
53         columns = 3,
54         x = 1824,
55         y = 128,
56         flyout = "LEFT",
57     },
58     ["Oma4"] = {
59         bar = 4,
60         start = 37,
61         length = 12,
62         columns = 3,
63         x = 1824,
64         y = 256,
65     },
66     ["Oma5"] = {
67         bar = 5,
68         start = 49,
69         length = 12,
70         columns = 3,
71         x = 1000,
72         y = 840,
73     },
74     ["Oma6"] = {
75         bar = 6,
76         start = 61,
77         length = 12,
78         x = 1000,
79         y = 600,
80     },
81     -- used as bonus bars for some classes
82     ["Oma7"] = {
83         bar = 7,
84         start = 73,
85         length = 12,
86         x = 1000,
87         y = 760,
88     },
89     ["Oma8"] = {
90         bar = 8,
91         start = 85,
92         length = 12,
93         x = 1000,
94         y = 720,
95     },
96     ["Oma9"] = {
97         bar = 9,
98         start = 97,
99         length = 12,
100         x = 1000,
101         y = 680,
102     },
103     ["Oma10"] = {
104         bar = 10,
105         start = 109,
106         length = 12,
107         x = 1000,
108         y = 640,
109     },
110 };
111
112 local usingBonusbars = {
113     --["WARRIOR"] = {[7]=true, [8]=true, [9]=true}, -- not using stance separated actionbars
114     ["DRUID"] = {[7]=true, [8]=true, [9]=true}, -- moonkin form page is usable anyway
115     --["DRUID"] = {[7]=true, [8]=true, [9]=true,[10]=true},
116     ["ROGUE"] = {[7]=true},
117     --["PRIEST"] = {[7]=true}, -- shadowform doesn't change abilities
118 };
119
120 local chars = {
121     ["Stormreaver"] = {
122         ["Vildan"] = {1, 2, 3, 4,},
123         ["Gedren"] = {1, 2, 3, 4,},
124         ["Gazden"] = {1, 2, 3, 4,},
125     },
126 };
127
128 local buttons = {};
129 local activeButtons = {};
130
131 local ActionBars = CreateFrame("Frame", "OmaActionBars", UIParent);
132 local inheritedFrames =
133 "SecureActionButtonTemplate,SecureHandlerDragTemplate,SecureHandlerStateTemplate";
134
135 local function showTooltip(secure)
136     GameTooltip_SetDefaultAnchor(GameTooltip, secure);
137     GameTooltip:SetAction(secure:GetAttribute("action"));
138 end
139
140 local function hideTooltip()
141     GameTooltip:Hide();
142 end
143
144 local numChargeCDs = 0;
145 local function createChargeCD(parent)
146     numChargeCDs = numChargeCDs + 1;
147     local frame = CreateFrame("Cooldown", "OmaChargeCD"..numChargeCDs, parent, "CooldownFrameTemplate");
148     frame:SetHideCountdownNumbers(false);
149     frame:SetDrawSwipe(false);
150     frame:SetAllPoints(parent);
151     frame:SetFrameStrata("TOOLTIP");
152     return frame;
153 end
154
155 local function clearChargeCD(parent)
156     if parent.chargecd then CooldownFrame_Clear(parent.chargecd) end
157 end
158
159 local function startChargeCD(parent, start, duration, modrate)
160     if start == 0 then
161         return clearChargeCD(parent);
162     end
163     parent.chargecd = parent.chargecd or createChargeCD(parent);
164     CooldownFrame_Set(parent.chargecd, start, duration, true, true, modrate);
165 end
166
167 local redoCooldown;
168
169 local function updateCooldown(button, slot)
170     -- CD update from FrameXML/ActionButton.lua
171     local locstart, locduration = GetActionLossOfControlCooldown(slot);
172     local start, duration, enable, modrate = GetActionCooldown(slot);
173     local charges, maxcharges, chargestart, chargeduration, chargemodrate = GetActionCharges(slot);
174     -- avoid as many updates as possible by checking if there's changes first
175     if button.prev and
176        button.prev[1] == locstart    and button.prev[2] == locduration and
177        button.prev[3] == start       and button.prev[4] == duration and
178        button.prev[5] == enable      and button.prev[6] == modrate and
179        button.prev[7] == charges     and button.prev[8] == maxcharges and
180        button.prev[9] == chargestart and button.prev[10] == chargeduration and
181        button.prev[11] == chargemodrate then
182         return;
183     end
184     button.prev = { locstart, locduration, start, duration, enable, modrate,
185         charges, maxcharges, chargestart, chargeduration, chargemodrate };
186     if (locstart + locduration) > (start + duration) then
187         if button.cd.currentCooldownType ~= COOLDOWN_TYPE_LOSS_OF_CONTROL then
188             button.cd:SetEdgeTexture(locCDTexture);
189             button.cd:SetSwipeColor(0.17, 0, 0);
190             button.cd:SetHideCountdownNumbers(true);
191             button.cd.currentCooldownType = COOLDOWN_TYPE_LOSS_OF_CONTROL;
192         end
193
194         CooldownFrame_Set(button.cd, locstart, locduration, true, true, modrate);
195         clearChargeCD(button);
196     else
197         if button.cd.currentCooldownType ~= COOLDOWN_TYPE_NORMAL then
198             button.cd:SetEdgeTexture(CDTexture);
199             button.cd:SetSwipeColor(0, 0, 0);
200             button.cd:SetHideCountdownNumbers(false);
201             button.cd.currentCooldownType = COOLDOWN_TYPE_NORMAL;
202         end
203
204         if locstart > 0 then
205             button.cd:SetScript("OnCooldownDone", redoCooldown);
206         end
207         if charges and maxcharges and maxcharges > 1 and charges < maxcharges then
208             startChargeCD(button, chargestart, chargeduration, chargemodrate);
209         else
210             clearChargeCD(button);
211         end
212         CooldownFrame_Set(button.cd, start, duration, enable, false, modrate);
213     end
214 end
215
216 local function redoCooldown(cd)
217     local button = cd:GetParent();
218     cd:SetScript("OnCooldownDone", nil);
219     updateCooldown(button, button.slot);
220 end
221
222 local function updateCount(button, slot)
223     if IsConsumableAction(slot) or IsStackableAction(slot) or
224             (not IsItemAction(slot) and GetActionCount(slot) > 0) then
225         local count = GetActionCount(slot);
226         if count > 99 then
227             button.count:SetText("*");
228         else
229             button.count:SetText(count);
230         end
231         button.count:Show();
232     else
233         local charges, maxcharges = GetActionCharges(slot);
234         if maxcharges > 1 then
235             button.count:SetText(charges);
236             button.count:Show();
237         else
238             button.count:Hide();
239         end
240     end
241 end
242
243 local function updateUsable(button, slot)
244     local isUsable, noMana = IsUsableAction(slot);
245     if isUsable then
246         button.icon:SetVertexColor(1, 1, 1);
247     elseif noMana then
248         button.icon:SetVertexColor(0, 0.5, 1);
249     else
250         button.icon:SetVertexColor(0.4, 0.4, 0.4);
251     end
252 end
253
254 local function updateState(button, slot)
255     button:SetChecked(IsCurrentAction(slot) or IsAutoRepeatAction(slot));
256 end
257
258 local function updateGlow(button, slot)
259     local stype, id, _ = GetActionInfo(slot);
260     if stype == "spell" and IsSpellOverlayed(id) then
261         button.glow:Show();
262     elseif stype == "macro" then
263         local _, _, macroid = GetMacroSpell(id);
264         if macroid and IsSpellOverlayed(macroid) then
265             button.glow:Show();
266         else
267             button.glow:Hide();
268         end
269     else -- TODO FlyoutHasSpell glow
270         button.glow:Hide();
271     end
272 end
273
274 local function startGlow(button, slot, spell)
275     local stype, id, _ = GetActionInfo(slot);
276     if stype == "spell" and id == spell then
277         button.glow:Show();
278     elseif stype == "macro" then
279         local _, _, macroid = GetMacroSpell(id);
280         if macroid and macroid == spell then
281             button.glow:Show();
282         end
283     end
284     -- TODO FlyoutHasSpell glow
285 end
286
287 local function stopGlow(button, slot, spell)
288     local stype, id, _ = GetActionInfo(slot);
289     if stype == "spell" and id == spell then
290         button.glow:Hide();
291     elseif stype == "macro" then
292         local _, _, macroid = GetMacroSpell(id);
293         if macroid and macroid == spell then
294             button.glow:Hide();
295         end
296     end
297     -- TODO FlyoutHasSpell glow
298 end
299
300 local function updateButton(button, slot)
301     if HasAction(slot) then
302         activeButtons[slot] = button;
303         button.base:Show();
304         button.icon:SetTexture(GetActionTexture(slot));
305         updateCooldown(button, slot);
306         updateUsable(button, slot);
307         updateState(button, slot);
308         updateCount(button, slot);
309         updateGlow(button, slot);
310         if not IsConsumableAction(slot) and not IsStackableAction(slot) then
311             button.text:SetText(ssub(GetActionText(slot) or "", 1, 4));
312             button.text:Show();
313         end
314         if button.hotkey.shown then button.hotkey:Show() end
315     else
316         activeButtons[slot] = nil;
317         if not button.grid then button.base:Hide() end
318         button.icon:SetTexture(nil);
319         button.cd:Hide();
320         button.count:Hide();
321         button.hotkey:Hide();
322         button.text:Hide();
323         button.glow:Hide();
324         button:SetChecked(false);
325     end
326 end
327
328 local function updateHotkeys(button)
329     local key = GetBindingKey(format("CLICK %s:LeftButton", button:GetName()));
330     if key and key ~= "" then
331         -- from LibKeyBound-1.0
332         key = key:upper();
333         key = key:gsub(" ", "");
334         key = key:gsub("ALT%-", "a");
335         key = key:gsub("CTRL%-", "c");
336         key = key:gsub("SHIFT%-", "s");
337         key = key:gsub("NUMPAD", "n");
338         button.hotkey:SetText(key);
339         button.hotkey.shown = true;
340         button.hotkey:Show();
341     else
342         button.hotkey.shown = nil;
343         button.hotkey:Hide();
344     end
345 end
346
347 local mainbartoggle = "[overridebar][possessbar][shapeshift]possess;";
348 mainbartoggle = mainbartoggle.."[bonusbar:1,stealth:1]bonusbar2;"; -- prowl
349 mainbartoggle = mainbartoggle.."[bonusbar:1]bonusbar1;[bonusbar:2]bonusbar2;"; -- cat form, unused
350 mainbartoggle = mainbartoggle.."[bonusbar:3]bonusbar3;[bonusbar:4]bonusbar4;"; -- bear form, moonkin form
351 mainbartoggle = mainbartoggle.."normal";
352 local function setupSnippets(secure, slot)
353     -- FrameXML/SecureHandlers.lua has arguments and return value
354     -- args: self, button, kind, value, ... (kind, value, ... from GetCursorInfo())
355     -- returns: kind, target, detail
356     -- or: "clear", kind, target, detail
357     -- used for Pickup* functions
358     -- some of these snippets based on LibActionButton-1.0
359     secure:SetAttribute("_ondragstart", [=[
360         return "action", self:GetAttribute("action");
361     ]=]);
362     secure:SetAttribute("_onreceivedrag", [=[
363         if not kind or not value then return nil end
364         return "action", self:GetAttribute("action");
365     ]=]);
366     -- pre-wrapper can pass a message to post-wrapper
367     secure:WrapScript(secure, "OnDragStart", [=[
368         local kind, value = GetActionInfo(self:GetAttribute("action"));
369         return "message", format("%s|%s", tostring(kind), tostring(value));
370     ]=], [=[
371         local kind, value = GetActionInfo(self:GetAttribute("action"));
372         if message ~= format("%s|%s", tostring(kind), tostring(value)) then
373             self:CallMethod("ActionChanged");
374         end
375     ]=]);
376     secure:WrapScript(secure, "OnReceiveDrag", [=[
377         local kind, value = GetActionInfo(self:GetAttribute("action"));
378         return "message", format("%s|%s", tostring(kind), tostring(value));
379     ]=], [=[
380         local kind, value = GetActionInfo(self:GetAttribute("action"));
381         if message ~= format("%s|%s", tostring(kind), tostring(value)) then
382             self:CallMethod("ActionChanged");
383         end
384     ]=]);
385     function secure:UpdateState()
386         return updateState(self, self.slot);
387     end
388     secure:WrapScript(secure, "OnClick", [=[
389         local kind, value = GetActionInfo(self:GetAttribute("action"));
390         return nil, format("%s|%s", tostring(kind), tostring(value));
391     ]=], [=[
392         local kind, value = GetActionInfo(self:GetAttribute("action"));
393         if message ~= format("%s|%s", tostring(kind), tostring(value)) then
394             self:CallMethod("ActionChanged");
395         else
396             self:CallMethod("UpdateState");
397         end
398     ]=]);
399     if slot < 13 then
400         -- first action bar has possible states based on vehicle/possess etc.
401         secure:SetAttribute("origaction", slot);
402         secure:SetAttribute("_onstate-possess", [=[
403             local oldslot = self:GetAttribute("action");
404             if newstate == "possess" then
405                 local slot;
406                 if HasVehicleActionBar() then
407                     slot = (GetVehicleBarIndex()-1)*12+self:GetAttribute("origaction");
408                 elseif HasOverrideActionBar() then
409                     slot = (GetOverrideBarIndex()-1)*12+self:GetAttribute("origaction");
410                 elseif HasTempShapeshiftActionBar() then
411                     slot = (GetTempShapeshiftBarIndex()-1)*12+self:GetAttribute("origaction");
412                 else
413                     -- something wrong, just revert to normal
414                     print("Possess bar index not found");
415                     slot = self:GetAttribute("origaction");
416                 end
417                 self:SetAttribute("action", slot);
418             elseif newstate == "bonusbar1" then
419                 self:SetAttribute("action", 72+self:GetAttribute("origaction"));
420             elseif newstate == "bonusbar2" then
421                 self:SetAttribute("action", 84+self:GetAttribute("origaction"));
422             elseif newstate == "bonusbar3" then
423                 self:SetAttribute("action", 96+self:GetAttribute("origaction"));
424             elseif newstate == "bonusbar4" then
425                 --self:SetAttribute("action", 108+self:GetAttribute("origaction"));
426                 -- moonkin form, don't change actionbar
427                 self:SetAttribute("action", self:GetAttribute("origaction"));
428             else
429                 self:SetAttribute("action", self:GetAttribute("origaction"));
430             end
431             self:CallMethod("ActionChanged", oldslot);
432         ]=]);
433         RegisterStateDriver(secure, "possess", mainbartoggle);
434     else
435         function secure:ShowButton() if HasAction(slot) then activeButtons[slot] = self end end
436         function secure:HideButton() activeButtons[slot] = nil end
437         -- all other action bar are hidden if with overridebar or vehicleui (not shapeshift, possessbar)
438         -- default Bartender4 options
439         secure:SetAttribute("_onstate-possess", [=[
440             if newstate == "possess" then
441                 self:Hide();
442                 self:CallMethod("HideButton");
443             else
444                 self:Show();
445                 self:CallMethod("ShowButton");
446             end
447         ]=]);
448         RegisterStateDriver(secure, "possess", "[overridebar][vehicleui] possess; normal");
449     end
450 end
451
452 local function createActionBar(parent, config)
453     local prev;
454     local i = 0;
455     local bar = CreateFrame("Frame", "OmaBTBar"..config.bar, parent, "SecureFrameTemplate");
456     bar:SetPoint("TOPLEFT", parent, "BOTTOMLEFT", config.x, config.y);
457     bar:SetWidth(1);
458     bar:SetHeight(1);
459     if config.hidden then
460         bar:Hide();
461     end
462     for slot = config.start, config.start+config.length-1 do
463         local secure = CreateFrame("CheckButton", "OmaBT"..slot, bar, inheritedFrames);
464         secure.slot = slot;
465         if slot == config.start then
466             secure:SetPoint("TOPLEFT");
467         elseif config.columns and i % config.columns == 0 then
468             secure:SetPoint("TOPLEFT", _G["OmaBT"..(slot-config.columns)], "BOTTOMLEFT");
469         else
470             secure:SetPoint("TOPLEFT", prev, "TOPRIGHT");
471         end
472         secure:RegisterForClicks("AnyUp");
473         if not BUTTONLOCK then
474             secure:RegisterForDrag("LeftButton", "RightButton");
475         end
476         if config.nomouse then
477             secure:EnableMouse(false);
478         else
479             -- only show tooltips for bars with mouse interaction
480             secure:SetScript("OnEnter", showTooltip);
481             secure:SetScript("OnLeave", hideTooltip);
482         end
483         secure:SetWidth(config.size or 32);
484         secure:SetHeight(config.size or 32);
485         secure.base = secure:CreateTexture(nil, "BACKGROUND");
486         secure.base:SetAllPoints();
487         secure.base:SetColorTexture(0, 0, 0, 0.5);
488         secure.iconbase = secure:CreateTexture(nil, "BORDER");
489         secure.iconbase:SetPoint("TOPLEFT", secure.base, "TOPLEFT", 1, -1);
490         secure.iconbase:SetPoint("BOTTOMRIGHT", secure.base, "BOTTOMRIGHT", -1, 1);
491         secure.iconbase:SetColorTexture(0, 0, 0, 0.5);
492         secure.iconbase:Hide();
493         secure.icon = secure:CreateTexture(nil, "ARTWORK");
494         secure.icon:SetPoint("TOPLEFT", secure.iconbase, "TOPLEFT");
495         secure.icon:SetPoint("BOTTOMRIGHT", secure.iconbase, "BOTTOMRIGHT");
496         secure.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93);
497         secure:SetCheckedTexture("Interface\\Buttons\\CheckButtonHilight");
498         secure.autocastable = secure:CreateTexture(nil, "OVERLAY");
499         secure.autocastable:SetPoint("CENTER");
500         secure.autocastable:SetWidth(58);
501         secure.autocastable:SetHeight(58);
502         secure.autocastable:SetTexture("Interface\\Buttons\\UI-AutoCastableOverlay");
503         secure.autocastable:Hide();
504         secure.glow = secure:CreateTexture(nil, "OVERLAY", nil, 1);
505         secure.glow:SetPoint("CENTER");
506         secure.glow:SetWidth(config.size and config.size+26 or 53);
507         secure.glow:SetHeight(config.size and config.size+26 or 53);
508         secure.glow:SetTexture("Interface\\SpellActivationOverlay\\IconAlert");
509         secure.glow:SetTexCoord(0.00781250, 0.50781250, 0.27734375, 0.52634375);
510         secure.glow:Hide();
511         secure.hotkey = secure:CreateFontString(nil, "OVERLAY", "NumberFontNormalGray");
512         secure.hotkey:SetPoint("TOPRIGHT", secure, "TOPRIGHT", 2, -1);
513         secure.count = secure:CreateFontString(nil, "OVERLAY", "NumberFontNormal");
514         secure.count:SetPoint("BOTTOMRIGHT", secure, "BOTTOMRIGHT", 2, -1);
515         secure.text = secure:CreateFontString(nil, "OVERLAY", "NumberFontNormal");
516         secure.text:SetPoint("BOTTOMLEFT", secure, "BOTTOMLEFT", 2, -1);
517         secure.text:Hide();
518         secure.cd = CreateFrame("Cooldown", "OmaBTCD"..slot, secure, "CooldownFrameTemplate");
519         secure.cd:SetAllPoints();
520         secure:SetAttribute("type", "action");
521         secure:SetAttribute("action", slot);
522         if config.flyout then
523             secure:SetAttribute("flyoutDirection", config.flyout);
524         end
525         function secure:ActionChanged(oldslot)
526             if oldslot then
527                 activeButtons[oldslot] = nil;
528                 self.prev = nil; -- invalidate previous CD when slot changes
529             end
530             self.slot = self:GetAttribute("action");
531             return updateButton(self, self.slot);
532         end
533         secure:ActionChanged(); -- initial update
534         setupSnippets(secure, slot);
535         updateHotkeys(secure);
536         buttons[slot] = secure;
537         prev = secure;
538         i = i + 1;
539     end
540 end
541
542 local function initialize()
543     local _, class = UnitClass("player");
544     local name, realm = UnitFullName("player");
545     ActionBars:SetFrameStrata("LOW");
546     ActionBars:SetPoint("BOTTOMLEFT");
547     ActionBars:SetWidth(1);
548     ActionBars:SetHeight(1);
549     for _, config in pairs(settings) do
550         if (not usingBonusbars[class] or not usingBonusbars[class][config.bar]) and
551            (not chars[realm] or not chars[realm][name] or chars[realm][name][config.bar]) then
552             createActionBar(ActionBars, config);
553         end
554     end
555 end
556
557 local function setupBindings()
558     _G["BINDING_HEADER_OmaAB"] = "Oma Action Bar";
559     for i = 1,10 do
560         _G["BINDING_HEADER_OMAABBLANK"..i] = "Bar "..i;
561         for j = 1,12 do
562             _G[format("BINDING_NAME_CLICK OmaBT%d:LeftButton", (i-1)*12+j)] = format("Bar %d Button %d", i, j);
563         end
564     end
565 end
566
567 local mounted = false;
568
569 local events = {
570     ["ACTIONBAR_UPDATE_COOLDOWN"] = function()
571         for _, button in pairs(activeButtons) do
572             updateCooldown(button, button.slot);
573         end
574     end,
575     ["SPELL_UPDATE_CHARGES"] = function()
576         for _, button in pairs(activeButtons) do
577             updateCount(button, button.slot);
578         end
579     end,
580     ["ACTIONBAR_SLOT_CHANGED"] = function(slot)
581         if buttons[slot] then buttons[slot]:ActionChanged() end
582     end,
583     ["ACTIONBAR_SHOWGRID"] = function()
584         for _, button in pairs(buttons) do
585             button.grid = true;
586             button.iconbase:Show();
587             if not activeButtons[button.slot] then button.base:Show() end
588         end
589     end,
590     ["ACTIONBAR_HIDEGRID"] = function()
591         for _, button in pairs(buttons) do
592             button.grid = nil;
593             button.iconbase:Hide();
594             if not activeButtons[button.slot] then button.base:Hide() end
595         end
596     end,
597     ["ACTIONBAR_UPDATE_STATE"] = function()
598         for _, button in pairs(activeButtons) do
599             updateState(button, button.slot);
600         end
601     end,
602     ["ACTIONBAR_UPDATE_USABLE"] = function()
603         for _, button in pairs(activeButtons) do
604             updateUsable(button, button.slot);
605         end
606     end,
607     ["UPDATE_OVERRIDE_ACTIONBAR"] = function()
608         if buttons[1] then -- called before PLAYER_LOGIN
609             for _, button in pairs(buttons) do
610                 updateButton(button, button.slot);
611             end
612         end
613     end,
614     ["START_AUTOREPEAT_SPELL"] = function()
615         for _, button in pairs(activeButtons) do
616             if IsAutoRepeatAction(button.slot) then
617                 button.autorepeating = true;
618                 button.icon:SetVertexColor(0, 1, 0.5);
619             end
620         end
621     end,
622     ["STOP_AUTOREPEAT_SPELL"] = function()
623         for _, button in pairs(activeButtons) do
624             if button.autorepeating then
625                 button.autorepeating = nil;
626                 updateUsable(button, button.slot);
627             end
628         end
629     end,
630     ["SPELL_ACTIVATION_OVERLAY_GLOW_SHOW"] = function(spell)
631         -- TODO create mapping from spellIDs to buttons
632         for _, button in pairs(activeButtons) do
633             startGlow(button, button.slot, spell);
634         end
635     end,
636     ["SPELL_ACTIVATION_OVERLAY_GLOW_HIDE"] = function(spell)
637         -- TODO create mapping from spellIDs to buttons
638         for _, button in pairs(activeButtons) do
639             stopGlow(button, button.slot, spell);
640         end
641     end,
642     ["UPDATE_BINDINGS"] = function()
643         for _, button in pairs(buttons) do
644             updateHotkeys(button);
645         end
646     end,
647     ["UNIT_AURA"] = function(unit)
648         -- using UNIT_AURA instead of COMPANION_UPDATE to not update every time
649         -- someone mounts, tracking player mount status with COMPANION_UPDATE is
650         -- inconsistent
651         if (not mounted and IsMounted()) or (mounted and not IsMounted()) then
652             mounted = not mounted;
653             for _, button in pairs(activeButtons) do
654                 updateState(button, button.slot);
655             end
656         end
657     end,
658     ["UPDATE_ALL_BUTTONS"] = function()
659         for _, button in pairs(buttons) do
660             updateButton(button, button.slot);
661         end
662     end,
663     ["PLAYER_LOGIN"] = function()
664         GameTooltip = _G["GameTooltip"];
665         initialize();
666     end,
667     ["ADDON_LOADED"] = function(addon)
668         if addon == "OmaAB" then
669             setupBindings();
670             ActionBars:UnregisterEvent("ADDON_LOADED");
671         end
672     end,
673 };
674 events["LOSS_OF_CONTROL_ADDED"] = events["ACTIONBAR_UPDATE_COOLDOWN"];
675 events["LOSS_OF_CONTROL_UPDATE"] = events["ACTIONBAR_UPDATE_COOLDOWN"]; -- TODO might change once tooltips are in
676 events["PLAYER_MOUNT_DISPLAY_CHANGED"] = events["ACTIONBAR_UPDATE_USABLE"];
677 events["TRADE_SKILL_SHOW"] = events["ACTIONBAR_UPDATE_STATE"];
678 events["TRADE_SKILL_CLOSE"] = events["ACTIONBAR_UPDATE_STATE"];
679 events["ARCHAEOLOGY_CLOSED"] = events["ACTIONBAR_UPDATE_STATE"];
680 events["PLAYER_ENTERING_WORLD"] = events["UPDATE_ALL_BUTTONS"];
681 events["UPDATE_VEHICLE_ACTIONBAR"] = events["UPDATE_ALL_BUTTONS"];
682 events["UPDATE_SHAPESHIFT_FORM"] = events["UPDATE_ALL_BUTTONS"];
683 events["SPELL_UPDATE_ICON"] = events["UPDATE_ALL_BUTTONS"];
684 events["PET_STABLE_UPDATE"] = events["UPDATE_ALL_BUTTONS"];
685 events["PET_STABLE_SHOW"] = events["UPDATE_ALL_BUTTONS"];
686 events["PLAYER_SPECIALIZATION_CHANGED"] = events["UPDATE_ALL_BUTTONS"];
687 events["UNIT_ENTERED_VEHICLE"] = function(unit)
688     if unit == "player" then events["ACTIONBAR_UPDATE_STATE"]() end
689 end
690 events["UNIT_EXITED_VEHICLE"] = events["UNIT_ENTERED_VEHICLE"];
691
692 ActionBars:RegisterEvent("ADDON_LOADED");
693 ActionBars:RegisterEvent("PLAYER_LOGIN");
694 ActionBars:RegisterEvent("ACTIONBAR_UPDATE_COOLDOWN");
695 ActionBars:RegisterEvent("ACTIONBAR_UPDATE_USABLE");
696 ActionBars:RegisterEvent("ACTIONBAR_UPDATE_STATE");
697 ActionBars:RegisterEvent("ACTIONBAR_SLOT_CHANGED");
698 ActionBars:RegisterEvent("ACTIONBAR_SHOWGRID");
699 ActionBars:RegisterEvent("ACTIONBAR_HIDEGRID");
700 ActionBars:RegisterEvent("SPELL_UPDATE_ICON");
701 ActionBars:RegisterEvent("SPELL_UPDATE_CHARGES");
702 ActionBars:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW");
703 ActionBars:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_HIDE");
704 ActionBars:RegisterEvent("UPDATE_VEHICLE_ACTIONBAR");
705 ActionBars:RegisterEvent("UPDATE_OVERRIDE_ACTIONBAR");
706 ActionBars:RegisterEvent("PLAYER_MOUNT_DISPLAY_CHANGED");
707 ActionBars:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED");
708 ActionBars:RegisterEvent("UNIT_ENTERED_VEHICLE");
709 ActionBars:RegisterEvent("UNIT_EXITED_VEHICLE");
710 ActionBars:RegisterEvent("PET_STABLE_UPDATE");
711 ActionBars:RegisterEvent("PET_STABLE_SHOW");
712 ActionBars:RegisterEvent("UPDATE_BINDINGS");
713 ActionBars:RegisterUnitEvent("UNIT_AURA", "player");
714 ActionBars:SetScript("OnEvent", function(self, event, arg1)
715     events[event](arg1);
716 end);