Back to Home

ESO Lua File v100028

ingame/inventory/inventory.lua

[◄ back to folders ]
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
--Variables
local g_playerInventory = nil
PLAYER_INVENTORY = nil
INVENTORY_BACKPACK = 1
INVENTORY_QUEST_ITEM = 2
INVENTORY_BANK = 3
INVENTORY_HOUSE_BANK = 4
INVENTORY_GUILD_BANK = 5
INVENTORY_CRAFT_BAG = 6
local SEARCH_TYPE_INVENTORY = 1
local SEARCH_TYPE_QUEST_ITEM = 2
local SEARCH_TYPE_QUEST_TOOL = 3
local CACHE_DATA = true
local DONT_CACHE_DATA = false
local DONT_USE_SHORT_FORMAT = false
local PREVENT_LAYOUT = false
local NOT_IS_GAMEPAD = false
local NEW_ICON_TEXTURE = "EsoUI/Art/Inventory/newItem_icon.dds"
local STOLEN_ICON_TEXTURE = "EsoUI/Art/Inventory/inventory_stolenItem_icon.dds"
BANKING_INTERACTION =
{
    type = "Banking",
    interactTypes = { INTERACTION_BANK },
}
GUILD_BANKING_INTERACTION =
{
    type = "GuildBanking",
    interactTypes = { INTERACTION_GUILDBANK },
}
-----------
--Callbacks
-----------
--tabs
local function HandleTabSwitch(tabData)
    g_playerInventory:ChangeFilter(tabData)
end
--Search Processors
local function GetInventoryItemInformation(bagId, slotIndex)
    local name = GetItemName(bagId, slotIndex)
    name = name:lower()
    local _, _, _, _, _, equipType, itemStyle = GetItemInfo(bagId, slotIndex)
    return name, equipType, itemStyle
end
local EQUIP_TYPE_NAMES = {}
local ITEM_STYLE_NAME = {}
local function ProcessInventoryItem(stringSearch, data, searchTerm, cache)
    local name, equipType, itemStyle = stringSearch:GetFromCache(data, cache, GetInventoryItemInformation, data.bagId, data.slotIndex)
    if(zo_plainstrfind(name, searchTerm)) then
        return true
    end
    if(equipType ~= EQUIP_TYPE_INVALID) then
        local equipTypeName = EQUIP_TYPE_NAMES[equipType]
        if(not equipTypeName) then
            equipTypeName = GetString("SI_EQUIPTYPE", equipType):lower()
            EQUIP_TYPE_NAMES[equipType] = equipTypeName
        end
        if(zo_plainstrfind(equipTypeName, searchTerm)) then
            return true
        end
    end
    if itemStyle ~= 0 then
        local itemStyleName = ITEM_STYLE_NAME[itemStyle]
        if not itemStyleName then
            itemStyleName = zo_strlower(GetItemStyleName(itemStyle))
            ITEM_STYLE_NAME[itemStyle] = itemStyleName
        end
        if zo_plainstrfind(itemStyleName, searchTerm) then
            return true
        end
    end
    return false
end
local function GetQuestItemInformation(questIndex, stepIndex, conditionIndex)
    local _, _, name = GetQuestItemInfo(questIndex, stepIndex, conditionIndex)
    name = name:lower()
    return name
end
local function ProcessQuestItem(stringSearch, data, searchTerm, cache)
    local name = stringSearch:GetFromCache(data, cache, GetQuestItemInformation, data.questIndex, data.stepIndex, data.conditionIndex)
    return zo_plainstrfind(name, searchTerm)
end
local function GetQuestToolInformation(questIndex, toolIndex)
    local _, _, _, name = GetQuestToolInfo(questIndex, toolIndex)
    name = name:lower()
    return name
end
local function ProcessQuestTool(stringSearch, data, searchTerm, cache)
    local name = stringSearch:GetFromCache(data, cache, GetQuestToolInformation, data.questIndex, data.toolIndex)
    return zo_plainstrfind(name, searchTerm)
end
-- Item List Sort management
local sortKeys =
{
    slotIndex = { isNumeric = true },
    stackCount = { tiebreaker = "slotIndex", isNumeric = true },
    name = { tiebreaker = "stackCount" },
    quality = { tiebreaker = "name", isNumeric = true },
    stackSellPrice = { tiebreaker = "name", tieBreakerSortOrder = ZO_SORT_ORDER_UP, isNumeric = true },
    statusSortOrder = { tiebreaker = "age", isNumeric = true},
    age = { tiebreaker = "name", tieBreakerSortOrder = ZO_SORT_ORDER_UP, isNumeric = true},
    traitInformationSortOrder = { tiebreaker = "name", isNumeric = true, tieBreakerSortOrder = ZO_SORT_ORDER_UP },
    sellInformationSortOrder = { tiebreaker = "name", isNumeric = true, tieBreakerSortOrder = ZO_SORT_ORDER_UP },
}
    return sortKeys
end
-- Item List Display management
local INVENTORY_DATA_TYPE_BACKPACK = 1
local INVENTORY_DATA_TYPE_QUEST = 2
local function InitializeInventoryList(inventory)
    local listView = inventory.listView
    if listView then
        ZO_ScrollList_Initialize(listView)
        ZO_ScrollList_AddDataType(listView, inventory.listDataType, inventory.rowTemplate, 52, inventory.listSetupCallback, inventory.listHiddenCallback, nil, ZO_InventorySlot_OnPoolReset)
        ZO_ScrollList_AddResizeOnScreenResize(listView)
    end
end
local function InitializeInventoryFilters(inventory)
    if(inventory.tabFilters) then
        local menuBar = inventory.filterBar
        for _, data in ipairs(inventory.tabFilters) do
            local filterButton = ZO_MenuBar_AddButton(menuBar, data)
            data.control = filterButton
            ZO_AlphaAnimation:New(GetControl(filterButton, "Flash"))
        end
    end
end
local function OnInventoryItemRowHidden(rowControl, slot)
    slot.slotControl = nil
end
function ZO_UpdateStatusControlIcons(inventorySlot, slotData)
    local statusControl = GetControl(inventorySlot, "StatusTexture")
    statusControl:ClearIcons()
    if slotData.brandNew then
        statusControl:AddIcon(NEW_ICON_TEXTURE)
    end
    if slotData.stolen then
        statusControl:AddIcon(STOLEN_ICON_TEXTURE)
    end
    if slotData.isPlayerLocked then
        statusControl:AddIcon(ZO_KEYBOARD_LOCKED_ICON)
    end
    if slotData.isBoPTradeable then
        statusControl:AddIcon(ZO_TRADE_BOP_ICON)
    end
    if slotData.isGemmable then
        statusControl:AddIcon(ZO_Currency_GetPlatformCurrencyIcon(CURT_CROWN_GEMS))
    end
    if slotData.bagId == BAG_WORN then
        statusControl:AddIcon(ZO_KEYBOARD_IS_EQUIPPED_ICON)
    end
    statusControl:Show()
    if slotData.age ~= 0 then
        slotData.clearAgeOnClose = true
    end
end
function ZO_UpdateTraitInformationControlIcon(inventorySlot, slotData)
    local traitInfoControl = GetControl(inventorySlot, "TraitInfo")
    traitInfoControl:ClearIcons()
    if slotData.traitInformation ~= ITEM_TRAIT_INFORMATION_NONE and not ZO_Store_IsShopping() then
        traitInfoControl:AddIcon(GetPlatformTraitInformationIcon(slotData.traitInformation))
        traitInfoControl:Show()
    end
end
function ZO_UpdateSellInformationControlIcon(inventorySlot, slotData)
    local sellInformationControl = GetControl(inventorySlot, "SellInformation")
    local sellInformationTexture = GetItemSellInformationIcon(slotData.sellInformation)
    if sellInformationTexture then
        sellInformationControl:SetTexture(sellInformationTexture)
        sellInformationControl:SetHidden(not ZO_Store_IsShopping())
    else
        sellInformationControl:SetHidden(true)
    end
end
ITEM_SLOT_CURRENCY_OPTIONS =
{
    showTooltips = false,
    font = "ZoFontGameShadow",
    iconSide = RIGHT,
}
local function GetDefaultSlotSellValue(slot)
    return (FENCE_MANAGER and SYSTEMS:GetObject("fence"):IsLaundering()) and slot.stackLaunderPrice or slot.stackSellPrice
end
local function SetupInventoryItemRow(rowControl, slot, overrideOptions)
    local options = overrideOptions or ITEM_SLOT_CURRENCY_OPTIONS
    local r, g, b = GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_QUALITY_COLORS, slot.quality)
    local nameControl = GetControl(rowControl, "Name")
    nameControl:SetText(slot.name) -- already formatted
    nameControl:SetColor(r, g, b, 1)
    local itemValue 
    if type(options.overrideSellValue) == "function" then
        itemValue = options.overrideSellValue(slot)
    else
        itemValue = GetDefaultSlotSellValue(slot)
    end
    local sellPriceControl = GetControl(rowControl, "SellPrice")
    sellPriceControl:SetHidden(false)
    ZO_CurrencyControl_SetSimpleCurrency(sellPriceControl, CURT_MONEY, itemValue, options)
    local inventorySlot = GetControl(rowControl, "Button")
    ZO_Inventory_BindSlot(inventorySlot, slot.inventory.slotType, slot.slotIndex, slot.bagId)
    ZO_PlayerInventorySlot_SetupSlot(rowControl, slot.stackCount, slot.iconFile, slot.meetsUsageRequirement, slot.locked or IsUnitDead("player"))
    slot.slotControl = rowControl
    ZO_UpdateStatusControlIcons(rowControl, slot)
    ZO_UpdateTraitInformationControlIcon(rowControl, slot)
    ZO_UpdateSellInformationControlIcon(rowControl, slot)
end
local function GetItemSlotSellValueWithBonus(slot)
    if FENCE_MANAGER and SYSTEMS:GetObject("fence"):IsSellingStolenItems() and FENCE_MANAGER:HasBonusToSellingStolenItems() then
        return GetItemSellValueWithBonuses(slot.bagId, slot.slotIndex) * slot.stackCount
    end
    return GetDefaultSlotSellValue(slot)
end
ITEM_BACKPACK_SLOT_CURRENCY_OPTIONS =
{
    showTooltips = false,
    font = "ZoFontGameShadow",
    iconSide = RIGHT,
}
local function SetupBackpackInventoryItemRow(rowControl, slot)
    SetupInventoryItemRow(rowControl, slot, ITEM_BACKPACK_SLOT_CURRENCY_OPTIONS)
end
local function SetupQuestRow(rowControl, questItem)
    local r, g, b = GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_TOOLTIP, ITEM_TOOLTIP_COLOR_QUEST_ITEM_NAME)
    local nameControl = GetControl(rowControl, "Name")
    nameControl:SetText(questItem.name) -- already formatted
    nameControl:SetColor(r, g, b, 1)
    GetControl(rowControl, "SellPrice"):SetHidden(true)
    local inventorySlot = GetControl(rowControl, "Button")
    ZO_InventorySlot_SetType(inventorySlot, SLOT_TYPE_QUEST_ITEM)
    questItem.slotControl = rowControl
    ZO_Inventory_SetupSlot(inventorySlot, questItem.stackCount, questItem.iconFile)
    ZO_Inventory_SetupQuestSlot(inventorySlot, questItem.questIndex, questItem.toolIndex, questItem.stepIndex, questItem.conditionIndex)
    ZO_UpdateStatusControlIcons(rowControl, questItem)
