-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackends.lua
More file actions
164 lines (134 loc) · 4.39 KB
/
Copy pathbackends.lua
File metadata and controls
164 lines (134 loc) · 4.39 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
153
154
155
156
157
158
159
160
161
162
163
164
--[[ Stash / backends ----------------------------------------------------------
Which window the cached bank is poured into.
Showing Blizzard's BankFrame is only the right answer when that is what you
see at a real bank. A backend is a small description of somebody else's bank
window, and the highest priority one that is actually loaded wins.
A backend that sets ownscache means the addon behind it already keeps its own
copy of the bank and will show that. In those cases the API diversion in
shim.lua stays switched off so there is only ever one source of truth on
screen; Stash just opens the window.
Adding one for another bag addon is a few lines:
Stash:RegisterBackend({
name = "mybags",
priority = 10,
detect = function() return MyBags_OpenBank and true or nil end,
isopen = function() return MyBankFrame:IsVisible() end,
open = function() MyBags_OpenBank() end,
close = function() MyBankFrame:Hide() end,
install = function() Stash:HookClose(MyBankFrame) end,
})
-----------------------------------------------------------------------------]]
local pairs, ipairs = pairs, ipairs
local getn, sort = table.getn, table.sort
Stash.modules.backends = true
Stash.backends = {}
function Stash:RegisterBackend(def)
if not def or not def.name or not def.detect then
return
end
Stash.backends[def.name] = def
end
-- The backend in use: whatever was pinned with /stash ui, else the best one
-- present.
function Stash:GetBackend()
local pinned = StashDB and StashDB.ui
if pinned and Stash.backends[pinned] and Stash.backends[pinned].detect() then
return Stash.backends[pinned]
end
local best
for _, backend in pairs(Stash.backends) do
if backend.detect() and (not best or (backend.priority or 0) > (best.priority or 0)) then
best = backend
end
end
return best
end
function Stash:ListBackends()
local names = {}
for name in pairs(Stash.backends) do
names[getn(names) + 1] = name
end
sort(names)
return names
end
-- --------------------------------------------------------------------------
-- Bagnon
--
-- Banknon is Bagnon's bank window. Bagnon keeps its own cache in BagnonDB and
-- switches Banknon over to it whenever the player is away from the bank, so
-- there is nothing for the shim to do here beyond opening the frame.
-- --------------------------------------------------------------------------
Stash:RegisterBackend({
name = "bagnon",
priority = 20,
ownscache = true,
label = "Bagnon (Banknon)",
detect = function()
return BagnonFrame_Open and Banknon and BagnonDB and true or nil
end,
isopen = function()
return Banknon and Banknon:IsVisible() and true or nil
end,
open = function()
BagnonFrame_Open("Banknon")
end,
close = function()
BagnonFrame_Close("Banknon")
end,
install = function()
Stash:HookClose(Banknon)
end,
})
-- --------------------------------------------------------------------------
-- Blizzard
--
-- Always available, and the right answer for bag addons that replace the bags
-- but leave the bank alone - EngInventory, for one, has no bank window at all,
-- so this is what its users see at a real bank too.
-- --------------------------------------------------------------------------
Stash:RegisterBackend({
name = "blizzard",
priority = 0,
label = "Blizzard BankFrame",
detect = function()
return BankFrame and true or nil
end,
isopen = function()
return BankFrame and BankFrame:IsShown() and true or nil
end,
open = function()
if ShowUIPanel then
ShowUIPanel(BankFrame)
else
BankFrame:Show()
end
end,
close = function()
if HideUIPanel then
HideUIPanel(BankFrame)
else
BankFrame:Hide()
end
end,
refresh = function()
Stash:RefreshBankFrame()
end,
install = function()
Stash:HookClose(BankFrame)
end,
})
-- --------------------------------------------------------------------------
-- init
--
-- Installing waits for PLAYER_LOGIN: the frames belonging to other addons do
-- not necessarily exist while this file is being read.
-- --------------------------------------------------------------------------
local init = CreateFrame("Frame")
init:RegisterEvent("PLAYER_LOGIN")
init:SetScript("OnEvent", function()
for _, backend in pairs(Stash.backends) do
if backend.detect() and backend.install then
backend.install()
end
end
end)