From 309e90efa24f1e917f25c4308d2d98396d2213d2 Mon Sep 17 00:00:00 2001 From: Salikh Gurgenidze Date: Wed, 24 Dec 2025 03:06:45 +0400 Subject: [PATCH] fix: sort food and drink properly in category view --- Core/Utils.lua | 28 ++++++++++++++++++++++++++++ UI/BagFrame.lua | 21 +++++++++++++++++++++ UI/ItemButton.lua | 44 ++++++++++++++++++++++---------------------- 3 files changed, 71 insertions(+), 22 deletions(-) diff --git a/Core/Utils.lua b/Core/Utils.lua index b1efb8c..fdad1bf 100644 --- a/Core/Utils.lua +++ b/Core/Utils.lua @@ -442,6 +442,34 @@ local function ExtractHyperlink(itemLink) return hyperlink end +-- Detect if a consumable has 'Use: Restores' or mentions 'while eating'/'while drinking' +function Utils:GetConsumableRestoreTag(bagID, slotID) + if not bagID or not slotID then return nil end + local tooltip = GetScanTooltip() + tooltip:ClearLines() + tooltip:SetBagItem(bagID, slotID) + local tag = nil + for i = 1, tooltip:NumLines() do + local line = getglobal("GudaBagScanTooltipTextLeft" .. i) + if line then + local text = line:GetText() + if text then + local tl = string.lower(text) + if string.find(tl, "while eating") then + tag = "eat" + break + elseif string.find(tl, "while drinking") then + tag = "drink" + break + elseif string.find(tl, "use: restores") then + tag = "restore" + end + end + end + end + return tag +end + -- Check if item is Arrow or Bullet (for Quiver routing) function Utils:IsArrowOrBullet(itemType) if not itemType then return false end diff --git a/UI/BagFrame.lua b/UI/BagFrame.lua index b06c8fa..6fba271 100644 --- a/UI/BagFrame.lua +++ b/UI/BagFrame.lua @@ -434,6 +434,14 @@ function BagFrame:DisplayItemsByCategory(bagData, isOtherChar, charName) local cat = "Miscellaneous" local itemName = itemData.name or "" + -- Detect consumable restore/eat/drink tag for current character only + if not isOtherChar and addon.Modules.Utils and addon.Modules.Utils.GetConsumableRestoreTag then + local tag = addon.Modules.Utils:GetConsumableRestoreTag(bagID, slotID) + if tag then + itemData.restoreTag = tag + end + end + -- Priority 1: Special items (Hearthstone, Mounts, Tools) if string.find(itemName, "Hearthstone") then table.insert(specialItems.Hearthstone, {bagID = bagID, slotID = slotID, itemData = itemData}) @@ -541,6 +549,19 @@ function BagFrame:DisplayItemsByCategory(bagData, isOtherChar, charName) if numItems > 0 then -- Sort items in category: Subclass > Quality > Name table.sort(items, function(a, b) + -- 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 + local function pr(t) + if t == "eat" then return 3 end + if t == "drink" then return 2 end + if t == "restore" then return 1 end + return 0 + end + if pr(pa) ~= pr(pb) then + return pr(pa) > pr(pb) + end + -- Fallback: subclass, quality, name if a.itemData.subclass ~= b.itemData.subclass then return (a.itemData.subclass or "") < (b.itemData.subclass or "") end diff --git a/UI/ItemButton.lua b/UI/ItemButton.lua index 1be41d8..fdcce7c 100644 --- a/UI/ItemButton.lua +++ b/UI/ItemButton.lua @@ -963,28 +963,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)