mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-12 08:30:00 +00:00
bags: rewrite logic to detect openable container items
This commit is contained in:
+39
-44
@@ -6,7 +6,32 @@ pfUI:RegisterModule("bags", "vanilla:tbc", function ()
|
|||||||
Spell_Nature_MoonKey = {frame="picklock"},
|
Spell_Nature_MoonKey = {frame="picklock"},
|
||||||
}
|
}
|
||||||
local scanner = libtipscan:GetScanner("openable")
|
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
|
-- prevent from being placed offscreen
|
||||||
_G.StackSplitFrame:SetClampedToScreen(true)
|
_G.StackSplitFrame:SetClampedToScreen(true)
|
||||||
|
|
||||||
@@ -346,30 +371,6 @@ pfUI:RegisterModule("bags", "vanilla:tbc", function ()
|
|||||||
end
|
end
|
||||||
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)
|
function pfUI.bag:UpdateSlot(bag, slot)
|
||||||
if not pfUI.bags[bag] then return end
|
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)
|
SetItemButtonCount(pfUI.bags[bag].slots[slot].frame, count)
|
||||||
SetItemButtonDesaturated(pfUI.bags[bag].slots[slot].frame, locked, 0.5, 0.5, 0.5)
|
SetItemButtonDesaturated(pfUI.bags[bag].slots[slot].frame, locked, 0.5, 0.5, 0.5)
|
||||||
|
|
||||||
local hasItem
|
local hasItem = texture and 1 or nil
|
||||||
if texture then
|
|
||||||
hasItem = 1
|
|
||||||
else
|
|
||||||
hasItem = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
pfUI.bags[bag].slots[slot].frame.hasItem = hasItem
|
pfUI.bags[bag].slots[slot].frame.hasItem = hasItem
|
||||||
pfUI.bags[bag].slots[slot].frame.qtext:SetText("")
|
pfUI.bags[bag].slots[slot].frame.qtext:SetText("")
|
||||||
|
|
||||||
pfUI.bag:Openable(bag, slot, hasItem)
|
|
||||||
|
|
||||||
ContainerFrame_UpdateCooldown(bag, pfUI.bags[bag].slots[slot].frame)
|
ContainerFrame_UpdateCooldown(bag, pfUI.bags[bag].slots[slot].frame)
|
||||||
|
|
||||||
-- detect backdrop border color
|
-- detect backdrop border color
|
||||||
@@ -804,9 +797,10 @@ pfUI:RegisterModule("bags", "vanilla:tbc", function ()
|
|||||||
frame.open.backdrop:SetBackdropBorderColor(1,1,.25,1)
|
frame.open.backdrop:SetBackdropBorderColor(1,1,.25,1)
|
||||||
frame.open.texture:SetVertexColor(1,1,.25,1)
|
frame.open.texture:SetVertexColor(1,1,.25,1)
|
||||||
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
|
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
|
||||||
if openable.bag and openable.slot then
|
|
||||||
-- GameTooltip:SetText(openable.name) -- title only
|
local bag, slot = GetNextOpenable()
|
||||||
GameTooltip:SetBagItem(openable.bag, openable.slot)
|
if bag and slot then
|
||||||
|
GameTooltip:SetBagItem(bag, slot)
|
||||||
else
|
else
|
||||||
GameTooltip:SetText(_G.EMPTY)
|
GameTooltip:SetText(_G.EMPTY)
|
||||||
end
|
end
|
||||||
@@ -822,22 +816,23 @@ pfUI:RegisterModule("bags", "vanilla:tbc", function ()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
frame.open:SetScript("OnClick", function()
|
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()
|
ClearCursor()
|
||||||
if MerchantFrame:IsShown() then
|
if MerchantFrame:IsShown() then
|
||||||
HideUIPanel(MerchantFrame)
|
HideUIPanel(MerchantFrame)
|
||||||
end
|
end
|
||||||
UseContainerItem(openable.bag, openable.slot)
|
UseContainerItem(bag, slot)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- update tooltip
|
-- reload tootltip
|
||||||
if openable.bag and openable.slot then
|
local bag, slot = GetNextOpenable()
|
||||||
-- GameTooltip:SetText(openable.name) -- title only
|
if bag and slot then
|
||||||
GameTooltip:SetBagItem(openable.bag, openable.slot)
|
GameTooltip:SetBagItem(bag, slot)
|
||||||
else
|
else
|
||||||
GameTooltip:SetText(_G.EMPTY)
|
GameTooltip:SetText(_G.EMPTY)
|
||||||
end
|
end
|
||||||
GameTooltip:Show()
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user