diff --git a/Core/Init.lua b/Core/Init.lua index 54f49fa..01f5e98 100644 --- a/Core/Init.lua +++ b/Core/Init.lua @@ -15,6 +15,9 @@ addon.DEBUG = false -- Debug sort flag (verbose sorting output) addon.DEBUG_SORT = false +-- Debug category view flag (for troubleshooting category view layout issues) +addon.DEBUG_CATEGORY = false + -- Constants addon.Constants = { -- Bag IDs @@ -243,6 +246,14 @@ function addon:DebugSort(msg, a1, a2, a3, a4, a5, a6, a7) end end +-- Debug category view print (only shows when DEBUG_CATEGORY is enabled) +function addon:DebugCategory(msg, a1, a2, a3, a4, a5, a6, a7) + if self.DEBUG_CATEGORY then + local text = string.format(msg or "nil", a1 or "", a2 or "", a3 or "", a4 or "", a5 or "", a6 or "", a7 or "") + DEFAULT_CHAT_FRAME:AddMessage("|cFFFF69B4[Category]|r |cFF00FF96Guda:|r " .. text) + end +end + -- Error handler function addon:Error(msg, a1, a2, a3, a4, a5, a6, a7) local text = string.format(msg, a1, a2, a3, a4, a5, a6, a7) diff --git a/Core/Main.lua b/Core/Main.lua index 21a50c2..d724770 100644 --- a/Core/Main.lua +++ b/Core/Main.lua @@ -132,6 +132,11 @@ function Main:SetupSlashCommands() addon.DEBUG_SORT = not addon.DEBUG_SORT addon:Print("Debug sort mode: %s", addon.DEBUG_SORT and "ON" or "OFF") + elseif msg == "debugcat" then + -- Toggle debug category view (for troubleshooting layout issues) + addon.DEBUG_CATEGORY = not addon.DEBUG_CATEGORY + addon:Print("Debug category mode: %s", addon.DEBUG_CATEGORY and "ON" or "OFF") + elseif msg == "quest" then -- Toggle quest bar local show = not addon.Modules.DB:GetSetting("showQuestBar") diff --git a/UI/BagFrame.lua b/UI/BagFrame.lua index 8622731..af86edf 100644 --- a/UI/BagFrame.lua +++ b/UI/BagFrame.lua @@ -422,6 +422,9 @@ function BagFrame:Update() return end + local viewType = addon.Modules.DB:GetSetting("bagViewType") or "single" + addon:DebugCategory("Update() START: viewType=%s", viewType) + -- Report entry for frame budget tracking if addon.Modules.Utils and addon.Modules.Utils.ReportEntry then addon.Modules.Utils:ReportEntry() @@ -453,16 +456,23 @@ function BagFrame:Update() end -- Mark all existing buttons as not in use (we'll mark active ones during display) + local totalButtonsBefore = 0 + local shownButtonsBefore = 0 for _, bagParent in pairs(bagParents) do if bagParent then local buttons = { bagParent:GetChildren() } for _, button in ipairs(buttons) do if button.hasItem ~= nil then + totalButtonsBefore = totalButtonsBefore + 1 + if button:IsShown() then + shownButtonsBefore = shownButtonsBefore + 1 + end button.inUse = false end end end end + addon:DebugCategory("Update() BEFORE: totalButtons=%d, shownButtons=%d", totalButtonsBefore, shownButtonsBefore) local bagData local isOtherChar = false @@ -515,7 +525,9 @@ function BagFrame:Update() end if viewType == "category" then + addon:DebugCategory("Update() calling DisplayItemsByCategory") self:DisplayItemsByCategory(bagData, isOtherChar, charName) + addon:DebugCategory("Update() DisplayItemsByCategory returned, itemButtons count=%d", table.getn(itemButtons)) -- Show sort button with merge icon/tooltip for category view local sortBtn = getglobal("Guda_BagFrame_SortButton") if sortBtn then @@ -544,6 +556,8 @@ function BagFrame:Update() self:UpdateBaglineLayout() -- Clean up unused buttons AFTER display is complete (prevents drag/drop issues) + local hiddenCount = 0 + local stillShownCount = 0 for _, bagParent in pairs(bagParents) do if bagParent then local buttons = { bagParent:GetChildren() } @@ -551,15 +565,20 @@ function BagFrame:Update() if button.hasItem ~= nil and not button.inUse then button:Hide() button:ClearAllPoints() + hiddenCount = hiddenCount + 1 + elseif button.hasItem ~= nil and button:IsShown() then + stillShownCount = stillShownCount + 1 end end end end + addon:DebugCategory("Update() CLEANUP: hidden=%d, stillShown=%d", hiddenCount, stillShownCount) -- Record performance metrics if addon.Modules.Utils and addon.Modules.Utils.RecordUpdateEnd then addon.Modules.Utils:RecordUpdateEnd() end + addon:DebugCategory("Update() END") end -- Delegate to centralized helpers @@ -578,11 +597,14 @@ function BagFrame:DisplayItemsByCategory(bagData, isOtherChar, charName) local perRow = addon.Modules.DB:GetSetting("bagColumns") or 10 local itemContainer = getglobal("Guda_BagFrame_ItemContainer") + addon:DebugCategory("DisplayItemsByCategory START: buttonSize=%d, spacing=%d, perRow=%d", buttonSize, spacing, perRow) + -- Use centralized category initialization local categories, specialItems = Guda_InitCategories() local categoryList = Guda_CategoryList -- Categorize all items using centralized function + local totalItemsCategorized = 0 for _, bagID in ipairs(addon.Constants.BAGS) do if not hiddenBags[bagID] then local bag = bagData[bagID] @@ -590,11 +612,13 @@ function BagFrame:DisplayItemsByCategory(bagData, isOtherChar, charName) for slotID, itemData in pairs(bag.slots) do if itemData then Guda_CategorizeItem(itemData, bagID, slotID, categories, specialItems, isOtherChar) + totalItemsCategorized = totalItemsCategorized + 1 end end end end end + addon:DebugCategory("DisplayItemsByCategory: totalItemsCategorized=%d", totalItemsCategorized) -- Calculate total empty slots and find first available one for drop target local totalFreeSlots = 0 @@ -640,10 +664,12 @@ function BagFrame:DisplayItemsByCategory(bagData, isOtherChar, charName) local categoryItemsProcessed = 0 local CATEGORY_ITEMS_PER_BUDGET_CHECK = 8 + local totalButtonsCreated = 0 for _, catName in ipairs(categoryList) do local items = categories[catName] local numItems = items and table.getn(items) or 0 if numItems > 0 then + addon:DebugCategory(" Category '%s': %d items, pos=(%d,%d)", catName, numItems, currentX, currentY) -- Sort items using centralized sorter Guda_SortCategoryItems(items) @@ -658,6 +684,7 @@ function BagFrame:DisplayItemsByCategory(bagData, isOtherChar, charName) currentX = 0 currentY = currentY + rowMaxHeight rowMaxHeight = 0 + addon:DebugCategory(" -> wrap to new row, Y=%d", currentY) end -- Add Header @@ -725,10 +752,12 @@ function BagFrame:DisplayItemsByCategory(bagData, isOtherChar, charName) end end + totalButtonsCreated = totalButtonsCreated + numItems if blockHeight > rowMaxHeight then rowMaxHeight = blockHeight end currentX = currentX + blockWidth + 20 end end + addon:DebugCategory("DisplayItemsByCategory: totalButtonsCreated=%d from categories", totalButtonsCreated) -- Update Y for bottom sections local y = currentY + rowMaxHeight @@ -868,6 +897,7 @@ function BagFrame:DisplayItemsByCategory(bagData, isOtherChar, charName) local finalHeight = math.abs(y) + 20 itemContainer:SetHeight(finalHeight) self:ResizeFrame(nil, nil, perRow, finalHeight) + addon:DebugCategory("DisplayItemsByCategory END: finalHeight=%d, itemButtons=%d", finalHeight, table.getn(itemButtons)) end -- Display items @@ -2698,6 +2728,9 @@ function BagFrame:Initialize() -- Only handle player bags (0-4) if not arg1 or arg1 < 0 or arg1 > 4 then return end + local viewType = addon.Modules.DB:GetSetting("bagViewType") or "single" + addon:DebugCategory("BAG_UPDATE: bagID=%s, viewType=%s", tostring(arg1), viewType) + -- Check if sorting is in progress - use full redraw with throttle local isSorting = addon.Modules.SortEngine and addon.Modules.SortEngine.sortingInProgress @@ -2708,11 +2741,14 @@ function BagFrame:Initialize() -- Try to update only changed slots in this bag local result = BagFrame:UpdateChangedSlots(arg1) + addon:DebugCategory("BAG_UPDATE: UpdateChangedSlots result=%s", tostring(result)) if result >= 0 then -- Success - updated slots without full redraw + addon:DebugCategory("BAG_UPDATE: Incremental update succeeded, skipping full redraw") return end -- Fall through to full redraw if incremental update failed + addon:DebugCategory("BAG_UPDATE: Incremental update failed, doing full redraw") end -- Sorting in progress or incremental update failed - use throttled full redraw diff --git a/UI/FrameHelpers.lua b/UI/FrameHelpers.lua index 145a020..cc1116f 100644 --- a/UI/FrameHelpers.lua +++ b/UI/FrameHelpers.lua @@ -143,10 +143,21 @@ local categoriesCache = nil local specialItemsCache = nil -- Clear a table without creating a new one (Lua 5.0 compatible) +-- For arrays, iterate backwards to safely remove all elements local function WipeTable(t) if not t then return end + -- For arrays (numeric keys), remove from end to start + local n = table.getn(t) + if n > 0 then + for i = n, 1, -1 do + table.remove(t, i) + end + end + -- Also clear any non-numeric keys (hash part) for k in pairs(t) do - t[k] = nil + if type(k) ~= "number" then + t[k] = nil + end end end @@ -161,10 +172,19 @@ function Guda_InitCategories() end -- Clear existing category arrays (don't recreate the main table) + local totalItemsBeforeWipe = 0 for cat, items in pairs(categoriesCache) do + totalItemsBeforeWipe = totalItemsBeforeWipe + table.getn(items) WipeTable(items) end + -- Verify wipe worked + local totalItemsAfterWipe = 0 + for cat, items in pairs(categoriesCache) do + totalItemsAfterWipe = totalItemsAfterWipe + table.getn(items) + end + addon:DebugCategory("InitCategories: beforeWipe=%d, afterWipe=%d", totalItemsBeforeWipe, totalItemsAfterWipe) + if addon.Modules.CategoryManager then -- Get full category order (all categories, not just enabled) local allCategories = addon.Modules.CategoryManager:GetCategoryOrder()