unusable: always rely on button caches again

This commit is contained in:
shagu
2024-04-23 17:57:17 +02:00
parent 119d5fe2a6
commit f7c8fdd886
+29 -37
View File
@@ -10,70 +10,62 @@ pfUI:RegisterModule("unusable", "vanilla:tbc", function ()
pfUI.unusable:RegisterEvent("ACTIONBAR_HIDEGRID") pfUI.unusable:RegisterEvent("ACTIONBAR_HIDEGRID")
pfUI.unusable:RegisterEvent("PLAYERBANKSLOTS_CHANGED") pfUI.unusable:RegisterEvent("PLAYERBANKSLOTS_CHANGED")
pfUI.unusable:RegisterEvent("BANKFRAME_OPENED") pfUI.unusable:RegisterEvent("BANKFRAME_OPENED")
pfUI.unusable.frames = {} pfUI.unusable.cache = {}
local scanner = libtipscan:GetScanner("unusable") local scanner = libtipscan:GetScanner("unusable")
local durability = string.gsub(DURABILITY_TEMPLATE, "%%[^%s]+", "(.+)") local durability = string.gsub(DURABILITY_TEMPLATE, "%%[^%s]+", "(.+)")
local r, g, b, a = strsplit(",", C.appearance.bags.unusable_color) local r, g, b, a = strsplit(",", C.appearance.bags.unusable_color)
function pfUI.unusable:UpdateSlot(bag, slot) function pfUI.unusable:UpdateSlot(bag, slot)
local self = self or pfUI.unusable -- create bag cache and clear slot cache
self.cache[bag] = self.cache[bag] or {}
self.cache[bag][slot] = nil
local frame = pfUI.bags[bag].slots[slot].frame local frame = pfUI.bags[bag].slots[slot].frame
local name = frame:GetName() local name = frame:GetName()
-- clear previous item slot caches if existing -- return on empty buttons
if self.frames[bag] and self.frames[bag][slot] then if not frame.hasItem then return end
self.frames[bag][slot] = nil
-- set the proper tooltip method
if bag == BANK_CONTAINER then
scanner:SetInventoryItem("player", 39+slot)
else
scanner:SetBagItem(bag, slot)
end end
if frame.hasItem then -- check for red color in tooltip
-- write current item frame to cache local red = scanner:Color(RED_FONT_COLOR)
self.frames[bag] = self.frames[bag] or {} if not red then return end
self.frames[bag][slot] = frame
-- read item tooltip -- check for broken items
if bag == BANK_CONTAINER then local left = scanner:Line(red)
-- scanner:SetOwner(WorldFrame,"ANCHOR_NONE") local _, _, broken = string.find(left, durability, 1)
scanner:SetInventoryItem("player", 39+slot) if broken then return end
else
-- scanner:SetOwner(WorldFrame,"ANCHOR_NONE")
scanner:SetBagItem(bag, slot)
end
-- check item tooltip -- update button vertex color
local red = scanner:Color(RED_FONT_COLOR) _G.SetItemButtonTextureVertexColor(frame, r, g, b, a)
if not red then return end
local left = scanner:Line(red)
-- ignore broken equipment
local _, _, is_broken = string.find(left, durability, 1)
if is_broken then return end
_G.SetItemButtonTextureVertexColor(_G[name], r, g, b, a)
end
end end
function pfUI.unusable:UpdateFrames() function pfUI.unusable:UpdateCache()
local self = self or pfUI.unusable local self = self or pfUI.unusable
-- update all known item frames -- iterate through all known caches
for bag, slots in pairs(self.frames) do for bag, slots in pairs(self.cache) do
for slot, frame in pairs(slots) do for slot, state in pairs(slots) do
pfUI.bag:UpdateSlot(bag, slot) pfUI.bag:UpdateSlot(bag, slot)
end end
end end
end end
pfUI.unusable:SetScript("OnEvent", function() pfUI.unusable:SetScript("OnEvent", function()
-- update all caches -- update all cached buttons
if event == "PLAYERBANKSLOTS_CHANGED" or event == "BANKFRAME_OPENED" then if event == "PLAYERBANKSLOTS_CHANGED" or event == "BANKFRAME_OPENED" then
-- BankFrameItemButton_OnUpdate fires after UpdateSlot overriding changes -- BankFrameItemButton_OnUpdate fires after UpdateSlot overriding changes
QueueFunction(this.UpdateFrames, this) QueueFunction(this.UpdateCache, this)
else else
-- regular update -- regular button update
this:UpdateFrames() this:UpdateCache()
end end
end) end)
end) end)