mirror of
https://github.com/brues-code/pfUI.git
synced 2026-09-22 15:46:56 +00:00
5b4cb2bc9f
Only show "Total" when the item is split across more than one location; a single-location item made "Total" duplicate the one breakdown line (e.g. "Equipped: 1 / Total: 1"). Route the Bags/Bank/Equipped/Total labels through the T translation table and add the keys to every locale file, using the Blizzard GlobalStrings as the reference for each localized term.
55 lines
1.9 KiB
Lua
55 lines
1.9 KiB
Lua
pfUI:RegisterModule("itemcount", function ()
|
|
-- Walk the 19 equipment slots looking for this item. C_Item.GetItemCount
|
|
-- bundles "bags + equipped" with no breakdown; we need to subtract the
|
|
-- equipped count to get a bags-only number.
|
|
local function CountEquipped(id)
|
|
local count = 0
|
|
for slot = INVSLOT_FIRST_EQUIPPED, INVSLOT_LAST_EQUIPPED do
|
|
if GetInventoryItemID("player", slot) == id then
|
|
count = count + 1
|
|
end
|
|
end
|
|
return count
|
|
end
|
|
|
|
local function AddCounts(frame, id)
|
|
if not id or id == HEARTHSTONE_ITEM_ID or C_Item.GetItemUniquenessByID(id) == 1 then return end
|
|
|
|
local total = C_Item.GetItemCount(id, true) -- bags + bank + equipped
|
|
if total < 1 then return end
|
|
|
|
local bagsAndEquipped = C_Item.GetItemCount(id, false)
|
|
local equipped = CountEquipped(id)
|
|
local bags = bagsAndEquipped - equipped
|
|
if bags < 0 then bags = 0 end
|
|
local bank = total - bagsAndEquipped
|
|
if bank < 0 then bank = 0 end
|
|
|
|
frame:AddLine(" ")
|
|
if bags > 0 then frame:AddDoubleLine(T["Bags"] .. ":", bags, 1, 1, 1, 1, 1, 1) end
|
|
if bank > 0 then frame:AddDoubleLine(T["Bank"] .. ":", bank, 1, 1, 1, 1, 1, 1) end
|
|
if equipped > 0 then frame:AddDoubleLine(T["Equipped"] .. ":", equipped, 1, 1, 1, 1, 1, 1) end
|
|
|
|
local sources = (bags > 0 and 1 or 0) + (bank > 0 and 1 or 0) + (equipped > 0 and 1 or 0)
|
|
if sources > 1 then
|
|
frame:AddDoubleLine(T["Total"] .. ":", total, 1, 1, 1, 1, 1, 1)
|
|
end
|
|
frame:Show()
|
|
end
|
|
|
|
pfUI.itemcount = CreateFrame("Frame", "pfItemCountTooltip", GameTooltip)
|
|
pfUI.itemcount:SetScript("OnShow", function()
|
|
if GameTooltip:HasItem() then
|
|
local _, _, id = GameTooltip:GetItem()
|
|
if id then AddCounts(GameTooltip, id) end
|
|
end
|
|
end)
|
|
|
|
hooksecurefunc("SetItemRef", function()
|
|
if ItemRefTooltip:HasItem() then
|
|
local _, _, id = ItemRefTooltip:GetItem()
|
|
if id then AddCounts(ItemRefTooltip, id) end
|
|
end
|
|
end)
|
|
end)
|