-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.lua
executable file
·71 lines (61 loc) · 1.85 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
-- local references to globals
local ActionButton_Update = ActionButton_Update
local CreateFrame = CreateFrame
local GetContainerItemInfo = C_Container.GetContainerItemInfo
local GetContainerNumSlots = C_Container.GetContainerNumSlots
local SPELL_REAGENTS = SPELL_REAGENTS
local tooltipFrame
local function cleanName (name)
-- pull text from link
local itemString, itemName = name:match("|H(.*)|h%[(.*)%]|h")
return itemName or name
end
local function reagentCheck (slot)
tooltipFrame:SetAction(slot)
regions = { tooltipFrame:GetRegions() }
for i, region in pairs(regions) do
if region:GetObjectType() == "FontString" then
local text = region:GetText()
if text and string.find(text, SPELL_REAGENTS) then
local reagent = string.gsub(text, SPELL_REAGENTS, '')
return cleanName(reagent)
end
end
end
return nil
end
local function getInventoryCount (item)
local toFind = cleanName(item)
local count = 0
for bag = 4, 0, -1 do
local size = GetContainerNumSlots(bag)
for slot = 1, size do
local texture, itemCount, locked, quality, readable, lootable, itemLink = GetContainerItemInfo(bag, slot);
if itemLink then
if toFind == cleanName(itemLink) then
count = count + itemCount
end
end
end
end
return count
end
local function init ()
-- create tooltip frame
tooltipFrame = CreateFrame("GameTooltip", "ReagentCount_GameTooltip", nil, "GameTooltipTemplate")
tooltipFrame:SetOwner(WorldFrame, "ANCHOR_NONE");
-- hook ActionButton_UpdateCount
hooksecurefunc("ActionButton_UpdateCount",
function (self)
local slot = self.action
if (GetActionInfo(slot) ~= 'item') then
local reagent = reagentCheck(slot)
if (reagent) then
local itemCount = getInventoryCount(reagent)
self.Count:SetText(itemCount)
end
end
end
)
end
init()