mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-31 16:06:57 +00:00
pfUI.events was a bare CallbackRegistry for pfUI's custom events. Build it from ClassicAPI's EventRegistry instead, so the same object also takes game events through RegisterFrameEventAndCallback, sharing one frame for all of them. Move the frames that existed only to listen for a few events onto it: libspell, focus, pixelperfect, innervatecall, loothistory, unusable, equipmentmanager (bank + window refresh), the actionbar grid, updatenotify, turtle-wow's steady shot, nampower's spell queue, superwow's group tracking and unitxp's notifications, plus newitem and mapreveal, which used the global EventRegistry. Handlers take their payload as arguments instead of the event/arg globals, and the per-frame PLAYER_LOGOUT teardown goes away, since the registry unregisters its frame on logout.
58 lines
2.1 KiB
Lua
58 lines
2.1 KiB
Lua
pfUI:RegisterModule("unusable", function ()
|
|
if not pfUI.bag then return end
|
|
if C.appearance.bags.unusable ~= "1" then return end
|
|
|
|
pfUI.unusable = {}
|
|
|
|
local r, g, b, a = strsplit(",", C.appearance.bags.unusable_color)
|
|
|
|
function pfUI.unusable:UpdateSlot(bag, slot)
|
|
-- break on invalid bag slots
|
|
if not pfUI.bags[bag] then return end
|
|
if not pfUI.bags[bag].slots[slot] then return end
|
|
|
|
-- return on empty buttons
|
|
local frame = pfUI.bags[bag].slots[slot].frame
|
|
if not frame.hasItem then return end
|
|
|
|
-- C_PlayerInfo.CanUseItem is the "is this red in the tooltip" gate:
|
|
-- proficiency, required level, class/race, skill/spell/rep. It checks
|
|
-- *requirements* only, so a broken (0-durability) item still reads as
|
|
-- usable -- no durability-line exclusion needed like the old scanner.
|
|
local itemID = C_Container.GetContainerItemID(bag, slot)
|
|
if itemID and not C_PlayerInfo.CanUseItem(itemID) then
|
|
_G.SetItemButtonTextureVertexColor(frame, r, g, b, a)
|
|
end
|
|
end
|
|
|
|
-- update on regular pfUI button updates
|
|
hooksecurefunc(pfUI.bag, "UpdateSlot", function(self, bag, slot)
|
|
pfUI.unusable:UpdateSlot(bag, slot)
|
|
end)
|
|
|
|
-- update on bank frame itemlock updates
|
|
hooksecurefunc("BankFrameItemButton_UpdateLock", function()
|
|
pfUI.unusable:UpdateSlot(-1, this:GetID())
|
|
end)
|
|
|
|
-- requirement changes (level, proficiency/skill, required spell, reputation,
|
|
-- 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
|
|
local function Refresh()
|
|
for _, bag in pairs(pfUI.BACKPACK) do
|
|
pfUI.bag.delay.UpdateBag[bag] = true
|
|
end
|
|
-- the bank frame is only created on first bank visit
|
|
if pfUI.bag.left and pfUI.bag.left:IsShown() then
|
|
for _, bag in pairs(pfUI.BANK) do
|
|
pfUI.bag.delay.UpdateBag[bag] = true
|
|
end
|
|
end
|
|
end
|
|
|
|
for _, event in ipairs({ "PLAYER_LEVEL_UP", "SKILL_LINES_CHANGED", "SPELLS_CHANGED",
|
|
"FACTION_STANDING_CHANGED", "PLAYER_PVP_RANK_CHANGED" }) do
|
|
pfUI.events:RegisterFrameEventAndCallback(event, Refresh)
|
|
end
|
|
end)
|