end
local function CreateNewTabFilterData(filterType, inventoryType, normal, pressed, highlight, hiddenColumns, hideTab)
    local filterString = GetString("SI_ITEMFILTERTYPE", filterType)
    local tabData = 
    {
        -- Custom data
        filterType = filterType,
        inventoryType = inventoryType,
        hiddenColumns = hiddenColumns,
        activeTabText = filterString,
        tooltipText = filterString,
        -- Menu bar data
        hidden = hideTab,
        ignoreVisibleCheck = hideTab == true,
        descriptor = filterType,
        normal = normal,
        pressed = pressed,
        highlight = highlight,
        callback = HandleTabSwitch,
    }
    return tabData
end
local function BaseInventoryFilter(currentFilter, slot)
    if(currentFilter ~= ITEMFILTERTYPE_JUNK and slot.isJunk) then return false end
    if(currentFilter == ITEMFILTERTYPE_JUNK and slot.isJunk) then return true end
    if(currentFilter == ITEMFILTERTYPE_ALL) then return true end
    for i = 1, #slot.filterData do
        if(slot.filterData[i] == currentFilter) then
            return true
        end
    end
    return false
end
-------------------
--Inventory Manager
-------------------
ZO_InventoryManager = ZO_Object:Subclass()
function ZO_InventoryManager:New(...)
    local manager = ZO_Object.New(self)
    manager:Initialize(...)
    return manager
