bags: rewrite logic to detect openable container items

This commit is contained in:
shagu
2025-04-11 16:24:10 +02:00
parent 20ebdaf3b5
commit 97cc897ca2
+39 -44
View File
@@ -6,7 +6,32 @@ pfUI:RegisterModule("bags", "vanilla:tbc", function ()
Spell_Nature_MoonKey = {frame="picklock"},
}
local scanner = libtipscan:GetScanner("openable")
local openable = {}
-- function to detect openable items in inventory
local openable = { bag = nil, slot = nil, icon = nil }
local function GetNextOpenable()
if openable.icon and openable.icon == GetContainerItemInfo(openable.bag, openable.slot) then
return openable.bag, openable.slot
end
for bag=-2, 11 do
local bagsize = GetContainerNumSlots(bag)
if bag == -2 and pfUI.bag.showKeyring == true then bagsize = GetKeyRingSize() end
for slot=1, bagsize do
if GetContainerItemInfo(bag, slot) then
scanner:SetBagItem(bag, slot)
if scanner:Find(_G.ITEM_OPENABLE, true) then
openable.bag = bag
openable.slot = slot
openable.icon = GetContainerItemInfo(bag, slot)
return openable.bag, openable.slot
end
end
end
end
end
-- prevent from being placed offscreen
_G.StackSplitFrame:SetClampedToScreen(true)
@@ -346,30 +371,6 @@ pfUI:RegisterModule("bags", "vanilla:tbc", function ()
end
end
function pfUI.bag:Openable(bag, slot, hasItem)
local prev_bag, prev_slot = openable.bag, openable.slot
if bag == prev_bag and slot == prev_slot then
openable.bag = nil
openable.slot = nil
openable.name = nil
end
if hasItem then
scanner:SetBagItem(bag, slot)
if scanner:Find(_G.ITEM_OPENABLE, true) then
openable.bag = bag
openable.slot = slot
openable.name = scanner:Line(1)
end
end
if pfUI.bag.right and pfUI.bag.right.open then
if openable.bag and openable.slot then
pfUI.bag.right.open.texture:SetTexture(pfUI.media["img:full"])
else
pfUI.bag.right.open.texture:SetTexture(pfUI.media["img:empty"])
end
end
end
function pfUI.bag:UpdateSlot(bag, slot)
if not pfUI.bags[bag] then return end
@@ -449,18 +450,10 @@ pfUI:RegisterModule("bags", "vanilla:tbc", function ()
SetItemButtonCount(pfUI.bags[bag].slots[slot].frame, count)
SetItemButtonDesaturated(pfUI.bags[bag].slots[slot].frame, locked, 0.5, 0.5, 0.5)
local hasItem
if texture then
hasItem = 1
else
hasItem = nil
end
local hasItem = texture and 1 or nil
pfUI.bags[bag].slots[slot].frame.hasItem = hasItem
pfUI.bags[bag].slots[slot].frame.qtext:SetText("")
pfUI.bag:Openable(bag, slot, hasItem)
ContainerFrame_UpdateCooldown(bag, pfUI.bags[bag].slots[slot].frame)
-- detect backdrop border color
@@ -804,9 +797,10 @@ pfUI:RegisterModule("bags", "vanilla:tbc", function ()
frame.open.backdrop:SetBackdropBorderColor(1,1,.25,1)
frame.open.texture:SetVertexColor(1,1,.25,1)
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
if openable.bag and openable.slot then
-- GameTooltip:SetText(openable.name) -- title only
GameTooltip:SetBagItem(openable.bag, openable.slot)
local bag, slot = GetNextOpenable()
if bag and slot then
GameTooltip:SetBagItem(bag, slot)
else
GameTooltip:SetText(_G.EMPTY)
end
@@ -822,22 +816,23 @@ pfUI:RegisterModule("bags", "vanilla:tbc", function ()
end)
frame.open:SetScript("OnClick", function()
if openable.bag and openable.slot then
-- open next container item
local bag, slot = GetNextOpenable()
if bag and slot then
ClearCursor()
if MerchantFrame:IsShown() then
HideUIPanel(MerchantFrame)
end
UseContainerItem(openable.bag, openable.slot)
UseContainerItem(bag, slot)
end
-- update tooltip
if openable.bag and openable.slot then
-- GameTooltip:SetText(openable.name) -- title only
GameTooltip:SetBagItem(openable.bag, openable.slot)
-- reload tootltip
local bag, slot = GetNextOpenable()
if bag and slot then
GameTooltip:SetBagItem(bag, slot)
else
GameTooltip:SetText(_G.EMPTY)
end
GameTooltip:Show()
end)
end