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