fix: tooltip counts
This commit is contained in:
+118
-15
@@ -10,15 +10,105 @@ local function GetItemIDFromLink(link)
|
|||||||
local _, _, itemID = strfind(link, "item:(%d+):?")
|
local _, _, itemID = strfind(link, "item:(%d+):?")
|
||||||
return itemID and tonumber(itemID) or nil
|
return itemID and tonumber(itemID) or nil
|
||||||
end
|
end
|
||||||
|
local function CountCurrentCharacterItems(itemID)
|
||||||
-- Count items for a specific character
|
|
||||||
-- Count items for a specific character with safety checks
|
|
||||||
local function CountItemsForCharacter(itemID, characterData)
|
|
||||||
local bagCount = 0
|
local bagCount = 0
|
||||||
local bankCount = 0
|
local bankCount = 0
|
||||||
local equippedCount = 0
|
local equippedCount = 0
|
||||||
|
|
||||||
-- Count bags with safety checks
|
-- Count current character's bags in real-time
|
||||||
|
for bagID = 0, 4 do
|
||||||
|
local numSlots = GetContainerNumSlots(bagID)
|
||||||
|
for slot = 1, numSlots do
|
||||||
|
local link = GetContainerItemLink(bagID, slot)
|
||||||
|
if link then
|
||||||
|
local slotItemID = GetItemIDFromLink(link)
|
||||||
|
if slotItemID == itemID then
|
||||||
|
local _, count = GetContainerItemInfo(bagID, slot)
|
||||||
|
bagCount = bagCount + (count or 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Count current character's bank in real-time if bank is open
|
||||||
|
local bankFrame = getglobal("BankFrame")
|
||||||
|
if bankFrame and bankFrame:IsVisible() then
|
||||||
|
-- Main bank slots (-1)
|
||||||
|
local numMainSlots = GetContainerNumSlots(-1) or 24
|
||||||
|
for slot = 1, numMainSlots do
|
||||||
|
local link = GetContainerItemLink(-1, slot)
|
||||||
|
if link then
|
||||||
|
local slotItemID = GetItemIDFromLink(link)
|
||||||
|
if slotItemID == itemID then
|
||||||
|
local _, count = GetContainerItemInfo(-1, slot)
|
||||||
|
bankCount = bankCount + (count or 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Bank bags (5-11)
|
||||||
|
for bagID = 5, 11 do
|
||||||
|
local numSlots = GetContainerNumSlots(bagID)
|
||||||
|
if numSlots and numSlots > 0 then
|
||||||
|
for slot = 1, numSlots do
|
||||||
|
local link = GetContainerItemLink(bagID, slot)
|
||||||
|
if link then
|
||||||
|
local slotItemID = GetItemIDFromLink(link)
|
||||||
|
if slotItemID == itemID then
|
||||||
|
local _, count = GetContainerItemInfo(bagID, slot)
|
||||||
|
bankCount = bankCount + (count or 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- Bank not open - use saved data for bank counts
|
||||||
|
local playerName = addon.Modules.DB:GetPlayerFullName()
|
||||||
|
local charData = Guda_DB and Guda_DB.characters and Guda_DB.characters[playerName]
|
||||||
|
if charData and charData.bank and type(charData.bank) == "table" then
|
||||||
|
for bagID, bagData in pairs(charData.bank) do
|
||||||
|
if bagData and type(bagData) == "table" and bagData.slots and type(bagData.slots) == "table" then
|
||||||
|
for slotID, itemData in pairs(bagData.slots) do
|
||||||
|
if itemData and type(itemData) == "table" and itemData.link then
|
||||||
|
local slotItemID = GetItemIDFromLink(itemData.link)
|
||||||
|
if slotItemID == itemID then
|
||||||
|
bankCount = bankCount + (itemData.count or 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Count equipped items in real-time
|
||||||
|
for slotID = 1, 19 do -- All equipment slots
|
||||||
|
local link = GetInventoryItemLink("player", slotID)
|
||||||
|
if link then
|
||||||
|
local slotItemID = GetItemIDFromLink(link)
|
||||||
|
if slotItemID == itemID then
|
||||||
|
equippedCount = equippedCount + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return bagCount, bankCount, equippedCount
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Count items for a specific character with real-time data for current character
|
||||||
|
local function CountItemsForCharacter(itemID, characterData, isCurrentChar)
|
||||||
|
-- For current character, use real-time counting to avoid database sync issues
|
||||||
|
if isCurrentChar then
|
||||||
|
return CountCurrentCharacterItems(itemID)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- For other characters, use saved data
|
||||||
|
local bagCount = 0
|
||||||
|
local bankCount = 0
|
||||||
|
local equippedCount = 0
|
||||||
|
|
||||||
|
-- Count bags from saved data
|
||||||
if characterData.bags and type(characterData.bags) == "table" then
|
if characterData.bags and type(characterData.bags) == "table" then
|
||||||
for bagID, bagData in pairs(characterData.bags) do
|
for bagID, bagData in pairs(characterData.bags) do
|
||||||
if bagData and type(bagData) == "table" and bagData.slots and type(bagData.slots) == "table" then
|
if bagData and type(bagData) == "table" and bagData.slots and type(bagData.slots) == "table" then
|
||||||
@@ -34,7 +124,7 @@ local function CountItemsForCharacter(itemID, characterData)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Count bank with safety checks
|
-- Count bank from saved data
|
||||||
if characterData.bank and type(characterData.bank) == "table" then
|
if characterData.bank and type(characterData.bank) == "table" then
|
||||||
for bagID, bagData in pairs(characterData.bank) do
|
for bagID, bagData in pairs(characterData.bank) do
|
||||||
if bagData and type(bagData) == "table" and bagData.slots and type(bagData.slots) == "table" then
|
if bagData and type(bagData) == "table" and bagData.slots and type(bagData.slots) == "table" then
|
||||||
@@ -50,7 +140,7 @@ local function CountItemsForCharacter(itemID, characterData)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Count equipped items from EquipmentScanner data with safety checks
|
-- Count equipped items from saved data
|
||||||
if characterData.equipped and type(characterData.equipped) == "table" then
|
if characterData.equipped and type(characterData.equipped) == "table" then
|
||||||
for slotName, itemData in pairs(characterData.equipped) do
|
for slotName, itemData in pairs(characterData.equipped) do
|
||||||
if itemData and type(itemData) == "table" and itemData.link then
|
if itemData and type(itemData) == "table" and itemData.link then
|
||||||
@@ -65,6 +155,7 @@ local function CountItemsForCharacter(itemID, characterData)
|
|||||||
return bagCount, bankCount, equippedCount
|
return bagCount, bankCount, equippedCount
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Get class color
|
-- Get class color
|
||||||
local function GetClassColor(classToken)
|
local function GetClassColor(classToken)
|
||||||
if not classToken then return 1.0, 1.0, 1.0 end
|
if not classToken then return 1.0, 1.0, 1.0 end
|
||||||
@@ -96,11 +187,14 @@ function Tooltip:AddInventoryInfo(tooltip, link)
|
|||||||
local characterCounts = {}
|
local characterCounts = {}
|
||||||
local hasAnyItems = false
|
local hasAnyItems = false
|
||||||
|
|
||||||
|
local currentPlayerName = addon.Modules.DB:GetPlayerFullName()
|
||||||
|
|
||||||
-- Count items across all characters with safety checks
|
-- Count items across all characters with safety checks
|
||||||
for charName, charData in pairs(Guda_DB.characters) do
|
for charName, charData in pairs(Guda_DB.characters) do
|
||||||
-- Ensure charData is actually a table before processing
|
-- Ensure charData is actually a table before processing
|
||||||
if type(charData) == "table" then
|
if type(charData) == "table" then
|
||||||
local bagCount, bankCount, equippedCount = CountItemsForCharacter(itemID, charData)
|
local isCurrentChar = (charName == currentPlayerName)
|
||||||
|
local bagCount, bankCount, equippedCount = CountItemsForCharacter(itemID, charData, isCurrentChar)
|
||||||
|
|
||||||
if bagCount > 0 or bankCount > 0 or equippedCount > 0 then
|
if bagCount > 0 or bankCount > 0 or equippedCount > 0 then
|
||||||
hasAnyItems = true
|
hasAnyItems = true
|
||||||
@@ -112,7 +206,8 @@ function Tooltip:AddInventoryInfo(tooltip, link)
|
|||||||
classToken = charData.classToken,
|
classToken = charData.classToken,
|
||||||
bagCount = bagCount,
|
bagCount = bagCount,
|
||||||
bankCount = bankCount,
|
bankCount = bankCount,
|
||||||
equippedCount = equippedCount
|
equippedCount = equippedCount,
|
||||||
|
isCurrent = isCurrentChar
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -124,16 +219,18 @@ function Tooltip:AddInventoryInfo(tooltip, link)
|
|||||||
if hasAnyItems then
|
if hasAnyItems then
|
||||||
tooltip:AddLine(" ")
|
tooltip:AddLine(" ")
|
||||||
|
|
||||||
-- Inventory label in exact bag frame title color (from your XML: |cFF00FF96)
|
-- Inventory label in exact bag frame title color
|
||||||
tooltip:AddLine("|cFFFFD200Inventory|r") -- Exact bag frame title color
|
tooltip:AddLine("|cFFFFD200Inventory|r")
|
||||||
|
|
||||||
-- Total line with cyan label and white count
|
-- Total line with cyan label and white count
|
||||||
local totalText = "|cFF00FFFFTotal|r: |cFFFFFFFF" .. totalCount .. "|r" -- Cyan label, white count
|
local totalText = "|cFF00FFFFTotal|r: |cFFFFFFFF" .. totalCount .. "|r"
|
||||||
local breakdownText = "(|cFF00FFFFBags|r: |cFFFFFFFF" .. totalBags .. "|r | |cFF00FFFFBank|r: |cFFFFFFFF" .. totalBank .. "|r)" -- Cyan labels, white counts
|
local breakdownText = "(|cFF00FFFFBags|r: |cFFFFFFFF" .. totalBags .. "|r | |cFF00FFFFBank|r: |cFFFFFFFF" .. totalBank .. "|r)"
|
||||||
|
|
||||||
tooltip:AddDoubleLine(totalText, breakdownText, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
|
tooltip:AddDoubleLine(totalText, breakdownText, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
|
||||||
|
|
||||||
|
-- Sort with current character first
|
||||||
table.sort(characterCounts, function(a, b)
|
table.sort(characterCounts, function(a, b)
|
||||||
|
if a.isCurrent and not b.isCurrent then return true end
|
||||||
|
if not a.isCurrent and b.isCurrent then return false end
|
||||||
return a.name < b.name
|
return a.name < b.name
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -156,7 +253,13 @@ function Tooltip:AddInventoryInfo(tooltip, link)
|
|||||||
countText = table.concat(parts, " | ")
|
countText = table.concat(parts, " | ")
|
||||||
end
|
end
|
||||||
|
|
||||||
tooltip:AddDoubleLine(charInfo.name, countText, r, g, b, 1.0, 1.0, 1.0)
|
-- Mark current character
|
||||||
|
local displayName = charInfo.name
|
||||||
|
if charInfo.isCurrent then
|
||||||
|
displayName = displayName .. " |cFFFFFF00(*)|r"
|
||||||
|
end
|
||||||
|
|
||||||
|
tooltip:AddDoubleLine(displayName, countText, r, g, b, 1.0, 1.0, 1.0)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add small gap between inventory data and vendor sell price
|
-- Add small gap between inventory data and vendor sell price
|
||||||
|
|||||||
Reference in New Issue
Block a user