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