forked from wowgaming/3.3.5-interface-files
-
Notifications
You must be signed in to change notification settings - Fork 1
/
BankFrame.lua
270 lines (240 loc) · 7.44 KB
/
BankFrame.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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
function ButtonInventorySlot (self)
return BankButtonIDToInvSlotID(self:GetID(),self.isBag)
end
function BankFrameBaseButton_OnLoad (self)
self:RegisterForDrag("LeftButton");
self:RegisterForClicks("LeftButtonUp","RightButtonUp");
self.GetInventorySlot = ButtonInventorySlot;
self.UpdateTooltip = BankFrameItemButton_OnEnter;
end
function BankFrameItemButton_OnLoad (self)
BankFrameBaseButton_OnLoad (self);
self.SplitStack = function(button, split)
SplitContainerItem(BANK_CONTAINER, button:GetID(), split);
end
end
function BankFrameBagButton_OnLoad (self)
self.isBag = 1;
BankFrameBaseButton_OnLoad(self);
end
function BankFrameItemButton_OnEnter (self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
if ( not GameTooltip:SetInventoryItem("player", self:GetInventorySlot()) ) then
if ( self.isBag ) then
GameTooltip:SetText(self.tooltipText);
end
end
CursorUpdate(self);
end
function BankFrameItemButton_Update (button)
local texture = _G[button:GetName().."IconTexture"];
local inventoryID = button:GetInventorySlot();
local textureName = GetInventoryItemTexture("player",inventoryID);
local slotName = button:GetName();
local id;
local slotTextureName;
button.hasItem = nil;
if( button.isBag ) then
id, slotTextureName = GetInventorySlotInfo(strsub(slotName,10));
else
local isQuestItem, questId, isActive = GetContainerItemQuestInfo(BANK_CONTAINER, button:GetID());
local questTexture = _G[button:GetName().."IconQuestTexture"];
if ( questId and not isActive ) then
questTexture:SetTexture(TEXTURE_ITEM_QUEST_BANG);
questTexture:Show();
elseif ( questId or isQuestItem ) then
questTexture:SetTexture(TEXTURE_ITEM_QUEST_BORDER);
questTexture:Show();
else
questTexture:Hide();
end
end
if ( textureName ) then
texture:SetTexture(textureName);
texture:Show();
SetItemButtonCount(button,GetInventoryItemCount("player",inventoryID));
button.hasItem = 1;
elseif ( slotTextureName and button.isBag ) then
texture:SetTexture(slotTextureName);
SetItemButtonCount(button,0);
texture:Show();
else
texture:Hide();
SetItemButtonCount(button,0);
end
BankFrameItemButton_UpdateLocked(button);
BankFrame_UpdateCooldown(BANK_CONTAINER, button);
end
function BankFrame_UpdateCooldown(container, button)
local cooldown = _G[button:GetName().."Cooldown"];
local start, duration, enable = GetContainerItemCooldown(container, button:GetID());
CooldownFrame_SetTimer(cooldown, start, duration, enable);
if ( duration > 0 and enable == 0 ) then
SetItemButtonTextureVertexColor(button, 0.4, 0.4, 0.4);
end
end
function BankFrameItemButton_UpdateLocked (button)
local inventoryID = button:GetInventorySlot();
if ( IsInventoryItemLocked(inventoryID) ) then
SetItemButtonDesaturated(button, 1, 0.5, 0.5, 0.5);
else
if ( button.isBag and ((button:GetID() - 4) > GetNumBankSlots()) ) then
return;
end
SetItemButtonDesaturated(button, nil, 0.5, 0.5, 0.5);
end
end
function BankFrame_OnLoad (self)
self:RegisterEvent("BANKFRAME_OPENED");
self:RegisterEvent("BANKFRAME_CLOSED");
end
function UpdateBagSlotStatus ()
local purchaseFrame = BankFramePurchaseInfo;
if( purchaseFrame == nil ) then
return;
end
local numSlots,full = GetNumBankSlots();
local button;
for i=1, NUM_BANKBAGSLOTS, 1 do
button = _G["BankFrameBag"..i];
if ( button ) then
if ( i <= numSlots ) then
SetItemButtonTextureVertexColor(button, 1.0,1.0,1.0);
button.tooltipText = BANK_BAG;
else
SetItemButtonTextureVertexColor(button, 1.0,0.1,0.1);
button.tooltipText = BANK_BAG_PURCHASE;
end
end
end
-- pass in # of current slots, returns cost of next slot
local cost = GetBankSlotCost(numSlots);
BankFrame.nextSlotCost = cost;
if( GetMoney() >= cost ) then
SetMoneyFrameColor("BankFrameDetailMoneyFrame", "white");
else
SetMoneyFrameColor("BankFrameDetailMoneyFrame", "red")
end
MoneyFrame_Update("BankFrameDetailMoneyFrame", cost);
if( full ) then
purchaseFrame:Hide();
else
purchaseFrame:Show();
end
end
function CloseBankBagFrames ()
for i=NUM_BAG_SLOTS+1, (NUM_BAG_SLOTS + NUM_BANKBAGSLOTS), 1 do
CloseBag(i);
end
end
function BankFrame_OnEvent (self, event, ...)
if ( event == "BANKFRAME_OPENED" ) then
BankFrameTitleText:SetText(UnitName("npc"));
SetPortraitTexture(BankPortraitTexture,"npc");
ShowUIPanel(self);
if ( not self:IsShown() ) then
CloseBankFrame();
end
elseif ( event == "BANKFRAME_CLOSED" ) then
HideUIPanel(self);
elseif ( event == "ITEM_LOCK_CHANGED" ) then
local bag, slot = ...;
if ( bag == BANK_CONTAINER ) then
if ( slot <= NUM_BANKGENERIC_SLOTS ) then
BankFrameItemButton_UpdateLocked(_G["BankFrameItem"..slot]);
else
BankFrameItemButton_UpdateLocked(_G["BankFrameBag"..(slot-NUM_BANKGENERIC_SLOTS)]);
end
end
elseif ( event == "PLAYERBANKSLOTS_CHANGED" ) then
local slot = ...;
if ( slot <= NUM_BANKGENERIC_SLOTS ) then
BankFrameItemButton_Update(_G["BankFrameItem"..slot]);
else
BankFrameItemButton_Update(_G["BankFrameBag"..(slot-NUM_BANKGENERIC_SLOTS)]);
end
elseif ( event == "PLAYER_MONEY" or event == "PLAYERBANKBAGSLOTS_CHANGED" ) then
UpdateBagSlotStatus();
end
end
function BankFrame_OnShow (self)
PlaySound("igMainMenuOpen");
self:RegisterEvent("ITEM_LOCK_CHANGED");
self:RegisterEvent("PLAYERBANKSLOTS_CHANGED");
self:RegisterEvent("PLAYERBANKBAGSLOTS_CHANGED");
self:RegisterEvent("PLAYER_MONEY");
self:RegisterEvent("BAG_UPDATE_COOLDOWN");
local button;
for i=1, NUM_BANKGENERIC_SLOTS, 1 do
button = _G["BankFrameItem"..i];
BankFrameItemButton_Update(button);
end
for i=1, NUM_BANKBAGSLOTS, 1 do
button = _G["BankFrameBag"..i];
BankFrameItemButton_Update(button);
end
UpdateBagSlotStatus();
end
function BankFrame_OnHide (self)
PlaySound("igMainMenuClose");
self:UnregisterEvent("ITEM_LOCK_CHANGED");
self:UnregisterEvent("PLAYERBANKSLOTS_CHANGED");
self:UnregisterEvent("PLAYERBANKBAGSLOTS_CHANGED");
self:UnregisterEvent("PLAYER_MONEY");
StaticPopup_Hide("CONFIRM_BUY_BANK_SLOT");
CloseBankBagFrames();
CloseBankFrame();
updateContainerFrameAnchors();
end
function BankFrameItemButtonGeneric_OnClick (self, button)
if ( button == "LeftButton" ) then
PickupContainerItem(BANK_CONTAINER, self:GetID());
else
UseContainerItem(BANK_CONTAINER, self:GetID());
end
end
function BankFrameItemButtonGeneric_OnModifiedClick (self, button)
if ( self.isBag ) then
return;
end
if ( HandleModifiedItemClick(GetContainerItemLink(BANK_CONTAINER, self:GetID())) ) then
return;
end
if ( IsModifiedClick("SPLITSTACK") ) then
local texture, itemCount, locked = GetContainerItemInfo(BANK_CONTAINER, self:GetID());
if ( not locked ) then
OpenStackSplitFrame(self.count, self, "BOTTOMLEFT", "TOPLEFT");
end
return;
end
end
function UpdateBagButtonHighlight (id)
local texture = _G["BankFrameBag"..(id - NUM_BAG_SLOTS).."HighlightFrameTexture"];
if ( not texture ) then
return;
end
local frame;
for i=1, NUM_CONTAINER_FRAMES, 1 do
frame = _G["ContainerFrame"..i];
if ( ( frame:GetID() == id ) and frame:IsShown() ) then
texture:Show();
return;
end
end
texture:Hide();
end
function BankFrameItemButtonBag_OnClick (self, button)
local inventoryID = self:GetInventorySlot();
local hadItem = PutItemInBag(inventoryID);
local id = self:GetID();
if ( not hadItem ) then
-- open bag
ToggleBag(id);
end
UpdateBagButtonHighlight(id);
end
function BankFrameItemButtonBag_Pickup (self)
local inventoryID = self:GetInventorySlot();
PickupBagFromSlot(inventoryID);
UpdateBagButtonHighlight(self:GetID());
end