From a95167a91a1303245f405d24faf32d7dcffbef4e Mon Sep 17 00:00:00 2001 From: Salikh Gurgenidze Date: Tue, 23 Dec 2025 20:35:02 +0400 Subject: [PATCH] fix: category toggle --- UI/BagFrame.lua | 44 ++++++++++++++++++-------------------------- UI/BankFrame.lua | 42 +++++++++++++++++------------------------- 2 files changed, 35 insertions(+), 51 deletions(-) diff --git a/UI/BagFrame.lua b/UI/BagFrame.lua index a1606fc..edbf7e6 100644 --- a/UI/BagFrame.lua +++ b/UI/BagFrame.lua @@ -323,6 +323,17 @@ function BagFrame:Update() -- Display items local viewType = addon.Modules.DB:GetSetting("bagViewType") or "single" + + -- Reset all section headers before displaying items + local i = 1 + while true do + local header = getglobal("Guda_BagFrame_SectionHeader" .. i) + if not header then break end + header.inUse = false + header:Hide() + i = i + 1 + end + if viewType == "category" then self:DisplayItemsByCategory(bagData, isOtherChar, charName) else @@ -335,20 +346,9 @@ function BagFrame:Update() -- Update bag slots info self:UpdateBagSlotsInfo(bagData, isOtherChar) - -- Update bagline layout (hover option) + -- Update bagline layout (hover option) self:UpdateBaglineLayout() - -- Clean up unused section headers - local i = 1 - while true do - local header = getglobal("Guda_BagFrame_SectionHeader" .. i) - if not header then break end - if not header.inUse then - header:Hide() - end - i = i + 1 - end - -- Clean up unused buttons AFTER display is complete (prevents drag/drop issues) for _, bagParent in pairs(bagParents) do if bagParent then @@ -398,15 +398,6 @@ function BagFrame:DisplayItemsByCategory(bagData, isOtherChar, charName) local perRow = addon.Modules.DB:GetSetting("bagColumns") or 10 local itemContainer = getglobal("Guda_BagFrame_ItemContainer") - -- Reset headers - local idx = 1 - while true do - local h = getglobal("Guda_BagFrame_SectionHeader" .. idx) - if not h then break end - h.inUse = false - idx = idx + 1 - end - -- Group items by category local categories = {} local categoryList = { @@ -510,8 +501,9 @@ function BagFrame:DisplayItemsByCategory(bagData, isOtherChar, charName) end -- Update container height - itemContainer:SetHeight(math.abs(y) + 20) - self:UpdateFrameSize() + local finalHeight = math.abs(y) + 20 + itemContainer:SetHeight(finalHeight) + self:ResizeFrame(nil, nil, perRow, finalHeight) end -- Display items @@ -676,12 +668,12 @@ function BagFrame:DisplayItems(bagData, isOtherChar, charName) end -- Resize frame based on number of rows and columns -function BagFrame:ResizeFrame(currentRow, currentCol, columns) +function BagFrame:ResizeFrame(currentRow, currentCol, columns, overrideHeight) local buttonSize = addon.Modules.DB:GetSetting("iconSize") or addon.Constants.BUTTON_SIZE local spacing = addon.Modules.DB:GetSetting("iconSpacing") or addon.Constants.BUTTON_SPACING -- Calculate actual number of rows used - local totalRows = currentRow + 1 + local totalRows = (currentRow or 0) + 1 -- Ensure at least 1 row if totalRows < 1 then @@ -690,7 +682,7 @@ function BagFrame:ResizeFrame(currentRow, currentCol, columns) -- Calculate required dimensions based on columns local containerWidth = (columns * (buttonSize + spacing)) + 20 - local containerHeight = (totalRows * (buttonSize + spacing)) + 20 + local containerHeight = overrideHeight or ((totalRows * (buttonSize + spacing)) + 20) local frameWidth = containerWidth + 20 -- Check if search bar is visible diff --git a/UI/BankFrame.lua b/UI/BankFrame.lua index 793891a..d88a657 100644 --- a/UI/BankFrame.lua +++ b/UI/BankFrame.lua @@ -178,6 +178,17 @@ function BankFrame:Update() end local viewType = addon.Modules.DB:GetSetting("bankViewType") or "single" + + -- Reset all section headers before displaying items + local i = 1 + while true do + local header = getglobal("Guda_BankFrame_SectionHeader" .. i) + if not header then break end + header.inUse = false + header:Hide() + i = i + 1 + end + if viewType == "category" then self:DisplayItemsByCategory(bankData, isOtherChar, charName) else @@ -190,17 +201,6 @@ function BankFrame:Update() -- Update bank slots info self:UpdateBankSlotsInfo(bankData, isOtherChar) - -- Clean up unused section headers - local i = 1 - while true do - local header = getglobal("Guda_BankFrame_SectionHeader" .. i) - if not header then break end - if not header.inUse then - header:Hide() - end - i = i + 1 - end - -- Clean up unused buttons AFTER display is complete (prevents drag/drop issues) for _, bankBagParent in pairs(bankBagParents) do if bankBagParent then @@ -250,15 +250,6 @@ function BankFrame:DisplayItemsByCategory(bankData, isOtherChar, charName) local perRow = addon.Modules.DB:GetSetting("bankColumns") or 10 local itemContainer = getglobal("Guda_BankFrame_ItemContainer") - -- Reset headers - local idx = 1 - while true do - local h = getglobal("Guda_BankFrame_SectionHeader" .. idx) - if not h then break end - h.inUse = false - idx = idx + 1 - end - -- Group items by category local categories = {} local categoryList = { @@ -357,8 +348,9 @@ function BankFrame:DisplayItemsByCategory(bankData, isOtherChar, charName) end -- Update container height - itemContainer:SetHeight(math.abs(y) + 20) - self:UpdateFrameSize() + local finalHeight = math.abs(y) + 20 + itemContainer:SetHeight(finalHeight) + self:ResizeFrame(nil, nil, perRow, finalHeight) end -- Display items @@ -495,12 +487,12 @@ function BankFrame:DisplayItems(bankData, isOtherChar, charName) end -- Resize bank frame based on number of rows and columns -function BankFrame:ResizeFrame(currentRow, currentCol, columns) +function BankFrame:ResizeFrame(currentRow, currentCol, columns, overrideHeight) local buttonSize = addon.Modules.DB:GetSetting("iconSize") or addon.Constants.BUTTON_SIZE local spacing = addon.Modules.DB:GetSetting("iconSpacing") or addon.Constants.BUTTON_SPACING -- Calculate actual number of rows used - local totalRows = currentRow + 1 + local totalRows = (currentRow or 0) + 1 if totalRows < 1 then totalRows = 1 end @@ -512,7 +504,7 @@ function BankFrame:ResizeFrame(currentRow, currentCol, columns) -- Calculate required dimensions local containerWidth = (columns * (buttonSize + spacing)) + 10 - local containerHeight = (totalRows * (buttonSize + spacing)) + 20 + local containerHeight = overrideHeight or ((totalRows * (buttonSize + spacing)) + 20) local frameWidth = containerWidth + 30 -- Check if search bar is visible