570b5ba - Add Mekkatorque mythic auras
[wowui.git] / OmaAB / ActionBars.lua
index 50a88b6..5b2233b 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,8 +16,8 @@ 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 = 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";
@@ -66,7 +67,6 @@ local settings = {
         bar = 5,
         start = 49,
         length = 12,
-        columns = 3,
         x = 1000,
         y = 840,
     },
@@ -117,9 +117,16 @@ local usingBonusbars = {
 };
 
 local chars = {
+    ["Sylvanas"] = {
+        ["Vildana"] = {1, 2, 3, 4,},
+    },
     ["Stormreaver"] = {
         ["Vildan"] = {1, 2, 3, 4,},
         ["Gedren"] = {1, 2, 3, 4,},
+        ["Gazden"] = {1, 2, 3, 4,},
+        ["Gedran"] = {1, 2, 3, 4,},
+        ["Iled"] = {1, 2, 3, 4,},
+        ["Gilden"] = {1, 2, 3, 4,},
     },
 };
 
@@ -130,6 +137,15 @@ local ActionBars = CreateFrame("Frame", "OmaActionBars", UIParent);
 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;
@@ -160,6 +176,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);
@@ -232,22 +260,14 @@ local function updateState(button, slot)
     button:SetChecked(IsCurrentAction(slot) or IsAutoRepeatAction(slot));
 end
 
-local function updateGlow(button, slot, spell, hide)
-    local stype, id, _ = GetActionInfo(slot);
-    if stype == "spell" and (spell and id == spell or IsSpellOverlayed(id)) then
-        if hide then
-            button.glow:Hide();
-        else
-            button.glow:Show();
-        end
+local function updateGlow(button, slot)
+    local stype, id = GetActionInfo(slot);
+    if stype == "spell" and IsSpellOverlayed(id) then
+        button.glow:Show();
     elseif stype == "macro" then
-        local _, _, macroid = GetMacroSpell(id);
-        if macroid and (spell and macroid == spell or IsSpellOverlayed(macroid)) then
-            if hide then
-                button.glow:Hide();
-            else
-                button.glow:Show();
-            end
+        local macroid = GetMacroSpell(id);
+        if macroid and IsSpellOverlayed(macroid) then
+            button.glow:Show();
         else
             button.glow:Hide();
         end
@@ -256,6 +276,32 @@ local function updateGlow(button, slot, spell, hide)
     end
 end
 
+local function startGlow(button, slot, spell)
+    local stype, id = GetActionInfo(slot);
+    if stype == "spell" and id == spell then
+        button.glow:Show();
+    elseif stype == "macro" then
+        local macroid = GetMacroSpell(id);
+        if macroid and macroid == spell then
+            button.glow:Show();
+        end
+    end
+    -- TODO FlyoutHasSpell glow
+end
+
+local function stopGlow(button, slot, spell)
+    local stype, id = GetActionInfo(slot);
+    if stype == "spell" and id == spell then
+        button.glow:Hide();
+    elseif stype == "macro" then
+        local macroid = GetMacroSpell(id);
+        if macroid and macroid == spell then
+            button.glow:Hide();
+        end
+    end
+    -- TODO FlyoutHasSpell glow
+end
+
 local function updateButton(button, slot)
     if HasAction(slot) then
         activeButtons[slot] = button;
@@ -434,6 +480,10 @@ local function createActionBar(parent, config)
         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);
@@ -458,8 +508,8 @@ local function createActionBar(parent, config)
         secure.autocastable:Hide();
         secure.glow = secure:CreateTexture(nil, "OVERLAY", nil, 1);
         secure.glow:SetPoint("CENTER");
-        secure.glow:SetWidth(config.size and config.size+20 or 52);
-        secure.glow:SetHeight(config.size and config.size+20 or 52);
+        secure.glow:SetWidth(config.size and config.size+26 or 53);
+        secure.glow:SetHeight(config.size and config.size+26 or 53);
         secure.glow:SetTexture("Interface\\SpellActivationOverlay\\IconAlert");
         secure.glow:SetTexCoord(0.00781250, 0.50781250, 0.27734375, 0.52634375);
         secure.glow:Hide();
@@ -478,7 +528,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
@@ -507,7 +560,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
@@ -517,23 +570,11 @@ local function setupBindings()
 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()
-        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()
@@ -594,17 +635,13 @@ local events = {
     ["SPELL_ACTIVATION_OVERLAY_GLOW_SHOW"] = function(spell)
         -- TODO create mapping from spellIDs to buttons
         for _, button in pairs(activeButtons) do
-            updateGlow(button, button.slot, spell);
-            -- CD update might be throttled, force it
-            updateCooldown(button, button.slot);
+            startGlow(button, button.slot, spell);
         end
     end,
     ["SPELL_ACTIVATION_OVERLAY_GLOW_HIDE"] = function(spell)
         -- TODO create mapping from spellIDs to buttons
         for _, button in pairs(activeButtons) do
-            updateGlow(button, button.slot, spell, true);
-            -- CD update might be throttled, force it
-            updateCooldown(button, button.slot);
+            stopGlow(button, button.slot, spell);
         end
     end,
     ["UPDATE_BINDINGS"] = function()
@@ -629,7 +666,6 @@ local events = {
         end
     end,
     ["PLAYER_LOGIN"] = function()
-        GameTooltip = _G["GameTooltip"]; -- TODO use PLAYER_ENTERING_WORLD with MoveAnything
         initialize();
     end,
     ["ADDON_LOADED"] = function(addon)
@@ -640,7 +676,7 @@ local events = {
     end,
 };
 events["LOSS_OF_CONTROL_ADDED"] = events["ACTIONBAR_UPDATE_COOLDOWN"];
-events["LOSS_OF_CONTROL_UPDATE"] = events["ACTIONBAR_UPDATE_COOLDOWN"]; -- TODO might change once tooltips are in
+events["LOSS_OF_CONTROL_UPDATE"] = events["ACTIONBAR_UPDATE_COOLDOWN"];
 events["PLAYER_MOUNT_DISPLAY_CHANGED"] = events["ACTIONBAR_UPDATE_USABLE"];
 events["TRADE_SKILL_SHOW"] = events["ACTIONBAR_UPDATE_STATE"];
 events["TRADE_SKILL_CLOSE"] = events["ACTIONBAR_UPDATE_STATE"];
@@ -656,8 +692,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"];
--- TODO overlay glow ? don't exactly know what it does, proc highlight?
--- tooltips
 
 ActionBars:RegisterEvent("ADDON_LOADED");
 ActionBars:RegisterEvent("PLAYER_LOGIN");