fix: hide bags on click on bagslot container
This commit is contained in:
+67
-21
@@ -10,6 +10,7 @@ local currentViewChar = nil -- nil = current character
|
|||||||
local searchText = ""
|
local searchText = ""
|
||||||
local itemButtons = {}
|
local itemButtons = {}
|
||||||
local showKeyring = false -- Toggle for keyring display
|
local showKeyring = false -- Toggle for keyring display
|
||||||
|
local hiddenBags = {} -- Track which bags are hidden (bagID -> true/false)
|
||||||
|
|
||||||
-- Global click catcher for clearing search focus
|
-- Global click catcher for clearing search focus
|
||||||
local clickCatcher = nil
|
local clickCatcher = nil
|
||||||
@@ -187,14 +188,17 @@ function BagFrame:DisplayItems(bagData, isOtherChar, charName)
|
|||||||
local perRow = addon.Modules.DB:GetSetting("bagColumns") or 10
|
local perRow = addon.Modules.DB:GetSetting("bagColumns") or 10
|
||||||
local itemContainer = getglobal("Guda_BagFrame_ItemContainer")
|
local itemContainer = getglobal("Guda_BagFrame_ItemContainer")
|
||||||
|
|
||||||
-- Build bag list - include keyring if toggled on
|
-- Build bag list - include keyring if toggled on, skip hidden bags
|
||||||
local bagsToShow = {}
|
local bagsToShow = {}
|
||||||
for _, bagID in ipairs(addon.Constants.BAGS) do
|
for _, bagID in ipairs(addon.Constants.BAGS) do
|
||||||
table.insert(bagsToShow, bagID)
|
-- Skip bags that are hidden
|
||||||
|
if not hiddenBags[bagID] then
|
||||||
|
table.insert(bagsToShow, bagID)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add keyring (-2) at the end if toggled on
|
-- Add keyring (-2) at the end if toggled on and not hidden
|
||||||
if showKeyring then
|
if showKeyring and not hiddenBags[-2] then
|
||||||
table.insert(bagsToShow, -2) -- Insert at end
|
table.insert(bagsToShow, -2) -- Insert at end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1355,18 +1359,20 @@ function Guda_BagSlot_OnLoad(button, bagID)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Set up the button with proper ID
|
-- Set up the button with proper ID
|
||||||
-- For bags 1-4, we need to get the inventory slot ID
|
|
||||||
if bagID == 0 then
|
if bagID == 0 then
|
||||||
-- Backpack (bag 0) - set a special texture
|
-- Backpack (bag 0)
|
||||||
button.bagID = 0
|
button.bagID = 0
|
||||||
button.hasItem = 1
|
button.hasItem = 1
|
||||||
SetItemButtonTexture(button, "Interface\\Buttons\\Button-Backpack-Up")
|
SetItemButtonTexture(button, "Interface\\Buttons\\Button-Backpack-Up")
|
||||||
else
|
else
|
||||||
-- Bags 1-4: Get inventory slot ID (19, 20, 21, 22)
|
-- Bags 1-4
|
||||||
local invSlot = ContainerIDToInventoryID(bagID)
|
local invSlot = ContainerIDToInventoryID(bagID)
|
||||||
button:SetID(invSlot)
|
button:SetID(invSlot)
|
||||||
button.bagID = bagID
|
button.bagID = bagID
|
||||||
|
|
||||||
|
-- REGISTER FOR DRAG - This is crucial for Classic
|
||||||
|
button:RegisterForDrag("LeftButton")
|
||||||
|
|
||||||
-- Register for updates
|
-- Register for updates
|
||||||
button:RegisterEvent("BAG_UPDATE")
|
button:RegisterEvent("BAG_UPDATE")
|
||||||
button:RegisterEvent("ITEM_LOCK_CHANGED")
|
button:RegisterEvent("ITEM_LOCK_CHANGED")
|
||||||
@@ -1378,12 +1384,38 @@ function Guda_BagSlot_OnLoad(button, bagID)
|
|||||||
Guda_BagSlot_Update(button, bagID)
|
Guda_BagSlot_Update(button, bagID)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Guda_BagSlot_OnDragStart(frame, bagID)
|
||||||
|
if bagID == 0 then return end
|
||||||
|
|
||||||
|
-- Check if we should start dragging (only if there's an item)
|
||||||
|
local invSlot = ContainerIDToInventoryID(bagID)
|
||||||
|
local texture = GetInventoryItemTexture("player", invSlot)
|
||||||
|
|
||||||
|
if texture then
|
||||||
|
frame:SetAlpha(0.6)
|
||||||
|
-- Immediate pickup for Classic
|
||||||
|
PickupInventoryItem(invSlot)
|
||||||
|
end
|
||||||
|
-- If no texture (empty slot), do nothing - drag won't start
|
||||||
|
end
|
||||||
|
|
||||||
|
function Guda_BagSlot_OnDragStop(frame, bagID)
|
||||||
|
frame:SetAlpha(1.0)
|
||||||
|
end
|
||||||
|
|
||||||
-- Update bag slot button texture
|
-- Update bag slot button texture
|
||||||
function Guda_BagSlot_Update(button, bagID)
|
function Guda_BagSlot_Update(button, bagID)
|
||||||
|
local isHidden = hiddenBags[bagID]
|
||||||
|
|
||||||
if bagID == 0 then
|
if bagID == 0 then
|
||||||
-- Backpack always has the same texture
|
-- Backpack always has the same texture
|
||||||
SetItemButtonTexture(button, "Interface\\Buttons\\Button-Backpack-Up")
|
SetItemButtonTexture(button, "Interface\\Buttons\\Button-Backpack-Up")
|
||||||
SetItemButtonTextureVertexColor(button, 1.0, 1.0, 1.0)
|
-- Dim if hidden
|
||||||
|
if isHidden then
|
||||||
|
SetItemButtonTextureVertexColor(button, 0.4, 0.4, 0.4)
|
||||||
|
else
|
||||||
|
SetItemButtonTextureVertexColor(button, 1.0, 1.0, 1.0)
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1394,7 +1426,12 @@ function Guda_BagSlot_Update(button, bagID)
|
|||||||
if texture then
|
if texture then
|
||||||
-- Bag is equipped
|
-- Bag is equipped
|
||||||
SetItemButtonTexture(button, texture)
|
SetItemButtonTexture(button, texture)
|
||||||
SetItemButtonTextureVertexColor(button, 1.0, 1.0, 1.0)
|
-- Dim if hidden
|
||||||
|
if isHidden then
|
||||||
|
SetItemButtonTextureVertexColor(button, 0.4, 0.4, 0.4)
|
||||||
|
else
|
||||||
|
SetItemButtonTextureVertexColor(button, 1.0, 1.0, 1.0)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
-- No bag in this slot
|
-- No bag in this slot
|
||||||
SetItemButtonTexture(button, "Interface\\PaperDoll\\UI-PaperDoll-Slot-Bag")
|
SetItemButtonTexture(button, "Interface\\PaperDoll\\UI-PaperDoll-Slot-Bag")
|
||||||
@@ -1424,22 +1461,31 @@ end
|
|||||||
|
|
||||||
-- OnClick handler
|
-- OnClick handler
|
||||||
function Guda_BagSlot_OnClick(button, bagID)
|
function Guda_BagSlot_OnClick(button, bagID)
|
||||||
if bagID == 0 then
|
-- Shift-click: Pick up/equip bag (original behavior)
|
||||||
-- Clicking backpack - do nothing special (it's always there)
|
if IsShiftKeyDown() then
|
||||||
|
if bagID == 0 then
|
||||||
|
return -- Can't pick up backpack
|
||||||
|
end
|
||||||
|
|
||||||
|
local invSlot = ContainerIDToInventoryID(bagID)
|
||||||
|
if CursorHasItem() then
|
||||||
|
PickupInventoryItem(invSlot)
|
||||||
|
else
|
||||||
|
PickupInventoryItem(invSlot)
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get the inventory slot for this bag
|
-- Regular click: Toggle bag visibility
|
||||||
local invSlot = ContainerIDToInventoryID(bagID)
|
hiddenBags[bagID] = not hiddenBags[bagID]
|
||||||
|
|
||||||
-- Check if cursor has an item
|
-- Update bag slot visual (dim/undim)
|
||||||
if CursorHasItem() then
|
Guda_BagSlot_Update(button, bagID)
|
||||||
-- Try to place item in this bag slot
|
|
||||||
PickupInventoryItem(invSlot)
|
-- Refresh the bag display
|
||||||
else
|
BagFrame:Update()
|
||||||
-- Pick up the bag from this slot
|
|
||||||
PickupInventoryItem(invSlot)
|
addon:Debug(string.format("Bag %d visibility toggled: %s", bagID, hiddenBags[bagID] and "hidden" or "visible"))
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- OnEnter handler for tooltip
|
-- OnEnter handler for tooltip
|
||||||
|
|||||||
+32
-4
@@ -274,7 +274,7 @@
|
|||||||
|
|
||||||
<Frames>
|
<Frames>
|
||||||
<!-- Bag Slot 1 -->
|
<!-- Bag Slot 1 -->
|
||||||
<Button name="$parent_BagSlot1" inherits="ItemButtonTemplate">
|
<Button name="$parent_BagSlot1" inherits="ItemButtonTemplate" movable="true">
|
||||||
<Size>
|
<Size>
|
||||||
<AbsDimension x="24" y="24"/>
|
<AbsDimension x="24" y="24"/>
|
||||||
</Size>
|
</Size>
|
||||||
@@ -287,6 +287,7 @@
|
|||||||
</Anchors>
|
</Anchors>
|
||||||
<Scripts>
|
<Scripts>
|
||||||
<OnLoad>
|
<OnLoad>
|
||||||
|
this:RegisterForDrag("LeftButton")
|
||||||
Guda_BagSlot_OnLoad(this, 1)
|
Guda_BagSlot_OnLoad(this, 1)
|
||||||
</OnLoad>
|
</OnLoad>
|
||||||
<OnClick>
|
<OnClick>
|
||||||
@@ -296,6 +297,12 @@
|
|||||||
Guda_BagSlot_OnEnter(this, 1)
|
Guda_BagSlot_OnEnter(this, 1)
|
||||||
Guda_BagFrame_HighlightBagSlots(1)
|
Guda_BagFrame_HighlightBagSlots(1)
|
||||||
</OnEnter>
|
</OnEnter>
|
||||||
|
<OnDragStart>
|
||||||
|
Guda_BagSlot_OnDragStart(this, 1)
|
||||||
|
</OnDragStart>
|
||||||
|
<OnDragStop>
|
||||||
|
Guda_BagSlot_OnDragStop(this, 1)
|
||||||
|
</OnDragStop>
|
||||||
<OnLeave>
|
<OnLeave>
|
||||||
GameTooltip:Hide()
|
GameTooltip:Hide()
|
||||||
Guda_BagFrame_ClearHighlightedSlots()
|
Guda_BagFrame_ClearHighlightedSlots()
|
||||||
@@ -307,7 +314,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<!-- Bag Slot 2 -->
|
<!-- Bag Slot 2 -->
|
||||||
<Button name="$parent_BagSlot2" inherits="ItemButtonTemplate">
|
<Button name="$parent_BagSlot2" inherits="ItemButtonTemplate" movable="true">
|
||||||
<Size>
|
<Size>
|
||||||
<AbsDimension x="24" y="24"/>
|
<AbsDimension x="24" y="24"/>
|
||||||
</Size>
|
</Size>
|
||||||
@@ -320,6 +327,7 @@
|
|||||||
</Anchors>
|
</Anchors>
|
||||||
<Scripts>
|
<Scripts>
|
||||||
<OnLoad>
|
<OnLoad>
|
||||||
|
this:RegisterForDrag("LeftButton")
|
||||||
Guda_BagSlot_OnLoad(this, 2)
|
Guda_BagSlot_OnLoad(this, 2)
|
||||||
</OnLoad>
|
</OnLoad>
|
||||||
<OnClick>
|
<OnClick>
|
||||||
@@ -329,6 +337,12 @@
|
|||||||
Guda_BagSlot_OnEnter(this, 2)
|
Guda_BagSlot_OnEnter(this, 2)
|
||||||
Guda_BagFrame_HighlightBagSlots(2)
|
Guda_BagFrame_HighlightBagSlots(2)
|
||||||
</OnEnter>
|
</OnEnter>
|
||||||
|
<OnDragStart>
|
||||||
|
Guda_BagSlot_OnDragStart(this, 2)
|
||||||
|
</OnDragStart>
|
||||||
|
<OnDragStop>
|
||||||
|
Guda_BagSlot_OnDragStop(this, 2)
|
||||||
|
</OnDragStop>
|
||||||
<OnLeave>
|
<OnLeave>
|
||||||
GameTooltip:Hide()
|
GameTooltip:Hide()
|
||||||
Guda_BagFrame_ClearHighlightedSlots()
|
Guda_BagFrame_ClearHighlightedSlots()
|
||||||
@@ -340,7 +354,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<!-- Bag Slot 3 -->
|
<!-- Bag Slot 3 -->
|
||||||
<Button name="$parent_BagSlot3" inherits="ItemButtonTemplate">
|
<Button name="$parent_BagSlot3" inherits="ItemButtonTemplate" movable="true">
|
||||||
<Size>
|
<Size>
|
||||||
<AbsDimension x="24" y="24"/>
|
<AbsDimension x="24" y="24"/>
|
||||||
</Size>
|
</Size>
|
||||||
@@ -353,6 +367,7 @@
|
|||||||
</Anchors>
|
</Anchors>
|
||||||
<Scripts>
|
<Scripts>
|
||||||
<OnLoad>
|
<OnLoad>
|
||||||
|
this:RegisterForDrag("LeftButton")
|
||||||
Guda_BagSlot_OnLoad(this, 3)
|
Guda_BagSlot_OnLoad(this, 3)
|
||||||
</OnLoad>
|
</OnLoad>
|
||||||
<OnClick>
|
<OnClick>
|
||||||
@@ -362,6 +377,12 @@
|
|||||||
Guda_BagSlot_OnEnter(this, 3)
|
Guda_BagSlot_OnEnter(this, 3)
|
||||||
Guda_BagFrame_HighlightBagSlots(3)
|
Guda_BagFrame_HighlightBagSlots(3)
|
||||||
</OnEnter>
|
</OnEnter>
|
||||||
|
<OnDragStart>
|
||||||
|
Guda_BagSlot_OnDragStart(this, 3)
|
||||||
|
</OnDragStart>
|
||||||
|
<OnDragStop>
|
||||||
|
Guda_BagSlot_OnDragStop(this, 3)
|
||||||
|
</OnDragStop>
|
||||||
<OnLeave>
|
<OnLeave>
|
||||||
GameTooltip:Hide()
|
GameTooltip:Hide()
|
||||||
Guda_BagFrame_ClearHighlightedSlots()
|
Guda_BagFrame_ClearHighlightedSlots()
|
||||||
@@ -373,7 +394,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<!-- Bag Slot 4 -->
|
<!-- Bag Slot 4 -->
|
||||||
<Button name="$parent_BagSlot4" inherits="ItemButtonTemplate">
|
<Button name="$parent_BagSlot4" inherits="ItemButtonTemplate" movable="true">
|
||||||
<Size>
|
<Size>
|
||||||
<AbsDimension x="24" y="24"/>
|
<AbsDimension x="24" y="24"/>
|
||||||
</Size>
|
</Size>
|
||||||
@@ -386,6 +407,7 @@
|
|||||||
</Anchors>
|
</Anchors>
|
||||||
<Scripts>
|
<Scripts>
|
||||||
<OnLoad>
|
<OnLoad>
|
||||||
|
this:RegisterForDrag("LeftButton")
|
||||||
Guda_BagSlot_OnLoad(this, 4)
|
Guda_BagSlot_OnLoad(this, 4)
|
||||||
</OnLoad>
|
</OnLoad>
|
||||||
<OnClick>
|
<OnClick>
|
||||||
@@ -395,6 +417,12 @@
|
|||||||
Guda_BagSlot_OnEnter(this, 4)
|
Guda_BagSlot_OnEnter(this, 4)
|
||||||
Guda_BagFrame_HighlightBagSlots(4)
|
Guda_BagFrame_HighlightBagSlots(4)
|
||||||
</OnEnter>
|
</OnEnter>
|
||||||
|
<OnDragStart>
|
||||||
|
Guda_BagSlot_OnDragStart(this, 4)
|
||||||
|
</OnDragStart>
|
||||||
|
<OnDragStop>
|
||||||
|
Guda_BagSlot_OnDragStop(this, 4)
|
||||||
|
</OnDragStop>
|
||||||
<OnLeave>
|
<OnLeave>
|
||||||
GameTooltip:Hide()
|
GameTooltip:Hide()
|
||||||
Guda_BagFrame_ClearHighlightedSlots()
|
Guda_BagFrame_ClearHighlightedSlots()
|
||||||
|
|||||||
Reference in New Issue
Block a user