fix: dropdown

This commit is contained in:
Salikh Gurgenidze
2025-12-27 23:29:44 +04:00
parent e6953aafc5
commit bf4ea760b2
5 changed files with 87 additions and 201 deletions
+61 -196
View File
@@ -112,6 +112,9 @@ end
-- OnHide
function Guda_BagFrame_OnHide(self)
-- Close any open dropdown menus when the bag frame is hidden
CloseDropDownMenus()
-- Clean up all buttons when frame is hidden (safe since we're not displaying)
for _, bagParent in pairs(bagParents) do
if bagParent then
@@ -1452,71 +1455,58 @@ function Guda_BagFrame_ToggleCharacterDropdown(button)
ToggleDropDownMenu(1, nil, menuFrame, "cursor", 0, 0)
end
-- Hide dropdown when clicking elsewhere
local function HideCharacterDropdown()
-- Handled by UIDropDownMenu system
-- Mailbox character dropdown
local function Guda_BagMailboxMenu_Initialize()
local characters = addon.Modules.DB:GetAllCharacters(false, true)
local info
for i, char in ipairs(characters) do
local charFullName = char.fullName
local charClassToken = char.classToken
-- 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
-- Create colored name
local coloredName = addon.Modules.Utils:ColorText(char.name, r, g, b)
info = {}
info.text = coloredName
info.func = function()
addon.Modules.MailboxFrame:ShowCharacter(charFullName)
if not Guda_MailboxFrame:IsShown() then
Guda_MailboxFrame:Show()
end
end
local mailboxViewChar = addon.Modules.MailboxFrame:GetCurrentViewChar()
info.checked = (mailboxViewChar == charFullName or (not mailboxViewChar and charFullName == addon.Modules.DB:GetPlayerFullName()))
UIDropDownMenu_AddButton(info)
end
end
-- Toggle mail dropdown
function Guda_BagFrame_ToggleMailDropdown(button)
if mailDropdown and mailDropdown:IsShown() then
mailDropdown:Hide()
return
local menuFrame = getglobal("Guda_BagMailboxMenu")
if not menuFrame then
menuFrame = CreateFrame("Frame", "Guda_BagMailboxMenu", UIParent, "UIDropDownMenuTemplate")
end
UIDropDownMenu_Initialize(menuFrame, Guda_BagMailboxMenu_Initialize, "MENU")
ToggleDropDownMenu(1, nil, menuFrame, "cursor", 0, 0)
end
if not mailDropdown then
-- Create dropdown frame
mailDropdown = CreateFrame("Frame", "Guda_MailDropdown", UIParent)
mailDropdown:SetFrameStrata("DIALOG")
mailDropdown:SetWidth(200)
mailDropdown: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 }
})
mailDropdown:SetBackdropColor(0, 0, 0, 0.95)
mailDropdown:EnableMouse(true)
mailDropdown:Hide()
-- Bank character dropdown
local function Guda_BagBankMenu_Initialize()
local characters = addon.Modules.DB:GetAllCharacters(false, true)
local info
mailDropdown.buttons = {}
end
-- Position dropdown below the button
mailDropdown:ClearAllPoints()
mailDropdown:SetPoint("TOPLEFT", button, "BOTTOMLEFT", 0, -2)
-- Clear existing buttons
for _, btn in ipairs(mailDropdown.buttons) do
btn:Hide()
end
mailDropdown.buttons = {}
-- Get all characters on current realm
local chars = addon.Modules.DB:GetAllCharacters(false, true)
local yOffset = -8
-- Add character buttons
for _, char in ipairs(chars) do
-- Capture variables in local scope for closure
for i, char in ipairs(characters) do
local charFullName = char.fullName
local charName = char.name
local charClassToken = char.classToken
local charButton = CreateFrame("Button", nil, mailDropdown)
charButton:SetWidth(188)
charButton:SetHeight(20)
charButton:SetPoint("TOP", mailDropdown, "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
@@ -1524,154 +1514,29 @@ function Guda_BagFrame_ToggleMailDropdown(button)
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)
-- Create colored name
local charName = char.name
local coloredName = addon.Modules.Utils:ColorText(charName, r, g, b)
-- 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 mailbox for this character
addon.Modules.MailboxFrame:ShowCharacter(charFullName)
if not Guda_MailboxFrame:IsShown() then
Guda_MailboxFrame:Show()
end
mailDropdown:Hide()
else
addon:Print("Error: Character fullName is nil")
end
end)
table.insert(mailDropdown.buttons, charButton)
yOffset = yOffset - 20
info = {}
info.text = coloredName
info.func = function()
Guda_BagFrame_ShowCharacterBank(charFullName, charName)
end
local bankViewChar = addon.Modules.BankFrame:GetCurrentViewChar()
info.checked = (bankViewChar == charFullName or (not bankViewChar and charFullName == addon.Modules.DB:GetPlayerFullName()))
UIDropDownMenu_AddButton(info)
end
-- Set dropdown height based on content
mailDropdown:SetHeight(math.abs(yOffset) + 8)
-- Show dropdown
mailDropdown:Show()
end
-- Toggle bank dropdown
function Guda_BagFrame_ToggleBankDropdown(button)
-- Hide character dropdown if it's shown
if characterDropdown and characterDropdown:IsShown() then
characterDropdown:Hide()
local menuFrame = getglobal("Guda_BagBankMenu")
if not menuFrame then
menuFrame = CreateFrame("Frame", "Guda_BagBankMenu", UIParent, "UIDropDownMenuTemplate")
end
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 on current realm
local chars = addon.Modules.DB:GetAllCharacters(false, 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()
UIDropDownMenu_Initialize(menuFrame, Guda_BagBankMenu_Initialize, "MENU")
ToggleDropDownMenu(1, nil, menuFrame, "cursor", 0, 0)
end
-- Show character's bank
+12
View File
@@ -81,6 +81,18 @@ function Guda_BankFrame_OnShow(self)
BankFrame:Update()
end
-- OnHide
function Guda_BankFrame_OnHide(self)
-- Close any open dropdown menus when the bank frame is hidden
CloseDropDownMenus()
-- Close the actual Blizzard bank too
local blizzardBankFrame = getglobal("BankFrame")
if blizzardBankFrame and blizzardBankFrame:IsShown() then
CloseBankFrame()
end
end
-- Toggle visibility
function BankFrame:Toggle()
if Guda_BankFrame:IsShown() then
+1 -5
View File
@@ -648,11 +648,7 @@
Guda_BankFrame_OnShow(this)
</OnShow>
<OnHide>
Guda_BankFrame:Hide()
-- Close the actual Blizzard bank too
if BankFrame and BankFrame:IsShown() then
CloseBankFrame()
end
Guda_BankFrame_OnHide(this)
</OnHide>
<OnMouseDown>
-- Clear search box focus when clicking on bank frame
+10
View File
@@ -61,6 +61,12 @@ function Guda_MailboxFrame_OnShow(self)
MailboxFrame:Update()
end
-- OnHide
function Guda_MailboxFrame_OnHide(self)
-- Close any open dropdown menus when the mailbox frame is hidden
CloseDropDownMenus()
end
-- Toggle visibility
function MailboxFrame:Toggle()
if Guda_MailboxFrame:IsShown() then
@@ -71,6 +77,10 @@ function MailboxFrame:Toggle()
end
-- Show specific character's mailbox
function MailboxFrame:GetCurrentViewChar()
return currentViewChar
end
function MailboxFrame:ShowCharacter(fullName)
currentViewChar = fullName
currentPage = 1
+3
View File
@@ -325,6 +325,9 @@
<OnShow>
Guda_MailboxFrame_OnShow(this)
</OnShow>
<OnHide>
Guda_MailboxFrame_OnHide(this)
</OnHide>
<OnMouseDown>
this:StartMoving()
</OnMouseDown>