From 839118841e7524e958c13c2ec5119fb7efe47a61 Mon Sep 17 00:00:00 2001 From: Salikh Gurgenidze Date: Sat, 27 Dec 2025 18:28:13 +0400 Subject: [PATCH] fix: mailbox count --- Core/Tooltip.lua | 46 +++++++++++++++++------- Data/MailboxScanner.lua | 77 ++++++++++++++++++++--------------------- UI/MailboxFrame.xml | 4 +-- 3 files changed, 74 insertions(+), 53 deletions(-) diff --git a/Core/Tooltip.lua b/Core/Tooltip.lua index 26aa665..b9201e9 100644 --- a/Core/Tooltip.lua +++ b/Core/Tooltip.lua @@ -112,17 +112,28 @@ local function CountCurrentCharacterItems(itemID) for _, mail in ipairs(charData.mailbox) do if mail.items then for _, item in ipairs(mail.items) do - if item.link then - local slotItemID = GetItemIDFromLink(item.link) - if slotItemID == itemID then + local slotItemID = item.link and GetItemIDFromLink(item.link) + if slotItemID == itemID then + mailCount = mailCount + (item.count or 1) + elseif not slotItemID and item.name then + -- Fallback to name matching if link is missing + local targetName = GetItemInfo(itemID) + if targetName == item.name then mailCount = mailCount + (item.count or 1) end end end - elseif mail.item and mail.item.link then -- Fallback for single item data structure - local slotItemID = GetItemIDFromLink(mail.item.link) + elseif mail.item then -- Fallback for single item data structure + local item = mail.item + local slotItemID = item.link and GetItemIDFromLink(item.link) if slotItemID == itemID then - mailCount = mailCount + (mail.item.count or 1) + mailCount = mailCount + (item.count or 1) + elseif not slotItemID and item.name then + -- Fallback to name matching if link is missing + local targetName = GetItemInfo(itemID) + if targetName == item.name then + mailCount = mailCount + (item.count or 1) + end end end end @@ -193,17 +204,28 @@ local function CountItemsForCharacter(itemID, characterData, isCurrentChar) for _, mail in ipairs(characterData.mailbox) do if mail.items then for _, item in ipairs(mail.items) do - if item.link then - local slotItemID = GetItemIDFromLink(item.link) - if slotItemID == itemID then + local slotItemID = item.link and GetItemIDFromLink(item.link) + if slotItemID == itemID then + mailCount = mailCount + (item.count or 1) + elseif not slotItemID and item.name then + -- Fallback to name matching if link is missing + local targetName = GetItemInfo(itemID) + if targetName == item.name then mailCount = mailCount + (item.count or 1) end end end - elseif mail.item and mail.item.link then -- Fallback for single item data structure - local slotItemID = GetItemIDFromLink(mail.item.link) + elseif mail.item then -- Fallback for single item data structure + local item = mail.item + local slotItemID = item.link and GetItemIDFromLink(item.link) if slotItemID == itemID then - mailCount = mailCount + (mail.item.count or 1) + mailCount = mailCount + (item.count or 1) + elseif not slotItemID and item.name then + -- Fallback to name matching if link is missing + local targetName = GetItemInfo(itemID) + if targetName == item.name then + mailCount = mailCount + (item.count or 1) + end end end end diff --git a/Data/MailboxScanner.lua b/Data/MailboxScanner.lua index 747a146..e981cf0 100644 --- a/Data/MailboxScanner.lua +++ b/Data/MailboxScanner.lua @@ -36,49 +36,48 @@ function MailboxScanner:ScanMailItemRows(index) local rows = {} if hasItem then - -- Turtle WoW supports up to 12 attachments per mail + local itemIndex = 1 + -- GetInboxItem(index, itemIndex) returns: name, texture, count, quality, canUse + local name, texture, count, quality, canUse = GetInboxItem(index, itemIndex) + if name then + local itemLink = addon.Modules.Utils:GetInboxItemLink(index, itemIndex) - -- GetInboxItem(index, itemIndex) returns: name, texture, count, quality, canUse - local name, texture, count, quality, canUse = GetInboxItem(index, itemIndex) - if name then - local itemLink = addon.Modules.Utils:GetInboxItemLink(index, itemIndex) + local itemData = { + link = itemLink, + texture = texture or "Interface\\Icons\\INV_Misc_Bag_08", + count = count or 1, + quality = quality or 0, + name = name, + } - local itemData = { - link = itemLink, - texture = texture or "Interface\\Icons\\INV_Misc_Bag_08", - count = count or 1, - quality = quality or 0, - name = name, - } - - -- If we have a link, try to get more detailed info - if itemLink then - local itemName, link, itemQuality, iLevel, itemCategory, itemType, itemStackCount, itemSubType, itemTexture, itemEquipLoc, itemSellPrice = addon.Modules.Utils:GetItemInfo(itemLink) - if itemName then - itemData.name = itemName - itemData.quality = itemQuality or itemData.quality - itemData.iLevel = iLevel - itemData.type = itemType - itemData.class = itemCategory - itemData.subclass = itemSubType - itemData.equipSlot = itemEquipLoc - if itemTexture then itemData.texture = itemTexture end - end + -- If we have a link, try to get more detailed info + if itemLink then + local itemName, link, itemQuality, iLevel, itemCategory, itemType, itemStackCount, itemSubType, itemTexture, itemEquipLoc, itemSellPrice = addon.Modules.Utils:GetItemInfo(itemLink) + if itemName then + itemData.name = itemName + itemData.quality = itemQuality or itemData.quality + itemData.iLevel = iLevel + itemData.type = itemType + itemData.class = itemCategory + itemData.subclass = itemSubType + itemData.equipSlot = itemEquipLoc + if itemTexture then itemData.texture = itemTexture end end + end - table.insert(rows, { - sender = sender, - subject = subject, - money = (itemIndex == 1) and money or 0, -- Attach money only to the first row of this mail - CODAmount = (itemIndex == 1) and CODAmount or 0, - daysLeft = daysLeft, - hasItem = true, - item = itemData, - mailIndex = index, - itemIndex = itemIndex, - wasRead = wasRead, - packageIcon = packageIcon, - }) + table.insert(rows, { + sender = sender, + subject = subject, + money = (itemIndex == 1) and money or 0, -- Attach money only to the first row of this mail + CODAmount = (itemIndex == 1) and CODAmount or 0, + daysLeft = daysLeft, + hasItem = true, + item = itemData, + mailIndex = index, + itemIndex = itemIndex, + wasRead = wasRead, + packageIcon = packageIcon, + }) end end diff --git a/UI/MailboxFrame.xml b/UI/MailboxFrame.xml index 88c7f10..5577d3d 100644 --- a/UI/MailboxFrame.xml +++ b/UI/MailboxFrame.xml @@ -150,12 +150,12 @@ - + - +