From e59b1bd6d958d4e7ff2736b83b70603d2396b1c4 Mon Sep 17 00:00:00 2001 From: shagu Date: Sun, 2 Dec 2018 15:42:14 +0100 Subject: [PATCH] actionbar: reduce reagent tooltip scans --- modules/actionbar.lua | 49 ++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/modules/actionbar.lua b/modules/actionbar.lua index e43bc190..1ed4fa3b 100644 --- a/modules/actionbar.lua +++ b/modules/actionbar.lua @@ -72,30 +72,39 @@ pfUI:RegisterModule("actionbar", function () -- reagent counter local reagentslots = { } + local reagentbuttons = { } + local reagent_capture = SPELL_REAGENTS.."(.+)" local scanner = libtipscan:GetScanner("actionbar") + local reagentcounter = CreateFrame("Frame", "pfReagentCounter", UIParent) + reagentcounter:RegisterEvent("PLAYER_ENTERING_WORLD") + reagentcounter:RegisterEvent("ACTIONBAR_SLOT_CHANGED") + reagentcounter:RegisterEvent("BAG_UPDATE") + reagentcounter:SetScript("OnEvent", function() + for slot = 1, 120 do + -- update reagent names per slot + if event == "PLAYER_ENTERING_WORLD" or event == "ACTIONBAR_SLOT_CHANGED" then + reagentslots[slot] = nil + scanner:SetAction(slot) + local _, reagents = scanner:Find(reagent_capture) + if reagents then + reagentslots[slot] = reagents + end + end - hooksecurefunc("ActionButton_OnEvent", function() - if event == "BAG_UPDATE" and arg1 < 5 then - ActionButton_Update() + -- update buttons + if reagentbuttons[slot] then + _G.this = reagentbuttons[slot] + ActionButton_Update() + end end end) - local reagent_capture = SPELL_REAGENTS.."(.+)" local oldIsConsumableAction = IsConsumableAction _G.IsConsumableAction = function(slot) if oldIsConsumableAction(slot) then return true end if this and this.GetParent and ActionButton_GetPagedID(this) == slot then - reagentslots[slot] = nil - scanner:SetAction(slot) - local _, reagents = scanner:Find(reagent_capture) - if reagents then - reagentslots[slot] = reagents - this:RegisterEvent("BAG_UPDATE") - return true - end - - this:UnregisterEvent("BAG_UPDATE") - return nil + reagentbuttons[slot] = reagentbuttons[slot] or this + return reagentslots[slot] and true end end @@ -105,7 +114,9 @@ pfUI:RegisterModule("actionbar", function () return GetItemCount(reagentslots[slot]) end - if oldGetActionCount(slot) then return oldGetActionCount(slot) end + if oldGetActionCount(slot) then + return oldGetActionCount(slot) + end end if C.bars.glowrange == "1" then @@ -530,7 +541,7 @@ pfUI:RegisterModule("actionbar", function () pushed:SetAllPoints(button) pushed:SetTexCoord(.08,.92,.08,.92) button.SetPushedTexture = function() return end - + local checked = button:GetCheckedTexture() checked:SetAllPoints(button) checked:SetTexCoord(.08,.92,.08,.92) @@ -568,7 +579,7 @@ pfUI:RegisterModule("actionbar", function () pushed:SetAllPoints(button) pushed:SetTexCoord(.08,.92,.08,.92) button.SetPushedTexture = function() return end - + local checked = button:GetCheckedTexture() checked:SetAllPoints(button) checked:SetTexCoord(.08,.92,.08,.92) @@ -622,7 +633,7 @@ pfUI:RegisterModule("actionbar", function () pushed:SetAllPoints(button) pushed:SetTexCoord(.08,.92,.08,.92) button.SetPushedTexture = function() return end - + local checked = button:GetCheckedTexture() checked:SetAllPoints(button) checked:SetTexCoord(.08,.92,.08,.92)