feat: info free slots/total slots

This commit is contained in:
Salikh Gurgenidze
2025-11-16 20:29:05 +04:00
parent 58d4d005e4
commit 99f65a41d4
5 changed files with 201 additions and 5 deletions
+9 -1
View File
@@ -128,6 +128,14 @@ function Utils:GetBagSlotCount(bagID)
if bagID == -1 then
-- Bank has 24 slots in vanilla
return 24
elseif bagID == -2 then
-- Keyring - vanilla WoW has 12-32 slots depending on version
local slots = GetContainerNumSlots(bagID)
if not slots or slots == 0 then
-- Fallback: keyring typically has 12 slots in vanilla
return 12
end
return slots
else
return GetContainerNumSlots(bagID) or 0
end
@@ -135,7 +143,7 @@ end
-- Check if bag is valid
function Utils:IsBagValid(bagID)
if bagID == 0 or bagID == -1 then
if bagID == 0 or bagID == -1 or bagID == -2 then
return true
end
return GetContainerNumSlots(bagID) and GetContainerNumSlots(bagID) > 0
+4
View File
@@ -10,10 +10,14 @@ addon.Modules.BagScanner = BagScanner
function BagScanner:ScanBags()
local bagData = {}
-- Scan regular bags
for _, bagID in ipairs(addon.Constants.BAGS) do
bagData[bagID] = self:ScanBag(bagID)
end
-- Also scan keyring (bagID -2)
bagData[-2] = self:ScanBag(-2)
return bagData
end
+91
View File
@@ -9,6 +9,7 @@ addon.Modules.BagFrame = BagFrame
local currentViewChar = nil -- nil = current character
local searchText = ""
local itemButtons = {}
local showKeyring = false -- Toggle for keyring display
-- Global click catcher for clearing search focus
local clickCatcher = nil
@@ -153,6 +154,9 @@ function BagFrame:Update()
-- Update money
self:UpdateMoney()
-- Update bag slots info
self:UpdateBagSlotsInfo(bagData, isOtherChar)
end
-- Display items
@@ -165,9 +169,32 @@ function BagFrame:DisplayItems(bagData, isOtherChar, charName)
local perRow = addon.Modules.DB:GetSetting("bagColumns") or 10
local itemContainer = getglobal("Guda_BagFrame_ItemContainer")
-- Build bag list - include keyring if toggled on
local bagsToShow = {}
for _, bagID in ipairs(addon.Constants.BAGS) do
table.insert(bagsToShow, bagID)
end
-- Add keyring (-2) at the end if toggled on
if showKeyring then
table.insert(bagsToShow, -2) -- Insert at end
end
for _, bagID in ipairs(bagsToShow) do
local bag = bagData[bagID]
-- Add spacing before keyring section
if bagID == -2 then
-- Add spacing before keyring
if col > 0 then
-- Move to next row if not at start of row
col = 0
row = row + 1
end
-- Add extra spacing (1 row)
row = row + 1
end
-- Get slot count for this bag
local numSlots
if isOtherChar and bag and bag.numSlots then
@@ -380,6 +407,47 @@ function BagFrame:UpdateMoney()
end
end
-- Update bag slots info text (excluding keyring)
function BagFrame:UpdateBagSlotsInfo(bagData, isOtherChar)
local infoText = getglobal("Guda_BagFrame_Toolbar_BagSlotsInfo_Text")
if not infoText then return end
local totalSlots = 0
local usedSlots = 0
-- Count slots in regular bags only (0-4), exclude keyring (-2)
for _, bagID in ipairs(addon.Constants.BAGS) do
local bag = bagData[bagID]
-- Get slot count for this bag
local numSlots
if isOtherChar and bag and bag.numSlots then
numSlots = bag.numSlots
else
numSlots = addon.Modules.Utils:GetBagSlotCount(bagID)
end
if numSlots and numSlots > 0 then
totalSlots = totalSlots + numSlots
-- Count used slots
if bag and bag.slots then
for slot = 1, numSlots do
if bag.slots[slot] then
usedSlots = usedSlots + 1
end
end
end
end
end
local freeSlots = totalSlots - usedSlots
-- Format: "56 / 80" (free / total)
infoText:SetText(string.format("%d / %d", freeSlots, totalSlots))
infoText:SetTextColor(0.7, 0.7, 0.7)
end
function BagFrame:CreateMoneyFrame()
local moneyFrame = CreateFrame("Frame", "Guda_BagFrame_MoneyFrame", Guda_BagFrame, "SmallMoneyFrameTemplate")
moneyFrame:SetPoint("BOTTOMRIGHT", Guda_BagFrame, "BOTTOMRIGHT", -15, 10)
@@ -738,6 +806,29 @@ function Guda_BagFrame_OnSearchChanged(self)
end
end
-- Keyring toggle handler
function Guda_BagFrame_ToggleKeyring()
showKeyring = not showKeyring
-- Update button appearance to show toggle state
local button = getglobal("Guda_BagFrame_Toolbar_KeyringButton")
if button then
local icon = getglobal(button:GetName().."_Icon")
if icon then
if showKeyring then
-- Highlighted when active
icon:SetVertexColor(1.0, 1.0, 0.5)
else
-- Normal color when inactive
icon:SetVertexColor(0.8, 0.8, 0.8)
end
end
end
-- Refresh display
BagFrame:Update()
end
-- Sort button handler
function Guda_BagFrame_Sort()
if currentViewChar then
+82 -1
View File
@@ -273,7 +273,88 @@
</Scripts>
<Frames>
<!-- All buttons moved to header -->
<!-- Keyring Button (footer left) -->
<Button name="$parent_KeyringButton">
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="LEFT">
<Offset>
<AbsDimension x="13" y="3"/>
</Offset>
</Anchor>
</Anchors>
<Layers>
<Layer level="ARTWORK">
<Texture name="$parent_Icon">
<Size>
<AbsDimension x="20" y="20"/>
</Size>
<Anchors>
<Anchor point="CENTER"/>
</Anchors>
<Color r="0.8" g="0.8" b="0.8"/>
</Texture>
</Layer>
</Layers>
<Scripts>
<OnLoad>
local icon = getglobal(this:GetName().."_Icon")
if icon then
icon:SetTexture("Interface\\Icons\\INV_Misc_Key_03")
icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
end
</OnLoad>
<OnClick>
Guda_BagFrame_ToggleKeyring()
</OnClick>
<OnEnter>
GameTooltip:SetOwner(this, "ANCHOR_TOP")
GameTooltip:SetText("Toggle Keyring")
GameTooltip:Show()
</OnEnter>
<OnLeave>
GameTooltip:Hide()
</OnLeave>
</Scripts>
</Button>
<!-- Bag Slots Info Text -->
<Frame name="$parent_BagSlotsInfo">
<Size>
<AbsDimension x="100" y="24"/>
</Size>
<Anchors>
<Anchor point="LEFT" relativePoint="RIGHT" relativeTo="$parent_KeyringButton">
<Offset>
<AbsDimension x="8" y="0"/>
</Offset>
</Anchor>
</Anchors>
<Layers>
<Layer level="OVERLAY">
<FontString name="$parent_Text" inherits="GameFontNormal">
<Anchors>
<Anchor point="LEFT">
<Offset>
<AbsDimension x="0" y="0"/>
</Offset>
</Anchor>
</Anchors>
</FontString>
</Layer>
</Layers>
<Scripts>
<OnLoad>
local text = getglobal(this:GetName().."_Text")
if text then
text:SetText("0 / 0")
text:SetTextColor(0.8, 0.8, 0.8)
end
</OnLoad>
</Scripts>
</Frame>
</Frames>
</Frame>
+15 -3
View File
@@ -164,8 +164,12 @@ function Guda_ItemButton_SetItem(self, bagID, slotID, itemData, isBank, otherCha
countText:Hide()
end
-- Set quality border
if itemData.quality and itemData.quality > 1 then
-- Set quality border (or keyring border)
if bagID == -2 then
-- Special border for keyring items (cyan/blue)
qualityBorder:SetVertexColor(0.2, 0.8, 1.0, 1)
qualityBorder:Show()
elseif itemData.quality and itemData.quality > 1 then
local r, g, b = addon.Modules.Utils:GetQualityColor(itemData.quality)
qualityBorder:SetVertexColor(r, g, b, 1)
qualityBorder:Show()
@@ -202,7 +206,15 @@ function Guda_ItemButton_SetItem(self, bagID, slotID, itemData, isBank, otherCha
end
countText:Hide()
qualityBorder:Hide()
-- Show border for empty keyring slots
if bagID == -2 then
qualityBorder:SetVertexColor(0.2, 0.8, 1.0, 0.5) -- Dimmer cyan for empty slots
qualityBorder:Show()
else
qualityBorder:Hide()
end
self:Show()
end