fix: replace bags

This commit is contained in:
Salikh Gurgenidze
2025-11-18 01:53:31 +04:00
parent e39b77e7b4
commit 748afb680c
3 changed files with 205 additions and 65 deletions
+64 -21
View File
@@ -1378,6 +1378,25 @@ function Guda_BagSlot_OnLoad(button, bagID)
button:RegisterEvent("ITEM_LOCK_CHANGED") button:RegisterEvent("ITEM_LOCK_CHANGED")
button:RegisterEvent("CURSOR_UPDATE") button:RegisterEvent("CURSOR_UPDATE")
button:RegisterEvent("UNIT_INVENTORY_CHANGED") button:RegisterEvent("UNIT_INVENTORY_CHANGED")
-- Accept drops (equip when a bag is dropped on this slot)
button:SetScript("OnReceiveDrag", function()
if this and this.bagID and this.bagID ~= 0 and CursorHasItem and CursorHasItem() then
local inv = ContainerIDToInventoryID(this.bagID)
if EquipCursorItem then
EquipCursorItem(inv)
elseif PutItemInBag then
PutItemInBag(inv)
end
Guda_BagSlot_Update(this, this.bagID)
if BagFrame and BagFrame.Update then BagFrame:Update() end
end
end)
end
-- Ensure we handle right-click toggling like BankFrame
if button.RegisterForClicks then
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
end end
-- Initial update -- Initial update
@@ -1395,6 +1414,9 @@ function Guda_BagSlot_OnDragStart(frame, bagID)
frame:SetAlpha(0.6) frame:SetAlpha(0.6)
-- Immediate pickup for Classic -- Immediate pickup for Classic
PickupInventoryItem(invSlot) PickupInventoryItem(invSlot)
-- Instantly reflect the change in UI (slot is now empty on cursor pickup)
Guda_BagSlot_Update(frame, bagID)
if BagFrame and BagFrame.Update then BagFrame:Update() end
end end
-- If no texture (empty slot), do nothing - drag won't start -- If no texture (empty slot), do nothing - drag won't start
end end
@@ -1461,31 +1483,37 @@ end
-- OnClick handler -- OnClick handler
function Guda_BagSlot_OnClick(button, bagID) function Guda_BagSlot_OnClick(button, bagID)
-- Shift-click: Pick up/equip bag (original behavior) local which = arg1 -- Vanilla uses global arg1 for mouse button name
if IsShiftKeyDown() then
if bagID == 0 then
return -- Can't pick up backpack
end
local invSlot = ContainerIDToInventoryID(bagID) -- Right-Click: toggle visibility
if CursorHasItem() then if which == "RightButton" then
PickupInventoryItem(invSlot) hiddenBags[bagID] = not hiddenBags[bagID]
else
PickupInventoryItem(invSlot) -- Update bag slot visual (dim/undim)
end Guda_BagSlot_Update(button, bagID)
-- Refresh the bag display
BagFrame:Update()
addon:Debug(string.format("Bag %d visibility toggled via %s: %s", bagID, tostring(which), hiddenBags[bagID] and "hidden" or "visible"))
return return
end end
-- Regular click: Toggle bag visibility -- Left-Click: equip bag from cursor into this slot (bags 1-4 only)
hiddenBags[bagID] = not hiddenBags[bagID] if which == "LeftButton" then
if bagID ~= 0 and CursorHasItem and CursorHasItem() then
-- Update bag slot visual (dim/undim) local invSlot = ContainerIDToInventoryID(bagID)
Guda_BagSlot_Update(button, bagID) if EquipCursorItem then
EquipCursorItem(invSlot)
-- Refresh the bag display else
BagFrame:Update() if PutItemInBag then PutItemInBag(invSlot) end
end
addon:Debug(string.format("Bag %d visibility toggled: %s", bagID, hiddenBags[bagID] and "hidden" or "visible")) -- Update visuals after attempted equip
Guda_BagSlot_Update(button, bagID)
BagFrame:Update()
end
return
end
end end
-- OnEnter handler for tooltip -- OnEnter handler for tooltip
@@ -1497,6 +1525,11 @@ function Guda_BagSlot_OnEnter(button, bagID)
GameTooltip:SetText("Backpack", 1.0, 1.0, 1.0) GameTooltip:SetText("Backpack", 1.0, 1.0, 1.0)
local numSlots = GetContainerNumSlots(0) local numSlots = GetContainerNumSlots(0)
GameTooltip:AddLine(string.format("%d Slots", numSlots), 0.8, 0.8, 0.8) GameTooltip:AddLine(string.format("%d Slots", numSlots), 0.8, 0.8, 0.8)
if hiddenBags[bagID] then
GameTooltip:AddLine("(Hidden - Right-Click to show)", 0.8, 0.5, 0.5)
else
GameTooltip:AddLine("(Right-Click to hide)", 0.5, 0.8, 0.5)
end
else else
-- Bag slot tooltip -- Bag slot tooltip
local invSlot = ContainerIDToInventoryID(bagID) local invSlot = ContainerIDToInventoryID(bagID)
@@ -1505,10 +1538,20 @@ function Guda_BagSlot_OnEnter(button, bagID)
if hasItem then if hasItem then
-- Show bag item tooltip -- Show bag item tooltip
GameTooltip:SetInventoryItem("player", invSlot) GameTooltip:SetInventoryItem("player", invSlot)
if hiddenBags[bagID] then
GameTooltip:AddLine("(Hidden - Right-Click to show)", 0.8, 0.5, 0.5)
else
GameTooltip:AddLine("(Right-Click to hide)", 0.5, 0.8, 0.5)
end
else else
-- Empty slot -- Empty slot
GameTooltip:SetText(string.format("Bag %d", bagID), 1.0, 1.0, 1.0) GameTooltip:SetText(string.format("Bag %d", bagID), 1.0, 1.0, 1.0)
GameTooltip:AddLine("Empty", 0.5, 0.5, 0.5) GameTooltip:AddLine("Empty", 0.5, 0.5, 0.5)
if hiddenBags[bagID] then
GameTooltip:AddLine("(Hidden - Right-Click to show)", 0.8, 0.5, 0.5)
else
GameTooltip:AddLine("(Right-Click to hide)", 0.5, 0.8, 0.5)
end
end end
end end
+140 -43
View File
@@ -662,6 +662,29 @@ function BankFrame:EnsureBagButtonsInitialized()
GameTooltip:Hide() GameTooltip:Hide()
Guda_BankFrame_ClearHighlightedSlots() Guda_BankFrame_ClearHighlightedSlots()
end) end)
-- Handle clicks (Right-Click toggles visibility)
if btn.RegisterForClicks then
btn:RegisterForClicks("LeftButtonUp", "RightButtonUp")
end
btn:SetScript("OnClick", function()
Guda_BankBagSlot_OnClick(this, bagID, arg1)
end)
-- Enable dragging with left button
if btn.RegisterForDrag then
btn:RegisterForDrag("LeftButton")
end
btn:SetScript("OnDragStart", function()
Guda_BankBagSlot_OnDragStart(this, bagID)
end)
btn:SetScript("OnDragStop", function()
Guda_BankBagSlot_OnDragStop(this, bagID)
end)
-- Accept drops to equip bag into this slot
btn:SetScript("OnReceiveDrag", function()
Guda_BankBagSlot_OnReceiveDrag(this, bagID)
end)
end end
-- Run our OnLoad logic (will also register events and initial update) -- Run our OnLoad logic (will also register events and initial update)
@@ -681,7 +704,7 @@ function BankFrame:GetBankInvSlotForBagID(bagID)
if not bagID or bagID == -1 then return nil, nil end if not bagID or bagID == -1 then return nil, nil end
local bankButtonID = bagID - 4 local bankButtonID = bagID - 4
-- Some clients accept bagID, but Vanilla expects bankButtonID with isBag=1 -- Some clients accept bagID, but Vanilla expects bankButtonID with isBag=1
local invSlot = BankButtonIDToInvSlotID(bankButtonID, 1) local invSlot = BankButtonIDToInvSlotID(bagID, 1)
return invSlot, bankButtonID return invSlot, bankButtonID
end end
@@ -792,10 +815,10 @@ function Guda_BankBagSlot_OnLoad(button, bagID)
-- Set the inventory slot ID so the button knows which slot it represents -- Set the inventory slot ID so the button knows which slot it represents
if bagID ~= -1 then if bagID ~= -1 then
local bankButtonID = bagID - 4 local invSlot = addon.Modules.BankFrame:GetBankInvSlotForBagID(bagID)
-- In 1.12 need the second arg = 1 for bank bag inventory slots if invSlot then
local invSlot = BankButtonIDToInvSlotID(bagID, 1) button:SetID(invSlot)
button:SetID(invSlot) end
end end
-- Register for updates -- Register for updates
@@ -803,10 +826,36 @@ function Guda_BankBagSlot_OnLoad(button, bagID)
button:RegisterEvent("PLAYERBANKSLOTS_CHANGED") button:RegisterEvent("PLAYERBANKSLOTS_CHANGED")
button:RegisterEvent("ITEM_LOCK_CHANGED") button:RegisterEvent("ITEM_LOCK_CHANGED")
button:RegisterEvent("PLAYER_MONEY") button:RegisterEvent("PLAYER_MONEY")
button:RegisterEvent("CURSOR_UPDATE")
button:RegisterEvent("UNIT_INVENTORY_CHANGED")
button:SetScript("OnEvent", function() button:SetScript("OnEvent", function()
Guda_BankBagSlot_Update(this, this.bagID) Guda_BankBagSlot_Update(this, this.bagID)
end) end)
-- Ensure we respond to right-click for hide/show
if button.RegisterForClicks then
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
end
button:SetScript("OnClick", function()
Guda_BankBagSlot_OnClick(this, this.bagID, arg1)
end)
-- Enable dragging with left button
if button.RegisterForDrag then
button:RegisterForDrag("LeftButton")
end
button:SetScript("OnDragStart", function()
Guda_BankBagSlot_OnDragStart(this, this.bagID)
end)
button:SetScript("OnDragStop", function()
Guda_BankBagSlot_OnDragStop(this, this.bagID)
end)
-- Accept drops to equip bag into this slot
button:SetScript("OnReceiveDrag", function()
Guda_BankBagSlot_OnReceiveDrag(this, this.bagID)
end)
-- Initial update -- Initial update
Guda_BankBagSlot_Update(button, bagID) Guda_BankBagSlot_Update(button, bagID)
end end
@@ -883,45 +932,42 @@ function Guda_BankBagSlot_Update(button, bagID)
end end
-- OnClick handler for bank bag slots -- OnClick handler for bank bag slots
function Guda_BankBagSlot_OnClick(button, bagID) function Guda_BankBagSlot_OnClick(button, bagID, which)
-- Shift-click: Purchase slot or equip/remove bag (original behavior) local which = which or arg1 -- Vanilla uses global arg1 for mouse button name
if IsShiftKeyDown() then
local bankButtonID = bagID - 4
local numSlots = GetNumBankSlots()
local isPurchased = (bankButtonID <= numSlots)
local invSlot = BankFrame:GetBankInvSlotForBagID(bagID)
if bagID == -1 then if which == "RightButton" then
return -- Can't interact with main bank bag -- Toggle visibility
hiddenBankBags[bagID] = not hiddenBankBags[bagID]
Guda_BankBagSlot_Update(button, bagID)
BankFrame:Update()
if addon and addon.DEBUG then
addon:Debug(string.format("Bank bag %d visibility toggled via %s: %s", bagID, tostring(which), hiddenBankBags[bagID] and "hidden" or "visible"))
end end
return
end
if not isPurchased then if which == "LeftButton" then
-- Slot not purchased - try to purchase it -- Equip bag from cursor into this bank bag slot (5-10) when bank open and purchased
StaticPopup_Show("CONFIRM_BUY_BANK_SLOT") if bagID and bagID ~= -1 and CursorHasItem and CursorHasItem() then
else local invSlot, bankButtonID = BankFrame:GetBankInvSlotForBagID(bagID)
-- Slot is purchased - handle bag equipping/removing if addon and addon.DEBUG then
if CursorHasItem() then addon:Debug(string.format("OnClick LEFT bag=%s bankBtn=%s invSlot=%s bankOpen=%s purchased=%s cursorHas=%s", tostring(bagID), tostring(bankButtonID), tostring(invSlot), tostring(addon.Modules.BankScanner:IsBankOpen()), tostring(bankButtonID and bankButtonID <= GetNumBankSlots()), tostring(CursorHasItem())))
PickupInventoryItem(invSlot) end
else if invSlot and addon.Modules.BankScanner:IsBankOpen() then
local hasItem = GetInventoryItemTexture("player", invSlot) local purchased = (bankButtonID and bankButtonID <= GetNumBankSlots())
if hasItem then if purchased then
PickupInventoryItem(invSlot) if EquipCursorItem then
EquipCursorItem(invSlot)
elseif PutItemInBag then
PutItemInBag(invSlot)
end
Guda_BankBagSlot_Update(button, bagID)
BankFrame:Update()
end end
end end
end end
return return
end end
-- Regular click: Toggle bag visibility
hiddenBankBags[bagID] = not hiddenBankBags[bagID]
-- Update bag slot visual (dim/undim)
Guda_BankBagSlot_Update(button, bagID)
-- Refresh the bank display
BankFrame:Update()
addon:Debug(string.format("Bank bag %d visibility toggled: %s", bagID, hiddenBankBags[bagID] and "hidden" or "visible"))
end end
-- OnEnter handler for tooltip -- OnEnter handler for tooltip
@@ -934,9 +980,9 @@ function Guda_BankBagSlot_OnEnter(button, bagID)
local numSlots = 24 local numSlots = 24
GameTooltip:AddLine(string.format("%d Slots", numSlots), 0.8, 0.8, 0.8) GameTooltip:AddLine(string.format("%d Slots", numSlots), 0.8, 0.8, 0.8)
if hiddenBankBags[bagID] then if hiddenBankBags[bagID] then
GameTooltip:AddLine("(Hidden - Click to show)", 0.8, 0.5, 0.5) GameTooltip:AddLine("(Hidden - Right-Click to show)", 0.8, 0.5, 0.5)
else else
GameTooltip:AddLine("(Click to hide)", 0.5, 0.8, 0.5) GameTooltip:AddLine("(Right-Click to hide)", 0.5, 0.8, 0.5)
end end
else else
local invSlot, bankButtonID = BankFrame:GetBankInvSlotForBagID(bagID) local invSlot, bankButtonID = BankFrame:GetBankInvSlotForBagID(bagID)
@@ -952,21 +998,29 @@ function Guda_BankBagSlot_OnEnter(button, bagID)
-- Show bag item tooltip -- Show bag item tooltip
GameTooltip:SetInventoryItem("player", invSlot) GameTooltip:SetInventoryItem("player", invSlot)
if hiddenBankBags[bagID] then if hiddenBankBags[bagID] then
GameTooltip:AddLine("(Hidden - Click to show)", 0.8, 0.5, 0.5) GameTooltip:AddLine("(Hidden - Right-Click to show)", 0.8, 0.5, 0.5)
else else
GameTooltip:AddLine("(Click to hide)", 0.5, 0.8, 0.5) GameTooltip:AddLine("(Right-Click to hide)", 0.5, 0.8, 0.5)
end end
elseif isPurchased then elseif isPurchased then
-- Empty purchased slot -- Empty purchased slot
GameTooltip:SetText(string.format("Bank Bag Slot %d", bankButtonID or -1), 1.0, 1.0, 1.0) GameTooltip:SetText(string.format("Bank Bag Slot %d", bankButtonID or -1), 1.0, 1.0, 1.0)
GameTooltip:AddLine("Empty", 0.8, 0.8, 0.8) GameTooltip:AddLine("Empty", 0.8, 0.8, 0.8)
GameTooltip:AddLine("Shift+Click to equip bag", 0.5, 0.5, 0.5) if hiddenBankBags[bagID] then
GameTooltip:AddLine("(Hidden - Right-Click to show)", 0.8, 0.5, 0.5)
else
GameTooltip:AddLine("(Right-Click to hide)", 0.5, 0.8, 0.5)
end
else else
-- Unpurchased slot -- Unpurchased slot
GameTooltip:SetText(string.format("Bank Bag Slot %d", bankButtonID or -1), 1.0, 1.0, 1.0) GameTooltip:SetText(string.format("Bank Bag Slot %d", bankButtonID or -1), 1.0, 1.0, 1.0)
local cost = GetBankSlotCost(numSlots) local cost = GetBankSlotCost(numSlots)
GameTooltip:AddLine("Shift+Click to purchase", 0.5, 1.0, 0.5)
GameTooltip:AddLine(addon.Modules.Utils:FormatMoney(cost, false, true), 1, 1, 1) GameTooltip:AddLine(addon.Modules.Utils:FormatMoney(cost, false, true), 1, 1, 1)
if hiddenBankBags[bagID] then
GameTooltip:AddLine("(Hidden - Right-Click to show)", 0.8, 0.5, 0.5)
else
GameTooltip:AddLine("(Right-Click to hide)", 0.5, 0.8, 0.5)
end
end end
end end
@@ -1018,4 +1072,47 @@ function Guda_BankFrame_ClearHighlightedSlots()
button:SetAlpha(1.0) button:SetAlpha(1.0)
end end
end end
end end
-- Drag handlers for bank bag slots
function Guda_BankBagSlot_OnDragStart(button, bagID)
if not bagID or bagID == -1 then return end
if not addon.Modules.BankScanner:IsBankOpen() then return end
local invSlot = addon.Modules.BankFrame:GetBankInvSlotForBagID(bagID)
if not invSlot then return end
local texture = GetInventoryItemTexture("player", invSlot)
if texture then
button:SetAlpha(0.6)
PickupInventoryItem(invSlot)
-- Instantly refresh visuals to reflect the slot is now on cursor
Guda_BankBagSlot_Update(button, bagID)
if BankFrame and BankFrame.Update then BankFrame:Update() end
end
end
function Guda_BankBagSlot_OnDragStop(button, bagID)
button:SetAlpha(1.0)
end
function Guda_BankBagSlot_OnReceiveDrag(button, bagID)
if not bagID or bagID == -1 then return end
if not CursorHasItem or not CursorHasItem() then return end
if not addon.Modules.BankScanner:IsBankOpen() then return end
local invSlot, bankButtonID = addon.Modules.BankFrame:GetBankInvSlotForBagID(bagID)
if not invSlot then return end
local purchased = (bankButtonID and bankButtonID <= GetNumBankSlots())
if not purchased then return end
if EquipCursorItem then
EquipCursorItem(invSlot)
elseif PutItemInBag then
PutItemInBag(invSlot)
end
Guda_BankBagSlot_Update(button, bagID)
if BankFrame and BankFrame.Update then BankFrame:Update() end
end
+1 -1
View File
@@ -311,7 +311,7 @@
</Button> </Button>
<!-- Bank Bag Slot 5 --> <!-- Bank Bag Slot 5 -->
<Button name="$parent_BankBag5" inherits="ItemButtonTemplate"> <Button name="$parent_BankBag5" inherits="ItemButtonTemplate" movable="true">
<Size> <Size>
<AbsDimension x="24" y="24"/> <AbsDimension x="24" y="24"/>
</Size> </Size>