From 7c5e4a0e08f103c0165731761c9c71ed1baa4b4b Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Thu, 28 May 2026 13:24:50 -0500 Subject: [PATCH] add Item Count module --- api/config.lua | 2 +- init/modules.xml | 1 + modules/itemcount.lua | 53 +++++++++++++++++++++++++++++++++++++++++++ modules/sellvalue.lua | 6 +---- 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 modules/itemcount.lua diff --git a/api/config.lua b/api/config.lua index d99d9038..f0841d8f 100644 --- a/api/config.lua +++ b/api/config.lua @@ -750,7 +750,7 @@ function pfUI:LoadConfig() pfUI:UpdateConfig("tooltip", nil, "alwaysperc", "0") pfUI:UpdateConfig("tooltip", "compare", "basestats", "1") pfUI:UpdateConfig("tooltip", "compare", "showalways", "0") - pfUI:UpdateConfig("tooltip", "vendor", "showalways", "0") + pfUI:UpdateConfig("tooltip", "vendor", "showalways", "1") pfUI:UpdateConfig("tooltip", "questitem", "showquest", "1") pfUI:UpdateConfig("tooltip", "questitem", "showcount", "0") pfUI:UpdateConfig("tooltip", "statusbar", "texture", "Interface\\AddOns\\pfUI\\img\\bar") diff --git a/init/modules.xml b/init/modules.xml index 5c174c79..1d6acbb5 100644 --- a/init/modules.xml +++ b/init/modules.xml @@ -44,6 +44,7 @@ + diff --git a/modules/itemcount.lua b/modules/itemcount.lua new file mode 100644 index 00000000..c50efdf8 --- /dev/null +++ b/modules/itemcount.lua @@ -0,0 +1,53 @@ +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 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("Bags:", bags, 1, 1, 1, 1, 1, 1) end + if bank > 0 then frame:AddDoubleLine("Bank:", bank, 1, 1, 1, 1, 1, 1) end + if equipped > 0 then frame:AddDoubleLine("Equipped:", equipped, 1, 1, 1, 1, 1, 1) end + frame:AddDoubleLine("Total:", total, 1, 1, 1, 1, 1, 1) + frame:Show() + end + + -- GameTooltip: piggyback on its OnShow lifecycle. Each tooltip refresh + -- hides/shows the parent which propagates Show() to this child frame. + 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) + + -- ItemRefTooltip: persistent tooltip from chat link clicks. + hooksecurefunc("SetItemRef", function() + if ItemRefTooltip:HasItem() then + local _, _, id = ItemRefTooltip:GetItem() + if id then AddCounts(ItemRefTooltip, id) end + end + end) +end) diff --git a/modules/sellvalue.lua b/modules/sellvalue.lua index 815cf997..3e2ff0a9 100644 --- a/modules/sellvalue.lua +++ b/modules/sellvalue.lua @@ -7,11 +7,7 @@ pfUI:RegisterModule("sellvalue", function () local buy = pfSellData[id] if sell == 0 and not buy then return end - if not MerchantFrame:IsShown() and sell > 0 then - SetTooltipMoney(frame, sell * count) - end - - if IsShiftKeyDown() or C.tooltip.vendor.showalways == "1" then + if C.tooltip.vendor.showalways == "1" or IsShiftKeyDown() then frame:AddLine(" ") if sell > 0 then