From d9a27f5e50331c22b603c7582b02eac7f005d84f Mon Sep 17 00:00:00 2001 From: Bunny67 Date: Tue, 25 Aug 2020 20:57:08 +0300 Subject: [PATCH] update WeakAuras.FindSpellActionButtons --- WeakAuras/GenericTrigger.lua | 57 +++++++++++++++++++++++++++++++++++- WeakAuras/Prototypes.lua | 27 +++-------------- 2 files changed, 60 insertions(+), 24 deletions(-) diff --git a/WeakAuras/GenericTrigger.lua b/WeakAuras/GenericTrigger.lua index 6b4b0de..f4b0d8f 100644 --- a/WeakAuras/GenericTrigger.lua +++ b/WeakAuras/GenericTrigger.lua @@ -59,7 +59,7 @@ if not WeakAuras.IsCorrectVersion() then return end -- Lua APIs local tinsert, tconcat, wipe = table.insert, table.concat, wipe -local tostring, pairs, type = tostring, pairs, type +local tonumber, tostring, pairs, type = tonumber, tostring, pairs, type local error, setmetatable = error, setmetatable WeakAurasAceEvents = setmetatable({}, {__tostring=function() return "WeakAuras" end}); @@ -3295,6 +3295,61 @@ do end end +-- Queued Action +do + local GetActionInfo, GetMacroSpell, GetSpellLink = GetActionInfo, GetMacroSpell, GetSpellLink + + local queuedActionFrame = nil + local buttonIDList = {} + local spellIDList = {} + + local function GetActionSpellID(slot) + local actionType, id, _, spellId = GetActionInfo(slot) + if actionType == "spell" then + return spellId + elseif actionType == "macro" then + local name, rank = GetMacroSpell(id) + if name then + local spellLink = GetSpellLink(name, rank or "") + if spellLink then + return tonumber(spellLink:match("spell:(%d+)")) + end + end + end + end + + function WeakAuras.WatchQueuedAction() + if not(queuedActionFrame) then + queuedActionFrame = CreateFrame("frame"); + WeakAuras.frames["Queued Action Frame"] = queuedActionFrame + for slotID = 1, 120 do + local spellID = GetActionSpellID(slotID) + if spellID then + buttonIDList[slotID] = spellID + spellIDList[spellID] = slotID + end + end + end + queuedActionFrame:RegisterEvent("ACTIONBAR_SLOT_CHANGED") + queuedActionFrame:SetScript("OnEvent", function(_, _, slotID) + WeakAuras.StartProfileSystem("generictrigger"); + local spellID = GetActionSpellID(slotID) + if spellID then + buttonIDList[slotID] = spellID + spellIDList[spellID] = slotID + elseif buttonIDList[slotID] then + spellIDList[buttonIDList[slotID]] = nil + buttonIDList[slotID] = nil + end + WeakAuras.StopProfileSystem("generictrigger"); + end) + end + + function WeakAuras.FindSpellActionButtons(spellID) + return spellIDList[spellID] + end +end + do local scheduled_scans = {}; diff --git a/WeakAuras/Prototypes.lua b/WeakAuras/Prototypes.lua index 1ccd9fc..78a4dcc 100644 --- a/WeakAuras/Prototypes.lua +++ b/WeakAuras/Prototypes.lua @@ -2,10 +2,9 @@ if not WeakAuras.IsCorrectVersion() then return end -- Lua APIs local tinsert, tsort = table.insert, table.sort -local tonumber, tostring = tonumber, tostring +local tostring = tostring local select, pairs, type = select, pairs, type local ceil, min = ceil, min -local match = string.match -- WoW APIs local GetTalentInfo = GetTalentInfo @@ -14,7 +13,6 @@ local GetSpellInfo, GetItemInfo, GetItemCount, GetItemIcon = GetSpellInfo, GetIt local GetShapeshiftFormInfo, GetShapeshiftForm = GetShapeshiftFormInfo, GetShapeshiftForm local GetRuneCooldown, UnitCastingInfo, UnitChannelInfo = GetRuneCooldown, UnitCastingInfo, UnitChannelInfo local UnitDetailedThreatSituation, UnitThreatSituation = UnitDetailedThreatSituation, UnitThreatSituation -local GetActionInfo, GetMacroSpell, GetSpellLink = GetActionInfo, GetMacroSpell, GetSpellLink local WeakAuras = WeakAuras local L = WeakAuras.L @@ -652,26 +650,6 @@ function WeakAuras.IsSpellKnownIncludingPet(spell) end end -function WeakAuras.FindSpellActionButtons(spellID) - for i = 120, 1, -1 do - local actionType, id, _, globalID = GetActionInfo(i) - if actionType == "spell" and globalID and globalID == spellID then - return i - elseif actionType == "macro" then - local name, rank = GetMacroSpell(id) - if name then - local spellLink = GetSpellLink(name, rank or "") - if spellLink then - globalID = tonumber(match(spellLink, "spell:(%d+)")) - if globalID and globalID == spellID then - return i - end - end - end - end - end -end - local function valuesForTalentFunction(trigger) return function() local single_class; @@ -5605,6 +5583,9 @@ WeakAuras.event_prototypes = { "ACTIONBAR_PAGE_CHANGED" }, name = L["Queued Action"], + loadFunc = function() + WeakAuras.WatchQueuedAction() + end, init = function(trigger) trigger.spellName = trigger.spellName or 0 local ret = [=[