feat: actual bag slots

This commit is contained in:
Salikh Gurgenidze
2025-11-17 13:49:29 +04:00
parent 75193d8c99
commit 1d65662327
3 changed files with 258 additions and 5 deletions
+10
View File
@@ -0,0 +1,10 @@
{
"permissions": {
"allow": [
"Bash(tree:*)",
"Bash(mkdir:*)"
],
"deny": [],
"ask": []
}
}
+120 -1
View File
@@ -1334,11 +1334,130 @@ local function DelayedHook()
end)
end
-- Bag Slot Button Handlers
-- OnLoad handler for bag slot buttons
function Guda_BagSlot_OnLoad(button, bagID)
-- Set up the button with proper ID
-- For bags 1-4, we need to get the inventory slot ID
if bagID == 0 then
-- Backpack (bag 0) - set a special texture
button.bagID = 0
button.hasItem = 1
SetItemButtonTexture(button, "Interface\\Buttons\\Button-Backpack-Up")
else
-- Bags 1-4: Get inventory slot ID (19, 20, 21, 22)
local invSlot = ContainerIDToInventoryID(bagID)
button:SetID(invSlot)
button.bagID = bagID
-- Register for updates
button:RegisterEvent("BAG_UPDATE")
button:RegisterEvent("ITEM_LOCK_CHANGED")
button:RegisterEvent("CURSOR_UPDATE")
button:RegisterEvent("UNIT_INVENTORY_CHANGED")
end
-- Initial update
Guda_BagSlot_Update(button, bagID)
end
-- Update bag slot button texture
function Guda_BagSlot_Update(button, bagID)
if bagID == 0 then
-- Backpack always has the same texture
SetItemButtonTexture(button, "Interface\\Buttons\\Button-Backpack-Up")
SetItemButtonTextureVertexColor(button, 1.0, 1.0, 1.0)
return
end
-- Get the inventory slot ID for this bag
local invSlot = ContainerIDToInventoryID(bagID)
local texture = GetInventoryItemTexture("player", invSlot)
if texture then
-- Bag is equipped
SetItemButtonTexture(button, texture)
SetItemButtonTextureVertexColor(button, 1.0, 1.0, 1.0)
else
-- No bag in this slot
SetItemButtonTexture(button, "Interface\\PaperDoll\\UI-PaperDoll-Slot-Bag")
SetItemButtonTextureVertexColor(button, 0.5, 0.5, 0.5)
end
end
-- OnEvent handler
function Guda_BagSlot_OnEvent(button, event, arg1)
local bagID = button.bagID
if not bagID then
return
end
if event == "BAG_UPDATE" then
if arg1 == bagID then
Guda_BagSlot_Update(button, bagID)
end
elseif event == "UNIT_INVENTORY_CHANGED" then
if arg1 == "player" then
Guda_BagSlot_Update(button, bagID)
end
elseif event == "ITEM_LOCK_CHANGED" or event == "CURSOR_UPDATE" then
Guda_BagSlot_Update(button, bagID)
end
end
-- OnClick handler
function Guda_BagSlot_OnClick(button, bagID)
if bagID == 0 then
-- Clicking backpack - do nothing special (it's always there)
return
end
-- Get the inventory slot for this bag
local invSlot = ContainerIDToInventoryID(bagID)
-- Check if cursor has an item
if CursorHasItem() then
-- Try to place item in this bag slot
PickupInventoryItem(invSlot)
else
-- Pick up the bag from this slot
PickupInventoryItem(invSlot)
end
end
-- OnEnter handler for tooltip
function Guda_BagSlot_OnEnter(button, bagID)
GameTooltip:SetOwner(button, "ANCHOR_TOP")
if bagID == 0 then
-- Backpack tooltip
GameTooltip:SetText("Backpack", 1.0, 1.0, 1.0)
local numSlots = GetContainerNumSlots(0)
GameTooltip:AddLine(string.format("%d Slots", numSlots), 0.8, 0.8, 0.8)
else
-- Bag slot tooltip
local invSlot = ContainerIDToInventoryID(bagID)
local hasItem = GetInventoryItemTexture("player", invSlot)
if hasItem then
-- Show bag item tooltip
GameTooltip:SetInventoryItem("player", invSlot)
else
-- Empty slot
GameTooltip:SetText(string.format("Bag %d", bagID), 1.0, 1.0, 1.0)
GameTooltip:AddLine("Empty", 0.5, 0.5, 0.5)
end
end
GameTooltip:Show()
end
-- Initialize
function BagFrame:Initialize()
-- Hook default bag functions
HookDefaultBags()
-- Delayed hook for bag containers (runs after UI loads)
DelayedHook()
+128 -4
View File
@@ -250,7 +250,7 @@
</Scripts>
</Button>
<!-- Toolbar Container (for money tooltip, kept for compatibility) -->
<!-- Toolbar Container (for money tooltip and bag slots) -->
<Frame name="$parent_Toolbar" enableMouse="true">
<Size>
<AbsDimension x="200" y="30"/>
@@ -273,15 +273,139 @@
</Scripts>
<Frames>
<!-- Keyring Button (footer left) -->
<Button name="$parent_KeyringButton">
<!-- Bag Slot 1 -->
<Button name="$parent_BagSlot1" inherits="ItemButtonTemplate">
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="LEFT">
<Offset>
<AbsDimension x="13" y="3"/>
<AbsDimension x="15" y="0"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnLoad>
Guda_BagSlot_OnLoad(this, 1)
</OnLoad>
<OnClick>
Guda_BagSlot_OnClick(this, 1)
</OnClick>
<OnEnter>
Guda_BagSlot_OnEnter(this, 1)
</OnEnter>
<OnLeave>
GameTooltip:Hide()
</OnLeave>
<OnEvent>
Guda_BagSlot_OnEvent(this, event, arg1)
</OnEvent>
</Scripts>
</Button>
<!-- Bag Slot 2 -->
<Button name="$parent_BagSlot2" inherits="ItemButtonTemplate">
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="LEFT" relativePoint="RIGHT" relativeTo="$parent_BagSlot1">
<Offset>
<AbsDimension x="2" y="0"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnLoad>
Guda_BagSlot_OnLoad(this, 2)
</OnLoad>
<OnClick>
Guda_BagSlot_OnClick(this, 2)
</OnClick>
<OnEnter>
Guda_BagSlot_OnEnter(this, 2)
</OnEnter>
<OnLeave>
GameTooltip:Hide()
</OnLeave>
<OnEvent>
Guda_BagSlot_OnEvent(this, event, arg1)
</OnEvent>
</Scripts>
</Button>
<!-- Bag Slot 3 -->
<Button name="$parent_BagSlot3" inherits="ItemButtonTemplate">
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="LEFT" relativePoint="RIGHT" relativeTo="$parent_BagSlot2">
<Offset>
<AbsDimension x="2" y="0"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnLoad>
Guda_BagSlot_OnLoad(this, 3)
</OnLoad>
<OnClick>
Guda_BagSlot_OnClick(this, 3)
</OnClick>
<OnEnter>
Guda_BagSlot_OnEnter(this, 3)
</OnEnter>
<OnLeave>
GameTooltip:Hide()
</OnLeave>
<OnEvent>
Guda_BagSlot_OnEvent(this, event, arg1)
</OnEvent>
</Scripts>
</Button>
<!-- Bag Slot 4 -->
<Button name="$parent_BagSlot4" inherits="ItemButtonTemplate">
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="LEFT" relativePoint="RIGHT" relativeTo="$parent_BagSlot3">
<Offset>
<AbsDimension x="2" y="0"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnLoad>
Guda_BagSlot_OnLoad(this, 4)
</OnLoad>
<OnClick>
Guda_BagSlot_OnClick(this, 4)
</OnClick>
<OnEnter>
Guda_BagSlot_OnEnter(this, 4)
</OnEnter>
<OnLeave>
GameTooltip:Hide()
</OnLeave>
<OnEvent>
Guda_BagSlot_OnEvent(this, event, arg1)
</OnEvent>
</Scripts>
</Button>
<!-- Keyring Button -->
<Button name="$parent_KeyringButton">
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="LEFT" relativePoint="RIGHT" relativeTo="$parent_BagSlot4">
<Offset>
<AbsDimension x="6" y="0"/>
</Offset>
</Anchor>
</Anchors>