-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInventorian.lua
More file actions
194 lines (162 loc) · 5.22 KB
/
Inventorian.lua
File metadata and controls
194 lines (162 loc) · 5.22 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
local _, Inventorian = ...
Inventorian = LibStub("AceAddon-3.0"):NewAddon(Inventorian, "Inventorian", "AceEvent-3.0", "AceHook-3.0", "AceConsole-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("Inventorian")
local db
local defaults = {
profile = {
bag = {
x = -20,
y = -80,
point = "RIGHT",
width = 384,
height = 512,
showBags = false,
},
bank = {
x = 220,
y = 120,
point = "LEFT",
width = 512,
height = 512,
showBags = false,
},
}
}
function Inventorian:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("InventorianDB", defaults, true)
db = self.db.profile
end
local BAG_CONFIG =
{
{
title = BAGSLOT,
bags = { Enum.BagIndex.Backpack, Enum.BagIndex.Bag_1, Enum.BagIndex.Bag_2, Enum.BagIndex.Bag_3, Enum.BagIndex.Bag_4 }
},
{
title = L["Reagents"],
bags = { Enum.BagIndex.ReagentBag },
isReagentBag = true,
}
}
local BANK_CONFIG =
{
{
title = BANK,
bags = { Enum.BagIndex.CharacterBankTab_1, Enum.BagIndex.CharacterBankTab_2, Enum.BagIndex.CharacterBankTab_3, Enum.BagIndex.CharacterBankTab_4, Enum.BagIndex.CharacterBankTab_5, Enum.BagIndex.CharacterBankTab_6 },
isBank = true,
},
{
title = ACCOUNT_QUEST_LABEL,
bags = { Enum.BagIndex.AccountBankTab_1, Enum.BagIndex.AccountBankTab_2, Enum.BagIndex.AccountBankTab_3, Enum.BagIndex.AccountBankTab_4, Enum.BagIndex.AccountBankTab_5 },
isBank = true,
isAccountBank = true,
},
}
local ACCOUNT_BANK_CONFIG =
{
{
title = ACCOUNT_QUEST_LABEL,
bags = { Enum.BagIndex.AccountBankTab_1, Enum.BagIndex.AccountBankTab_2, Enum.BagIndex.AccountBankTab_3, Enum.BagIndex.AccountBankTab_4, Enum.BagIndex.AccountBankTab_5 },
isBank = true,
isAccountBank = true,
}
}
function Inventorian:OnEnable()
self.bag = Inventorian.Frame:Create("InventorianBagFrame", L["%s's Inventory"], db.bag, BAG_CONFIG)
self.bank = Inventorian.Frame:Create("InventorianBankFrame", L["%s's Bank"], db.bank, BANK_CONFIG)
self.accountbank = Inventorian.Frame:Create("InventorianAccountBankFrame", L["%s's Account Bank"], db.bank, ACCOUNT_BANK_CONFIG)
self:SetupBagHooks()
self:RegisterChatCommand("inventorian", "HandleSlash")
SetCVarBitfield("closedInfoFrames", LE_FRAME_TUTORIAL_EQUIP_REAGENT_BAG, true);
end
function Inventorian:HandleSlash(cmd)
if strtrim(cmd) == "bank" then
self.bank:ShowFrame()
else
self:Print("Available Commands:")
self:Print(" /inventorian bank: Show the current characters bank")
end
end
function Inventorian:AutoShowInventory()
self.bag:ShowFrame(true)
end
function Inventorian:AutoHideInventory()
self.bag:HideFrame(true)
end
function Inventorian:ToggleBackpack()
self.bag:ToggleFrame()
end
function Inventorian:OpenAllBags()
self.bag:ShowFrame()
end
function Inventorian:CloseAllBags()
self.bag:HideFrame()
end
function Inventorian:AutoShowBank()
self.bank:ShowFrame(true)
end
function Inventorian:AutoShowAccountBank()
self.accountbank:ShowFrame(true)
end
function Inventorian:AutoHideBank()
self.bank:HideFrame(true)
self.accountbank:HideFrame(true)
end
function Inventorian:UpdateBag()
self.bag:Update()
self.bank:Update()
end
function Inventorian:SetupBagHooks()
self.UIHider = CreateFrame("Frame")
self.UIHider:Hide()
-- auto magic display code
self:RawHook("OpenBackpack", "AutoShowInventory", true)
self:SecureHook("CloseBackpack", "AutoHideInventory")
self:RawHook("ToggleBag", "ToggleBackpack", true)
self:RawHook("ToggleBackpack", true)
self:RawHook("ToggleAllBags", "ToggleBackpack", true)
self:RawHook("OpenAllBags", true)
self:RawHook("OpenBag", "OpenAllBags", true)
--self:RawHook("GetBackpackFrame", function() return self.bag:IsShown() and self.bag or nil end, true)
self:SecureHook(ContainerFrameSettingsManager.TokenTracker, "Update", function() Inventorian.Frame.ManageBackpackTokenFrame(self.bag) end, true)
BankFrame:UnregisterAllEvents()
BankFrame:SetScript("OnShow", nil)
BankFrame:SetParent(self.UIHider)
local Events = self:GetModule("Events")
Events.Register(self, "BANK_OPENED", function()
self:AutoShowBank()
self:AutoShowInventory()
end)
Events.Register(self, "ACCOUNT_BANK_OPENED", function()
self:AutoShowAccountBank()
self:AutoShowInventory()
end)
Events.Register(self, "BANK_CLOSED", function()
self:AutoHideBank()
self:AutoHideInventory()
end)
self:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_SHOW")
self:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_HIDE")
self:SecureHook("ContainerFrame_UpdateAll", "UpdateBag")
-- noop out container anchor update
UpdateContainerFrameAnchors = function() end
-- stop the bank from being a UI Panel
BankFrame:SetAttribute("UIPanelLayout-defined", true)
BankFrame:SetAttribute("UIPanelLayout-area", nil)
end
function Inventorian:PLAYER_INTERACTION_MANAGER_FRAME_SHOW(event, id)
if id == Enum.PlayerInteractionType.TradePartner then
self:AutoShowInventory()
elseif id == Enum.PlayerInteractionType.Auctioneer then
self:AutoShowInventory()
end
end
function Inventorian:PLAYER_INTERACTION_MANAGER_FRAME_HIDE(event, id)
if id == Enum.PlayerInteractionType.MailInfo then
self:AutoHideInventory() -- only close when leaving the mailbox, don't auto-open here
elseif id == Enum.PlayerInteractionType.TradePartner then
self:AutoHideInventory()
elseif id == Enum.PlayerInteractionType.Auctioneer then
self:AutoHideInventory()
end
end