fix: sort food and drink properly in category view

This commit is contained in:
Salikh Gurgenidze
2025-12-24 03:06:45 +04:00
parent 74c6ff184e
commit 309e90efa2
3 changed files with 71 additions and 22 deletions
+28
View File
@@ -442,6 +442,34 @@ local function ExtractHyperlink(itemLink)
return hyperlink return hyperlink
end 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) -- Check if item is Arrow or Bullet (for Quiver routing)
function Utils:IsArrowOrBullet(itemType) function Utils:IsArrowOrBullet(itemType)
if not itemType then return false end if not itemType then return false end
+21
View File
@@ -434,6 +434,14 @@ function BagFrame:DisplayItemsByCategory(bagData, isOtherChar, charName)
local cat = "Miscellaneous" local cat = "Miscellaneous"
local itemName = itemData.name or "" 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) -- Priority 1: Special items (Hearthstone, Mounts, Tools)
if string.find(itemName, "Hearthstone") then if string.find(itemName, "Hearthstone") then
table.insert(specialItems.Hearthstone, {bagID = bagID, slotID = slotID, itemData = itemData}) table.insert(specialItems.Hearthstone, {bagID = bagID, slotID = slotID, itemData = itemData})
@@ -541,6 +549,19 @@ function BagFrame:DisplayItemsByCategory(bagData, isOtherChar, charName)
if numItems > 0 then if numItems > 0 then
-- Sort items in category: Subclass > Quality > Name -- Sort items in category: Subclass > Quality > Name
table.sort(items, function(a, b) 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 if a.itemData.subclass ~= b.itemData.subclass then
return (a.itemData.subclass or "") < (b.itemData.subclass or "") return (a.itemData.subclass or "") < (b.itemData.subclass or "")
end end
+22 -22
View File
@@ -963,28 +963,28 @@ function Guda_ItemButton_OnEnter(self)
-- Debug: print hovered item's texture path to chat -- Debug: print hovered item's texture path to chat
-- Uses GetItemInfo on the hovered item's ID -- Uses GetItemInfo on the hovered item's ID
--if self.hasItem then if self.hasItem then
-- local link = nil local link = nil
-- if self.itemData and self.itemData.link then if self.itemData and self.itemData.link then
-- link = self.itemData.link link = self.itemData.link
-- else else
-- -- Fallback to live bag query -- Fallback to live bag query
-- link = GetContainerItemLink(self.bagID, self.slotID) link = GetContainerItemLink(self.bagID, self.slotID)
-- end end
-- if link and addon and addon.Modules and addon.Modules.Utils and addon.Modules.Utils.ExtractItemID then if link and addon and addon.Modules and addon.Modules.Utils and addon.Modules.Utils.ExtractItemID then
-- local itemID = addon.Modules.Utils:ExtractItemID(link) local itemID = addon.Modules.Utils:ExtractItemID(link)
-- if itemID and addon.Modules.Utils.GetItemInfoSafe then if itemID and addon.Modules.Utils.GetItemInfoSafe then
-- local name, itemLink, itemRarity, itemLevel, itemCategory, itemType, itemStackCount, local name, itemLink, itemRarity, itemLevel, itemCategory, itemType, itemStackCount,
-- itemSubType, itemTexture, itemEquipLoc, itemSellPrice = addon.Modules.Utils:GetItemInfoSafe(itemID) itemSubType, itemTexture, itemEquipLoc, itemSellPrice = addon.Modules.Utils:GetItemInfoSafe(itemID)
-- if addon and addon.Print then if addon and addon.Print then
-- addon:Print("itemTexture: %s", tostring(itemTexture)) addon:Print("itemTexture: %s", tostring(itemTexture))
-- addon:Print("itemCategory: %s", tostring(itemCategory)) addon:Print("itemCategory: %s", tostring(itemCategory))
-- addon:Print("itemType: %s", tostring(itemType)) addon:Print("itemType: %s", tostring(itemType))
-- addon:Print("itemType: %s", tostring(itemType)) addon:Print("itemType: %s", tostring(itemType))
-- end end
-- end end
-- end end
--end end
-- Handle merchant sell cursor (same approach as BagShui) -- Handle merchant sell cursor (same approach as BagShui)
if MerchantFrame:IsShown() and not self.isBank and not self.otherChar and self.hasItem then if MerchantFrame:IsShown() and not self.isBank and not self.otherChar and self.hasItem then
ShowContainerSellCursor(self.bagID, self.slotID) ShowContainerSellCursor(self.bagID, self.slotID)