forked from AssemblerManiac/InventoryInsight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInventoryInsight_Backpack.lua
1614 lines (1391 loc) · 58.1 KB
/
InventoryInsight_Backpack.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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
local function p(...)
-- Ensure IIfA and its debug function are properly initialized
if not IIfA or not IIfA.DebugOut then return end
-- Ensure the conditions for debugging are met
if not IIFA_DATABASE[IIfA.currentAccount] or not IIFA_DATABASE[IIfA.currentAccount].settings.bDebug then return end
IIfA:DebugOut(...)
end
-- this is for the buttons
local function enableFilterButton(num)
local buttonName = "Button" .. num
local button = IIFA_GUI_Header_Filter:GetNamedChild(buttonName)
if button then
button:SetState(BSTATE_PRESSED)
end
end
local function disableFilterButton(num)
local button = IIFA_GUI_Header_Filter:GetNamedChild("Button" .. num)
if button then
button:SetState(BSTATE_NORMAL)
end
end
function IIfA:GetActiveFilter()
if not IIfA.ActiveFilter then return 0 end
return tonumber(IIfA.ActiveFilter)
end
function IIfA:SetActiveFilter(value)
if value == nil then
value = 0
else
value = tonumber(value)
end
local currentFilter = IIfA:GetActiveFilter()
if tonumber(currentFilter) == value then
value = 0
end
IIfA.ActiveFilter = value
if currentFilter ~= value then
disableFilterButton(currentFilter)
end
enableFilterButton(value)
IIfA:RefreshInventoryScroll()
end
function IIfA:GetActiveSubFilter()
if not IIfA.activeSubFilter then return 0 end
return tonumber(IIfA.activeSubFilter)
end
function IIfA:SetActiveSubFilter(value)
value = tonumber(value)
if IIfA:GetActiveSubFilter() == value then
IIfA.activeSubFilter = 0
else
IIfA.activeSubFilter = value
end
IIfA:RefreshInventoryScroll()
end
--[[----------------------------------------------------------------------]]
--[[----------------------------------------------------------------------]]
--[[------ GUI functions ------------------------------------------------]]
function IIfA:GUIDoubleClick(control, button)
if button == MOUSE_BUTTON_INDEX_LEFT and control.itemLink then
if control.itemLink ~= IIfA.EMPTY_STRING then
ZO_ChatWindowTextEntryEditBox:SetText(ZO_ChatWindowTextEntryEditBox:GetText() .. ZO_CachedStrFormat(SI_TOOLTIP_ITEM_NAME, control.itemLink))
end
end
end
local function getHouseIds()
local ret = {}
for houseName, houseId in pairs(IIfA:GetTrackedHouses()) do
table.insert(ret, houseId)
end
return ret
end
local function isHouse()
return IIfA:GetTrackingWithHouseNames()[locationName]
end
function IIfA:GetCurrentCompanionName()
if HasActiveCompanion() then
return ZO_CachedStrFormat(SI_UNIT_NAME, GetCompanionName(GetActiveCompanionDefId()))
-- returns nil if no current active companion
else return end
end
function IIfA:GetCurrentCompanionHashId()
local currentCompanionName
local companionNameHash
if HasActiveCompanion() then
currentCompanionName = IIfA:GetCurrentCompanionName()
companionNameHash = HashString(currentCompanionName)
return tostring(companionNameHash)
end
-- returns nil if no current active companion
return
end
local function is_empty_or_nil(t)
if t == nil or t == "" then return true end
return type(t) == "table" and ZO_IsTableEmpty(t) or false
end
local function is_in(search_value, search_table)
if is_empty_or_nil(search_value) then return false end
for k, v in pairs(search_table) do
if search_value == v then return true end
if type(search_value) == "string" then
if zo_strfind(zo_strlower(v), zo_strlower(search_value)) then return true end
end
end
return false
end
local function DoesInventoryMatchList(locationName, location)
local bagId = location.bagID
local filter = IIfA.InventoryListFilter
local filterBag = IIfA.InventoryListFilterBagId
local allBanks = { BAG_BANK, BAG_SUBSCRIBER_BANK, BAG_GUILDBANK }
local guildBank = { BAG_GUILDBANK }
local allCharacterInventory = { BAG_BACKPACK, BAG_WORN, BAG_COMPANION_WORN }
local allCompanions = { BAG_COMPANION_WORN }
local allEquipped = { BAG_WORN, BAG_COMPANION_WORN }
local allStorage = { BAG_BACKPACK, BAG_WORN, BAG_BANK, BAG_SUBSCRIBER_BANK, BAG_VIRTUAL, BAG_COMPANION_WORN }
local bankAndCharacters = { BAG_BACKPACK, BAG_WORN, BAG_BANK, BAG_SUBSCRIBER_BANK, BAG_COMPANION_WORN }
local currentCharacter = { BAG_BACKPACK, BAG_WORN }
local banksOnly = { BAG_BANK, BAG_SUBSCRIBER_BANK }
local craftBag = { BAG_VIRTUAL }
-- Local variable for collectHouseData
local serverData = IIFA_DATABASE[IIfA.currentAccount].servers[IIfA.currentServerType]
local collectHouseData = serverData.collectHouseData[bagId]
-- if locationName == "attributes" then return false end
if (filter == GetString(IIFA_LOCATION_NAME_ALL)) then
return true
elseif (filter == GetString(IIFA_LOCATION_NAME_ALL_BANKS)) then
return is_in(bagId, allBanks) and IIfA.trackedBags[bagId]
elseif (filter == GetString(IIFA_LOCATION_NAME_ALL_GUILDBANKS)) then
return is_in(bagId, guildBank)
elseif (filter == GetString(IIFA_LOCATION_NAME_ALL_CHARACTERS)) then
return is_in(bagId, allCharacterInventory)
elseif (filter == GetString(IIFA_LOCATION_NAME_ALL_COMPANIONS)) then
return is_in(bagId, allCompanions)
elseif (filter == GetString(IIFA_LOCATION_NAME_ALL_EQUIPPED)) then
return is_in(bagId, allEquipped)
elseif (filter == GetString(IIFA_LOCATION_NAME_ALL_STORAGE)) then
return is_in(bagId, allStorage) or GetCollectibleForHouseBankBag(bagId) > 0
elseif (filter == GetString(IIFA_LOCATION_NAME_EVERYTHING)) then
return is_in(bagId, allStorage) or GetCollectibleForHouseBankBag(bagId) > 0 or collectHouseData
elseif (filter == GetString(IIFA_LOCATION_NAME_BANK_ONLY)) then
return is_in(bagId, banksOnly)
elseif (filter == GetString(IIFA_LOCATION_NAME_BANK_AND_CHARACTERS)) then
return is_in(bagId, bankAndCharacters)
elseif (filter == GetString(IIFA_LOCATION_NAME_BANK_CURRENT_CHARACTER)) then
return is_in(bagId, banksOnly) or (is_in(bagId, currentCharacter) and locationName == IIfA.currentCharacterId)
elseif (filter == GetString(IIFA_LOCATION_NAME_BANK_OTHER_CHARACTERS)) then
return is_in(bagId, banksOnly) or (is_in(bagId, currentCharacter) and locationName ~= IIfA.currentCharacterId)
elseif (filter == GetString(IIFA_LOCATION_NAME_CRAFT_BAG)) then
return is_in(bagId, craftBag)
elseif (filter == GetString(IIFA_LOCATION_NAME_HOUSING_STORAGE) and filterBag == nil) then
-- all housing storage chests/coffers
return GetCollectibleForHouseBankBag(bagId) > 0
elseif (filter == GetString(IIFA_LOCATION_NAME_HOUSING_STORAGE) and filterBag ~= nil) then
-- specific housing storage chest/coffer
return bagId == filterBag and GetCollectibleForHouseBankBag(bagId) > 0
elseif (filter == GetString(IIFA_LOCATION_NAME_ALL_HOUSES)) then
return collectHouseData
elseif (IIfA:GetHouseIdFromName(filter) ~= nil) then
return (bagId == IIfA:GetHouseIdFromName(filter))
else
-- is it a specific character
if is_in(bagId, currentCharacter) then
-- it's a character name, convert to Id, check that against location Name in the dbv3 table
if locationName == serverData.CharNameToId[filter] then return true end
-- Check companion equipment, convert to Id
elseif is_in(bagId, allCompanions) then
if locationName == serverData.CompanionNameToId[filter] then return true end
else
-- it's a bank to compare, do it direct
return locationName == filter
end
end
end
--@Baertram:
--Made the function global to be used in other addons like FCOItemSaver
function IIfA:DoesInventoryMatchList(locationName, location)
return DoesInventoryMatchList(locationName, location)
end
local function matchCurrentInventory(locationName)
-- if locationName == "attributes" then return false end
local accountInventoryList = IIfA:GetAccountInventoryList()
for i, inventoryName in pairs(accountInventoryList) do
if inventoryName == locationName then return true end
end
return (IIfA:GetInventoryListFilter() == GetString(IIFA_LOCATION_NAME_ALL))
end
local qualityDictionary
local function getColoredString(color, s)
local c = ZO_ColorDef:New(GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_QUALITY_COLORS, color))
return c:Colorize(s)
end
local function getQualityDict()
if qualityDictionary == nil then
qualityDictionary = {
[GetString(IIFA_DROPDOWN_QUALITY_MENU_ANY)] = IIFA_FILTER_MENU_QUALITY_ANY,
[getColoredString(ITEM_DISPLAY_QUALITY_TRASH, GetString(SI_ITEMDISPLAYQUALITY0))] = ITEM_DISPLAY_QUALITY_TRASH,
[getColoredString(ITEM_DISPLAY_QUALITY_NORMAL, GetString(SI_ITEMDISPLAYQUALITY1))] = ITEM_DISPLAY_QUALITY_NORMAL,
[getColoredString(ITEM_DISPLAY_QUALITY_MAGIC, GetString(SI_ITEMDISPLAYQUALITY2))] = ITEM_DISPLAY_QUALITY_MAGIC,
[getColoredString(ITEM_DISPLAY_QUALITY_ARCANE, GetString(SI_ITEMDISPLAYQUALITY3))] = ITEM_DISPLAY_QUALITY_ARCANE,
[getColoredString(ITEM_DISPLAY_QUALITY_ARTIFACT, GetString(SI_ITEMDISPLAYQUALITY4))] = ITEM_DISPLAY_QUALITY_ARTIFACT,
[getColoredString(ITEM_DISPLAY_QUALITY_LEGENDARY, GetString(SI_ITEMDISPLAYQUALITY5))] = ITEM_DISPLAY_QUALITY_LEGENDARY,
[getColoredString(ITEM_DISPLAY_QUALITY_MYTHIC_OVERRIDE, GetString(SI_ITEMDISPLAYQUALITY6))] = ITEM_DISPLAY_QUALITY_MYTHIC_OVERRIDE,
}
end
return qualityDictionary
end
function IIfA:getQualityDict()
return qualityDictionary or getQualityDict()
end
--[[ Only used in IIfA:UpdateScrollDataLinesData()
This is not used from the XML file when a user clicks a filter button.
When a user clicks a filter button that is IIfA:GuiOnFilterButton()
]]--
local function matchFilter(itemName, itemLink)
if not itemLink then return end
local ret = false
local itemMatch = false
local isCompanionItem = GetItemLinkActorCategory(itemLink) == GAMEPLAY_ACTOR_CATEGORY_COMPANION
local weaponType = GetItemLinkWeaponType(itemLink)
local armorType = GetItemLinkArmorType(itemLink)
local itemType, specializedItemType = GetItemLinkItemType(itemLink)
local equipType = GetItemLinkEquipType(itemLink)
-- for furniture
local furnitureDataId
if IIfA:isItemLink(itemLink) then
furnitureDataId = GetItemLinkFurnitureDataId(itemLink)
elseif IIfA:isCollectibleLink(itemLink) then
local collectibleId = IIfA:GetCollectibleLinkItemId(itemLink)
furnitureDataId = GetCollectibleFurnitureDataId(collectibleId)
itemType = ITEMTYPE_FURNISHING
end
local categoryId, subcategoryId = GetFurnitureDataCategoryInfo(furnitureDataId)
local isFurnishingItem = itemType == ITEMTYPE_FURNISHING
local function itemWearable()
return equipType == EQUIP_TYPE_CHEST
or equipType == EQUIP_TYPE_FEET
or equipType == EQUIP_TYPE_HAND
or equipType == EQUIP_TYPE_HEAD
or equipType == EQUIP_TYPE_LEGS
or equipType == EQUIP_TYPE_SHOULDERS
or equipType == EQUIP_TYPE_WAIST
end
local isWearable = itemWearable()
local function itemWeapon()
return weaponType == WEAPONTYPE_AXE
or weaponType == WEAPONTYPE_HAMMER
or weaponType == WEAPONTYPE_SWORD
or weaponType == WEAPONTYPE_DAGGER
or weaponType == WEAPONTYPE_TWO_HANDED_AXE
or weaponType == WEAPONTYPE_TWO_HANDED_HAMMER
or weaponType == WEAPONTYPE_TWO_HANDED_SWORD
or weaponType == WEAPONTYPE_BOW
or weaponType == WEAPONTYPE_FIRE_STAFF
or weaponType == WEAPONTYPE_FROST_STAFF
or weaponType == WEAPONTYPE_LIGHTNING_STAFF
or weaponType == WEAPONTYPE_HEALING_STAFF
end
local isWeapon = itemWeapon()
-- 17-7-30 AM - moved lowercasing to when it's created, one less call to lowercase for every item
-- 2024-11-10 Sharlikran - ony use when IIfA:IsItemSet() when there is a search string
--Empty search string? Then skip all searches with names
local searchFilter = IIfA.searchFilter
local hasSearchFilter = searchFilter and searchFilter > IIfA.EMPTY_STRING
local function HasItemNameSearchFilter()
local hasValidItemName = itemName and itemName > IIfA.EMPTY_STRING
local validMatch = false
-- Only proceed if the item name and search filter are not empty
if hasSearchFilter then
if hasValidItemName then
-- Set name of item and convert to lowercase
local name = zo_strlower(ZO_CachedStrFormat("<<C:1>>", itemName))
-- Match the item name against the search filter
validMatch = zo_plainstrfind(name, searchFilter)
end
end
return validMatch
end
local hasValidItemNameFilter = HasItemNameSearchFilter()
local function HasSetSearchFilter()
-- Local variable to indicate a match
local retSet = false
local hasSetInfo, setName
-- Check if there’s a search filter and if set-based filtering is enabled
if hasSearchFilter and (IIFA_DATABASE[IIfA.currentAccount].settings.bFilterOnSetNameToo or IIFA_DATABASE[IIfA.currentAccount].settings.bFilterOnSetName) then
hasSetInfo, setName = IIfA:IsItemSet(itemLink)
if hasSetInfo then
-- Check if the set name matches the search filter
retSet = zo_plainstrfind(zo_strlower(setName), searchFilter)
end
end
return retSet
end
local hasValidSetFilter = HasSetSearchFilter()
local hasSingleFilterMatch = IIfA.filterTypes and type(IIfA.filterTypes) == "table" and #IIfA.filterTypes >= 1
local hasDualFilterMatch = IIfA.filterTypes and type(IIfA.filterTypes) == "table" and #IIfA.filterTypes >= 2
local hasValidFurnishingFilterType = IIfA.filterTypes and type(IIfA.filterTypes) == "table" and #IIfA.filterTypes >= 3
-- the following groups use nil initially rather than a type from GetItemLinkItemType()
local isFilterGroupAllItems = IIfA.filterGroup == "All"
local isFilterGroupWeapons = IIfA.filterGroup == "Weapons"
local isFilterGroupArmor = IIfA.filterGroup == "Armor"
local isFilterGroupJewelry = IIfA.filterGroup == "Jewelry"
local isFilterGroupCompanion = IIfA.filterGroup == "Companion"
local isFilterGroupFurnishing = IIfA.filterGroup == "Furnishing"
--[[ Check if the filter group is set to something specific (not "All") and
IIfA.filterTypes is populated ]]--
local isFilterGroupSpecific = IIfA.filterGroup ~= "All"
--[[ the following groups use corresponding itemType constants
within a table and compared to GetItemLinkItemType() ]]--
local isFilterGroupConsumable = IIfA.filterGroup == "Consumable"
local isFilterGroupMaterials = IIfA.filterGroup == "Materials"
local isFilterGroupSpecialized = IIfA.filterGroup == "Specialized"
local isFilterGroupMisc = IIfA.filterGroup == "Misc"
local isFilterGroupMiscSubfilter = IIfA.filterGroup == "MiscSubfilter"
local isFilterGroupStolen = IIfA.filterGroup == "Stolen"
local isFilterGroupAppearance = IIfA.filterGroup == "Appearance"
local isFilterGroupJunk = IIfA.filterGroup == "Junk"
--[[TODO: Would anyone ever choose Stolen and a set name? ]]--
if isFilterGroupStolen then
-- If the filter is set to "Stolen"
ret = IsItemLinkStolen(itemLink)
end
if isFilterGroupAllItems then
-- If the filter is set to "All"
ret = true
end
if isFilterGroupSpecific and not isFilterGroupStolen then
local function shouldMatchAllWeaponTypes()
local invalidFilterType = not IIfA.filterTypes or #IIfA.filterTypes == 0
return invalidFilterType and not isCompanionItem and isWeapon
end
local function shouldMatchAllArmorTypes()
local invalidFilterType = not IIfA.filterTypes or #IIfA.filterTypes == 0
local hasShield = weaponType == WEAPONTYPE_SHIELD
local hasDisguise = specializedItemType == SPECIALIZED_ITEMTYPE_DISGUISE
local hasCostume = specializedItemType == SPECIALIZED_ITEMTYPE_COSTUME
return invalidFilterType and not isCompanionItem and (hasShield or hasDisguise or isWearable or hasCostume)
end
local function shouldMatchAllJewelryTypes()
local invalidFilterType = not IIfA.filterTypes or #IIfA.filterTypes == 0
local isJewelry = armorType == ARMORTYPE_NONE and (equipType == EQUIP_TYPE_NECK or equipType == EQUIP_TYPE_RING)
return invalidFilterType and not isCompanionItem and isJewelry
end
local function shouldMatchAllCompanionItems()
local invalidFilterType = not IIfA.filterTypes or #IIfA.filterTypes == 0
return invalidFilterType and isCompanionItem
end
local function shouldMatchAllFurnishingItems()
local invalidFilterType = not IIfA.filterTypes or #IIfA.filterTypes == 0
return invalidFilterType and isFurnishingItem
end
--[[
Consumable, Materials, Furnishings (Specialized), Misc, Junk : use Item Types for All
All, Weapons, Armor, Jewelry, Companion : use nil for All
]]--
--[[ All and Stolen Considered first and set ret to true ]]--
--[[
All : All (Unique)
Weapons :
Armor :
Shield : Armor
Appearance : Armor
Jewelry :
Consumable :
Materials :
Furnishings : Specialized
Companion :
Misc :
Scripting : Misc (incorporated)
Stolen : Misc
Junk : Misc
]]--
-- Weapons (Uses nil for top filter)
--[[The values for Weapons use WEAPONTYPE without an leading
itemType]]--
if isFilterGroupWeapons then
if shouldMatchAllWeaponTypes() then
itemMatch = true
elseif hasSingleFilterMatch then
for i = 1, #IIfA.filterTypes do
if weaponType == IIfA.filterTypes[i] and not isCompanionItem then
itemMatch = true
break
end
end
end
end
-- Armor (Uses nil for top filter)
--[[The values for Armor use armorType as the first parameter then
subsequent comparisons use EQUIP_TYPE ]]--
if isFilterGroupArmor then
if shouldMatchAllArmorTypes() then
itemMatch = true
elseif hasDualFilterMatch then
if armorType == IIfA.filterTypes[1] then
for i = 2, #IIfA.filterTypes do
if equipType == IIfA.filterTypes[i] and not isCompanionItem then
itemMatch = true
break
end
end
end
end
end
-- Appearance
if isFilterGroupAppearance then
--[[The values for Appearance use SPECIALIZED_ITEMTYPE because
there are two Itemtypes and IIfA.filterTypes[1] would not work ]]--
if hasSingleFilterMatch then
for i = 1, #IIfA.filterTypes do
if (specializedItemType == IIfA.filterTypes[i]) then
itemMatch = true
break
end
end
end
end
-- Jewelry (Uses nil for top filter)
--[[The values for Jewelry use only EQUIP_TYPE because
armorType will be equal to ARMORTYPE_NONE ]]--
if isFilterGroupJewelry then
if shouldMatchAllJewelryTypes() then
itemMatch = true
elseif hasSingleFilterMatch then
for i = 1, #IIfA.filterTypes do
if equipType == IIfA.filterTypes[i] and not isCompanionItem then
itemMatch = true
break
end
end
end
end
-- Consumable
if isFilterGroupConsumable then
--[[The values for Consumable use the Itemtypes and while recipe
uses Specialized it will function independently of this filter ]]--
if hasSingleFilterMatch then
for i = 1, #IIfA.filterTypes do
if (itemType == IIfA.filterTypes[i]) then
itemMatch = true
break
end
end
end
end
-- Materials
if isFilterGroupMaterials then
--[[The values for Materials use the Itemtypes ]]--
if hasSingleFilterMatch then
for i = 1, #IIfA.filterTypes do
if (itemType == IIfA.filterTypes[i]) then
itemMatch = true
break
end
end
end
end
-- Furnishings (Uses nil for top filter)
if isFilterGroupFurnishing then
--[[The values for Furnishings are using custom constants to use with
GetFurnitureDataCategoryInfo() where categoryId is similar to itemType
and subcategoryId is similar to specializedItemType
The main difference is that the first type is the itemType for Furnishings
then the special categoryId, and then the subtype if selected. ]]--
if shouldMatchAllFurnishingItems() then
itemMatch = true
elseif hasValidFurnishingFilterType then
if itemType == IIfA.filterTypes[1] and categoryId == IIfA.filterTypes[2] then
for i = 3, #IIfA.filterTypes do
if (subcategoryId == IIfA.filterTypes[i]) then
itemMatch = true
break
end
end
end
end
end
-- Specialized
if isFilterGroupSpecialized then
--[[The values for Specialized use the Itemtypes as the first parameter
then iterate over SPECIALIZED_ITEMTYPE ]]--
if hasDualFilterMatch then
if itemType == IIfA.filterTypes[1] then
for i = 2, #IIfA.filterTypes do
if (specializedItemType == IIfA.filterTypes[i]) then
itemMatch = true
break
end
end
end
end
end
-- MiscSubfilter
if isFilterGroupMiscSubfilter then
--[[The values for MiscSubfilter iterate over specialized item types ]]--
if hasSingleFilterMatch then
for i = 1, #IIfA.filterTypes do
if (specializedItemType == IIfA.filterTypes[i]) then
itemMatch = true
break
end
end
end
end
-- Companion (Uses nil for top filter)
if isFilterGroupCompanion and isCompanionItem then
if shouldMatchAllCompanionItems() then
itemMatch = true
elseif hasDualFilterMatch then
if IIfA.filterTypes[1] == ITEMTYPE_ARMOR then
for i = 2, #IIfA.filterTypes do
if equipType == IIfA.filterTypes[i] then
itemMatch = true
break
end
end
elseif IIfA.filterTypes[1] == ITEMTYPE_WEAPON then
for i = 2, #IIfA.filterTypes do
if weaponType == IIfA.filterTypes[i] then
itemMatch = true
break
end
end
end
end
end
-- Misc
if isFilterGroupMisc then
--[[The values for Misc use the Itemtypes and while Stolen
uses its own category it functions independently of this filter ]]--
if hasSingleFilterMatch then
for i = 1, #IIfA.filterTypes do
if (itemType == IIfA.filterTypes[i]) then
itemMatch = true
break
end
end
end
end
-- Junk
if isFilterGroupJunk then
--[[The values for Junk use the Itemtypes but are part of Misc ]]--
if hasSingleFilterMatch then
if itemType == IIfA.filterTypes[1] then
itemMatch = true
end
end
end
ret = itemMatch
end
if hasSearchFilter then
if IIFA_DATABASE[IIfA.currentAccount].settings.bFilterOnSetName then
-- Only set name matches are allowed
ret = ret and hasValidSetFilter
elseif IIFA_DATABASE[IIfA.currentAccount].settings.bFilterOnSetNameToo then
-- Either set name or item name matches
ret = ret and (hasValidSetFilter or hasValidItemNameFilter)
else
-- When both options are false, only item names should match
ret = ret and hasValidItemNameFilter
end
end
return ret
end
local function matchQuality(itemQuality)
local quality = IIfA.InventoryListFilterQuality
return IIFA_FILTER_MENU_QUALITY_ANY == quality or itemQuality == quality
end
--sort datalines
local function IIfA_FilterCompareUp(a, b)
local sort1 = (IIfA.bSortQuality and a.quality) or a.name
local sort2 = (IIfA.bSortQuality and b.quality) or b.name
return (sort1 or IIfA.EMPTY_STRING) < (sort2 or IIfA.EMPTY_STRING)
end
local function IIfA_FilterCompareDown(a, b)
return IIfA_FilterCompareUp(b, a)
end
local function sort(dataLines)
if dataLines == nil then dataLines = IIFA_GUI_ListHolder.dataLines end
if (IIfA.ScrollSortUp) then
dataLines = table.sort(dataLines, IIfA_FilterCompareUp)
elseif (not IIfA.ScrollSortUp) then
dataLines = table.sort(dataLines, IIfA_FilterCompareDown)
end
end
local function itemSum(location)
if type(location.bagSlot) ~= "table" then return 0 end
local totQty = 0
for bagSlot, itemCount in pairs(location.bagSlot) do
totQty = totQty + itemCount
end
return totQty
end
local function checkSearchFilter(searchFilterNew)
local searchFilterCurrent = IIfA.searchFilter
if ((searchFilterNew and searchFilterCurrent and searchFilterNew ~= searchFilterCurrent) or
(not searchFilterNew and not searchFilterCurrent) or
(searchFilterCurrent and searchFilterCurrent == "Click to search..."))
then
searchFilterNew = searchFilterNew or IIfA.GUI_SearchBox:GetText()
searchFilterNew = ZO_CachedStrFormat("<<C:1>>", searchFilterNew)
return zo_strlower(searchFilterNew)
else
return searchFilterCurrent
end
end
function IIfA:UpdateScrollDataLinesData()
IIfA.searchFilter = checkSearchFilter()
local dataLines = {}
local DBv3 = IIFA_DATABASE[IIfA.currentAccount].servers[IIfA.currentServerType].DBv3
local totalItems = 0 -- Tracks total item counts across all entries
if DBv3 then
-- Create coroutine to process database items in chunks
local co = coroutine.create(function()
for itemKey, dbItem in pairs(DBv3) do
-- Determine the item link
local identifiedLink = nil
if IIfA:isCollectibleLink(itemKey) or IIfA:isItemLink(itemKey) then
identifiedLink = itemKey
elseif IIfA:isItemKey(itemKey) then
identifiedLink = dbItem.itemLink
end
if identifiedLink and identifiedLink ~= IIfA.EMPTY_STRING then
-- Retrieve item details based on its type
local identifiedIcon, identifiedItemName, identifiedItemQuality
if IIfA:isCollectibleLink(identifiedLink) then
local collectibleId = IIfA:GetCollectibleLinkItemId(identifiedLink)
identifiedIcon = GetCollectibleIcon(collectibleId)
identifiedItemName = ZO_CachedStrFormat(SI_TOOLTIP_ITEM_NAME, GetCollectibleName(collectibleId))
identifiedItemQuality = 1
elseif IIfA:isItemLink(identifiedLink) then
identifiedIcon = GetItemLinkIcon(identifiedLink)
identifiedItemName = ZO_CachedStrFormat(SI_TOOLTIP_ITEM_NAME, GetItemLinkName(identifiedLink))
identifiedItemQuality = GetItemLinkDisplayQuality(identifiedLink)
end
-- Update cached item data
dbItem.itemName = dbItem.itemName or identifiedItemName
dbItem.itemQuality = dbItem.itemQuality or identifiedItemQuality
dbItem.filterType = dbItem.filterType or 0
-- Initialize tracking variables for this item
local itemCount = 0
local bWorn, bWornCompanion = false, false
local isItemMatched = false
-- Process each location and update counts and states
for locationName, locData in pairs(dbItem.locations) do
itemCount = itemCount + itemSum(locData)
if DoesInventoryMatchList(locationName, locData) then
isItemMatched = true
end
if locData.bagID == BAG_WORN then
bWorn = true
elseif locData.bagID == BAG_COMPANION_WORN then
bWornCompanion = true
end
end
local dataLine = {
link = identifiedLink,
qty = itemCount,
icon = identifiedIcon,
name = dbItem.itemName,
quality = dbItem.itemQuality,
filter = dbItem.filterType,
worn = bWorn,
wornCompanion = bWornCompanion
}
-- Add data to dataLines if the item meets all criteria
if itemCount > 0 and isItemMatched and matchFilter(identifiedItemName, identifiedLink) and matchQuality(dbItem.itemQuality) then
table.insert(dataLines, dataLine)
totalItems = totalItems + itemCount
end
end
-- Yield after processing each item to prevent blocking
coroutine.yield()
end
end)
-- Resume coroutine until complete
while coroutine.status(co) ~= "dead" do
local success, err = coroutine.resume(co)
if not success then
d("Error in UpdateScrollDataLinesData coroutine: " .. tostring(err))
break
end
end
end
-- Update GUI elements with processed data
IIFA_GUI_ListHolder.dataLines = dataLines
sort(IIFA_GUI_ListHolder.dataLines)
IIFA_GUI_ListHolder.dataOffset = 0
IIFA_GUI_ListHolder_Slider:SetValue(0)
-- Set handlers for scroll interaction
IIFA_GUI_ListHolder_SliderUp:SetHandler("OnClicked", function(self, button, ctrl, alt, shiftPressed)
local increment = shiftPressed and 10 or 1
IIfA:GuiOnScroll(self:GetParent(), increment)
end)
IIFA_GUI_ListHolder_SliderDown:SetHandler("OnClicked", function(self, button, ctrl, alt, shiftPressed)
local increment = shiftPressed and -10 or -1
IIfA:GuiOnScroll(self:GetParent(), increment)
end)
IIFA_GUI_ListHolder:SetHandler("OnMouseWheel", function(self, delta, ctrl, alt, shiftPressed)
local increment = delta * (shiftPressed and 10 or 1)
IIfA:GuiOnScroll(self:GetParent(), increment)
end)
-- even if the counts aren’t visible, update them so they show properly if user turns them on
IIFA_GUI_ListHolder_Counts_Items:SetText("Item count: " .. totalItems)
IIFA_GUI_ListHolder_Counts_Slots:SetText("Appx. slots used: " .. #dataLines)
end
--Update the FCOItemSaver marker icons at the IIfA inventory frames
local function updateFCOISMarkerIcons(curLine, showFCOISMarkerIcons, createFCOISMarkerIcons, iconId)
if not FCOIS or not IIfA.UpdateFCOISMarkerIcons then return end
IIfA:UpdateFCOISMarkerIcons(curLine, showFCOISMarkerIcons, createFCOISMarkerIcons, iconId)
end
local function fillLine(curLine, curItem)
local color
if curItem == nil then
curLine.itemLink = IIfA.EMPTY_STRING
curLine.icon:SetTexture(nil)
curLine.icon:SetAlpha(0)
curLine.text:SetText(IIfA.EMPTY_STRING)
curLine.qty:SetText(IIfA.EMPTY_STRING)
curLine.worn:SetHidden(true)
curLine.wornCompanion:SetHidden(true)
curLine.stolen:SetHidden(true)
-- Hide the FCOIS marker icons at the line (do not create them if not needed) -> File plugins/FCOIS/IIfA_FCOIS.lua
updateFCOISMarkerIcons(curLine, false, false, -1)
else
local r, g, b, a = 255, 255, 255, 1
if (curItem.quality) then
color = GetItemQualityColor(curItem.quality)
r, g, b, a = color:UnpackRGBA()
end
curLine.itemLink = curItem.link
curLine.icon:SetTexture(curItem.icon)
curLine.icon:SetAlpha(1)
local text = ZO_CachedStrFormat(SI_TOOLTIP_ITEM_NAME, curItem.name)
curLine.text:SetText(text)
curLine.text:SetColor(r, g, b, a)
curLine.qty:SetText(curItem.qty)
curLine.worn:SetHidden(not curItem.worn)
curLine.wornCompanion:SetHidden(not curItem.wornCompanion)
curLine.stolen:SetHidden(not IsItemLinkStolen(curItem.link))
-- Show the FCOIS marker icons at the line, if enabled in the settings (create them if needed) -> File plugins/FCOIS/IIfA_FCOIS.lua
updateFCOISMarkerIcons(curLine, IIFA_DATABASE[IIfA.currentAccount].settings.FCOISshowMarkerIcons, false, -1)
end
end
function IIfA:SetDataLinesData()
-- p("SetDataLinesData")
local curLine, curData
for i = 1, IIFA_GUI_ListHolder.maxLines do
curLine = IIFA_GUI_ListHolder.lines[i]
curData = IIFA_GUI_ListHolder.dataLines[IIFA_GUI_ListHolder.dataOffset + i]
IIFA_GUI_ListHolder.lines[i] = curLine
if (curData ~= nil) then
fillLine(curLine, curData)
else
fillLine(curLine, nil)
end
end
end
function IIfA:UpdateInventoryScroll()
if IIFA_GUI_ListHolder.dataOffset < 0 then IIFA_GUI_ListHolder.dataOffset = 0 end
if IIFA_GUI_ListHolder.maxLines == nil then IIFA_GUI_ListHolder.maxLines = 35 end
IIfA:SetDataLinesData()
local total = #IIFA_GUI_ListHolder.dataLines - IIFA_GUI_ListHolder.maxLines
IIFA_GUI_ListHolder_Slider:SetMinMax(0, total)
end
function IIfA:RefreshInventoryScroll()
-- p("RefreshInventoryScroll")
IIfA:UpdateScrollDataLinesData()
IIfA:UpdateInventoryScroll()
end
function IIfA:SetItemCountPosition()
for i = 1, IIFA_GUI_ListHolder.maxLines do
local line = IIFA_GUI_ListHolder.lines[i]
line.text:ClearAnchors()
line.qty:ClearAnchors()
if IIFA_DATABASE[IIfA.currentAccount].settings.showItemCountOnRight then
line.qty:SetAnchor(TOPRIGHT, line, TOPRIGHT, 0, 0)
line.text:SetAnchor(TOPLEFT, line:GetNamedChild("Button"), TOPRIGHT, 18, 0)
line.text:SetAnchor(TOPRIGHT, line.qty, TOPLEFT, -10, 0)
else
line.qty:SetAnchor(TOPLEFT, line:GetNamedChild("Button"), TOPRIGHT, 8, -3)
line.text:SetAnchor(TOPLEFT, line.qty, TOPRIGHT, 18, 0)
line.text:SetAnchor(TOPRIGHT, line, TOPLEFT, 0, 0)
end
end
end
-- Define constants for anchor groups
local IIFA_DEFAULT_ANCHOR = 1
-- Define constants for anchor types
local IIFA_ANCHOR_EQUIPPED = 1
local IIFA_ANCHOR_COMPANION_EQUIPPED = 2
local IIFA_ANCHOR_STOLEN = 3
-- Function to retrieve anchor values
local function GetAnchor(group, anchor, control)
-- Anchor definitions
local anchorGroups = {
[IIFA_DEFAULT_ANCHOR] = {
[IIFA_ANCHOR_EQUIPPED] = { TOPRIGHT, control, TOPLEFT, 12, 5 },
[IIFA_ANCHOR_COMPANION_EQUIPPED] = { TOPRIGHT, control, TOPLEFT, 12, 5 },
[IIFA_ANCHOR_STOLEN] = { BOTTOMRIGHT, control, BOTTOMLEFT, 15, -8 },
},
}
local groupAnchors = anchorGroups[group]
if groupAnchors then
local anchorValues = groupAnchors[anchor]
if anchorValues then
return unpack(anchorValues) -- Return point, relativeTo, relativePoint, offsetX, offsetY
end
end
-- Fallback to default equipped anchor
return unpack(anchorGroups[IIFA_DEFAULT_ANCHOR][IIFA_ANCHOR_EQUIPPED])
end
function IIfA:CreateLine(i, predecessor, parent)
local line = WINDOW_MANAGER:CreateControlFromVirtual("IIFA_ListItem_" .. i, parent, "IIFA_SlotTemplate")
line.icon = line:GetNamedChild("Button"):GetNamedChild("Icon")
line.text = line:GetNamedChild("Name")
line.qty = line:GetNamedChild("Qty")
line.worn = line:GetNamedChild("IconWorn")
line.wornCompanion = line:GetNamedChild("IconCompanionWorn")
line.stolen = line:GetNamedChild("IconStolen")
line:SetHidden(false)
line:SetMouseEnabled(true)
line:SetHeight(IIFA_GUI_ListHolder.rowHeight)
line.worn:ClearAnchors()
local wornPoint, wornRelativeTo, wornRelativePoint, wornOffsetX, wornOffsetY = GetAnchor(IIFA_DEFAULT_ANCHOR, IIFA_ANCHOR_EQUIPPED, line)
line.worn:SetAnchor(wornPoint, wornRelativeTo, wornRelativePoint, wornOffsetX, wornOffsetY)
line.wornCompanion:ClearAnchors()
local wornCompanionPoint, wornCompanionRelativeTo, wornCompanionRelativePoint, wornCompanionOffsetX, wornCompanionOffsetY = GetAnchor(IIFA_DEFAULT_ANCHOR, IIFA_ANCHOR_COMPANION_EQUIPPED, line)
line.wornCompanion:SetAnchor(wornCompanionPoint, wornCompanionRelativeTo, wornCompanionRelativePoint, wornCompanionOffsetX, wornCompanionOffsetY)
line.stolen:ClearAnchors()
local stolenPoint, stolenRelativeTo, stolenRelativePoint, stolenOffsetX, stolenOffsetY = GetAnchor(IIFA_DEFAULT_ANCHOR, IIFA_ANCHOR_STOLEN, line)
line.stolen:SetAnchor(stolenPoint, stolenRelativeTo, stolenRelativePoint, stolenOffsetX, stolenOffsetY)
if i == 1 then
line:SetAnchor(TOPLEFT, IIFA_GUI_ListHolder, TOPLEFT, 0, 0)
line:SetAnchor(TOPRIGHT, IIFA_GUI_ListHolder, TOPRIGHT, 0, 0)
else
line:SetAnchor(TOPLEFT, predecessor, BOTTOMLEFT, 0, 0)
line:SetAnchor(TOPRIGHT, predecessor, BOTTOMRIGHT, 0, 0)
end
line:SetHandler("OnMouseEnter", function(self) IIfA:GuiLineOnMouseEnter(self) end)
line:SetHandler("OnMouseExit", function(self) IIfA:GuiLineOnMouseExit(self) end)
line:SetHandler("OnMouseDoubleClick", function(...) IIfA:GUIDoubleClick(...) end)
return line
end
function IIfA:CreateInventoryScroll()
p("CreateInventoryScroll")
IIFA_GUI_ListHolder.dataOffset = 0
IIFA_GUI_ListHolder.dataLines = {}
IIFA_GUI_ListHolder.lines = {}
IIFA_GUI_Header_SortBar.Icon = IIFA_GUI_Header_SortBar:GetNamedChild("_Sort"):GetNamedChild("_Icon")
-- Set max lines to the amount that can be shown based on constraints
IIFA_GUI_ListHolder.maxLines = 35
local predecessor = nil
for i = 1, IIFA_GUI_ListHolder.maxLines do
IIFA_GUI_ListHolder.lines[i] = IIfA:CreateLine(i, predecessor, IIFA_GUI_ListHolder)