f89d735 - Better method to avoid unnecessary CD updates
[wowui.git] / OmaAB / ActionBars.lua
index 729ac4f..e6637e9 100644 (file)
@@ -16,7 +16,8 @@ local CreateFrame = CreateFrame;
 local RegisterStateDriver = RegisterStateDriver;
 local CooldownFrame_Set, CooldownFrame_Clear = CooldownFrame_Set, CooldownFrame_Clear;
 local CTimerAfter = C_Timer.After;
 local RegisterStateDriver = RegisterStateDriver;
 local CooldownFrame_Set, CooldownFrame_Clear = CooldownFrame_Set, CooldownFrame_Clear;
 local CTimerAfter = C_Timer.After;
-local GameTooltip = nil;
+local GameTooltip = GameTooltip;
+local GameTooltip_SetDefaultAnchor = GameTooltip_SetDefaultAnchor;
 local COOLDOWN_TYPE_LOSS_OF_CONTROL = COOLDOWN_TYPE_LOSS_OF_CONTROL;
 local COOLDOWN_TYPE_NORMAL = COOLDOWN_TYPE_NORMAL;
 local CDTexture = "Interface\\Cooldown\\edge";
 local COOLDOWN_TYPE_LOSS_OF_CONTROL = COOLDOWN_TYPE_LOSS_OF_CONTROL;
 local COOLDOWN_TYPE_NORMAL = COOLDOWN_TYPE_NORMAL;
 local CDTexture = "Interface\\Cooldown\\edge";
@@ -120,6 +121,7 @@ local chars = {
     ["Stormreaver"] = {
         ["Vildan"] = {1, 2, 3, 4,},
         ["Gedren"] = {1, 2, 3, 4,},
     ["Stormreaver"] = {
         ["Vildan"] = {1, 2, 3, 4,},
         ["Gedren"] = {1, 2, 3, 4,},
+        ["Gazden"] = {1, 2, 3, 4,},
     },
 };
 
     },
 };
 
@@ -130,6 +132,15 @@ local ActionBars = CreateFrame("Frame", "OmaActionBars", UIParent);
 local inheritedFrames =
 "SecureActionButtonTemplate,SecureHandlerDragTemplate,SecureHandlerStateTemplate";
 
 local inheritedFrames =
 "SecureActionButtonTemplate,SecureHandlerDragTemplate,SecureHandlerStateTemplate";
 
+local function showTooltip(secure)
+    GameTooltip_SetDefaultAnchor(GameTooltip, secure);
+    GameTooltip:SetAction(secure:GetAttribute("action"));
+end
+
+local function hideTooltip()
+    GameTooltip:Hide();
+end
+
 local numChargeCDs = 0;
 local function createChargeCD(parent)
     numChargeCDs = numChargeCDs + 1;
 local numChargeCDs = 0;
 local function createChargeCD(parent)
     numChargeCDs = numChargeCDs + 1;
@@ -160,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);
     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);
     if (locstart + locduration) > (start + duration) then
         if button.cd.currentCooldownType ~= COOLDOWN_TYPE_LOSS_OF_CONTROL then
             button.cd:SetEdgeTexture(locCDTexture);
@@ -452,6 +475,10 @@ local function createActionBar(parent, config)
         end
         if config.nomouse then
             secure:EnableMouse(false);
         end
         if config.nomouse then
             secure:EnableMouse(false);
+        else
+            -- only show tooltips for bars with mouse interaction
+            secure:SetScript("OnEnter", showTooltip);
+            secure:SetScript("OnLeave", hideTooltip);
         end
         secure:SetWidth(config.size or 32);
         secure:SetHeight(config.size or 32);
         end
         secure:SetWidth(config.size or 32);
         secure:SetHeight(config.size or 32);
@@ -535,23 +562,11 @@ local function setupBindings()
 end
 
 local mounted = false;
 end
 
 local mounted = false;
-local throttleCD = false;
-local function throttleCDDone()
-    throttleCD = false
-    -- 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 events = {
     ["ACTIONBAR_UPDATE_COOLDOWN"] = function()
 
 local events = {
     ["ACTIONBAR_UPDATE_COOLDOWN"] = function()
-        if not throttleCD then -- only update at most once/frame
-            throttleCD = true;
-            for _, button in pairs(activeButtons) do
-                updateCooldown(button, button.slot);
-            end
-            CTimerAfter(0.01, throttleCDDone); -- wait one frame
+        for _, button in pairs(activeButtons) do
+            updateCooldown(button, button.slot);
         end
     end,
     ["SPELL_UPDATE_CHARGES"] = function()
         end
     end,
     ["SPELL_UPDATE_CHARGES"] = function()
@@ -643,7 +658,7 @@ local events = {
         end
     end,
     ["PLAYER_LOGIN"] = function()
         end
     end,
     ["PLAYER_LOGIN"] = function()
-        GameTooltip = _G["GameTooltip"]; -- TODO use PLAYER_ENTERING_WORLD with MoveAnything
+        GameTooltip = _G["GameTooltip"];
         initialize();
     end,
     ["ADDON_LOADED"] = function(addon)
         initialize();
     end,
     ["ADDON_LOADED"] = function(addon)
@@ -670,7 +685,6 @@ events["UNIT_ENTERED_VEHICLE"] = function(unit)
     if unit == "player" then events["ACTIONBAR_UPDATE_STATE"]() end
 end
 events["UNIT_EXITED_VEHICLE"] = events["UNIT_ENTERED_VEHICLE"];
     if unit == "player" then events["ACTIONBAR_UPDATE_STATE"]() end
 end
 events["UNIT_EXITED_VEHICLE"] = events["UNIT_ENTERED_VEHICLE"];
--- tooltips
 
 ActionBars:RegisterEvent("ADDON_LOADED");
 ActionBars:RegisterEvent("PLAYER_LOGIN");
 
 ActionBars:RegisterEvent("ADDON_LOADED");
 ActionBars:RegisterEvent("PLAYER_LOGIN");