From d71de1fd7f6c205b584c37d825483f3c65171981 Mon Sep 17 00:00:00 2001 From: Salikh Gurgenidze Date: Thu, 25 Dec 2025 01:02:44 +0400 Subject: [PATCH 1/3] fix: sort cooking --- Sorting/SortEngine.lua | 5 +++++ UI/BagFrame.lua | 13 +++++++++++++ UI/ItemButton.lua | 44 +++++++++++++++++++++--------------------- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/Sorting/SortEngine.lua b/Sorting/SortEngine.lua index 99ba3de..911f617 100644 --- a/Sorting/SortEngine.lua +++ b/Sorting/SortEngine.lua @@ -564,6 +564,11 @@ local function AddSortKeys(items) -- Texture pattern for grouping similar items (especially trade goods) item.texturePattern = GetTexturePattern(itemTexture) + -- Group Trade Goods that are meats/eggs together regardless of texture + local nameLower = item.itemName and string.lower(item.itemName) or "" + if itemType == "Trade Goods" and (string.find(nameLower, "meat") or string.find(nameLower, "egg")) then + item.texturePattern = "trade_meat_egg" + end -- Inverted values for descending sorts item.invertedQuality = -(tonumber(itemRarity) or 0) diff --git a/UI/BagFrame.lua b/UI/BagFrame.lua index 7a1222d..aa0f50c 100644 --- a/UI/BagFrame.lua +++ b/UI/BagFrame.lua @@ -553,6 +553,19 @@ function BagFrame:DisplayItemsByCategory(bagData, isOtherChar, charName) if numItems > 0 then -- Sort items in category: Subclass > Quality > Name table.sort(items, function(a, b) + -- Group Trade Goods that are meats/eggs together + local function isMeatEgg(d) + if not d or not d.name then return false end + local t = d.type or d.class or "" + if t ~= "Trade Goods" then return false end + local n = string.lower(d.name) + return string.find(n, "meat") or string.find(n, "egg") + end + local ma = isMeatEgg(a.itemData) + local mb = isMeatEgg(b.itemData) + if ma ~= mb then + return ma and not mb + end -- Priority: consumable restore tags (eat > drink > restore > nil) local pa = a.itemData and a.itemData.restoreTag or nil local pb = b.itemData and b.itemData.restoreTag or nil diff --git a/UI/ItemButton.lua b/UI/ItemButton.lua index db454a7..485628f 100644 --- a/UI/ItemButton.lua +++ b/UI/ItemButton.lua @@ -983,28 +983,28 @@ function Guda_ItemButton_OnEnter(self) -- Debug: print hovered item's texture path to chat -- Uses GetItemInfo on the hovered item's ID - --if self.hasItem then - -- local link = nil - -- if self.itemData and self.itemData.link then - -- link = self.itemData.link - -- else - -- -- Fallback to live bag query - -- link = GetContainerItemLink(self.bagID, self.slotID) - -- end - -- if link and addon and addon.Modules and addon.Modules.Utils and addon.Modules.Utils.ExtractItemID then - -- local itemID = addon.Modules.Utils:ExtractItemID(link) - -- if itemID and addon.Modules.Utils.GetItemInfoSafe then - -- local name, itemLink, itemRarity, itemLevel, itemCategory, itemType, itemStackCount, - -- itemSubType, itemTexture, itemEquipLoc, itemSellPrice = addon.Modules.Utils:GetItemInfoSafe(itemID) - -- if addon and addon.Print then - -- addon:Print("itemTexture: %s", tostring(itemTexture)) - -- addon:Print("itemCategory: %s", tostring(itemCategory)) - -- addon:Print("itemType: %s", tostring(itemType)) - -- addon:Print("itemType: %s", tostring(itemType)) - -- end - -- end - -- end - --end + if self.hasItem then + local link = nil + if self.itemData and self.itemData.link then + link = self.itemData.link + else + -- Fallback to live bag query + link = GetContainerItemLink(self.bagID, self.slotID) + end + if link and addon and addon.Modules and addon.Modules.Utils and addon.Modules.Utils.ExtractItemID then + local itemID = addon.Modules.Utils:ExtractItemID(link) + if itemID and addon.Modules.Utils.GetItemInfoSafe then + local name, itemLink, itemRarity, itemLevel, itemCategory, itemType, itemStackCount, + itemSubType, itemTexture, itemEquipLoc, itemSellPrice = addon.Modules.Utils:GetItemInfoSafe(itemID) + if addon and addon.Print then + addon:Print("itemTexture: %s", tostring(itemTexture)) + addon:Print("itemCategory: %s", tostring(itemCategory)) + addon:Print("itemType: %s", tostring(itemType)) + addon:Print("itemType: %s", tostring(itemType)) + end + end + end + end -- Handle merchant sell cursor (same approach as BagShui) if MerchantFrame:IsShown() and not self.isBank and not self.otherChar and self.hasItem then ShowContainerSellCursor(self.bagID, self.slotID) From 38c892abb84490c45a8b89a83b8dd1ca850f1941 Mon Sep 17 00:00:00 2001 From: Salikh Gurgenidze Date: Thu, 25 Dec 2025 01:41:16 +0400 Subject: [PATCH 2/3] fix:comment item --- UI/ItemButton.lua | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/UI/ItemButton.lua b/UI/ItemButton.lua index 485628f..db454a7 100644 --- a/UI/ItemButton.lua +++ b/UI/ItemButton.lua @@ -983,28 +983,28 @@ function Guda_ItemButton_OnEnter(self) -- Debug: print hovered item's texture path to chat -- Uses GetItemInfo on the hovered item's ID - if self.hasItem then - local link = nil - if self.itemData and self.itemData.link then - link = self.itemData.link - else - -- Fallback to live bag query - link = GetContainerItemLink(self.bagID, self.slotID) - end - if link and addon and addon.Modules and addon.Modules.Utils and addon.Modules.Utils.ExtractItemID then - local itemID = addon.Modules.Utils:ExtractItemID(link) - if itemID and addon.Modules.Utils.GetItemInfoSafe then - local name, itemLink, itemRarity, itemLevel, itemCategory, itemType, itemStackCount, - itemSubType, itemTexture, itemEquipLoc, itemSellPrice = addon.Modules.Utils:GetItemInfoSafe(itemID) - if addon and addon.Print then - addon:Print("itemTexture: %s", tostring(itemTexture)) - addon:Print("itemCategory: %s", tostring(itemCategory)) - addon:Print("itemType: %s", tostring(itemType)) - addon:Print("itemType: %s", tostring(itemType)) - end - end - end - end + --if self.hasItem then + -- local link = nil + -- if self.itemData and self.itemData.link then + -- link = self.itemData.link + -- else + -- -- Fallback to live bag query + -- link = GetContainerItemLink(self.bagID, self.slotID) + -- end + -- if link and addon and addon.Modules and addon.Modules.Utils and addon.Modules.Utils.ExtractItemID then + -- local itemID = addon.Modules.Utils:ExtractItemID(link) + -- if itemID and addon.Modules.Utils.GetItemInfoSafe then + -- local name, itemLink, itemRarity, itemLevel, itemCategory, itemType, itemStackCount, + -- itemSubType, itemTexture, itemEquipLoc, itemSellPrice = addon.Modules.Utils:GetItemInfoSafe(itemID) + -- if addon and addon.Print then + -- addon:Print("itemTexture: %s", tostring(itemTexture)) + -- addon:Print("itemCategory: %s", tostring(itemCategory)) + -- addon:Print("itemType: %s", tostring(itemType)) + -- addon:Print("itemType: %s", tostring(itemType)) + -- end + -- end + -- end + --end -- Handle merchant sell cursor (same approach as BagShui) if MerchantFrame:IsShown() and not self.isBank and not self.otherChar and self.hasItem then ShowContainerSellCursor(self.bagID, self.slotID) From 4da6bba5659d3db3d54a84d68c8f5b3e1c29ec9e Mon Sep 17 00:00:00 2001 From: Salikh Gurgenidze Date: Thu, 25 Dec 2025 01:54:28 +0400 Subject: [PATCH 3/3] feat: reverse stack sorting --- Sorting/SortEngine.lua | 30 ++++++++++++++++++++++++++++-- UI/SettingsPopup.lua | 40 ++++++++++++++++++++++++++++++++++++++++ UI/SettingsPopup.xml | 33 ++++++++++++++++++++++++++------- 3 files changed, 94 insertions(+), 9 deletions(-) diff --git a/Sorting/SortEngine.lua b/Sorting/SortEngine.lua index 911f617..fd5b90d 100644 --- a/Sorting/SortEngine.lua +++ b/Sorting/SortEngine.lua @@ -489,6 +489,9 @@ local function AddSortKeys(items) item.texturePattern = "" item.invertedCount = 0 item.invertedItemID = 0 + item.maxStackCount = 1 + item.isStackable = false + item.stackCount = 1 else -- Check if item is equippable (Armor or Weapon category) local isEquippable = itemCategory == "Armor" or itemCategory == "Weapon" @@ -576,6 +579,11 @@ local function AddSortKeys(items) item.invertedCount = -(tonumber(item.data.count) or 1) item.invertedItemID = -tonumber(itemID) + -- Stack info for reverse stack sorting + item.maxStackCount = tonumber(itemStackCount) or 1 + item.isStackable = item.maxStackCount > 1 + item.stackCount = tonumber(item.data.count) or 1 + -- Name for alphabetical sorting item.itemName = item.name or "" end @@ -586,6 +594,15 @@ end local function SortItems(items) AddSortKeys(items) + -- Get reverse stack sort setting from DB + local reverseStackSort = false + if addon.Modules.DB and addon.Modules.DB.GetSetting then + reverseStackSort = addon.Modules.DB:GetSetting("reverseStackSort") + if reverseStackSort == nil then + reverseStackSort = false + end + end + table.sort(items, function(a, b) -- 1. Priority items first (Hearthstone, etc.) if a.priority ~= b.priority then @@ -677,9 +694,18 @@ local function SortItems(items) if a.invertedItemLevel ~= b.invertedItemLevel then return a.invertedItemLevel < b.invertedItemLevel end - -- Then by stack count (larger stacks first) + -- Then by stack count + -- If reverse stack sort is enabled AND both items are the same stackable item, + -- place smaller stacks before larger ones if a.invertedCount ~= b.invertedCount then - return a.invertedCount < b.invertedCount + -- Check if both items are the same stackable item (same itemID) + if reverseStackSort and a.isStackable and b.isStackable and a.invertedItemID == b.invertedItemID then + -- Reverse: smaller stacks first (compare stackCount ascending) + return a.stackCount < b.stackCount + else + -- Normal: larger stacks first (use invertedCount) + return a.invertedCount < b.invertedCount + end end -- Final stable sort: preserve original collection order for identical items -- This prevents unnecessary reshuffling when items are already sorted diff --git a/UI/SettingsPopup.lua b/UI/SettingsPopup.lua index 076d209..56f4030 100644 --- a/UI/SettingsPopup.lua +++ b/UI/SettingsPopup.lua @@ -973,6 +973,46 @@ function Guda_SettingsPopup_BankViewTypeButton_OnClick() end end +-- Reverse Stack Sort Checkbox OnLoad +function Guda_SettingsPopup_ReverseStackSortCheckbox_OnLoad(self) + local text = getglobal(self:GetName().."Text") + if text then + text:SetText("Reverse Stack Sort") + + -- Increase font size + local font, _, flags = text:GetFont() + if font then + text:SetFont(font, 13, flags) + end + end + + -- Tooltip + self.tooltipText = "When enabled, smaller stacks of the same item will be sorted before larger stacks (e.g., stack of 16 before stack of 20)." + + local reverseStackSort = false + if Guda and Guda.Modules and Guda.Modules.DB then + reverseStackSort = Guda.Modules.DB:GetSetting("reverseStackSort") + if reverseStackSort == nil then + reverseStackSort = false + end + end + + self:SetChecked(reverseStackSort and 1 or 0) +end + +-- Reverse Stack Sort Checkbox OnClick +function Guda_SettingsPopup_ReverseStackSortCheckbox_OnClick(self) + local isChecked = self:GetChecked() == 1 + + -- Save setting + if Guda and Guda.Modules and Guda.Modules.DB then + Guda.Modules.DB:SetSetting("reverseStackSort", isChecked) + end + + -- Note: Sorting will use the new setting on next sort operation + -- No immediate UI update needed +end + -- Initialize function SettingsPopup:Initialize() Guda:Debug("Settings popup initialized") diff --git a/UI/SettingsPopup.xml b/UI/SettingsPopup.xml index ae35e62..8763f71 100644 --- a/UI/SettingsPopup.xml +++ b/UI/SettingsPopup.xml @@ -395,12 +395,31 @@ - -