vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[**************************************************************** |
2 | BankItems v10900 |
||
3 | |||
4 | Author: wow.jaslaughter.com |
||
5 | **************************************************************** |
||
6 | Description: |
||
7 | Type /bi or /bankitems to see what is currently in your |
||
8 | bank. You must visit your bank one time to initialize. |
||
9 | |||
10 | Credits: |
||
11 | Original concept from Merphle |
||
12 | I look for SellValue data for the list, an addon originally |
||
13 | by Sarf. I use the version from CapnBry at http://capnbry.net/wow |
||
14 | |||
15 | Official Site: |
||
16 | wow.jaslaughter.com |
||
17 | |||
18 | BankItems-10900 |
||
19 | ****************************************************************]] |
||
20 | |||
21 | BINDING_HEADER_BANKITEMS = "BankItems Bindings"; |
||
22 | BINDING_NAME_TOGGLEBANKITEMS = "Toggle BankItems"; |
||
23 | BINDING_NAME_TOGGLEBANKITEMSALL = "Toggle BankItems and all Bags"; |
||
24 | BINDING_NAME_RESETFRAMEPOS = "Reset BankItems positions"; |
||
25 | BANKITEMS_VERSIONTEXT = "BankItems v10900"; |
||
26 | |||
27 | BankItems_Save = {}; |
||
28 | local loaded = nil; |
||
29 | local bankPlayer = nil; |
||
30 | local bankPlayerName = nil; |
||
31 | local allRealms = 0; |
||
32 | local allBags = 0; |
||
33 | local CONTAINER_FRAME_TABLE = { |
||
34 | [0] = {"Interface\\ContainerFrame\\UI-BackpackBackground", 256, 256, 239}, |
||
35 | [1] = {"Interface\\ContainerFrame\\UI-Bag-1x4", 256, 128, 96}, |
||
36 | [2] = {"Interface\\ContainerFrame\\UI-Bag-1x4", 256, 128, 96}, |
||
37 | [3] = {"Interface\\ContainerFrame\\UI-Bag-1x4", 256, 128, 96}, |
||
38 | [4] = {"Interface\\ContainerFrame\\UI-Bag-1x4", 256, 128, 96}, |
||
39 | [5] = {"Interface\\ContainerFrame\\UI-Bag-1x4+2", 256, 128, 116}, |
||
40 | [6] = {"Interface\\ContainerFrame\\UI-Bag-1x4+2", 256, 128, 116}, |
||
41 | [7] = {"Interface\\ContainerFrame\\UI-Bag-1x4+2", 256, 128, 116}, |
||
42 | [8] = {"Interface\\ContainerFrame\\UI-Bag-2x4", 256, 256, 137}, |
||
43 | [9] = {"Interface\\ContainerFrame\\UI-Bag-2x4+2", 256, 256, 157}, |
||
44 | [10] = {"Interface\\ContainerFrame\\UI-Bag-2x4+2", 256, 256, 157}, |
||
45 | [11] = {"Interface\\ContainerFrame\\UI-Bag-2x4+2", 256, 256, 157}, |
||
46 | [12] = {"Interface\\ContainerFrame\\UI-Bag-3x4", 256, 256, 178}, |
||
47 | [13] = {"Interface\\ContainerFrame\\UI-Bag-3x4+2", 256, 256, 198}, |
||
48 | [14] = {"Interface\\ContainerFrame\\UI-Bag-3x4+2", 256, 256, 198}, |
||
49 | [15] = {"Interface\\ContainerFrame\\UI-Bag-3x4+2", 256, 256, 198}, |
||
50 | [16] = {"Interface\\ContainerFrame\\UI-Bag-4x4", 256, 256, 219}, |
||
51 | [18] = {"Interface\\ContainerFrame\\UI-Bag-4x4+2", 256, 256, 239}, |
||
52 | [20] = {"Interface\\ContainerFrame\\UI-Bag-5x4", 256, 256, 259}, |
||
53 | }; |
||
54 | |||
55 | function BankItems_OnLoad() |
||
56 | this:RegisterEvent("VARIABLES_LOADED"); |
||
57 | |||
58 | this:RegisterEvent("BANKFRAME_OPENED"); |
||
59 | this:RegisterEvent("PLAYERBANKSLOTS_CHANGED"); |
||
60 | this:RegisterEvent("PLAYERBANKBAGSLOTS_CHANGED"); |
||
61 | this:RegisterEvent("BAG_UPDATE"); |
||
62 | |||
63 | this:RegisterEvent("PLAYER_MONEY"); |
||
64 | |||
65 | SlashCmdList["BANKITEMS"] = function(msg) BankItems_SlashHandler(msg) end; |
||
66 | SLASH_BANKITEMS1 = "/bankitems"; |
||
67 | SLASH_BANKITEMS2 = "/bi"; |
||
68 | |||
69 | tinsert(UISpecialFrames,"BankItems_Frame"); |
||
70 | end |
||
71 | |||
72 | function BankItems_OnEvent(event) |
||
73 | if ( event == "VARIABLES_LOADED" ) then |
||
74 | loaded = 1; |
||
75 | end |
||
76 | if ( not loaded ) then |
||
77 | return; |
||
78 | end |
||
79 | if ( bankPlayer == nil ) then |
||
80 | bankPlayer = BankItems_GetPlayer(UnitName("player").."|"..BankItems_Trim(GetCVar("realmName"))); |
||
81 | BankItems_SaveMoney(); |
||
82 | return; |
||
83 | end |
||
84 | if ( event == "BANKFRAME_OPENED" or event == "PLAYERBANKSLOTS_CHANGED" or event == "PLAYERBANKBAGSLOTS_CHANGED" ) then |
||
85 | BankItems_SaveItems(); |
||
86 | return; |
||
87 | end |
||
88 | if ( event == "BAG_UPDATE" and BankFrame:IsVisible() ) then |
||
89 | BankItems_SaveItems(); |
||
90 | if ( tonumber(arg1) and tonumber(arg1) > 4 and tonumber(arg1) <= 10 ) then |
||
91 | BankItems_PopulateBag(arg1); |
||
92 | end |
||
93 | return; |
||
94 | end |
||
95 | if ( event == "PLAYER_MONEY" ) then |
||
96 | BankItems_SaveMoney(); |
||
97 | return; |
||
98 | end |
||
99 | end |
||
100 | |||
101 | function BankItems_Frame_OnShow() |
||
102 | PlaySound("igMainMenuOpen"); |
||
103 | if ( not BankItems_Frame.hasShown ) then |
||
104 | BankItems_Frame.hasShown = 1; |
||
105 | SetPortraitTexture(BankItems_Portrait, "player"); |
||
106 | BankItems_TotalMoneyText:ClearAllPoints(); |
||
107 | BankItems_TotalMoneyText:SetPoint("LEFT","BankItems_MoneyFrameTotalCopperButton","RIGHT",0,0); |
||
108 | end |
||
109 | BankItems_SaveMoney(); |
||
110 | end |
||
111 | |||
112 | function BankItems_Frame_OnHide() |
||
113 | for bagNum = 1, 6 do |
||
114 | getglobal("BankItems_ContainerFrame"..bagNum):Hide(); |
||
115 | end |
||
116 | end |
||
117 | |||
118 | function BankItems_GetPlayer(playerName) |
||
119 | if ( not BankItems_Save[playerName] or (not BankItems_Save[playerName].money and table.getn(BankItems_Save[playerName]) == 0) ) then |
||
120 | BankItems_Save[playerName] = {}; |
||
121 | end |
||
122 | BankItems_TitleText:SetText(BankItems_Split(playerName,"|")[1].." of "..BankItems_Split(playerName,"|")[2]); |
||
123 | bankPlayerName = playerName; |
||
124 | if ( playerName == UnitName("player").."|"..BankItems_Trim(GetCVar("realmName")) ) then |
||
125 | SetPortraitTexture(BankItems_Portrait, "player"); |
||
126 | else |
||
127 | BankItems_Portrait:SetTexture("Interface\\QuestFrame\\UI-QuestLog-BookIcon"); |
||
128 | end |
||
129 | return BankItems_Save[playerName]; |
||
130 | end |
||
131 | |||
132 | function BankItems_SlashHandler(msg) |
||
133 | if ( msg and strlen(msg) > 0 ) then |
||
134 | msg = strlower(msg); |
||
135 | end |
||
136 | if ( not msg ) then |
||
137 | msg = ""; |
||
138 | end |
||
139 | if ( msg == "list" ) then |
||
140 | BankItems_ListAll(); |
||
141 | return; |
||
142 | end |
||
143 | if ( msg == "resetpos" ) then |
||
144 | BankItems_ResetPos(); |
||
145 | return; |
||
146 | end |
||
147 | if ( msg == "clear" ) then |
||
148 | local selected = BankItems_UserDropdown_GetValue(); |
||
149 | if ( BankItems_Save[selected] ) then |
||
150 | BankItems_Save[selected] = nil; |
||
151 | end |
||
152 | bankPlayer = BankItems_GetPlayer(UnitName("player").."|"..BankItems_Trim(GetCVar("realmName"))); |
||
153 | if ( BankFrame:IsVisible() ) then |
||
154 | BankItems_SaveItems(); |
||
155 | end |
||
156 | BankItems_SaveMoney(); |
||
157 | |||
158 | BankItems_Frame:Hide(); |
||
159 | end |
||
160 | if ( msg == "clearall" ) then |
||
161 | BankItems_Save = {}; |
||
162 | bankPlayer = BankItems_GetPlayer(UnitName("player").."|"..BankItems_Trim(GetCVar("realmName"))); |
||
163 | if ( BankFrame:IsVisible() ) then |
||
164 | BankItems_SaveItems(); |
||
165 | end |
||
166 | BankItems_SaveMoney(); |
||
167 | |||
168 | BankItems_Frame:Hide(); |
||
169 | end |
||
170 | if ( msg == "help" ) then |
||
171 | BankItems_Chat(BANKITEMS_VERSIONTEXT); |
||
172 | BankItems_Chat("Type /bi or /bankitems to open BankItems"); |
||
173 | BankItems_Chat("-- /bi all : open BankItems and all bags"); |
||
174 | BankItems_Chat("-- /bi list : list contents in chat"); |
||
175 | BankItems_Chat("-- /bi clear : clear currently selected player's info"); |
||
176 | BankItems_Chat("-- /bi clearall : clear all players' info"); |
||
177 | BankItems_Chat("-- /bi resetpos : reset BankItems and bags position"); |
||
178 | return; |
||
179 | end |
||
180 | if ( msg == "allrealms" ) then |
||
181 | if ( allRealms == 0 ) then |
||
182 | allRealms = 1; |
||
183 | else |
||
184 | allRealms = 0; |
||
185 | end |
||
186 | end |
||
187 | BankItems_PopulateFrame(); |
||
188 | |||
189 | if ( BankItems_Frame:IsVisible() ) then |
||
190 | BankItems_Frame:Hide(); |
||
191 | else |
||
192 | BankItems_Frame:Show(); |
||
193 | if ( msg == "all" ) then |
||
194 | allBags = 1; |
||
195 | for num = 1, 6 do |
||
196 | getglobal("BankItems_ContainerFrame"..num):Hide(); |
||
197 | BankItems_Bag_OnClick(num + 4); |
||
198 | end |
||
199 | else |
||
200 | allBags = 0; |
||
201 | end |
||
202 | end |
||
203 | end |
||
204 | |||
205 | function BankItems_ResetPos() |
||
206 | BankItems_Frame:ClearAllPoints(); |
||
207 | BankItems_Frame:SetPoint("TOPLEFT","UIParent","TOPLEFT",50,-104); |
||
208 | |||
209 | BankItems_ContainerFrame1:ClearAllPoints(); |
||
210 | BankItems_ContainerFrame1:SetPoint("TOPLEFT","BankItems_Frame","TOPRIGHT",0,-260); |
||
211 | |||
212 | BankItems_ContainerFrame2:ClearAllPoints(); |
||
213 | BankItems_ContainerFrame2:SetPoint("TOPLEFT","BankItems_Frame","TOPRIGHT",0,0); |
||
214 | |||
215 | BankItems_ContainerFrame3:ClearAllPoints(); |
||
216 | BankItems_ContainerFrame3:SetPoint("TOPLEFT","BankItems_Frame","TOPRIGHT",0,-520); |
||
217 | |||
218 | BankItems_ContainerFrame4:ClearAllPoints(); |
||
219 | BankItems_ContainerFrame4:SetPoint("TOPLEFT","BankItems_Frame","TOPRIGHT",256,0); |
||
220 | |||
221 | BankItems_ContainerFrame5:ClearAllPoints(); |
||
222 | BankItems_ContainerFrame5:SetPoint("TOPLEFT","BankItems_Frame","TOPRIGHT",256,-260); |
||
223 | |||
224 | BankItems_ContainerFrame6:ClearAllPoints(); |
||
225 | BankItems_ContainerFrame6:SetPoint("TOPLEFT","BankItems_Frame","TOPRIGHT",256,-520); |
||
226 | end |
||
227 | |||
228 | function BankItems_SaveMoney() |
||
229 | if ( UnitName("player") and BankItems_Trim(GetCVar("realmName")) ) then |
||
230 | if ( BankItems_Save[UnitName("player").."|"..BankItems_Trim(GetCVar("realmName"))] ) then |
||
231 | BankItems_Save[UnitName("player").."|"..BankItems_Trim(GetCVar("realmName"))]["money"] = GetMoney(); |
||
232 | end |
||
233 | if ( BankItems_MoneyFrame:IsVisible() ) then |
||
234 | MoneyFrame_Update("BankItems_MoneyFrame", bankPlayer.money); |
||
235 | end |
||
236 | end |
||
237 | end |
||
238 | |||
239 | function BankItems_UpdateTotalMoney() |
||
240 | BankItems_SaveMoney(); |
||
241 | local totalMula = 0; |
||
242 | |||
243 | if ( allRealms == 1 ) then |
||
244 | for key, value in BankItems_Save do |
||
245 | if ( BankItems_Save[key].money ) then |
||
246 | totalMula = totalMula + BankItems_Save[key].money; |
||
247 | end |
||
248 | end |
||
249 | else |
||
250 | for key, value in BankItems_Save do |
||
251 | local thisRealmPlayers = BankItems_Split(key, "|")[2]; |
||
252 | if ( thisRealmPlayers == BankItems_Trim(GetCVar("realmName")) and (table.getn(BankItems_Save[key]) > 0 or BankItems_Save[key].money) ) then |
||
253 | if ( BankItems_Save[key].money ) then |
||
254 | totalMula = totalMula + BankItems_Save[key].money; |
||
255 | end |
||
256 | end |
||
257 | end |
||
258 | end |
||
259 | MoneyFrame_Update("BankItems_MoneyFrameTotal", totalMula); |
||
260 | end |
||
261 | |||
262 | function BankItems_SaveItems() |
||
263 | local itemLink,icon,quantity,bagNum_Slots; |
||
264 | local currPlayer = BankItems_Save[UnitName("player").."|"..BankItems_Trim(GetCVar("realmName"))]; |
||
265 | if ( BankFrame:IsVisible() ) then |
||
266 | for num = 1, 24 do |
||
267 | itemLink = GetContainerItemLink(BANK_CONTAINER, num); |
||
268 | icon, quantity = GetContainerItemInfo(BANK_CONTAINER, num); |
||
269 | if ( itemLink ) then |
||
270 | currPlayer[num] = { |
||
271 | ["icon"] = icon, |
||
272 | ["count"] = quantity, |
||
273 | ["link"] = itemLink |
||
274 | }; |
||
275 | else |
||
276 | currPlayer[num] = nil; |
||
277 | end |
||
278 | end |
||
279 | for bagNum = 5, 10 do |
||
280 | bagNum_Slots = GetContainerNumSlots(bagNum); |
||
281 | bagNum_ID = BankButtonIDToInvSlotID(bagNum, 1); |
||
282 | itemLink = GetInventoryItemLink("player", bagNum_ID); |
||
283 | icon = GetInventoryItemTexture("player", bagNum_ID); |
||
284 | |||
285 | if ( icon ) then |
||
286 | currPlayer["Bag"..bagNum] = { |
||
287 | ["link"] = itemLink, |
||
288 | ["icon"] = icon, |
||
289 | ["size"] = bagNum_Slots |
||
290 | }; |
||
291 | else |
||
292 | currPlayer["Bag"..bagNum] = nil; |
||
293 | getglobal("BankItems_ContainerFrame"..(bagNum - 4)):Hide(); |
||
294 | break; |
||
295 | end |
||
296 | |||
297 | itemLink = nil; |
||
298 | |||
299 | for bagItem = 1, bagNum_Slots do |
||
300 | itemLink = GetContainerItemLink(bagNum, bagItem); |
||
301 | icon, quantity = GetContainerItemInfo(bagNum, bagItem); |
||
302 | if ( itemLink ) then |
||
303 | currPlayer["Bag"..bagNum][bagItem] = { |
||
304 | ["link"] = itemLink, |
||
305 | ["icon"] = icon, |
||
306 | ["count"] = quantity |
||
307 | }; |
||
308 | else |
||
309 | currPlayer["Bag"..bagNum][bagItem] = nil; |
||
310 | end |
||
311 | end |
||
312 | end |
||
313 | end |
||
314 | BankItems_SaveMoney(); |
||
315 | if ( BankItems_Frame:IsVisible() ) then |
||
316 | BankItems_PopulateFrame(); |
||
317 | end |
||
318 | currPlayer = nil; |
||
319 | end |
||
320 | |||
321 | function BankItems_ListAll() |
||
322 | local sellValue; |
||
323 | if ( bankPlayer ) then |
||
324 | for num = 1, 24 do |
||
325 | if ( bankPlayer[num] and bankPlayer[num].link ) then |
||
326 | if ( sellValues ) then |
||
327 | sellValue = BankItem_ParseMoney(SellValues[BankItems_ParseLink(bankPlayer[num].link)]); |
||
328 | elseif ( ItemLinks ) then |
||
329 | sellValue = BankItem_ParseMoney(ItemLinks[BankItems_ParseLink(bankPlayer[num].link)].p); |
||
330 | end |
||
331 | if ( sellValue ) then |
||
332 | BankItems_Chat("Item "..num..": "..bankPlayer[num].link.." x"..bankPlayer[num].count.." (Sells for "..sellValue.." each)"); |
||
333 | else |
||
334 | BankItems_Chat("Item "..num..": "..bankPlayer[num].link.." x"..bankPlayer[num].count); |
||
335 | end |
||
336 | end |
||
337 | end |
||
338 | for bagNum = 5, 10 do |
||
339 | if ( bankPlayer["Bag"..bagNum] and bankPlayer["Bag"..bagNum].size > 0 ) then |
||
340 | for bagItem = 1, bankPlayer["Bag"..bagNum].size do |
||
341 | if ( bankPlayer["Bag"..bagNum][bagItem] and bankPlayer["Bag"..bagNum][bagItem].link ) then |
||
342 | if ( sellValues ) then |
||
343 | sellValue = BankItem_ParseMoney(SellValues[BankItems_ParseLink(bankPlayer["Bag"..bagNum][bagItem].link)]); |
||
344 | elseif ( ItemLinks ) then |
||
345 | sellValue = BankItem_ParseMoney(ItemLinks[BankItems_ParseLink(bankPlayer["Bag"..bagNum][bagItem].link)].p); |
||
346 | end |
||
347 | if ( sellValue ) then |
||
348 | BankItems_Chat("Bag "..(bagNum - 4).." Item "..bagItem..": "..bankPlayer["Bag"..bagNum][bagItem].link.." x"..bankPlayer["Bag"..bagNum][bagItem].count.." (Sells for "..sellValue.." each)"); |
||
349 | else |
||
350 | BankItems_Chat("Bag "..(bagNum - 4).." Item "..bagItem..": "..bankPlayer["Bag"..bagNum][bagItem].link.." x"..bankPlayer["Bag"..bagNum][bagItem].count); |
||
351 | end |
||
352 | end |
||
353 | end |
||
354 | end |
||
355 | end |
||
356 | end |
||
357 | end |
||
358 | |||
359 | function BankItems_PopulateFrame() |
||
360 | local texture,button; |
||
361 | if ( bankPlayer ) then |
||
362 | for num = 1, 24 do |
||
363 | button = getglobal("BankItems_Item"..num); |
||
364 | texture = getglobal("BankItems_Item"..num.."IconTexture"); |
||
365 | if ( bankPlayer[num] ) then |
||
366 | texture:SetTexture(bankPlayer[num].icon); |
||
367 | SetItemButtonCount(button,bankPlayer[num].count); |
||
368 | else |
||
369 | texture:SetTexture(""); |
||
370 | SetItemButtonCount(getglobal("BankItems_Item"..num),nil); |
||
371 | end |
||
372 | end |
||
373 | for bagNum = 5, 10 do |
||
374 | button = getglobal("BankItems_Bag"..(bagNum - 4)); |
||
375 | texture = getglobal(button:GetName().."IconTexture"); |
||
376 | if ( bankPlayer["Bag"..bagNum] and bankPlayer["Bag"..bagNum].icon ) then |
||
377 | texture:SetTexture(bankPlayer["Bag"..bagNum].icon); |
||
378 | SetItemButtonTextureVertexColor(button, 1.0,1.0,1.0); |
||
379 | else |
||
380 | texture:SetTexture("Interface\\PaperDoll\\UI-PaperDoll-Slot-Bag"); |
||
381 | SetItemButtonTextureVertexColor(button, 1.0,0.1,0.1); |
||
382 | end |
||
383 | button:Show(); |
||
384 | end |
||
385 | if ( bankPlayer.money ) then |
||
386 | MoneyFrame_Update("BankItems_MoneyFrame", bankPlayer.money); |
||
387 | BankItems_MoneyFrame:Show(); |
||
388 | else |
||
389 | BankItems_MoneyFrame:Hide(); |
||
390 | end |
||
391 | end |
||
392 | BankItems_UpdateTotalMoney(); |
||
393 | end |
||
394 | |||
395 | function BankItems_Button_OnEnter() |
||
396 | if ( not bankPlayer[this:GetID()] ) then |
||
397 | return; |
||
398 | end |
||
399 | |||
400 | local myLink = bankPlayer[this:GetID()].link; |
||
401 | if ( myLink and strlen(myLink) > 0 ) then |
||
402 | GameTooltip:SetOwner(this,"ANCHOR_RIGHT"); |
||
403 | _,_,myLink = strfind(myLink,"|H(item:%d+:%d+:%d+:%d+)|"); |
||
404 | GameTooltip:SetHyperlink(myLink); |
||
405 | end |
||
406 | end |
||
407 | |||
408 | function BankItems_BagItem_OnEnter() |
||
409 | local bagID = "Bag"..this:GetParent():GetID(); |
||
410 | if ( not bankPlayer[bagID].link ) then |
||
411 | return; |
||
412 | end |
||
413 | local itemID = bankPlayer[bagID].size - ( this:GetID() - 1 ); |
||
414 | if ( bankPlayer[bagID][itemID] ) then |
||
415 | local myLink = bankPlayer[bagID][itemID].link; |
||
416 | if ( myLink and strlen(myLink) > 0 ) then |
||
417 | GameTooltip:SetOwner(this,"ANCHOR_RIGHT"); |
||
418 | _,_,myLink = strfind(myLink,"|H(item:%d+:%d+:%d+:%d+)|"); |
||
419 | GameTooltip:SetHyperlink(myLink); |
||
420 | end |
||
421 | end |
||
422 | end |
||
423 | |||
424 | function BankItems_Button_OnClick(arg1) |
||
425 | if ( bankPlayer[this:GetID()] ) then |
||
426 | if ( IsControlKeyDown() ) then |
||
427 | DressUpItemLink(bankPlayer[this:GetID()].link); |
||
428 | elseif ( arg1 == "LeftButton" and ChatFrameEditBox:IsVisible() ) then |
||
429 | ChatFrameEditBox:Insert(bankPlayer[this:GetID()].link); |
||
430 | end |
||
431 | end |
||
432 | end |
||
433 | |||
434 | function BankItems_BagItem_OnClick(arg1) |
||
435 | local bagID = "Bag"..this:GetParent():GetID(); |
||
436 | local itemID = bankPlayer[bagID].size - ( this:GetID() - 1 ); |
||
437 | if ( bankPlayer[bagID][itemID] ) then |
||
438 | if ( IsControlKeyDown() ) then |
||
439 | DressUpItemLink(bankPlayer[bagID][itemID].link); |
||
440 | elseif ( arg1 == "LeftButton" and ChatFrameEditBox:IsVisible() ) then |
||
441 | ChatFrameEditBox:Insert(bankPlayer[bagID][itemID].link); |
||
442 | end |
||
443 | end |
||
444 | end |
||
445 | |||
446 | function BankItems_Bag_OnEnter() |
||
447 | if ( bankPlayer["Bag"..this:GetID()] and bankPlayer["Bag"..this:GetID()].link ) then |
||
448 | local myLink = bankPlayer["Bag"..this:GetID()].link; |
||
449 | if ( myLink and strlen(myLink) > 0 ) then |
||
450 | GameTooltip:SetOwner(this,"ANCHOR_RIGHT"); |
||
451 | _,_,myLink = strfind(myLink,"|H(item:%d+:%d+:%d+:%d+)|"); |
||
452 | GameTooltip:SetHyperlink(myLink); |
||
453 | end |
||
454 | end |
||
455 | end |
||
456 | |||
457 | function BankItems_Bag_OnClick(bagID) |
||
458 | if ( not bankPlayer["Bag"..bagID] or not bankPlayer["Bag"..bagID].link ) then |
||
459 | return; |
||
460 | end |
||
461 | if ( bankPlayer["Bag"..bagID].size == 0 ) then |
||
462 | if ( GetContainerNumSlots(bagID) > 0 and BankFrame:IsVisible() ) then |
||
463 | BankItems_SaveItems(); |
||
464 | else |
||
465 | BankItems_Chat("Bank bag is empty, and not initialized."); |
||
466 | return; |
||
467 | end |
||
468 | end |
||
469 | local theBag = bankPlayer["Bag"..bagID]; |
||
470 | local bagFrame = getglobal("BankItems_ContainerFrame"..(bagID - 4)); |
||
471 | local bagName = bagFrame:GetName(); |
||
472 | |||
473 | if ( bagFrame:IsVisible() ) then |
||
474 | bagFrame:Hide(); |
||
475 | return; |
||
476 | end |
||
477 | |||
478 | getglobal(bagName.."Name"):SetText(BankItems_ParseLink(theBag.link)); |
||
479 | getglobal(bagName.."Portrait"):SetTexture(theBag.icon); |
||
480 | |||
481 | -- Generate the frame |
||
482 | local frameSettings = CONTAINER_FRAME_TABLE[theBag.size]; |
||
483 | local frameBG = getglobal(bagName.."BackgroundTexture"); |
||
484 | local columns = NUM_CONTAINER_COLUMNS; |
||
485 | local rows = ceil(theBag.size / columns); |
||
486 | local button,item,idx; |
||
487 | |||
488 | bagFrame:SetWidth(CONTAINER_WIDTH); |
||
489 | bagFrame:SetHeight(frameSettings[4]); |
||
490 | frameBG:SetTexture(frameSettings[1]); |
||
491 | frameBG:SetWidth(frameSettings[2]); |
||
492 | frameBG:SetHeight(frameSettings[3]); |
||
493 | |||
494 | for bagItem = 1, theBag.size do |
||
495 | idx = theBag.size - (bagItem - 1); |
||
496 | item = theBag[idx]; |
||
497 | button = getglobal(bagName.."Item"..bagItem); |
||
498 | |||
499 | if ( bagItem == 1 ) then |
||
500 | button:SetPoint("BOTTOMRIGHT", bagName, "BOTTOMRIGHT", -11, 9); |
||
501 | else |
||
502 | if ( mod((bagItem-1), columns) == 0 ) then |
||
503 | button:SetPoint("BOTTOMRIGHT", bagName.."Item"..(bagItem - columns), "TOPRIGHT", 0, 4); |
||
504 | else |
||
505 | button:SetPoint("BOTTOMRIGHT", bagName.."Item"..(bagItem - 1), "BOTTOMLEFT", -5, 0); |
||
506 | end |
||
507 | end |
||
508 | button:Show(); |
||
509 | end |
||
510 | for bagItem = theBag.size + 1, 20 do |
||
511 | getglobal(bagName.."Item"..bagItem):Hide(); |
||
512 | end |
||
513 | BankItems_PopulateBag(bagID); |
||
514 | bagFrame:Show(); |
||
515 | PlaySound("igBackPackOpen"); |
||
516 | end |
||
517 | |||
518 | function BankItems_PopulateBag(bagID) |
||
519 | local item,theBag,idx; |
||
520 | if ( bankPlayer["Bag"..bagID].size ) then |
||
521 | theBag = bankPlayer["Bag"..bagID]; |
||
522 | for bagItem = 1, theBag.size do |
||
523 | idx = theBag.size - (bagItem - 1); |
||
524 | item = theBag[idx]; |
||
525 | button = getglobal("BankItems_ContainerFrame"..(bagID - 4).."Item"..bagItem); |
||
526 | |||
527 | if ( item ) then |
||
528 | SetItemButtonTexture(button, item.icon); |
||
529 | SetItemButtonCount(button, item.count); |
||
530 | else |
||
531 | SetItemButtonTexture(button,""); |
||
532 | SetItemButtonCount(button, nil); |
||
533 | end |
||
534 | end |
||
535 | end |
||
536 | end |
||
537 | |||
538 | function BankItems_Bag_OnShow() |
||
539 | getglobal("BankItems_Bag"..(this:GetID() - 4).."HighlightFrameTexture"):Show(); |
||
540 | end |
||
541 | |||
542 | function BankItems_Bag_OnHide() |
||
543 | getglobal("BankItems_Bag"..(this:GetID() - 4).."HighlightFrameTexture"):Hide(); |
||
544 | end |
||
545 | |||
546 | function BankItems_ParseLink(link) |
||
547 | if (string.find(link, "[", 1, true)) then |
||
548 | local _,_,name = string.find(link, "^.*%[(.*)%].*$"); |
||
549 | return name; |
||
550 | else |
||
551 | return link; |
||
552 | end |
||
553 | end |
||
554 | |||
555 | function BankItems_Chat(msg) |
||
556 | if( DEFAULT_CHAT_FRAME ) then |
||
557 | DEFAULT_CHAT_FRAME:AddMessage("<BankItems> "..msg, 1.0, 1.0, 0.0); |
||
558 | end |
||
559 | end |
||
560 | |||
561 | function BankItem_ParseMoney(money) |
||
562 | local disp = ""; |
||
563 | if ( money ) then |
||
564 | local g,s,c; |
||
565 | g = math.floor(money / 10000); |
||
566 | money = math.mod(money,10000); |
||
567 | s = math.floor(money / 100); |
||
568 | money = math.mod(money,100); |
||
569 | c = math.mod(money, 100); |
||
570 | if ( g and g > 0 ) then |
||
571 | disp = g.."g "; |
||
572 | end |
||
573 | if ( s and s > 0 ) then |
||
574 | disp = disp..s.."s "; |
||
575 | end |
||
576 | if ( c and c > 0) then |
||
577 | disp = disp..c.."c"; |
||
578 | end |
||
579 | if ( strlen(disp) > 0 ) then |
||
580 | return disp; |
||
581 | else |
||
582 | return nil; |
||
583 | end |
||
584 | else |
||
585 | return nil; |
||
586 | end |
||
587 | end |
||
588 | |||
589 | function BankItems_UserDropdown_GetValue() |
||
590 | if ( bankPlayerName ) then |
||
591 | return bankPlayerName; |
||
592 | else |
||
593 | return (UnitName("player").."|"..BankItems_Trim(GetCVar("realmName"))); |
||
594 | end |
||
595 | end |
||
596 | |||
597 | function BankItems_UserDropdown_OnLoad() |
||
598 | UIDropDownMenu_Initialize(this, BankItems_UserDropdown_Initialize); |
||
599 | UIDropDownMenu_SetSelectedValue(this, BankItems_UserDropdown_GetValue()); |
||
600 | BankItems_UserDropdown.tooltip = "You are viewing this player's bank contents."; |
||
601 | UIDropDownMenu_SetWidth(140, BankItems_UserDropdown); |
||
602 | OptionsFrame_EnableDropDown(BankItems_UserDropdown); |
||
603 | end |
||
604 | |||
605 | function BankItems_UserDropdown_OnClick() |
||
606 | if ( not bankPlayer ) then |
||
607 | return; |
||
608 | end |
||
609 | UIDropDownMenu_SetSelectedValue(BankItems_UserDropdown, this.value); |
||
610 | if ( this.value ) then |
||
611 | bankPlayer = BankItems_GetPlayer(this.value); |
||
612 | end |
||
613 | BankItems_Frame_OnHide(); |
||
614 | BankItems_PopulateFrame(); |
||
615 | |||
616 | if ( allBags == 1 ) then |
||
617 | for num = 1, 6 do |
||
618 | getglobal("BankItems_ContainerFrame"..num):Hide(); |
||
619 | BankItems_Bag_OnClick(num + 4); |
||
620 | end |
||
621 | end |
||
622 | end |
||
623 | |||
624 | function BankItems_UserDropdown_Initialize() |
||
625 | local selectedValue = UIDropDownMenu_GetSelectedValue(BankItems_UserDropdown); |
||
626 | local info; |
||
627 | |||
628 | if ( allRealms == 1 ) then |
||
629 | for key, value in BankItems_Save do |
||
630 | if ( table.getn(BankItems_Save[key]) > 0 or BankItems_Save[key].money ) then |
||
631 | info = {}; |
||
632 | info.text = BankItems_Split(key,"|")[1].." of "..BankItems_Split(key,"|")[2]; |
||
633 | info.value = key; |
||
634 | info.func = BankItems_UserDropdown_OnClick; |
||
635 | if ( selectedValue == info.value ) then |
||
636 | info.checked = 1; |
||
637 | else |
||
638 | info.checked = nil; |
||
639 | end |
||
640 | UIDropDownMenu_AddButton(info); |
||
641 | end |
||
642 | end |
||
643 | else |
||
644 | for key, value in BankItems_Save do |
||
645 | local thisRealmPlayers = BankItems_Split(key, "|")[2]; |
||
646 | if ( thisRealmPlayers == BankItems_Trim(GetCVar("realmName")) and (table.getn(BankItems_Save[key]) > 0 or BankItems_Save[key].money) ) then |
||
647 | info = {}; |
||
648 | info.text = BankItems_Split(key,"|")[1].." of "..BankItems_Split(key,"|")[2]; |
||
649 | info.value = key; |
||
650 | info.func = BankItems_UserDropdown_OnClick; |
||
651 | if ( selectedValue == info.value ) then |
||
652 | info.checked = 1; |
||
653 | else |
||
654 | info.checked = nil; |
||
655 | end |
||
656 | UIDropDownMenu_AddButton(info); |
||
657 | end |
||
658 | end |
||
659 | end |
||
660 | end |
||
661 | |||
662 | function BankItems_Split(toCut, separator) |
||
663 | local splitted = {}; |
||
664 | local i = 0; |
||
665 | local regEx = "([^" .. separator .. "]*)" .. separator .. "?"; |
||
666 | |||
667 | for item in string.gfind(toCut .. separator, regEx) do |
||
668 | i = i + 1; |
||
669 | splitted[i] = BankItems_Trim(item) or ''; |
||
670 | end |
||
671 | if ( splitted[i] == '' ) then |
||
672 | splitted[i] = nil; |
||
673 | end |
||
674 | return splitted; |
||
675 | end |
||
676 | |||
677 | function BankItems_Trim (s) |
||
678 | return (string.gsub(s, "^%s*(.-)%s*$", "%1")); |
||
679 | end |
||
680 | |||
681 | function BankItems_ShowAllRealms_CheckOnClick() |
||
682 | if ( BankItems_Frame:IsVisible() ) then |
||
683 | BankItems_Frame:Hide(); |
||
684 | end |
||
685 | BankItems_SlashHandler("allrealms"); |
||
686 | end |
||
687 | |||
688 | function BankItems_ShowAllRealms_CheckOnLoad() |
||
689 | if ( allRealms == 1 ) then |
||
690 | this.checked = 1; |
||
691 | else |
||
692 | this.checked = nil; |
||
693 | end |
||
694 | OptionsFrame_EnableCheckBox(this); |
||
695 | this:SetChecked(this.checked); |
||
696 | getglobal(this:GetName().."Text"):SetText("Show All Realms"); |
||
697 | this.tooltipText = "Check to show all saved characters, regardless of realm."; |
||
698 | end |