end
function ZO_InventoryManager:Initialize(control)
    g_playerInventory = self
    self.selectedTabType = INVENTORY_BACKPACK
    local backpackSearch = ZO_StringSearch:New(CACHE_DATA)
    backpackSearch:AddProcessor(SEARCH_TYPE_INVENTORY, ProcessInventoryItem)
    local bankSearch = ZO_StringSearch:New(CACHE_DATA)
    bankSearch:AddProcessor(SEARCH_TYPE_INVENTORY, ProcessInventoryItem)
    local guildBankSearch = ZO_StringSearch:New(CACHE_DATA)
    guildBankSearch:AddProcessor(SEARCH_TYPE_INVENTORY, ProcessInventoryItem)
    local questItemSearch = ZO_StringSearch:New(CACHE_DATA)
    questItemSearch:AddProcessor(SEARCH_TYPE_QUEST_ITEM, ProcessQuestItem)
    questItemSearch:AddProcessor(SEARCH_TYPE_QUEST_TOOL, ProcessQuestTool)
    local craftBagSearch = ZO_StringSearch:New(CACHE_DATA)
    craftBagSearch:AddProcessor(SEARCH_TYPE_INVENTORY, ProcessInventoryItem)
    local typicalHiddenColumns =
    {
        ["traitInformationSortOrder"] = true,
        ["sellInformationSortOrder"] = true,
    }
    local questHiddenColumns =
    {
        ["traitInformationSortOrder"] = true,
        ["sellInformationSortOrder"] = true,
        ["statusSortOrder"] = true,
        ["stackSellPrice"] = true,
    }
    local gearHiddenColumns =
    {
        ["traitInformationSortOrder"] = function() return GetInteractionType() == INTERACTION_VENDOR end,
        ["sellInformationSortOrder"] = function() return GetInteractionType() ~= INTERACTION_VENDOR end,
    }
    local tradingHouseHiddenColumns =
    {
        ["statusSortOrder"] = true,
        ["sellInformationSortOrder"] = true,
    }
    local HIDE_TAB = true
    -- Need to define these in reverse order than how you want to display them
    local backpackFilters =
    {
        CreateNewTabFilterData(ITEMFILTERTYPE_JUNK, INVENTORY_BACKPACK, "EsoUI/Art/Inventory/inventory_tabIcon_junk_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_junk_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_junk_over.dds", gearHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_QUEST, INVENTORY_QUEST_ITEM, "EsoUI/Art/Inventory/inventory_tabIcon_quest_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_quest_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_quest_over.dds", questHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_MISCELLANEOUS, INVENTORY_BACKPACK, "EsoUI/Art/Inventory/inventory_tabIcon_misc_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_misc_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_misc_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_FURNISHING, INVENTORY_BACKPACK, "EsoUI/Art/Crafting/provisioner_indexIcon_furnishings_up.dds", "EsoUI/Art/Crafting/provisioner_indexIcon_furnishings_down.dds", "EsoUI/Art/Crafting/provisioner_indexIcon_furnishings_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_CRAFTING, INVENTORY_BACKPACK, "EsoUI/Art/Inventory/inventory_tabIcon_crafting_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_crafting_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_crafting_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_CONSUMABLE, INVENTORY_BACKPACK, "EsoUI/Art/Inventory/inventory_tabIcon_consumables_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_consumables_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_consumables_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_JEWELRY, INVENTORY_BACKPACK, "EsoUI/Art/Crafting/jewelry_tabIcon_icon_up.dds", "EsoUI/Art/Crafting/jewelry_tabIcon_down.dds", "EsoUI/Art/Crafting/jewelry_tabIcon_icon_over.dds", gearHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_ARMOR, INVENTORY_BACKPACK, "EsoUI/Art/Inventory/inventory_tabIcon_armor_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_armor_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_armor_over.dds", gearHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_WEAPONS, INVENTORY_BACKPACK, "EsoUI/Art/Inventory/inventory_tabIcon_weapons_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_weapons_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_weapons_over.dds", gearHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_ALL, INVENTORY_BACKPACK, "EsoUI/Art/Inventory/inventory_tabIcon_all_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_all_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_all_over.dds", gearHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_TRADING_HOUSE, INVENTORY_BACKPACK, "", "", "", tradingHouseHiddenColumns, HIDE_TAB),
    }
    local bankFilters =
    {
        CreateNewTabFilterData(ITEMFILTERTYPE_JUNK, INVENTORY_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_junk_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_junk_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_junk_over.dds", gearHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_MISCELLANEOUS, INVENTORY_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_misc_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_misc_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_misc_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_FURNISHING, INVENTORY_BANK, "EsoUI/Art/Crafting/provisioner_indexIcon_furnishings_up.dds", "EsoUI/Art/Crafting/provisioner_indexIcon_furnishings_down.dds", "EsoUI/Art/Crafting/provisioner_indexIcon_furnishings_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_CRAFTING, INVENTORY_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_crafting_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_crafting_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_crafting_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_CONSUMABLE, INVENTORY_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_consumables_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_consumables_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_consumables_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_JEWELRY, INVENTORY_BANK, "EsoUI/Art/Crafting/jewelry_tabIcon_icon_up.dds", "EsoUI/Art/Crafting/jewelry_tabIcon_down.dds", "EsoUI/Art/Crafting/jewelry_tabIcon_icon_over.dds", gearHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_ARMOR, INVENTORY_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_armor_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_armor_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_armor_over.dds", gearHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_WEAPONS, INVENTORY_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_weapons_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_weapons_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_weapons_over.dds", gearHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_ALL, INVENTORY_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_all_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_all_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_all_over.dds", gearHiddenColumns),
    }
    local houseBankFilters =
    {
        CreateNewTabFilterData(ITEMFILTERTYPE_JUNK, INVENTORY_HOUSE_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_junk_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_junk_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_junk_over.dds", gearHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_MISCELLANEOUS, INVENTORY_HOUSE_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_misc_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_misc_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_misc_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_FURNISHING, INVENTORY_HOUSE_BANK, "EsoUI/Art/Crafting/provisioner_indexIcon_furnishings_up.dds", "EsoUI/Art/Crafting/provisioner_indexIcon_furnishings_down.dds", "EsoUI/Art/Crafting/provisioner_indexIcon_furnishings_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_CRAFTING, INVENTORY_HOUSE_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_crafting_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_crafting_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_crafting_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_CONSUMABLE, INVENTORY_HOUSE_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_consumables_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_consumables_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_consumables_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_JEWELRY, INVENTORY_HOUSE_BANK, "EsoUI/Art/Crafting/jewelry_tabIcon_icon_up.dds", "EsoUI/Art/Crafting/jewelry_tabIcon_down.dds", "EsoUI/Art/Crafting/jewelry_tabIcon_icon_over.dds", gearHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_ARMOR, INVENTORY_HOUSE_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_armor_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_armor_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_armor_over.dds", gearHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_WEAPONS, INVENTORY_HOUSE_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_weapons_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_weapons_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_weapons_over.dds", gearHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_ALL, INVENTORY_HOUSE_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_all_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_all_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_all_over.dds", gearHiddenColumns),
    }
    local guildBankFilters =
    {
        CreateNewTabFilterData(ITEMFILTERTYPE_MISCELLANEOUS, INVENTORY_GUILD_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_misc_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_misc_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_misc_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_FURNISHING, INVENTORY_GUILD_BANK, "EsoUI/Art/Crafting/provisioner_indexIcon_furnishings_up.dds", "EsoUI/Art/Crafting/provisioner_indexIcon_furnishings_down.dds", "EsoUI/Art/Crafting/provisioner_indexIcon_furnishings_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_CRAFTING, INVENTORY_GUILD_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_crafting_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_crafting_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_crafting_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_CONSUMABLE, INVENTORY_GUILD_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_consumables_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_consumables_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_consumables_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_JEWELRY, INVENTORY_GUILD_BANK, "EsoUI/Art/Crafting/jewelry_tabIcon_icon_up.dds", "EsoUI/Art/Crafting/jewelry_tabIcon_down.dds", "EsoUI/Art/Crafting/jewelry_tabIcon_icon_over.dds", gearHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_ARMOR, INVENTORY_GUILD_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_armor_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_armor_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_armor_over.dds", gearHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_WEAPONS, INVENTORY_GUILD_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_weapons_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_weapons_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_weapons_over.dds", gearHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_ALL, INVENTORY_GUILD_BANK, "EsoUI/Art/Inventory/inventory_tabIcon_all_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_all_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_all_over.dds", gearHiddenColumns),
    }
    local craftBagFilters =
    {
        CreateNewTabFilterData(ITEMFILTERTYPE_TRAIT_ITEMS, INVENTORY_CRAFT_BAG, "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_itemTrait_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_itemTrait_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_itemTrait_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_STYLE_MATERIALS, INVENTORY_CRAFT_BAG, "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_styleMaterial_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_styleMaterial_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_styleMaterial_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_PROVISIONING, INVENTORY_CRAFT_BAG, "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_provisioning_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_provisioning_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_provisioning_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_ENCHANTING, INVENTORY_CRAFT_BAG, "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_enchanting_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_enchanting_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_enchanting_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_ALCHEMY, INVENTORY_CRAFT_BAG, "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_alchemy_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_alchemy_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_alchemy_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_JEWELRYCRAFTING, INVENTORY_CRAFT_BAG, "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_jewelrycrafting_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_jewelrycrafting_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_jewelrycrafting_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_WOODWORKING, INVENTORY_CRAFT_BAG, "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_woodworking_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_woodworking_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_woodworking_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_CLOTHING, INVENTORY_CRAFT_BAG, "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_clothing_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_clothing_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_clothing_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_BLACKSMITHING, INVENTORY_CRAFT_BAG, "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_blacksmithing_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_blacksmithing_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_Craftbag_blacksmithing_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_ALL, INVENTORY_CRAFT_BAG, "EsoUI/Art/Inventory/inventory_tabIcon_all_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_all_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_all_over.dds", typicalHiddenColumns),
    }
    local function BackpackAltFreeSlotType()
        if self:IsBanking() then 
            return self:GetBankInventoryType() 
        elseif self:IsGuildBanking() then
            return INVENTORY_GUILD_BANK
        else
            return nil  --hide label
        end
    end
    local inventories =
    {
        [INVENTORY_BACKPACK] =
        {
            stringSearch = backpackSearch,
            searchBox = ZO_PlayerInventorySearchBox,
            slotType = SLOT_TYPE_ITEM,
            backingBags = { BAG_BACKPACK },
            slots = { [BAG_BACKPACK] = {} },
            listView = ZO_PlayerInventoryList,
            listDataType = INVENTORY_DATA_TYPE_BACKPACK,
            listSetupCallback = SetupBackpackInventoryItemRow,
            listHiddenCallback = OnInventoryItemRowHidden,
            freeSlotsLabel = ZO_PlayerInventoryInfoBarFreeSlots,
            altFreeSlotsLabel = ZO_PlayerInventoryInfoBarAltFreeSlots,
            freeSlotType = INVENTORY_BACKPACK,
            altFreeSlotType = BackpackAltFreeSlotType,
            freeSlotsStringId = SI_INVENTORY_BACKPACK_REMAINING_SPACES,
            freeSlotsFullStringId = SI_INVENTORY_BACKPACK_COMPLETELY_FULL,
            currentSortKey = "statusSortOrder",
            currentSortOrder = ZO_SORT_ORDER_DOWN,
            currentFilter = ITEMFILTERTYPE_ALL,
            tabFilters = backpackFilters,
            filterBar = ZO_PlayerInventoryTabs,
            rowTemplate = "ZO_PlayerInventorySlot",
            activeTab = ZO_PlayerInventoryTabsActive,
            inventoryEmptyStringId = function(self)
                    if self:IsGuildBanking() then
                        local guildId = GetSelectedGuildBankId() 
                        if not DoesPlayerHaveGuildPermission(guildId, GUILD_PERMISSION_BANK_DEPOSIT) then
                            return GetString(SI_INVENTORY_ERROR_GUILD_BANK_NO_DEPOSIT_PERMISSIONS)
                        elseif not DoesGuildHavePrivilege(guildId, GUILD_PRIVILEGE_BANK_DEPOSIT) then
                            return zo_strformat(SI_INVENTORY_ERROR_GUILD_BANK_NO_DEPOSIT_PRIVILEGES, GetNumGuildMembersRequiredForPrivilege(GUILD_PRIVILEGE_BANK_DEPOSIT))
                        end
                    end
                    return GetString(SI_INVENTORY_ERROR_INVENTORY_EMPTY)
                end
        },
        [INVENTORY_QUEST_ITEM] =
        {
            slots = {},
            stringSearch = questItemSearch,
            searchBox = ZO_PlayerInventorySearchBox,
            slotType = SLOT_TYPE_QUEST_ITEM,
            listView = ZO_PlayerInventoryQuest,
            listDataType = INVENTORY_DATA_TYPE_QUEST,
            listSetupCallback = SetupQuestRow,
            listHiddenCallback = OnInventoryItemRowHidden,
            currentFilter = ITEMFILTERTYPE_ALL,
            currentSortKey = "name",
            currentSortOrder = ZO_SORT_ORDER_UP,
            rowTemplate = "ZO_PlayerInventorySlot",
            hiddenColumns = questHiddenColumns,
        },
        [INVENTORY_BANK] =
        {
            stringSearch = bankSearch,
            searchBox = ZO_PlayerBankSearchBox,
            slotType = SLOT_TYPE_BANK_ITEM,
            backingBags = { BAG_BANK, BAG_SUBSCRIBER_BANK },
            slots = { [BAG_BANK] = {}, [BAG_SUBSCRIBER_BANK] = {} },
            listView = ZO_PlayerBankBackpack,
            listDataType = INVENTORY_DATA_TYPE_BACKPACK,
            listSetupCallback = SetupInventoryItemRow,
            listHiddenCallback = OnInventoryItemRowHidden,
            freeSlotsLabel = ZO_PlayerBankInfoBarFreeSlots,
            altFreeSlotsLabel = ZO_PlayerBankInfoBarAltFreeSlots,
            freeSlotType = INVENTORY_BACKPACK,
            altFreeSlotType = INVENTORY_BANK,
            freeSlotsStringId = SI_INVENTORY_BANK_REMAINING_SPACES,
            freeSlotsFullStringId = SI_INVENTORY_BANK_COMPLETELY_FULL,
            currentSortKey = "name",
            currentSortOrder = ZO_SORT_ORDER_UP,
            currentFilter = ITEMFILTERTYPE_ALL,
            tabFilters = bankFilters,
            filterBar = ZO_PlayerBankTabs,
            rowTemplate = "ZO_PlayerInventorySlot",
            activeTab = ZO_PlayerBankTabsActive,
        },
        [INVENTORY_HOUSE_BANK] =
        {
            stringSearch = bankSearch,
            searchBox = ZO_HouseBankSearchBox,
            slotType = SLOT_TYPE_BANK_ITEM,
            --backing bags and slots are dynamically setup
            listView = ZO_HouseBankBackpack,
            listDataType = INVENTORY_DATA_TYPE_BACKPACK,
            listSetupCallback = SetupInventoryItemRow,
            listHiddenCallback = OnInventoryItemRowHidden,
            freeSlotsLabel = ZO_HouseBankInfoBarFreeSlots,
            altFreeSlotsLabel = ZO_HouseBankInfoBarAltFreeSlots,
            freeSlotType = INVENTORY_BACKPACK,
            altFreeSlotType = INVENTORY_HOUSE_BANK,
            freeSlotsStringId = SI_INVENTORY_HOUSE_BANK_REMAINING_SPACES,
            freeSlotsFullStringId = SI_INVENTORY_HOUSE_BANK_COMPLETELY_FULL,
            currentSortKey = "name",
            currentSortOrder = ZO_SORT_ORDER_UP,
            currentFilter = ITEMFILTERTYPE_ALL,
            tabFilters = houseBankFilters,
            filterBar = ZO_HouseBankTabs,
            rowTemplate = "ZO_PlayerInventorySlot",
            activeTab = ZO_HouseBankTabsActive,
        },
        [INVENTORY_GUILD_BANK] =
        {
            stringSearch = guildBankSearch,
            searchBox = ZO_GuildBankSearchBox,
            slotType = SLOT_TYPE_GUILD_BANK_ITEM,
            backingBags = { BAG_GUILDBANK },
            slots = { [BAG_GUILDBANK] = {} },
            listView = ZO_GuildBankBackpack,
            listDataType = INVENTORY_DATA_TYPE_BACKPACK,
            listSetupCallback = SetupInventoryItemRow,
            listHiddenCallback = OnInventoryItemRowHidden,
            freeSlotsLabel = ZO_GuildBankInfoBarFreeSlots,
            altFreeSlotsLabel = ZO_GuildBankInfoBarAltFreeSlots,
            freeSlotType = INVENTORY_BACKPACK,
            altFreeSlotType = INVENTORY_GUILD_BANK,
            freeSlotsStringId = SI_INVENTORY_BANK_REMAINING_SPACES,
            freeSlotsFullStringId = SI_INVENTORY_BANK_COMPLETELY_FULL,
            currentSortKey = "name",
            currentSortOrder = ZO_SORT_ORDER_UP,
            currentFilter = ITEMFILTERTYPE_ALL,
            tabFilters = guildBankFilters,
            filterBar = ZO_GuildBankTabs,
            rowTemplate = "ZO_PlayerInventorySlot",
            activeTab = ZO_GuildBankTabsActive,
            inventoryEmptyStringId = function(self) 
                return GetString(SI_INVENTORY_ERROR_GUILD_BANK_EMPTY)
            end
        },
        [INVENTORY_CRAFT_BAG] =
        {
            stringSearch = craftBagSearch,
            searchBox = ZO_CraftBagSearchBox,
            slotType = SLOT_TYPE_CRAFT_BAG_ITEM,
            backingBags = { BAG_VIRTUAL },
            slots = { [BAG_VIRTUAL] = {} },
            listView = ZO_CraftBagList,
            listDataType = INVENTORY_DATA_TYPE_BACKPACK,
            listSetupCallback = SetupBackpackInventoryItemRow,
            listHiddenCallback = OnInventoryItemRowHidden,
            currentSortKey = "statusSortOrder",
            currentSortOrder = ZO_SORT_ORDER_DOWN,
            currentFilter = ITEMFILTERTYPE_ALL,
            tabFilters = craftBagFilters,
            filterBar = ZO_CraftBagTabs,
            rowTemplate = "ZO_CraftBagSlot",
            activeTab = ZO_CraftBagTabsActive,
            inventoryEmptyStringId = SI_INVENTORY_ERROR_CRAFT_BAG_EMPTY,
        },
    }
    self.isListDirty = {}
    self:InitializeHeaderSort(INVENTORY_BACKPACK, inventories[INVENTORY_BACKPACK], ZO_PlayerInventorySortBy)
    self:InitializeHeaderSort(INVENTORY_BANK, inventories[INVENTORY_BANK], ZO_PlayerBankSortBy)
    self:InitializeHeaderSort(INVENTORY_HOUSE_BANK, inventories[INVENTORY_HOUSE_BANK], ZO_HouseBankSortBy)
    self:InitializeHeaderSort(INVENTORY_GUILD_BANK, inventories[INVENTORY_GUILD_BANK], ZO_GuildBankSortBy)
    self:InitializeHeaderSort(INVENTORY_CRAFT_BAG, inventories[INVENTORY_CRAFT_BAG], ZO_CraftBagSortBy)
    self.inventories = inventories
    self.searchToInventoryType = {}
    self.bagToInventoryType =
    {
        [BAG_BACKPACK] = INVENTORY_BACKPACK,
        [BAG_BANK] = INVENTORY_BANK,
        [BAG_SUBSCRIBER_BANK] = INVENTORY_BANK,
        [BAG_GUILDBANK] = INVENTORY_GUILD_BANK,
        [BAG_VIRTUAL] = INVENTORY_CRAFT_BAG,
    }
    for i = BAG_HOUSE_BANK_ONE, BAG_HOUSE_BANK_TEN do
        self.bagToInventoryType[i] = INVENTORY_HOUSE_BANK
    end
    for inventoryType, inventoryData in pairs(self.inventories) do
        InitializeInventoryList(inventoryData)
        InitializeInventoryFilters(inventoryData)
        self.searchToInventoryType[inventoryData.stringSearch] = inventoryType
    end
    INVENTORY_FRAGMENT = ZO_FadeSceneFragment:New(ZO_PlayerInventory)
    INVENTORY_FRAGMENT:RegisterCallback("StateChange", function(oldState, newState)
        if(newState == SCENE_FRAGMENT_SHOWING) then
            local UPDATE_EVEN_IF_HIDDEN = true
            if self.isListDirty[INVENTORY_BACKPACK] or self.isListDirty[INVENTORY_QUEST_ITEM] then
                self:UpdateList(INVENTORY_BACKPACK, UPDATE_EVEN_IF_HIDDEN)
                self:UpdateList(INVENTORY_QUEST_ITEM, UPDATE_EVEN_IF_HIDDEN)
            end
            self:RefreshMoney()
            self:UpdateFreeSlots(INVENTORY_BACKPACK)
            self:UpdateApparelSection()
            --Reseting the comparison stats here since its too later when the window is already hidden.
        elseif(newState == SCENE_FRAGMENT_HIDDEN) then
            ZO_InventorySlot_RemoveMouseOverKeybinds()
            ZO_PlayerInventory_EndSearch(ZO_PlayerInventorySearchBox)
            self:ClearNewStatusOnItemsThePlayerHasSeen(INVENTORY_BACKPACK)
        end
    end)
    SHARED_INVENTORY:RegisterCallback("SlotAdded", function(bagId, slotIndex, newSlotData) 
        local inventory = self.bagToInventoryType[bagId]
        if inventory then
            self:OnInventoryItemAdded(inventory, bagId, slotIndex, newSlotData) 
        end
    end)
    SHARED_INVENTORY:RegisterCallback("SlotRemoved", function(bagId, slotIndex, oldSlotData) 
        local inventory = self.bagToInventoryType[bagId]
        if inventory then
            self:OnInventoryItemRemoved(inventory, bagId, slotIndex, oldSlotData)
        end
    end)
    self.itemsLockedDueToDeath = IsUnitDead("player")
    self:RefreshAllInventorySlots(INVENTORY_BACKPACK)
    self:RefreshAllInventorySlots(INVENTORY_CRAFT_BAG)
    self:RefreshAllInventorySlots(INVENTORY_BANK)
    self:RefreshMoney()
end
function ZO_InventoryManager:InitializeHeaderSort(inventoryType, inventory, headerControl)
    local sortHeaders = ZO_SortHeaderGroup:New(headerControl, true)
    local function OnSortHeaderClicked(key, order)
        self:ChangeSort(key, inventoryType, order)
    end
    sortHeaders:RegisterCallback(ZO_SortHeaderGroup.HEADER_CLICKED, OnSortHeaderClicked)
    sortHeaders:AddHeadersFromContainer()
    sortHeaders:SelectHeaderByKey(inventory.currentSortKey, ZO_SortHeaderGroup.SUPPRESS_CALLBACKS)
    inventory.sortHeaders = sortHeaders
end
do
    local function OnRequestDestroyItem(eventCode, bag, slot, itemCount, name, needsConfirm)
        local _, actualItemCount = GetItemInfo(bag, slot)
        if itemCount == 0 and actualItemCount > 1 then
            itemCount = actualItemCount
        end
        local quality = GetItemQuality(bag, slot)
        local coloredItemName = GetItemQualityColor(quality):Colorize(name)
        if(needsConfirm) then
            local dialogName = "CONFIRM_DESTROY_ITEM_PROMPT"
            if IsInGamepadPreferredMode() then
                dialogName = ZO_GAMEPAD_CONFIRM_DESTROY_DIALOG
            end
            ZO_Dialogs_ShowPlatformDialog(dialogName, nil, {mainTextParams = {coloredItemName, itemCount, GetString(SI_DESTROY_ITEM_CONFIRMATION)}})
        else
            ZO_Dialogs_ShowPlatformDialog("DESTROY_ITEM_PROMPT", nil, {mainTextParams = {coloredItemName, itemCount}})
        end
    end
    local function OnCancelRequestDestroyItem()
        ZO_Dialogs_ReleaseDialog("DESTROY_ITEM_PROMPT")
        ZO_Dialogs_ReleaseDialog("CONFIRM_DESTROY_ITEM_PROMPT")
    end
    BUY_BAG_SPACE_INTERACTION =
    {
        type = "Buy Bag Space",
        interactTypes = { INTERACTION_BUY_BAG_SPACE },
    }
    local function OnBuyBagSpace(eventCode, cost)
        if IsInGamepadPreferredMode() then
            BUY_BAG_SPACE_GAMEPAD:Show(cost)
        else
            if(not ZO_Dialogs_FindDialog("BUY_BAG_SPACE")) then
                ZO_Dialogs_ShowDialog("BUY_BAG_SPACE", {cost = cost})
                INTERACT_WINDOW:OnBeginInteraction(BUY_BAG_SPACE_INTERACTION)
            end
        end
    end
    local function OnBuyBankSpace(eventCode, cost)
         if IsInGamepadPreferredMode() then
            BUY_BANK_SPACE_GAMEPAD:Show(cost)
        else
            if(not ZO_Dialogs_FindDialog("BUY_BANK_SPACE")) then
                ZO_Dialogs_ShowDialog("BUY_BANK_SPACE", {cost = cost})
            end
        end
    end
    local function OnCloseBuySpace()
        ZO_Dialogs_ReleaseDialog("BUY_BAG_SPACE")
        ZO_Dialogs_ReleaseDialog("BUY_BANK_SPACE")
        BUY_BAG_SPACE_GAMEPAD:Hide()
    end
    local function HandleCursorPickup(eventCode, cursorType, unused1, unused2, unused3, unused4, unused5, unused6, itemSoundCategory)
        if cursorType == MOUSE_CONTENT_INVENTORY_ITEM or cursorType == MOUSE_CONTENT_EQUIPPED_ITEM or cursorType == MOUSE_CONTENT_QUEST_ITEM then
            ZO_InventoryLandingArea_SetHidden(ZO_PlayerBankBackpackLandingArea, false, SI_INVENTORY_LANDING_AREA_MOVE_TO_BANK)
            ZO_InventoryLandingArea_SetHidden(ZO_PlayerInventoryListLandingArea, false, SI_INVENTORY_LANDING_AREA_MOVE_TO_BACKPACK)
        elseif cursorType == MOUSE_CONTENT_STORE_ITEM then
            ZO_InventoryLandingArea_SetHidden(ZO_PlayerInventoryListLandingArea, false, SI_INVENTORY_LANDING_AREA_BUY_ITEM)
        elseif cursorType == MOUSE_CONTENT_STORE_BUYBACK_ITEM then
            ZO_InventoryLandingArea_SetHidden(ZO_PlayerInventoryListLandingArea, false, SI_INVENTORY_LANDING_AREA_BUYBACK_ITEM)
        end
        PlayItemSound(itemSoundCategory, ITEM_SOUND_ACTION_PICKUP)
    end
    local function HandleCursorCleared(eventCode, oldCursorType)
        ZO_InventoryLandingArea_SetHidden(ZO_PlayerBankBackpackLandingArea, true)
        ZO_InventoryLandingArea_SetHidden(ZO_PlayerInventoryListLandingArea, true)
    end
    function ZO_InventoryManager:RegisterForEvents(control)
        control:RegisterForEvent(EVENT_VISUAL_LAYER_CHANGED, function() self:UpdateApparelSection() end)
    
        --inventory events
        local function OnFullInventoryUpdated(bagId)
            if bagId == BAG_BANK then
                self:RefreshBankUpgradeKeybind()
            end
            for inventoryType, inventory in pairs(self.inventories) do
                if inventory.backingBags then
                    for searchBagIndex, searchBagId in ipairs(inventory.backingBags) do
                        if searchBagId == bagId then
                            self:RefreshAllInventorySlots(inventoryType)
                            break
                        end
                    end
                end
            end
        end
    
        local function OnPlayerActivated()
            self:RefreshAllInventorySlots(INVENTORY_BACKPACK)
            self:RefreshAllInventorySlots(INVENTORY_CRAFT_BAG)
        end
    
        local function RefreshMoney()
            self:RefreshMoney()
        end
        SHARED_INVENTORY:RegisterCallback("FullInventoryUpdate", OnFullInventoryUpdated)
        SHARED_INVENTORY:RegisterCallback("SingleSlotInventoryUpdate", function(bagId, slotIndex) self:OnInventorySlotUpdated(bagId, slotIndex) end)
        control:RegisterForEvent(EVENT_INVENTORY_SLOT_LOCKED, function(event, bagId, slotIndex) self:OnInventorySlotLocked(bagId, slotIndex) end)
        control:RegisterForEvent(EVENT_INVENTORY_SLOT_UNLOCKED, function(event, bagId, slotIndex) self:OnInventorySlotUnlocked(bagId, slotIndex) end)
        control:RegisterForEvent(EVENT_MOUSE_REQUEST_DESTROY_ITEM, OnRequestDestroyItem)
        control:RegisterForEvent(EVENT_CANCEL_MOUSE_REQUEST_DESTROY_ITEM, OnCancelRequestDestroyItem)
        control:RegisterForEvent(EVENT_CURSOR_PICKUP, HandleCursorPickup)
        control:RegisterForEvent(EVENT_CURSOR_DROPPED, HandleCursorCleared)
        control:RegisterForEvent(EVENT_PLAYER_ACTIVATED, OnPlayerActivated)
        control:RegisterForEvent(EVENT_MONEY_UPDATE, RefreshMoney)
        control:RegisterForEvent(EVENT_BANKED_MONEY_UPDATE, RefreshMoney)
        control:RegisterForEvent(EVENT_GUILD_BANKED_MONEY_UPDATE, RefreshMoney)
        --quest item events
        local function OnQuestsUpdated()
            --the quest we were planning to abandon may be gone, kill the prompt
            ZO_Dialogs_ReleaseDialog("ABANDON_QUEST")
            self:RefreshAllQuests()
            CALLBACK_MANAGER:FireCallbacks("QuestUpdate")
        end
        local function OnSingleQuestUpdated(journalIndex)
            self:RefreshQuest(journalIndex)
            CALLBACK_MANAGER:FireCallbacks("QuestUpdate")
        end
        local function OnUpdateCooldowns()
            self:UpdateItemCooldowns(INVENTORY_BACKPACK)
            self:UpdateItemCooldowns(INVENTORY_QUEST_ITEM)
        end
        SHARED_INVENTORY:RegisterCallback("FullQuestUpdate", OnQuestsUpdated)
        SHARED_INVENTORY:RegisterCallback("SingleQuestUpdate", OnSingleQuestUpdated)
        control:RegisterForEvent(EVENT_ACTION_UPDATE_COOLDOWNS, OnUpdateCooldowns)
        --bank events
        local function OnOpenBank()
            if not IsInGamepadPreferredMode() then
                local inventoryType = self:GetBankInventoryType()
                if inventoryType == INVENTORY_BANK then
                    SCENE_MANAGER:Show("bank")
                elseif inventoryType == INVENTORY_HOUSE_BANK then
                    SCENE_MANAGER:Show("houseBank")
                end
            end
        end
        local function OnCloseBank()
            if not IsInGamepadPreferredMode() then
                --The banking bag has already been cleared by this point so just close both of the possible scenes instead of trying to figure out which one was open
                SCENE_MANAGER:Hide("bank")
                SCENE_MANAGER:Hide("houseBank")
                if ZO_Dialogs_IsShowingDialog() then
                    ZO_Dialogs_ReleaseAllDialogs()
                end
            end
        end
        control:RegisterForEvent(EVENT_OPEN_BANK, OnOpenBank)
        control:RegisterForEvent(EVENT_CLOSE_BANK, OnCloseBank)
        --guild bank events
        local function OnOpenGuildBank()
            if not IsInGamepadPreferredMode() then
                self:OpenGuildBank()
            end
        end
        local function OnCloseGuildBank()
            if not IsInGamepadPreferredMode() then
                self:CloseGuildBank()
            end
        end
        local function OnGuildBankSelected(eventCode, guildId)
            self:SetGuildBankLoading(guildId)
        end
        local function OnGuildBankDeselected()
            self:OnGuildBankDeselected()
        end
        local function OnGuildBankItemsReady()
            self:SetGuildBankLoaded()
        end
        local function OnGuildBankOpenError(eventCode, error)
            self:OnGuildBankOpenError(error)
        end
        local function OnGuildSizeChanged()
            self:GuildSizeChanged()
        end
        local function OnGuildRanksChanged(eventCode, guildId)
            self:RefreshGuildBankPermissions(guildId)
        end
        local function OnGuildRankChanged(eventCode, guildId)
            self:RefreshGuildBankPermissions(guildId)
        end
        local function OnGuildMemberRankChanged(eventCode, guildId, displayName)
            if(displayName == GetDisplayName()) then
                self:RefreshGuildBankPermissions(guildId)
            end
        end
        control:RegisterForEvent(EVENT_OPEN_GUILD_BANK, OnOpenGuildBank)
        control:RegisterForEvent(EVENT_CLOSE_GUILD_BANK, OnCloseGuildBank)
        control:RegisterForEvent(EVENT_GUILD_BANK_SELECTED, OnGuildBankSelected)
        control:RegisterForEvent(EVENT_GUILD_BANK_DESELECTED, OnGuildBankDeselected)
        control:RegisterForEvent(EVENT_GUILD_BANK_ITEMS_READY, OnGuildBankItemsReady)
        control:RegisterForEvent(EVENT_GUILD_BANK_OPEN_ERROR, OnGuildBankOpenError)
        control:RegisterForEvent(EVENT_GUILD_RANKS_CHANGED, OnGuildRanksChanged)
        control:RegisterForEvent(EVENT_GUILD_RANK_CHANGED, OnGuildRankChanged)
        control:RegisterForEvent(EVENT_GUILD_MEMBER_RANK_CHANGED, OnGuildMemberRankChanged)
        control:RegisterForEvent(EVENT_GUILD_MEMBER_ADDED, OnGuildSizeChanged)
        control:RegisterForEvent(EVENT_GUILD_MEMBER_REMOVED, OnGuildSizeChanged)
        --inventory upgrade events
        local function UpdateFreeSlotsBackpack()
            self:UpdateFreeSlots(INVENTORY_BACKPACK)
        end
        local function UpdateFreeSlotsBank()
            self:UpdateFreeSlots(INVENTORY_BANK)
        end
        control:RegisterForEvent(EVENT_INVENTORY_BUY_BAG_SPACE, OnBuyBagSpace)
        control:RegisterForEvent(EVENT_INVENTORY_BOUGHT_BAG_SPACE, UpdateFreeSlotsBackpack)
        control:RegisterForEvent(EVENT_MOUNT_INFO_UPDATED, UpdateFreeSlotsBackpack)
        control:RegisterForEvent(EVENT_INVENTORY_BUY_BANK_SPACE, OnBuyBankSpace)
        control:RegisterForEvent(EVENT_INVENTORY_BOUGHT_BANK_SPACE, UpdateFreeSlotsBank)
        control:RegisterForEvent(EVENT_INVENTORY_CLOSE_BUY_SPACE, OnCloseBuySpace)
        --player events
        local function RefreshAllInventoryOverlays()
            self:RefreshAllInventoryOverlays(INVENTORY_BACKPACK)
        end
        local function OnPlayerDead()
            RefreshAllInventoryOverlays()
            self.itemsLockedDueToDeath = true
        end
        local function OnPlayerAlive()
            RefreshAllInventoryOverlays()
            self.itemsLockedDueToDeath = false
        end
        control:RegisterForEvent(EVENT_PLAYER_DEAD, OnPlayerDead)
        control:RegisterForEvent(EVENT_PLAYER_ALIVE, OnPlayerAlive)
        control:RegisterForEvent(EVENT_LEVEL_UPDATE, RefreshAllInventoryOverlays)
        control:AddFilterForEvent(EVENT_LEVEL_UPDATE, REGISTER_FILTER_UNIT_TAG, "player")
        control:RegisterForEvent(EVENT_CHAMPION_POINT_GAINED, RefreshAllInventoryOverlays)
    end
end
--General
---------
--Selects a filter tab in this inventory type and then sorts by a key that appears under that filter tab
function ZO_InventoryManager:SelectAndChangeSort(inventoryType, tabFilterType, newSortKey, newSortOrder)
    local inventoryInfo = self.inventories[inventoryType]
    if inventoryInfo then
        local tabFilter
        for _, searchTabFilter in ipairs(inventoryInfo.tabFilters) do
            if searchTabFilter.filterType == tabFilterType then
                tabFilter = searchTabFilter
                break
            end
        end
        if tabFilter then
            self:ChangeFilter(tabFilter)
            --The sort headers change based on the selected tab filter
            inventoryInfo.sortHeaders:SelectHeaderByKey(newSortKey, ZO_SortHeaderGroup.SUPPRESS_CALLBACKS, not ZO_SortHeaderGroup.FORCE_RESELECT, newSortOrder)
            self:ChangeSort(newSortKey, inventoryType, newSortOrder)
        end
    end
end
function ZO_InventoryManager:ChangeSort(newSortKey, inventoryType, newSortOrder)
    if self.selectedTabType == INVENTORY_QUEST_ITEM then
        inventoryType = INVENTORY_QUEST_ITEM
    end
    local inventory = self.inventories[inventoryType]
    inventory.currentSortKey = newSortKey
    inventory.currentSortOrder = newSortOrder
    inventory.lastSavedSortKey = nil
    inventory.lastSavedSortOrder = nil
    self:ApplySort(inventoryType)
end
function ZO_InventoryManager:ApplySort(inventoryType)
    local inventory
    if inventoryType == INVENTORY_BANK then
        inventory = self.inventories[INVENTORY_BANK]
    elseif inventoryType == INVENTORY_HOUSE_BANK then
        inventory = self.inventories[INVENTORY_HOUSE_BANK]
    elseif inventoryType == INVENTORY_GUILD_BANK then
        inventory = self.inventories[INVENTORY_GUILD_BANK]
    elseif inventoryType == INVENTORY_CRAFT_BAG then
        inventory = self.inventories[INVENTORY_CRAFT_BAG]
    else
        -- Use normal inventory by default (instead of the quest item inventory for example)
        inventory = self.inventories[self.selectedTabType]
    end
    local list = inventory.listView
    local scrollData = ZO_ScrollList_GetDataList(list)
    if inventory.sortFn == nil then
        inventory.sortFn =  function(entry1, entry2)
                                return ZO_TableOrderingFunction(entry1.data, entry2.data, inventory.currentSortKey, sortKeys, inventory.currentSortOrder)
                            end
    end
    table.sort(scrollData, inventory.sortFn)
end
-- Utility function to basically remap quest_item inventory to the backpack inventory because the backpack inventory
-- is what stores all the display-type data.
function ZO_InventoryManager:GetDisplayInventoryTable(inventoryType)
    inventoryType = (inventoryType == INVENTORY_QUEST_ITEM) and INVENTORY_BACKPACK or inventoryType
    return self.inventories[inventoryType]
end
function ZO_InventoryManager:GetTabFilterInfo(inventoryType, tabControl)
    local inventory = self:GetDisplayInventoryTable(inventoryType)
    local filterData = inventory.tabFilters[tabControl] or tabControl -- the or tabControl is for the new style, because the data table is just passed in here
    return filterData.filterType, filterData.activeTabText, filterData.hiddenColumns
end
do
    local function ForceSortDataOnInventory(inventory, sortKey, sortOrder)
        inventory.currentSortKey = sortKey
        inventory.currentSortOrder = sortOrder
    end
    function ZO_InventoryManager:ChangeFilter(filterTab)
        -- special case inventory list hiding based on selecting quest inventory
        -- bank filters don't mess with the visibility of the regular inventory
        if filterTab.descriptor == ITEMFILTERTYPE_QUEST then
            ZO_PlayerInventoryList:SetHidden(true)
            ZO_PlayerInventoryQuest:SetHidden(false)
            self.selectedTabType = INVENTORY_QUEST_ITEM
        end
        if filterTab.inventoryType == INVENTORY_BACKPACK then
            ZO_PlayerInventoryList:SetHidden(false)
            ZO_PlayerInventoryQuest:SetHidden(true)
            self.selectedTabType = INVENTORY_BACKPACK
        end
        local inventoryType = filterTab.inventoryType
        local inventory = self.inventories[inventoryType]
        local activeTabText
        inventory.currentFilter, activeTabText, inventory.hiddenColumns = self:GetTabFilterInfo(inventoryType, filterTab)
        local displayInventory = self:GetDisplayInventoryTable(inventoryType)
        local activeTabControl = displayInventory.activeTab
        if(activeTabControl) then
            activeTabControl:SetText(activeTabText)
        end
        -- Manage hiding columns that show/hide depending on the current filter. If the sort was on a column that becomes hidden
        -- then the sort needs to pick a new column.
        local sortHeaders = displayInventory.sortHeaders
        if sortHeaders then
            sortHeaders:SetHeadersHiddenFromKeyList(inventory.hiddenColumns, true)
            
            local canUseLastSavedSortKey = inventory.lastSavedSortKey and inventory.hiddenColumns[inventory.lastSavedSortKey]
            if type(canUseLastSavedSortKey) == "function" then
                canUseLastSavedSortKey = canUseLastSavedSortKey()
            end
            local canUseCurrentSortKey = inventory.hiddenColumns[inventory.currentSortKey]
            if canUseCurrentSortKey and type(canUseCurrentSortKey) == "function" then
                canUseCurrentSortKey = canUseCurrentSortKey()
            end
            if inventory.lastSavedSortKey and not canUseLastSavedSortKey then
                -- Restore the last saved value if the header exists again
                local lastSavedSortKey = inventory.lastSavedSortKey
                local lastSavedSortOrder = inventory.lastSavedSortOrder
                sortHeaders:SelectHeaderByKey(lastSavedSortKey, ZO_SortHeaderGroup.SUPPRESS_CALLBACKS, ZO_SortHeaderGroup.FORCE_RESELECT, lastSavedSortOrder)
                ForceSortDataOnInventory(inventory, lastSavedSortKey, lastSavedSortOrder)
                ForceSortDataOnInventory(displayInventory, lastSavedSortKey, lastSavedSortOrder)
                inventory.lastSavedSortKey = nil
                inventory.lastSavedSortOrder = nil
            elseif canUseCurrentSortKey then
                inventory.lastSavedSortKey = inventory.currentSortKey
                inventory.lastSavedSortOrder = inventory.currentSortOrder
                -- User wanted to sort by a column that's gone!
                -- Fallback to name...the default sort is "statusSortOrder", but there are filters that hide that one, so "name" is the
                -- only safe bet for now...
                sortHeaders:SelectHeaderByKey("name", ZO_SortHeaderGroup.SUPPRESS_CALLBACKS)
                -- Switch both inventory and displayInventory to the fallback
                ForceSortDataOnInventory(inventory, "name", ZO_SORT_ORDER_UP)
                ForceSortDataOnInventory(displayInventory, "name", ZO_SORT_ORDER_UP)
            else
                -- This is mostly for when in backpack inventory and we select on/off the quest item filter
                -- since the sort header object only knows of backpack but inventories have different sort values
                sortHeaders:SelectHeaderByKey(inventory.currentSortKey, ZO_SortHeaderGroup.SUPPRESS_CALLBACKS, ZO_SortHeaderGroup.FORCE_RESELECT, inventory.currentSortOrder)
            end
        end
        ZO_ScrollList_ResetToTop(inventory.listView)
        self:UpdateList(inventoryType)
        if inventoryType == INVENTORY_BACKPACK and INVENTORY_MENU_BAR then
            INVENTORY_MENU_BAR:UpdateInventoryKeybinds()
        end
        local isEmptyList = not ZO_ScrollList_HasVisibleData(inventory.listView)
        self:UpdateEmptyBagLabel(inventoryType, isEmptyList)
    end
end
--Bag Window
------------
function ZO_InventoryManager:UpdateSortOrderButtonTextures(sortButton, inventoryType)
    local inventory = self.inventories[inventoryType]
    if inventory.currentSortOrder == ZO_SORT_ORDER_UP then
        sortButton:SetNormalTexture("EsoUI/Art/WorldMap/mapNav_upArrow_up.dds")
        sortButton:SetMouseOverTexture("EsoUI/Art/Buttons/ESO_buttonLarge_mouseOver.dds")
        sortButton:SetPressedTexture("EsoUI/Art/WorldMap/mapNav_upArrow_down.dds")
    else
        sortButton:SetNormalTexture("EsoUI/Art/WorldMap/mapNav_downArrow_up.dds")
        sortButton:SetMouseOverTexture("EsoUI/Art/Buttons/ESO_buttonLarge_mouseOver.dds")
        sortButton:SetPressedTexture("EsoUI/Art/WorldMap/mapNav_downArrow_down.dds")
    end
end
function ZO_InventoryManager:ToggleSortOrder(sortButton, inventoryType)
    local inventory = self.inventories[inventoryType]
    inventory.currentSortOrder = not inventory.currentSortOrder
    if inventoryType == INVENTORY_BACKPACK then
        self.inventories[INVENTORY_QUEST_ITEM].currentSortOrder = inventory.currentSortOrder
    end
    self:UpdateSortOrderButtonTextures(sortButton, inventoryType)
    self:ApplySort(inventoryType)
end
function ZO_InventoryManager:ShowToggleSortOrderTooltip(anchorControl, inventoryType)
    InitializeTooltip(InformationTooltip, anchorControl, TOPRIGHT, 0, 0)
    -- Show the opposite string of the current sort order because that's what will happen when the button is clicked
    if(self.inventories[inventoryType].currentSortOrder == ZO_SORT_ORDER_UP) then
        SetTooltipText(InformationTooltip, GetString(SI_INVENTORY_SORT_DESCENDING_TOOLTIP))
    else
        SetTooltipText(InformationTooltip, GetString(SI_INVENTORY_SORT_ASCENDING_TOOLTIP))
    end
end
function ZO_InventoryManager:HideToggleSortOrderTooltip()
    ClearTooltip(InformationTooltip)
end
do
    local DONT_SHOW_ALL = false
    local HAS_ENOUGH = false
    function ZO_InventoryManager:RefreshMoney()
        local moneyBar, altMoneyBar = self:GetContextualMoneyControls()
        if self:IsBanking() then
            self:RefreshBankUpgradeKeybind()
            ZO_CurrencyControl_SetSimpleCurrency(moneyBar, CURT_MONEY, GetCurrencyAmount(CURT_MONEY, CURRENCY_LOCATION_CHARACTER), ZO_KEYBOARD_CURRENCY_BANK_TOOLTIP_OPTIONS)
            if self:GetBankInventoryType() == INVENTORY_BANK then
                ZO_CurrencyControl_SetSimpleCurrency(altMoneyBar, CURT_MONEY, GetCurrencyAmount(CURT_MONEY, CURRENCY_LOCATION_BANK), ZO_KEYBOARD_CURRENCY_BANK_TOOLTIP_OPTIONS)
            end
        elseif self:IsGuildBanking() then
            ZO_CurrencyControl_SetSimpleCurrency(moneyBar, CURT_MONEY, GetCurrencyAmount(CURT_MONEY, CURRENCY_LOCATION_CHARACTER), ZO_KEYBOARD_CURRENCY_GUILD_BANK_TOOLTIP_OPTIONS)
            local displayOptions =
                {
                    obfuscateAmount = not DoesPlayerHaveGuildPermission(GetSelectedGuildBankId(), GUILD_PERMISSION_BANK_VIEW_GOLD),
                }
            ZO_CurrencyControl_SetSimpleCurrency(altMoneyBar, CURT_MONEY, GetCurrencyAmount(CURT_MONEY, CURRENCY_LOCATION_GUILD_BANK), ZO_KEYBOARD_CURRENCY_GUILD_BANK_TOOLTIP_OPTIONS, DONT_SHOW_ALL, HAS_ENOUGH, displayOptions)
        else
            ZO_CurrencyControl_SetSimpleCurrency(moneyBar, CURT_MONEY, GetCurrencyAmount(CURT_MONEY, CURRENCY_LOCATION_CHARACTER), ZO_KEYBOARD_CURRENCY_OPTIONS)
        end
    end
end
function ZO_InventoryManager:UpdateFreeSlots(inventoryType)
    local inventory = self.inventories[inventoryType]
    local freeSlotType
    local altFreeSlotType
    if (type(inventory.freeSlotType) == "function") then
        freeSlotType = inventory.freeSlotType()
    else
        freeSlotType = inventory.freeSlotType
    end
    if (type(inventory.altFreeSlotType) == "function") then
        altFreeSlotType = inventory.altFreeSlotType()
    else
        altFreeSlotType = inventory.altFreeSlotType
    end
    if(inventory.freeSlotsLabel) then
        local freeSlotTypeInventory = self.inventories[freeSlotType]
        local numUsedSlots, numSlots = self:GetNumSlots(freeSlotType)
        if(numUsedSlots < numSlots) then
            inventory.freeSlotsLabel:SetText(zo_strformat(freeSlotTypeInventory.freeSlotsStringId, numUsedSlots, numSlots))
        else
            inventory.freeSlotsLabel:SetText(zo_strformat(freeSlotTypeInventory.freeSlotsFullStringId, numUsedSlots, numSlots))
        end
    end
    if(inventory.altFreeSlotsLabel and altFreeSlotType) then
        local numUsedSlots, numSlots = self:GetNumSlots(altFreeSlotType)
        local altFreeSlotInventory = self.inventories[altFreeSlotType] --grab the alternateInventory to use it's string id's
        if(numUsedSlots < numSlots) then
            inventory.altFreeSlotsLabel:SetText(zo_strformat(altFreeSlotInventory.freeSlotsStringId, numUsedSlots, numSlots))
        else
            inventory.altFreeSlotsLabel:SetText(zo_strformat(altFreeSlotInventory.freeSlotsFullStringId, numUsedSlots, numSlots))
        end
    end
end
function ZO_InventoryManager:SetupInitialFilter()
    ZO_MenuBar_SelectDescriptor(self.inventories[INVENTORY_BACKPACK].filterBar, ITEMFILTERTYPE_ALL)
    ZO_MenuBar_SelectDescriptor(self.inventories[INVENTORY_BANK].filterBar, ITEMFILTERTYPE_ALL)
    ZO_MenuBar_SelectDescriptor(self.inventories[INVENTORY_HOUSE_BANK].filterBar, ITEMFILTERTYPE_ALL)
    ZO_MenuBar_SelectDescriptor(self.inventories[INVENTORY_GUILD_BANK].filterBar, ITEMFILTERTYPE_ALL)
    ZO_MenuBar_SelectDescriptor(self.inventories[INVENTORY_CRAFT_BAG].filterBar, ITEMFILTERTYPE_ALL)
end
function ZO_InventoryManager:PlayItemAddedAlert(filterData, tabFilters)
    if(self.suppressItemAddedAlert) then return end
    for filterKey, tabFilter in pairs(tabFilters) do
        for filterIndex = 1, #filterData do
            if(filterData[filterIndex] == tabFilter.filterType or tabFilter.filterType == ITEMFILTERTYPE_ALL) then
                local anim = ZO_AlphaAnimation_GetAnimation(GetControl(tabFilter.control, "Flash"))
                if(not anim:IsPlaying()) then
                    anim:PingPong(0, .5, 700, 11)
                end
                break
            end
        end
    end
end
function ZO_InventoryManager:UpdateApparelSection()
    if ZO_CharacterApparelHidden then
        ZO_CharacterApparelHidden:SetHidden(not IsEquipSlotVisualCategoryHidden(EQUIP_SLOT_VISUAL_CATEGORY_APPAREL))
    end
end
--Inventory Item
----------------
function ZO_InventoryManager:AddInventoryItem(inventoryType, slotIndex, bagId)
    local inventory = self.inventories[inventoryType]
    if inventory.backingBags then
        -- Default bagId to backingBags[1] for addon backwards-compatibility
        bagId = bagId or inventory.backingBags[1]
        inventory.slots[bagId][slotIndex] = SHARED_INVENTORY:GenerateSingleSlotData(bagId, slotIndex)
    end
end
function ZO_InventoryManager:UpdateNewStatus(inventoryType, slotIndex, bagId)
    local inventory = self.inventories[inventoryType]
    if inventory.backingBags then
        -- Default bagId to backingBags[1] for addon backwards-compatibility
        bagId = bagId or inventory.backingBags[1]
        -- might not have the slot data yet depending on who is calling this and when, this will ensure we have the correct data
        -- if the slot data was already created this will essentially be a no-op (some table lookups)
        self:AddInventoryItem(inventoryType, slotIndex, bagId)
        local slot = inventory.slots[bagId][slotIndex]
        if slot and slot.age ~= 0 then
            slot.clearAgeOnClose = true
        end
    end
end
function ZO_InventoryManager:GetNumSlots(inventoryType, excludeUnavailable)
    local inventory = self.inventories[inventoryType]
    local usedSlots = 0
    local bagSize = 0
    
    if inventory.backingBags then
        for k, bagId in ipairs(inventory.backingBags) do
            usedSlots = usedSlots + GetNumBagUsedSlots(bagId)
            bagSize = bagSize + GetBagUseableSize(bagId)
        end
    end
    return usedSlots, bagSize
end
function ZO_InventoryManager:OnInventoryItemRemoved(inventoryType, bagId, slotIndex, oldSlotData)
    local inventory = self.inventories[inventoryType]
    if(oldSlotData) then
        inventory.stringSearch:Remove(oldSlotData.searchData)
    end
end
function ZO_InventoryManager:OnInventoryItemAdded(inventoryType, bagId, slotIndex, newSlotData)
    local inventory = self.inventories[inventoryType]
    newSlotData.searchData = {type = SEARCH_TYPE_INVENTORY, bagId = bagId, slotIndex = slotIndex}
    newSlotData.inventory = inventory
    inventory.stringSearch:Insert(newSlotData.searchData)
    -- play a brief flash animation on all the filter tabs that match this item's filterTypes
    if newSlotData.brandNew then
        self:PlayItemAddedAlert(newSlotData.filterData, inventory.tabFilters)
    end
end
function ZO_InventoryManager:DoesBagHaveEmptySlot(bagId)
    local inventoryType = self.bagToInventoryType[bagId]
    if inventoryType then
        local numUsedSlots, numSlots = self:GetNumSlots(inventoryType)
        return numUsedSlots < numSlots
    end
    return false
end
do
    local function HasAnyQuickSlottableItems(slots)
        for slotIndex, slotData in pairs(slots) do
            if slotData.filterData then
                for i = 1, #slotData.filterData do
                    if slotData.filterData[i] == ITEMFILTERTYPE_QUICKSLOT then
                        return true
                    end
                end
            end
        end
        return false
    end
    function ZO_InventoryManager:HasAnyQuickSlottableItems(inventoryType)
        local inventory = self.inventories[inventoryType]
        if inventory.backingBags then
            if inventory.hasAnyQuickSlottableItems == nil then
                for bagIndex, bagId in ipairs(inventory.backingBags) do
                    inventory.hasAnyQuickSlottableItems = HasAnyQuickSlottableItems(inventory.slots[bagId])
                end
            end
            return inventory.hasAnyQuickSlottableItems
        else
            return false
        end
    end
end
function ZO_InventoryManager:ShouldAddSlotToList(inventory, slot)
    if(not slot or slot.stackCount <= 0) then return false end
    if(not inventory.stringSearch:IsMatch(self.cachedSearchText, slot.searchData)) then return false end
    local currentFilter = inventory.currentFilter
    local additionalFilterPasses = true
    local additionalFilter = inventory.additionalFilter
    if(type(additionalFilter) == "function") then
        additionalFilterPasses = additionalFilter(slot)
    end
    if(type(currentFilter) ~= "function") then
        return additionalFilterPasses and BaseInventoryFilter(currentFilter, slot)
    else
        return additionalFilterPasses and currentFilter(slot)
    end
    return false
end
function ZO_InventoryManager:UpdateList(inventoryType, updateEvenIfHidden)
    local inventory = self.inventories[inventoryType]
    --Only need slots to update the list, not a backing bag (quest items have no backing bag but create slots)
    if inventory.slots then
        local list = inventory.listView
        if (list and not list:IsHidden()) or updateEvenIfHidden then
            local scrollData = ZO_ScrollList_GetDataList(list)
            ZO_ScrollList_Clear(list)
            -- TODO: possibly change the quest item implementation to just be a list of slots instead of being indexed by questIndex/slot
            -- For now just write two different iteration functions for quest/real inventories.
            self.cachedSearchText = inventory.searchBox:GetText()
            if inventoryType == INVENTORY_QUEST_ITEM then
                local questItems = inventory.slots
                for questIndex, questItemTable in pairs(questItems) do
                    for questItemIndex = 1, #questItemTable do
                        local slotData = questItemTable[questItemIndex]
                        if(self:ShouldAddSlotToList(inventory, slotData)) then
                            scrollData[#scrollData + 1] = ZO_ScrollList_CreateDataEntry(inventory.listDataType, slotData)
                        end
                    end
                end
            else
                if self:ShouldAddEntries(inventoryType) then
                    local slots = inventory.slots
                    for bagIndex, bagId in ipairs(inventory.backingBags) do
                        if slots[bagId] then                  
                            for slotIndex, slotData in pairs(slots[bagId]) do
                                if self:ShouldAddSlotToList(inventory, slotData) then
                                    scrollData[#scrollData + 1] = ZO_ScrollList_CreateDataEntry(inventory.listDataType, slotData)
                                end
                            end
                        end
                    end
                end
            end
            self.cachedSearchText = nil
            self:ApplySort(inventoryType)
            KEYBIND_STRIP:UpdateKeybindButtonGroup(self.bankWithdrawTabKeybindButtonGroup)
            local isEmptyList = not ZO_ScrollList_HasVisibleData(list)
            if inventory.sortHeaders then
                inventory.sortHeaders.headerContainer:SetHidden(isEmptyList)
            end
            self:UpdateEmptyBagLabel(inventoryType, isEmptyList)
            self.isListDirty[inventoryType] = false      
        else
            self.isListDirty[inventoryType] = true
        end
    end
end
function ZO_InventoryManager:ShouldAddEntries(inventoryType)
    local guildId = GetSelectedGuildBankId()
    return inventoryType ~= INVENTORY_BACKPACK or not self:IsGuildBanking() or (DoesPlayerHaveGuildPermission(guildId, GUILD_PERMISSION_BANK_DEPOSIT) and DoesGuildHavePrivilege(guildId, GUILD_PRIVILEGE_BANK_DEPOSIT))  
end
function ZO_InventoryManager:EmptyInventory(inventory)
    if inventory then
        if inventory.backingBags then
            for bagIndex, bagId in ipairs(inventory.backingBags) do
                if inventory.slots[bagId] then
                    ZO_ClearTable(inventory.slots[bagId])
                end
            end
            inventory.hasAnyQuickSlottableItems = nil
        end
    end
end
function ZO_InventoryManager:RefreshAllInventorySlots(inventoryType)
    local inventory = self.inventories[inventoryType]
    if inventory.backingBags then
        self:EmptyInventory(inventory)
        local search = inventory.stringSearch
        if search then
            search:RemoveAll()
        end
        self.suppressItemAddedAlert = true
        for k, bagId in ipairs(inventory.backingBags) do
            for slotIndex in ZO_IterateBagSlots(bagId) do
                self:AddInventoryItem(inventoryType, slotIndex, bagId)
            end
        end
        if inventoryType == INVENTORY_BACKPACK then
            CALLBACK_MANAGER:FireCallbacks("BackpackFullUpdate")
        end
        self:LayoutInventoryItems(inventoryType)
        self.suppressItemAddedAlert = nil
    end
end
function ZO_InventoryManager:RefreshInventorySlot(inventoryType, slotIndex, bagId)
    local inventory = self.inventories[inventoryType]
    if inventory.backingBags then       
        -- Default bagId to backingBags[1] for addon backwards-compatibility
        bagId = bagId or inventory.backingBags[1]
        inventory.hasAnyQuickSlottableItems = nil
        self:AddInventoryItem(inventoryType, slotIndex, bagId)
        if inventoryType == INVENTORY_BACKPACK then
            CALLBACK_MANAGER:FireCallbacks("BackpackSlotUpdate", slotIndex)
        end
        -- Rebuild the entire list, refilter, and resort every time a single item is updated...sadness.
        self:LayoutInventoryItems(inventoryType)
        local slot = inventory.slots[bagId][slotIndex]
        if slot and slot.slotControl then
            CALLBACK_MANAGER:FireCallbacks("InventorySlotUpdate", GetControl(slot.slotControl, "Button"))
        end
    end
end
function ZO_InventoryManager:LayoutInventoryItems(inventoryType)
    self:UpdateList(inventoryType)
    self:UpdateFreeSlots(inventoryType)
end
-- This function only refreshes the 'traditional' slotted bags: backpack and bank
function ZO_InventoryManager:RefreshAllInventoryOverlays(inventoryType)
    local inventory = self.inventories[inventoryType]
    if inventory.backingBags then
        for k, bagId in ipairs(inventory.backingBags) do
            local numSlots = GetBagSize(bagId)
            for slotIndex = 0, numSlots - 1 do
                self:RefreshInventorySlotOverlay(inventoryType, slotIndex, bagId)
            end
        end
    end
end
do
    local function ShouldClearAgeOnClose(slot, inventoryManager)
        if slot and slot.clearAgeOnClose then
            local layout = inventoryManager.appliedLayout
            if layout and layout.waitUntilInventoryOpensToClearNewStatus then
                return false
            end
            return true
        end
        return false
    end
    local function TryClearNewStatus(inventory, bagId, slotIndex, inventoryManager)
        local slot = inventory.slots[bagId][slotIndex]
        if ShouldClearAgeOnClose(slot, inventoryManager) then
            slot.clearAgeOnClose = nil
            SHARED_INVENTORY:ClearNewStatus(bagId, slotIndex)
            return true
        else
            return false
        end
    end
    function ZO_InventoryManager:ClearNewStatusOnItemsThePlayerHasSeen(inventoryType)
        local inventory = self.inventories[inventoryType]
        if inventory.backingBags then
            local anyNewStatusCleared = false
            for k, bagId in ipairs(inventory.backingBags) do
                for slotIndex in ZO_IterateBagSlots(bagId) do
                    local newStatusCleared = TryClearNewStatus(inventory, bagId, slotIndex, self)
                    anyNewStatusCleared = anyNewStatusCleared or newStatusCleared
                end
            end
            if anyNewStatusCleared then
                if inventory.currentSortKey == "statusSortOrder" then
                    self:ApplySort(inventoryType)
                end
                if inventory.listView then
                    local REFRESH_ALL_DATA = nil
                    ZO_ScrollList_RefreshVisible(inventory.listView, REFRESH_ALL_DATA, ZO_UpdateStatusControlIcons)
                end
                if MAIN_MENU_KEYBOARD then
                    MAIN_MENU_KEYBOARD:RefreshCategoryBar()
                end
            end
        end
    end
end
function ZO_InventoryManager:RefreshInventorySlotLocked(inventoryType, slotIndex, locked, bagId)
    local inventory = self.inventories[inventoryType]
    if inventory.backingBags then
        -- Default bagId to backingBags[1] for addon backwards-compatibility
        bagId = bagId or inventory.backingBags[1]
        if inventory.slots then
            local bag = inventory.slots[bagId]
            if bag then
                local slot = bag[slotIndex]
                if slot and slot.locked ~= locked then
                    slot.locked = locked
                    if(inventory.listView and slot.slotControl) then
                        ZO_PlayerInventorySlot_SetupUsableAndLockedColor(slot.slotControl, slot.meetsUsageRequirement, slot.locked)
                        CALLBACK_MANAGER:FireCallbacks("InventorySlotUpdate", GetControl(slot.slotControl, "Button"))
                    end
                end
            end
        end
    end
end
function ZO_InventoryManager:RefreshInventorySlotOverlay(inventoryType, slotIndex, bagId)
    local inventory = self.inventories[inventoryType]
    if inventory.backingBags then
        -- Default bagId to backingBags[1] for addon backwards-compatibility
        bagId = bagId or inventory.backingBags[1]
        local slot = inventory.slots[bagId][slotIndex]
        if slot then
            local _, _, _, meetsUsageRequirement, _ = GetItemInfo(bagId, slotIndex)
            local isLocalPlayerDead = IsUnitDead("player")
            local isLocked = slot.locked or isLocalPlayerDead
            if meetsUsageRequirement ~= slot.meetsUsageRequirement or isLocalPlayerDead ~= self.itemsLockedDueToDeath then
                slot.meetsUsageRequirement = meetsUsageRequirement
                if slot.slotControl then
                    ZO_PlayerInventorySlot_SetupUsableAndLockedColor(slot.slotControl, slot.meetsUsageRequirement, isLocked)
                    CALLBACK_MANAGER:FireCallbacks("InventorySlotUpdate", GetControl(slot.slotControl, "Button"))
                end
            end
        end
    end
end
function ZO_InventoryManager:UpdateItemCooldowns(inventoryType)
    local inventory = self.inventories[inventoryType]
    if(inventory.listView) then
        ZO_ScrollList_RefreshVisible(inventory.listView, nil, ZO_InventorySlot_UpdateCooldowns)
    end
end
function ZO_InventoryManager:IsSlotOccupied(bagId, slotIndex)
    local inventoryType = self.bagToInventoryType[bagId]
    local slot = self.inventories[inventoryType].slots[bagId][slotIndex]
    return ((slot ~= nil) and (slot.stackCount > 0))
end
do
    local function UpdateItemTable(bagId, slotIndex, predicate, dataTable)
        if not predicate or predicate(bagId, slotIndex) then
            local _, stackCount = GetItemInfo(bagId, slotIndex)
            if not dataTable then
                return { bag = bagId, index = slotIndex, stack = stackCount }
            else
                dataTable.stack = dataTable.stack + stackCount
            end
        end
        return dataTable
    end
    --where ... are inventory types
    function ZO_InventoryManager:GenerateVirtualStackedItem(predicate, specificItemInstanceId, ...)
        local data
        for i = 1, select("#", ...) do
            local inventoryType = select(i, ...)
            local inventory = self.inventories[inventoryType]
            if inventory.backingBags then
                for k, bagId in ipairs(inventory.backingBags) do
                    for slotIndex in ZO_IterateBagSlots(bagId) do
                        local itemInstanceId = GetItemInstanceId(bagId, slotIndex)
                        if itemInstanceId == specificItemInstanceId then
                            data = UpdateItemTable(bagId, slotIndex, predicate, data)
                        end
                    end
                end
            end
        end
        return data
    end
    --where ... are inventory types
    function ZO_InventoryManager:GenerateAllSlotsInVirtualStackedItem(predicate, specificItemInstanceId, ...)
        local matchingSlots = {}
        for i = 1, select("#", ...) do
            local inventoryType = select(i, ...)
            local inventory = self.inventories[inventoryType]
            if inventory.backingBags then
                for k, bagId in ipairs(inventory.backingBags) do
                    for slotIndex in ZO_IterateBagSlots(bagId) do
                        local itemInstanceId = GetItemInstanceId(bagId, slotIndex)
                        if itemInstanceId == specificItemInstanceId and (predicate == nil or predicate(bagId, slotIndex)) then
                            local _, stackCount = GetItemInfo(bagId, slotIndex)
                            table.insert(matchingSlots, {bagId = bagId, slotIndex = slotIndex, stackCount = stackCount})
                        end
                    end
                end
            end
        end
        return matchingSlots
    end
    function ZO_InventoryManager:GenerateListOfVirtualStackedItems(inventoryType, predicate, itemIds)
        local inventory = self.inventories[inventoryType]
        itemIds = itemIds or {}
        if inventory.backingBags then
            for k, bagId in ipairs(inventory.backingBags) do
                self:GenerateListOfVirtualStackedItemsFromBag(bagId, predicate, itemIds)
            end
        end
        return itemIds
    end
    function ZO_InventoryManager:GenerateListOfVirtualStackedItemsFromBag(bagId, predicate, itemIds)
        local itemData
        for slotIndex in ZO_IterateBagSlots(bagId) do
            local itemInstanceId = GetItemInstanceId(bagId, slotIndex)
            if itemInstanceId then
                itemData = itemIds[itemInstanceId]
                itemIds[itemInstanceId] = UpdateItemTable(bagId, slotIndex, predicate, itemData)
            end
        end
    end
end
--Backpack
----------
function ZO_InventoryManager:GetNumBackpackSlots()
    local inventory = self.inventories[INVENTORY_BACKPACK]
    local backpackSize = 0
    if inventory.backingBags then
        for k, bagId in ipairs(inventory.backingBags) do
            backpackSize = backpackSize + GetBagSize(bagId)
        end
    end
    return backpackSize
end
function ZO_InventoryManager:GetBackpackItem(slotIndex, bagId)
    local inventory = self.inventories[INVENTORY_BACKPACK]
    -- Default bagId to backingBags[1] for addon backwards-compatibility
    bagId = bagId or inventory.backingBags[1]
    return inventory.slots[bagId][slotIndex]
end
function ZO_InventoryManager:IsShowingBackpack()
    return not ZO_PlayerInventory:IsHidden()
end
function ZO_InventoryManager:ApplyBackpackLayout(layoutData)
    if(layoutData == self.appliedLayout and not layoutData.alwaysReapplyLayout) then
        return
    end
    
    self.appliedLayout = layoutData
    self:ApplySharedBagLayout(ZO_PlayerInventory, layoutData)
    self:ApplySharedBagLayout(ZO_CraftBag, layoutData)
    local inventory = self.inventories[INVENTORY_BACKPACK]
    inventory.additionalFilter = layoutData.additionalFilter
    local menuBar = inventory.filterBar
    ZO_MenuBar_ClearButtons(menuBar)
    for _, filterData in ipairs(inventory.tabFilters) do
        if not layoutData.hiddenFilters or not layoutData.hiddenFilters[filterData.filterType] then
            ZO_MenuBar_AddButton(menuBar, filterData)
        end
    end
    local selectedTab = layoutData.selectedTab or ITEMFILTERTYPE_ALL
    ZO_MenuBar_SelectDescriptor(self.inventories[INVENTORY_BACKPACK].filterBar, selectedTab)
    local hideBankInfo = layoutData.hideBankInfo
    local hideCurrencyInfo = layoutData.hideCurrencyInfo
    ZO_PlayerInventoryInfoBarMoney:SetHidden(hideCurrencyInfo)
    ZO_PlayerInventoryInfoBarAltMoney:SetHidden(hideBankInfo or hideCurrencyInfo)
    ZO_PlayerInventoryInfoBarAltFreeSlots:SetHidden(hideBankInfo)
    ZO_CraftBagInfoBarMoney:SetHidden(hideCurrencyInfo)
    ZO_CraftBagInfoBarAltMoney:SetHidden(hideBankInfo or hideCurrencyInfo)
    ZO_CraftBagInfoBarAltFreeSlots:SetHidden(hideBankInfo)
    local useSearchBar = layoutData.useSearchBar
    ZO_PlayerInventorySearch:SetHidden(not useSearchBar)
    local hideTabBar = layoutData.hideTabBar
    ZO_PlayerInventoryTabs:SetHidden(hideTabBar)
end
function ZO_InventoryManager:ApplySharedBagLayout(inventoryControl, layoutData)
    inventoryControl:ClearAnchors()
    inventoryControl:SetAnchor(TOPLEFT, ZO_SharedRightPanelBackground, TOPLEFT, 0, layoutData.inventoryTopOffsetY)
    inventoryControl:SetAnchor(BOTTOMLEFT, ZO_SharedRightPanelBackground, BOTTOMLEFT, 0, layoutData.inventoryBottomOffsetY)
    local inventoryContainer = inventoryControl:GetNamedChild("List")
    inventoryContainer:SetWidth(layoutData.width)
    inventoryContainer:ClearAnchors()
    inventoryContainer:SetAnchor(TOPRIGHT, inventoryControl, TOPRIGHT, 0, layoutData.backpackOffsetY)
    inventoryContainer:SetAnchor(BOTTOMRIGHT)
    ZO_ScrollList_SetHeight(inventoryContainer, inventoryContainer:GetHeight())
    ZO_ScrollList_Commit(inventoryContainer)
    local sortHeaders = inventoryControl:GetNamedChild("SortBy")
    sortHeaders:ClearAnchors()
    sortHeaders:SetAnchor(TOPRIGHT, inventoryControl, TOPRIGHT, 0, layoutData.sortByOffsetY)
    sortHeaders:SetWidth(layoutData.width)
    local emptyLabel = inventoryControl:GetNamedChild("Empty")
    emptyLabel:ClearAnchors()
    emptyLabel:SetAnchor(TOPLEFT, inventoryControl, TOPLEFT, 50, layoutData.emptyLabelOffsetY)
    emptyLabel:SetAnchor(TOPRIGHT, inventoryControl, TOPRIGHT, -50, layoutData.emptyLabelOffsetY)
    local sortByName = sortHeaders:GetNamedChild("Name")
    sortByName:SetWidth(layoutData.sortByNameWidth)
    local filterDivider = inventoryControl:GetNamedChild("FilterDivider")
    filterDivider:ClearAnchors()
    filterDivider:SetAnchor(TOP, ZO_SharedRightPanelBackground, TOP, 0, layoutData.inventoryFilterDividerTopOffsetY)
end
--Quest Items
-------------
function ZO_InventoryManager:AddQuestItem(questItem, searchType)
    local inventory = self.inventories[INVENTORY_QUEST_ITEM]
    questItem.inventory = inventory
    --store all tools and items in a subtable under the questIndex for faster access
    local questIndex = questItem.questIndex
    if not inventory.slots[questIndex] then
        inventory.slots[questIndex] = {}
    end
    questItem.slotIndex = questIndex
    table.insert(inventory.slots[questIndex], questItem)
    local index = #inventory.slots[questIndex]
    if(searchType == SEARCH_TYPE_QUEST_ITEM) then
        questItem.searchData = {type = SEARCH_TYPE_QUEST_ITEM, questIndex = questIndex, stepIndex = questItem.stepIndex, conditionIndex = questItem.conditionIndex, index = index }
    else
        questItem.searchData = {type = SEARCH_TYPE_QUEST_TOOL, questIndex = questIndex, toolIndex = questItem.toolIndex, index = index }
    end
    inventory.stringSearch:Insert(questItem.searchData)
end
function ZO_InventoryManager:RefreshAllQuests()
    for questIndex = 1, MAX_JOURNAL_QUESTS do
        self:RefreshQuest(questIndex, PREVENT_LAYOUT)
    end
    self:UpdateList(INVENTORY_QUEST_ITEM)
end
function ZO_InventoryManager:RefreshQuest(questIndex, doLayout)
    if doLayout == nil then
        doLayout = true
    end
    self:ResetQuest(questIndex)
    local questCache = SHARED_INVENTORY:GenerateSingleQuestCache(questIndex)
    if questCache then
        for _, questItem in pairs(questCache) do
            local searchType = questItem.toolIndex and SEARCH_TYPE_QUEST_TOOL or SEARCH_TYPE_QUEST_ITEM
            self:AddQuestItem(questItem, searchType)
        end
    end
    if doLayout then
        self:UpdateList(INVENTORY_QUEST_ITEM)
    end
end
function ZO_InventoryManager:ResetQuest(questIndex)
    local inventory = self.inventories[INVENTORY_QUEST_ITEM]
    local itemTable = inventory.slots[questIndex]
    if itemTable then
        --remove all quest items from search
        for i = 1, #itemTable do
            inventory.stringSearch:Remove(itemTable.searchData)
        end
    end
    inventory.slots[questIndex] = nil
end
--Launder
---------
function ZO_InventoryManager:RefreshBackpackWithFenceData(callback)
    -- If no callback is specified, ZO_ScrollList will attempt to use the default callback specified for each list element's data type
    ZO_ScrollList_RefreshVisible(self.inventories[BAG_BACKPACK].listView, nil, callback)
end
--Bank
------
--Bank Deposit/Withdraw Dialog
local ZO_BankGenericCurrencyDepositWithdrawDialog = ZO_Object:Subclass()
function ZO_BankGenericCurrencyDepositWithdrawDialog:New(...)
    local obj = ZO_Object.New(self)
    obj:Initialize(...)
    return obj
end
function ZO_BankGenericCurrencyDepositWithdrawDialog:Initialize(prefix, currencyBankLocation, canWithdrawFunction)
    local control = CreateControlFromVirtual(prefix .. "CurrencyTransferDialog", GuiRoot, "ZO_PlayerBankDepositWithdrawCurrency")
    self.control = control
    self.depositWithdrawButton = control:GetNamedChild("DepositWithdraw")
    local container = control:GetNamedChild("Container")
    local headersContainer = container:GetNamedChild("Headers")
    self.withdrawDepositCurrencyHeaderLabel = headersContainer:GetNamedChild("WithdrawDeposit")
    local amountsContainer = container:GetNamedChild("Amounts")
    self.carriedCurrencyLabel = amountsContainer:GetNamedChild("Carried")
    self.bankedCurrencyLabel = amountsContainer:GetNamedChild("Banked")
    local currenciesComboBoxControl = amountsContainer:GetNamedChild("ComboBox")
    self.depositWithdrawCurrency = container:GetNamedChild("DepositWithdrawCurrency")
    self.currencyBankLocation = currencyBankLocation
    for currencyType = CURT_ITERATION_BEGIN, CURT_ITERATION_END do
        if CanCurrencyBeStoredInLocation(currencyType, currencyBankLocation) then
            if not self.currencyType then
                self.currencyType = currencyType
            end
            if self.singularCurrency == nil then
                self.singularCurrency = true
            elseif self.singularCurrency == true then
                self.singularCurrency = false
            end
        end
    end
    if self.singularCurrency then
        self.carriedCurrencyLabel:SetHidden(false)
        self.bankedCurrencyLabel:SetHidden(false)
    else
        local comboBox = ZO_ComboBox:New(currenciesComboBoxControl)
        comboBox:SetSortsItems(false)
        comboBox:SetFont("ZoFontWinT1")
        comboBox:SetSpacing(15)
        comboBox:SetHorizontalAlignment(TEXT_ALIGN_RIGHT)
        self.currenciesComboBox = comboBox
        currenciesComboBoxControl:SetHidden(false)
    end
    self.withdrawDialogName = prefix.."_WITHDRAW_GOLD"
    ZO_Dialogs_RegisterCustomDialog(self.withdrawDialogName,
    {
        customControl = control,
        title =
        {
            text = SI_BANK_WITHDRAW_CURRENCY,
        },
        setup = function(dialog)
            self.withdrawMode = true
            self.depositWithdrawButton:SetState(BSTATE_NORMAL, false) --reenable in case deposit disabled it and the user cancelled
            local ON_CURRENCY_CHANGED_CALLBACK = nil
            ZO_DefaultCurrencyInputField_Initialize(self.depositWithdrawCurrency, ON_CURRENCY_CHANGED_CALLBACK, self.currencyType)
            self.withdrawDepositCurrencyHeaderLabel:SetText(GetString(SI_BANK_CURRENCY_VALUE_ENTRY_WITHDRAW_HEADER))
            self:UpdateMoneyInputAndDisplay()
            self:FocusInput()
        end,
        buttons =
        {
            {
                control = self.depositWithdrawButton,
                text = SI_BANK_WITHDRAW_BIND,
                callback = function(dialog)
                                local amount = ZO_DefaultCurrencyInputField_GetCurrency(self.depositWithdrawCurrency)
                                if amount > 0 then
                                    TransferCurrency(self.currencyType, amount, self.currencyBankLocation, GetCurrencyPlayerStoredLocation(self.currencyType))
                                end
                            end,
            },
            {
                control = control:GetNamedChild("Cancel"),
                text = SI_DIALOG_CANCEL,
            }
        }
    })
    self.depositDialogName = prefix.."_DEPOSIT_GOLD"
    ZO_Dialogs_RegisterCustomDialog(self.depositDialogName,
    {
        customControl = control,
        title =
        {
            text = SI_BANK_DEPOSIT_CURRENCY,
        },