mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-20 03:20:49 +00:00
actionbar: rewrite reagent counter logic and caches
This commit is contained in:
+51
-35
@@ -1594,9 +1594,32 @@ pfUI:RegisterModule("actionbar", "vanilla:tbc", function ()
|
|||||||
if C.bars.reagents == "1" then
|
if C.bars.reagents == "1" then
|
||||||
local reagent_slots = { }
|
local reagent_slots = { }
|
||||||
local reagent_counts = { }
|
local reagent_counts = { }
|
||||||
local reagent_textureslots = { }
|
|
||||||
local reagent_capture = SPELL_REAGENTS.."(.+)"
|
local reagent_capture = SPELL_REAGENTS.."(.+)"
|
||||||
local scanner = libtipscan:GetScanner("actionbar")
|
local scanner = libtipscan:GetScanner("actionbar")
|
||||||
|
|
||||||
|
local UpdateSlot = function(slot)
|
||||||
|
local texture = GetActionTexture(slot)
|
||||||
|
|
||||||
|
-- update buttons that previously had an reagent
|
||||||
|
if reagent_slots[slot] and not HasAction(slot) then
|
||||||
|
reagent_slots[slot] = nil
|
||||||
|
updatecache[slot] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- search for reagent requirements
|
||||||
|
if HasAction(slot) then
|
||||||
|
scanner:SetAction(slot)
|
||||||
|
local _, reagents = scanner:Find(reagent_capture)
|
||||||
|
|
||||||
|
-- update on reagent requirement changes
|
||||||
|
if reagent_slots[slot] ~= reagents then
|
||||||
|
reagent_counts[reagents] = reagent_counts[reagents] or 0
|
||||||
|
reagent_slots[slot] = reagents
|
||||||
|
updatecache[slot] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local reagentcounter = CreateFrame("Frame", "pfReagentCounter", UIParent)
|
local reagentcounter = CreateFrame("Frame", "pfReagentCounter", UIParent)
|
||||||
reagentcounter:RegisterEvent("PLAYER_ENTERING_WORLD")
|
reagentcounter:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||||
reagentcounter:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
|
reagentcounter:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
|
||||||
@@ -1605,47 +1628,40 @@ pfUI:RegisterModule("actionbar", "vanilla:tbc", function ()
|
|||||||
if event == "BAG_UPDATE" then
|
if event == "BAG_UPDATE" then
|
||||||
this.event = true
|
this.event = true
|
||||||
else
|
else
|
||||||
for slot = 1, 120 do
|
this.scan = 1
|
||||||
local texture = GetActionTexture(slot)
|
|
||||||
|
|
||||||
-- update buttons that previously had an reagent
|
|
||||||
if reagent_slots[slot] and not texture then
|
|
||||||
reagent_textureslots[slot] = nil
|
|
||||||
reagent_slots[slot] = nil
|
|
||||||
updatecache[slot] = true
|
|
||||||
end
|
|
||||||
|
|
||||||
-- search for reagents on buttons with different icon
|
|
||||||
if reagent_textureslots[slot] ~= texture then
|
|
||||||
if HasAction(slot) then
|
|
||||||
reagent_textureslots[slot] = texture
|
|
||||||
scanner:SetAction(slot)
|
|
||||||
local _, reagents = scanner:Find(reagent_capture)
|
|
||||||
if reagents then
|
|
||||||
reagent_slots[slot] = reagents
|
|
||||||
reagent_counts[reagents] = reagent_counts[reagents] or 0
|
|
||||||
updatecache[slot] = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- limit bag events to one per second
|
-- limit events to one per second and smoothen action scanning
|
||||||
reagentcounter:SetScript("OnUpdate", function()
|
reagentcounter:SetScript("OnUpdate", function()
|
||||||
|
-- scan one action slot per frame
|
||||||
|
if this.scan and this.scan <= 120 then
|
||||||
|
UpdateSlot(this.scan)
|
||||||
|
this.scan = this.scan + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- trigger reagent count updates after action scans
|
||||||
|
if this.scan and this.scan >= 120 then
|
||||||
|
this.event = true
|
||||||
|
this.scan = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- queue events to fire only once per second
|
||||||
|
if not this.event then return end
|
||||||
if ( this.tick or 1) > GetTime() then return else this.tick = GetTime() + 1 end
|
if ( this.tick or 1) > GetTime() then return else this.tick = GetTime() + 1 end
|
||||||
|
|
||||||
if this.event then
|
-- scan for all reagent item counts
|
||||||
for item in pairs(reagent_counts) do
|
for item in pairs(reagent_counts) do
|
||||||
reagent_counts[item] = GetItemCount(item)
|
reagent_counts[item] = GetItemCount(item)
|
||||||
end
|
|
||||||
for slot in pairs(reagent_slots) do
|
|
||||||
updatecache[slot] = true
|
|
||||||
end
|
|
||||||
|
|
||||||
this.event = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- update all actionbar buttons
|
||||||
|
for slot in pairs(reagent_slots) do
|
||||||
|
updatecache[slot] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- remove event trigger
|
||||||
|
this.event = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function IsReagentAction(slot)
|
function IsReagentAction(slot)
|
||||||
|
|||||||
Reference in New Issue
Block a user