mirror of
https://github.com/brues-code/pfUI.git
synced 2026-09-27 01:46:03 +00:00
unusable: rework module and rewrite caching logic
This commit is contained in:
+38
-27
@@ -10,47 +10,58 @@ pfUI:RegisterModule("unusable", "vanilla:tbc", function ()
|
||||
pfUI.unusable:RegisterEvent("ACTIONBAR_HIDEGRID")
|
||||
pfUI.unusable:RegisterEvent("PLAYERBANKSLOTS_CHANGED")
|
||||
pfUI.unusable:RegisterEvent("BANKFRAME_OPENED")
|
||||
pfUI.unusable.cache = {}
|
||||
pfUI.unusable.frames = {}
|
||||
|
||||
local scanner = libtipscan:GetScanner("unusable")
|
||||
local dura_capture = string.gsub(DURABILITY_TEMPLATE, "%%[^%s]+", "(.+)")
|
||||
local durability = string.gsub(DURABILITY_TEMPLATE, "%%[^%s]+", "(.+)")
|
||||
local r, g, b, a = strsplit(",", C.appearance.bags.unusable_color)
|
||||
|
||||
function pfUI.unusable:UpdateSlot(bag, slot)
|
||||
local self = self or pfUI.unusable
|
||||
|
||||
local frame = pfUI.bags[bag].slots[slot].frame
|
||||
self.cache[bag] = self.cache[bag] or {}
|
||||
local name = frame:GetName()
|
||||
|
||||
-- clear previous item slot caches if existing
|
||||
if self.frames[bag] and self.frames[bag][slot] then
|
||||
self.frames[bag][slot] = nil
|
||||
end
|
||||
|
||||
if frame.hasItem then
|
||||
-- write current item frame to cache
|
||||
self.frames[bag] = self.frames[bag] or {}
|
||||
self.frames[bag][slot] = frame
|
||||
|
||||
-- read item tooltip
|
||||
if bag == BANK_CONTAINER then
|
||||
-- scanner:SetOwner(WorldFrame,"ANCHOR_NONE")
|
||||
scanner:SetInventoryItem("player", 39+slot)
|
||||
else
|
||||
-- scanner:SetOwner(WorldFrame,"ANCHOR_NONE")
|
||||
scanner:SetBagItem(bag, slot)
|
||||
end
|
||||
local name = frame:GetName()
|
||||
local red_line = scanner:Color(RED_FONT_COLOR)
|
||||
if red_line then
|
||||
local left = scanner:Line(red_line)
|
||||
local _,_, is_durability = string.find(left,dura_capture,1)
|
||||
if not is_durability then
|
||||
_G.SetItemButtonTextureVertexColor(_G[name],r,g,b,a)
|
||||
self.cache[bag][slot] = true
|
||||
end
|
||||
else
|
||||
self.cache[bag][slot] = false
|
||||
end
|
||||
else
|
||||
if self.cache[bag][slot] then
|
||||
self.cache[bag][slot] = false
|
||||
end
|
||||
|
||||
-- check item tooltip
|
||||
local red = scanner:Color(RED_FONT_COLOR)
|
||||
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
|
||||
|
||||
function pfUI.unusable:UpdateCache()
|
||||
function pfUI.unusable:UpdateFrames()
|
||||
local self = self or pfUI.unusable
|
||||
for bag,slots in pairs(self.cache) do
|
||||
for slot,status in pairs(slots) do
|
||||
if status then
|
||||
pfUI.bag:UpdateSlot(bag, slot)
|
||||
end
|
||||
|
||||
-- update all known item frames
|
||||
for bag, slots in pairs(self.frames) do
|
||||
for slot, frame in pairs(slots) do
|
||||
pfUI.bag:UpdateSlot(bag, slot)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -59,10 +70,10 @@ pfUI:RegisterModule("unusable", "vanilla:tbc", function ()
|
||||
-- update all caches
|
||||
if event == "PLAYERBANKSLOTS_CHANGED" or event == "BANKFRAME_OPENED" then
|
||||
-- BankFrameItemButton_OnUpdate fires after UpdateSlot overriding changes
|
||||
QueueFunction(this.UpdateCache,this)
|
||||
QueueFunction(this.UpdateFrames, this)
|
||||
else
|
||||
-- regular update
|
||||
this:UpdateCache()
|
||||
this:UpdateFrames()
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user