mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-24 13:00:50 +00:00
unusable: always rely on button caches again
This commit is contained in:
+29
-37
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user