fix: sort food and drink properly in category view
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+22
-22
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user