-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPossessions.lua
More file actions
1932 lines (1667 loc) · 59.7 KB
/
Copy pathPossessions.lua
File metadata and controls
1932 lines (1667 loc) · 59.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
Possessions: AddOn to keep track of all of your items.
License:
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program (see GLP.txt); if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
]]
local _G = getfenv(0)
local tonumber = _G.tonumber
local pairs = _G.pairs
local GetItemInfo = _G.GetItemInfo
local GetInventoryItemLink = _G.GetInventoryItemLink
local string = _G.string
local DEFAULT_CHAT_FRAME = _G.DEFAULT_CHAT_FRAME
local POSSESSIONS_VERSION = GetAddOnMetadata("Possessions","Version"):match("%d+\.%d*\.%d*")
local CHARACTER_NUM_ITEMS = 19
local POSSESSIONS_ITEMS_TOSHOW = 15
local POSSESSIONS_ITEMS_HEIGHT = 16
local Possessions_INVENTORY_SLOT_LIST = {
{ name = "HeadSlot" },
{ name = "NeckSlot" },
{ name = "ShoulderSlot" },
{ name = "BackSlot" },
{ name = "ChestSlot" },
{ name = "ShirtSlot" },
{ name = "TabardSlot" },
{ name = "WristSlot" },
{ name = "HandsSlot" },
{ name = "WaistSlot" },
{ name = "LegsSlot" },
{ name = "FeetSlot" },
{ name = "Finger0Slot" },
{ name = "Finger1Slot" },
{ name = "Trinket0Slot" },
{ name = "Trinket1Slot" },
{ name = "MainHandSlot" },
{ name = "SecondaryHandSlot" },
{ name = "RangedSlot" },
}
local realmName, playerName, playerFaction, playerGuild
local searchString
local searchChar
local searchLoc
local searchSlot
local searchType
local searchSubType
local characterTable = { }
local DisplayIndices = { }
local TempTable = { }
local PlayerItemTable
local info = {}
local lastScan = 0
local GuildBankUpdateCount = 0
local INDEX_LINK = 0
local INDEX_NAME = 1
local INDEX_ICON = 2
local INDEX_QUANTITY = 3
local INDEX_RARITY = 4
local INDEX_LOCS = 5
local POSS_INVENTORY_CONTAINER = 0
local POSS_BANK_CONTAINER = -1
local POSS_PLAYER_CONTAINER = -2
local POSS_MAIL_CONTAINER = -3
local POSS_KEYRING_CONTAINER = -4
local POSS_PLAYERBAG_CONTAINER = -5
local POSS_BANKBAG_CONTAINER = -6
local POSS_GUILDBANK_CONTAINER = -7
local sendMailItems = {}
local sendMailItemQuantities = {}
local sendMailMoney = 0
local sendMailRecipient = ""
local possessionsLocationNames = {
{container = POSS_BANK_CONTAINER, name = PossessionsLocale.TEXT_BANK},
{container = POSS_MAIL_CONTAINER, name = PossessionsLocale.TEXT_INBOX},
{container = POSS_INVENTORY_CONTAINER, name = PossessionsLocale.TEXT_INVENTORY},
{container = POSS_KEYRING_CONTAINER, name = PossessionsLocale.TEXT_KEYRING},
{container = POSS_PLAYER_CONTAINER, name = PossessionsLocale.TEXT_PLAYER},
{container = POSS_PLAYERBAG_CONTAINER, name = PossessionsLocale.TEXT_PLAYERBAGS},
{container = POSS_BANKBAG_CONTAINER, name = PossessionsLocale.TEXT_BANKBAGS},
{container = POSS_GUILDBANK_CONTAINER, name = PossessionsLocale.TEXT_GUILDBANK}
};
local possessionsSlotNames = {
{slot = INVTYPE_AMMO, name = "INVTYPE_AMMO"}, --Ammo
{slot = INVTYPE_CLOAK, name = "INVTYPE_CLOAK"}, --Back
{slot = INVTYPE_BAG, name = "INVTYPE_BAG"}, --Bag
{slot = INVTYPE_RANGED, name = "INVTYPE_RANGED"}, --Bow
{slot = INVTYPE_CHEST, name = "INVTYPE_CHEST"}, --Chest
{slot = INVTYPE_FEET, name = "INVTYPE_FEET"}, --Feet
{slot = INVTYPE_FINGER, name = "INVTYPE_FINGER"}, --Finger
{slot = INVTYPE_HAND, name = "INVTYPE_HAND"}, --Hands
{slot = INVTYPE_HEAD, name = "INVTYPE_HEAD"}, --Head
{slot = INVTYPE_HOLDABLE, name = "INVTYPE_HOLDABLE"}, --Held in Off-hand
{slot = INVTYPE_LEGS, name = "INVTYPE_LEGS"}, --Legs
{slot = INVTYPE_WEAPONMAINHAND, name = "INVTYPE_WEAPONMAINHAND"}, --Main Hand
{slot = INVTYPE_NECK, name = "INVTYPE_NECK"}, --Neck
{slot = INVTYPE_WEAPONOFFHAND, name = "INVTYPE_WEAPONOFFHAND"}, --Off Hand
{slot = INVTYPE_WEAPON, name = "INVTYPE_WEAPON"}, --One-Hand
{slot = INVTYPE_RELIC, name = "INVTYPE_RELIC"}, --Relic
{slot = INVTYPE_ROBE, name = "INVTYPE_ROBE"}, --Robe
{slot = INVTYPE_SHIELD, name = "INVTYPE_SHIELD"}, --Shield
{slot = INVTYPE_SHOULDER, name = "INVTYPE_SHOULDER"}, --Shoulder
{slot = INVTYPE_BODY, name = "INVTYPE_BODY"}, --Shirt
{slot = INVTYPE_TABARD, name = "INVTYPE_TABARD"}, --Tabard
{slot = INVTYPE_THROWN, name = "INVTYPE_THROWN"}, --Thrown
{slot = INVTYPE_TRINKET, name = "INVTYPE_TRINKET"}, --Trinket
{slot = INVTYPE_2HWEAPON, name = "INVTYPE_2HWEAPON"}, --Two-Hand
{slot = INVTYPE_WAIST, name = "INVTYPE_WAIST"}, --Waist
{slot = INVTYPE_RANGEDRIGHT, name = "INVTYPE_RANGEDRIGHT"}, --Wand/Gun/Crossbow
{slot = INVTYPE_WRIST, name = "INVTYPE_WRIST"} --Wrist
};
local possessionsTypes = {}
local possessionsSubTypes = PossessionsLocale.TYPE_TABLE
function Possessions_SlotDropDown_OnClick(self)
local id = self:GetID()
UIDropDownMenu_SetSelectedID(Possessions_SlotDropDown, id)
if( id > 1) then
searchSlot = possessionsSlotNames[id-1].name
else
searchSlot = nil
end
Possessions_Update()
end
function Possessions_SlotDropDown_Initialize(self)
info.text = PossessionsLocale.TEXT_ALLSLOTS
info.func = Possessions_SlotDropDown_OnClick
info.checked = nil
UIDropDownMenu_AddButton(info)
for i,slotname in pairs(possessionsSlotNames) do
if slotname.name == "INVTYPE_SHIELD" then
info.text = SHIELDSLOT
elseif slotname.name == "INVTYPE_RANGED" then
info.text = "Bow"
elseif slotname.name == "INVTYPE_RANGEDRIGHT" then
info.text = "Wand/Gun/Crossbow"
elseif slotname.name == "INVTYPE_ROBE" then
info.text = "Robe"
else
info.text = slotname.slot
end
info.func = Possessions_SlotDropDown_OnClick
info.checked = nil
UIDropDownMenu_AddButton(info)
end
end
function Possessions_SlotDropDown_OnShow(self)
UIDropDownMenu_Initialize(self, Possessions_SlotDropDown_Initialize)
UIDropDownMenu_SetSelectedID(self, 1)
UIDropDownMenu_SetWidth(self, 90, 0)
end
function Possessions_LocDropDown_OnClick(self)
local id = self:GetID();
UIDropDownMenu_SetSelectedID(Possessions_LocDropDown, id);
if( id > 1) then
searchLoc = possessionsLocationNames[id-1].container;
else
searchLoc = nil;
end
Possessions_Update();
end
function Possessions_LocDropDown_Initialize(self)
info.text = PossessionsLocale.TEXT_ALLLOCS;
info.func = Possessions_LocDropDown_OnClick;
info.checked = nil
UIDropDownMenu_AddButton(info);
for i,location in pairs(possessionsLocationNames) do
info.text = location.name;
info.func = Possessions_LocDropDown_OnClick;
info.checked = nil
UIDropDownMenu_AddButton(info);
end
end
function Possessions_LocDropDown_OnShow(self)
UIDropDownMenu_Initialize(self, Possessions_LocDropDown_Initialize);
UIDropDownMenu_SetSelectedID(self, 1);
UIDropDownMenu_SetWidth(self, 90, 0);
end
function Possessions_CharDropDown_OnClick(self)
local id = self:GetID();
UIDropDownMenu_SetSelectedID(Possessions_CharDropDown, id);
if( id > 1) then
searchChar = characterTable[id-1];
else
searchChar = nil;
end
Possessions_Update();
end
function Possessions_CharDropDown_Initialize(self)
info.text = PossessionsLocale.TEXT_ALLCHARS
info.func = Possessions_CharDropDown_OnClick
info.checked = nil
UIDropDownMenu_AddButton(info);
for i = 1, #characterTable do
info.text = characterTable[i]
info.func = Possessions_CharDropDown_OnClick
info.checked = nil
UIDropDownMenu_AddButton(info)
end
end
function Possessions_CharDropDown_OnShow(self)
UIDropDownMenu_Initialize(self, Possessions_CharDropDown_Initialize);
UIDropDownMenu_SetSelectedID(self, 1);
UIDropDownMenu_SetWidth(self, 90, 0);
end
function Possessions_TypeDropDown_OnClick(self)
local id = self:GetID();
UIDropDownMenu_SetSelectedID(Possessions_TypeDropDown, id);
if( id > 1) then
searchType = possessionsTypes[id-1];
else
searchType = nil;
end
Possessions_Update();
end
function Possessions_TypeDropDown_Initialize(self)
info.text = PossessionsLocale.TEXT_ALLTYPES;
info.func = Possessions_TypeDropDown_OnClick;
info.checked = nil
UIDropDownMenu_AddButton(info);
for i = 1, #possessionsTypes, 1 do
info.text = possessionsTypes[i];
info.func = Possessions_TypeDropDown_OnClick;
info.checked = nil
UIDropDownMenu_AddButton(info);
end
end
function Possessions_TypeDropDown_OnShow(self)
UIDropDownMenu_Initialize(self, Possessions_TypeDropDown_Initialize);
UIDropDownMenu_SetSelectedID(self, 1);
UIDropDownMenu_SetWidth(self, 207, 0);
end
function Possessions_SubTypeDropDown_OnClick(self)
searchType = self.value["Level1_Key"];
searchSubType = self.value["Sublevel_Key"];
if (searchType and searchSubType) then
Possessions_SubTypeDropDownText:SetText(self.value["Level1_Key"].." - "..self.value["Sublevel_Key"]);
else
Possessions_SubTypeDropDownText:SetText(self.value["Level1_Key"] or PossessionsLocale.TEXT_ALLTYPES);
end
DropDownList1:Hide();
Possessions_Update();
end
function Possessions_SubTypeDropDown_Initialize(self, level)
level = level or 1;
if (level == 1) then
local subInfo = UIDropDownMenu_CreateInfo();
subInfo.notCheckable = true;
subInfo.text = PossessionsLocale.TEXT_ALLTYPES;
subInfo.func = Possessions_SubTypeDropDown_OnClick;
UIDropDownMenu_AddButton(subInfo, level);
for key, subarray in pairs(possessionsSubTypes) do
local subInfo = UIDropDownMenu_CreateInfo();
if #subarray > 1 then
subInfo.hasArrow = true;
end
subInfo.notCheckable = true;
subInfo.text = key;
subInfo.func = Possessions_SubTypeDropDown_OnClick;
subInfo.value = {
["Level1_Key"] = key;
};
UIDropDownMenu_AddButton(subInfo, level);
end
end
if (level == 2) then
local Level1_Key = UIDROPDOWNMENU_MENU_VALUE["Level1_Key"];
local subarray = possessionsSubTypes[Level1_Key];
for key, value in ipairs(subarray) do
local subInfo = UIDropDownMenu_CreateInfo();
subInfo.hasArrow = false; -- no submenus this time
subInfo.notCheckable = true;
subInfo.text = value;
subInfo.func = Possessions_SubTypeDropDown_OnClick;
subInfo.value = {
["Level1_Key"] = Level1_Key;
["Sublevel_Key"] = value;
};
UIDropDownMenu_AddButton(subInfo, level);
end
end
end
function Possessions_SubTypeDropDown_OnShow(self)
UIDropDownMenu_Initialize(self, Possessions_SubTypeDropDown_Initialize);
UIDropDownMenu_SetWidth(self, 207, 0);
end
function Possessions_FixLink(link)
if( not link ) then
return nil
end
if string.match(link, "item:") then
return link
end
local ncolon = select(2,string.gsub(link, ":", ""))
if( ncolon == 3 ) then
return "item:" .. string.gsub(link, "(%-?%d+):(.*):(.*):(%-?%d+)", "%1:%2:0:0:0:0:%3:%4")
elseif( ncolon < 7 ) then --Link is too short
return "item:" .. link .. string.rep(":0",7-ncolon)
elseif( ncolon > 7 ) then --Link is too long for some reason
return "item:" .. string.match(link, "^(%-?%d+:.*:.*:.*:.*:.*:.*:%-?%d+)")
else
return "item:" .. link
end
end
function Possessions_BuildLink(item)
return select(4, GetItemQualityColor(item[INDEX_RARITY])) .."|Hitem:".. Possessions_FixLink(item[INDEX_LINK]) .. "|h["..item[INDEX_NAME].."]|h|r";
end
function Possessions_CompressLink(link)
if not link then return end
local itemLink
local _, _, itemID, ench, j1, j2, j3, j4, suffixID, uniqueID = string.find(link, "(%-?%d+):(%-?%d+):(%-?%d+):(%-?%d+):(%-?%d+):(%-?%d+):(%-?%d+):(%-?%d+)")
j1 = tonumber(j1)
j2 = tonumber(j2)
j3 = tonumber(j3)
j4 = tonumber(j4)
suffixID = tonumber(suffixID)
if (suffixID < 0) then
uniqueID = bit.band( tonumber(uniqueID), 65535)
end
if(j1 == 0 and j2 == 0 and j3 == 0 and j4 == 0) then --If there are no occupied Jewel slots
if(tonumber(ench) == 0 and suffixID == 0) then --If there is no enchant nor suffix
itemLink = itemID --Store itemID only to save memory
elseif(suffixID < 0) then --If the suffixID is negative, store the full uniqueID
itemLink = itemID..":"..ench..":"..suffixID..":"..uniqueID --Store short format
else
itemLink = itemID..":"..ench..":"..suffixID..":0" --Use the pre 2.0.1 style itemString to save memory
end
elseif(suffixID < 0) then --Some jewel slots are occupied and the suffixid is negative
itemLink = itemID..":"..ench..":"..j1..":"..j2..":"..j3..":"..j4..":"..suffixID..":"..uniqueID --Full link with uniqueID needed
else
itemLink = itemID..":"..ench..":"..j1..":"..j2..":"..j3..":"..j4..":"..suffixID --Full link needed
end
return itemLink
end
function Possessions_StoreLink(bagnum, containerItemNum, link)
if(link) then
local name, _, rarity = GetItemInfo(link)
if name then
if not PlayerItemTable[bagnum] then
PlayerItemTable[bagnum] = { }
PlayerItemTable[bagnum][containerItemNum] = {}
elseif not PlayerItemTable[bagnum][containerItemNum] then
PlayerItemTable[bagnum][containerItemNum] = {}
end
--Only assign values if they have changed. May or may not help performance
local compressedLink = Possessions_CompressLink(link)
if PlayerItemTable[bagnum][containerItemNum][INDEX_LINK] ~= compressedLink then
PlayerItemTable[bagnum][containerItemNum][INDEX_LINK] = compressedLink
PlayerItemTable[bagnum][containerItemNum][INDEX_NAME] = name
PlayerItemTable[bagnum][containerItemNum][INDEX_RARITY] = rarity
end
return true
end
end
return false
end
function Possessions_ReloadBag(bagnum)
local link
local maxContainerItems = GetContainerNumSlots(bagnum)
local bagLink = nil
local bagSlotContainer = nil
local storebagnum = bagnum
--Done in this manner to preserve backwards compatibility with SavedVariables from Oystein's versions
if ( bagnum == KEYRING_CONTAINER ) then
storebagnum = POSS_KEYRING_CONTAINER
elseif ( bagnum > 0 and bagnum <= NUM_BAG_SLOTS ) then
--This is an inventory bag, store its info
bagLink = GetInventoryItemLink("player",ContainerIDToInventoryID(bagnum))
bagSlotContainer = POSS_PLAYERBAG_CONTAINER
elseif ( bagnum > NUM_BAG_SLOTS ) then
--This is a bank bag, store its info
bagLink = GetInventoryItemLink("player",ContainerIDToInventoryID(bagnum))
bagSlotContainer = POSS_BANKBAG_CONTAINER
end
--Try to store the bag itself
if( Possessions_StoreLink(bagSlotContainer, bagnum, bagLink) ) then
PlayerItemTable[bagSlotContainer][bagnum][INDEX_QUANTITY] = 1
if( Possessions_IsLiteMode() == false ) then
PlayerItemTable[bagSlotContainer][bagnum][INDEX_ICON] = select(10, GetItemInfo(bagLink))
end
end
if ( maxContainerItems > 0) then
if not PlayerItemTable[storebagnum] then
PlayerItemTable[storebagnum] = { }
end
local storeBag = PlayerItemTable[storebagnum]
local storeContainerItemNum
for containerItemNum = 1, maxContainerItems do
storeContainerItemNum = containerItemNum
link = GetContainerItemLink(bagnum, containerItemNum)
if( link ) then
local compressedLink = Possessions_CompressLink(link)
--Try to find an existing stack of this item type in the same bag to use
if( Possessions_IsLiteMode() == true ) then --Only search for existing stack if Lite Mode is enabled
--Look through previous bag contents
for prevContItemNum=1, containerItemNum-1 do
if storeBag[prevContItemNum] then
if storeBag[prevContItemNum][INDEX_LINK] == compressedLink then -- and storeBag[prevContItemNum][INDEX_QUANTITY] > 0 then --Don't want quantity to be 0 since we might put stuff into a slot that will soon be overwritten by new contents
storeContainerItemNum = prevContItemNum
break
end
end
end
end
if storeContainerItemNum ~= containerItemNum then
storeBag[storeContainerItemNum][INDEX_QUANTITY] = storeBag[storeContainerItemNum][INDEX_QUANTITY] + select(2,GetContainerItemInfo(bagnum, containerItemNum))
if storeBag[containerItemNum] then
storeBag[containerItemNum] = nil
end
else --Did not find existing stack within same bag
--Store the new link normally
if( Possessions_StoreLink(storebagnum, containerItemNum, link) ) then
storeBag[containerItemNum][INDEX_ICON], storeBag[containerItemNum][INDEX_QUANTITY] = GetContainerItemInfo(bagnum, containerItemNum) --select(2,GetContainerItemInfo(bagnum, containerItemNum))
if( Possessions_IsLiteMode() == true ) then
storeBag[containerItemNum][INDEX_ICON] = nil
end
end
end
else
if storeBag[containerItemNum] and storeBag[containerItemNum][INDEX_QUANTITY] > 0 then
storeBag[containerItemNum] = nil
end
end
end
end
end
function Possessions_Hide()
HideUIPanel(Possessions_Frame)
end
function Possessions_Show()
Possessions_ClearDropDowns()
Possessions_Update()
ShowUIPanel(Possessions_Frame)
Possessions_SearchBox:SetFocus();
end
function Possessions_Toggle()
if( Possessions_Frame:IsVisible() ) then
Possessions_Hide()
else
Possessions_Show()
end
end
function Possessions_SlashCommandHandler(msg)
if (msg == "") then
Possessions_Toggle()
return
end
local command, argument = msg:match("^(%S+)%s*(.-)$")
command = (command or ""):lower()
argument = (argument or "")
if(command == "-clear") then
if( not PossessionsData[realmName][argument] ) then
argument = argument:lower()
end
if( PossessionsData[realmName][argument] ) then
if(argument == playerName) then
DEFAULT_CHAT_FRAME:AddMessage("[Possessions]: Cannot clear data for the current character.")
else
PossessionsData[realmName][argument] = nil
characterTable = { }
for index, value in pairs(PossessionsData[realmName]) do
table.insert(characterTable, Possessions_Capitalize(index))
end
table.sort(characterTable)
DEFAULT_CHAT_FRAME:AddMessage("[Possessions]: Data for '"..argument.."' cleared.")
end
else
DEFAULT_CHAT_FRAME:AddMessage("[Possessions]: No data stored for '"..Possessions_Capitalize(argument).."'.")
end
elseif command == "-validate" and argument == "all" then
--/poss -validate all
local link
local numValidated = 0
for character, charTable in pairs(PossessionsData[realmName]) do
for index, value in pairs(charTable.items) do
for index2, value2 in pairs(value) do
if value2[INDEX_LINK] then
link = Possessions_FixLink( value2[INDEX_LINK] )
if not GetItemInfo(link) then
PossScanningTooltip:ClearLines()
PossScanningTooltip:SetHyperlink(link)
numValidated = numValidated + 1
end
end
end
end
end
DEFAULT_CHAT_FRAME:AddMessage("[Possessions]: Validated "..numValidated.." items.")
elseif command == "-globaltooltip" then
if argument == "on" or argument == "enable" then
PossessionsData.config.globalTooltip = true
DEFAULT_CHAT_FRAME:AddMessage("[Possessions]: -globaltooltip on")
elseif argument == "off" or argument == "disable" then
PossessionsData.config.globalTooltip = false
DEFAULT_CHAT_FRAME:AddMessage("[Possessions]: -globaltooltip off")
else
DEFAULT_CHAT_FRAME:AddMessage(
format("[Possessions]: -globaltooltip %s",
PossessionsData.config.globalTooltip and "on" or "off")
)
end
elseif command == "-forcetooltip" then
if argument == "on" or argument == "enable" then
PossessionsData.config.forcedGlobalTooltip = true
DEFAULT_CHAT_FRAME:AddMessage("[Possessions]: -forcetooltip on")
elseif argument == "off" or argument == "disable" then
PossessionsData.config.forcedGlobalTooltip = false
DEFAULT_CHAT_FRAME:AddMessage("[Possessions]: -forcetooltip off")
else
DEFAULT_CHAT_FRAME:AddMessage(
format("[Possessions]: -forcetooltip %s",
PossessionsData.config.forcedGlobalTooltip and "on" or "off")
)
end
else
local itemName = GetItemInfo(msg)
Possessions_SearchBox:SetText(itemName or msg or "")
Possessions_Show()
end
end
function Possessions_ClearDropDowns()
searchChar = nil;
searchLoc = nil;
searchSlot = nil;
searchType = nil;
searchSubType = nil;
UIDropDownMenu_SetSelectedID(Possessions_CharDropDown, 0);
UIDropDownMenu_SetSelectedID(Possessions_LocDropDown, 0);
UIDropDownMenu_SetSelectedID(Possessions_SlotDropDown, 0);
UIDropDownMenu_SetSelectedID(Possessions_SubTypeDropDown, 0);
Possessions_CharDropDownText:SetText(PossessionsLocale.TEXT_ALLCHARS);
Possessions_LocDropDownText:SetText(PossessionsLocale.TEXT_ALLLOCS);
Possessions_SlotDropDownText:SetText(PossessionsLocale.TEXT_ALLSLOTS);
Possessions_SubTypeDropDownText:SetText(PossessionsLocale.TEXT_ALLTYPES);
end
function Possessions_ResetButton_OnClick(self)
Possessions_ClearDropDowns()
Possessions_SearchBox:SetText("")
Possessions_Update()
end
function Possessions_Update()
FauxScrollFrame_SetOffset(Possessions_IC_ScrollFrame, 0);
_G.Possessions_IC_ScrollFrameScrollBar:SetValue(0);
local msg = Possessions_SearchBox:GetText();
if( msg and msg ~= "" ) then
searchString = string.lower(msg);
else
searchString = nil;
end
Possessions_BuildDisplayIndices();
Possessions_UpdateView();
end
function Possessions_BuildDisplayIndices()
local link
local location
local slot = nil
local subtype = nil
local itemType = nil
local theLink = nil
local textResult
for link, value in pairs(TempTable) do
if value[INDEX_QUANTITY] > 0 then
TempTable[link][INDEX_QUANTITY] = 0
for charName, locations in pairs(value[INDEX_LOCS]) do
for location, quant in pairs(locations) do
if quant > 0 then
TempTable[link][INDEX_LOCS][charName][location] = 0
end
end
end
end
end
for index, value in pairs(PossessionsData[realmName]) do
if (not value.faction or value.faction == playerFaction) then
for index2, value2 in pairs(value.items) do
for index3, value3 in pairs(value2) do
if value3[INDEX_LINK] then
link = Possessions_FixLink( value3[INDEX_LINK] )
textResult = false
_, theLink, _, _, _, itemType, subtype, _, slot = GetItemInfo( link )
--See if the item is in a guild bank
--Check if the name matches, or the tooltip lines if fulltext searching is enabled
if ( (Possessions_SearchGuildBank() == true) or (POSS_GUILDBANK_CONTAINER~=index2) ) then
if not searchString or searchString == "" then
textResult = true
elseif string.find(string.lower(value3[INDEX_NAME]), searchString) then
textResult = true
elseif Possessions_SearchFullText() == true and theLink then
PossScanningTooltip:ClearLines()
PossScanningTooltip:SetHyperlink(theLink)
for i=1,PossScanningTooltip:NumLines() do
if string.find(string.lower( _G["PossScanningTooltipTextLeft"..i]:GetText() or "" ), searchString) or
string.find(string.lower( _G["PossScanningTooltipTextRight"..i]:GetText() or "" ), searchString) then
textResult = true
break
end
end
end
end
if( textResult
and (not searchChar or searchChar == Possessions_Capitalize(index))
and (not searchLoc or searchLoc == Possessions_Bag2Loc(index2))
and (not searchSlot or searchSlot == slot)
and (not searchType or searchType == itemType)
and (not searchSubType or searchSubType == subtype)
) then
--Check if an entry has been created yet for the item. Items are bunched up by name
if (not TempTable[link]) then
TempTable[link] = { }
TempTable[link][INDEX_NAME] = value3[INDEX_NAME]
TempTable[link][INDEX_RARITY] = value3[INDEX_RARITY]
TempTable[link][INDEX_ICON] = value3[INDEX_ICON]
TempTable[link][INDEX_QUANTITY] = 0
TempTable[link][INDEX_LOCS] = { }
elseif( TempTable[link][INDEX_RARITY] == -1 ) then
TempTable[link][INDEX_RARITY] = value3[INDEX_RARITY]
end
--Increment quantity held
TempTable[link][INDEX_QUANTITY] = TempTable[link][INDEX_QUANTITY] + value3[INDEX_QUANTITY]
if( not TempTable[link][INDEX_LOCS][index] ) then
TempTable[link][INDEX_LOCS][index] = { }
end
location = Possessions_Bag2Loc(index2)
TempTable[link][INDEX_LOCS][index][location] = (TempTable[link][INDEX_LOCS][index][location] or 0) + value3[INDEX_QUANTITY]
end
end --if value3[INDEX_LINK]
end
end
end
end
local iNew = 1
--Copy search results from TempTable to Display Table
for index, value in pairs(TempTable) do
if value[INDEX_QUANTITY] > 0 then
if not DisplayIndices[iNew] then
DisplayIndices[iNew] = { }
end
DisplayIndices[iNew][INDEX_LINK] = index
DisplayIndices[iNew][INDEX_NAME] = value[INDEX_NAME]
DisplayIndices[iNew][INDEX_RARITY] = value[INDEX_RARITY]
DisplayIndices[iNew][INDEX_QUANTITY] = value[INDEX_QUANTITY]
DisplayIndices[iNew][INDEX_ICON] = value[INDEX_ICON]
DisplayIndices[iNew][INDEX_LOCS] = value[INDEX_LOCS]
--Copy location data to DisplayIndices and Reset quantities in TempTable to 0 for next search
iNew = iNew + 1
end
end
DisplayIndices.OnePastEnd = iNew --Keep track of number of Indices
--Hide extra stuff from previous searches by setting the quantity to 0
while(iNew <= #DisplayIndices ) do
DisplayIndices[iNew][INDEX_QUANTITY] = 0
iNew = iNew + 1
end
--Sort functions are modified to keep entries with Quantity=0 at the end of the list
if( POSSESSIONS_Sort_Name == 1) then
table.sort(DisplayIndices, Possessions_NameComparison);
else
table.sort(DisplayIndices, Possessions_RarityComparison);
end
Possessions_CountMoney();
end
function Possessions_UpdateView()
local item, itemIndex, buttonPrefix, iItem
FauxScrollFrame_Update(Possessions_IC_ScrollFrame, DisplayIndices.OnePastEnd-1, POSSESSIONS_ITEMS_TOSHOW, POSSESSIONS_ITEMS_HEIGHT)
for iItem = 1, POSSESSIONS_ITEMS_TOSHOW, 1 do
itemIndex = iItem + FauxScrollFrame_GetOffset(Possessions_IC_ScrollFrame)
buttonPrefix = "POSSESSIONS_BrowseButton"..iItem
if( itemIndex < DisplayIndices.OnePastEnd ) then
item = DisplayIndices[itemIndex]
if( item[INDEX_RARITY] ~= -1) then
_G[buttonPrefix.."Name"]:SetText( select(4,GetItemQualityColor(item[INDEX_RARITY])) .. item[INDEX_NAME].."|r")
else
_G[buttonPrefix.."Name"]:SetText(item[INDEX_NAME])
end
_G[buttonPrefix.."Quantity"]:SetText(item[INDEX_QUANTITY])
--Find the item's icon
_G[buttonPrefix.."ItemIconTexture"]:SetTexture( item[INDEX_ICON] or (item[INDEX_LINK] and select(10, GetItemInfo( item[INDEX_LINK] ))) or "Interface\\Icons\\INV_Misc_QuestionMark")
_G[buttonPrefix]:Show()
else
_G[buttonPrefix]:Hide()
end
end
end
function Possessions_Bag2Loc(bag)
if( bag < -1 ) then
return bag
elseif( bag > NUM_BAG_SLOTS or bag == -1 ) then
return POSS_BANK_CONTAINER
else
-- 0 to NUM_BAG_SLOTS is inventory
return POSS_INVENTORY_CONTAINER
end
end
function Possessions_RarityComparison(elem1, elem2)
if elem1[INDEX_QUANTITY] == 0 and elem2[INDEX_QUANTITY] == 0 then
return elem1[INDEX_NAME] < elem2[INDEX_NAME]
elseif elem1[INDEX_QUANTITY] == 0 then
return false
elseif elem2[INDEX_QUANTITY] == 0 then
return true
elseif( elem1[INDEX_RARITY] == elem2[INDEX_RARITY] ) then
return elem1[INDEX_NAME] < elem2[INDEX_NAME]
else
return elem1[INDEX_RARITY] > elem2[INDEX_RARITY]
end
end
function Possessions_NameComparison(elem1, elem2)
if elem1[INDEX_QUANTITY] == 0 and elem2[INDEX_QUANTITY] == 0 then
return elem1[INDEX_NAME] < elem2[INDEX_NAME]
elseif elem1[INDEX_QUANTITY] == 0 then
return false
elseif elem2[INDEX_QUANTITY] == 0 then
return true
else
return elem1[INDEX_NAME] < elem2[INDEX_NAME]
end
end
--------------------------------------------------
-- Handle button clicks
--------------------------------------------------
function Possessions_Click(self, button)
local id = self:GetID();
if(id == 0) then
id = self:GetParent():GetID();
end
local offset = FauxScrollFrame_GetOffset(Possessions_IC_ScrollFrame);
local item = DisplayIndices[id + offset];
if (item[INDEX_LINK]) then
local itemLink = select(2,GetItemInfo( item[INDEX_LINK] )) --Don't need to FixLink this since it is fixed for DisplayIndices
if( button == "RightButton" ) then
if(itemLink) then
DEFAULT_CHAT_FRAME:AddMessage("[Possessions]: "..itemLink..PossessionsLocale.SAFE_MESSAGE)
else
GameTooltip:SetHyperlink( item[INDEX_LINK] )
--Saeris's LootLink color!
DEFAULT_CHAT_FRAME:AddMessage("[Possessions]: "..PossessionsLocale.QUERY_MESSAGE..Possessions_BuildLink(item)..".")
end
elseif( button == "LeftButton" ) then
if not itemLink then return end
if IsShiftKeyDown() then
if (WIM and WIM.EditBoxInFocus) then
WIM.EditBoxInFocus:Insert(itemLink)
else
local editbox = ChatEdit_ChooseBoxForSend()
ChatEdit_ActivateChat(editbox)
if editbox then
editbox:Insert(itemLink)
end
end
elseif IsControlKeyDown() then
DressUpItemLink(itemLink)
else
SetItemRef(itemLink)
ItemRefTooltip:Show()
end
end
end
end
local PossItemTooltip = CreateFrame("GameTooltip",
"PossessionsItemTooltip", UIParent, "GameTooltipTemplate")
function Possessions_ItemButton_OnEnter(self)
local id = self:GetID()
local itemLink
local itemStackCount
if(id == 0) then
id = self:GetParent():GetID()
end
local offset = FauxScrollFrame_GetOffset(Possessions_IC_ScrollFrame)
local item = DisplayIndices[id + offset]
PossItemTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
_, itemLink, _, _, _, _, _, itemStackCount = GetItemInfo( item[INDEX_LINK] )
if( itemLink ) then
PossItemTooltip:SetHyperlink(itemLink)
if (IsAddOnLoaded("RecipeBook")) then
RecipeBook_DoHookedFunction(PossItemTooltip, itemLink)
end
else
PossItemTooltip:AddLine(item[INDEX_NAME].." ("..PossessionsLocale.ERRORTOOLTIP_L1..")")
if( item[INDEX_LINK]) then
PossItemTooltip:AddLine(PossessionsLocale.ERRORTOOLTIP_L2..item[INDEX_LINK])
PossItemTooltip:AddLine(PossessionsLocale.ERRORTOOLTIP_L3, 1, 1, 1, 1)
PossItemTooltip:AddLine(PossessionsLocale.ERRORTOOLTIP_L4, nil, nil, nil, 1) --Last 1 tells the tooltip to wrap the text
end
end
local location
local adj
local texture
local line
PossItemTooltip:AddLine(" ");
for charName, value in pairs(item[INDEX_LOCS]) do
for index2, quantity in pairs(value) do
if quantity > 0 then --Make sure that the quantity is greater than 0
adj = " in "
if( index2 == POSS_BANK_CONTAINER ) then
location = "bank"
texture = "Interface\\Icons\\INV_Misc_Bag_16"
elseif( index2 == POSS_KEYRING_CONTAINER ) then
location = "keyring"
texture = "Interface\\Icons\\INV_Misc_Key_14"
elseif( index2 == POSS_PLAYER_CONTAINER ) then
location = "person"
adj = " on "
texture = "Interface\\Icons\\INV_Misc_Bag_09_Blue"
elseif( index2 == POSS_INVENTORY_CONTAINER ) then
location = "inventory"
texture = "Interface\\Icons\\INV_Misc_Bag_08"
elseif( index2 == POSS_MAIL_CONTAINER ) then
location = "Inbox"
texture = "Interface\\Icons\\INV_Letter_02"
elseif( index2 == POSS_PLAYERBAG_CONTAINER ) then
location = "Inventory Bag Slots"
texture = "Interface\\Icons\\INV_Misc_Bag_EnchantedMageweave" --FIXME
elseif( index2 == POSS_BANKBAG_CONTAINER ) then
location = "Bank Bag Slots"
texture = "Interface\\Icons\\INV_Misc_Bag_15"
elseif( index2 == POSS_GUILDBANK_CONTAINER ) then
location = "Guild Bank"
texture = "Interface\\Icons\\INV_Misc_Bag_14"
else
location = "unknown"
texture = "Interface\\Icons\\INV_Misc_QuestionMark"
end
line = quantity .. adj .. Possessions_Capitalize(charName) .. "'s " .. location
PossItemTooltip:AddLine(line)
PossItemTooltip:AddTexture(texture)
end
end
end
if( itemStackCount ) then
PossItemTooltip:AddLine("Stack Count: "..itemStackCount)
end
PossItemTooltip:Show()
end
function Possessions_Capitalize(str)
--Capitalize only the first letter
return string.upper(string.sub(str,1,1)) .. string.sub(str,2)
end
function Possessions_ItemButton_OnLeave(self)
PossItemTooltip:Hide()
end
function Possessions_convertDB0to1()
DEFAULT_CHAT_FRAME:AddMessage("[Possessions]: Updating data to new format")
local tempTable = { }
for item, value in pairs(PossessionsData) do
tempTable[item] = { }
DEFAULT_CHAT_FRAME:AddMessage("[Possessions]: Server: " .. item)
for item2, value2 in pairs(value) do
tempTable[item][item2] = { }
tempTable[item][item2].items = { }
DEFAULT_CHAT_FRAME:AddMessage("[Possessions]: Char: " .. item2)
for item3, value3 in pairs(value2) do
tempTable[item][item2].items[item3] = value3
end
end