-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtooltip.lua
More file actions
152 lines (123 loc) · 4.93 KB
/
Copy pathtooltip.lua
File metadata and controls
152 lines (123 loc) · 4.93 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
--[[ Stash / tooltip -----------------------------------------------------------
The container and inventory wrappers in shim.lua are enough to draw the bank,
but not to explain it: GameTooltip:SetBagItem and GameTooltip:SetInventoryItem
read the live slot inside the client and never touch those Lua functions. Away
from the bank they find nothing and the tooltip comes up empty.
So both are replaced with versions that recognise a cached bank slot and build
the tooltip from the stored item link instead. That covers Blizzard's bank
buttons, Bagnon (which calls SetInventoryItem for bank slots), and anything
else going through the normal calls.
Frames are tables with their methods on a metatable, so assigning the method
on the instance shadows it and the original stays reachable for everything
that is not a cached bank slot.
-----------------------------------------------------------------------------]]
Stash.modules.tooltip = true
local strfind, strsub = strfind, strsub
-- Vanilla's SetHyperlink is happiest with the bare "item:id:ench:suffix:unique"
-- form, so pull that back out of the stored link.
function Stash:ItemString(link)
if not link then
return nil
end
local _, _, itemstring = strfind(link, "(item:%d+:%d+:%d+:%d+)")
if itemstring then
return itemstring
end
local _, _, id = strfind(link, "item:(%d+)")
return id and ("item:" .. id .. ":0:0:0") or nil
end
-- --------------------------------------------------------------------------
-- rendering
-- --------------------------------------------------------------------------
-- Draws a cached item into the given tooltip. Returns true when it managed to,
-- so the callers below know whether to fall through to the real function.
local function ShowCached(tooltip, item, note)
local itemstring = Stash:ItemString(item and item.link)
if not itemstring then
return nil
end
tooltip:SetHyperlink(itemstring)
if item.count and item.count > 1 then
tooltip:AddLine("Stack of " .. item.count, 0.6, 0.6, 0.6)
end
tooltip:AddLine(note, 1, 0.82, 0)
tooltip:Show()
return true
end
local function CachedNote()
local char = Stash:GetChar(Stash.viewing)
local who = Stash.viewing or UnitName("player")
if char and char.updated then
return who .. "'s bank, as of your last visit"
end
return who .. "'s bank (cached)"
end
-- --------------------------------------------------------------------------
-- bag slots
-- --------------------------------------------------------------------------
local origSetBagItem = GameTooltip.SetBagItem
function GameTooltip.SetBagItem(self, bag, slot)
if Stash:Serving(bag) then
local container = Stash:GetContainer(bag)
local item = container and container.items[slot]
if ShowCached(self, item, CachedNote()) then
-- hasCooldown, repairCost: nothing to report for a picture of a bank
return nil, 0
end
if item then
return nil, 0
end
end
return origSetBagItem(self, bag, slot)
end
-- --------------------------------------------------------------------------
-- inventory slots
--
-- The 24 bank slots are inventory slots too, and that is how Blizzard's own
-- bank buttons ask for their tooltips.
-- --------------------------------------------------------------------------
local origSetInventoryItem = GameTooltip.SetInventoryItem
function GameTooltip.SetInventoryItem(self, unit, slot, nameOnly)
if Stash.offline and (unit == "player" or unit == nil) and Stash.invmaps then
local bankslot = Stash.invmaps.bankslot[slot]
if bankslot then
local container = Stash:GetContainer(Stash.BANK_CONTAINER)
local item = container and container.items[bankslot]
if ShowCached(self, item, CachedNote()) then
return 1, nil, 0
end
-- an empty cached slot really is empty; do not let the live bank answer
return nil, nil, 0
end
local bag = Stash.invmaps.bankbag[slot]
if bag then
local container = Stash:GetContainer(bag)
if container and container.link then
if ShowCached(self, { link = container.link, count = 1 }, CachedNote()) then
return 1, nil, 0
end
end
return nil, nil, 0
end
end
return origSetInventoryItem(self, unit, slot, nameOnly)
end
-- --------------------------------------------------------------------------
-- guild bank slots
-- --------------------------------------------------------------------------
if GameTooltip.SetGuildBankItem then
local origSetGuildBankItem = GameTooltip.SetGuildBankItem
function GameTooltip.SetGuildBankItem(self, tab, slot)
if Stash.gboffline then
local store = Stash:GetGuild()
local record = store and store.tabs[tab]
local item = record and record.items[slot]
local note = (Stash.viewingguild or "Guild") .. " bank, as of your last visit"
if ShowCached(self, item, note) then
return nil, 0
end
return nil, 0
end
return origSetGuildBankItem(self, tab, slot)
end
end