feat: open bank from bag slots

This commit is contained in:
Salikh Gurgenidze
2025-11-16 21:00:49 +04:00
parent 99f65a41d4
commit 20ea2d14c1
4 changed files with 311 additions and 62 deletions
+135
View File
@@ -789,6 +789,141 @@ local function HideCharacterDropdown()
end
end
-- Bank dropdown management
local bankDropdown = nil
-- Toggle bank dropdown
function Guda_BagFrame_ToggleBankDropdown(button)
if bankDropdown and bankDropdown:IsShown() then
bankDropdown:Hide()
return
end
if not bankDropdown then
-- Create dropdown frame
bankDropdown = CreateFrame("Frame", "Guda_BankDropdown", UIParent)
bankDropdown:SetFrameStrata("DIALOG")
bankDropdown:SetWidth(200)
bankDropdown:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true,
tileSize = 16,
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }
})
bankDropdown:SetBackdropColor(0, 0, 0, 0.95)
bankDropdown:EnableMouse(true)
bankDropdown:Hide()
bankDropdown.buttons = {}
end
-- Position dropdown below the button
bankDropdown:ClearAllPoints()
bankDropdown:SetPoint("TOPLEFT", button, "BOTTOMLEFT", 0, -2)
-- Clear existing buttons
for _, btn in ipairs(bankDropdown.buttons) do
btn:Hide()
end
bankDropdown.buttons = {}
-- Get all characters
local chars = addon.Modules.DB:GetAllCharacters(true)
local yOffset = -8
-- Add character buttons
for _, char in ipairs(chars) do
-- Capture variables in local scope for closure
local charFullName = char.fullName
local charName = char.name
local charMoney = char.money or 0
local charClassToken = char.classToken
local charButton = CreateFrame("Button", nil, bankDropdown)
charButton:SetWidth(188)
charButton:SetHeight(20)
charButton:SetPoint("TOP", bankDropdown, "TOP", 0, yOffset)
-- Button background on hover
local charBg = charButton:CreateTexture(nil, "BACKGROUND")
charBg:SetAllPoints()
charBg:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
charBg:SetBlendMode("ADD")
charBg:SetAlpha(0)
-- Get class color
local classColor = charClassToken and RAID_CLASS_COLORS[charClassToken]
local r, g, b = 1, 1, 1
if classColor then
r, g, b = classColor.r, classColor.g, classColor.b
end
-- Button text
local charText = charButton:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
charText:SetPoint("LEFT", charButton, "LEFT", 8, 0)
charText:SetText(charName)
charText:SetTextColor(r, g, b)
-- Money text
local moneyText = charButton:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
moneyText:SetPoint("RIGHT", charButton, "RIGHT", -8, 0)
moneyText:SetText(addon.Modules.Utils:FormatMoney(charMoney))
moneyText:SetTextColor(0.7, 0.7, 0.7)
-- Button scripts
charButton:SetScript("OnEnter", function()
charBg:SetAlpha(0.3)
end)
charButton:SetScript("OnLeave", function()
charBg:SetAlpha(0)
end)
charButton:SetScript("OnClick", function()
if charFullName then
-- Show bank for this character
Guda_BagFrame_ShowCharacterBank(charFullName, charName)
bankDropdown:Hide()
else
addon:Print("Error: Character fullName is nil")
end
end)
table.insert(bankDropdown.buttons, charButton)
yOffset = yOffset - 20
end
-- Set dropdown height based on content
bankDropdown:SetHeight(math.abs(yOffset) + 8)
-- Show dropdown
bankDropdown:Show()
end
-- Show character's bank
function Guda_BagFrame_ShowCharacterBank(fullName, displayName)
-- Use the existing BankFrame module
if not addon.Modules.BankFrame then
addon:Print("Bank frame module not available")
return
end
-- Position bank frame at center of screen
if Guda_BankFrame then
Guda_BankFrame:ClearAllPoints()
Guda_BankFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
end
-- Show the character's bank
addon.Modules.BankFrame:ShowCharacter(fullName)
-- Make sure frame is shown
if Guda_BankFrame then
Guda_BankFrame:Show()
end
end
-- Search changed handler
function Guda_BagFrame_OnSearchChanged(self)
local text = self:GetText()
+2 -2
View File
@@ -232,12 +232,12 @@
<OnLoad>
local icon = getglobal(this:GetName().."_Icon")
if icon then
icon:SetTexture("Interface\\Icons\\INV_Misc_Bag_09")
icon:SetTexture("Interface\\Icons\\INV_Misc_Bag_08")
icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
end
</OnLoad>
<OnClick>
Guda_BankFrame:Toggle()
Guda_BagFrame_ToggleBankDropdown(this)
</OnClick>
<OnEnter>
GameTooltip:SetOwner(this, "ANCHOR_TOP")
+63 -19
View File
@@ -11,8 +11,13 @@ local searchText = ""
-- OnLoad
function Guda_BankFrame_OnLoad(self)
getglobal(self:GetName().."_Title"):SetText("Guda Bank")
getglobal(self:GetName().."_SearchBox"):SetText("Search...")
-- Set up search box placeholder
local searchBox = getglobal(self:GetName().."_SearchBar_SearchBox")
if searchBox then
searchBox:SetText("Search bank...")
searchBox:SetTextColor(0.5, 0.5, 0.5, 1)
end
addon:Debug("Bank frame loaded")
end
@@ -23,7 +28,18 @@ end
-- OnHide
function Guda_BankFrame_OnHide(self)
Guda_ReleaseAllButtons()
-- Only release buttons that belong to this frame
local itemContainer = getglobal("Guda_BankFrame_ItemContainer")
if itemContainer then
-- Hide only the buttons that are children of this container
local children = { itemContainer:GetChildren() }
for _, child in ipairs(children) do
if child.hasItem ~= nil then -- It's an item button
child:Hide()
child:ClearAllPoints()
end
end
end
end
-- Toggle visibility
@@ -53,7 +69,17 @@ function BankFrame:Update()
return
end
Guda_ReleaseAllButtons()
-- Only release buttons that belong to this frame
local itemContainer = getglobal("Guda_BankFrame_ItemContainer")
if itemContainer then
local children = { itemContainer:GetChildren() }
for _, child in ipairs(children) do
if child.hasItem ~= nil then -- It's an item button
child:Hide()
child:ClearAllPoints()
end
end
end
local bankData
local isOtherChar = false
@@ -85,30 +111,48 @@ function BankFrame:DisplayItems(bankData, isOtherChar, charName)
local col = 0
local buttonSize = addon.Modules.DB:GetSetting("iconSize") or addon.Constants.BUTTON_SIZE
local spacing = addon.Modules.DB:GetSetting("iconSpacing") or addon.Constants.BUTTON_SPACING
local perRow = addon.Modules.DB:GetSetting("bankColumns") or 15
local perRow = addon.Modules.DB:GetSetting("bankColumns") or 10
local itemContainer = getglobal("Guda_BankFrame_ItemContainer")
for _, bagID in ipairs(addon.Constants.BANK_BAGS) do
local bag = bankData[bagID]
if bag and bag.slots then
for slot, itemData in pairs(bag.slots) do
if self:PassesSearchFilter(itemData) then
local button = Guda_GetItemButton(itemContainer)
-- Get slot count for this bag
local numSlots
if isOtherChar and bag and bag.numSlots then
-- Use stored slot count for other characters
numSlots = bag.numSlots
else
-- Use current character's bag slot count
numSlots = addon.Modules.Utils:GetBagSlotCount(bagID)
end
local xPos = x + (col * (buttonSize + spacing))
local yPos = y - (row * (buttonSize + spacing))
-- Only show bags that have slots
if numSlots and numSlots > 0 then
-- Iterate through ALL slots (1 to numSlots) to show empty slots too
for slot = 1, numSlots do
local itemData = bag and bag.slots and bag.slots[slot] or nil
button:ClearAllPoints()
button:SetPoint("TOPLEFT", itemContainer, "TOPLEFT", xPos, yPos)
-- Check if item matches search filter
local matchesFilter = self:PassesSearchFilter(itemData)
Guda_ItemButton_SetItem(button, bagID, slot, itemData, true, isOtherChar and charName or nil)
local button = Guda_GetItemButton(itemContainer)
col = col + 1
if col >= perRow then
col = 0
row = row + 1
end
-- Position button
local xPos = x + (col * (buttonSize + spacing))
local yPos = y - (row * (buttonSize + spacing))
button:ClearAllPoints()
button:SetPoint("TOPLEFT", itemContainer, "TOPLEFT", xPos, yPos)
-- Set item data with filter match info
Guda_ItemButton_SetItem(button, bagID, slot, itemData, true, isOtherChar and charName or nil, matchesFilter)
-- Advance position
col = col + 1
if col >= perRow then
col = 0
row = row + 1
end
end
end
+111 -41
View File
@@ -3,37 +3,38 @@
<!-- Bank Frame -->
<Frame name="Guda_BankFrame" toplevel="true" movable="true" enableMouse="true" hidden="true" parent="UIParent">
<Size>
<AbsDimension x="400" y="500"/>
<AbsDimension x="420" y="600"/>
</Size>
<Anchors>
<Anchor point="LEFT" relativePoint="LEFT" relativeTo="UIParent">
<Anchor point="CENTER" relativePoint="CENTER" relativeTo="UIParent">
<Offset>
<AbsDimension x="50" y="0"/>
<AbsDimension x="0" y="0"/>
</Offset>
</Anchor>
</Anchors>
<Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
<Backdrop bgFile="Interface\Tooltips\UI-Tooltip-Background" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
<BackgroundInsets>
<AbsInset left="11" right="12" top="12" bottom="11"/>
</BackgroundInsets>
<TileSize>
<AbsValue val="32"/>
<AbsValue val="16"/>
</TileSize>
<EdgeSize>
<AbsValue val="32"/>
</EdgeSize>
<Color r="0" g="0" b="0" a="0.9"/>
</Backdrop>
<Layers>
<!-- Title -->
<!-- Title at top -->
<Layer level="ARTWORK">
<FontString name="$parent_Title" inherits="GameFontNormalLarge">
<Anchors>
<Anchor point="TOP">
<Offset>
<AbsDimension x="0" y="-18"/>
<AbsDimension x="0" y="-12"/>
</Offset>
</Anchor>
</Anchors>
@@ -58,21 +59,44 @@
</Scripts>
</Button>
<!-- Settings Button -->
<!-- Settings Button (header right, next to close) -->
<Button name="$parent_SettingsButton">
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="TOPRIGHT" relativePoint="TOPLEFT" relativeTo="$parent_CloseButton" x="-5" y="0"/>
<Anchor point="TOPRIGHT" relativePoint="TOPLEFT" relativeTo="$parent_CloseButton">
<Offset>
<AbsDimension x="0" y="-5"/>
</Offset>
</Anchor>
</Anchors>
<NormalTexture file="Interface\Icons\Trade_Engineering"/>
<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\\Trade_Engineering")
icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
end
</OnLoad>
<OnClick>
Guda_OpenSettings()
</OnClick>
<OnEnter>
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
GameTooltip:SetOwner(this, "ANCHOR_TOP")
GameTooltip:SetText("Settings")
GameTooltip:Show()
</OnEnter>
@@ -82,51 +106,91 @@
</Scripts>
</Button>
<!-- Search Box -->
<EditBox name="$parent_SearchBox" autoFocus="false" inherits="InputBoxTemplate">
<!-- Search Bar (below title) -->
<Frame name="$parent_SearchBar">
<Size>
<AbsDimension x="200" y="20"/>
<AbsDimension x="400" y="30"/>
</Size>
<Anchors>
<Anchor point="TOP">
<Offset>
<AbsDimension x="0" y="-48"/>
<AbsDimension x="0" y="-40"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnTextChanged>
Guda_BankFrame_OnSearchChanged(this)
</OnTextChanged>
<OnEscapePressed>
this:ClearFocus()
</OnEscapePressed>
</Scripts>
</EditBox>
<!-- Sort Button -->
<Button name="$parent_SortButton" inherits="UIPanelButtonTemplate" text="Sort Bank">
<Size>
<AbsDimension x="100" y="22"/>
</Size>
<Anchors>
<Anchor point="BOTTOM" x="0" y="10"/>
</Anchors>
<Scripts>
<OnClick>
Guda_BankFrame_Sort()
</OnClick>
</Scripts>
</Button>
<Frames>
<!-- Full-width Search Box -->
<EditBox name="$parent_SearchBox" autoFocus="false" inherits="InputBoxTemplate">
<Size>
<AbsDimension x="0" y="20"/>
</Size>
<Anchors>
<Anchor point="LEFT">
<Offset>
<AbsDimension x="16" y="0"/>
</Offset>
</Anchor>
<Anchor point="RIGHT">
<Offset>
<AbsDimension x="-10" y="0"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnEditFocusGained>
if this:GetText() == "Search bank..." then
this:SetText("")
this:SetTextColor(1, 1, 1, 1)
end
</OnEditFocusGained>
<OnEditFocusLost>
if this:GetText() == "" then
this:SetText("Search bank...")
this:SetTextColor(0.5, 0.5, 0.5, 1)
Guda_BankFrame_OnSearchChanged(this)
end
</OnEditFocusLost>
<OnTextChanged>
Guda_BankFrame_OnSearchChanged(this)
</OnTextChanged>
<OnEscapePressed>
this:SetText("Search bank...")
this:SetTextColor(0.5, 0.5, 0.5, 1)
this:ClearFocus()
Guda_BankFrame_OnSearchChanged(this)
</OnEscapePressed>
</Scripts>
</EditBox>
</Frames>
</Frame>
<!-- Container for item buttons -->
<Frame name="$parent_ItemContainer">
<Frame name="$parent_ItemContainer" enableMouse="true">
<Size>
<AbsDimension x="370" y="420"/>
<AbsDimension x="400" y="480"/>
</Size>
<Anchors>
<Anchor point="TOP" x="0" y="-75"/>
<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="$parent_SearchBar" x="0" y="-5"/>
</Anchors>
<Backdrop bgFile="Interface\Tooltips\UI-Tooltip-Background" tile="true">
<BackgroundInsets>
<AbsInset left="0" right="0" top="0" bottom="0"/>
</BackgroundInsets>
<TileSize>
<AbsValue val="16"/>
</TileSize>
<Color r="0" g="0" b="0" a="0.5"/>
</Backdrop>
<Scripts>
<OnMouseDown>
-- Clear search focus when clicking in item area
local searchBox = getglobal("Guda_BankFrame_SearchBar_SearchBox")
if searchBox then
searchBox:ClearFocus()
end
</OnMouseDown>
</Scripts>
</Frame>
</Frames>
@@ -141,6 +205,12 @@
Guda_BankFrame_OnHide(this)
</OnHide>
<OnMouseDown>
-- Clear search box focus when clicking on bank frame
local searchBox = getglobal("Guda_BankFrame_SearchBar_SearchBox")
if searchBox then
searchBox:ClearFocus()
end
if (arg1 == "LeftButton") then
this:StartMoving()
end