vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 All In One Inventory
3  
4 By sarf
5  
6 This mod allows you to view and interact with your inventory without caring about bags.
7  
8 Thanks goes to SirBender for the background conversion and other stuff! :)
9  
10 Thanks to amoeba for the ultra-nice Lock Button! Even if they lacked transparency. :)
11  
12 CosmosUI URL:
13 http://www.cosmosui.org/forums/viewtopic.php?t=
14  
15 ]]
16  
17  
18 -- Constants
19 ALLINONEINVENTORY_MAX_ID = 109;
20 ALLINONEINVENTORY_WIDTH = 350;
21  
22 ALLINONEINVENTORY_NUM_COLUMNS = 8;
23 ALLINONEINVENTORY_COLUMNS_MIN = 2;
24 ALLINONEINVENTORY_COLUMNS_MAX = 16;
25 ALLINONEINVENTORY_BASE_HEIGHT = 64;
26 ALLINONEINVENTORY_ROW_HEIGHT = 40;
27  
28 ALLINONEINVENTORY_BASE_WIDTH = 26;
29 ALLINONEINVENTORY_COL_WIDTH = 40;
30  
31 ALLINONEINVENTORY_ALPHA_MIN = 0;
32 ALLINONEINVENTORY_ALPHA_MAX = 1;
33  
34 ALLINONEINVENTORY_SCALE_MIN = 0;
35 ALLINONEINVENTORY_SCALE_MAX = 2;
36  
37 ALLINONEINVENTORY_SCHEDULENAME_UPDATE = "AllInOneInventory_UpdateBags";
38 ALLINONEINVENTORY_MAXIMUM_NUMBER_OF_BUTTONS = 109;
39 ALLINONEINVENTORY_MINIMUM_TIME_BETWEEN_UPDATES = 0.2;
40  
41 -- Variables
42 AllInOneInventory_Enabled = 0;
43 AllInOneInventory_ReplaceBags = 0;
44 AllInOneInventory_IncludeShotBags = 1;
45 AllInOneInventory_ShowPrice = 1;
46 AllInOneInventory_Locked = 0;
47 AllInOneInventory_SwapBagOrder = 0;
48 AllInOneInventory_Alpha = 1;
49 AllInOneInventory_Scale = 1;
50  
51 AllInOneInventory_ExcludeSlots = {};
52  
53  
54 AllInOneInventory_IncludeBagZero = 1;
55 AllInOneInventory_IncludeBagOne = 1;
56 AllInOneInventory_IncludeBagTwo = 1;
57 AllInOneInventory_IncludeBagThree = 1;
58 AllInOneInventory_IncludeBagFour = 1;
59  
60 AllInOneInventory_ModifyTooltipsAtMerchant = 1;
61  
62 AllInOneInventory_BagStringIndex = {
63 [0] = "Zero",
64 [1] = "One",
65 [2] = "Two",
66 [3] = "Three",
67 [4] = "Four",
68 };
69  
70 AllInOneInventory_BagsToInclude = {
71 [0] = "AllInOneInventory_IncludeBagZero",
72 [1] = "AllInOneInventory_IncludeBagOne",
73 [2] = "AllInOneInventory_IncludeBagTwo",
74 [3] = "AllInOneInventory_IncludeBagThree",
75 [4] = "AllInOneInventory_IncludeBagFour",
76 };
77  
78  
79 AllInOneInventory_Columns = ALLINONEINVENTORY_NUM_COLUMNS;
80  
81 AllInOneInventory_Patching_Tooltip = 0;
82  
83 AllInOneInventory_Saved_SellValue_OnShow = nil;
84 AllInOneInventory_Saved_UseContainerItem = nil;
85 AllInOneInventory_Saved_ToggleBag = nil;
86 AllInOneInventory_Saved_OpenBag = nil;
87 AllInOneInventory_Saved_CloseBag = nil;
88 AllInOneInventory_Saved_ToggleBackpack = nil;
89 AllInOneInventory_Saved_CloseBackpack = nil;
90 AllInOneInventory_Saved_OpenBackpack = nil;
91 AllInOneInventory_Saved_BagSlotButton_OnClick = nil;
92 AllInOneInventory_Saved_BagSlotButton_OnDrag = nil;
93 AllInOneInventory_Saved_BackpackButton_OnClick = nil;
94 AllInOneInventory_Saved_CloseAllWindows = nil;
95 AllInOneInventory_Saved_OpenAllBags = nil;
96 AllInOneInventory_Saved_DepositBox_RefreshWindows = nil;
97  
98 function AIOI_Schedule_Own(time, func, p1, p2, p3, p4, p5, p6, p7, p8, p9)
99 func(p1, p2, p3, p4, p5, p6, p7, p8, p9);
100 end
101  
102 function AIOI_ScheduleByName_Own(name, time, func, p1, p2, p3, p4, p5, p6, p7, p8, p9)
103 func(p1, p2, p3, p4, p5, p6, p7, p8, p9);
104 end
105  
106 -- executed on load, calls general set-up functions
107 function AllInOneInventoryScriptFrame_OnLoad()
108 local func = AIOI_ScheduleByName_Own;
109 if ( Chronos ) and ( Chronos.scheduleByName ) then
110 func = Chronos.scheduleByName;
111 elseif ( Cosmos_ScheduleByName ) then
112 func = Cosmos_ScheduleByName;
113 end
114 setglobal("AIOI_ScheduleByName", func);
115 func = AIOI_Schedule_Own;
116 if ( Chronos ) and ( Chronos.schedule ) then
117 func = Chronos.schedule;
118 elseif ( Cosmos_Schedule ) then
119 func = Cosmos_Schedule;
120 end
121 setglobal("AIOI_Schedule", func);
122  
123 AllInOneInventory_Register();
124 AllInOneInventory_Setup_Hooks(1);
125 --DynamicData.item.addOnInventoryUpdateHandler(AllInOneInventoryFrame_OnInventoryUpdate);
126 end
127  
128 function AllInOneInventory_Register_SlashCommands()
129 SlashCmdList["ALLINONEINVENTORYSLASHMAIN"] = AllInOneInventory_Main_ChatCommandHandler;
130 SLASH_ALLINONEINVENTORYSLASHMAIN1 = "/allinoneinventory";
131 SLASH_ALLINONEINVENTORYSLASHMAIN2 = "/aioi";
132 end
133  
134 -- registers the mod with the system, integrating it with slash commands and "master" AddOns
135 function AllInOneInventory_Register()
136 this:RegisterEvent("PLAYER_LOGIN");
137 this:RegisterEvent("ADDON_LOADED");
138 AllInOneInventory_Register_SlashCommands()
139 end
140  
141 function AllInOneInventory_Extract_NextParameter(msg)
142 local params = msg;
143 local command = params;
144 local index = strfind(command, " ");
145 if ( index ) then
146 command = strsub(command, 1, index-1);
147 params = strsub(params, index+1);
148 else
149 params = "";
150 end
151 return command, params;
152 end
153  
154 function AllInOneInventory_GetItemInfo(id)
155 local bag, slot = AllInOneInventory_GetIdAsBagSlot(id);
156 return GetContainerItemInfo(bag, slot);
157 end
158  
159 function AllInOneInventory_GetNumberOfSlotsInBag(bag)
160 local slots = 0;
161 if ( AllInOneInventory_ShouldIncludeBag(bag) ) then
162 slots = GetContainerNumSlots(bag);
163 if ( AllInOneInventory_ExcludeSlots ) and ( AllInOneInventory_ExcludeSlots[bag] ) then
164 local n = 0;
165 for k, v in AllInOneInventory_ExcludeSlots[bag] do
166 n = n + 1;
167 end
168 slots = slots - n;
169 end
170 end
171 return slots;
172 end
173  
174 AllInOneInventory_GetBags_Table = {};
175  
176 function AllInOneInventory_GetBags()
177 local bag = 0;
178 local bags = AllInOneInventory_GetBags_Table;
179 for bag = 0, 4 do
180 bags[bag] = AllInOneInventory_GetNumberOfSlotsInBag(bag);
181 end
182 return bags;
183 end
184  
185 function AllInOneInventory_GetBagsTotalSlots()
186 local bags = AllInOneInventory_GetBags();
187 local slots = 0;
188 for k, v in bags do
189 slots = slots + v;
190 end
191 return slots;
192 end
193  
194 function AllInOneInventory_GetIdAsBagSlot(id)
195 if ( not id ) then
196 --return 0, 1;
197 return nil, nil;
198 end
199 local bagSlots = AllInOneInventory_GetBags();
200 local leftId = id;
201 local curSlots = 0;
202 local bag, slots;
203 local ok = true;
204 local bag = 0;
205 if ( AllInOneInventory_SwapBagOrder == 1 ) then
206 bag = 4;
207 end
208 while ( ok ) do
209 curSlots = bagSlots[bag];
210 if ( not curSlots ) then
211 curSlots = 0;
212 end
213 if ( leftId - curSlots <= 0 ) then
214 if ( AllInOneInventory_ExcludeSlots[bag] ) then
215 for i = 1, leftId do
216 if ( AllInOneInventory_ExcludeSlots[bag][i] ) then
217 leftId = leftId + 1;
218 end
219 end
220 end
221 return bag, leftId;
222 else
223 leftId = leftId - curSlots;
224 end
225 if ( AllInOneInventory_SwapBagOrder == 1 ) then
226 bag = bag - 1;
227 if ( bag < 0 ) then
228 ok = false;
229 end
230 else
231 bag = bag + 1;
232 if ( bag > 4 ) then
233 ok = false;
234 end
235 end
236 end
237 return -1, -1;
238 end
239  
240 function AllInOneInventory_CommandUsage()
241 for k, v in ALLINONEINVENTORY_CHAT_COMMAND_USAGE do
242 AllInOneInventory_Print(v);
243 end
244 end
245  
246 -- Handles chat - e.g. slashcommands - enabling/disabling the AllInOneInventory
247 function AllInOneInventory_Main_ChatCommandHandler(msg)
248  
249 local func = AllInOneInventory_Toggle_Enabled;
250  
251 local toggleFunc = true;
252  
253 if ( ( not msg) or ( strlen(msg) <= 0 ) ) then
254 AllInOneInventory_CommandUsage();
255 return;
256 end
257  
258 local commandName, params = AllInOneInventory_Extract_NextParameter(msg);
259  
260 if ( ( commandName ) and ( strlen(commandName) > 0 ) ) then
261 commandName = string.lower(commandName);
262 else
263 commandName = "";
264 end
265  
266 if ( strfind( commandName, "state" ) ) then
267 func = AllInOneInventory_Toggle_Enabled;
268 elseif ( ( ( strfind( commandName, "togglebag" ) ) ) ) then
269 local bagNumber;
270 bagNumber, params = AllInOneInventory_Extract_NextParameter(params);
271 func = nil;
272 bagNumber = tonumber(bagNumber);
273 if ( bagNumber ) then
274 local str = AllInOneInventory_BagStringIndex[bagNumber];
275 if ( str ) then
276 func = getglobal(format("AllInOneInventory_Toggle_IncludeBag%s", str));
277 end
278 end
279 if ( func ) then
280 func(-1);
281 else
282 AllInOneInventory_Print(ALLINFOURINVENTORY_CHAT_NO_SUCH_BAGNUMBER);
283 end
284 return;
285 elseif ( ( ( strfind( commandName, "toggleslot" ) ) ) ) then
286 local bagNumber;
287 local slotNumber;
288 bagNumber, params = AllInOneInventory_Extract_NextParameter(params);
289 slotNumber, params = AllInOneInventory_Extract_NextParameter(params);
290 return AllInOneInventory_Toggle_ExcludedSlot(bagNumber, slotNumber);
291 elseif ( ( strfind( commandName, "swap" ) ) or ( ( strfind( commandName, "order" ) ) ) ) then
292 func = AllInOneInventory_Toggle_SwapBagOrder;
293 toggleFunc = false;
294 elseif ( ( ( strfind( commandName, "toggle" ) ) ) ) then
295 func = ToggleAllInOneInventoryFrame;
296 toggleFunc = false;
297 elseif ( ( strfind( commandName, "show" ) ) ) then
298 func = OpenAllInOneInventoryFrame;
299 toggleFunc = false;
300 elseif ( ( strfind( commandName, "hide" ) ) ) then
301 func = CloseAllInOneInventoryFrame;
302 toggleFunc = false;
303 elseif ( ( strfind( commandName, "replacebag" ) ) or ( ( strfind( commandName, "hijackbag" ) ) ) ) then
304 func = AllInOneInventory_Toggle_ReplaceBags;
305 elseif ( strfind( commandName, "include" ) ) then
306 func = AllInOneInventory_Toggle_IncludeShotBags;
307 elseif ( strfind( commandName, "reset" ) ) then
308 func = AllInOneInventoryFrame_ResetButton;
309 func();
310 AllInOneInventory_Print(TEXT(ALLINONEINVENTORY_CHAT_RESETPOSITION));
311 return;
312 elseif ( ( strfind( commandName, "setcols" ) ) or ( ( strfind( commandName, "cols" ) ) ) or ( ( strfind( commandName, "column" ) ) ) ) then
313 func = AllInOneInventory_Change_Columns;
314 toggleFunc = false;
315 local cols = 0;
316 cols, params = AllInOneInventory_Extract_NextParameter(params);
317 cols = tonumber(cols);
318 if ( not cols ) then
319 AllInOneInventory_CommandUsage();
320 return;
321 else
322 return func(1, cols);
323 end
324 elseif ( strfind( commandName, "alpha" ) ) then
325 func = AllInOneInventory_Change_Alpha;
326 toggleFunc = false;
327 local cols = 0;
328 cols, params = AllInOneInventory_Extract_NextParameter(params);
329 cols = tonumber(cols);
330 if ( not cols ) then
331 AllInOneInventory_CommandUsage();
332 return;
333 else
334 return func(1, cols);
335 end
336 elseif ( strfind( commandName, "scale" ) ) or ( strfind( commandName, "size" ) ) then
337 func = AllInOneInventory_Change_Scale;
338 toggleFunc = false;
339 local cols = 0;
340 cols, params = AllInOneInventory_Extract_NextParameter(params);
341 cols = tonumber(cols);
342 if ( not cols ) then
343 AllInOneInventory_CommandUsage();
344 return;
345 else
346 return func(1, cols);
347 end
348 else
349 AllInOneInventory_CommandUsage();
350 return;
351 end
352  
353 if ( toggleFunc ) then
354 -- Toggle appropriately
355 if ( (string.find(params, 'on')) or ((string.find(params, '1')) and (not string.find(params, '-1')) ) ) then
356 func(1);
357 else
358 if ( (string.find(params, 'off')) or (string.find(params, '0')) ) then
359 func(0);
360 else
361 func(-1);
362 end
363 end
364 else
365 func();
366 end
367 end
368  
369 function UseAllInOneInventoryItem(id)
370 local b,s = AllInOneInventory_GetIdAsBagSlot(id);
371 if ( ( b > -1 ) and ( s > -1 ) ) then
372 return AllInOneInventory_Saved_UseContainerItem(b, s);
373 end
374 return false;
375 end
376  
377 -- Does things with the hooked function
378 function AllInOneInventory_UseContainerItem(bag, slot)
379 if ( not slot ) then
380 local b,s = AllInOneInventory_GetIdAsBagSlot(bag);
381 if ( ( b > -1 ) and ( s > -1 ) ) then
382 return AllInOneInventory_Saved_UseContainerItem(b, s);
383 end
384 end
385 return AllInOneInventory_Saved_UseContainerItem(bag, slot);
386 end
387  
388 AllInOneInventory_ContainerFrames = {
389 [1] = "ContainerFrame1",
390 [2] = "ContainerFrame2",
391 [3] = "ContainerFrame3",
392 [4] = "ContainerFrame4",
393 [5] = "ContainerFrame5",
394 [6] = "ContainerFrame6",
395 [7] = "ContainerFrame7",
396 [8] = "ContainerFrame8",
397 [9] = "ContainerFrame9",
398 [10] = "ContainerFrame10",
399 [11] = "ContainerFrame11",
400 };
401  
402 function AllInOneInventory_ToggleBackpack()
403 if ( AllInOneInventory_ReplaceBags == 1 ) then
404 if ( AllInOneInventoryFrame:IsVisible() ) then
405 local frame = nil;
406 local frameName = nil;
407 for i=1, NUM_CONTAINER_FRAMES, 1 do
408 frameName = AllInOneInventory_ContainerFrames[i];
409 if ( not frameName ) then frameName = "ContainerFrame"..i; end
410 frame = getglobal(frameName);
411 if ( frame:IsVisible() ) then
412 frame:Hide();
413 end
414 end
415 CloseAllInOneInventoryFrame();
416 else
417 OpenAllInOneInventoryFrame();
418 end
419 else
420 AllInOneInventory_Saved_ToggleBackpack()
421 end
422 AllInOneInventory_UpdateBagState();
423 end
424  
425 function AllInOneInventory_BagSlotButton_OnClick()
426 AllInOneInventory_Saved_BagSlotButton_OnClick()
427 AllInOneInventory_UpdateBagState();
428 end
429  
430 function AllInOneInventory_BagSlotButton_OnDrag()
431 AllInOneInventory_Saved_BagSlotButton_OnDrag()
432 AllInOneInventory_UpdateBagState();
433 end
434  
435 function AllInOneInventory_BackpackButton_OnClick()
436 AllInOneInventory_Saved_BackpackButton_OnClick()
437 AllInOneInventory_UpdateBagState();
438 end
439  
440 function AllInOneInventory_OpenBackpack()
441 if ( AllInOneInventory_ReplaceBags == 1 ) then
442 OpenAllInOneInventoryFrame();
443 return;
444 end
445 AllInOneInventory_Saved_OpenBackpack();
446 AllInOneInventory_UpdateBagState();
447 end
448  
449 function AllInOneInventory_CloseBackpack()
450 if ( AllInOneInventory_ReplaceBags == 1 ) then
451 CloseAllInOneInventoryFrame();
452 return;
453 end
454 AllInOneInventory_Saved_CloseBackpack();
455 AllInOneInventory_UpdateBagState();
456 end
457  
458 function AllInOneInventory_IsShotBag(bag)
459 if ( bag < 0 ) or ( bag > 4 ) then
460 return false;
461 end
462 local name = "MainMenuBarBackpackButton";
463 if ( bag > 0 ) then
464 name = "CharacterBag"..(bag-1).."Slot";
465 end
466 local objCount = getglobal(name.."Count");
467 if ( objCount ) and ( objCount:IsVisible() ) then
468 local tmp = objCount:GetText();
469 if ( ( tmp ) and ( strlen(tmp) > 0) ) then
470 return true;
471 end
472 end
473 return false;
474 end
475  
476 function AllInOneInventory_ShouldIncludeBag(bag)
477 if ( ( bag >= 0 ) and ( bag <= 4 ) ) then
478 if ( getglobal(AllInOneInventory_BagsToInclude[bag]) ~= 1 ) then
479 return false;
480 end
481 if ( ( AllInOneInventory_IncludeShotBags == 1 ) or ( not AllInOneInventory_IsShotBag(bag) ) ) then
482 return true;
483 else
484 return false;
485 end
486 return true;
487 end
488 return false;
489 end
490  
491  
492 function AllInOneInventory_ShouldOverrideBag(bag)
493 if ( AllInOneInventory_ReplaceBags == 1 ) then
494 if ( AllInOneInventory_ShouldIncludeBag(bag) ) then
495 return true;
496 else
497 return false;
498 end
499 else
500 return false;
501 end
502 end
503  
504 function AllInOneInventory_ToggleBag(bag)
505 if ( AllInOneInventory_ShouldOverrideBag(bag) ) then
506 ToggleAllInOneInventoryFrame();
507 return;
508 else
509 AllInOneInventory_Saved_ToggleBag(bag);
510 AllInOneInventory_UpdateBagState();
511 end
512 end
513  
514 function AllInOneInventory_CloseBag(bag)
515 if ( AllInOneInventory_ShouldOverrideBag(bag) ) then
516 return;
517 else
518 AllInOneInventory_Saved_CloseBag(bag);
519 AllInOneInventory_UpdateBagState();
520 end
521 end
522  
523 function AllInOneInventory_OpenBag(bag)
524 if ( AllInOneInventory_ShouldOverrideBag(bag) ) then
525 return;
526 else
527 AllInOneInventory_Saved_OpenBag(bag)
528 AllInOneInventory_UpdateBagState();
529 end
530 end
531  
532 -- Hooks/unhooks functions. If toggle is 1, hooks functions, otherwise it unhooks functions.
533 -- Hooking functions mean that you replace them with your own functions and then call the
534 -- original function at your leisure.
535 function AllInOneInventory_Setup_Hooks(toggle)
536 if ( toggle == 1 ) then
537 if ( DepositBox_RefreshWindows ) and ( AllInOneInventory_Saved_DepositBox_RefreshWindows ~= DepositBox_RefreshWindows ) and ( AllInOneInventory_Saved_DepositBox_RefreshWindows == nil ) then
538 AllInOneInventory_Saved_DepositBox_RefreshWindows = DepositBox_RefreshWindows;
539 DepositBox_RefreshWindows = AllInOneInventory_DepositBox_RefreshWindows;
540 end
541 if ( SellValue_OnShow ) and ( SellValue_OnShow ~= AllInOneInventory_SellValue_OnShow ) and (AllInOneInventory_Saved_SellValue_OnShow == nil) then
542 AllInOneInventory_Saved_SellValue_OnShow = SellValue_OnShow;
543 SellValue_OnShow = AllInOneInventory_SellValue_OnShow;
544 end
545 if ( ( UseContainerItem ~= AllInOneInventory_UseContainerItem ) and (AllInOneInventory_Saved_UseContainerItem == nil) ) then
546 AllInOneInventory_Saved_UseContainerItem = UseContainerItem;
547 UseContainerItem = AllInOneInventory_UseContainerItem;
548 end
549 if ( ( ToggleBag ~= AllInOneInventory_ToggleBag ) and (AllInOneInventory_Saved_ToggleBag == nil) ) then
550 AllInOneInventory_Saved_ToggleBag = ToggleBag;
551 ToggleBag = AllInOneInventory_ToggleBag;
552 end
553 if ( ( CloseBag ~= AllInOneInventory_CloseBag ) and (AllInOneInventory_Saved_CloseBag == nil) ) then
554 AllInOneInventory_Saved_CloseBag = CloseBag;
555 CloseBag = AllInOneInventory_CloseBag;
556 end
557 if ( ( OpenBag ~= AllInOneInventory_OpenBag ) and (AllInOneInventory_Saved_OpenBag == nil) ) then
558 AllInOneInventory_Saved_OpenBag = OpenBag;
559 OpenBag = AllInOneInventory_OpenBag;
560 end
561 if ( ( ToggleBackpack ~= AllInOneInventory_ToggleBackpack ) and (AllInOneInventory_Saved_ToggleBackpack == nil) ) then
562 AllInOneInventory_Saved_ToggleBackpack = ToggleBackpack;
563 ToggleBackpack = AllInOneInventory_ToggleBackpack;
564 end
565 if ( ( CloseBackpack ~= AllInOneInventory_CloseBackpack ) and (AllInOneInventory_Saved_CloseBackpack == nil) ) then
566 AllInOneInventory_Saved_CloseBackpack = CloseBackpack;
567 CloseBackpack = AllInOneInventory_CloseBackpack;
568 end
569 if ( ( OpenBackpack ~= AllInOneInventory_OpenBackpack ) and (AllInOneInventory_Saved_OpenBackpack == nil) ) then
570 AllInOneInventory_Saved_OpenBackpack = OpenBackpack;
571 OpenBackpack = AllInOneInventory_OpenBackpack;
572 end
573 if ( ( BagSlotButton_OnClick ~= AllInOneInventory_BagSlotButton_OnClick ) and (AllInOneInventory_Saved_BagSlotButton_OnClick == nil) ) then
574 AllInOneInventory_Saved_BagSlotButton_OnClick = BagSlotButton_OnClick;
575 BagSlotButton_OnClick = AllInOneInventory_BagSlotButton_OnClick;
576 end
577 if ( ( BagSlotButton_OnDrag ~= AllInOneInventory_BagSlotButton_OnDrag ) and (AllInOneInventory_Saved_BagSlotButton_OnDrag == nil) ) then
578 AllInOneInventory_Saved_BagSlotButton_OnDrag = BagSlotButton_OnDrag;
579 BagSlotButton_OnDrag = AllInOneInventory_BagSlotButton_OnDrag;
580 end
581 if ( ( BackpackButton_OnClick ~= AllInOneInventory_BackpackButton_OnClick ) and (AllInOneInventory_Saved_BackpackButton_OnClick == nil) ) then
582 AllInOneInventory_Saved_BackpackButton_OnClick = BackpackButton_OnClick;
583 BackpackButton_OnClick = AllInOneInventory_BackpackButton_OnClick;
584 end
585 if ( ( CloseAllWindows ~= AllInOneInventory_CloseAllWindows ) and (AllInOneInventory_Saved_CloseAllWindows == nil) ) then
586 AllInOneInventory_Saved_CloseAllWindows = CloseAllWindows;
587 CloseAllWindows = AllInOneInventory_CloseAllWindows;
588 end
589 if ( ( OpenAllBags ~= AllInOneInventory_OpenAllBags ) and (AllInOneInventory_Saved_OpenAllBags == nil) ) then
590 AllInOneInventory_Saved_OpenAllBags = OpenAllBags;
591 OpenAllBags = AllInOneInventory_OpenAllBags;
592 end
593 else
594 if ( DepositBox_RefreshWindows == AllInOneInventory_Saved_DepositBox_RefreshWindows ) then
595 AllInOneInventory_Saved_DepositBox_RefreshWindows = DepositBox_RefreshWindows;
596 DepositBox_RefreshWindows = AllInOneInventory_DepositBox_RefreshWindows;
597 end
598 if ( SellValue_OnShow == AllInOneInventory_SellValue_OnShow) then
599 SellValue_OnShow = AllInOneInventory_Saved_SellValue_OnShow;
600 AllInOneInventory_Saved_SellValue_OnShow = nil;
601 end
602 if ( UseContainerItem == AllInOneInventory_UseContainerItem) then
603 UseContainerItem = AllInOneInventory_Saved_UseContainerItem;
604 AllInOneInventory_Saved_UseContainerItem = nil;
605 end
606 if ( ToggleBag == AllInOneInventory_ToggleBag) then
607 ToggleBag = AllInOneInventory_Saved_ToggleBag;
608 AllInOneInventory_Saved_ToggleBag = nil;
609 end
610 if ( CloseBag == AllInOneInventory_CloseBag) then
611 CloseBag = AllInOneInventory_Saved_CloseBag;
612 AllInOneInventory_Saved_CloseBag = nil;
613 end
614 if ( OpenBag == AllInOneInventory_OpenBag) then
615 OpenBag = AllInOneInventory_Saved_OpenBag;
616 AllInOneInventory_Saved_OpenBag = nil;
617 end
618 if ( ToggleBackpack == AllInOneInventory_ToggleBackpack) then
619 ToggleBackpack = AllInOneInventory_Saved_ToggleBackpack;
620 AllInOneInventory_Saved_ToggleBackpack = nil;
621 end
622 if ( CloseBackpack == AllInOneInventory_CloseBackpack) then
623 CloseBackpack = AllInOneInventory_Saved_CloseBackpack;
624 AllInOneInventory_Saved_CloseBackpack = nil;
625 end
626 if ( OpenBackpack == AllInOneInventory_OpenBackpack) then
627 OpenBackpack = AllInOneInventory_Saved_OpenBackpack;
628 AllInOneInventory_Saved_OpenBackpack = nil;
629 end
630 if ( BagSlotButton_OnClick == AllInOneInventory_BagSlotButton_OnClick) then
631 BagSlotButton_OnClick = AllInOneInventory_Saved_BagSlotButton_OnClick;
632 AllInOneInventory_Saved_BagSlotButton_OnClick = nil;
633 end
634 if ( BagSlotButton_OnDrag == AllInOneInventory_BagSlotButton_OnDrag) then
635 BagSlotButton_OnDrag = AllInOneInventory_Saved_BagSlotButton_OnDrag;
636 AllInOneInventory_Saved_BagSlotButton_OnDrag = nil;
637 end
638 if ( BackpackButton_OnClick == AllInOneInventory_BackpackButton_OnClick) then
639 BackpackButton_OnClick = AllInOneInventory_Saved_BackpackButton_OnClick;
640 AllInOneInventory_Saved_BackpackButton_OnClick = nil;
641 end
642 if ( CloseAllWindows == AllInOneInventory_CloseAllWindows) then
643 CloseAllWindows = AllInOneInventory_Saved_CloseAllWindows;
644 AllInOneInventory_Saved_CloseAllWindows = nil;
645 end
646 if ( OpenAllBags == AllInOneInventory_OpenAllBags) then
647 OpenAllBags = AllInOneInventory_Saved_OpenAllBags;
648 AllInOneInventory_Saved_OpenAllBags = nil;
649 end
650 end
651 end
652  
653 -- Handles events
654 function AllInOneInventoryScriptFrame_OnEvent(event)
655 if ( event == "PLAYER_LOGIN" ) then
656 local value = getglobal("AllInOneInventory_Enabled");
657 if (value == nil ) then
658 -- defaults to off
659 value = 0;
660 end
661 AllInOneInventory_Toggle_Enabled(value);
662 local value = getglobal("AllInOneInventory_ReplaceBags");
663 if (value == nil ) then
664 -- defaults to off
665 value = 0;
666 end
667 AllInOneInventory_Toggle_ReplaceBags(value);
668 local value = getglobal("AllInOneInventory_SwapBagOrder");
669 if (value == nil ) then
670 -- defaults to off
671 value = 0;
672 end
673 AllInOneInventory_Toggle_SwapBagOrder(value);
674 local value = getglobal("AllInOneInventory_Alpha");
675 if (value == nil ) then
676 -- defaults to off
677 value = 0;
678 end
679 AllInOneInventory_Change_Alpha(1, value);
680 local value = getglobal("AllInOneInventory_Scale");
681 if (value == nil ) then
682 -- defaults to off
683 value = 0;
684 end
685 AllInOneInventory_Change_Scale(1, value);
686 local value = getglobal("AllInOneInventory_IncludeShotBags");
687 if (value == nil ) then
688 -- defaults to off
689 value = 1;
690 end
691 AllInOneInventory_Toggle_IncludeShotBags(value);
692 local value = getglobal("AllInOneInventory_Columns");
693 if (value == nil ) or ( value <= 0 ) then
694 -- defaults to 8
695 value = ALLINONEINVENTORY_NUM_COLUMNS;
696 end
697 AllInOneInventory_Change_Columns(1, value);
698 local func = nil;
699 for k, v in AllInOneInventory_BagStringIndex do
700 func = getglobal(string.format("AllInOneInventory_Toggle_IncludeBag%s", v));
701 value = getglobal(string.format("AllInOneInventory_IncludeBag%s", v));
702 if ( not value ) then
703 value = 1;
704 end
705 if ( func ) then
706 func(value);
707 end
708 end
709 local value = AllInOneInventory_Locked;
710 if ( not value ) or ( value <= 0 ) then
711 -- defaults to off
712 value = 0;
713 end
714 AllInOneInventory_Toggle_Locked(value);
715 elseif ( event == "ADDON_LOADED" ) then
716 if ( IsAddOnLoaded("DepositBox") ) then
717 end
718 AllInOneInventory_Setup_Hooks(1);
719 end
720 end
721  
722 -- Toggles the enabled/disabled state of an option and returns the new state
723 -- if toggle is 1, it's enabled
724 -- if toggle is 0, it's disabled
725 -- otherwise, it's toggled
726 function AllInOneInventory_Generic_Toggle(toggle, variableName, enableMessage, disableMessage, CosmosVarName)
727 local oldvalue = getglobal(variableName);
728 local newvalue = toggle;
729 if ( ( toggle ~= 1 ) and ( toggle ~= 0 ) ) then
730 if (oldvalue == 1) then
731 newvalue = 0;
732 elseif ( oldvalue == 0 ) then
733 newvalue = 1;
734 else
735 newvalue = 0;
736 end
737 end
738 setglobal(variableName, newvalue);
739 if ( newvalue ~= oldvalue ) then
740 local text = "";
741 if ( newvalue == 1 ) then
742 if ( enableMessage ) then
743 text = TEXT(getglobal(enableMessage));
744 end
745 else
746 if ( disableMessage ) then
747 text = TEXT(getglobal(disableMessage));
748 end
749 end
750 if ( text ) and ( strlen(text) > 0 ) then
751 AllInOneInventory_Print(text);
752 end
753 end
754 return newvalue;
755 end
756  
757 -- Toggles the enabled/disabled state of the AllInOneInventory
758 -- if toggle is 1, it's enabled
759 -- if toggle is 0, it's disabled
760 -- otherwise, it's toggled
761 function AllInOneInventory_Toggle_Enabled(toggle)
762 AllInOneInventory_DoToggle_Enabled(toggle, true);
763 end
764  
765 -- does the actual toggling
766 function AllInOneInventory_DoToggle_Enabled(toggle, showText)
767 local newvalue = 0;
768 if ( showText ) then
769 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_Enabled", "ALLINONEINVENTORY_CHAT_ENABLED", "ALLINONEINVENTORY_CHAT_DISABLED");
770 else
771 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_Enabled");
772 end
773 end
774  
775 -- toggling - no text
776 function AllInOneInventory_Toggle_Enabled_NoChat(toggle)
777 AllInOneInventory_DoToggle_Enabled(toggle, false);
778 end
779  
780 function AllInOneInventory_Toggle_Enabled(toggle)
781 AllInOneInventory_DoToggle_Enabled(toggle, true);
782 end
783  
784 -- does the actual toggling
785 function AllInOneInventory_DoToggle_ReplaceBags(toggle, showText)
786 local newvalue = 0;
787 if ( showText ) then
788 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_ReplaceBags", "ALLINONEINVENTORY_CHAT_REPLACEBAGS_ENABLED", "ALLINONEINVENTORY_CHAT_REPLACEBAGS_DISABLED");
789 else
790 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_ReplaceBags");
791 end
792 if ( newvalue == 1 ) then
793 AllInOneInventory_Saved_CloseBackpack();
794 end
795 end
796  
797 -- toggling - no text
798 function AllInOneInventory_Toggle_ReplaceBags_NoChat(toggle)
799 AllInOneInventory_DoToggle_ReplaceBags(toggle, false);
800 end
801  
802 function AllInOneInventory_Toggle_ReplaceBags(toggle)
803 AllInOneInventory_DoToggle_ReplaceBags(toggle, true);
804 end
805  
806 -- does the actual toggling
807 function AllInOneInventory_DoToggle_IncludeShotBags(toggle, showText)
808 local newvalue = 0;
809 if ( showText ) then
810 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_IncludeShotBags", "ALLINONEINVENTORY_CHAT_INCLUDE_SHOTBAGS_ENABLED", "ALLINONEINVENTORY_CHAT_INCLUDE_SHOTBAGS_DISABLED");
811 else
812 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_IncludeShotBags");
813 end
814 local frame = getglobal("AllInOneInventoryFrame");
815 if ( frame ) then
816 AllInOneInventoryFrame_Update(frame);
817 AllInOneInventory_UpdateBagState();
818 end
819 end
820  
821 -- toggling - no text
822 function AllInOneInventory_Toggle_IncludeShotBags_NoChat(toggle)
823 AllInOneInventory_DoToggle_IncludeShotBags(toggle, false);
824 end
825  
826 function AllInOneInventory_Toggle_IncludeShotBags(toggle)
827 AllInOneInventory_DoToggle_IncludeShotBags(toggle, true);
828 end
829  
830 -- does the actual toggling
831 function AllInOneInventory_DoToggle_IncludeBagZero(toggle, showText)
832 local newvalue = 0;
833 if ( showText ) then
834 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_IncludeBagZero", "ALLINONEINVENTORY_CHAT_INCLUDE_BAGZERO_ENABLED", "ALLINONEINVENTORY_CHAT_INCLUDE_BAGZERO_DISABLED");
835 else
836 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_IncludeBagZero");
837 end
838 local frame = getglobal("AllInOneInventoryFrame");
839 if ( frame ) then
840 AllInOneInventoryFrame_Update(frame);
841 AllInOneInventory_UpdateBagState();
842 end
843 end
844  
845 -- toggling - no text
846 function AllInOneInventory_Toggle_IncludeBagZero_NoChat(toggle)
847 AllInOneInventory_DoToggle_IncludeBagZero(toggle, false);
848 end
849  
850 function AllInOneInventory_Toggle_IncludeBagZero(toggle)
851 AllInOneInventory_DoToggle_IncludeBagZero(toggle, true);
852 end
853  
854 -- does the actual toggling
855 function AllInOneInventory_DoToggle_IncludeBagOne(toggle, showText)
856 local newvalue = 0;
857 if ( showText ) then
858 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_IncludeBagOne", "ALLINONEINVENTORY_CHAT_INCLUDE_BAGONE_ENABLED", "ALLINONEINVENTORY_CHAT_INCLUDE_BAGONE_DISABLED");
859 else
860 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_IncludeBagOne");
861 end
862 local frame = getglobal("AllInOneInventoryFrame");
863 if ( frame ) then
864 AllInOneInventoryFrame_Update(frame);
865 AllInOneInventory_UpdateBagState();
866 end
867 end
868  
869 -- toggling - no text
870 function AllInOneInventory_Toggle_IncludeBagOne_NoChat(toggle)
871 AllInOneInventory_DoToggle_IncludeBagOne(toggle, false);
872 end
873  
874 function AllInOneInventory_Toggle_IncludeBagOne(toggle)
875 AllInOneInventory_DoToggle_IncludeBagOne(toggle, true);
876 end
877  
878 -- does the actual toggling
879 function AllInOneInventory_DoToggle_IncludeBagTwo(toggle, showText)
880 local newvalue = 0;
881 if ( showText ) then
882 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_IncludeBagTwo", "ALLINONEINVENTORY_CHAT_INCLUDE_BAGTWO_ENABLED", "ALLINONEINVENTORY_CHAT_INCLUDE_BAGTWO_DISABLED");
883 else
884 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_IncludeBagTwo");
885 end
886 local frame = getglobal("AllInOneInventoryFrame");
887 if ( frame ) then
888 AllInOneInventoryFrame_Update(frame);
889 AllInOneInventory_UpdateBagState();
890 end
891 end
892  
893 -- toggling - no text
894 function AllInOneInventory_Toggle_IncludeBagTwo_NoChat(toggle)
895 AllInOneInventory_DoToggle_IncludeBagTwo(toggle, false);
896 end
897  
898 function AllInOneInventory_Toggle_IncludeBagTwo(toggle)
899 AllInOneInventory_DoToggle_IncludeBagTwo(toggle, true);
900 end
901  
902 -- does the actual toggling
903 function AllInOneInventory_DoToggle_IncludeBagThree(toggle, showText)
904 local newvalue = 0;
905 if ( showText ) then
906 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_IncludeBagThree", "ALLINONEINVENTORY_CHAT_INCLUDE_BAGTHREE_ENABLED", "ALLINONEINVENTORY_CHAT_INCLUDE_BAGTHREE_DISABLED");
907 else
908 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_IncludeBagThree");
909 end
910 local frame = getglobal("AllInOneInventoryFrame");
911 if ( frame ) then
912 AllInOneInventoryFrame_Update(frame);
913 AllInOneInventory_UpdateBagState();
914 end
915 end
916  
917 -- toggling - no text
918 function AllInOneInventory_Toggle_IncludeBagThree_NoChat(toggle)
919 AllInOneInventory_DoToggle_IncludeBagThree(toggle, false);
920 end
921  
922 function AllInOneInventory_Toggle_IncludeBagThree(toggle)
923 AllInOneInventory_DoToggle_IncludeBagThree(toggle, true);
924 end
925  
926 -- does the actual toggling
927 function AllInOneInventory_DoToggle_IncludeBagFour(toggle, showText)
928 local newvalue = 0;
929 if ( showText ) then
930 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_IncludeBagFour", "ALLINONEINVENTORY_CHAT_INCLUDE_BAGFOUR_ENABLED", "ALLINONEINVENTORY_CHAT_INCLUDE_BAGFOUR_DISABLED");
931 else
932 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_IncludeBagFour");
933 end
934 local frame = getglobal("AllInOneInventoryFrame");
935 if ( frame ) then
936 AllInOneInventoryFrame_Update(frame);
937 AllInOneInventory_UpdateBagState();
938 end
939 end
940  
941 -- toggling - no text
942 function AllInOneInventory_Toggle_IncludeBagFour_NoChat(toggle)
943 AllInOneInventory_DoToggle_IncludeBagFour(toggle, false);
944 end
945  
946 function AllInOneInventory_Toggle_IncludeBagFour(toggle)
947 AllInOneInventory_DoToggle_IncludeBagFour(toggle, true);
948 end
949  
950  
951 function AllInOneInventory_Generic_Number(value, variableName, message, formatValueMessage)
952 local oldvalue = getglobal(variableName);
953 local newvalue = value;
954 if ( type(newvalue) ~= "number" ) then
955 newvalue = tonumber(oldvalue);
956 if ( not newvalue ) then
957 return;
958 end
959 end
960 setglobal(variableName, newvalue);
961 if ( newvalue ~= oldvalue ) then
962 local text = nil;
963 if ( formatValueMessage ) then
964 text = format(TEXT(getglobal(formatValueMessage)), newvalue);
965 elseif ( message ) then
966 text = TEXT(getglobal(formatValueMessage));
967 end
968 if ( text ) and ( strlen(text) > 0 ) then
969 AllInOneInventory_Print(text);
970 end
971 end
972 return newvalue;
973 end
974  
975 function AllInOneInventory_Generic_Value(value, variableName, message, formatValueMessage)
976 local oldvalue = getglobal(variableName);
977 local newvalue = value;
978 setglobal(variableName, newvalue);
979 if ( newvalue ~= oldvalue ) then
980 local text = nil;
981 if ( formatValueMessage ) then
982 text = format(TEXT(getglobal(formatValueMessage)), newvalue);
983 elseif ( message ) then
984 text = TEXT(getglobal(formatValueMessage));
985 end
986 if ( text ) and ( strlen(text) > 0 ) then
987 AllInOneInventory_Print(text);
988 end
989 end
990 return newvalue;
991 end
992  
993 -- does the actual setting
994 function AllInOneInventory_DoChange_Columns(value, showText)
995 local newvalue = 0;
996 if ( showText ) then
997 newvalue = AllInOneInventory_Generic_Number(value, "AllInOneInventory_Columns", nil, "ALLINONEINVENTORY_CHAT_COLUMNS_FORMAT");
998 else
999 newvalue = AllInOneInventory_Generic_Number(value, "AllInOneInventory_Columns");
1000 end
1001 AllInOneInventoryFrame_SetColumns(newvalue);
1002 end
1003  
1004 -- toggling - no text
1005 function AllInOneInventory_Change_Columns_NoChat(toggle, value)
1006 AllInOneInventory_DoChange_Columns(value, false);
1007 end
1008  
1009 function AllInOneInventory_Change_Columns(toggle, value)
1010 AllInOneInventory_DoChange_Columns(value, true);
1011 end
1012  
1013 function AllInOneInventory_DoToggle_SwapBagOrder(toggle, showText)
1014 local newvalue = 0;
1015 if ( showText ) then
1016 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_SwapBagOrder", "ALLINONEINVENTORY_CHAT_SWAP_BAG_ORDER_ENABLED", "ALLINONEINVENTORY_CHAT_SWAP_BAG_ORDER_DISABLED");
1017 else
1018 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_SwapBagOrder");
1019 end
1020 end
1021  
1022 function AllInOneInventory_Toggle_SwapBagOrder_NoChat(toggle)
1023 AllInOneInventory_DoToggle_SwapBagOrder(toggle, false);
1024 end
1025  
1026 function AllInOneInventory_Toggle_SwapBagOrder(toggle)
1027 AllInOneInventory_DoToggle_SwapBagOrder(toggle, true);
1028 end
1029  
1030  
1031 function AllInOneInventoryFrame_SetAlpha(alpha)
1032 if ( not alpha ) then
1033 return;
1034 end
1035 if ( type(alpha) ~= "number" ) then
1036 alpha = tonumber(alpha);
1037 if ( not alpha ) then
1038 return;
1039 end
1040 end
1041 if ( alpha > ALLINONEINVENTORY_ALPHA_MAX ) then
1042 alpha = ALLINONEINVENTORY_ALPHA_MAX;
1043 end
1044 if ( alpha <= ALLINONEINVENTORY_ALPHA_MIN ) then
1045 local parentAlpha = 1;
1046 if ( UIParent ) and ( UIParent.GetAlpha ) then
1047 parentAlpha = UIParent:GetAlpha();
1048 if ( not parentAlpha ) then
1049 parentAlpha = 1;
1050 end
1051 end
1052 if ( parentAlpha ) then
1053 alpha = parentAlpha;
1054 end
1055 end
1056 if ( not alpha ) then
1057 return;
1058 end
1059 AllInOneInventoryFrame:SetAlpha(alpha);
1060 end
1061  
1062  
1063 function AllInOneInventory_DoChange_Alpha(value, showText)
1064 local newvalue = 0;
1065 if ( showText ) then
1066 newvalue = AllInOneInventory_Generic_Number(value, "AllInOneInventory_Alpha", nil, "ALLINONEINVENTORY_CHAT_ALPHA_FORMAT");
1067 else
1068 newvalue = AllInOneInventory_Generic_Number(value, "AllInOneInventory_Alpha");
1069 end
1070 AllInOneInventoryFrame_SetAlpha(newvalue);
1071 end
1072  
1073 -- toggling - no text
1074 function AllInOneInventory_Change_Alpha_NoChat(toggle, value)
1075 AllInOneInventory_DoChange_Alpha(value, false);
1076 end
1077  
1078 function AllInOneInventory_Change_Alpha(toggle, value)
1079 AllInOneInventory_DoChange_Alpha(value, true);
1080 end
1081  
1082 function AllInOneInventoryFrame_SetScale(scale)
1083 if ( not scale ) then
1084 return;
1085 end
1086 if ( type(scale) ~= "number" ) then
1087 scale = tonumber(scale);
1088 if ( not scale ) then
1089 return;
1090 end
1091 end
1092 if ( scale > ALLINONEINVENTORY_SCALE_MAX ) then
1093 scale = ALLINONEINVENTORY_SCALE_MAX;
1094 end
1095 if ( scale <= ALLINONEINVENTORY_SCALE_MIN ) then
1096 scale = 1;
1097 -- Since patch 1.9, scales are relative to parent.
1098 -- The code block below is not necessary
1099 --[[
1100 local parentScale = 1;
1101 if ( UIParent ) and ( UIParent.GetScale ) then
1102 parentScale = UIParent:GetScale();
1103 if ( not parentScale ) then
1104 parentScale = 1;
1105 end
1106 end
1107 if ( parentScale ) then
1108 scale = parentScale;
1109 end
1110 ]]--
1111 end
1112 if ( not scale ) then
1113 return;
1114 end
1115 AllInOneInventoryFrame:SetScale(scale);
1116 end
1117  
1118  
1119 function AllInOneInventory_DoChange_Scale(value, showText)
1120 local newvalue = 1;
1121 if ( showText ) then
1122 newvalue = AllInOneInventory_Generic_Number(value, "AllInOneInventory_Scale", nil, "ALLINONEINVENTORY_CHAT_SCALE_FORMAT");
1123 else
1124 newvalue = AllInOneInventory_Generic_Number(value, "AllInOneInventory_Scale");
1125 end
1126 AllInOneInventoryFrame_SetScale(newvalue);
1127 end
1128  
1129 -- toggling - no text
1130 function AllInOneInventory_Change_Scale_NoChat(toggle, value)
1131 AllInOneInventory_DoChange_Scale(value, false);
1132 end
1133  
1134 function AllInOneInventory_Change_Scale(toggle, value)
1135 AllInOneInventory_DoChange_Scale(value, true);
1136 end
1137  
1138  
1139 -- Prints out text to a chat box.
1140 function AllInOneInventory_Print(msg,r,g,b,frame,id,unknown4th)
1141 if (not r) then r = 1.0; end
1142 if (not g) then g = 1.0; end
1143 if (not b) then b = 0.0; end
1144 if ( Print ) then
1145 Print(msg, r, g, b, frame, id, unknown4th);
1146 return;
1147 end
1148 if(unknown4th) then
1149 local temp = id;
1150 id = unknown4th;
1151 unknown4th = id;
1152 end
1153  
1154 if ( frame ) then
1155 frame:AddMessage(msg,r,g,b,id,unknown4th);
1156 else
1157 if ( DEFAULT_CHAT_FRAME ) then
1158 DEFAULT_CHAT_FRAME:AddMessage(msg, r, g, b,id,unknown4th);
1159 end
1160 end
1161 end
1162  
1163 function AllInOneInventory_IsBagOpen(id)
1164 local formatStr = "ContainerFrame%d";
1165 local frame = nil;
1166 for i = 1, NUM_CONTAINER_FRAMES do
1167 frame = getglobal(format(formatStr, i));
1168 if ( ( frame ) and ( frame:IsVisible() ) and ( frame:GetID() == id ) ) then
1169 return true;
1170 end
1171 end
1172 return false;
1173 end
1174  
1175 function AllInOneInventory_GetBagState(bag, baseToggle)
1176 if ( AllInOneInventory_ShouldOverrideBag(bag) ) then
1177 local toggle = (AllInOneInventory_IsBagOpen(bag) or baseToggle);
1178 if ( ( toggle == true ) or ( toggle == 1 ) ) then
1179 return 1;
1180 else
1181 return 0;
1182 end
1183 else
1184 if ( AllInOneInventory_IsBagOpen(bag) ) then
1185 return 1;
1186 else
1187 return 0;
1188 end
1189 end
1190 end
1191  
1192 function AllInOneInventory_UpdateBagState()
1193 local shouldBeChecked = AllInOneInventoryFrame:IsVisible();
1194 MainMenuBarBackpackButton:SetChecked(AllInOneInventory_GetBagState(0, shouldBeChecked));
1195 local bagButton = nil;
1196 local formatStr = "CharacterBag%dSlot";
1197 for i = 0, 3 do
1198 bagButton = getglobal(format(formatStr, i));
1199 if ( bagButton ) then
1200 bagButton:SetChecked(AllInOneInventory_GetBagState(i+1, shouldBeChecked));
1201 end
1202 end
1203 end
1204  
1205 function ToggleAllInOneInventoryFrame()
1206 if ( AllInOneInventoryFrame:IsVisible() ) then
1207 CloseAllInOneInventoryFrame();
1208 else
1209 OpenAllInOneInventoryFrame();
1210 end
1211 AllInOneInventory_UpdateBagState();
1212 end
1213  
1214  
1215 function AllInOneInventory_CloseAllWindows(ignoreCenter)
1216 local wasVisible = AllInOneInventoryFrame:IsVisible();
1217 CloseAllInOneInventoryFrame();
1218 local realClosed = nil;
1219 if ( arg ) then
1220 realClosed = AllInOneInventory_Saved_CloseAllWindows(ignoreCenter);
1221 else
1222 realClosed = AllInOneInventory_Saved_CloseAllWindows();
1223 end
1224 if ( wasVisible ) then
1225 return 1;
1226 else
1227 return realClosed;
1228 end
1229 end
1230  
1231 function CloseAllInOneInventoryFrame()
1232 local value = false;
1233 local frame = getglobal("AllInOneInventoryFrame");
1234 if ( frame ) and ( frame:IsVisible() ) then
1235 frame:Hide();
1236 value = true;
1237 end
1238 AllInOneInventory_UpdateBagState();
1239 return value;
1240 end
1241  
1242 function OpenAllInOneInventoryFrame()
1243 local value = false;
1244 local frame = getglobal("AllInOneInventoryFrame");
1245 if ( frame ) then
1246 AllInOneInventoryFrame_Update(frame);
1247 if ( not frame:IsVisible() ) then
1248 frame:Show();
1249 value = true;
1250 end
1251 end
1252 AllInOneInventory_UpdateBagState();
1253 return value;
1254 end
1255  
1256 function AllInOneInventoryFrame_OnLoad()
1257 this:RegisterForClicks("LeftButtonUp", "RightButtonUp");
1258 --DynamicData.item.addOnInventoryUpdateHandler(AllInOneInventoryFrame_OnInventoryUpdate);
1259 --DynamicData.item.addOnInventoryCooldownUpdateHandler(AllInOneInventoryFrame_OnInventoryCooldownUpdate);
1260 end
1261  
1262 AllInOneInventoryFrame_LastInventoryUpdate = {};
1263 ALLINONEINVENTORYFRAME_UPDATE_DELAY = 1;
1264  
1265 function AllInOneInventoryFrame_OnInventoryUpdate(bag, scanType)
1266 local curTime = GetTime();
1267 local qwe = AllInOneInventoryFrame_LastInventoryUpdate[scanType];
1268 if ( not qwe ) then
1269 qwe = 0;
1270 end
1271 local fixTime = ALLINONEINVENTORYFRAME_UPDATE_DELAY - (curTime - qwe);
1272 if ( fixTime <= 0 ) then
1273 fixTime = 0.01;
1274 end
1275 AIOI_ScheduleByName("AIOI_INV_UPDATE_"..scanType, fixTime, AllInOneInventoryFrame_DoInventoryUpdate, bag, scanType);
1276 end
1277  
1278 function AllInOneInventoryFrame_DoInventoryUpdate(bag, scanType)
1279 AllInOneInventoryFrame_LastInventoryUpdate[scanType] = GetTime();
1280 local frame = getglobal("AllInOneInventoryFrame");
1281 local func = nil;
1282 if ( scanType ) then
1283 if ( ( scanType and DYNAMICDATA_ITEM_SCAN_TYPE_COOLDOWN ) > 0 ) then
1284 func = getglobal("AllInOneInventoryFrame_UpdateAllCooldowns");
1285 end
1286 if ( ( scanType and DYNAMICDATA_ITEM_SCAN_TYPE_ITEMINFO ) > 0 ) then
1287 func = getglobal("AllInOneInventoryFrame_Update");
1288 end
1289 else
1290 func = getglobal("AllInOneInventoryFrame_Update");
1291 end
1292 if ( ( frame ) and ( frame:IsVisible() ) ) then
1293 if ( func ) then
1294 func(frame);
1295 end
1296 end
1297 end
1298  
1299 function AllInOneInventoryFrame_OnInventoryCooldownUpdate()
1300 local frame = getglobal("AllInOneInventoryFrame");
1301 if ( frame ) then
1302 AllInOneInventoryFrame_UpdateAllCooldowns(frame);
1303 if ( frame:IsVisible() ) then
1304 --AllInOneInventoryFrame_Update(frame);
1305 end
1306 end
1307 end
1308  
1309  
1310 function AllInOneInventoryFrame_OnEvent(event)
1311 end
1312  
1313 function AllInOneInventoryFrame_OnHide()
1314 PlaySound("igBackPackClose");
1315 AllInOneInventory_StopMoving(this);
1316 end
1317  
1318 function AllInOneInventoryFrame_OnShow()
1319 AllInOneInventoryFrame_Update(this);
1320 PlaySound("igBackPackOpen");
1321 end
1322  
1323 function AllInOneInventoryFrame_UpdateAllCooldowns(frame)
1324 local name = frame:GetName();
1325 local itemInfo;
1326 local itemButton;
1327 local bag, slot;
1328 for buttonID = 1, ALLINONEINVENTORY_MAXIMUM_NUMBER_OF_BUTTONS do
1329 itemButton = getglobal(name.."Item"..buttonID);
1330 if ( itemButton ) and ( itemButton:IsVisible() ) then
1331 bag, slot = AllInOneInventory_GetIdAsBagSlot(itemButton:GetID());
1332 itemInfo = AllInOneInventoryItems_GetInfo(bag, slot);
1333 if ( ( itemInfo ) and ( itemInfo.t ) and ( strlen(itemInfo.t) > 0 ) ) then
1334 AllInOneInventoryFrame_UpdateCooldown(itemButton);
1335 end
1336 end
1337 end
1338 end
1339  
1340 function AllInOneInventoryFrame_UpdateButton(frame, buttonID)
1341 local name = frame:GetName();
1342 local itemButton = getglobal(name.."Item"..buttonID);
1343  
1344 if ( not itemButton ) or ( not itemButton:IsVisible() ) then
1345 return;
1346 end
1347  
1348 local bag, slot = AllInOneInventory_GetIdAsBagSlot(itemButton:GetID());
1349 if ( bag == -1 ) and ( slot == -1 ) then
1350 return;
1351 end
1352  
1353 local itemInfo = AllInOneInventoryItems_GetInfo(bag, slot);
1354  
1355 if ( not itemInfo ) then
1356 itemInfo = AllInOneInventoryItems_NoItem;
1357 end
1358  
1359 SetItemButtonTexture(itemButton, itemInfo.t);
1360 SetItemButtonCount(itemButton, itemInfo.c);
1361  
1362 SetItemButtonDesaturated(itemButton, itemInfo.l, 0.5, 0.5, 0.5);
1363  
1364 if ( ( itemInfo.t ) and ( strlen(itemInfo.t) > 0 ) ) then
1365 AllInOneInventoryFrame_UpdateCooldown(itemButton);
1366 else
1367 local cooldownFrame = getglobal(itemButton:GetName().."Cooldown");
1368 if ( cooldownFrame ) then
1369 cooldownFrame:Hide();
1370 end
1371 end
1372  
1373 local readable = itemInfo.r;
1374 --local normalTexture = getglobal(name.."Item"..j.."NormalTexture");
1375 --if ( quality and quality ~= -1) then
1376 -- local color = getglobal("ITEM_QUALITY".. quality .."_COLOR");
1377 -- normalTexture:SetVertexColor(color.r, color.g, color.b);
1378 --else
1379 -- normalTexture:SetVertexColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b);
1380 --end
1381 local showSell = nil;
1382 if ( GameTooltip:IsOwned(itemButton) ) then
1383 if ( itemInfo.t ) and ( strlen(itemInfo.t) > 0 ) then
1384 AllInOneInventory_Patching_Tooltip = 1;
1385 local hasCooldown, repairCost = GameTooltip:SetBagItem(bag, slot);
1386 if ( hasCooldown ) then
1387 itemButton.updateTooltip = TOOLTIP_UPDATE_TIME;
1388 else
1389 itemButton.updateTooltip = nil;
1390 end
1391 if ( ( InRepairMode() ) and ( repairCost ) and (repairCost > 0) ) then
1392 GameTooltip:AddLine(TEXT(REPAIR_COST), "", 1, 1, 1);
1393 SetTooltipMoney(GameTooltip, repairCost);
1394 --GameTooltip:Show();
1395 elseif ( MerchantFrame:IsVisible() and not locked) then
1396 showSell = 1;
1397 end
1398 AllInOneInventory_ModifyItemTooltip(bag, slot, "GameTooltip");
1399 AllInOneInventory_Patching_Tooltip = 0;
1400 else
1401 GameTooltip:Hide();
1402 end
1403 if ( showSell ) then
1404 ShowContainerSellCursor(bag, slot);
1405 elseif ( readable ) then
1406 ShowInspectCursor();
1407 else
1408 ResetCursor();
1409 end
1410 end
1411 end
1412  
1413 function AllInOneInventoryFrame_Update(frame)
1414 if ( not AllInOneInventoryFrame_UpdateLookIfNeeded() ) then
1415 for j=1, frame.size, 1 do
1416 AllInOneInventoryFrame_UpdateButton(frame, j);
1417 end
1418 end
1419 end
1420  
1421 function AllInOneInventoryFrame_UpdateCooldown(button)
1422 local bag, slot = AllInOneInventory_GetIdAsBagSlot(button:GetID());
1423 if ( bag == -1 ) and ( slot == -1 ) then
1424 return;
1425 end
1426  
1427 local cooldownFrame = getglobal(button:GetName().."Cooldown");
1428 local itemInfo = AllInOneInventoryItems_GetInfo(bag, slot);
1429 local start, duration, enable = 0, 0, 1;
1430 if ( itemInfo ) then
1431 start, duration, enable = itemInfo.cs, itemInfo.cd, itemInfo.ce;
1432 end
1433 CooldownFrame_SetTimer(cooldownFrame, start, duration, enable);
1434 if ( ( duration > 0 ) and ( enable == 0 ) ) then
1435 SetItemButtonTextureVertexColor(button, 0.4, 0.4, 0.4);
1436 end
1437 end
1438  
1439 function AllInOneInventoryFrameItemButton_OnLoad()
1440 this:RegisterForClicks("LeftButtonUp", "RightButtonUp");
1441 this:RegisterForDrag("LeftButton");
1442  
1443 this.SplitStack = function(button, split)
1444 SplitContainerItem(button:GetParent():GetID(), button:GetID(), split);
1445 end
1446 end
1447  
1448 function AllInOneInventory_HandleQuickMount(bag, slot)
1449 if ( QuickMount_PickupItem ) then
1450 local itemInfo = AllInOneInventoryItems_GetInfo(bag, slot);
1451 if ( itemInfo ) and ( itemInfo.t ) and ( strlen(itemInfo.t) >= 0 ) then
1452 QuickMount_PickupItem(bag, slot, itemInfo.n, itemInfo.t);
1453 end
1454 end
1455 end
1456  
1457 function AllInOneInventoryFrameItemButton_OnClick(button, ignoreShift)
1458 local bag, slot = AllInOneInventory_GetIdAsBagSlot(this:GetID());
1459 if ( LootDestroyer_DoItem_OnClick ) then
1460 if ( LootDestroyer_DoItem_OnClick(bag, slot, button, ignoreShift) ) then
1461 return;
1462 end
1463 end
1464 if ( button == "LeftButton" ) then
1465 if ( IsShiftKeyDown() and not ignoreShift ) then
1466 if ( ChatFrameEditBox:IsVisible() ) then
1467 ChatFrameEditBox:Insert(GetContainerItemLink(bag, slot));
1468 else
1469 local itemInfo = AllInOneInventoryItems_GetInfo(bag, slot);
1470 if ( itemInfo ) and ( not itemInfo.l ) then
1471 this.SplitStack = function(button, split)
1472 SplitContainerItem(bag, slot, split);
1473 end
1474 OpenStackSplitFrame(this.count, this, "BOTTOMRIGHT", "TOPRIGHT");
1475 end
1476 end
1477 elseif ( IsControlKeyDown() ) then
1478 DressUpItemLink(GetContainerItemLink(bag, slot));
1479 else
1480 AllInOneInventory_HandleQuickMount(bag, slot);
1481 PickupContainerItem(bag, slot);
1482 end
1483 else
1484 -- Modifier2Sell fixed by daun
1485 if ( MerchantFrame:IsVisible() ) and ( Modifier2Sell_BagSlotButton_OnClick ) then
1486 if ( not Modifier2Sell_BagSlotButton_OnClick(button, ignoreShift, bag, slot) ) then
1487 return;
1488 end
1489 end
1490 if ( IsControlKeyDown() and not ignoreShift ) then
1491 return;
1492 elseif ( IsShiftKeyDown() and MerchantFrame:IsVisible() and not ignoreShift ) then
1493 this.SplitStack = function(button, split)
1494 SplitContainerItem(bag, slot, split);
1495 MerchantItemButton_OnClick("LeftButton");
1496 end
1497 OpenStackSplitFrame(this.count, this, "BOTTOMRIGHT", "TOPRIGHT");
1498 elseif ( MerchantFrame:IsVisible() and MerchantFrame.selectedTab == 2 ) then
1499 -- Don't sell the item if the buyback tab is selected
1500 return;
1501 else
1502 UseContainerItem(bag, slot);
1503 StackSplitFrame:Hide();
1504 end
1505 end
1506 end
1507  
1508 function AllInOneInventoryFrameItemButton_OnEnter()
1509 AllInOneInventory_Patching_Tooltip = 1;
1510 local tooltip = GameTooltip;
1511 local bag, slot = AllInOneInventory_GetIdAsBagSlot(this:GetID());
1512  
1513 local itemInfo = AllInOneInventoryItems_GetInfo(bag, slot);
1514 if ( ( not itemInfo ) or ( not itemInfo.t ) or ( strlen(itemInfo.t) <= 0 ) ) then
1515 tooltip:Hide();
1516 return;
1517 end
1518 tooltip:SetOwner(this, "ANCHOR_LEFT");
1519 local hasCooldown, repairCost = GameTooltip:SetBagItem(bag, slot);
1520 if ( hasCooldown ) then
1521 this.updateTooltip = 1;
1522 else
1523 this.updateTooltip = nil;
1524 end
1525 if ( InRepairMode() and (repairCost and repairCost > 0) ) then
1526 tooltip:AddLine(TEXT(REPAIR_COST), "", 1, 1, 1);
1527 SetTooltipMoney(tooltip, repairCost);
1528 tooltip:Show();
1529 elseif ( MerchantFrame:IsVisible() ) then
1530 ShowContainerSellCursor(bag, slot);
1531 AllInOneInventoryFrame_RegisterCurrentTooltipSellValue(tooltip, bag, slot);
1532 elseif ( this.readable ) then
1533 ShowInspectCursor();
1534 end
1535  
1536 AllInOneInventory_ModifyItemTooltip(bag, slot, tooltip:GetName());
1537 AllInOneInventory_Patching_Tooltip = 0;
1538 end
1539  
1540 function AllInOneInventoryFrame_RegisterCurrentTooltipSellValue(tooltip, bag, slot)
1541 local itemInfo = AllInOneInventoryItems_GetInfo(bag, slot);
1542 if ( not itemInfo ) or ( not itemInfo.n ) or ( strlen(itemInfo.n) <= 0 ) then
1543 return;
1544 end
1545 if ( SellValue_SaveFor ) then
1546 local moneyFrame = getglobal(tooltip:GetName().."MoneyFrame");
1547 if ( moneyFrame ) and ( moneyFrame:IsVisible() ) and ( moneyFrame.staticMoney ) then
1548 SellValue_SaveFor(bag, slot, itemInfo.n, moneyFrame.staticMoney);
1549 end
1550 end
1551 if ( LootLink_ProcessLinks ) then
1552 local link = GetContainerItemLink(bag, slot);
1553 local name = LootLink_ProcessLinks(link);
1554 if ( LootLink_VendorEntry_Hook ) then
1555 local moneyFrame = getglobal(tooltip:GetName().."MoneyFrame");
1556 if ( moneyFrame ) and ( moneyFrame:IsVisible() ) and ( moneyFrame.staticMoney ) then
1557 if ( itemInfo.c ) and ( itemInfo.c > 0 ) then
1558 local money = moneyFrame.staticMoney / itemInfo.c;
1559 if ( ItemLinks[name] ) then
1560 if ( not ItemLinks[name].price ) and ( not ItemLinks[name].p ) then
1561 ItemLinks[name].p = money;
1562 end
1563 --LootLink_VendorEntry_Hook(bag, slot, itemInfo.n, moneyFrame.staticMoney);
1564 end
1565 end
1566 else
1567 local stringFormat = tooltip:GetName().."TextLeft%d";
1568 local string = nil;
1569 local text = nil;
1570 for i = 2, 10 do
1571 string = getglobal(stringFormat, i);
1572 if ( string ) and ( string:IsVisible() ) then
1573 text = string:GetText();
1574 if ( text ) and ( text == TEXT(ITEM_UNSELLABLE) ) then
1575 if ( ItemLinks[name] ) and ( ( ItemLinks[name].p ) or ( ItemLinks[name].price ) ) then
1576 ItemLinks[name].p = nil;
1577 ItemLinks[name].price = nil;
1578 end
1579 end
1580 end
1581 end
1582  
1583 end
1584 end
1585 end
1586 end
1587  
1588 function AllInOneInventoryFrameItemButton_OnLeave()
1589 this.updateTooltip = nil;
1590 if ( GameTooltip:IsOwned(this) ) then
1591 GameTooltip:Hide();
1592 ResetCursor();
1593 end
1594 end
1595  
1596 -- modifies the tooltip
1597 function AllInOneInventory_ModifyItemTooltip(bag, slot, tooltipName)
1598 if ( not tooltipName ) then
1599 tooltipName = "GameTooltip";
1600 end
1601 --AllInOneInventory_ReagentHelper_ModifyItemTooltip(bag, slot, tooltipName);
1602 AllInOneInventory_LootLink_ModifyItemTooltip(bag, slot, tooltipName);
1603 AllInOneInventory_SellValue_ModifyItemTooltip(bag, slot, tooltipName);
1604 local tooltip = getglobal(tooltipName);
1605 if ( not tooltip ) then
1606 return;
1607 end
1608 tooltip:Show();
1609 end
1610  
1611 function AllInOneInventory_SellValue_ModifyItemTooltip(bag, slot, tooltipName)
1612 local tooltip = getglobal(tooltipName);
1613 if ( not tooltip ) then
1614 return;
1615 end
1616 if ( not SellValue_AddMoneyToTooltip ) then
1617 return;
1618 end
1619 local itemInfo = AllInOneInventoryItems_GetInfo(bag, slot);
1620  
1621 if ( not SellValues ) or ( MerchantFrame:IsVisible() ) then
1622 return;
1623 end
1624  
1625 local itemName = nil;
1626 local itemCount = nil;
1627 if ( itemInfo ) then
1628 itemCount = itemInfo.c;
1629 if ( itemInfo.n ) then
1630 if ( InvList_ShortenItemName ) then
1631 itemName = InvList_ShortenItemName(itemInfo.n);
1632 else
1633 itemName = itemInfo.n;
1634 end
1635 end
1636 end
1637 if ( not itemName ) or ( strlen(itemName) <= 0 ) then
1638 return;
1639 end
1640 if ( IsAddOnLoaded("SellValue") ) then
1641 -- Don't add a tooltip for hidden items for SellValue
1642 if ( not InvList_TooltipMode ) or
1643 ( ( InvList_TooltipMode == 1 ) and ( InvList_HiddenItems ) and ( InvList_HiddenItems[itemName] ) ) then
1644 return;
1645 end
1646 end
1647  
1648 local price = SellValues[itemName];
1649  
1650 if ( price ) then
1651 local linesAdded = 0;
1652 if ( price == 0 ) then
1653 local msg = NOSELLPRICE;
1654 if ( not msg ) then
1655 msg = ITEM_UNSELLABLE;
1656 end
1657 tooltip:AddLine(msg, 1.0, 1.0, 0);
1658 linesAdded = 1;
1659 else
1660 tooltip:AddLine(SELLVALUE_COST, 1.0, 1.0, 0);
1661 SetTooltipMoney(tooltip, price);
1662 linesAdded = 2;
1663 end -- if price > 0
1664  
1665 -- Adjust width to account for new lines
1666 if ( tooltip:GetWidth() < 120 ) then tooltip:SetWidth(120); end
1667 end -- if price
1668 end
1669  
1670 function AllInOneInventory_LootLink_ModifyItemTooltip(bag, slot, tooltipName)
1671 local tooltip = getglobal(tooltipName);
1672 if ( not tooltip ) then
1673 tooltip = getglobal("GameTooltip");
1674 tooltipName = "GameTooltip";
1675 end
1676 if ( not tooltip ) then
1677 return false;
1678 end
1679 local shouldModify = true;
1680 if ( ( InRepairMode() ) or
1681 ( AllInOneInventory_ModifyTooltipsAtMerchant == 0 ) and ( MerchantFrame:IsVisible() ) ) then
1682 shouldModify = false;
1683 end
1684 if (
1685 ( LootLink_AddExtraTooltipInfo ) and
1686 ( shouldModify ) and ( ItemLinks ) ) then
1687 local itemInfo = AllInOneInventoryItems_GetInfo(bag, slot);
1688 local name = nil;
1689 if ( itemInfo ) and ( itemInfo.n ) then
1690 name = itemInfo.n;
1691 end
1692 local data = ItemLinks[name];
1693 if ( ( not LootLinkState ) or ( not LootLinkState.HideInfo ) ) and ( name ) and ( data ) then
1694 if ( itemInfo ) and ( itemInfo.t ) then
1695 if ( AllInOneInventory_ShowPrice == 1 ) then
1696 local money = ItemLinks[name].p;
1697 if ( not money ) and ( ItemLinks[name].price ) then
1698 money = ItemLinks[name].price;
1699 end
1700 local stack = ItemLinks[name].x;
1701 if ( not stack ) and ( ItemLinks[name].stack ) then
1702 stack = ItemLinks[name].stack;
1703 end
1704 if ( money ) then
1705 AIOI_LootLink_SetTooltipMoney(tooltip, itemInfo.c, money, stack);
1706 end
1707 end
1708 LootLink_AddExtraTooltipInfo(tooltip, name, itemInfo.c, data);
1709 --tooltip:Show();
1710 if( tooltip == GameTooltip ) then
1711 GameTooltip.llDone = 1;
1712 end
1713 end
1714 end
1715 elseif ( ( LootLink_Tooltip_Hook ) and ( shouldModify ) and ( ItemLinks ) ) then
1716 local name = nil;
1717 local itemInfo = AllInOneInventoryItems_GetInfo(bag, slot);
1718 if ( itemInfo ) then
1719 name = itemInfo.n;
1720 end
1721 if ( itemInfo ) and ( name ) and ( strlen(name) > 0 ) and ( ItemLinks[name] ) then
1722 local data = ItemLinks[name];
1723 local money = 0;
1724 if ( data.p ) then
1725 money = data.p;
1726 elseif ( data.price ) then
1727 money = data.price;
1728 end
1729 if ( not money ) then money = 0; end
1730 local tooltip = getglobal(tooltipName);
1731 if ( not tooltip ) then
1732 return;
1733 end
1734 LootLink_Tooltip_Hook(tooltip, name, money, itemInfo.c, data);
1735 --tooltip:Show();
1736 end
1737 end
1738 end
1739  
1740 function AllInOneInventory_ReagentHelper_ModifyItemTooltip(bag, slot, tooltipName)
1741 if ( ReagentHelper_ModifyTooltip ) then
1742 local shouldModifyTooltip = true;
1743 if ( Auctioneer_GetFilter ) then
1744 if ( Auctioneer_GetFilter("all") ) and ( Auctioneer_GetFilter("usage") ) then
1745 shouldModifyTooltip = false;
1746 end
1747 end
1748 if ( shouldModifyTooltip ) then
1749 ReagentHelper_ModifyTooltip(tooltipName);
1750 end
1751 else
1752 -- No Labels
1753 end
1754 end
1755  
1756 function AllInOneInventoryFrameItemButton_OnUpdate(elapsed)
1757 if ( not this.updateTooltip ) then
1758 return;
1759 end
1760  
1761 this.updateTooltip = this.updateTooltip - elapsed;
1762 if ( this.updateTooltip > 0 ) then
1763 return;
1764 end
1765  
1766 if ( GameTooltip:IsOwned(this) ) then
1767 AllInOneInventoryFrameItemButton_OnEnter();
1768 else
1769 this.updateTooltip = nil;
1770 end
1771 end
1772  
1773 function AllInOneInventoryFrame_UpdateLookIfNeeded()
1774 local slots = AllInOneInventory_GetBagsTotalSlots();
1775 local frame = getglobal("AllInOneInventoryFrame");
1776 if ( ( frame ) and ( not frame.size ) or ( slots ~= frame.size ) ) then
1777 AllInOneInventoryFrame_UpdateLook(frame, slots);
1778 return true;
1779 end
1780 return false;
1781 end
1782  
1783 function AllInOneInventoryFrame_SetColumns(col)
1784 if ( type(col) ~= "number" ) then
1785 col = tonumber(col);
1786 end
1787 if ( not col ) then
1788 return;
1789 end
1790 if ( ( col >= ALLINONEINVENTORY_COLUMNS_MIN )
1791 and ( col <= ALLINONEINVENTORY_COLUMNS_MAX )
1792 ) then
1793 AllInOneInventory_Columns = col;
1794 AllInOneInventoryFrame_UpdateLook(getglobal("AllInOneInventoryFrame"), AllInOneInventory_GetBagsTotalSlots());
1795 end
1796 end
1797  
1798 function AllInOneInventoryFrame_GetAppropriateHeight(rows)
1799 return ALLINONEINVENTORY_BASE_HEIGHT + ( ALLINONEINVENTORY_ROW_HEIGHT * rows );
1800 end
1801  
1802 function AllInOneInventoryFrame_GetAppropriateWidth(cols)
1803 return ALLINONEINVENTORY_BASE_WIDTH + ( ALLINONEINVENTORY_COL_WIDTH * cols );
1804 end
1805  
1806  
1807 AllInOneInventoryFrame_AnchorWidgetList = { "MainMenuBar"};
1808  
1809 function AllInOneInventoryFrame_AddAnchorWidget(widgetName)
1810 table.insert(AllInOneInventoryFrame_AnchorWidgetList, widgetName);
1811 end
1812  
1813 function AllInOneInventoryFrame_GetAnchorWidget()
1814 local obj = nil;
1815 for k, v in AllInOneInventoryFrame_AnchorWidgetList do
1816 obj = getglobal(v);
1817 if ( obj ) and ( obj:IsVisible() ) then
1818 return v;
1819 end
1820 end
1821 return "UIParent";
1822 end
1823  
1824 function AllInOneInventoryFrame_ResetButton()
1825 AllInOneInventoryFrame_ResetPosition(AllInOneInventoryFrame);
1826 end
1827  
1828 function AllInOneInventoryFrame_ResetPosition(frame)
1829 frame:ClearAllPoints();
1830 frame:SetPoint("CENTER", "UIParent", "CENTER");
1831 end
1832  
1833 function AllInOneInventoryFrame_ResetPositionOld(frame)
1834 local anchorWidgetName = AllInOneInventoryFrame_GetAnchorWidget();
1835 local anchorWidget = getglobal(anchorWidgetName);
1836 local anchorWidgetYOffset = 5;
1837  
1838 if ( anchorWidgetName == "UIParent" ) then
1839 anchorWidgetYOffset = 54;
1840 end
1841  
1842 local xPos = -17;
1843  
1844 if ( SideBarLeft_ShouldShiftBagFramesLeftOnShow ) then
1845 if ( ( SideBarLeft_ShouldShiftBagFramesLeftOnShow() ) and ( SideBar:IsVisible() ) ) then
1846 local temp = UIParent:GetWidth() - anchorWidget:GetWidth();
1847 if ( SideBarLeft_GetSafeOffset ) then
1848 xPos = temp + SideBarLeft_GetSafeOffset();
1849 else
1850 xPos = temp;
1851 end
1852 if ( xPos > 0 ) then
1853 xPos = 1-xPos;
1854 end
1855 end
1856 end
1857  
1858 frame:ClearAllPoints();
1859 frame:SetPoint("BOTTOMRIGHT", anchorWidgetName, "TOPRIGHT", xPos, anchorWidgetYOffset);
1860 end
1861  
1862 function AllInOneInventoryFrame_DoNothing()
1863 end
1864  
1865 function AllInOneInventoryFrame_UpdateLook(frame, frameSize)
1866 if ( not frame ) then
1867 frame = getglobal("AllInOneInventoryFrame");
1868 end
1869 if ( ( not frameSize ) or ( frameSize == 0 ) ) then
1870 frameSize = AllInOneInventory_GetBagsTotalSlots()
1871 end
1872 if ( not frame ) or ( not frameSize ) or ( frameSize == 0 )then
1873 AIOI_ScheduleByName("AIOI_UPDATE_LOOK", 1, AllInOneInventoryFrame_UpdateLook, frame, frameSize);
1874 else
1875 AIOI_ScheduleByName("AIOI_UPDATE_LOOK", 1, AllInOneInventoryFrame_DoNothing);
1876 end
1877 frame.size = frameSize;
1878  
1879 local name = frame:GetName();
1880 -- local bgTexture = getglobal(name.."BackgroundTexture");
1881 getglobal(name.."MoneyFrame"):Show();
1882 local columns = AllInOneInventory_Columns;
1883 if (columns > frame.size) then columns = frame.size; end -- doesn't make sense to have more columns than slots, just in case sarf decides to increase the upper limit
1884 if ( columns <= 0 ) then
1885 columns = 8;
1886 end
1887 local rows = ceil(frame.size / columns);
1888 if ( rows <= 0 ) then
1889 rows = 1;
1890 end
1891 -- Added a short name, in case the long name doesn't fit ;)
1892 if (columns <= 4) then
1893 getglobal(name.."Name"):SetText(ALLINONEINVENTORY_BAG_TITLE_SHORT);
1894 else
1895 getglobal(name.."Name"):SetText(ALLINONEINVENTORY_BAG_TITLE_LONG);
1896 end
1897  
1898 local oldHeight = frame:GetHeight();
1899 local height = AllInOneInventoryFrame_GetAppropriateHeight(rows);
1900 frame:SetHeight(height);
1901  
1902 local oldWidth = frame:GetWidth();
1903 local width = AllInOneInventoryFrame_GetAppropriateWidth(columns);
1904 frame:SetWidth(width);
1905 if ( frame:IsVisible() ) then
1906 frame:Show();
1907 end
1908  
1909 -- bgTexture:Hide();
1910  
1911 local diffHeight = ceil(height - oldHeight);
1912 local diffWidth = ceil(width - oldWidth);
1913  
1914 if ( ( ( diffHeight > 1 ) or ( diffHeight < -1 ) ) or ( ( diffWidth > 1 ) or ( diffWidth < -1 ) ) ) then
1915 --AllInOneInventoryFrame_ResetPosition(frame);
1916 end
1917  
1918 -- texture code to make it look like a normal bag...
1919 local lastColumnIsComplete = false;
1920 if (rows == floor(frame.size / columns)) then lastColumnIsComplete = true; end
1921  
1922 -- set textures for moneyframe:
1923 getglobal(name.."TextureBottomMiddle"):SetWidth((columns - 2) * 42 + 70);
1924  
1925 -- show the first row (assumes that columns < frame.size)
1926 local texture = getglobal(name.."ItemTexture1");
1927 if ( texture ) then
1928 texture:SetTexture("Interface\\AddOns\\AllInOneInventory\\Skin\\first_right");
1929 texture:SetPoint("TOPLEFT", name.."TextureBottomRight", "TOPLEFT", -35, 43);
1930 texture:Show();
1931 end
1932 for i=2, (columns-1), 1 do
1933 local texture = getglobal(name.."ItemTexture"..i);
1934 if ( texture ) then
1935 texture:SetTexture("Interface\\AddOns\\AllInOneInventory\\Skin\\first_middle");
1936 texture:SetPoint("TOPLEFT", name.."ItemTexture"..(i - 1), "TOPLEFT", -42, 0);
1937 texture:Show();
1938 end
1939 end
1940 local texture = getglobal(name.."ItemTexture"..columns);
1941 if ( texture ) then
1942 texture:SetTexture("Interface\\AddOns\\AllInOneInventory\\Skin\\first_left");
1943 texture:SetPoint("TOPLEFT", name.."ItemTexture"..(columns - 1), "TOPLEFT", -47, 0);
1944 texture:Show();
1945 end
1946  
1947 -- show the other rows
1948 for j=1, (rows - 1), 1 do
1949 local texture = getglobal(name.."ItemTexture"..(j * columns + 1));
1950 if ( texture ) then
1951 texture:SetTexture("Interface\\AddOns\\AllInOneInventory\\Skin\\second_right");
1952 local textureOffsetX = 0; if (j == 1) then textureOffsetX = -3; end
1953 texture:SetPoint("TOPLEFT", name.."ItemTexture"..((j - 1) * columns + 1), "TOPLEFT", textureOffsetX, 41);
1954 texture:Show();
1955 end
1956 local slotsInRow = columns;
1957 if ((j + 1) * columns > frame.size) then slotsInRow = frame.size - (j * columns); end
1958 for i=2, (slotsInRow - 1), 1 do
1959 local texture = getglobal(name.."ItemTexture"..(j * columns + i));
1960 if ( texture ) then
1961 texture:SetTexture("Interface\\AddOns\\AllInOneInventory\\Skin\\second_middle");
1962 texture:SetPoint("TOPLEFT", name.."ItemTexture"..(j * columns + i - 1), "TOPLEFT", -42, 0);
1963 texture:Show();
1964 end
1965 end
1966 if (slotsInRow == columns) then
1967 local texture = getglobal(name.."ItemTexture"..(j * columns + slotsInRow));
1968 if ( texture ) then
1969 texture:SetTexture("Interface\\AddOns\\AllInOneInventory\\Skin\\second_left");
1970 texture:SetPoint("TOPLEFT", name.."ItemTexture"..(j * columns + slotsInRow - 1), "TOPLEFT", -44, 0);
1971 texture:Show();
1972 end
1973 elseif (slotsInRow > 1) then
1974 local texture = getglobal(name.."ItemTexture"..(j * columns + slotsInRow));
1975 if ( texture ) then
1976 texture:SetTexture("Interface\\AddOns\\AllInOneInventory\\Skin\\second_middle");
1977 texture:SetPoint("TOPLEFT", name.."ItemTexture"..(j * columns + slotsInRow - 1), "TOPLEFT", -42, 0);
1978 texture:Show();
1979 end
1980 end
1981 end
1982  
1983 getglobal(name.."TextureTopMiddle"):SetWidth((columns - 2) * 42 + 22);
1984 if (lastColumnIsComplete) then
1985 local textureOffsetX = 0; if (frame.size == columns) then textureOffsetX = -3; end
1986 getglobal(name.."TextureTopRight"):SetTexture("Interface\\AddOns\\AllInOneInventory\\Skin\\top_right_large");
1987 getglobal(name.."TextureTopRight"):SetPoint("BOTTOMLEFT", name.."ItemTexture"..((rows - 1) * columns + 1), "TOPLEFT", 19 + textureOffsetX, 0);
1988 getglobal(name.."TextureTopMiddle"):SetPoint("BOTTOMRIGHT", name.."TextureTopRight", "BOTTOMLEFT", 0, -34);
1989 getglobal(name.."CloseButton"):SetPoint("BOTTOMLEFT", name.."TextureTopRight", "BOTTOMLEFT", 4, 12);
1990 else
1991 getglobal(name.."TextureTopRight"):SetTexture("Interface\\AddOns\\AllInOneInventory\\Skin\\top_right_small");
1992 getglobal(name.."TextureTopRight"):SetPoint("BOTTOMLEFT", name.."ItemTexture"..((rows - 1) * columns + 1), "TOPLEFT", 19, 0);
1993 getglobal(name.."TextureTopMiddle"):SetPoint("BOTTOMRIGHT", name.."TextureTopRight", "BOTTOMLEFT", 0, -51);
1994 getglobal(name.."CloseButton"):SetPoint("BOTTOMLEFT", name.."TextureTopRight", "BOTTOMLEFT", 4, -5);
1995 end
1996  
1997 for j=0, (frame.size - 1), 1 do
1998 local itemButton = getglobal(name.."Item"..(frame.size - j));
1999 itemButton:SetID(frame.size - j);
2000 itemButton:ClearAllPoints();
2001 -- Set first button
2002 if ( j == 0 ) then
2003 itemButton:SetPoint("TOPLEFT", name.."ItemTexture1", "TOPLEFT", 4, -1);
2004 else
2005 if ( mod(j, columns) == 0 ) then
2006 itemButton:SetPoint("TOPLEFT", name.."Item"..(frame.size - j + columns), "TOPLEFT", 0, 41);
2007 else
2008 itemButton:SetPoint("TOPLEFT", name.."Item"..(frame.size - j + 1), "TOPLEFT", -42, 0);
2009 end
2010 end
2011 itemButton:Show();
2012  
2013 AllInOneInventoryFrame_UpdateButton(frame, (frame.size - j));
2014 end
2015 local button = nil;
2016 local texture = nil;
2017 for i = frame.size+1, ALLINONEINVENTORY_MAX_ID do
2018 button = getglobal(name.."Item"..i);
2019 if ( button ) then
2020 button:Hide();
2021 end
2022 texture = getglobal(name.."ItemTexture"..i); -- hide the textures, that are not needed
2023 if ( texture ) then
2024 texture:Hide();
2025 end
2026 end
2027 end
2028  
2029 -- Thanks to 'lugo for this fix!
2030 function AllInOneInventory_OpenAllBags(forceOpen)
2031 if ( AllInOneInventory_ReplaceBags == 1 ) then
2032 local bagsOpen = 0;
2033 local totalBags = 1;
2034 for i=1, NUM_CONTAINER_FRAMES, 1 do
2035 local containerFrame = getglobal(AllInOneInventory_ContainerFrames[i]);
2036 if ( not containerFrame ) then break; end
2037 local bagButton = getglobal("CharacterBag"..(i -1).."Slot");
2038 if (i <= NUM_BAG_FRAMES) then
2039 local id = bagButton:GetID() - CharacterBag0Slot:GetID() + 1;
2040 if ((not AllInOneInventory_ShouldOverrideBag(id)) and (GetContainerNumSlots(id) > 0)) then
2041 totalBags = totalBags + 1;
2042 end
2043 end
2044 if ( containerFrame:IsVisible() ) then
2045 containerFrame:Hide();
2046 if (containerFrame:GetID() <= NUM_BAG_FRAMES) then
2047 bagsOpen = bagsOpen + 1;
2048 end
2049 end
2050 end
2051  
2052 if (AllInOneInventoryFrame:IsVisible()) then
2053 CloseAllInOneInventoryFrame();
2054 bagsOpen = bagsOpen + 1;
2055 end
2056  
2057 if ( bagsOpen == totalBags and not forceOpen ) then
2058 return;
2059 end
2060  
2061 ToggleAllInOneInventoryFrame();
2062 if ( AllInOneInventoryFrame:IsVisible() ) then
2063 AllInOneInventory_OpenBag(1);
2064 AllInOneInventory_OpenBag(2);
2065 AllInOneInventory_OpenBag(3);
2066 AllInOneInventory_OpenBag(4);
2067 end
2068 return;
2069 end
2070 AllInOneInventory_Saved_OpenAllBags(forceOpen);
2071 end
2072  
2073 function AllInOneInventory_DepositBox_RefreshWindows()
2074 AllInOneInventory_Saved_DepositBox_RefreshWindows();
2075 MoneyFrame_Update("AllInOneInventoryFrameMoneyFrame", GetMoney() - GetCursorMoney());
2076 end
2077  
2078  
2079 function AIOI_LootLink_SetTooltipMoney(frame, count, money, stack)
2080 if ( not money ) then return; end
2081 if ( money <= 0) then return; end
2082 if ( count and count > 1 ) then
2083 money = money * count;
2084 frame:AddLine(format(LOOTLINK_SELL_PRICE_N, count), 1.0, 1.0, 1.0);
2085 elseif( stack ) then
2086 frame:AddLine(LOOTLINK_SELL_PRICE_EACH, 1.0, 1.0, 1.0);
2087 else
2088 frame:AddLine(LOOTLINK_SELL_PRICE, 1.0, 1.0, 1.0);
2089 end
2090  
2091 local numLines = frame:NumLines();
2092 local moneyFrame = getglobal(frame:GetName().."MoneyFrame");
2093 local newLine = frame:GetName().."TextLeft"..numLines;
2094  
2095 moneyFrame:SetPoint("LEFT", newLine, "RIGHT", 4, 0);
2096 moneyFrame:Show();
2097 MoneyFrame_Update(moneyFrame:GetName(), money);
2098 frame:SetMinimumWidth(moneyFrame:GetWidth() + getglobal(newLine):GetWidth() - 10);
2099 end
2100  
2101 function AllInOneInventory_SellValue_OnShow()
2102 if ( AllInOneInventory_Patching_Tooltip ~= 1 ) then
2103 AllInOneInventory_Saved_SellValue_OnShow();
2104 end
2105 end
2106  
2107 function AllInOneInventory_StartMoving(frame)
2108 if ( not frame.isMoving ) and ( frame.isLocked ~= 1 ) then
2109 frame:StartMoving();
2110 frame.isMoving = true;
2111 end
2112 end
2113  
2114 function AllInOneInventory_StopMoving(frame)
2115 if ( frame.isMoving ) then
2116 frame:StopMovingOrSizing();
2117 frame.isMoving = false;
2118 end
2119 end
2120  
2121 function AllInOneInventory_ToggleLock(frame)
2122 if ( frame.isLocked ~= 1 ) then
2123 frame.isLocked = 1;
2124 else
2125 frame.isLocked = nil;
2126 end
2127 end
2128  
2129 function AllInOneInventory_SetLock(frame)
2130 if ( not frame ) then
2131 frame = AllInOneInventoryFrame;
2132 end
2133 local lockButton = getglobal(frame:GetName().."LockButton");
2134 if ( AllInOneInventory_Locked ~= 1 ) then
2135 frame.isLocked = 0;
2136 if ( lockButton ) then
2137 lockButton:SetChecked(1);
2138 end
2139 else
2140 AllInOneInventory_StopMoving(frame);
2141 frame.isLocked = 1;
2142 if ( lockButton ) then
2143 lockButton:SetChecked(0);
2144 end
2145 end
2146 end
2147  
2148 function AllInOneInventory_GetLock(frame)
2149 if ( frame.isLocked == 1 ) then
2150 return 1;
2151 else
2152 return 0;
2153 end
2154 end
2155  
2156 function ToggleLockAllInOneInventoryFrame()
2157 AllInOneInventory_Toggle_Locked(-1);
2158 end
2159  
2160 function AllInOneInventory_Toggle_Locked(toggle)
2161 AllInOneInventory_DoToggle_Locked(toggle, true);
2162 end
2163  
2164 function AllInOneInventory_Toggle_Locked_NoChat(toggle)
2165 AllInOneInventory_DoToggle_Locked(toggle, false);
2166 end
2167  
2168 -- does the actual toggling
2169 function AllInOneInventory_DoToggle_Locked(toggle, showText)
2170 local newvalue = 0;
2171 if ( showText ) then
2172 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_Locked", "ALLINONEINVENTORY_CHAT_LOCKED_ENABLED", "ALLINONEINVENTORY_CHAT_LOCKED_DISABLED");
2173 else
2174 newvalue = AllInOneInventory_Generic_Toggle(toggle, "AllInOneInventory_Locked");
2175 end
2176 local frame = getglobal("AllInOneInventoryFrame");
2177 if ( frame ) then
2178 AllInOneInventory_SetLock(frame, newvalue);
2179 end
2180 end
2181  
2182 function AllInOneInventory_Toggle_ExcludedSlot(bag, slot)
2183 return AllInOneInventory_DoToggle_ExcludedSlot(bag, slot, 1)
2184 end
2185  
2186 function AllInOneInventory_Toggle_ExcludedSlot_NoChat(bag, slot)
2187 return AllInOneInventory_DoToggle_ExcludedSlot(bag, slot)
2188 end
2189  
2190 function AllInOneInventory_DoToggle_ExcludedSlot(bag, slot, showText)
2191 if ( bag ) and ( slot ) then
2192 if ( type(bag) == "string" ) then
2193 bag = tonumber(bag);
2194 end
2195 if ( type(slot) == "string" ) then
2196 slot = tonumber(slot);
2197 end
2198 end
2199 if ( not bag ) or ( not slot ) then
2200 if ( showText ) then
2201 AllInOneInventory_Print(ALLINONEINVENTORY_TOGGLE_SLOT_FAIL);
2202 end
2203 return false;
2204 end
2205 if ( not AllInOneInventory_ExcludedSlots ) then
2206 AllInOneInventory_ExcludedSlots = {};
2207 end
2208 if ( not AllInOneInventory_ExcludedSlots[bag] ) then
2209 AllInOneInventory_ExcludedSlots[bag] = {};
2210 end
2211 local newState = ALLINONEINVENTORY_TOGGLE_SLOT_OFF;
2212 if ( not AllInOneInventory_ExcludedSlots[bag][slot] ) then
2213 newState = ALLINONEINVENTORY_TOGGLE_SLOT_ON;
2214 AllInOneInventory_ExcludedSlots[bag][slot] = 1;
2215 else
2216 AllInOneInventory_ExcludedSlots[bag][slot] = nil;
2217 end
2218 if ( showText ) then
2219 AllInOneInventory_Print(string.format(ALLINONEINVENTORY_TOGGLE_SLOT, bag, slot, newState));
2220 end
2221 return true;
2222 end
2223  
2224 function AllInOneInventory_OnMouseDown(button, frame)
2225 --[[
2226 if ( button == "LeftButton" ) and ( IsShiftKeyDown() ) then
2227 ToggleLockAllInOneInventoryFrame();
2228 else
2229 end
2230 ]]--
2231 AllInOneInventory_StartMoving(frame);
2232 end
2233  
2234 setglobal("AIOI_ScheduleByName", AIOI_ScheduleByName_Own);
2235 setglobal("AIOI_Schedule", AIOI_Schedule_Own);
2236  
2237