· 9 years ago · Jan 30, 2017, 09:04 PM
1--[[ =================================================================
2 Description:
3 Type /ubi or /uberinventory to see what you currently own,
4 whether it is in the bank or in the bags you carry.
5 So now where ever you are in the World of Warcraft you can
6 get an overview of all your loot.
7
8 Dependencies:
9 None
10
11 Credits:
12 A big 'Thank You' to all the people at Blizzard Entertainment
13 for making World of Warcraft.
14 ================================================================= --]]
15
16-- Local globals
17 local _G = _G;
18 local strfind, strgsub, strlower = string.find, string.gsub, string.lower;
19 local floor, ceil, abs, tonumber = math.floor, math.ceil, math.abs, tonumber;
20 local pairs, tinsert, tsort, wipe = pairs, table.insert, table.sort, wipe;
21
22-- Classes structure (used to be provided by GetAuctionItemClasses and GetAuctionItemSubClasses)
23 UBI_CLASSES = { { id = 1, name = UBI_ALL_CLASSES, childs = {} },
24 -- Weapons
25 { id = 2, name = GetItemClassInfo(2)
26 , childs = { AUCTION_SUBCATEGORY_ONE_HANDED
27 , AUCTION_SUBCATEGORY_TWO_HANDED
28 , AUCTION_SUBCATEGORY_RANGED
29 , AUCTION_SUBCATEGORY_MISCELLANEOUS
30 , AUCTION_SUBCATEGORY_OTHER
31 } },
32 -- Armor
33 { id = 3, name = GetItemClassInfo(4)
34 , childs = { GetItemSubClassInfo(4, LE_ITEM_ARMOR_PLATE)
35 , GetItemSubClassInfo(4, LE_ITEM_ARMOR_MAIL)
36 , GetItemSubClassInfo(4, LE_ITEM_ARMOR_LEATHER)
37 , GetItemSubClassInfo(4, LE_ITEM_ARMOR_CLOTH)
38 , GetItemSubClassInfo(4, LE_ITEM_ARMOR_GENERIC)
39 , GetItemSubClassInfo(4, LE_ITEM_ARMOR_COSMETIC)
40 } },
41 -- Container
42 { id = 4, name = GetItemClassInfo(1)
43 , childs = { GetItemSubClassInfo(1,0)
44 , GetItemSubClassInfo(1,1)
45 , GetItemSubClassInfo(1,2)
46 , GetItemSubClassInfo(1,3)
47 , GetItemSubClassInfo(1,4)
48 , GetItemSubClassInfo(1,5)
49 , GetItemSubClassInfo(1,6)
50 , GetItemSubClassInfo(1,7)
51 , GetItemSubClassInfo(1,8)
52 , GetItemSubClassInfo(1,9)
53 , GetItemSubClassInfo(1,10)
54 } },
55 -- Gem
56 { id = 5, name = GetItemClassInfo(3)
57 , childs = { GetItemSubClassInfo(3,0)
58 , GetItemSubClassInfo(3,1)
59 , GetItemSubClassInfo(3,2)
60 , GetItemSubClassInfo(3,3)
61 , GetItemSubClassInfo(3,4)
62 , GetItemSubClassInfo(3,5)
63 , GetItemSubClassInfo(3,6)
64 , GetItemSubClassInfo(3,7)
65 , GetItemSubClassInfo(3,8)
66 , GetItemSubClassInfo(3,9)
67 , GetItemSubClassInfo(3,10)
68 , GetItemSubClassInfo(3,11)
69 } },
70 -- Item Enhancement
71 { id = 6, name = GetItemClassInfo(8)
72 , childs = { GetItemSubClassInfo(8,0)
73 , GetItemSubClassInfo(8,1)
74 , GetItemSubClassInfo(8,2)
75 , GetItemSubClassInfo(8,3)
76 , GetItemSubClassInfo(8,4)
77 , GetItemSubClassInfo(8,5)
78 , GetItemSubClassInfo(8,6)
79 , GetItemSubClassInfo(8,7)
80 , GetItemSubClassInfo(8,8)
81 , GetItemSubClassInfo(8,9)
82 , GetItemSubClassInfo(8,10)
83 , GetItemSubClassInfo(8,11)
84 , GetItemSubClassInfo(8,12)
85 , GetItemSubClassInfo(8,13)
86 } },
87 -- Consumable
88 { id = 7, name = GetItemClassInfo(0)
89 , childs = { GetItemSubClassInfo(0,0)
90 , GetItemSubClassInfo(0,1)
91 , GetItemSubClassInfo(0,2)
92 , GetItemSubClassInfo(0,3)
93 , GetItemSubClassInfo(0,5)
94 , GetItemSubClassInfo(0,7)
95 , GetItemSubClassInfo(0,9)
96 , GetItemSubClassInfo(0,8)
97 } },
98 -- Glyph
99 { id = 8, name = GetItemClassInfo(16)
100 , childs = { GetItemSubClassInfo(16,1)
101 , GetItemSubClassInfo(16,2)
102 , GetItemSubClassInfo(16,3)
103 , GetItemSubClassInfo(16,4)
104 , GetItemSubClassInfo(16,5)
105 , GetItemSubClassInfo(16,6)
106 , GetItemSubClassInfo(16,7)
107 , GetItemSubClassInfo(16,8)
108 , GetItemSubClassInfo(16,9)
109 , GetItemSubClassInfo(16,10)
110 , GetItemSubClassInfo(16,11)
111 , GetItemSubClassInfo(16,12)
112 } },
113 -- Trade Goods
114 { id = 9, name = GetItemClassInfo(7)
115 , childs = { GetItemSubClassInfo(7,5)
116 , GetItemSubClassInfo(7,6)
117 , GetItemSubClassInfo(7,7)
118 , GetItemSubClassInfo(7,8)
119 , GetItemSubClassInfo(7,9)
120 , GetItemSubClassInfo(7,12)
121 , GetItemSubClassInfo(7,16)
122 , GetItemSubClassInfo(7,4)
123 , GetItemSubClassInfo(7,1)
124 , GetItemSubClassInfo(7,10)
125 , GetItemSubClassInfo(7,11)
126 } },
127 -- Recipe
128 { id = 10, name = GetItemClassInfo(9)
129 , childs = { GetItemSubClassInfo(9,1)
130 , GetItemSubClassInfo(9,2)
131 , GetItemSubClassInfo(9,3)
132 , GetItemSubClassInfo(9,4)
133 , GetItemSubClassInfo(9,6)
134 , GetItemSubClassInfo(9,8)
135 , GetItemSubClassInfo(9,10)
136 , GetItemSubClassInfo(9,11)
137 , GetItemSubClassInfo(9,5)
138 , GetItemSubClassInfo(9,7)
139 , GetItemSubClassInfo(9,9)
140 , GetItemSubClassInfo(9,0)
141 } },
142 -- Battle Pets
143 { id = 11, name = GetItemClassInfo(17)
144 , childs = { GetItemSubClassInfo(17,0)
145 , GetItemSubClassInfo(17,1)
146 , GetItemSubClassInfo(17,2)
147 , GetItemSubClassInfo(17,3)
148 , GetItemSubClassInfo(17,4)
149 , GetItemSubClassInfo(17,5)
150 , GetItemSubClassInfo(17,6)
151 , GetItemSubClassInfo(17,7)
152 , GetItemSubClassInfo(17,8)
153 , GetItemSubClassInfo(17,9)
154 } },
155 -- Quest Items
156 { id = 12, name = GetItemClassInfo(12)
157 , childs = {} },
158 -- Miscellaneous
159 { id = 13, name = GetItemClassInfo(15)
160 , childs = { GetItemSubClassInfo(15,0)
161 , GetItemSubClassInfo(15,1)
162 , GetItemSubClassInfo(15,2)
163 , GetItemSubClassInfo(15,3)
164 , GetItemSubClassInfo(15,4)
165 , GetItemSubClassInfo(15,5)
166 } },
167 -- WoW Token
168 { id = 14, name = GetItemClassInfo(18)
169 , childs = {} },
170 };
171
172-- Information on tokens
173 local UBI_Currencies = {
174 -- Legiom
175 { id=-1, name = EXPANSION_NAME6, force = false },
176 { id=1155, force = true }, -- Ancient Mana
177 { id=1275, force = true }, -- Curious Coin
178 { id=1226, force = true }, -- Nethershard
179 { id=1220, force = true }, -- Order Resources
180 { id=1273, force = true }, -- Seal of Broken Fate
181 { id=1154, force = true }, -- Shadowy Coins
182 { id=1149, force = true }, -- Sightless Eye
183 { id=1268, force = true }, -- Timeworn Artifact
184
185 -- Dungeon and Raid
186 { id=-2, name = LFG_TYPE_DUNGEON.." & "..LFG_TYPE_RAID, force = false },
187 { id=615, force = true }, -- Mote of Darkness
188 { id=395, force = true }, -- Justice Points
189 { id=1166, force = true }, -- Timewarped Badge
190 { id=614, force = true }, -- Mote of Darkness
191 { id=396, force = true }, -- Valor Points
192
193 -- Miscellaneous
194 { id=-3, name = MISCELLANEOUS, force = false },
195 { id=515, force = true }, -- Darkmoon Prize Ticket
196 { id=81, force = true }, -- Epicurean's Award
197 { id=402, force = true }, -- Ironpaw Token
198 { id=416, force = true }, -- Mark of the World Tree
199
200 -- Player vs Player
201 { id=-4, name = PLAYER_V_PLAYER, force = false },
202 { id=391, force = true }, -- Tol Barad Commendation
203
204 -- Warlords of Draenor
205 { id=-5, name = EXPANSION_NAME5, force = false },
206 { id=823, force = true }, -- Apexis Crystal
207 { id=944, force = true }, -- Artifact Fragment
208 { id=824, force = true }, -- Garrison Resources
209 { id=994, force = true }, -- Seal of Tempered Fate
210 { id=1101, force = true }, -- Oil
211 { id=1129, force = true }, -- Seal of Inevitable Fate
212
213 -- Mist of Pandaria
214 { id=-6, name = EXPANSION_NAME4, force = false },
215 { id=738, force = true }, -- Lesser Charm of Good Fortune
216 { id=697, force = true }, -- Elder Charm of Good Fortune
217 { id=777, force = true }, -- Timeless Coin
218 { id=776, force = true }, -- Warforged Seal
219 { id=752, force = true }, -- Mogu Rune of Fate
220
221 -- Cataclysm
222 { id=-7, name = EXPANSION_NAME3, force = false },
223 { id=361, force = true }, -- Illustrious Jewelcrafter's Token
224 { id=698, force = true }, -- Zen Jewelcrafter's Token
225
226 -- Wrath of the Lich King
227 { id=-8, name = EXPANSION_NAME2, force = false },
228 { id=241, force = true }, -- Champion's Seal
229 { id=61, force = true }, -- Dalaran Jewelcrafting Token
230
231 };
232
233-- Text and tooltips for checkbuttons
234 UBI_CheckButtons = {
235 { text = UBI_OPTION_MONEY, tooltip = UBI_OPTION_MONEY_TIP },
236 { text = UBI_OPTION_BALANCE, tooltip = UBI_OPTION_BALANCE_TIP },
237 { text = UBI_OPTION_SELLPRICES, tooltip = UBI_OPTION_SELLPRICES_TIP },
238 { text = UBI_OPTION_RECIPEPRICES, tooltip = UBI_OPTION_RECIPEPRICES_TIP },
239 { text = UBI_OPTION_QUESTREWARD, tooltip = UBI_OPTION_QUESTREWARD_TIP },
240 { text = UBI_OPTION_RECIPEDROP, tooltip = UBI_OPTION_RECIPEDROP_TIP },
241 { text = UBI_OPTION_TAKEMONEY, tooltip = UBI_OPTION_TAKEMONEY_TIP },
242 { text = UBI_OPTION_SHOWMAP, tooltip = UBI_OPTION_SHOWMAP_TIP },
243 { text = UBI_OPTION_GBSEND, tooltip = UBI_OPTION_GBSEND_TIP },
244 { text = UBI_OPTION_GBRECEIVE, tooltip = UBI_OPTION_GBRECEIVE_TIP },
245 { text = UBI_OPTION_WARN_MAILEXPIRE, tooltip = UBI_OPTION_WARN_MAILEXPIRE_TIP },
246 { text = UBI_OPTION_HIGHLIGHT, tooltip = UBI_OPTION_HIGHLIGHT_TIP },
247 { text = UBI_OPTION_SHOWTOOLTIP, tooltip = UBI_OPTION_SHOWTOOLTIP_TIP },
248 { text = UBI_OPTION_ITEMCOUNT, tooltip = UBI_OPTION_ITEMCOUNT_TIP },
249 { text = UBI_OPTION_GBTRACK, tooltip = UBI_OPTION_GBTRACK_TIP },
250 { text = UBI_OPTION_PRICES_VENDOR, tooltip = UBI_OPTION_PRICES_VENDOR_TIP },
251 { text = UBI_OPTION_PRICES_AH, tooltip = UBI_OPTION_PRICES_AH_TIP },
252 };
253
254-- Static dialogs
255 StaticPopupDialogs["UBI_CONFIRM_DELETE"] = {
256 text = "%s",
257 button1 = YES,
258 button2 = NO,
259 timeout = 10,
260 whileDead = 1,
261 exclusive = 1,
262 showAlert = 1,
263 hideOnEscape = 1
264 };
265
266-- Enable/Disable an UI object
267 function UberInventory_SetState( object, state )
268 if ( object ) then
269 if ( state ) then
270 object:Enable();
271 else
272 object:Disable();
273 end;
274 end;
275 end;
276
277-- UberInventory task: Collect mailbox cash
278 function UBI_Task_CollectCash( mailid )
279 -- Mail info
280 local _, _, mailSender, mailSubject, cashAttached = GetInboxHeaderInfo( mailid );
281 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo( mailid );
282
283 if ( cashAttached > 0 ) then
284 -- Report cash attached to message
285 UberInventory_Message( UBI_MAIL_CASH:format( GetCoinTextureString( cashAttached ), mailSender, mailSubject ), true );
286
287 -- Take the money
288 TakeInboxMoney( mailid );
289 end;
290 end;
291
292-- UberInventory task: Send stream end indication
293 function UBI_Task_SendMessage( task, info )
294 -- Define valid tasks
295 local valid_tasks = { VERINFO=1, GBSTART=1, GBITEM=1, GBCASH=1, GBEND=1, GBREQUEST=1 };
296
297 -- Only send message when in a guild and a valid task has been provided
298 if ( IsInGuild() and valid_tasks[task] ) then
299 if ( info ) then
300 SendAddonMessage( "UBI", "UBI:"..task.." "..info, "GUILD" );
301 else
302 SendAddonMessage( "UBI", "UBI:"..task, "GUILD" );
303 end;
304 end;
305 end;
306
307-- Upgrade data structures
308 function UberInventory_Upgrade()
309 -- From global to local
310 local UBI_Options = UBI_Options;
311 local UBI_Data = UBI_Data;
312
313 -- Upgrade process
314 if ( UBI_Options["version"] ~= UBI_VERSION ) then
315 -- Show upgrade message
316 UberInventory_Message( UBI_UPGRADE, true );
317
318 -- Upgrade to version 6.1
319 if ( UBI_Options["version"] < "6.1" ) then
320 if ( not UBI_Options["track_gb_data"] ) then
321 UBI_Options["track_gb_data"] = true;
322 end;
323 end;
324
325 -- Upgrade to version 6.2
326 if ( UBI_Options["version"] < "6.2" ) then
327 -- Overwrite and notify user (Ticket #15)
328 UBI_Options["show_item_count"] = true;
329 UberInventory_Message( C_RED.."The setting for "..C_CLOSE..C_WHITE.."'Show item count info"..C_CLOSE..C_RED.." has been reset to "..C_CLOSE..C_BLUE.."true"..C_CLOSE, true );
330 end;
331
332 -- Upgrade to version 6.4
333 if ( UBI_Options["version"] < "6.4" ) then
334 UBI_Options["pricing_data"] = "vendor";
335 end;
336
337 -- Upgrade to version 7.1
338 if ( UBI_Options["version"] < "7.1" ) then
339 -- Play warning sound
340 PlaySound( "RaidWarning" );
341
342 -- Wipe all data
343 UBI_Data = {};
344
345 -- Alert user of data wipe
346 UberInventory_Message( C_RED.."The data storage has been reset. Please revisit all your characters (including Bank, Mailbox, Void Storage) to collect all item data."..C_CLOSE, true );
347 end;
348
349 -- Set current version
350 UBI_Options["version"] = UBI_VERSION;
351 end;
352 end;
353
354-- Days since visit
355 function UberInventory_DaysSince( visit )
356 local timediff;
357 local today = time( UberInventory_GetDateTime() );
358
359 if ( type( visit ) == "table" ) then
360 timediff = difftime( today, time( visit ) or today );
361 else
362 timediff = difftime( today, visit or today )
363 end;
364
365 return floor( timediff / UBI_SEC_IN_DAY ), SecondsToTime( timediff );
366 end;
367
368-- Send message to the default chat frame
369 function UberInventory_Message( msg, prefix )
370 -- Initialize
371 local prefixText = "";
372
373 -- Add application prefix
374 if ( prefix and true ) then
375 prefixText = C_GREEN.."UBI: "..C_CLOSE;
376 end;
377
378 -- Send message to chatframe
379 DEFAULT_CHAT_FRAME:AddMessage( prefixText..( msg or "" ) );
380 end;
381
382-- Save cash owned
383 function UberInventory_SaveMoney()
384 if ( not UBI_ACTIVE ) then return; end;
385
386 -- Save money
387 UBI_Money["Cash"] = GetMoney();
388 end;
389
390-- Save other currencies owned ( Honor points, Arena points, Tokens, etc )
391 function UberInventory_Save_Currencies()
392 if ( not UBI_ACTIVE ) then return; end;
393
394 -- Save other currencies
395 for key, value in pairs( UBI_Currencies ) do
396 if ( value.id > 0 ) then
397 local name, amount, icon = GetCurrencyInfo( value.id );
398 value.name, value.icon = name, icon;
399 UBI_Money["Currencies"][value.id] = amount or 0;
400 end;
401 end;
402 end;
403
404-- Specialized SetTooltipMoney function (till internal Blizzard code for SetTooltipMoney is fixed)
405 function UberInventory_SetTooltipMoney( tooltip, money, type, prefix, suffix )
406 -- Initialize
407 local moneystring = GetCoinTextureString( money );
408
409 -- Build the string
410 if ( prefix ) then moneystring = prefix..moneystring; end;
411 if ( suffix ) then moneystring = moneystring..suffix; end;
412
413 -- Add info to the tooltip
414 tooltip:AddLine( moneystring.." ", 1.0, 1.0, 1.0 );
415 end;
416
417-- Update slot count information
418 function UberInventory_Update_SlotCount()
419 UberInventoryFrameBagSlots:SetFormattedText( UBI_SLOT_BAGS, UBI_Options["bag_free"] , UBI_Options["bag_max"] );
420 UberInventoryFrameBankSlots:SetFormattedText( UBI_SLOT_BANK, UBI_Options["bank_free"], UBI_Options["bank_max"] );
421 UberInventoryFrameReagentBankSlots:SetFormattedText( UBI_SLOT_REAGENTBANK, UBI_Options["reagent_free"], UBI_Options["reagent_max"] );
422 end;
423
424-- Fetch item prices (buy, sell)
425 function UberInventory_GetItemPrices( itemid )
426 -- Initialize
427 local buyoutPrice, buyPrice, sellPrice;
428
429 if ( itemid ) then
430 local buyPrice = UBI_Prices_Buy[itemid];
431 local sellPrice = select( 11, GetItemInfo( itemid ) );
432
433 -- Get Auction House buyout price (if available)
434 if ( type( GetAuctionBuyout ) == "function" ) then
435 -- AuctionLite, Auctionator, AuctionaMaster
436 buyoutPrice = GetAuctionBuyout( itemid ) or 0;
437 -- elseif ( AucAdvanced ) then
438 -- -- Auctioneer
439 -- buyoutPrice = select( 6, AucAdvanced.Modules.Util.SimpleAuction.Private.GetItems( itemid ) ) or 0;
440 end;
441 end;
442
443 return buyPrice, sellPrice, buyoutPrice;
444 end;
445
446-- Get Date and time (platform independed)
447 function UberInventory_GetDateTime()
448 local _, month_, day_, year_ = CalendarGetDate();
449 local hour_, minute_ = GetGameTime();
450
451 return { year=year_, month=month_, day=day_, hour=hour_, min=minute_, sec=00 };
452 end;
453
454-- Extract info from tooltip
455 function UberInventory_Scan_Tooltip( itemid, color, searchtext )
456 -- Rounding function
457 local function round( x, digit )
458 -- Positions to be shifted
459 local shift = 10 ^ digit;
460
461 -- Round the number to wanted decimals
462 return floor( x * shift + 0.5 ) / shift;
463 end;
464
465 -- Initialize
466 local digits = 4;
467 local colorFound, textFound = false, false;
468 local r, g, b, a, txtLeft, txtRight;
469
470 -- Setup tooltip for extracting data
471 local tooltip = UberInventory_ItemTooltip;
472 tooltip:ClearLines();
473 tooltip:SetHyperlink( UberInventory_GetLink( itemid ) );
474 tooltip:Show();
475
476 -- Correct color precision
477 color.r = round( color.r, digits );
478 color.g = round( color.g, digits );
479 color.b = round( color.b, digits );
480
481 -- Traverse tooltip lines
482 for i = 1, tooltip:NumLines() do
483 -- Get text
484 txtLeft = _G[tooltip:GetName().."TextLeft"..i]:GetText();
485 txtRight = _G[tooltip:GetName().."TextRight"..i]:GetText();
486
487 -- Find the specified color
488 if ( color ) then
489 -- Check left color
490 r, g, b, a = _G[tooltip:GetName().."TextLeft"..i]:GetTextColor();
491
492 -- Check if requested color was used
493 if ( ( round( r, digits ) == color.r ) and
494 ( round( g, digits ) == color.g ) and
495 ( round( b, digits ) == color.b ) and
496 txtLeft ) then
497 colorFound = true;
498 end;
499
500 -- Check right color
501 local r, g, b, a = _G[tooltip:GetName().."TextRight"..i]:GetTextColor();
502
503 -- Check if requested color was used
504 if ( ( round( r, digits ) == color.r ) and
505 ( round( g, digits ) == color.g ) and
506 ( round( b, digits ) == color.b ) and
507 txtRight ) then
508 colorFound = true;
509 end;
510 end;
511
512 -- Find the specified text
513 if ( searchtext and txtLeft ) then
514 textFound = txtLeft:match( searchtext );
515 end;
516 if ( searchtext and txtRight ) then
517 textFound = txtRight:match( searchtext );
518 end;
519
520 -- Stop on first blank line or new-line char
521 if ( txtLeft == "" or txtLeft:find( "\n" ) ) then
522 return colorFound, textFound;
523 end;
524 end;
525
526 return colorFound, textFound;
527 end;
528
529-- Can item used by current player
530 function UberInventory_UsableItem( itemid )
531 -- Initialize
532 local TOOLTIP_RED = { r = 0.99999779462814, g = 0.12548992037773, b = 0.12548992037773 };
533
534 -- Determine if the color red is used within the tooltip
535 local colorFound, textFound = UberInventory_Scan_Tooltip( itemid, TOOLTIP_RED, ITEM_SPELL_KNOWN );
536
537 -- Return result (usable or not)
538 return ( ( not colorFound ) or textFound );
539 end;
540
541-- Build list of usable alts
542 function UberInventory_GetAlts()
543 -- Initialize
544 local UBI_Characters = UBI_Characters;
545 wipe( UBI_Characters );
546
547 -- Traverse all players to determine valid alts
548 for key, value in pairs( UBI_Data[UBI_REALM] ) do
549 if ( key ~= "Guildbank" ) and
550 ( key ~= UBI_PLAYER ) and
551 ( ( UBI_Data[UBI_REALM][key]["Options"]["faction"] or "<Unknown>" ) == UBI_FACTION ) then
552 -- Add alt to the list
553 tinsert( UBI_Characters, key );
554 end;
555 end;
556
557 -- Sort alts alphabetically
558 tsort( UBI_Characters );
559 end;
560
561-- Build list of guildbanks
562 function UberInventory_GetGuildbanks()
563 -- Initialize
564 local UBI_Guildbanks = UBI_Guildbanks;
565 wipe( UBI_Guildbanks );
566
567 -- Traverse all guildbanks
568 for key, value in pairs( UBI_Guildbank ) do
569 if ( ( value["Faction"] or "<Unknown>" ) == UBI_FACTION ) then
570 -- Add alt to the list
571 tinsert( UBI_Guildbanks, key );
572 end;
573 end;
574
575 -- Sort alts alphabetically
576 tsort( UBI_Guildbanks );
577 end;
578
579-- Populate locations internal list
580 function UberInventory_Build_Locations()
581 -- Initialize
582 local UBI_Item, level;
583 local UBI_LocationCounter = UBI_LocationCounter;
584
585 -- Clear locations and reset counter
586 wipe( UBI_LocationList );
587 UBI_LocationCounter = 1;
588
589 -- Custom function for adding items to dropdownbox
590 local function UberInventory_AddLocation( item, itemtype )
591 item.owner = UberInventoryFrameLocationDropDown;
592 UBI_LocationList[UBI_LocationCounter] = { key = item.value, name = item.text, value = strtrim( item.text ), type = itemtype, object = item };
593 UBI_LocationCounter = UBI_LocationCounter + 1;
594 end;
595
596 -- All items (inludes current characters, all guildbanks and all other characters)
597 UBI_Item = { text = UBI_ALL_LOCATIONS,
598 value = UBI_LocationCounter,
599 notCheckable = 1,
600 func = UberInventory_Locations_OnClick,
601 colorCode = "|cFFFFFF00" };
602 UberInventory_AddLocation( UBI_Item, "complete" );
603
604 -- Insert divider
605 UBI_Item = { text = "",
606 isTitle = 1,
607 notCheckable = 1 };
608 UberInventory_AddLocation( UBI_Item, "title" );
609
610 -- Current characters
611 if ( UBI_Options["level"] ) then
612 level = " ["..C_YELLOW..UBI_Options["level"]..C_CLOSE.."]";
613 else
614 level = "";
615 end;
616
617 UBI_Item = { text = UBI_PLAYER..level,
618 value = UBI_LocationCounter,
619 notCheckable = 1,
620 func = UberInventory_Locations_OnClick,
621 colorCode = "|cFFFFFF00" };
622 UberInventory_AddLocation( UBI_Item, "current" );
623
624 -- Add the basic locations (including Guildbank when member of a guild)
625 for key, value in pairs( UBI_LOCATIONS ) do
626 -- Set new item
627 UBI_Item = { text = " "..value,
628 value = UBI_LocationCounter,
629 icon = UBI_LOCATION_TEXTURE[key],
630 notCheckable = 1,
631 func = UberInventory_Locations_OnClick };
632
633 -- Add item to dropdown
634 UberInventory_AddLocation( UBI_Item, "current" );
635 end;
636
637 -- Add separator if there are guildbanks to be added
638 if ( #UBI_Guildbanks > 0 ) then
639 -- Set new item
640 UBI_Item = { text = "",
641 isTitle = 1,
642 notCheckable = 1 };
643 UberInventory_AddLocation( UBI_Item, "title" );
644
645 UBI_Item = { text = UBI_ALL_GUILDBANKS,
646 value = UBI_LocationCounter,
647 notCheckable = 1,
648 func = UberInventory_Locations_OnClick,
649 colorCode = "|cFFFFFF00" };
650 UberInventory_AddLocation( UBI_Item, "all_guildbank" );
651 end;
652
653 -- Add guildbanks (how to determine faction for image?)
654 for key, value in pairs( UBI_Guildbanks ) do
655 -- Set new item
656 UBI_Item = { text = " "..value,
657 value = UBI_LocationCounter,
658 icon = UBI_LOCATION_TEXTURE[7],
659 notCheckable = 1,
660 func = UberInventory_Locations_OnClick };
661
662 -- Add highlight to current players guildbank
663 if ( value == UBI_GUILD ) then
664 UBI_Item.colorCode = ITEM_QUALITY_COLORS[5].hex;
665 end;
666
667 -- Add item to dropdown (Guildbank only added if in a guild)
668 UberInventory_AddLocation( UBI_Item, "guildbank" );
669 end;
670
671 -- Add separator if there are alts to be added
672 if ( #UBI_Characters > 0 ) then
673 -- Set new item
674 UBI_Item = { text = "",
675 isTitle = 1,
676 notCheckable = 1 };
677 UberInventory_AddLocation( UBI_Item, "title" );
678
679 UBI_Item = { text = UBI_ALL_CHARACTERS,
680 value = UBI_LocationCounter,
681 notCheckable = 1,
682 func = UberInventory_Locations_OnClick,
683 colorCode = "|cFFFFFF00" };
684 UberInventory_AddLocation( UBI_Item, "all_character" );
685 end;
686
687 -- Add alts to the list from the same realm and faction (Alliance or Horde)
688 for key, value in pairs( UBI_Characters ) do
689 if ( UBI_Data[UBI_REALM][value]["Options"]["level"] ) then
690 level = " ["..C_YELLOW..UBI_Data[UBI_REALM][value]["Options"]["level"]..C_CLOSE.."]";
691 else
692 level = "";
693 end;
694
695 UBI_Item = { text = " "..value..level,
696 value = UBI_LocationCounter,
697 icon = UBI_LOCATION_TEXTURE[7], -- Faction icon
698 notCheckable = 1,
699 func = UberInventory_Locations_OnClick };
700
701 -- Replace faction icon with class icon if the class is known
702 if ( UBI_Data[UBI_REALM][value]["Options"]["class"] and UBI_Data[UBI_REALM][value]["Options"]["class"] ~= "??" ) then
703 local tLeft, tRight, tTop, tBottom = unpack( CLASS_ICON_TCOORDS[ UBI_Data[UBI_REALM][value]["Options"]["class"] ] );
704
705 UBI_Item.icon = "Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Classes";
706 UBI_Item.tCoordLeft = tLeft;
707 UBI_Item.tCoordRight = tRight;
708 UBI_Item.tCoordTop = tTop;
709 UBI_Item.tCoordBottom = tBottom;
710 end;
711
712 UberInventory_AddLocation( UBI_Item, "character" );
713 end;
714 end;
715
716-- Populate locations dropdown box (Also contains items for alts on the same realm from the same faction (Alliance or Horde))
717 function UberInventory_Locations_Init( self )
718 -- Build list of locations
719 UberInventory_Build_Locations();
720
721 -- Add items to the dropdown box
722 for key, value in pairs( UBI_LocationList ) do
723 -- Add item to dropdown
724 UIDropDownMenu_AddButton( value.object );
725 end;
726 end;
727
728-- Resets position in scrollframe to the top
729 function UberInventory_ScrollToTop()
730 FauxScrollFrame_SetOffset( UberInventoryFrameScroll, 0 );
731 UberInventoryFrameScrollScrollBar:SetValue( 0 );
732 end;
733
734-- Update locations dropdown box
735 function UberInventory_Locations_OnClick( self )
736 UBI_FILTER_LOCATIONS = self.value;
737 UIDropDownMenu_SetText( self.owner, UBI_LocationList[UBI_FILTER_LOCATIONS].value );
738 UberInventory_ScrollToTop();
739 UberInventory_DisplayItems();
740
741 -- Update token info on screen
742 if ( UberInventoryTokens:IsVisible() ) then
743 UberInventory_DisplayTokens();
744 end;
745 end;
746
747-- Populate quality dropdown box
748 function UberInventory_Quality_Init( self )
749 -- Initialize
750 local UBI_Item;
751 local UBI_QUALITY = UBI_QUALITY;
752
753 for key, value in pairs( UBI_QUALITY ) do
754 -- Set new item
755 UBI_Item = { text = value,
756 value = key,
757 owner = UberInventoryFrameQualityDropDown,
758 notCheckable = 1,
759 func = UberInventory_Quality_OnClick,
760 colorCode = ITEM_QUALITY_COLORS[key-2].hex };
761
762 -- Add item to dropdown
763 UIDropDownMenu_AddButton( UBI_Item );
764 end;
765 end;
766
767-- Update quality dropdown box
768 function UberInventory_Quality_OnClick( self )
769 UBI_FILTER_QUALITY = self.value;
770 UIDropDownMenu_SetText( self.owner, UBI_QUALITY[UBI_FILTER_QUALITY] );
771 UberInventory_ScrollToTop();
772 UberInventory_DisplayItems();
773 end;
774
775-- Populate classes dropdown box
776 function UberInventory_Classes_Init( self )
777 -- Initialize
778 local subclasses, UBI_Item;
779 local UBI_CLASSES = UBI_CLASSES;
780
781 -- Build structure for classes
782 if ( UIDROPDOWNMENU_MENU_LEVEL == 1 ) then
783 for key, value in pairs( UBI_CLASSES ) do
784 -- Set new item
785 UBI_Item = { text = value.name,
786 value = {value.id, 0},
787 owner = UberInventoryFrameClassDropDown,
788 notCheckable = 1,
789 hasArrow = #(value.childs) > 0,
790 func = UberInventory_Classes_OnClick };
791
792 -- Add item to dropdown
793 UIDropDownMenu_AddButton( UBI_Item, UIDROPDOWNMENU_MENU_LEVEL );
794 end;
795 end;
796
797 -- Build structure for subclasses
798 if ( UIDROPDOWNMENU_MENU_LEVEL == 2 ) then
799 -- Determine subclasses
800 subclasses = UBI_CLASSES[UIDROPDOWNMENU_MENU_VALUE[1]].childs;
801
802 for key, value in pairs( subclasses ) do
803 if ( value ) then
804 -- Set new tem
805 UBI_Item = { text = value,
806 value = { UIDROPDOWNMENU_MENU_VALUE[1], key },
807 owner = UberInventoryFrameClassDropDown,
808 notCheckable = 1,
809 func = UberInventory_Classes_OnClick
810 };
811
812 -- Add item to dropdown
813 UIDropDownMenu_AddButton( UBI_Item, UIDROPDOWNMENU_MENU_LEVEL );
814 end;
815 end;
816 end;
817 end;
818
819-- Update classes dropdown box
820 function UberInventory_Classes_OnClick( self )
821 -- Get selection
822 UBI_FILTER_CLASSES = self.value[1];
823 UBI_FILTER_SUBCLASSES = self.value[2];
824
825 -- Determine dropdown text
826 local infoText = UBI_CLASSES[UBI_FILTER_CLASSES].name;
827 if ( UBI_FILTER_SUBCLASSES > 0 ) then
828 infoText = infoText.." > "..UBI_CLASSES[UBI_FILTER_CLASSES].childs[UBI_FILTER_SUBCLASSES]
829 HideDropDownMenu( 1 ); -- Collapse also the top level menu
830 end;
831
832 UIDropDownMenu_SetText( self.owner, infoText );
833 UberInventory_ScrollToTop();
834 UberInventory_DisplayItems();
835 end;
836
837-- Returns an itemLink
838 function UberInventory_GetLink( itemid, record )
839 if ( record and ( record.type == UBI_BATTLEPET_CLASS and record.item ~= 82800 ) ) then
840 return UberInventory_GetBattlePetLink( record );
841 end;
842
843 -- Get name of item
844 local itemName, itemLink, itemQuality = GetItemInfo( itemid );
845
846 -- If the item has never been seen before, itemName will be nil
847 if ( itemName == nil ) then
848 local color = ITEM_QUALITY_COLORS[0].hex;
849 itemLink = color.."|Hitem:"..itemid..":0:0:0:0:0:0:0|h["..UBI_ITEM_UNCACHED.."]|h|r";
850 end;
851
852 -- Return itemLink
853 return itemLink;
854 end;
855
856-- Returns an Battlepet Link
857 function UberInventory_GetBattlePetLink( record )
858 -- Initialize
859 local health, power, speed = 0, 0, 0;
860
861 -- Get name of item
862 local name, icon, petType, companionID, tooltipSource, tooltipDescription, isWild, canBattle, isTradeable, isUnique, obtainable = C_PetJournal.GetPetInfoBySpeciesID( record.itemid );
863
864 -- If the item has never been seen before, name will be nil
865 if ( name == nil ) then
866 name = UBI_ITEM_UNCACHED;
867 end;
868
869 -- Get additional battlepet info
870 if ( record.extra ) then
871 health = record.extra[1] or 0;
872 power = record.extra[2] or 0;
873 speed = record.extra[3] or 0;
874 end;
875
876 -- Determine item color
877 local color = ITEM_QUALITY_COLORS[record.quality].hex;
878
879 -- Return itemLink
880 return color.."|Hbattlepet:"..record.itemid..":"..record.level..":"..record.quality..":"..health..":"..power..":"..speed..":0x0000000000000000|h["..name.."]|h|r";
881 end;
882
883-- Handle OnEnter event of the Minimap icon
884 function UberInventory_Minimap_OnEnter( object, anchor )
885 -- Set location of tooltip and clear old content
886 GameTooltip:SetOwner( object, anchor );
887 GameTooltip:SetPoint( "TOPLEFT", object, "BOTTOMLEFT" );
888
889 -- Add title (AddOn name and version)
890 GameTooltip:AddDoubleLine( UBI_NAME, UBI_VERSION,
891 HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b,
892 NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b );
893
894 -- Add slot information
895 GameTooltip:AddDoubleLine( UBI_BAG, UBI_FREE:format( UBI_Options["bag_free"] , UBI_Options["bag_max"] ) );
896 GameTooltip:AddDoubleLine( UBI_BANK, UBI_FREE:format( UBI_Options["bank_free"] , UBI_Options["bank_max"] ) );
897 GameTooltip:AddDoubleLine( UBI_REAGENT, UBI_FREE:format( UBI_Options["reagent_free"] , UBI_Options["reagent_max"] ) );
898
899 -- Add cash inforamtion
900 GameTooltip:AddDoubleLine( UBI_CASH_TOTAL, GetCoinTextureString( GetMoney() + UBI_Money["mail"] ) );
901
902 -- (Re)display the tooltip
903 GameTooltip:Show();
904 end;
905
906-- Sorting table content
907 function UberInventory_SortFilter( str, cmdline )
908 -- From global to local
909 local UBI_Track = UBI_Track;
910 local UBI_Sorted = UBI_Sorted;
911 local UBI_Items_Work = UBI_Items_Work;
912
913 -- determine if sorting/collecting is needed
914 if ( UBI_Filter.text == UBI_FILTER_TEXT and
915 UBI_Filter.location == UBI_FILTER_LOCATIONS and
916 UBI_Filter.quality == UBI_FILTER_QUALITY and
917 UBI_Filter.class == UBI_FILTER_CLASSES and
918 UBI_Filter.subclass == UBI_FILTER_SUBCLASSES and
919 UBI_Filter.usable == UBI_FILTER_USABLE and
920 UBI_Filter.date == UBI_SCAN_DATE ) and not UberInventoryFrame:IsVisible() then
921 return;
922 else
923 -- Store new filter settings
924 UBI_Filter = { text = UBI_FILTER_TEXT,
925 location = UBI_FILTER_LOCATIONS,
926 quality = UBI_FILTER_QUALITY,
927 class = UBI_FILTER_CLASSES,
928 subclass = UBI_FILTER_SUBCLASSES,
929 usable = UBI_FILTER_USABLE,
930 date = UBI_SCAN_DATE };
931 end;
932
933 -- Initialize globals
934 wipe( UBI_Sorted );
935 wipe( UBI_Track );
936 wipe( UBI_Items_Work );
937 UBI_Inventory_count = 0;
938
939 -- Copy items to separate array for sorting and displaying
940 local include_item;
941 local subclasses;
942 local function UberInventory_CopyItems( str, cmdline )
943 -- Copy items to local array (including filter)
944 for key, record in pairs( UBI_Items_Work ) do
945 -- Initialize
946 include_item = true;
947
948 -- Count number of unique items
949 if ( not UBI_Track[record.itemid] ) then
950 UBI_Inventory_count = UBI_Inventory_count + 1;
951 UBI_Track[record.itemid] = 0;
952 end;
953
954 -- Fix totalCount (only for actual characters)
955 if ( record.bag_count ) then
956 record.total = record.bag_count + record.bank_count + record.mailbox_count + record.equip_count + ( record.void_count or 0 ) + ( record.reagent_count or 0 );
957 end;
958
959 -- Only apply filters when searching from then inventory frame
960 if ( not cmdline ) then
961 -- Filter on location (3 = Character, 4 = Bags, 5 = Banks, 6 = Mail, 7 = Equipped, 8 = Void Storage, 9 = Reagent Bank )
962 if ( ( UBI_FILTER_LOCATIONS == 4 and record.bag_count == 0 ) or
963 ( UBI_FILTER_LOCATIONS == 5 and record.bank_count == 0 ) or
964 ( UBI_FILTER_LOCATIONS == 6 and record.mailbox_count == 0 ) or
965 ( UBI_FILTER_LOCATIONS == 7 and record.equip_count == 0 ) or
966 ( UBI_FILTER_LOCATIONS == 8 and ( record.void_count or 0 ) == 0 ) or
967 ( UBI_FILTER_LOCATIONS == 9 and ( record.reagent_count or 0 ) == 0 ) ) then
968 include_item = false;
969 end;
970
971 -- Filter on quality
972 if ( UBI_FILTER_QUALITY > 1 and record.quality ~= UBI_FILTER_QUALITY-2 ) then
973 include_item = false;
974 end;
975
976 -- Filter on class
977 if ( UBI_FILTER_CLASSES > 1 and record.type ~= UBI_CLASSES[UBI_FILTER_CLASSES].name ) then
978 include_item = false;
979 end;
980
981 -- Filter on subclass
982 if ( UBI_FILTER_SUBCLASSES > 0 and record.subtype ~= UBI_CLASSES[UBI_FILTER_CLASSES].childs[UBI_FILTER_SUBCLASSES] ) then
983 include_item = false;
984 end;
985
986 -- Filter on usability
987 if ( UBI_FILTER_USABLE ) then
988 if ( not UberInventory_UsableItem( record.itemid ) ) then
989 include_item = false;
990 end;
991 end;
992 end;
993
994 -- Filter on name and store into structure suitable for sorting
995 if ( ( strfind( strlower( record.name ) , strlower( str ) ) or 0 ) > 0 ) and include_item then
996 -- Insert item into sorting structure
997 if ( UBI_Track[record.itemid] == 0 ) then
998 tinsert( UBI_Sorted, record );
999 end;
1000
1001 -- Track correct item totals
1002 UBI_Track[record.itemid] = UBI_Track[record.itemid] + record.total;
1003 end;
1004 end;
1005 end;
1006
1007 -- Set base list of items to use
1008 if ( cmdline or UBI_LocationList[UBI_FILTER_LOCATIONS].type == "current" ) then
1009 -- Current character
1010 UBI_Items_Work = UBI_Items;
1011 UberInventory_CopyItems( str, cmdline );
1012 elseif ( UBI_LocationList[UBI_FILTER_LOCATIONS].type == "guildbank" ) then
1013 -- Guildbank
1014 UBI_Items_Work = UBI_Guildbank[UBI_LocationList[UBI_FILTER_LOCATIONS].value]["Items"];
1015 UberInventory_CopyItems( str, cmdline );
1016 elseif ( UBI_LocationList[UBI_FILTER_LOCATIONS].type == "character" ) then
1017 -- Alt characters
1018 local character = strgsub( UBI_LocationList[UBI_FILTER_LOCATIONS].value, " .*", "" );
1019 UBI_Items_Work = UBI_Data[UBI_REALM][character]["Items"];
1020 UberInventory_CopyItems( str, cmdline );
1021 elseif ( UBI_LocationList[UBI_FILTER_LOCATIONS].type == "complete" ) then
1022 -- Traverse characters
1023 for key, value in pairs( UBI_Characters ) do
1024 UBI_Items_Work = UBI_Data[UBI_REALM][value]["Items"];
1025 UberInventory_CopyItems( str, cmdline );
1026 end;
1027
1028 -- Current character
1029 UBI_Items_Work = UBI_Items;
1030 UberInventory_CopyItems( str, cmdline );
1031
1032 -- Traverse guildbanks
1033 for key, value in pairs( UBI_Guildbanks ) do
1034 UBI_Items_Work = UBI_Guildbank[value]["Items"];
1035 UberInventory_CopyItems( str, cmdline );
1036 end;
1037 elseif ( UBI_LocationList[UBI_FILTER_LOCATIONS].type == "all_guildbank" ) then
1038 -- Traverse guildbanks
1039 for key, value in pairs( UBI_Guildbanks ) do
1040 UBI_Items_Work = UBI_Guildbank[value]["Items"];
1041 UberInventory_CopyItems( str, cmdline );
1042 end;
1043 elseif ( UBI_LocationList[UBI_FILTER_LOCATIONS].type == "all_character" ) then
1044 -- Current character
1045 UBI_Items_Work = UBI_Items;
1046 UberInventory_CopyItems( str, cmdline );
1047
1048 -- Traverse characters
1049 for key, value in pairs( UBI_Characters ) do
1050 UBI_Items_Work = UBI_Data[UBI_REALM][value]["Items"];
1051 UberInventory_CopyItems( str, cmdline );
1052 end;
1053 end;
1054
1055 -- Sort the array alphabetically based on item name
1056 tsort( UBI_Sorted, function( rec1, rec2 )
1057 return rec1.name < rec2.name
1058 end );
1059 end;
1060
1061-- Reset filters
1062 function UberInventory_ResetFilters( button )
1063 -- Reset dropdown for location
1064 if ( button == "RightButton" ) then
1065 UBI_FILTER_LOCATIONS = 1; -- All items
1066 else
1067 UBI_FILTER_LOCATIONS = 3; -- Current character
1068 end;
1069 UIDropDownMenu_SetText( UberInventoryFrameLocationDropDown, UBI_LocationList[UBI_FILTER_LOCATIONS].value );
1070
1071 -- Reset dropdown for quality
1072 UBI_FILTER_QUALITY = 1;
1073 UIDropDownMenu_SetText( UberInventoryFrameQualityDropDown, UBI_QUALITY[UBI_FILTER_QUALITY] );
1074
1075 -- Reset dropdown for class
1076 UBI_FILTER_CLASSES = 1;
1077 UBI_FILTER_SUBCLASSES = 0;
1078 UIDropDownMenu_SetText( UberInventoryFrameClassDropDown, UBI_ALL_CLASSES );
1079
1080 -- Reset usable items
1081 UBI_FILTER_USABLE = false;
1082 UberInventoryFrameUsableItems:SetChecked( UBI_FILTER_USABLE );
1083
1084 -- Reset search text (and refresh items displayed)
1085 if ( UBI_FILTER_TEXT == "" ) then
1086 UberInventory_ScrollToTop();
1087 UberInventory_DisplayItems();
1088
1089 -- Update token info on screen
1090 if ( UberInventoryTokens:IsVisible() ) then
1091 UberInventory_DisplayTokens();
1092 end;
1093 else
1094 UberInventoryFrameItemSearch:SetText( "" );
1095 end;
1096 end;
1097
1098-- Reset item counts
1099 function UberInventory_ResetCount( location )
1100 -- From global to local
1101 local UBI_Items = UBI_Items;
1102
1103 -- Clear counts
1104 location = location.."_count";
1105 for key, record in pairs( UBI_Items ) do
1106 record[location] = 0;
1107 end;
1108 end;
1109
1110-- Add sell prices to items in your bag (only used if not already at a merchant)
1111 function UberInventory_AddItemInfo( tooltip )
1112 -- Skip when user does not want information added to tooltip
1113 if ( not UBI_Options["show_tooltip"] ) then return; end;
1114
1115 -- Function for adding counts per location (only non-zero locations are added to the tooltip)
1116 local function AddLocationInfo( tooltip, bag, bank, mailbox, equipped, void, reagent )
1117 tooltip:AddLine( "|n" );
1118 if ( bag > 0 ) then tooltip:AddDoubleLine( UBI_LOCATIONS[1], bag ); tooltip:AddTexture( UBI_LOCATION_TEXTURE[1] ); end;
1119 if ( bank > 0 ) then tooltip:AddDoubleLine( UBI_LOCATIONS[2], bank ); tooltip:AddTexture( UBI_LOCATION_TEXTURE[2] ); end;
1120 if ( mailbox > 0 ) then tooltip:AddDoubleLine( UBI_LOCATIONS[3], mailbox ); tooltip:AddTexture( UBI_LOCATION_TEXTURE[3] ); end;
1121 if ( equipped > 0 ) then tooltip:AddDoubleLine( UBI_LOCATIONS[4], equipped ); tooltip:AddTexture( UBI_LOCATION_TEXTURE[4] ); end;
1122 if ( ( void or 0 ) > 0 ) then tooltip:AddDoubleLine( UBI_LOCATIONS[5], void ); tooltip:AddTexture( UBI_LOCATION_TEXTURE[5] ); end;
1123 if ( ( reagent or 0 ) > 0 ) then tooltip:AddDoubleLine( UBI_LOCATIONS[6], reagent ); tooltip:AddTexture( UBI_LOCATION_TEXTURE[6] ); end;
1124 end;
1125
1126 -- Set smaller font for vendor, quest and drop information
1127 local function SetSmallerFont()
1128 local numlines = tooltip:NumLines();
1129 local txtLeft = _G[ tooltip:GetName().."TextLeft"..numlines ];
1130 local txtRight = _G[ tooltip:GetName().."TextRight"..numlines ];
1131 txtLeft:SetFontObject( GameTooltipTextSmall );
1132 txtLeft:SetTextColor( 0.0, 1.0, 0.0 );
1133 txtRight:SetFontObject( GameTooltipTextSmall );
1134 txtRight:SetTextColor( 0.0, 0.7, 1.0 );
1135 end;
1136
1137 -- Initialize
1138 local itemCount = 1;
1139 local guildCount = 0;
1140 local spacerAdded = false;
1141
1142 -- Get the itemLink
1143 local itemName, itemLink = tooltip:GetItem();
1144
1145 -- Does the slot contain an item
1146 if ( itemLink ) then
1147 -- Get item ID
1148 local _, itemId = strsplit( ":", itemLink );
1149 local _, _, _, _, _, itemType, itemSubType = GetItemInfo( itemLink );
1150
1151 -- Get count (only if count label exists and is visible, otherwise use the value 1)
1152 if ( tooltip:GetName() == "ItemRefTooltip" ) then
1153 itemCount = 1;
1154 else
1155 -- Special fix needed for Auctioneer Advanced, since this AddOn removes itembutton as soon as
1156 -- the mouse is over it to display a bigger button on a different location.
1157 -- (2009/07/28) Additional fix implemented (ticket #4)
1158 -- (2009/08/01) Additional fix implemented (related to Skillet)
1159 if ( GetMouseFocus() and GetMouseFocus():GetName() ) then
1160 local objCount = _G[ GetMouseFocus():GetName().."Count" ];
1161 if ( objCount and objCount:IsVisible() and objCount.GetText ) then
1162 itemCount = tonumber( objCount:GetText() or "" ) or 1;
1163 end;
1164 else
1165 itemCount = 1;
1166 end;
1167 end;
1168
1169 -- Get stored sell price
1170 local itemId_num = tonumber( itemId );
1171 local buyPrice, sellPrice, buyoutPrice = UberInventory_GetItemPrices( itemId_num );
1172 local name, area, mob, rate, count;
1173 local UBI_Zones = UBI_Zones;
1174 local totalCount = 0;
1175
1176 -- Only perform the following part when it not has already been done (gets called twice for recipe related items)
1177 if ( not tooltip.UBI_InfoAdded or false ) then
1178
1179 -- Add additional pricing information when not at a vendor
1180 if ( not MerchantFrame:IsVisible() or tooltip == ItemRefTooltip ) then
1181 -- Add pricing information for selling to vendors
1182 if ( UBI_Options["show_sell_prices"] ) then
1183 if ( ( sellPrice or 0 ) == 0 ) then -- Item unsellable
1184 tooltip:AddLine( "|n" );
1185 tooltip:AddLine( ITEM_UNSELLABLE, 1.0, 1.0, 1.0 );
1186 elseif ( itemCount > 0 ) then -- Calculate sell price and add it
1187 -- Add money to the tooltip
1188 tooltip:AddLine( "|n" );
1189 if ( UBI_Options["pricing_data"] == "vendor" ) then
1190 UberInventory_SetTooltipMoney( tooltip, sellPrice * itemCount, "STATIC", UBI_ITEM_SELL, "" );
1191 else
1192 UberInventory_SetTooltipMoney( tooltip, buyoutPrice * itemCount, "STATIC", UBI_ITEM_BUYOUT, "" );
1193 end;
1194 end;
1195 end;
1196
1197 -- Add pricing information for buying recipes from vendors (mainly for auction house use)
1198 local recipeData = UBI_RecipeVendors[itemId_num];
1199 if ( UBI_Options["show_recipe_prices"] and recipeData ) then
1200 -- Add section title (incl cash) to the tooltip
1201 tooltip:AddLine( "|n" );
1202 if ( buyPrice ) then
1203 tooltip:AddLine( UBI_ITEM_RECIPE_SOLD_BY:format( GetCoinTextureString( buyPrice ) ), 1.0, 1.0, 1.0 );
1204 else
1205 tooltip:AddLine( UBI_ITEM_RECIPE_SOLD_BY:format( "??" ), 1.0, 1.0, 1.0 );
1206 end;
1207
1208 -- Add vendors to the tooltip
1209 count = 0;
1210 for idx, vendor in pairs( recipeData ) do
1211 if ( count >= UBI_MAX_RECIPE_INFO ) then break; end;
1212 name, area = strsplit( "|", UBI_Creatures[vendor] );
1213 tooltip:AddDoubleLine( " "..name, UBI_Zones[tonumber( area )] );
1214 SetSmallerFont();
1215 count = count + 1;
1216 end;
1217 end;
1218
1219 -- Add quest reward information for recipes
1220 local recipeQuest = UBI_RecipeQuestRewards[itemId_num];
1221 if ( UBI_Options["show_recipe_reward"] and recipeQuest ) then
1222 -- Add section title to the tooltip
1223 tooltip:AddLine( "|n" );
1224 tooltip:AddLine( UBI_ITEM_RECIPE_REWARD_FROM, 1.0, 1.0, 1.0 );
1225
1226 -- Add quests to the tooltip
1227 count = 0;
1228 for idx, quest in pairs( recipeQuest ) do
1229 if ( count >= UBI_MAX_RECIPE_INFO ) then break; end;
1230 name, area = strsplit( "|", UBI_Quests[quest] )
1231 tooltip:AddDoubleLine( " "..name, UBI_Zones[tonumber( area )] );
1232 SetSmallerFont();
1233 count = count + 1;
1234 end;
1235 end;
1236
1237 -- Add drop information for recipes
1238 local recipeDrop = UBI_RecipeDrops[itemId_num];
1239 if ( UBI_Options["show_recipe_drop"] and recipeDrop ) then
1240 -- Add section title to the tooltip
1241 tooltip:AddLine( "|n" );
1242 tooltip:AddLine( UBI_ITEM_RECIPE_DROP_BY, 1.0, 1.0, 1.0 );
1243
1244 -- Add quests to the tooltip
1245 count = 0;
1246 for idx, drop in pairs( recipeDrop ) do
1247 if ( count >= UBI_MAX_RECIPE_INFO ) then break; end;
1248 mob, rate = strsplit( ":", drop );
1249 mob = tonumber( mob );
1250 rate = tonumber( rate );
1251 name, area = strsplit( "|", UBI_Creatures[mob] );
1252 tooltip:AddDoubleLine( " "..name.." ("..UBI_Droprates[rate]..")", UBI_Zones[tonumber( area )] );
1253 SetSmallerFont();
1254 count = count + 1;
1255 end;
1256 end;
1257 end;
1258
1259 -- Only display item counts when show_item_count is turned on
1260 if ( UBI_Options["show_item_count"] ) then
1261
1262 -- Add counts (if UBI_TooltipItem is populated then we are showing a tooltip from the main inventory frame)
1263 if ( UBI_TooltipItem ) then
1264 -- Only add the info when we are not show data from the guildbank
1265 if ( UBI_TooltipItem["bag_count"] and ( UBI_LocationList[UBI_FILTER_LOCATIONS].type == "current" or
1266 UBI_LocationList[UBI_FILTER_LOCATIONS].type == "character" ) ) then
1267 -- Add full item count information
1268 AddLocationInfo( tooltip,
1269 UBI_TooltipItem["bag_count"],
1270 UBI_TooltipItem["bank_count"],
1271 UBI_TooltipItem["mailbox_count"],
1272 UBI_TooltipItem["equip_count"],
1273 UBI_TooltipItem["void_count"],
1274 UBI_TooltipItem["reagent_count"] );
1275 totalCount = totalCount + UBI_TooltipItem["bag_count"] + UBI_TooltipItem["bank_count"] + UBI_TooltipItem["mailbox_count"] + UBI_TooltipItem["equip_count"] + ( UBI_TooltipItem["void_count"] or 0 ) + ( UBI_TooltipItem["reagent_count"] or 0 );
1276 spacerAdded = true;
1277 end;
1278 elseif ( UBI_Items[itemId] ) then
1279 AddLocationInfo( tooltip,
1280 UBI_Items[itemId]["bag_count"],
1281 UBI_Items[itemId]["bank_count"],
1282 UBI_Items[itemId]["mailbox_count"],
1283 UBI_Items[itemId]["equip_count"],
1284 UBI_Items[itemId]["void_count"],
1285 UBI_Items[itemId]["reagent_count"] );
1286 totalCount = totalCount + UBI_Items[itemId]["bag_count"] + UBI_Items[itemId]["bank_count"] + UBI_Items[itemId]["mailbox_count"] + UBI_Items[itemId]["equip_count"] + ( UBI_Items[itemId]["void_count"] or 0 ) + ( UBI_Items[itemId]["reagent_count"] or 0 );
1287 spacerAdded = true;
1288 end;
1289
1290 -- Add info from current character if viewing data from an alt
1291 if ( UBI_Items[itemId] and UBI_TooltipLocation and UBI_LocationList[UBI_FILTER_LOCATIONS].type ~= "current" ) then
1292 -- Insert spacer if not already added
1293 if ( not spacerAdded ) then
1294 tooltip:AddLine( "|n" );
1295 spacerAdded = true;
1296 end;
1297
1298 -- Add the count and icon for the current alt
1299 totalCount = totalCount + UBI_Items[itemId].total;
1300 tooltip:AddDoubleLine( UBI_PLAYER, UBI_Items[itemId].total );
1301 tooltip:AddTexture( UBI_LOCATION_TEXTURE[7] );
1302 end;
1303
1304 -- Add information for alt characters
1305 local UBI_Characters = UBI_Characters;
1306 local record;
1307 for key, value in pairs( UBI_Characters ) do
1308 if ( UBI_Data[UBI_REALM][value]["Items"][itemId] ) then
1309 if ( value ~= strtrim( UBI_LocationList[UBI_TooltipLocation or 1].name ) ) then
1310 -- Insert spacer if not already added
1311 if ( not spacerAdded ) then
1312 tooltip:AddLine( "|n" );
1313 spacerAdded = true;
1314 end;
1315
1316 -- Fix total
1317 record = UBI_Data[UBI_REALM][value]["Items"][itemId];
1318 record.total = record.bag_count + record.bank_count + record.mailbox_count + record.equip_count + (record.void_count or 0) + (record.reagent_count or 0);
1319 totalCount = totalCount + ( record.total or 0 );
1320
1321 -- Add the count and icon for the current alt
1322 tooltip:AddDoubleLine( value, record.total );
1323 tooltip:AddTexture( UBI_LOCATION_TEXTURE[7] );
1324 end;
1325 end;
1326 end;
1327
1328 -- Add information for guildbanks
1329 local UBI_Guildbanks = UBI_Guildbanks;
1330 for key, value in pairs( UBI_Guildbanks ) do
1331 if ( UBI_Guildbank[value]["Items"][itemId] ) then
1332 -- Insert spacer if not already added
1333 if ( not spacerAdded ) then
1334 tooltip:AddLine( "|n" );
1335 spacerAdded = true;
1336 end;
1337
1338 -- Add the count and icon for the current guildbank
1339 totalCount = totalCount + UBI_Guildbank[value]["Items"][itemId].total;
1340 tooltip:AddDoubleLine( C_GREY..value..C_CLOSE, C_GREY..UBI_Guildbank[value]["Items"][itemId].total..C_CLOSE );
1341 tooltip:AddTexture( UBI_LOCATION_TEXTURE[7] );
1342 end;
1343 end;
1344
1345 -- Add total itemcount
1346 if ( totalCount > 0 ) then
1347 tooltip:AddDoubleLine( " ", C_YELLOW..UBI_SIGMA_ICON.." "..totalCount..C_CLOSE );
1348 end;
1349
1350 end;
1351 end;
1352 end;
1353
1354 tooltip.maxlines = tooltip:NumLines();
1355 end;
1356
1357-- HOOK - Set new OnTooltipSetItem and OnHide script for Tooltip objects
1358 function UberInventory_HookTooltip( tooltip )
1359 -- From global to local
1360 local UBI_Hooks = UBI_Hooks;
1361
1362 -- Store default script
1363 local tooltipName = tooltip:GetName();
1364 UBI_Hooks["OnTooltipSetItem"][tooltipName] = tooltip:GetScript( "OnTooltipSetItem" );
1365 UBI_Hooks["OnTooltipCleared"][tooltipName] = tooltip:GetScript( "OnTooltipCleared" );
1366
1367 -- Set new script to handle OntooltipSetItem
1368 tooltip:SetScript( "OnTooltipSetItem", function( self, ... )
1369 -- From global to local
1370 local UBI_Hooks = UBI_Hooks;
1371
1372 -- Get tooltip name
1373 local tooltipName = self:GetName();
1374
1375 -- Call default script
1376 if ( UBI_Hooks["OnTooltipSetItem"][tooltipName] ) then
1377 UBI_Hooks["OnTooltipSetItem"][tooltipName]( self, ... );
1378 end;
1379
1380 -- Call new script (adds the item information)
1381 UberInventory_AddItemInfo( self );
1382
1383 -- Turn on UberInventory indicator
1384 self.UBI_InfoAdded = true;
1385 end );
1386
1387 -- Set new script to handle OnTooltipCleared
1388 tooltip:SetScript( "OnTooltipCleared", function( self, ... )
1389 -- From global to local
1390 local UBI_Hooks = UBI_Hooks;
1391
1392 -- Get tooltip name
1393 local tooltipName = self:GetName();
1394
1395 -- Force reset of fonts (maxlines is a custom attribute added within the UberInventory_AddItemInfo function)
1396 if ( self.maxlines ) then
1397 local txtLeft, txtRight;
1398 for i = 1, self.maxlines do
1399 txtLeft = _G[self:GetName().."TextLeft"..i];
1400 txtRight = _G[self:GetName().."TextRight"..i];
1401 if ( txtLeft ) then txtLeft:SetFontObject( GameTooltipText ); end;
1402 if ( txtRight ) then txtRight:SetFontObject( GameTooltipText ); end;
1403 end;
1404 end;
1405
1406 -- Call default script
1407 if ( UBI_Hooks["OnTooltipCleared"][tooltipName] ) then
1408 UBI_Hooks["OnTooltipCleared"][tooltipName]( self, ... );
1409 end;
1410
1411 -- Turn off UberInventory indicator
1412 self.UBI_InfoAdded = false;
1413 end );
1414 end;
1415
1416-- Get item information and store it
1417 function UberInventory_Item( bagID, slotID, location )
1418 -- From global to local
1419 local UBI_Items = UBI_Items;
1420
1421 -- Initialize
1422 local bankCount, bagCount, mailCount, equipCount, voidCount, reagentCount = 0, 0, 0, 0, 0, 0;
1423 local itemLink = nil;
1424 local questItem, questID = nil, nil;
1425 local extra = {};
1426
1427 -- Get itemLink
1428 if ( location == "mailbox" ) then
1429 itemLink = GetInboxItemLink( bagID, slotID );
1430 questItem, questID = GetContainerItemQuestInfo( bagID, slotID );
1431 elseif ( location == "equip" ) then
1432 itemLink = GetInventoryItemLink( "player", slotID );
1433 elseif ( location == "void" ) then
1434 local itemID = GetVoidItemInfo( bagID, slotID );
1435 if ( itemID ) then
1436 itemLink = UberInventory_GetLink( itemID );
1437 end;
1438 else
1439 itemLink = GetContainerItemLink( bagID, slotID );
1440 questItem, questID = GetContainerItemQuestInfo( bagID, slotID );
1441 end;
1442
1443 -- Retrieve item information
1444 if ( itemLink ) then
1445 -- Initialize
1446 local itemCount, _ = 0;
1447
1448 -- Fetch item information (itemLink skipped from GetItemInfo, does not always work at this stage (Quest related items))
1449 local itemName, _, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture = GetItemInfo( itemLink );
1450 local _, itemId, enchantId, jewelId1, jewelId2, jewelId3, jewelId4, suffixId, uniqueId = strsplit( ":", itemLink );
1451
1452 if ( location == "mailbox" ) then
1453 _, _, _, itemCount = GetInboxItem( bagID, slotID );
1454 elseif ( location == "equip" ) then
1455 itemCount = 1;
1456 else
1457 _, itemCount = GetContainerItemInfo( bagID, slotID );
1458 end;
1459
1460 -- Get existing item counts or activate sorting (new item is added)
1461 if ( UBI_Items[itemId] ) then
1462 bankCount = ( UBI_Items[itemId]["bank_count"] or 0 );
1463 bagCount = ( UBI_Items[itemId]["bag_count"] or 0 );
1464 mailCount = ( UBI_Items[itemId]["mailbox_count"] or 0 );
1465 equipCount = ( UBI_Items[itemId]["equip_count"] or 0 );
1466 voidCount = ( UBI_Items[itemId]["void_count"] or 0 );
1467 reagentCount = ( UBI_Items[itemId]["reagent_count"] or 0 );
1468 end;
1469
1470 -- Sort out itemCount
1471 if ( location == "bank" ) then
1472 bankCount = bankCount + itemCount;
1473 elseif ( location == "bag" ) then
1474 bagCount = bagCount + itemCount;
1475 elseif ( location == "mailbox" ) then
1476 mailCount = mailCount + ( itemCount or 0 );
1477 elseif ( location == "equip" ) then
1478 equipCount = equipCount + itemCount;
1479 elseif ( location == "void" ) then
1480 voidCount = voidCount + ( itemCount or 1 );
1481 elseif ( location == "reagent" ) then
1482 reagentCount = reagentCount + ( itemCount or 1 );
1483 end;
1484 local totalCount = bagCount + bankCount + mailCount + equipCount + ( voidCount or 0 ) + ( reagentCount or 0 );
1485
1486 -- Handle Battle Pets
1487 if ( strfind( itemLink, "battlepet:" ) and itemId ~= 82800 ) then
1488 local _, speciesID, level, breedQuality, maxHealth, power, speed, battlePetID = strsplit( ":", itemLink );
1489 local name, icon, petType, companionID, tooltipSource, tooltipDescription, isWild, canBattle, isTradeable, isUnique, obtainable = C_PetJournal.GetPetInfoBySpeciesID( speciesID );
1490
1491 itemName = name;
1492 itemQuality = tonumber( breedQuality );
1493 itemType = UBI_BATTLEPET_CLASS;
1494 itemSubType = _G["BATTLE_PET_NAME_"..petType];
1495 itemLevel = level;
1496 extra = { maxHealth, power, speed };
1497 end;
1498
1499 -- Store the item information
1500 UBI_Items[itemId] = { ["itemid"] = tonumber( itemId ),
1501 ["name"] = itemName,
1502 ["quality"] = itemQuality,
1503 ["level"] = itemLevel,
1504 ["bag_count"] = bagCount,
1505 ["bank_count"] = bankCount,
1506 ["mailbox_count"] = mailCount,
1507 ["equip_count"] = equipCount,
1508 ["void_count"] = voidCount,
1509 ["reagent_count"] = reagentCount,
1510 ["type"] = itemType,
1511 ["subtype"] = itemSubType,
1512 ["total"] = totalCount,
1513 ["qitem"] = questItem,
1514 ["qid"] = questID,
1515 ["extra"] = extra
1516 };
1517 end;
1518 end;
1519
1520-- Handle Bag items
1521 function UberInventory_Save_Bag()
1522 if ( not UBI_ACTIVE ) then return; end;
1523
1524 -- Initialize
1525 local slotCount, freeCount = 0, 0;
1526
1527 -- Reset bag counts
1528 UberInventory_ResetCount( "bag" );
1529
1530 -- Traverse bags
1531 for bagID = 0, 4 do
1532 if ( GetContainerNumSlots( bagID ) ) then
1533 slotCount = slotCount + GetContainerNumSlots( bagID );
1534 freeCount = freeCount + GetContainerNumFreeSlots( bagID );
1535 for slotID = 1, GetContainerNumSlots( bagID ) do
1536 UberInventory_Item( bagID, slotID, "bag" );
1537 end;
1538 end;
1539 end;
1540
1541 -- Save slot count
1542 UBI_Options["bag_max"] = slotCount;
1543 UBI_Options["bag_free"] = freeCount;
1544 end;
1545
1546-- Handle Void Storage
1547 function UberInventory_Save_VoidStorage( event )
1548 if ( not UBI_ACTIVE ) then return; end;
1549
1550 -- Reset void storage counts
1551 UberInventory_ResetCount( "void" );
1552
1553 -- Traverse void storage slots
1554 for tabID = 2, 1, -1 do
1555 for voidID = 1, 80 do
1556 UberInventory_Item( tabID, voidID, "void" );
1557 end;
1558 end;
1559
1560 -- Update inventory frame if visible
1561 if ( UberInventoryFrame:IsVisible() ) then
1562 UberInventory_DisplayItems();
1563 end;
1564 end;
1565
1566-- Handle Reagent Bank items
1567 function UberInventory_Save_ReagentBank()
1568 if ( not UBI_ACTIVE ) then return; end;
1569
1570 -- Intialize
1571 local slotCount, freeCount = 0, 0;
1572
1573 -- Reset reagent bank counts
1574 UberInventory_ResetCount( "reagent" );
1575
1576 -- Traverse reagent bag
1577 if ( GetContainerNumSlots( REAGENTBANK_CONTAINER ) ) then
1578 slotCount = GetContainerNumSlots( REAGENTBANK_CONTAINER );
1579 for slotID = 1, GetContainerNumSlots( REAGENTBANK_CONTAINER ) do
1580 if ( not GetContainerItemLink( REAGENTBANK_CONTAINER, slotID ) ) then
1581 freeCount = freeCount + 1;
1582 end;
1583
1584 UberInventory_Item( REAGENTBANK_CONTAINER, slotID, "reagent" );
1585 end;
1586 end;
1587
1588 -- Save slot count
1589 UBI_Options["reagent_max"] = slotCount;
1590 UBI_Options["reagent_free"] = freeCount;
1591
1592 -- Update inventory frame if visible
1593 if ( UberInventoryFrame:IsVisible() ) then
1594 UberInventory_DisplayItems();
1595 end;
1596 end;
1597
1598-- Handle Bank items
1599 function UberInventory_Save_Bank()
1600 if ( not UBI_ACTIVE ) then return; end;
1601
1602 -- Intialize
1603 local slotCount, freeCount = 0, 0;
1604
1605 if ( UBI_BANK_OPEN ) then
1606 -- Reset bank counts
1607 UberInventory_ResetCount( "bank" );
1608
1609 -- Traverse bank slots
1610 slotCount = GetContainerNumSlots( BANK_CONTAINER );
1611 for slotID = 1, GetContainerNumSlots( BANK_CONTAINER ) do
1612 if ( not GetContainerItemLink( BANK_CONTAINER, slotID ) ) then
1613 freeCount = freeCount + 1;
1614 end;
1615 UberInventory_Item( BANK_CONTAINER, slotID, "bank" );
1616 end;
1617
1618 -- Traverse bank bags
1619 for bagID = 5, 11 do
1620 if ( GetContainerNumSlots( bagID ) ) then
1621 slotCount = slotCount + GetContainerNumSlots( bagID );
1622 freeCount = freeCount + GetContainerNumFreeSlots( bagID );
1623 for slotID = 1, GetContainerNumSlots( bagID ) do
1624 UberInventory_Item( bagID, slotID, "bank" );
1625 end;
1626 end;
1627 end;
1628
1629 -- Save slot count
1630 UBI_Options["bank_max"] = slotCount;
1631 UBI_Options["bank_free"] = freeCount;
1632 end;
1633 end;
1634
1635-- Handle Mailbox items
1636 function UberInventory_Save_Mailbox()
1637 if ( not UBI_ACTIVE ) then return; end;
1638
1639 -- Initialize
1640 local today = time( UberInventory_GetDateTime() );
1641 local UBI_Options = UBI_Options;
1642 local UBI_Money = UBI_Money;
1643 local mailSender, mailSubject, cashAttached, daysLeft, itemAttached, _;
1644 local mailText, mailTexture, mailTakeable, mailInvoice;
1645 local invoiceType, bid, buyout, deposit, consignment;
1646
1647 if ( UBI_MAILBOX_OPEN ) then
1648 -- Reset mailbox cash
1649 UBI_Money["mail"] = 0;
1650
1651 -- Reset expiration date
1652 if ( UBI_Options["mail_expires"] ) then wipe( UBI_Options["mail_expires"] ) else UBI_Options["mail_expires"] = {}; end;
1653
1654 -- Reset mailbox counts
1655 UberInventory_ResetCount( "mailbox" );
1656
1657 -- Get number of mails in inbox
1658 local numItems = GetInboxNumItems();
1659
1660 -- Traverse mailbox (Reverse order)
1661 for mailID = numItems, 1, -1 do
1662 -- Mail info
1663 _, _, mailSender, mailSubject, cashAttached, _, daysLeft, itemAttached = GetInboxHeaderInfo( mailID );
1664 daysLeft = today + ( floor( daysLeft ) * UBI_SEC_IN_DAY );
1665
1666 -- Register all mails stored in mailbox stored by expiration date (exclude sales pending mails)
1667 if ( itemAttached or cashAttached > 0 ) then
1668 UBI_Options["mail_expires"][daysLeft] = ( UBI_Options["mail_expires"][daysLeft] or 0 ) + 1;
1669 end;
1670
1671 -- Handle attachment
1672 if ( itemAttached ) then
1673 for attachID = 1, ATTACHMENTS_MAX_RECEIVE do
1674 UberInventory_Item( mailID, attachID, "mailbox" );
1675 end;
1676 end;
1677
1678 -- Handle money
1679 if ( cashAttached > 0 ) then
1680 if ( UBI_Options["take_money"] ) then
1681 -- Add task to take inbox money (if not items are attached this also deletes the mail)
1682 TaskHandlerLib:AddTask( "UberInventory", UBI_Task_CollectCash, mailID );
1683 end;
1684
1685 -- Record the mailbox cash
1686 UBI_Money["mail"] = UBI_Money["mail"] + cashAttached;
1687 end;
1688
1689 -- Update wallet/mail info (if mainframe is shown)
1690 UberInventory_WalletMailCashInfo();
1691 end;
1692
1693 -- Reregister MAIL_INBOX_UPDATE event
1694 UBI:RegisterEvent( "MAIL_INBOX_UPDATE" );
1695 end;
1696 end;
1697
1698-- Handle Equiped items
1699 function UberInventory_Save_Equipped()
1700 if ( not UBI_ACTIVE ) then return; end;
1701
1702 -- Initialize
1703 local slotID, _;
1704
1705 -- Reset Equiped counts
1706 UberInventory_ResetCount( "equip" );
1707
1708 -- Traverse equip slots
1709 for key, value in pairs( UBI_EQUIP_SLOTS ) do
1710 slotID, _ = GetInventorySlotInfo( value );
1711 UberInventory_Item( nil, slotID, "equip" );
1712 end;
1713 end;
1714
1715-- Handle Guildbank items
1716 function UberInventory_Save_Guildbank( event )
1717 if ( not UBI_ACTIVE ) then return; end;
1718
1719 -- Exit if tracking is turned off
1720 if ( not UBI_Options["track_gb_data"] ) then return; end;
1721
1722 -- Exit if already saving gb data
1723 if ( UBI_PROCESSING_GB ) then return; end;
1724
1725 -- From global to local
1726 local UBI_Guildbank = UBI_Guildbank;
1727
1728 -- Initialize
1729 local itemCount = 0;
1730 local name, icon, isViewable, canDeposit, numWithdrawals, remainingWithdrawals, count, itemLink, _;
1731 local itemName, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture;
1732 local itemId, enchantId, jewelId1, jewelId2, jewelId3, jewelId4, suffixId, uniqueId;
1733
1734 if ( UBI_GUILDBANK_OPENED ) then
1735 -- indicate we are already saving gb data
1736 UBI_PROCESSING_GB = true;
1737
1738 -- Start out to assume we have view access to all guildbank tabs
1739 UBI_GUILDBANK_VIEWACCESS = true;
1740
1741 -- Clear the existing data
1742 wipe( UBI_Guildbank[UBI_GUILD]["Items"] );
1743
1744 -- Traverse guild bank tabs/slots to store into UberInventory
1745 for gbTab = 1, GetNumGuildBankTabs() do
1746 -- Can we view the content of all guildbank tabs?
1747 -- isViewable = true;
1748 local name, icon, isViewable = GetGuildBankTabInfo( gbTab );
1749 if ( not isViewable ) then
1750 UBI_GUILDBANK_VIEWACCESS = false;
1751 end;
1752
1753 -- Only collect when tab is viewable (to prevent messages in chat)
1754 if ( isViewable ) then
1755
1756 for gbSlot = 1, (MAX_GUILDBANK_SLOTS_PER_TAB or 98) do
1757 -- Reset
1758 itemCount = 0;
1759
1760 -- Get slot information
1761 _, count, _ = GetGuildBankItemInfo( gbTab, gbSlot );
1762 itemLink = GetGuildBankItemLink( gbTab, gbSlot );
1763
1764 if ( itemLink ) then
1765 -- Fetch item information
1766 itemName, _, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture = GetItemInfo( itemLink );
1767 _, itemId, enchantId, jewelId1, jewelId2, jewelId3, jewelId4, suffixId, uniqueId = strsplit( ":", itemLink );
1768
1769 -- Get existing item count
1770 if ( UBI_Guildbank[UBI_GUILD]["Items"][itemId] ) then
1771 itemCount = UBI_Guildbank[UBI_GUILD]["Items"][itemId]["count"];
1772 end;
1773
1774 -- Handle Battle Pets
1775 if ( strfind( itemLink, "battlepet:" ) ) then
1776 local _, speciesID, level, breedQuality, maxHealth, power, speed, battlePetID = strsplit( ":", itemLink );
1777 local name, icon, petType, companionID, tooltipSource, tooltipDescription, isWild, canBattle, isTradeable, isUnique, obtainable = C_PetJournal.GetPetInfoBySpeciesID( speciesID );
1778
1779 itemName = name;
1780 itemQuality = tonumber( breedQuality );
1781 itemType = UBI_BATTLEPET_CLASS;
1782 itemSubType = _G["BATTLE_PET_NAME_"..petType];
1783 itemLevel = level;
1784 extra = { maxHealth, power, speed };
1785 end;
1786
1787 -- Store the item information
1788 UBI_Guildbank[UBI_GUILD]["Items"][itemId] = { ["itemid"] = tonumber( itemId ),
1789 ["name"] = itemName,
1790 ["quality"] = itemQuality,
1791 ["level"] = itemLevel,
1792 ["count"] = itemCount + count,
1793 ["type"] = itemType,
1794 ["subtype"] = itemSubType,
1795 ["extra"] = extra,
1796 ["total"] = itemCount + count };
1797 end;
1798 end;
1799 end;
1800
1801 end;
1802
1803 -- Done saving gb data
1804 UBI_PROCESSING_GB = false;
1805 end;
1806
1807 -- Store guildbank cash
1808 UBI_Guildbank[UBI_GUILD]["Cash"] = GetGuildBankMoney();
1809
1810 -- Rebuild list of guildbanks
1811 UberInventory_GetGuildbanks();
1812
1813 -- Update inventory frame if visible
1814 if ( UberInventoryFrame:IsVisible() ) then
1815 UberInventory_DisplayItems();
1816 end;
1817 end;
1818
1819-- Handle Guildbank items
1820 function UberInventory_Receive_Guildbank()
1821 -- From global to local
1822 local UBI_Guildbank = UBI_Guildbank;
1823 local UBI_GBData = UBI_GBData;
1824
1825 -- Exit if tracking is turned off
1826 if ( not UBI_Options["track_gb_data"] ) then return; end;
1827
1828 -- Init guildbank structures (if needed)
1829 UberInventory_Guildbank_Init()
1830
1831 -- Show receiving data
1832 UberInventory_Message( UBI_NEW_GBDATA:format( UBI_GBSender ), true );
1833
1834 -- Clear the existing data
1835 wipe( UBI_Guildbank[UBI_GUILD]["Items"] );
1836
1837 -- Traverse all guildbank tabs and slots
1838 local itemLink, itemName, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, _;
1839 for key, value in pairs( UBI_GBData ) do
1840 -- Fetch item information
1841 itemLink = UberInventory_GetLink( value.itemid );
1842 itemName, _, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture = GetItemInfo( itemLink );
1843
1844 -- Store the item information
1845 UBI_Guildbank[UBI_GUILD]["Items"][value.itemid] = { ["itemid"] = tonumber( value.itemid ),
1846 ["name"] = value.name or itemName or UBI_ITEM_UNCACHED,
1847 ["quality"] = value.quality or itemQuality,
1848 ["level"] = value.level or itemLevel or 0,
1849 ["count"] = value.count,
1850 ["type"] = value.type or itemType or UBI_ITEM_UNCACHED,
1851 ["subtype"] = value.subtype or itemSubType or UBI_ITEM_UNCACHED,
1852 ["total"] = value.count };
1853
1854 if ( value.extra ) then
1855 end;
1856 end;
1857
1858 -- Update inventory frame if visible
1859 if ( UberInventoryFrame:IsVisible() ) then
1860 -- Update items
1861 UberInventory_DisplayItems();
1862
1863 -- Update slot count information
1864 UberInventory_Update_SlotCount();
1865 end;
1866
1867 -- Track Guildbank last visit date/time
1868 UBI_Options["guildbank_visit"] = UberInventory_GetDateTime();
1869
1870 -- Clear sender
1871 UBI_GBSender = nil;
1872 end;
1873
1874-- Send Guildbank data to other guild members
1875 function UberInventory_Send_Guildbank()
1876 -- From global to local
1877 local UBI_Guildbank = UBI_Guildbank;
1878 local sendData;
1879
1880 -- Get number of online guild members
1881 local numTotal, numOnline = GetNumGuildMembers();
1882
1883 -- Exit if tracking is turned off
1884 if ( not UBI_Options["track_gb_data"] ) then return; end;
1885
1886 -- Only send data when we have view access to all guildbank tabs
1887 if ( UBI_GUILDBANK_VIEWACCESS and numOnline > 1 ) then
1888 -- Show message
1889 UberInventory_Message( UBI_GB_SENDING, true );
1890
1891 -- Send start message
1892 TaskHandlerLib:AddTask( "UberInventory", UBI_Task_SendMessage, "GBSTART", UBI_VERSION );
1893
1894 -- Send the actual guildbank data
1895 for key, record in pairs( UBI_Guildbank[UBI_GUILD]["Items"] ) do
1896 -- Create data string
1897 sendData = key.." "..
1898 record["count"].." "..
1899 strgsub( record["name"], " ", "_" ).." "..
1900 strgsub( record["type"], " ", "_" ).." "..
1901 strgsub( record["subtype"], " ", "_" ).." "..
1902 record["level"].." "..
1903 record["quality"];
1904
1905 -- Send data string
1906 TaskHandlerLib:AddTask( "UberInventory", UBI_Task_SendMessage, "GBITEM", sendData );
1907 end;
1908
1909 -- Send cash
1910 TaskHandlerLib:AddTask( "UberInventory", UBI_Task_SendMessage, "GBCASH", UBI_Guildbank[UBI_GUILD]["Cash"] );
1911
1912 -- Send done message
1913 TaskHandlerLib:AddTask( "UberInventory", UBI_Task_SendMessage, "GBEND" );
1914 end;
1915 end;
1916
1917-- Check for expiring mails (only when the option warn_mailexpire is on)
1918 function UberInventory_MailExpirationCheck()
1919 -- From global to local
1920 local UBI_Data = UBI_Data;
1921 local realm, daysLeft;
1922
1923 if ( UBI_Options["warn_mailexpire"] ) then
1924 -- Check mail expiration for all characters from the current realm
1925 for key, record in pairs( UBI_Data ) do
1926 realm = key;
1927
1928 for player, value in pairs( UBI_Data[realm] ) do
1929 if ( player ~= "Guildbank" and value["Options"]["mail_expires"] ) then
1930 for key, record in pairs( value["Options"]["mail_expires"] ) do
1931 -- Get number of days till expiration (negative number are good)
1932 daysLeft = UberInventory_DaysSince( key );
1933
1934 -- If daysleft less then zero, mail expires into the future, positive numbers means the mail are already expired
1935 if ( daysLeft < 0 ) then
1936 daysLeft = abs( daysLeft );
1937 if ( daysLeft <= UBI_MAIL_EXPIRE_WARNING ) then
1938 UberInventory_Message( UBI_MAIL_EXPIRES:format( player, realm, record, daysLeft ), true );
1939 end;
1940 else
1941 UberInventory_Message( UBI_MAIL_LOST:format( player, realm, record, daysLeft ), true );
1942 end;
1943 end;
1944 end;
1945 end;
1946 end;
1947 end;
1948 end;
1949
1950-- Cleanup inventory
1951 function UberInventory_Cleanup()
1952 -- From global to local
1953 local UBI_Items = UBI_Items;
1954
1955 -- Remove items for which bag_count, bank_count, mailbox_count and equip_count equals 0
1956 for key, record in pairs( UBI_Items ) do
1957 if ( record.name ) then
1958 if ( record.bag_count + record.bank_count + record.mailbox_count + record.equip_count + ( record.void_count or 0 ) + ( record.reagent_count or 0 ) == 0 ) then
1959 -- Remove the item
1960 UBI_Items[key] = nil;
1961 end;
1962 else
1963 -- Remove the item if name is not found
1964 UBI_Items[key] = nil;
1965 end;
1966 end;
1967 end;
1968
1969-- Update inventory
1970 function UberInventory_UpdateInventory( location )
1971 -- Update the inventory
1972 if ( location == "bank" or location == "all" ) then
1973 UberInventory_Save_Bank();
1974 end;
1975 if ( location == "bag" or location == "all" ) then
1976 UberInventory_Save_Bag();
1977 end;
1978 if ( location == "mail" or location == "all" ) then
1979 UberInventory_Save_Mailbox();
1980 end;
1981 if ( location == "equip" or location == "all" ) then
1982 UberInventory_Save_Equipped();
1983 end;
1984 if ( location == "reagent" or location == "all" ) then
1985 UberInventory_Save_ReagentBank();
1986 end;
1987
1988 -- Store last update info
1989 UBI_SCAN_DATE = time();
1990
1991 -- Cleanup the inventory (remove zero-count items)
1992 UberInventory_Cleanup();
1993
1994 -- Get cash information
1995 UberInventory_SaveMoney();
1996
1997 -- Update wallet/mail info (if mainframe is shown)
1998 UberInventory_WalletMailCashInfo();
1999
2000 -- Update inventory frame if visible
2001 if ( UberInventoryFrame:IsVisible() ) then
2002 -- Update items
2003 UberInventory_DisplayItems();
2004
2005 -- Update token info on screen
2006 if ( UberInventoryTokens:IsVisible() ) then
2007 UberInventory_DisplayTokens();
2008 end;
2009
2010 -- Update slot count information
2011 UberInventory_Update_SlotCount();
2012 end;
2013 end;
2014
2015-- Handle UBI initialization
2016 function UberInventory_Init()
2017 -- Initiliaze all parts of the saved variable
2018 if ( UBI_Data == nil ) then
2019 UBI_Data = {};
2020 end;
2021
2022 if ( UBI_Data[UBI_REALM] == nil ) then
2023 UBI_Data[UBI_REALM] = {};
2024 end;
2025
2026 if ( UBI_Data[UBI_REALM][UBI_PLAYER] == nil ) then
2027 UBI_Data[UBI_REALM][UBI_PLAYER] = {};
2028 end;
2029
2030 if ( UBI_Data[UBI_REALM][UBI_PLAYER]["Options"] == nil ) then
2031 UBI_Data[UBI_REALM][UBI_PLAYER]["Options"] = { ["version"] = UBI_VERSION,
2032 ["show_money"] = UBI_Defaults["show_money"],
2033 ["show_balance"] = UBI_Defaults["show_balance"],
2034 ["show_tooltip"] = UBI_Defaults["show_tooltip"],
2035 ["show_item_count"] = UBI_Defaults["show_item_count"],
2036 ["show_sell_prices"] = UBI_Defaults["show_sell_prices"],
2037 ["show_recipe_prices"] = UBI_Defaults["show_recipe_prices"],
2038 ["show_recipe_reward"] = UBI_Defaults["show_recipe_reward"],
2039 ["show_recipe_drop"] = UBI_Defaults["show_recipe_drop"],
2040 ["show_minimap"] = UBI_Defaults["show_minimap"],
2041 ["show_highlight"] = UBI_Defaults["show_highlight"],
2042 ["track_gb_data"] = UBI_Defaults["track_gb_data"],
2043 ["send_gb_data"] = UBI_Defaults["send_gb_data"],
2044 ["receive_gb_data"] = UBI_Defaults["receive_gb_data"],
2045 ["warn_mailexpire"] = UBI_Defaults["warn_mailexpire"],
2046 ["pricing_data"] = "vendor",
2047 ["bag_max"] = 0,
2048 ["bag_free"] = 0,
2049 ["bank_max"] = 0,
2050 ["bank_free"] = 0,
2051 ["reagent_max"] = 0,
2052 ["reagent_free"] = 0,
2053 ["minimap"] = UBI_Defaults["minimap"],
2054 ["alpha"] = UBI_Defaults["alpha"],
2055 ["take_money"] = UBI_Defaults["take_money"],
2056 ["faction"] = UBI_FACTION,
2057 ["mail_expires"] = {},
2058 ["level"] = UnitLevel( "player" ),
2059 ["class"] = select( 2, UnitClass( "player" ) ),
2060 };
2061 end;
2062
2063 if ( UBI_Data[UBI_REALM][UBI_PLAYER]["Items"] == nil ) then
2064 UBI_Data[UBI_REALM][UBI_PLAYER]["Items"] = {};
2065 end;
2066
2067 if ( UBI_Data[UBI_REALM][UBI_PLAYER]["Money"] == nil ) then
2068 UBI_Data[UBI_REALM][UBI_PLAYER]["Money"] = { ["mail"] = 0,
2069 ["Cash"] = 0,
2070 ["Currencies"] = {} };
2071 end;
2072
2073 if ( UBI_Data[UBI_REALM]["Guildbank"] == nil ) then
2074 UBI_Data[UBI_REALM]["Guildbank"] = {};
2075 end;
2076
2077 -- Create global variables for easy reference
2078 UBI_Money = UBI_Data[UBI_REALM][UBI_PLAYER]["Money"];
2079 UBI_Items = UBI_Data[UBI_REALM][UBI_PLAYER]["Items"];
2080 UBI_Options = UBI_Data[UBI_REALM][UBI_PLAYER]["Options"];
2081 UBI_Guildbank = UBI_Data[UBI_REALM]["Guildbank"];
2082
2083 -- Upgrade data structures
2084 UberInventory_Upgrade();
2085
2086 -- Set faction again, to allow for faction change
2087 UBI_Options["faction"] = UBI_FACTION;
2088
2089 -- Build list of alts and guildbanks
2090 UberInventory_GetAlts();
2091 UberInventory_GetGuildbanks();
2092
2093 -- Build the inventory
2094 UberInventory_UpdateInventory( "all" );
2095
2096 -- Build list for locations
2097 UberInventory_Build_Locations();
2098
2099 -- Initialize Options dialog
2100 UberInventory_AddCategory( UberInventoryOptionsFrame );
2101
2102 -- Force refersh of stored currencies
2103 UberInventory_Save_Currencies();
2104
2105 UBI:RegisterEvent( "BAG_UPDATE" );
2106 end;
2107
2108-- Initialize guildbank data structure
2109 function UberInventory_Guildbank_Init()
2110 if ( IsInGuild() and UBI_Options["track_gb_data"] ) then
2111 if ( UBI_GUILD and not UBI_Guildbank[UBI_GUILD] ) then
2112 UBI_Guildbank[UBI_GUILD] = {};
2113 UBI_Guildbank[UBI_GUILD]["Items"] = {};
2114 UBI_Guildbank[UBI_GUILD]["Cash"] = 0;
2115 UBI_Guildbank[UBI_GUILD]["Faction"] = UBI_FACTION;
2116 end;
2117 end;
2118 end;
2119
2120-- Register events
2121 function UberInventory_RegisterEvents()
2122 for key, value in pairs( UBI_TRACKED_EVENTS ) do
2123 UBI:RegisterEvent( value );
2124 end;
2125 end;
2126
2127-- Register events
2128 function UberInventory_UnregisterEvents()
2129 for key, value in pairs( UBI_TRACKED_EVENTS ) do
2130 UBI:UnregisterEvent( value );
2131 end;
2132 end;
2133
2134-- Handle startup of the addon
2135 function UberInventory_OnLoad()
2136 -- Install hooks
2137 UberInventory_Install_Hooks();
2138
2139 -- Show startup message
2140 UberInventory_Message( UBI_STARTUP_MESSAGE, false );
2141
2142 -- Register slash commands
2143 SlashCmdList["UBI"] = UberInventory_SlashHandler;
2144 SLASH_UBI1 = "/ubi";
2145 SLASH_UBI2 = "/uberinventory";
2146
2147 -- Register events to be monitored
2148 UberInventory_RegisterEvents();
2149
2150 -- Correct quality list
2151 tinsert( UBI_QUALITY, 1, UBI_ALL_QUALITIES );
2152 end;
2153
2154-- Install all of the hooks used by UberInventory
2155 function UberInventory_Install_Hooks()
2156 -- Hook the Tooltips (OnTooltipSetItem, OnTooltipCleared)
2157 UberInventory_HookTooltip( GameTooltip );
2158 UberInventory_HookTooltip( ItemRefTooltip );
2159 UberInventory_HookTooltip( ShoppingTooltip1 );
2160 UberInventory_HookTooltip( ShoppingTooltip2 );
2161
2162 -- Hook mail stuff
2163 UBI_Hooks["ReturnInboxItem"] = ReturnInboxItem;
2164 ReturnInboxItem = UberInventory_ReturnInboxItem;
2165 UBI_Hooks["SendMail"] = SendMail;
2166 SendMail = UberInventory_SendMail;
2167 end;
2168
2169-- Track mails returned to (current account) characters
2170 function UberInventory_ReturnInboxItem( mailID )
2171 local _, _, mailSender, mailSubject, cashAttached, _, daysLeft, itemAttached = GetInboxHeaderInfo( mailID );
2172
2173 wipe( UBI_Mail_Transfer );
2174 UBI_Mail_Transfer.to = mailSender;
2175 UBI_Mail_Transfer.cash = cashAttached;
2176 UBI_Mail_Transfer.items = {};
2177
2178 for attachID = 1, ATTACHMENTS_MAX_RECEIVE do
2179 local itemName, _, _, itemCount = GetInboxItem( mailID, attachID );
2180 if ( itemName ) then
2181 local _, itemId = strsplit( ":", GetInboxItemLink( mailID, attachID ) );
2182 UBI_Mail_Transfer.items[itemId] = ( UBI_Mail_Transfer.items[itemId] or 0 ) + ( itemCount or 0 );
2183 end;
2184 end;
2185
2186 if ( UBI_Hooks["ReturnInboxItem"] ) then
2187 UBI_Hooks["ReturnInboxItem"]( mailID );
2188 end;
2189 end;
2190
2191-- Track mails sent to (current account) characters
2192 function UberInventory_SendMail( to, subject, body )
2193 wipe( UBI_Mail_Transfer );
2194 UBI_Mail_Transfer.to = to;
2195 UBI_Mail_Transfer.cash = GetSendMailMoney();
2196 UBI_Mail_Transfer.items = {};
2197
2198 for i = 1, ATTACHMENTS_MAX_SEND do
2199 local itemName, itemTexture, itemCount = GetSendMailItem( i );
2200 if ( itemName ) then
2201 local _, itemId = strsplit( ":", GetSendMailItemLink( i ) );
2202 UBI_Mail_Transfer.items[itemId] = ( UBI_Mail_Transfer.items[itemId] or 0 ) + itemCount;
2203 end;
2204 end;
2205
2206 if ( UBI_Hooks["SendMail"] ) then
2207 UBI_Hooks["SendMail"]( to, subject, body );
2208 end;
2209 end;
2210
2211-- Transfer gold/items between characters
2212 function UberInventory_Transfer()
2213 if ( UBI_Mail_Transfer.to ) then
2214 if ( UBI_Data[UBI_REALM][UBI_Mail_Transfer.to] ) then
2215 -- Determine expiration date/time of transfered cash/items
2216 local daysLeft = time( UberInventory_GetDateTime() ) + ( 30 * UBI_SEC_IN_DAY );
2217
2218 -- Transfer cash
2219 UBI_Data[UBI_REALM][UBI_Mail_Transfer.to]["Money"]["mail"] = ( UBI_Data[UBI_REALM][UBI_Mail_Transfer.to]["Money"]["mail"] or 0 ) + UBI_Mail_Transfer.cash;
2220
2221 -- Transfer items
2222 local itemName, itemLink, itemQuality, itemLevel, itemClass, itemSubclass, tempItem, _;
2223 local itemCount = 0;
2224 for key, value in pairs( UBI_Mail_Transfer.items ) do
2225 itemName, itemLink, itemQuality, itemLevel, _, itemClass, itemSubclass = GetItemInfo( key );
2226 tempItem = UBI_Data[UBI_REALM][UBI_Mail_Transfer.to]["Items"][key];
2227 if ( tempItem ) then
2228 UBI_Data[UBI_REALM][UBI_Mail_Transfer.to]["Items"][key] = { ["itemid"] = tonumber( key ),
2229 ["name"] = itemName,
2230 ["quality"] = itemQuality,
2231 ["level"] = itemLevel,
2232 ["bag_count"] = tempItem["bag_count"],
2233 ["bank_count"] = tempItem["bank_count"],
2234 ["mailbox_count"] = tempItem["mailbox_count"] + value,
2235 ["equip_count"] = tempItem["equip_count"],
2236 ["void_count"] = ( tempItem["void_count"] or 0 ),
2237 ["reagent_count"] = ( tempItem["reagent_count"] or 0 ),
2238 ["type"] = itemClass,
2239 ["subtype"] = itemSubclass,
2240 ["total"] = tempItem["total"] + value,
2241 ["qitem"] = tempItem["qitem"],
2242 ["qid"] = tempItem["qitem"],
2243 };
2244 else
2245 UBI_Data[UBI_REALM][UBI_Mail_Transfer.to]["Items"][key] = { ["itemid"] = tonumber( key ),
2246 ["name"] = itemName,
2247 ["quality"] = itemQuality,
2248 ["level"] = itemLevel,
2249 ["bag_count"] = 0,
2250 ["bank_count"] = 0,
2251 ["mailbox_count"] = value,
2252 ["equip_count"] = 0,
2253 ["void_count"] = 0,
2254 ["reagent_count"] = 0,
2255 ["type"] = itemClass,
2256 ["subtype"] = itemSubclass,
2257 ["total"] = value,
2258 };
2259 end;
2260 itemCount = itemCount + 1;
2261 end;
2262
2263 -- Register new expiration
2264 if ( UBI_Mail_Transfer.cash > 0 or itemCount > 0 ) then
2265 UBI_Data[UBI_REALM][UBI_Mail_Transfer.to]["Options"]["mail_expires"][daysLeft] = ( UBI_Data[UBI_REALM][UBI_Mail_Transfer.to]["Options"]["mail_expires"][daysLeft] or 0 ) + 1;
2266 end;
2267 end;
2268 end;
2269
2270 -- Force refresh if main window is open
2271 if ( UberInventoryFrame:IsVisible() ) then
2272 UberInventory_DisplayItems();
2273 end;
2274
2275 -- Clear temporary data
2276 wipe( UBI_Mail_Transfer );
2277 end;
2278
2279-- Handle events sent to the addon
2280 function UberInventory_OnEvent( self, event, ... )
2281 -- Get additional arguments
2282 local arg1, arg2, arg3, arg4 = ...;
2283
2284 -- Load data from previous session
2285 if ( event == "ADDON_LOADED" and arg1 == "UberInventory" ) then
2286 -- Execute main initialization code
2287 UberInventory_Init();
2288
2289 -- Track current player level and class
2290 UBI_Options["level"] = UnitLevel( "player" );
2291 UBI_Options["class"] = select( 2, UnitClass( "player" ) );
2292
2293 -- Check bank visit
2294 if ( UberInventory_DaysSince( UBI_Options["bank_visit"] ) >= UBI_BANK_VISIT_INTERVAL ) then
2295 UberInventory_Message( UBI_LAST_BANK_VISIT:format( UberInventory_DaysSince( UBI_Options["bank_visit"] ) ), true );
2296 else
2297 if ( not UBI_Options["bank_visit"] ) then UberInventory_Message( UBI_VISIT_BANK, true ); end;
2298 end;
2299
2300 -- Check guildbank visit
2301 if ( IsInGuild() ) then
2302 if ( UberInventory_DaysSince( UBI_Options["guildbank_visit"] ) >= UBI_GUILDBANK_VISIT_INTERVAL ) then
2303 UberInventory_Message( UBI_LAST_GUILDBANK_VISIT:format( UberInventory_DaysSince( UBI_Options["guildbank_visit"] ) ), true );
2304 else
2305 if ( not UBI_Options["guildbank_visit"] ) then UberInventory_Message( UBI_VISIT_GUILDBANK, true ); end;
2306 end;
2307 end;
2308
2309 -- Check mailbox visit
2310 if ( UberInventory_DaysSince( UBI_Options["mail_visit"] ) >= UBI_MAILBOX_VISIT_INTERVAL ) then
2311 UberInventory_Message( UBI_LAST_MAILBOX_VISIT:format( UberInventory_DaysSince( UBI_Options["mail_visit"] ) ), true );
2312 else
2313 if ( not UBI_Options["mail_visit"] ) then UberInventory_Message( UBI_VISIT_MAILBOX, true ); end;
2314 end;
2315
2316 -- Check for mail that are about to expire
2317 UberInventory_MailExpirationCheck();
2318
2319 -- Show or hide the minimap icon
2320 UberInventory_Minimap_Toggle();
2321
2322 -- Assign proper location for minimap
2323 UberInventory_Minimap_Update( UBI_Options["minimap"] );
2324
2325 -- Set transparency
2326 UberInventory_Change_Alpha( UBI_Options["alpha"] );
2327
2328 -- Broadcast current version to the guild
2329 UBI_Task_SendMessage( "VERINFO", UBI_VERSION );
2330
2331 return;
2332 end;
2333
2334 -- Track the new level of the player
2335 if ( event == "PLAYER_LEVEL_UP" ) then
2336 -- Track current player level and rebuild the list
2337 UBI_Options["level"] = arg1;
2338 UberInventory_Build_Locations();
2339 end;
2340
2341 if ( event == "PLAYER_LEAVING_WORLD" ) then
2342 UBI_ACTIVE = false;
2343 end;
2344
2345 -- Update info inventory change (enters the world, enters/leaves an instance, or respawns at a graveyard, reloadui)
2346 if ( event == "PLAYER_ENTERING_WORLD" ) then
2347 UBI_ACTIVE = true;
2348
2349 -- Register AddOn Message prefix (4.1)
2350 RegisterAddonMessagePrefix( "UBI" );
2351
2352 -- Update balance frame
2353 UberInventory_ShowBalanceFrame( UBI_Options["show_balance"] );
2354
2355 -- Get guild name
2356 UBI_GUILD = GetGuildInfo( "player" );
2357 UberInventory_Guildbank_Init();
2358
2359 UberInventory_UpdateInventory( "all" );
2360 return;
2361 end;
2362
2363 if ( event == "UNIT_INVENTORY_CHANGED" and arg1 == "player" ) then
2364 UberInventory_UpdateInventory( "equip" );
2365 return;
2366 end;
2367
2368 -- After a money event show the current cash amount
2369 if ( event == "PLAYER_MONEY" ) then
2370 -- Save current cash balance
2371 UberInventory_SaveMoney();
2372
2373 -- Update wallet/mail info (if mainframe is shown)
2374 UberInventory_WalletMailCashInfo();
2375
2376 -- Show message
2377 if ( UBI_Options["show_money"] ) then
2378 UberInventory_Message( UBI_MONEY_MESSAGE:format( GetCoinTextureString( GetMoney() ) ), true );
2379 end;
2380 return;
2381 end;
2382
2383 -- On currency changes update stored data and refresh UI
2384 if ( event == "CURRENCY_DISPLAY_UPDATE" ) then
2385 -- Save other currencies
2386 if ( UBI_Money ) then
2387 UberInventory_Save_Currencies();
2388 end;
2389
2390 -- Update token info on screen
2391 if ( UberInventoryTokens:IsVisible() ) then
2392 UberInventory_DisplayTokens();
2393 end;
2394
2395 return;
2396 end;
2397
2398 -- Bank closed
2399 if ( event == "BANKFRAME_CLOSED" ) then
2400 UBI_BANK_OPEN = false;
2401 return;
2402 end;
2403
2404 -- Bank opened
2405 if ( event == "BANKFRAME_OPENED" ) then
2406 UBI_BANK_OPEN = true;
2407 UBI_Options["bank_visit"] = UberInventory_GetDateTime();
2408 UberInventory_UpdateInventory( "bank" );
2409 return;
2410 end;
2411
2412 -- Items in the bank have changed
2413 if ( event == "PLAYERREAGENTBANKSLOTS_CHANGED" ) then
2414 UberInventory_UpdateInventory( "reagent" );
2415 return;
2416 end;
2417
2418 -- Items in the bank have changed
2419 if ( event == "PLAYERBANKSLOTS_CHANGED" or event == "PLAYERBANKBAGSLOTS_CHANGED" ) then
2420 UberInventory_UpdateInventory( "bank" );
2421 return;
2422 end;
2423
2424 -- Guildbank closed (send guildbank data using the chat system)
2425 if ( event == "GUILDBANKFRAME_CLOSED" and UBI_GUILDBANK_OPENED and UBI_Options["track_gb_data"] ) then
2426 -- Store guildbank cash
2427 UBI_Guildbank[UBI_GUILD]["Cash"] = GetGuildBankMoney();
2428
2429 -- Start sending guildbank data
2430 if ( UBI_Options["send_gb_data"] ) then
2431 UberInventory_Send_Guildbank();
2432 end;
2433 UBI:UnregisterEvent( "GUILDBANKBAGSLOTS_CHANGED" );
2434 UBI:UnregisterEvent( "GUILDBANK_UPDATE_TABS" );
2435
2436 UBI_GUILDBANK_OPENED = false;
2437 return;
2438 end;
2439
2440 -- Guild cash changed
2441 if ( event == "GUILDBANK_UPDATE_MONEY" and IsInGuild() and UBI_Options["track_gb_data"] ) then
2442 if ( UBI_Guildbank and UBI_Guildbank[UBI_GUILD] and UBI_Guildbank[UBI_GUILD]["Cash"] ) then
2443 UBI_Guildbank[UBI_GUILD]["Cash"] = GetGuildBankMoney();
2444 end;
2445
2446 -- Update cash info on screen
2447 if ( UberInventoryFrame:IsVisible() ) then
2448 UberInventory_DisplayItems();
2449 end;
2450 return;
2451 end;
2452
2453 -- Guildbank opened
2454 if ( event == "GUILDBANKFRAME_OPENED" and UBI_Options["track_gb_data"] ) then
2455 -- Track Guildbank open
2456 UBI_GUILDBANK_OPENED = true;
2457
2458 UBI:RegisterEvent( "GUILDBANKBAGSLOTS_CHANGED" );
2459 UBI:RegisterEvent( "GUILDBANK_UPDATE_TABS" );
2460
2461 -- Traverse guild bank tabs and force loading of data
2462 for gbTab = 1, GetNumGuildBankTabs() do
2463 -- Retrieve data from the server (only for visible tabs to prevent warnings)
2464 local name, icon, isViewable = GetGuildBankTabInfo( gbTab );
2465 if ( isViewable ) then
2466 TaskHandlerLib:AddTask( "UberInventory", QueryGuildBankTab, gbTab );
2467 end;
2468 end;
2469
2470 -- Track Guildbank last visit date/time
2471 UBI_Options["guildbank_visit"] = UberInventory_GetDateTime();
2472
2473 return;
2474 end;
2475
2476 -- Update Guildbank information
2477 if ( ( event == "GUILDBANK_UPDATE_TABS" or event == "GUILDBANKBAGSLOTS_CHANGED" ) and UBI_GUILDBANK_OPENED and UBI_Options["track_gb_data"] ) then
2478 -- Send start message
2479 UberInventory_Save_Guildbank( event );
2480 return;
2481 end;
2482
2483 -- Mailbox opened
2484 if ( event == "MAIL_SHOW" ) then
2485 UBI_MAILBOX_OPEN = true;
2486 UBI:RegisterEvent( "MAIL_CLOSED" );
2487 UBI:RegisterEvent( "MAIL_INBOX_UPDATE" );
2488 return;
2489 end;
2490
2491 -- Mailbox changes
2492 if ( event == "MAIL_INBOX_UPDATE" ) then
2493 UBI:UnregisterEvent( "MAIL_INBOX_UPDATE" ); -- Prevent additional MAIL_INBOX_UPDATE event to be handled
2494 UberInventory_UpdateInventory( "mail" );
2495 return;
2496 end;
2497
2498 -- Mailbox closed
2499 if ( event == "MAIL_CLOSED" ) then
2500 UBI:UnregisterEvent( "MAIL_CLOSED" ); -- Prevent second MAIL_CLOSED event to be handled
2501 UBI:RegisterEvent( "MAIL_INBOX_UPDATE" ); -- Re-register MAIL_INBOX_UPDATE event
2502 UBI_Options["mail_visit"] = UberInventory_GetDateTime();
2503 UberInventory_UpdateInventory( "mail" );
2504 UBI_MAILBOX_OPEN = false;
2505 return;
2506 end;
2507
2508 -- Record transferred gold/items
2509 if ( event == "MAIL_SUCCESS" ) then
2510 UberInventory_Transfer();
2511 return;
2512 end;
2513
2514 -- Items in the bags have changed
2515 if ( event == "BAG_UPDATE" and arg1 >= -2 ) then
2516 -- Update inventory
2517 UberInventory_UpdateInventory( "bag" );
2518
2519 -- If bank is open rescan item
2520 if ( ( arg1 == BANK_CONTAINER) or ( arg1 == REAGENTBANK_CONTAINER ) or ( arg1 >= 5 and arg1 <= 11 ) ) then UberInventory_Save_Bank(); end;
2521
2522 -- If guildbank is open rescan it
2523 if ( UBI_GUILDBANK_OPENED ) then UberInventory_Save_Guildbank( 'UBI_RESCAN_GUILDBANK' ); end;
2524 return;
2525 end;
2526
2527 -- Void Storage events
2528 if ( event == "VOID_STORAGE_OPEN" or event == "VOID_STORAGE_CLOSE" or event == "VOID_STORAGE_UPDATE" or event == "VOID_TRANSFER_DONE" or event == "VOID_STORAGE_CONTENTS_UPDATE" ) then
2529 UberInventory_Save_VoidStorage( event );
2530 end;
2531
2532 -- Handle UberInventory related guildchat messages
2533 if ( event == "CHAT_MSG_ADDON" and arg1 == "UBI" and arg4 ~= UBI_PLAYER and ( UBI_Options["receive_gb_data"] or UBI_GUILDBANK_FORCED ) ) then
2534 if ( arg2:find( "UBI:VERINFO" ) ) then
2535 -- Extract version number from the data string
2536 local _, gbVersion = strsplit( " ", arg2 );
2537
2538 -- Check if there is a more recent version of UberInventory
2539 if ( tonumber( gbVersion ) > ( tonumber( UBI_VERSION ) or 0 ) and not UBI_VERSION_WARNING ) then
2540 UberInventory_Message( UBI_NEW_VERSION:format( arg4, gbVersion ), true );
2541 UBI_VERSION_WARNING = true;
2542 end;
2543
2544 -- If this version is more recent send message to other users using this addon
2545 if ( tonumber( gbVersion ) < ( tonumber( UBI_VERSION ) or 0 ) ) then
2546 UBI_Task_SendMessage( "VERINFO", UBI_VERSION );
2547 end;
2548 elseif ( arg2:find( "UBI:GBSTART" ) and not UBI_GUILDBANK_OPENED ) then
2549 -- Start receiving Guildbank data, reset on each new receive from player.
2550 -- This way only the most recent data should be received.
2551 -- Only data from equal versions is allowed
2552 wipe( UBI_GBData );
2553 UBI_GBSender = arg4;
2554 elseif ( arg2:find( "UBI:GBITEM" ) and not UBI_GUILDBANK_OPENED ) then
2555 -- Receiving Guildbank data (item), only receive data from latest sender
2556 if ( UBI_GBSender == arg4 and UBI_Options["track_gb_data"] ) then
2557 local _, itemID, itemCount, itemName, itemType, itemSubtype, itemLevel, itemQuality, extra = strsplit( " ", arg2 );
2558 UBI_GBData[itemID] = { ["itemid"] = tonumber( itemID ),
2559 ["count"] = tonumber( itemCount ),
2560 ["name"] = strgsub( itemName, "_", " " ),
2561 ["type"] = strgsub( itemType, "_", " " ),
2562 ["subtype"] = strgsub( itemSubtype, "_", " " ),
2563 ["level"] = tonumber( itemLevel ),
2564 ["quality"] = tonumber( itemQuality ) };
2565 end;
2566 elseif ( arg2:find( "UBI:GBCASH" ) and not UBI_GUILDBANK_OPENED ) then
2567 -- Receiving Guildbank cash, only receive data from latest sender
2568 if ( UBI_GBSender == arg4 and UBI_Options["track_gb_data"] ) then
2569 -- Init guildbank structures (if needed)
2570 UberInventory_Guildbank_Init();
2571
2572 local _, gbCash = strsplit( " ", arg2 );
2573 UBI_Guildbank[UBI_GUILD]["Cash"] = tonumber( gbCash );
2574
2575 -- Update cash info on screen
2576 if ( UberInventoryFrame:IsVisible() ) then
2577 UberInventory_DisplayItems();
2578 end;
2579 end;
2580 elseif ( arg2:find( "UBI:GBEND" ) and not UBI_GUILDBANK_OPENED ) then
2581 -- Stop receiving Guildbank data and process the received data, only process data from latest sender
2582 if ( UBI_GBSender == arg4 and UBI_Options["track_gb_data"] ) then
2583 UberInventory_Receive_Guildbank();
2584 UBI_GUILDBANK_FORCED = false;
2585 end;
2586 end;
2587 end;
2588
2589 -- Handle request for sending guildbank data
2590 if ( event == "CHAT_MSG_ADDON" and arg1 == "UBI" and arg4 ~= UBI_PLAYER ) then
2591 if ( arg2:find( "UBI:GBREQUEST" ) and UBI_Options["track_gb_data"] ) then
2592 if ( UBI_GUILDBANK_OPENED and UBI_GUILDBANK_VIEWACCESS ) then
2593 UberInventory_Send_Guildbank();
2594 end;
2595 end;
2596 end;
2597
2598 -- Pandarian toon has selected faction
2599 if ( event == "NEUTRAL_FACTION_SELECT_RESULT" ) then
2600 UberInventory_GetAlts();
2601 UberInventory_GetGuildbanks();
2602 end;
2603
2604 -- Build the inventory
2605 UberInventory_UpdateInventory( "all" );
2606
2607 -- Build list for locations
2608 UberInventory_Build_Locations();
2609
2610 -- Rebuild list of guildbanks
2611 if ( UBI_GUILD ~= GetGuildInfo( "player" ) ) then
2612 UBI_GUILD = GetGuildInfo( "player" );
2613 UberInventory_Guildbank_Init();
2614 UberInventory_GetGuildbanks();
2615 UberInventory_Build_Locations();
2616 end;
2617 end;
2618
2619-- Show or hide the balance frame
2620 function UberInventory_ShowBalanceFrame( showFrame )
2621 if ( showFrame ) then
2622 UberInventoryBalanceFrame:Show();
2623 MoneyFrame_Update( "UberInventoryBalanceFrameMoneyFrame", GetMoney() );
2624 else
2625 UberInventoryBalanceFrame:Hide();
2626 end;
2627 end;
2628
2629-- Update minimap button
2630 function UberInventory_Minimap_Update( angle )
2631 -- Only redraw the icon if the angle has changed
2632 if ( UBI_MINIMAP_ANGLE ~= angle ) then
2633 UberInventoryMinimap:SetPoint( "TOPLEFT",
2634 "Minimap",
2635 "TOPLEFT",
2636 54 - (78 * cos( angle )),
2637 (78 * sin( angle )) - 55 );
2638 end;
2639
2640 -- Update current angle
2641 UBI_MINIMAP_ANGLE = angle;
2642 end;
2643
2644-- Update minimap button
2645 function UberInventory_Minimap_Toggle()
2646 if ( UBI_Options["show_minimap"]) then
2647 UberInventoryMinimap:Show();
2648 else
2649 UberInventoryMinimap:Hide();
2650 end;
2651 end;
2652
2653-- Update transparency of frames
2654 function UberInventory_Change_Alpha( alpha )
2655 UberInventoryFrameTexture:SetAlpha( alpha );
2656 UberInventoryFrameBorderTexture:SetAlpha( alpha );
2657 UberInventoryTokensTexture:SetAlpha( alpha );
2658 UberInventoryTokensBorderTexture:SetAlpha( alpha );
2659 end;
2660
2661
2662-- Handle Pricing info radio buttons
2663 function UberInventory_Change_Pricing( id )
2664 -- Turn all buttons off
2665 SettingPriceVendor:SetChecked( nil );
2666 SettingPriceAH:SetChecked( nil );
2667
2668 -- Turn only the clicked button on
2669 if ( id == 16 ) then
2670 SettingPriceVendor:SetChecked( true );
2671 elseif ( id == 17 ) then
2672 SettingPriceAH:SetChecked( true );
2673 end;
2674 end;
2675
2676-- Init frame options
2677 function UberInventory_SetOptions( frame )
2678 -- Initiliaze
2679 local UBI_Options = UBI_Options;
2680
2681 -- Apply settings to the frame
2682 _G[ "SettingMoney" ]:SetChecked( UBI_Options["show_money"] );
2683 _G[ "SettingBalance" ]:SetChecked( UBI_Options["show_balance"] );
2684 _G[ "SettingShowTooltip" ]:SetChecked( UBI_Options["show_tooltip"] );
2685 _G[ "SettingSellPrice" ]:SetChecked( UBI_Options["show_sell_prices"] );
2686 _G[ "SettingRecipePrice" ]:SetChecked( UBI_Options["show_recipe_prices"] );
2687 _G[ "SettingQuestReward" ]:SetChecked( UBI_Options["show_recipe_reward"] );
2688 _G[ "SettingRecipeDrop" ]:SetChecked( UBI_Options["show_recipe_drop"] );
2689 _G[ "SettingHighlight" ]:SetChecked( UBI_Options["show_highlight"] );
2690 _G[ "SettingInboxMoney" ]:SetChecked( UBI_Options["take_money"] );
2691 _G[ "SettingShowMinimap" ]:SetChecked( UBI_Options["show_minimap"] );
2692 _G[ "SettingMinimap" ]:SetValue( UBI_Options["minimap"] );
2693 _G[ "SettingAlpha" ]:SetValue( UBI_Options["alpha"] );
2694 _G[ "SettingSendGuildbankData" ]:SetChecked( UBI_Options["send_gb_data"] );
2695 _G[ "SettingReceiveGuildbankData" ]:SetChecked( UBI_Options["receive_gb_data"] );
2696 _G[ "SettingTrackGuildbankData" ]:SetChecked( UBI_Options["track_gb_data"] );
2697 _G[ "SettingWarnMailExpire" ]:SetChecked( UBI_Options["warn_mailexpire"] );
2698 _G[ "SettingShowItemcount" ]:SetChecked( UBI_Options["show_item_count"] );
2699
2700 if ( UBI_Options["pricing_data"] == "vendor" ) then
2701 UberInventory_Change_Pricing( 16 );
2702 elseif ( UBI_Options["pricing_data"] == "AH" ) then
2703 UberInventory_Change_Pricing( 17 );
2704 end;
2705
2706 UberInventory_Redraw_TooltipOptions();
2707 UberInventory_Redraw_MinimapOptions();
2708 end;
2709
2710-- Redraw state for tooltip options
2711 function UberInventory_Redraw_TooltipOptions()
2712 local state = _G[ "SettingShowTooltip" ]:GetChecked();
2713
2714 UberInventory_SetState( _G[ "SettingSellPrice" ], state );
2715 UberInventory_SetState( _G[ "SettingRecipePrice" ], state );
2716 UberInventory_SetState( _G[ "SettingQuestReward" ], state );
2717 UberInventory_SetState( _G[ "SettingRecipeDrop" ], state );
2718 end;
2719
2720-- Redraw state for minimap options
2721 function UberInventory_Redraw_MinimapOptions()
2722 local state = _G[ "SettingShowMinimap" ]:GetChecked();
2723
2724 UberInventory_SetState( _G[ "SettingMinimap" ], state );
2725 end;
2726
2727-- Save frame options
2728 function UberInventory_SaveOptions( frame )
2729 -- Initiliaze
2730 local UBI_Options = UBI_Options;
2731
2732 -- Save settings from the frame
2733 UBI_Options["show_money"] = _G[ "SettingMoney" ]:GetChecked();
2734 UBI_Options["show_balance"] = _G[ "SettingBalance" ]:GetChecked();
2735 UBI_Options["show_tooltip"] = _G[ "SettingShowTooltip" ]:GetChecked();
2736 UBI_Options["show_sell_prices"] = _G[ "SettingSellPrice" ]:GetChecked();
2737 UBI_Options["show_recipe_prices"] = _G[ "SettingRecipePrice" ]:GetChecked();
2738 UBI_Options["show_recipe_reward"] = _G[ "SettingQuestReward" ]:GetChecked();
2739 UBI_Options["show_recipe_drop"] = _G[ "SettingRecipeDrop" ]:GetChecked();
2740 UBI_Options["show_highlight"] = _G[ "SettingHighlight" ]:GetChecked();
2741 UBI_Options["show_item_count"] = _G[ "SettingShowItemcount" ]:GetChecked();
2742 UBI_Options["take_money"] = _G[ "SettingInboxMoney" ]:GetChecked();
2743 UBI_Options["show_minimap"] = _G[ "SettingShowMinimap" ]:GetChecked();
2744 UBI_Options["minimap"] = _G[ "SettingMinimap" ]:GetValue();
2745 UBI_Options["alpha"] = _G[ "SettingAlpha" ]:GetValue();
2746 UBI_Options["send_gb_data"] = _G[ "SettingSendGuildbankData" ]:GetChecked();
2747 UBI_Options["receive_gb_data"] = _G[ "SettingReceiveGuildbankData" ]:GetChecked();
2748 UBI_Options["track_gb_data"] = _G[ "SettingTrackGuildbankData" ]:GetChecked();
2749 UBI_Options["warn_mailexpire"] = _G[ "SettingWarnMailExpire" ]:GetChecked();
2750
2751 if ( _G[ "SettingPriceVendor" ]:GetChecked() ) then
2752 UBI_Options["pricing_data"] = "vendor";
2753 else
2754 UBI_Options["pricing_data"] = "AH";
2755 end;
2756
2757 end;
2758
2759-- Apply setting to the UI
2760 function UberInventory_UpdateUI()
2761 -- Initiliaze
2762 local UBI_Options = UBI_Options;
2763
2764 -- Hide or show balance frame based on the current settings (look for a more elegant solution)
2765 UberInventory_ShowBalanceFrame( UBI_Options["show_balance"] );
2766
2767 -- Show or hide minimap icon
2768 UberInventory_Minimap_Toggle();
2769
2770 -- Restore or set minimap location
2771 UberInventory_Minimap_Update( UBI_Options["minimap"] );
2772
2773 -- Restore or set transparency
2774 UberInventory_Change_Alpha( UBI_Options["alpha"] );
2775
2776 -- Force refresh
2777 UberInventory_DisplayItems();
2778 end;
2779
2780-- Revert all options to default values
2781 function UberInventory_SetDefaults( frame )
2782 -- Initiliaze
2783 local UBI_Options = UBI_Options;
2784
2785 -- Restore defaults
2786 for key, value in pairs( UBI_Defaults ) do
2787 UBI_Options[key] = value;
2788 end;
2789
2790 -- Hide or show balance frame based on the current settings (look for a more elegant solution)
2791 UberInventory_ShowBalanceFrame( UBI_Options["show_balance"] );
2792
2793 -- Show or hide minimap icon
2794 UberInventory_Minimap_Toggle();
2795
2796 -- Restore or set minimap location
2797 UberInventory_Minimap_Update( UBI_Options["minimap"] );
2798
2799 -- Restore or set transparency
2800 UberInventory_Change_Alpha( UBI_Options["alpha"] );
2801
2802 -- Redraw Options frame
2803 UberInventory_SetOptions( frame );
2804 end;
2805
2806-- Make Settings frame known to the system
2807 function UberInventory_AddCategory( frame )
2808 -- Set panel name
2809 frame.name = UBI_NAME;
2810
2811 -- Set okay function
2812 frame.okay = function( self )
2813 UberInventory_SaveOptions( self );
2814 UberInventory_UpdateUI();
2815 end;
2816
2817 -- Set cancel function
2818 frame.cancel = function( self )
2819 UberInventory_SetOptions( self );
2820 UberInventory_UpdateUI();
2821 end;
2822
2823 -- set defaults function
2824 frame.default = function( self )
2825 UberInventory_SetDefaults( self );
2826 UberInventory_UpdateUI();
2827 end;
2828
2829 -- Add the panel
2830 InterfaceOptions_AddCategory( frame );
2831 end;
2832
2833-- Update button mask to indicate item usability (clear = usable, red = usuable, blue = uncached item)
2834 function UberInventory_MarkButton( button, itemid )
2835 -- Clear state
2836 button:SetAttribute( "usable", nil );
2837
2838 -- Reapply color coding
2839 if UberInventory_UsableItem( itemid ) then
2840 SetItemButtonTextureVertexColor( button, 1, 1, 1 );
2841 else
2842 SetItemButtonTextureVertexColor( button, 1, 0.1, 0.1 );
2843 end;
2844
2845 -- Item still not locally cached, mark it again
2846 if ( not GetItemInfo( itemid ) ) then
2847 button:SetAttribute( "usable", "uncached" );
2848 SetItemButtonTextureVertexColor( button, 0.2, 0.2, 0.8 );
2849 end;
2850 end;
2851
2852-- Handle uncached items
2853 function UberInventory_ItemButton_OnUpdate( self, elapsed )
2854 -- Initialize
2855 local state = self:GetAttribute( "usable" );
2856 local total_elapsed = self:GetAttribute( "elapsed" ) + elapsed;
2857
2858 -- To minimize load perform the rest only if item is uncached and concerns a visible button
2859 if ( state and state == "uncached" and self:IsVisible() ) then
2860 -- Update total elapsed time since last real call
2861 self:SetAttribute( "elapsed", total_elapsed );
2862
2863 -- Re-mark the button and reset elapsed
2864 if ( total_elapsed > 0.5 ) then
2865 UberInventory_MarkButton( self, self:GetID() );
2866 self:SetAttribute( "elapsed", 0 );
2867 end;
2868 end;
2869 end;
2870
2871-- Update cash field
2872 function UberInventory_UpdateCashField( frame, cash, prefix )
2873 -- Update cash info and resize frame
2874 if ( cash > 0 ) then
2875 frame:SetText( (prefix or "")..GetCoinTextureString( cash ).." " );
2876 else
2877 frame:SetText( (prefix or "").."- " );
2878 end;
2879 end;
2880
2881-- Update inventory button
2882 function UberInventory_UpdateButton( slot, record )
2883 local objSlot = _G[ "UberInventoryFrameItem"..slot ];
2884 local button = objSlot:GetName().."ItemButton";
2885 local buttonObj = _G[ button ];
2886
2887 -- Record is nil, item does not exist and button should be hidden
2888 if ( not record ) then
2889 objSlot:Hide();
2890 return;
2891 else
2892 objSlot:Show();
2893 end;
2894
2895 -- Get itemID
2896 local itemid = record["itemid"];
2897
2898 -- Get item prices
2899 local buyPrice, sellPrice, buyoutPrice = UberInventory_GetItemPrices( itemid );
2900
2901 -- Get item counts
2902 local bagCount = record["bag_count"] or 0;
2903 local bankCount = record["bank_count"] or 0;
2904 local mailCount = record["mailbox_count"] or 0;
2905 local equipCount = record["equip_count"] or 0;
2906 local voidCount = record["void_count"] or 0;
2907 local reagentCount = record["reagent_count"] or 0;
2908 local guildCount = record["count"] or 0;
2909 local totalCount = record["total"] or 0;
2910
2911 -- Quest information
2912 local questID = ( record["qid"] or 0 );
2913 local questItem = ( record["qitem"] or flase );
2914
2915 -- Get correct totalCount for combined inventory searches
2916 if ( UBI_LocationList[UBI_FILTER_LOCATIONS].type == "complete" or UBI_LocationList[UBI_FILTER_LOCATIONS].type == "all_character" or UBI_LocationList[UBI_FILTER_LOCATIONS].type == "all_guildbank" ) then
2917 totalCount = UBI_Track[record.itemid] or 0;
2918 end;
2919
2920 -- Set item image
2921 if ( record["type"] == UBI_BATTLEPET_CLASS and itemid ~= 82800 ) then
2922 local _, icon = C_PetJournal.GetPetInfoBySpeciesID( itemid );
2923 SetItemButtonTexture( buttonObj, icon );
2924 else
2925 SetItemButtonTexture( buttonObj, GetItemIcon( itemid ) );
2926 end;
2927
2928 -- Set item name
2929 local itemcolor = ITEM_QUALITY_COLORS[record.quality];
2930 _G[ button.."ItemName" ]:SetText( record["name"] );
2931 _G[ button.."ItemName" ]:SetTextColor( itemcolor.r, itemcolor.g, itemcolor.b );
2932
2933
2934 -- Set item count
2935 if ( UBI_LocationList[UBI_FILTER_LOCATIONS].type == "current" or UBI_LocationList[UBI_FILTER_LOCATIONS].type == "character" ) then
2936 _G[ button.."ItemCount" ]:SetFormattedText( UBI_ITEM_COUNT, totalCount, bagCount, bankCount, mailCount, equipCount, voidCount, reagentCount );
2937 else
2938 _G[ button.."ItemCount" ]:SetFormattedText( UBI_ITEM_COUNT_SINGLE, totalCount );
2939 end;
2940 SetItemButtonCount( buttonObj, totalCount );
2941
2942 -- Set item id (for tooltip)
2943 buttonObj:SetID( itemid );
2944 buttonObj:SetAttribute( "inventoryitem", record );
2945 buttonObj:SetAttribute( "location", UBI_FILTER_LOCATIONS );
2946 buttonObj:SetAttribute( "usable", nil );
2947 buttonObj:SetAttribute( "elapsed", 0 );
2948
2949 -- Update buy, buyout and sell prices
2950 if ( UBI_Options["pricing_data"] == "vendor" ) then
2951 -- Show sell price
2952 _G[ button.."ItemSell" ]:Show();
2953
2954 -- Update price fields
2955 UberInventory_UpdateCashField( _G[ button.."ItemBuy" ], buyPrice or 0, UBI_ITEM_BUY );
2956 UberInventory_UpdateCashField( _G[ button.."ItemSell" ], sellPrice or 0, UBI_ITEM_SELL );
2957 else
2958 -- Hide sell price
2959 _G[ button.."ItemSell" ]:Hide();
2960
2961 -- Update price field
2962 UberInventory_UpdateCashField( _G[ button.."ItemBuy" ], buyoutPrice or 0, UBI_ITEM_BUYOUT );
2963 end;
2964
2965 -- Mark usability onto the itembutton
2966 if ( record["type"] ~= UBI_BATTLEPET_CLASS ) then
2967 UberInventory_MarkButton( buttonObj, itemid );
2968 end;
2969
2970 -- Mark quest item
2971 local questTexture = _G[ button.."IconQuestTexture" ];
2972 if ( questID > 0 ) then
2973 questTexture:SetTexture( TEXTURE_ITEM_QUEST_BANG );
2974 questTexture:Show();
2975 elseif ( questItem ) then
2976 questTexture:SetTexture( TEXTURE_ITEM_QUEST_BORDER) ;
2977 questTexture:Show();
2978 else
2979 questTexture:Hide();
2980 end;
2981 end;
2982
2983-- Mousewheel support for scrolling through items
2984 function UberInventory_OnMouseWheel( frame, delta, type )
2985 local offset = FauxScrollFrame_GetOffset( frame ) or 0;
2986 local newOffset = math.max( offset - delta, 0 );
2987
2988 -- Update scroll positions and force redisplay of content
2989 if ( type == "ITEMS" ) then
2990 local maxOffset = ceil( ( #UBI_Sorted - UBI_NUM_ITEMBUTTONS ) / 2 );
2991 frame:SetVerticalScroll( math.min( maxOffset, newOffset ) * 36 );
2992 UberInventory_DisplayItems();
2993 else
2994 local maxOffset = #UBI_Currencies+1 - UBI_NUM_TOKENBUTTONS;
2995 frame:SetVerticalScroll( math.min( maxOffset, newOffset ) * 17 );
2996 UberInventory_DisplayTokens();
2997 end;
2998 end;
2999
3000-- Display items (by page, UBI_NUM_ITEMBUTTONS items)
3001 function UberInventory_DisplayItems()
3002 -- From global to local
3003 local UBI_Characters = UBI_Characters;
3004 local UBI_Guildbanks = UBI_Guildbanks;
3005 local UBI_Data = UBI_Data;
3006 local UBI_Guildbank = UBI_Guildbank;
3007 local UBI_Sorted = UBI_Sorted;
3008
3009 -- Create GB structure if it does not already exist
3010 UberInventory_Guildbank_Init();
3011
3012 -- Sort and filter items
3013 UberInventory_SortFilter( UBI_FILTER_TEXT or "", false );
3014
3015 -- Get current offset
3016 local offset = FauxScrollFrame_GetOffset( UberInventoryFrameScroll ) or 0;
3017
3018 -- Update scrollbars (reset scroll position when needed)
3019 if ( offset > ceil( (#UBI_Sorted-UBI_NUM_ITEMBUTTONS) / 2 ) ) then
3020 UberInventory_ScrollToTop();
3021 offset = 0;
3022 else
3023 FauxScrollFrame_Update( UberInventoryFrameScroll, ceil( #UBI_Sorted / 2 ), 8, 36 );
3024 end;
3025
3026 -- Execute code to actually add the items to the inventory frame
3027 local index;
3028 for slot = 1, UBI_NUM_ITEMBUTTONS do
3029 -- Calculate the actual index within sorted array
3030 index = ( offset * 2 ) + slot;
3031
3032 -- Display item
3033 UberInventory_UpdateButton( slot, UBI_Sorted[ index ] );
3034 end;
3035
3036 -- Update inventory count
3037 UberInventoryFrameInventoryCount:SetFormattedText( UBI_INVENTORY_COUNT, #UBI_Sorted, UBI_Inventory_count );
3038
3039 -- Disable the token button
3040 UberInventory_SetState( UberInventoryFrameTokensButton, false );
3041
3042 -- Show/Hide the moneyframe for displaying Guildbank or Alt cash
3043 if ( UBI_LocationList[UBI_FILTER_LOCATIONS].type == "current" ) then
3044 UberInventoryFrameMoneyOthersCash:SetText( UBI_EMPTY_TEXT );
3045 UberInventory_SetState( UberInventoryFrameTokensButton, true );
3046 else
3047 -- Initialize
3048 local otherCash = 0;
3049
3050 -- Determine the cash owned
3051 if ( UBI_LocationList[UBI_FILTER_LOCATIONS].type == "guildbank" ) then
3052 otherCash = UBI_Guildbank[UBI_LocationList[UBI_FILTER_LOCATIONS].value]["Cash"];
3053 elseif ( UBI_LocationList[UBI_FILTER_LOCATIONS].type == "character" ) then
3054 local character = strgsub( UBI_LocationList[UBI_FILTER_LOCATIONS].value, " .*", "" );
3055 otherCash = UBI_Data[UBI_REALM][character]["Money"]["Cash"] + UBI_Data[UBI_REALM][character]["Money"]["mail"];
3056 UberInventory_SetState( UberInventoryFrameTokensButton, true );
3057 elseif ( UBI_LocationList[UBI_FILTER_LOCATIONS].type == "all_character" ) then
3058 -- Traverse guildbanks
3059 otherCash = otherCash + UBI_Data[UBI_REALM][UBI_PLAYER]["Money"]["Cash"] + UBI_Data[UBI_REALM][UBI_PLAYER]["Money"]["mail"];
3060
3061 -- Traverse characters
3062 for key, value in pairs( UBI_Characters ) do
3063 otherCash = otherCash + UBI_Data[UBI_REALM][value]["Money"]["Cash"] + UBI_Data[UBI_REALM][value]["Money"]["mail"];
3064 end;
3065 elseif ( UBI_LocationList[UBI_FILTER_LOCATIONS].type == "all_guildbank" ) then
3066 -- Traverse guildbanks
3067 for key, value in pairs( UBI_Guildbanks ) do
3068 otherCash = otherCash + UBI_Guildbank[value]["Cash"];
3069 end;
3070 elseif ( UBI_LocationList[UBI_FILTER_LOCATIONS].type == "complete" ) then
3071 -- Traverse guildbanks
3072 otherCash = otherCash + UBI_Data[UBI_REALM][UBI_PLAYER]["Money"]["Cash"] + UBI_Data[UBI_REALM][UBI_PLAYER]["Money"]["mail"];
3073
3074 -- Traverse characters
3075 for key, value in pairs( UBI_Characters ) do
3076 otherCash = otherCash + UBI_Data[UBI_REALM][value]["Money"]["Cash"] + UBI_Data[UBI_REALM][value]["Money"]["mail"];
3077 end;
3078
3079 -- Traverse guildbanks
3080 for key, value in pairs( UBI_Guildbanks ) do
3081 otherCash = otherCash + UBI_Guildbank[value]["Cash"];
3082 end;
3083 end;
3084
3085 -- Update the cash info for Alt/Guildbank
3086 UberInventory_UpdateCashField( UberInventoryFrameMoneyOthersCash, otherCash );
3087 end;
3088 end;
3089
3090-- Display tokens
3091 function UberInventory_DisplayTokens()
3092 local tokenList = {};
3093 local line, index, button, currency, tokenData, toon;
3094 local offset = FauxScrollFrame_GetOffset( UberInventoryTokensScroll );
3095
3096 -- Determine token set to be displayed
3097 if ( UBI_LocationList[UBI_FILTER_LOCATIONS].type == "current" ) then
3098 tokenData = UBI_Data[UBI_REALM][UBI_PLAYER]["Money"]["Currencies"];
3099 toon = UBI_PLAYER;
3100 elseif ( UBI_LocationList[UBI_FILTER_LOCATIONS].type == "character" ) then
3101 local character = strgsub( UBI_LocationList[UBI_FILTER_LOCATIONS].value, " .*", "" );
3102 tokenData = UBI_Data[UBI_REALM][character]["Money"]["Currencies"];
3103 toon = UBI_LocationList[UBI_FILTER_LOCATIONS].value;
3104 else
3105 UberInventoryTokens:Hide();
3106 return;
3107 end;
3108
3109 -- Build new list containing headings, non-zero tokens and forced tokens
3110 for key, value in pairs( UBI_Currencies ) do
3111 if ( value.id < 0 or value.force ) then
3112 tinsert( tokenList, value );
3113 else
3114 if ( ( tokenData[value.id] or 0 ) > 0 ) then
3115 tinsert( tokenList, value );
3116 end;
3117 end;
3118 end;
3119 local length = #tokenList;
3120
3121 -- Update scrollbars
3122 FauxScrollFrame_Update( UberInventoryTokensScroll, length+1, UBI_NUM_TOKENBUTTONS, 17 );
3123
3124 -- Set title and show frame
3125 UberInventoryTokensHeading:SetText( UBI_TOKEN:format( toon ) );
3126 UberInventoryTokens:Show();
3127
3128 -- Redraw items
3129 for line = 1, UBI_NUM_TOKENBUTTONS, 1 do
3130 index = offset + line;
3131 button = _G[ "Token"..line ];
3132 if index <= length then
3133 if ( tokenList[index].id > 0 ) then
3134 _G[ "Token"..line.."Icon" ]:SetTexture( tokenList[index].icon );
3135 _G[ "Token"..line.."Icon" ]:Show();
3136 if ( ( tokenData[tokenList[index].id] or 0 ) > 0 ) then
3137 _G[ "Token"..line.."Name" ]:SetTextColor( 1.0, 1.0, 1.0 );
3138 _G[ "Token"..line.."Count" ]:SetTextColor( 1.0, 1.0, 1.0 );
3139 else
3140 _G[ "Token"..line.."Name" ]:SetTextColor( 0.7, 0.7, 0.7 );
3141 _G[ "Token"..line.."Count" ]:SetTextColor( 0.7, 0.7, 0.7 );
3142 end;
3143 _G[ "Token"..line.."Name" ]:SetText( " "..( tokenList[index].name or "??" ) );
3144 _G[ "Token"..line.."Count" ]:SetText( tokenData[tokenList[index].id] or 0 );
3145 _G[ "Token"..line.."Count" ]:Show();
3146 else
3147 _G[ "Token"..line.."Icon" ]:Hide();
3148 _G[ "Token"..line.."Name" ]:SetTextColor( 1.0, 0.82, 0.0 );
3149 _G[ "Token"..line.."Name" ]:SetText( tokenList[index].name );
3150 _G[ "Token"..line.."Count" ]:Hide();
3151 end;
3152 button:Show();
3153 else
3154 button:Hide();
3155 end;
3156 end;
3157
3158 end;
3159
3160-- Update wallet/mail cash info on screen
3161 function UberInventory_WalletMailCashInfo()
3162 if( UberInventoryFrame:IsVisible() ) then
3163 -- Update cash balance information
3164 UberInventory_UpdateCashField( UberInventoryFrameMoneyWalletCash, GetMoney() );
3165 UberInventory_UpdateCashField( UberInventoryFrameMoneyMailCash, UBI_Money["mail"] );
3166 end;
3167 end;
3168
3169-- Show or hide the Main dialog
3170 function UberInventory_Toggle_Main()
3171 if( UberInventoryFrame:IsVisible() ) then
3172 UberInventoryFrame:Hide();
3173 else
3174 -- Show the frame
3175 UberInventoryFrame:Show();
3176 UberInventoryFrame:SetBackdropColor( 0, 0, 0, 1 );
3177
3178 -- Update wallet/mail cash information
3179 UberInventory_WalletMailCashInfo();
3180
3181 -- Force refresh
3182 UberInventory_DisplayItems();
3183
3184 -- Update slot count information
3185 UberInventory_Update_SlotCount();
3186 end;
3187 end;
3188
3189-- Show or hide the Main dialog
3190 function UberInventory_Toggle_Tokens()
3191 if( UberInventoryTokens:IsVisible() ) then
3192 UberInventoryTokens:Hide();
3193 else
3194 -- Show the frame
3195 UberInventoryTokens:Show();
3196 UberInventoryTokens:SetBackdropColor( 0, 0, 0, 1 );
3197 end;
3198 end;
3199
3200-- Show/Hide tooltip info
3201 function UberInventory_Toggle_Tooltip()
3202 UBI_Options["show_tooltip"] = not UBI_Options["show_tooltip"];
3203 end;
3204
3205-- Set/Remove hightlight for container/item
3206 function UberInventory_Highlighter( item, state )
3207 -- Set hightlight from container/item
3208 function HighlightOn( frame )
3209 SetItemButtonTextureVertexColor( frame, .6, .6, .6, 1 );
3210 frame:GetNormalTexture():SetVertexColor( .6, .6, .6, 1 );
3211 frame:LockHighlight();
3212 tinsert( UBI_Highlights, frame );
3213 end;
3214
3215 -- Remove hightlight from container/item
3216 function HighlightOff( frame )
3217 SetItemButtonTextureVertexColor( frame, 1, 1, 1 );
3218 frame:GetNormalTexture():SetVertexColor( 1, 1, 1 );
3219 frame:UnlockHighlight();
3220 end;
3221
3222 -- Exit if highlighting has been turned off
3223 if ( not UBI_Options["show_highlight"] ) then
3224 return;
3225 end;
3226
3227 -- Set or remove highlights
3228 if ( state == "off" ) then
3229 -- Remove all previous highlights
3230 for id, frame in pairs( UBI_Highlights ) do
3231 HighlightOff( frame );
3232 end;
3233 wipe( UBI_Highlights );
3234 else
3235 -- Initialize
3236 local bagid, slotid, itemid, itemlink, index, container, _;
3237
3238 -- Travese all containers and slots (bag, bank) to locate items
3239 for bagid = -2, 11, 1 do
3240 index = IsBagOpen( bagid );
3241 for slotid = 1, GetContainerNumSlots( bagid ) do
3242 itemlink = GetContainerItemLink( bagid, slotid );
3243 if ( itemlink ) then
3244 _, itemid = strsplit( ":", itemlink );
3245 if ( tonumber(itemid) == item and UI_CONTAINER_OBJECTS[bagid]:IsShown() ) then
3246 -- Highlight container
3247 if ( bagid ~= -1 ) then
3248 HighlightOn( UI_CONTAINER_OBJECTS[bagid] );
3249 end;
3250
3251 -- Highlight item
3252 if ( index or bagid == BANK_CONTAINER ) then
3253 if ( bagid == -1 ) then
3254 container = "BankFrameItem"..slotid;
3255 else
3256 slotid = GetContainerNumSlots( bagid ) - slotid + 1;
3257 container = "ContainerFrame"..index.."Item"..slotid;
3258 end;
3259 HighlightOn( _G[ container ] );
3260 end;
3261 end;
3262 end;
3263 end;
3264 end;
3265
3266 -- Travese all gb slots to locate item
3267 if ( UBI_GUILDBANK_OPENED ) then
3268 local gbTab, gbSlot;
3269 for gbTab = 1, GetNumGuildBankTabs() do
3270 for gbSlot = 1, MAX_GUILDBANK_SLOTS_PER_TAB do
3271 itemlink = GetGuildBankItemLink( gbTab, gbSlot );
3272 if ( itemlink ) then
3273 _, itemid = strsplit( ":", itemlink );
3274 if ( tonumber(itemid) == item ) then
3275 -- Highlight tab
3276 container = "GuildBankTab"..gbTab.."Button";
3277 HighlightOn( _G[ container ] );
3278
3279 -- Highlight item
3280 if ( GetCurrentGuildBankTab() == gbTab ) then
3281 index = mod( gbSlot, NUM_SLOTS_PER_GUILDBANK_GROUP );
3282 if ( index == 0 ) then
3283 index = NUM_SLOTS_PER_GUILDBANK_GROUP;
3284 end
3285 column = ceil( ( gbSlot - 0.5 ) / NUM_SLOTS_PER_GUILDBANK_GROUP );
3286 container = "GuildBankColumn"..column.."Button"..index;
3287 HighlightOn( _G[ container ] );
3288 end;
3289 end;
3290 end;
3291 end;
3292 end;
3293 end;
3294 end;
3295 end;
3296
3297-- Perform item search
3298 function UberInventory_Search( str )
3299 -- From global to local
3300 local itemText, msg, count = "", "", 0;
3301 local icon;
3302
3303 -- Display search criteria
3304 UberInventory_Message( UBI_ITEM_SEARCH:format( str ), true );
3305
3306 -- Search and display items found
3307 local itemCounts = { 0, 0, 0, 0, 0 };
3308 for key, value in pairs( UBI_Items ) do
3309 if ( ( strfind( strlower( value.name ) , strlower( str ) ) or 0 ) > 0 ) then
3310 -- Get item count
3311 itemCounts = { value.total,
3312 value.bag_count or 0,
3313 value.bank_count or 0,
3314 value.mailbox_count or 0,
3315 value.equip_count or 0,
3316 value.void_count or 0,
3317 value.reagent_count or 0, };
3318
3319 -- Set item image
3320 if ( value.type == UBI_BATTLEPET_CLASS and value.itemid ~= 82800 ) then
3321 _, icon = C_PetJournal.GetPetInfoBySpeciesID( value.itemid );
3322 else
3323 icon = GetItemIcon( value.itemid );
3324 end;
3325
3326 -- Build search result
3327 itemText = "|T"..icon..":0|t "..UberInventory_GetLink( value.itemid, value );
3328 msg = " "..itemText.." "..UBI_ITEM_COUNT_SINGLE:format( itemCounts[1] ).." (";
3329 for loc = 2, #itemCounts do
3330 if ( itemCounts[loc] > 0 ) then
3331 msg = msg.."|T"..UBI_LOCATION_TEXTURE[loc-1]..":0|t "..UBI_LOCATIONS[loc-1].." = "..itemCounts[loc].." / ";
3332 end;
3333 end;
3334
3335 -- Display result
3336 count = count + 1;
3337 UberInventory_Message( msg:sub( 1, msg:len()-3 )..")", true );
3338 end;
3339 end;
3340
3341 -- Display end of search
3342 if ( count == 0 ) then
3343 UberInventory_Message( UBI_ITEM_SEARCH_NONE, true );
3344 else
3345 UberInventory_Message( UBI_ITEM_SEARCH_DONE, true );
3346 end;
3347 end;
3348
3349-- Remove character or guildbank data
3350 function UberInventory_RemoveData( data )
3351 -- split of command and name (guildbank names can contain spaces, unlike character names)
3352 local command, _ = strsplit( " ", data ):lower();
3353 local name = data:sub( command:len()+2 );
3354
3355 -- Remove the data
3356 if ( command == "remchar" and name ~= "Guildbank" ) then
3357 -- Do not remove data for the current connected character
3358 if ( name == UBI_PLAYER ) then
3359 UberInventory_Message( UBI_REM_NOTALLOWED, true );
3360 return;
3361 end;
3362
3363 -- Check if character has data stored and delete it if so
3364 if ( UBI_Data[UBI_REALM][name] ) then
3365 StaticPopupDialogs["UBI_CONFIRM_DELETE"].OnAccept = function()
3366 -- Remove data
3367 UBI_Data[UBI_REALM][name] = nil;
3368
3369 -- Display message
3370 UberInventory_Message( UBI_REM_DONE:format( name ), true );
3371
3372 -- Rebuild list of alts
3373 UberInventory_GetAlts();
3374
3375 -- Reset filters
3376 UberInventory_ResetFilters();
3377 end;
3378
3379 -- Ask for remove confirmation
3380 StaticPopup_Show( "UBI_CONFIRM_DELETE", UBI_REM_CHARACTER:format( name ) );
3381 else
3382 UberInventory_Message( UBI_REM_CHARNOTFOUND:format( name ), true );
3383 end;
3384 elseif ( command == "remguild" ) then
3385 -- Check if guildbank has data stored and delete it if so
3386 if ( UBI_Guildbank[name] ) then
3387 StaticPopupDialogs["UBI_CONFIRM_DELETE"].OnAccept = function()
3388 -- Remove data
3389 UBI_Guildbank[name] = nil;
3390
3391 -- Display message
3392 UberInventory_Message( UBI_REM_DONE:format( name ), true );
3393
3394 -- When current guild is removed reinitialize data structure
3395 if ( UBI_GUILD == name ) then
3396 UberInventory_Guildbank_Init();
3397 end;
3398
3399 -- Rebuild list of guildbanks
3400 UberInventory_GetGuildbanks();
3401
3402 -- Reset filters
3403 UberInventory_ResetFilters();
3404 end;
3405
3406 -- Ask for remove confirmation
3407 StaticPopup_Show( "UBI_CONFIRM_DELETE", UBI_REM_GUILDBANK:format( name ) );
3408 else
3409 UberInventory_Message( UBI_REM_GUILDNOTFOUND:format( name ), true );
3410 end;
3411 end;
3412
3413 -- Rebuild location list
3414 UberInventory_Build_Locations();
3415 end;
3416
3417-- Show help message
3418 function UberInventory_ShowHelp()
3419 for key, value in pairs( UBI_HELP ) do
3420 UberInventory_Message( value, true );
3421 end;
3422 end;
3423
3424-- Handle slash commands
3425 function UberInventory_SlashHandler( msg, editbox )
3426 -- arguments should be handled case-insensitve
3427 local orgData = msg;
3428 msg = strlower( msg );
3429
3430 -- Handle each individual argument
3431 if ( msg == "" ) then
3432 -- Show main dialog
3433 UberInventory_Toggle_Main();
3434 elseif ( msg:find( "remchar" ) or msg:find( "remguild" ) ) then
3435 -- Remove character or guild data
3436 UberInventory_RemoveData( orgData );
3437 elseif ( msg == "help" ) or ( msg == "?" ) then
3438 -- Show help info
3439 UberInventory_ShowHelp();
3440 elseif ( msg == "resetpos" ) then
3441 UberInventoryFrame:ClearAllPoints();
3442 UberInventoryFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 0);
3443 elseif ( msg == "sendgb" ) then
3444 if ( UBI_GUILDBANK_OPENED and UBI_GUILDBANK_VIEWACCESS ) then
3445 UberInventory_Send_Guildbank();
3446 else
3447 if ( not UBI_GUILDBANK_OPENED ) then
3448 UberInventory_Message( UBI_SENDGB_VISIT, true );
3449 end;
3450 if ( not UBI_GUILDBANK_VIEWACCESS ) then
3451 UberInventory_Message( UBI_SENDGB_ACCESS, true );
3452 end;
3453 end;
3454 elseif ( msg == "requestgb" ) then
3455 UBI_GUILDBANK_FORCED = true;
3456 TaskHandlerLib:AddTask( "UberInventory", UBI_Task_SendMessage, "GBREQUEST" );
3457 UberInventory_Message( UBI_GB_REQUESTED, true );
3458 else
3459 -- Perform item search
3460 UberInventory_Search( msg or "" );
3461 end;
3462 end;