3f90dc3 - Remove most healabsorb, remove concatenation from event handlers
[wowui.git] / OmaAB / ActionBars.lua
index 012c5f9..706e33e 100644 (file)
@@ -6,6 +6,7 @@ local ssub = string.sub;
 local GetActionInfo, GetActionTexture = GetActionInfo, GetActionTexture;
 local GetActionLossOfControlCooldown = GetActionLossOfControlCooldown;
 local GetActionCooldown, GetActionCharges = GetActionCooldown, GetActionCharges;
+local GetActionText, GetBindingKey = GetActionText, GetBindingKey;
 local IsConsumableAction, IsStackableAction = IsConsumableAction, IsStackableAction;
 local IsItemAction, GetActionCount = IsItemAction, GetActionCount;
 local IsSpellOverlayed, GetMacroSpell = IsSpellOverlayed, GetMacroSpell;
@@ -15,7 +16,6 @@ local IsCurrentAction, IsAutoRepeatAction = IsCurrentAction, IsAutoRepeatAction;
 local CreateFrame = CreateFrame;
 local RegisterStateDriver = RegisterStateDriver;
 local CooldownFrame_Set, CooldownFrame_Clear = CooldownFrame_Set, CooldownFrame_Clear;
-local CTimerAfter = C_Timer.After;
 local GameTooltip = GameTooltip;
 local GameTooltip_SetDefaultAnchor = GameTooltip_SetDefaultAnchor;
 local COOLDOWN_TYPE_LOSS_OF_CONTROL = COOLDOWN_TYPE_LOSS_OF_CONTROL;
@@ -171,6 +171,18 @@ local function updateCooldown(button, slot)
     local locstart, locduration = GetActionLossOfControlCooldown(slot);
     local start, duration, enable, modrate = GetActionCooldown(slot);
     local charges, maxcharges, chargestart, chargeduration, chargemodrate = GetActionCharges(slot);
+    -- avoid as many updates as possible by checking if there's changes first
+    if button.prev and
+       button.prev[1] == locstart    and button.prev[2] == locduration and
+       button.prev[3] == start       and button.prev[4] == duration and
+       button.prev[5] == enable      and button.prev[6] == modrate and
+       button.prev[7] == charges     and button.prev[8] == maxcharges and
+       button.prev[9] == chargestart and button.prev[10] == chargeduration and
+       button.prev[11] == chargemodrate then
+        return;
+    end
+    button.prev = { locstart, locduration, start, duration, enable, modrate,
+        charges, maxcharges, chargestart, chargeduration, chargemodrate };
     if (locstart + locduration) > (start + duration) then
         if button.cd.currentCooldownType ~= COOLDOWN_TYPE_LOSS_OF_CONTROL then
             button.cd:SetEdgeTexture(locCDTexture);
@@ -511,7 +523,10 @@ local function createActionBar(parent, config)
             secure:SetAttribute("flyoutDirection", config.flyout);
         end
         function secure:ActionChanged(oldslot)
-            if oldslot then activeButtons[oldslot] = nil end
+            if oldslot then
+                activeButtons[oldslot] = nil;
+                self.prev = nil; -- invalidate previous CD when slot changes
+            end
             self.slot = self:GetAttribute("action");
             return updateButton(self, self.slot);
         end
@@ -540,7 +555,7 @@ local function initialize()
 end
 
 local function setupBindings()
-    BINDING_HEADER_OmaAB = "Oma Action Bar";
+    _G["BINDING_HEADER_OmaAB"] = "Oma Action Bar";
     for i = 1,10 do
         _G["BINDING_HEADER_OMAABBLANK"..i] = "Bar "..i;
         for j = 1,12 do
@@ -550,33 +565,11 @@ local function setupBindings()
 end
 
 local mounted = false;
--- throttleCD 3-state, nil -> false -> true -> nil
--- this way there's not double update each time the first
--- update event comes, instead the extra throttled update comes
--- if there are >2 ACTIONBAR_UPDATE_COOLDOWN events in one frame
-local throttleCD = nil;
-local function throttleCDDone()
-    -- update CD once more to confirm newest CD change is taken in even with some throttling
-    for _, button in pairs(activeButtons) do
-        updateCooldown(button, button.slot);
-    end
-end
-local function throttleCDReset()
-    throttleCD = nil;
-end
 
 local events = {
     ["ACTIONBAR_UPDATE_COOLDOWN"] = function()
-        if not throttleCD then -- only update at most once/frame
-            throttleCD = throttleCD == false and true or false;
-            if throttleCD then
-                CTimerAfter(0.01, throttleCDDone); -- wait one frame
-            else
-                for _, button in pairs(activeButtons) do
-                    updateCooldown(button, button.slot);
-                end
-                CTimerAfter(0.01, throttleCDReset); -- wait one frame
-            end
+        for _, button in pairs(activeButtons) do
+            updateCooldown(button, button.slot);
         end
     end,
     ["SPELL_UPDATE_CHARGES"] = function()