mirror of
https://github.com/brues-code/pfUI.git
synced 2026-11-05 02:06:57 +00:00
Bags: batch event-queued updates on a timer, drop the OnUpdate
This commit is contained in:
+30
-16
@@ -89,42 +89,56 @@ pfUI:RegisterModule("bags", function ()
|
|||||||
|
|
||||||
pfUI.bag.delay = { UpdateBag = {} }
|
pfUI.bag.delay = { UpdateBag = {} }
|
||||||
|
|
||||||
pfUI.bag:SetScript("OnUpdate", function()
|
-- run the updates queued by events, batched into one pass per 0.1s
|
||||||
-- update delayed ones every 0.1s
|
local function FlushDelayed()
|
||||||
if ( this.tick or 1) > GetTime() then return else this.tick = GetTime() + .1 end
|
local delay = pfUI.bag.delay
|
||||||
|
delay.pending = nil
|
||||||
|
|
||||||
if this.delay.RefreshSpells then
|
if delay.RefreshSpells then
|
||||||
this.delay.RefreshSpells = nil
|
delay.RefreshSpells = nil
|
||||||
pfUI.bag:RefreshSpells()
|
pfUI.bag:RefreshSpells()
|
||||||
end
|
end
|
||||||
|
|
||||||
if this.delay.CheckFullUpdate then
|
if delay.CheckFullUpdate then
|
||||||
this.delay.CheckFullUpdate = nil
|
delay.CheckFullUpdate = nil
|
||||||
pfUI.bag:CheckFullUpdate()
|
pfUI.bag:CheckFullUpdate()
|
||||||
end
|
end
|
||||||
|
|
||||||
if this.delay.UpdateCooldowns then
|
if delay.UpdateCooldowns then
|
||||||
this.delay.UpdateCooldowns = nil
|
delay.UpdateCooldowns = nil
|
||||||
pfUI.bag:UpdateCooldowns()
|
pfUI.bag:UpdateCooldowns()
|
||||||
end
|
end
|
||||||
|
|
||||||
if this.delay.UpdateItemLock then
|
if delay.UpdateItemLock then
|
||||||
this.delay.UpdateItemLock = nil
|
delay.UpdateItemLock = nil
|
||||||
pfUI.bag:UpdateItemLock()
|
pfUI.bag:UpdateItemLock()
|
||||||
end
|
end
|
||||||
|
|
||||||
if this.delay.UpdateSearch then
|
if delay.UpdateSearch then
|
||||||
this.delay.UpdateSearch = nil
|
delay.UpdateSearch = nil
|
||||||
pfUI.bag:UpdateSearch()
|
pfUI.bag:UpdateSearch()
|
||||||
end
|
end
|
||||||
|
|
||||||
for bag in pairs(this.delay.UpdateBag) do
|
for bag in pairs(delay.UpdateBag) do
|
||||||
this.delay.UpdateBag[bag] = nil
|
delay.UpdateBag[bag] = nil
|
||||||
pfUI.bag:UpdateBag(bag)
|
pfUI.bag:UpdateBag(bag)
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
|
|
||||||
|
local function ScheduleFlush()
|
||||||
|
if pfUI.bag.delay.pending then return end
|
||||||
|
pfUI.bag.delay.pending = true
|
||||||
|
C_Timer.After(.1, FlushDelayed)
|
||||||
|
end
|
||||||
|
|
||||||
|
function pfUI.bag:QueueBagUpdate(bag)
|
||||||
|
self.delay.UpdateBag[bag] = true
|
||||||
|
ScheduleFlush()
|
||||||
|
end
|
||||||
|
|
||||||
pfUI.bag:SetScript("OnEvent", function()
|
pfUI.bag:SetScript("OnEvent", function()
|
||||||
|
ScheduleFlush()
|
||||||
|
|
||||||
if event == "PLAYER_ENTERING_WORLD" then
|
if event == "PLAYER_ENTERING_WORLD" then
|
||||||
pfUI.bag:CreateBags()
|
pfUI.bag:CreateBags()
|
||||||
pfUI.bag.right:Hide()
|
pfUI.bag.right:Hide()
|
||||||
|
|||||||
@@ -37,15 +37,15 @@ pfUI:RegisterModule("unusable", function ()
|
|||||||
|
|
||||||
-- requirement changes (level, proficiency/skill, required spell, reputation,
|
-- requirement changes (level, proficiency/skill, required spell, reputation,
|
||||||
-- honor rank) don't touch the bags; queue a full rebag through pfUI.bag's
|
-- honor rank) don't touch the bags; queue a full rebag through pfUI.bag's
|
||||||
-- coalesced delay, whose UpdateSlot resets the tint before we reapply it
|
-- batched updates, whose UpdateSlot resets the tint before we reapply it
|
||||||
local function Refresh()
|
local function Refresh()
|
||||||
for _, bag in pairs(pfUI.BACKPACK) do
|
for _, bag in pairs(pfUI.BACKPACK) do
|
||||||
pfUI.bag.delay.UpdateBag[bag] = true
|
pfUI.bag:QueueBagUpdate(bag)
|
||||||
end
|
end
|
||||||
-- the bank frame is only created on first bank visit
|
-- the bank frame is only created on first bank visit
|
||||||
if pfUI.bag.left and pfUI.bag.left:IsShown() then
|
if pfUI.bag.left and pfUI.bag.left:IsShown() then
|
||||||
for _, bag in pairs(pfUI.BANK) do
|
for _, bag in pairs(pfUI.BANK) do
|
||||||
pfUI.bag.delay.UpdateBag[bag] = true
|
pfUI.bag:QueueBagUpdate(bag)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user