GetItemCount via C_Item, reagents via C_Spell.GetSpellReagents

Drops the legacy pfUI.api.GetItemCount wrapper (name-based bag walk +
GetItemInfo per slot) entirely — both call sites switch to direct
C_Item.GetItemCount(itemID) calls.

actionbar reagent counter: drops the SPELL_REAGENTS tooltip-scan +
libtipscan dependency. UpdateSlot now does GetActionInfo(slot) →
spellID → C_Spell.GetSpellReagents → reagent itemID, stored per slot.
Counts update via C_Item.GetItemCount(itemID). reagent_counts is
keyed by itemID instead of localized name string. Multi-reagent
spells now resolve cleanly (only first reagent counted, matching old
single-name behavior). Macro and bag-item actions skip cleanly.

questitem: switches to hooksecurefunc("SetItemRef", ...) + the
modern GameTooltip:HasItem / :GetItem pair instead of monkey-patching
_G.SetItemRef and string.find-parsing the "item:NNN" out of the link.
Drops the libtooltip indirection for the regular tooltip path —
GameTooltip:GetItem returns name + itemID directly. AddTooltip
extended to accept the itemID (both callers already had it and were
discarding it).
This commit is contained in:
Brues
2026-05-21 16:20:19 -05:00
parent 1012a67865
commit 8e635afeed
3 changed files with 41 additions and 68 deletions
-25
View File
@@ -406,31 +406,6 @@ function pfUI.api.GetItemLinkByName(name)
end
end
-- [ GetItemCount ]
-- Returns information about how many of a given item the player has.
-- 'itemName' [string] name of the item
-- returns: [int] the number of the given item
function pfUI.api.GetItemCount(itemName)
local count = 0
for bag = 4, 0, -1 do
for slot = 1, GetContainerNumSlots(bag) do
local _, itemCount = GetContainerItemInfo(bag, slot)
if itemCount then
local itemLink = GetContainerItemLink(bag,slot)
local _, _, itemParse = strfind(itemLink, "(%d+):")
local queryName = GetItemInfo(itemParse)
if queryName and queryName ~= "" then
if queryName == itemName then
count = count + itemCount
end
end
end
end
end
return count
end
-- [ FindItem ]
-- Returns the bag and slot position of an item based on the name.
-- 'item' [string] name of the item
+22 -25
View File
@@ -1639,34 +1639,31 @@ pfUI:RegisterModule("actionbar", "vanilla", function ()
-- reagent counter
if C.bars.reagents == "1" then
local reagent_slots = { }
local reagent_counts = { }
local reagent_capture = SPELL_REAGENTS.."(.+)"
local scanner = libtipscan:GetScanner("actionbar")
local reagent_slots = { } -- action slot -> first reagent itemID
local reagent_counts = { } -- itemID -> count in player's inventory
-- For a given action slot, resolve the spell's first reagent itemID
-- via GetActionInfo + C_Spell.GetSpellReagents. Macro actions and
-- bag-item actions are skipped (their reagent resolution would need a
-- macro-body parse / item-effect lookup that we don't bother with).
local UpdateSlot = function(slot)
local texture = GetActionTexture(slot)
-- update buttons that previously had an reagent
if reagent_slots[slot] and not HasAction(slot) then
reagent_slots[slot] = nil
updatecache[slot] = true
local newID = nil
if HasAction(slot) then
local kind, spellID = GetActionInfo(slot)
if kind == "spell" and spellID then
local reagents = C_Spell.GetSpellReagents(spellID)
if reagents and reagents[1] then
newID = reagents[1].itemID
end
end
end
-- search for reagent requirements
if HasAction(slot) then
scanner:SetAction(slot)
local _, reagents = scanner:Find(reagent_capture)
-- remove reagent counts if existing
reagents = reagents and string.gsub(reagents, " %((.+)%)", "")
-- update on reagent requirement changes
if reagents and reagent_slots[slot] ~= reagents then
reagent_counts[reagents] = reagent_counts[reagents] or 0
reagent_slots[slot] = reagents
updatecache[slot] = true
if reagent_slots[slot] ~= newID then
reagent_slots[slot] = newID
if newID then
reagent_counts[newID] = reagent_counts[newID] or 0
end
updatecache[slot] = true
end
end
@@ -1705,8 +1702,8 @@ pfUI:RegisterModule("actionbar", "vanilla", function ()
if ( this.tick or 1) > GetTime() then return else this.tick = GetTime() + 1 end
-- scan for all reagent item counts
for item in pairs(reagent_counts) do
reagent_counts[item] = GetItemCount(item)
for itemID in pairs(reagent_counts) do
reagent_counts[itemID] = C_Item.GetItemCount(itemID)
end
-- update all actionbar buttons
+19 -18
View File
@@ -2,7 +2,7 @@ pfUI:RegisterModule("questitem", function ()
local questlog = {}
local itemcache = {}
local function AddTooltip(frame, item)
local function AddTooltip(frame, item, itemID)
-- abort when no item was given
if not item then return end
@@ -54,7 +54,8 @@ pfUI:RegisterModule("questitem", function ()
if C.tooltip.questitem.showcount == "1" and itemcache[item] and itemcache[item] ~= false then
local _, _, required = strfind(string.lower(questlog[itemcache[item]]), "_"..string.lower(item).."_(.-)_")
if required then
quest = string.format("%s |cffaaaaaa[%s/%s]", quest, (GetItemCount(item) or 0), required)
local have = itemID and C_Item.GetItemCount(itemID) or 0
quest = string.format("%s |cffaaaaaa[%s/%s]", quest, have, required)
end
end
@@ -134,25 +135,25 @@ pfUI:RegisterModule("questitem", function ()
pfUI.questitem.run = GetTime() + .5
end
-- add to regular tooltips
pfUI.questitem.tooltip = CreateFrame("Frame", "pfQuestItems", GameTooltip )
-- regular tooltip: catch every Show via a child frame's OnShow, then ask
-- the tooltip directly for the item it's displaying. Replaces a libtooltip
-- indirection that did the same query with extra caching layers.
pfUI.questitem.tooltip = CreateFrame("Frame", "pfQuestItems", GameTooltip)
pfUI.questitem.tooltip:SetScript("OnShow", function()
if libtooltip:GetItemLink() then
local id = libtooltip:GetItemID()
if not id then return end
local name = GetItemInfo(id)
AddTooltip(GameTooltip, name)
if GameTooltip:HasItem() then
local name, _, id = GameTooltip:GetItem()
if name and id then AddTooltip(GameTooltip, name, id) end
end
end)
-- add to itemref tooltips
local HookSetItemRef = SetItemRef
_G.SetItemRef = function(link, text, button)
HookSetItemRef(link, text, button)
local item, _, id = string.find(link, "item:(%d+):.*")
if not IsAltKeyDown() and not IsShiftKeyDown() and not IsControlKeyDown() and item then
local name = GetItemInfo(id)
AddTooltip(ItemRefTooltip, name)
-- itemref tooltip (chat link clicks): hooksecurefunc runs after SetItemRef
-- populates ItemRefTooltip, so we just read the item back out of the tooltip
-- instead of re-parsing the "item:NNN" out of the link string.
hooksecurefunc("SetItemRef", function()
if IsAltKeyDown() or IsShiftKeyDown() or IsControlKeyDown() then return end
if ItemRefTooltip:HasItem() then
local name, _, id = ItemRefTooltip:GetItem()
if name and id then AddTooltip(ItemRefTooltip, name, id) end
end
end
end)
end)