ESO Lua File v100011

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
--Variables
local PlayerInventory = nil
PLAYER_INVENTORY = nil
INVENTORY_BACKPACK = 1
INVENTORY_QUEST_ITEM = 2
INVENTORY_BANK = 3
INVENTORY_GUILD_BANK = 4
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 PREVENT_LAYOUT = false
local searchButtonTexture = "EsoUI/Art/Buttons/searchButton_normal.dds"
local searchButtonDownTexture = "EsoUI/Art/Buttons/searchButton_mouseDown.dds"
local cancelButtonTexture = "EsoUI/Art/Buttons/cancelButton_normal.dds"
local cancelButtonDownTexture = "EsoUI/Art/Buttons/cancelButton_mouseDown.dds"
local NEW_ICON_TEXTURE = "EsoUI/Art/Inventory/newItem_icon.dds"
local STOLEN_ICON_TEXTURE = "EsoUI/Art/Inventory/inventory_stolenItem_icon.dds"
INVENTORY_CURRENCY_OPTIONS =
{
    showTooltips = true,
    customTooltip = SI_CURRENCY_YOUR_GOLD,
    font = "ZoFontGameLargeBold",
    iconSide = RIGHT,
}
INVENTORY_BANKED_CURRENCY_OPTIONS =
{
    showTooltips = true,
    customTooltip = SI_CURRENCY_YOUR_BANKED_GOLD,
    font = "ZoFontGameLargeBold",
    iconSide = RIGHT,
}
INVENTORY_ALLIANCE_POINTS_OPTIONS =
{
    showTooltips = true,
    customTooltip = SI_CURRENCY_YOUR_ALLIANCE_POINTS,
    font = "ZoFontGameLargeBold",
    iconSide = RIGHT,
}
GUILD_BANKING_INTERACTION =
{
    type = "GuildBanking",
    interactTypes = { INTERACTION_GUILDBANK },
}
-----------
--Callbacks
-----------
--tabs
local function HandleTabSwitch(tabData)
    -- special case inventory list hiding based on selecting quest inventory
    -- bank filters don't mess with the visibility of the regular inventory
    if(tabData.descriptor == ITEMFILTERTYPE_QUEST) then
        ZO_PlayerInventoryBackpack:SetHidden(true)
        ZO_PlayerInventoryQuest:SetHidden(false)
        PlayerInventory.selectedTabType = INVENTORY_QUEST_ITEM
    end
    if(tabData.inventoryType == INVENTORY_BACKPACK) then
        ZO_PlayerInventoryBackpack:SetHidden(false)
        ZO_PlayerInventoryQuest:SetHidden(true)
        PlayerInventory.selectedTabType = INVENTORY_BACKPACK
    end
    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 ~= ITEMSTYLE_NONE) then
        local itemStyleName = ITEM_STYLE_NAME[itemStyle]
        if(not itemStyleName) then
            itemStyleName = GetString("SI_ITEMSTYLE", itemStyle):lower()
            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", isNumeric = true },
    age = { tiebreaker = "name", isNumeric = true, reverseTiebreakerSortOrder = true },
    statValue = { tiebreaker = "name", isNumeric = true },
}
    return sortKeys
end
local bankSortTypes =
{
    ZO_ComboBox:CreateItemEntry(GetString(SI_INVENTORY_SORT_TYPE_NAME), function() PlayerInventory:ChangeSort("name", INVENTORY_BANK) end),
    ZO_ComboBox:CreateItemEntry(GetString(SI_INVENTORY_SORT_TYPE_PRICE), function() PlayerInventory:ChangeSort("stackSellPrice", INVENTORY_BANK) end),
    -- NOTE: Bank cannot sort by age...items moved to the bank (or back again) do not have their age persisted yet.
}
local function InitializeHeaderSort(inventoryType, inventory, headerControl)
    local sortHeaders = ZO_SortHeaderGroup:New(headerControl, true)
    local function OnSortHeaderClicked(key, order)
        PlayerInventory:ChangeSort(key, inventoryType, order)
    end
    sortHeaders:RegisterCallback(ZO_SortHeaderGroup.HEADER_CLICKED, OnSortHeaderClicked)
    sortHeaders:AddHeadersFromContainer()
    sortHeaders:SelectHeaderByKey(inventory.currentSortKey, ZO_SortHeaderGroup.SUPPRESS_CALLBACKS)
    sortHeaders:SelectHeaderByKey(inventory.currentSortKey, ZO_SortHeaderGroup.SUPPRESS_CALLBACKS) -- select twice to make it descending! EVIL, ask chip about a better way to do this.
    inventory.sortHeaders = sortHeaders
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
        ZO_MenuBar_SetData(menuBar, inventory.filterBarData)
        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
local function UpdateStatusControl(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
    statusControl:Show()
    if(slotData.age ~= 0) then
        slotData.clearAgeOnClose = true
    end
end
local function UpdateStatValueControl(inventorySlot, slot)
    local statControl = GetControl(inventorySlot, "StatValue")
    if(statControl) then
        -- NOT A HACK, stat values can be nil in certain cases...quest items have nil values.
        local showStatColumn = not slot.inventory.hiddenColumns["statValue"]
        statControl:SetText((showStatColumn and (slot.statValue ~= nil) and (slot.statValue > 0)) and tostring(slot.statValue) or "")
    end
end
ITEM_SLOT_CURRENCY_OPTIONS =
{
    showTooltips = false,
    font = "ZoFontGameShadow",
    iconSide = RIGHT,
}
local function SetupInventoryItemRow(rowControl, slot)
    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 sellPriceControl = GetControl(rowControl, "SellPrice")
    sellPriceControl:SetHidden(false)
    ZO_CurrencyControl_SetSimpleCurrency(sellPriceControl, 
                                         CURRENCY_TYPE_MONEY, 
                                         (FENCE_MANAGER and SYSTEMS:GetObject("fence"):IsLaundering()) and slot.stackLaunderPrice or slot.stackSellPrice, 
                                         ITEM_SLOT_CURRENCY_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
    UpdateStatusControl(rowControl, slot)
    UpdateStatValueControl(rowControl, slot)
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)
    UpdateStatusControl(rowControl, questItem)
    UpdateStatValueControl(rowControl, questItem)
end
local function CreateNewTabFilterData(filterType, inventoryType, normal, pressed, highlight, hiddenColumns)
    local isHiddenTab = type(filterType) == "function"
    local filterString = isHiddenTab and "" or GetString("SI_ITEMFILTERTYPE", filterType)
    local tabData = 
    {
        -- Custom data
        filterType = filterType,
        inventoryType = inventoryType,
        hiddenColumns = hiddenColumns,
        activeTabText = isHiddenTab and "" or filterString,
        tooltipText = isHiddenTab and "" or filterString,
        -- Menu bar data
        hidden = isHiddenTab,
        descriptor = filterType,
        normal = normal,
        pressed = pressed,
        highlight = highlight,
        callback = HandleTabSwitch,
    }
    return tabData
end
local function TradingHouseFilter(slot)
    return not IsItemBound(slot.bagId, slot.slotIndex)
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.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 typicalHiddenColumns =
    {
        ["statValue"] = true,
    }
    local questHiddenColumns =
    {
        ["statValue"] = true,
        ["age"] = true,
        ["stackSellPrice"] = true,
    }
    local gearHiddenColumns =
    {
        -- Don't hide anything!
    }
    local tradingHouseHiddenColumns =
    {
        ["statValue"] = true,
        ["age"] = 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", typicalHiddenColumns),
        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_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_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", typicalHiddenColumns),
        CreateNewTabFilterData(TradingHouseFilter, INVENTORY_BACKPACK, "", "", "", tradingHouseHiddenColumns),
    }
    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", typicalHiddenColumns),
        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_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_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", typicalHiddenColumns),
    }
    local guildBankFilters =
    {
        CreateNewTabFilterData(ITEMFILTERTYPE_JUNK, INVENTORY_GUILD_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", typicalHiddenColumns),
        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_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_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", typicalHiddenColumns),
    }
    local filterBarData =
    {
        initialButtonAnchorPoint = RIGHT,
        buttonTemplate = "ZO_InventoryFilterTab",
        normalSize = 51,
        downSize = 64,
        buttonPadding = -15,
        animationDuration = 180,
    }
    local inventories =
    {
        [INVENTORY_BACKPACK] =
        {
            slots = {},
            stringSearch = backpackSearch,
            searchBox = ZO_PlayerInventorySearchBox,
            slotType = SLOT_TYPE_ITEM,
            backingBag = BAG_BACKPACK,
            listView = ZO_PlayerInventoryBackpack,
            listDataType = INVENTORY_DATA_TYPE_BACKPACK,
            listSetupCallback = SetupInventoryItemRow,
            listHiddenCallback = OnInventoryItemRowHidden,
            freeSlotsLabel = ZO_PlayerInventoryInfoBarFreeSlots,
            freeSlotsStringId = SI_INVENTORY_BACKPACK_REMAINING_SPACES,
            freeSlotsFullStringId = SI_INVENTORY_BACKPACK_COMPLETELY_FULL,
            currentSortKey = "age",
            currentSortOrder = ZO_SORT_ORDER_DOWN,
            currentFilter = ITEMFILTERTYPE_ALL,
            tabFilters = backpackFilters,
            filterBar = ZO_PlayerInventoryTabs,
            filterBarData = filterBarData,            
            tabIconSize = 64, -- unused currently...might be resurrected
            rowTemplate = "ZO_PlayerInventorySlot",
            activeTab = ZO_PlayerInventoryTabsActive,
        },
        [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,
            rowTemplate = "ZO_PlayerInventorySlot",
            hiddenColumns = questHiddenColumns,
        },
        [INVENTORY_BANK] =
        {
            slots = {},
            stringSearch = bankSearch,
            searchBox = ZO_PlayerBankSearchBox,
            slotType = SLOT_TYPE_BANK_ITEM,
            backingBag = BAG_BANK,
            listView = ZO_PlayerBankBackpack,
            listDataType = INVENTORY_DATA_TYPE_BACKPACK,
            listSetupCallback = SetupInventoryItemRow,
            listHiddenCallback = OnInventoryItemRowHidden,
            freeSlotsLabel = ZO_PlayerBankInfoBarFreeSlots,
            freeSlotsStringId = SI_INVENTORY_BANK_REMAINING_SPACES,
            freeSlotsFullStringId = SI_INVENTORY_BANK_COMPLETELY_FULL,
            currentSortKey = "name",
            currentSortOrder = ZO_SORT_ORDER_DOWN,
            currentFilter = ITEMFILTERTYPE_ALL,
            tabFilters = bankFilters,
            filterBar = ZO_PlayerBankTabs,
            filterBarData = filterBarData,
            tabIconSize = 64, -- unused currently...might be resurrected
            rowTemplate = "ZO_PlayerInventorySlot",
            activeTab = ZO_PlayerBankTabsActive,
        },
        [INVENTORY_GUILD_BANK] =
        {
            slots = {},
            stringSearch = guildBankSearch,
            searchBox = ZO_GuildBankSearchBox,
            slotType = SLOT_TYPE_GUILD_BANK_ITEM,
            backingBag = BAG_GUILDBANK,
            listView = ZO_GuildBankBackpack,
            listDataType = INVENTORY_DATA_TYPE_BACKPACK,
            listSetupCallback = SetupInventoryItemRow,
            listHiddenCallback = OnInventoryItemRowHidden,
            freeSlotsLabel = ZO_GuildBankInfoBarFreeSlots,
            freeSlotsStringId = SI_INVENTORY_BANK_REMAINING_SPACES,
            freeSlotsFullStringId = SI_INVENTORY_BANK_COMPLETELY_FULL,
            currentSortKey = "name",
            currentSortOrder = ZO_SORT_ORDER_DOWN,
            currentFilter = ITEMFILTERTYPE_ALL,   
            tabFilters = guildBankFilters,
            filterBar = ZO_GuildBankTabs,
            filterBarData = filterBarData,            
            tabIconSize = 64, -- unused currently...might be resurrected
            rowTemplate = "ZO_PlayerInventorySlot",
            activeTab = ZO_GuildBankTabsActive,
        },
    }
    InitializeHeaderSort(INVENTORY_BACKPACK, inventories[INVENTORY_BACKPACK], ZO_PlayerInventorySortBy)
    InitializeHeaderSort(INVENTORY_BANK, inventories[INVENTORY_BANK], ZO_PlayerBankSortBy)
    InitializeHeaderSort(INVENTORY_GUILD_BANK, inventories[INVENTORY_GUILD_BANK], ZO_GuildBankSortBy)
    manager.inventories = inventories
    manager.searchToInventoryType = {}
    manager.bagToInventoryType =
    {
        [BAG_BACKPACK] = INVENTORY_BACKPACK,
        [BAG_BANK] = INVENTORY_BANK,
        [BAG_GUILDBANK] = INVENTORY_GUILD_BANK,
    }
    for inventoryType, inventoryData in pairs(manager.inventories) do
        InitializeInventoryList(inventoryData)
        InitializeInventoryFilters(inventoryData)
        manager.searchToInventoryType[inventoryData.stringSearch] = inventoryType
    end
    INVENTORY_FRAGMENT = ZO_FadeSceneFragment:New(ZO_PlayerInventory)
    INVENTORY_FRAGMENT:RegisterCallback("StateChange", function(oldState, newState)
        if(newState == SCENE_FRAGMENT_HIDDEN) then            
            ZO_InventorySlot_RemoveMouseOverKeybinds()
            ZO_PlayerInventory_EndSearch(ZO_PlayerInventorySearchBox)
            manager:ClearNewStatusOnItemsThePlayerHasSeen(INVENTORY_BACKPACK)
        end
    end)
    SHARED_INVENTORY:RegisterCallback("SlotAdded", function(bagId, slotIndex, newSlotData) 
        local inventory = manager.bagToInventoryType[bagId]
        if inventory then
            manager:OnInventoryItemAdded(inventory, bagId, slotIndex, newSlotData) 
        end
    end)
    SHARED_INVENTORY:RegisterCallback("SlotRemoved", function(bagId, slotIndex, oldSlotData) 
        local inventory = manager.bagToInventoryType[bagId]
        if inventory then
            manager:OnInventoryItemRemoved(inventory, bagId, slotIndex, oldSlotData) 
        end
    end)
    return manager
end
--General
---------
function ZO_InventoryManager:ChangeSort(newSortKey, inventoryType, newSortOrder)
    self.inventories[inventoryType].currentSortKey = newSortKey
    self.inventories[inventoryType].currentSortOrder = newSortOrder
    self:ApplySort(inventoryType)
    if(inventoryType == INVENTORY_BACKPACK) then
        self.inventories[INVENTORY_QUEST_ITEM].currentSortKey = newSortKey
        self.inventories[INVENTORY_QUEST_ITEM].currentSortOrder = newSortOrder
        self:ApplySort(INVENTORY_QUEST_ITEM)
    end
end
local function ForceSortDataOnInventory(inventory, sortKey, sortOrder)
    inventory.currentSortKey = sortKey
    inventory.currentSortOrder = sortOrder
end
function ZO_InventoryManager:ApplySort(inventoryType)
    local inventory = self.inventories[self.selectedTabType]    -- Use normal inventory by default...
    if(inventoryType == INVENTORY_BANK) then                    -- ...but override it if the desired type is actually bank or guild bank
        inventory = self.inventories[INVENTORY_BANK]
    elseif(inventoryType == INVENTORY_GUILD_BANK) then
        inventory = self.inventories[INVENTORY_GUILD_BANK]
    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
-- Might need to make this generic...store in filter data? Probably need a massive refactoring of how to determine which
-- columns are shown and what they are called when they're shown....
local filterTypeToValueColumnName =
{
    [ITEMFILTERTYPE_ARMOR] = SI_INVENTORY_SORT_TYPE_ARMOR,
    [ITEMFILTERTYPE_WEAPONS] = SI_INVENTORY_SORT_TYPE_POWER,
}
function ZO_InventoryManager:UpdateColumnText(inventory)
    local sortHeaders = inventory.sortHeaders
    if(sortHeaders) then
        sortHeaders:SetHeaderNameForKey("statValue", GetString(filterTypeToValueColumnName[inventory.currentFilter]))
    end
end
function ZO_InventoryManager:ChangeFilter(filterTab)
    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
    self:UpdateColumnText(displayInventory)
    -- 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)
        if(inventory.hiddenColumns[inventory.currentSortKey]) then
            -- User wanted to sort by a column that's gone!
            -- Fallback to name...the default sort is "age", 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)
        end
    end
    ZO_ScrollList_ResetToTop(inventory.listView)
    self:UpdateList(inventoryType)
    if inventoryType == INVENTORY_BACKPACK and INVENTORY_MENU_BAR then
        INVENTORY_MENU_BAR:UpdateInventoryKeybinds()
    end
end
function ZO_InventoryManager:SlotForInventoryControl(inventorySlotControl)
    local slotIndex = inventorySlotControl.slotIndex
    if(slotIndex) then
        local slotType = ZO_InventorySlot_GetType(inventorySlotControl)
        if(slotType == SLOT_TYPE_ITEM or slotType == SLOT_TYPE_GAMEPAD_INVENTORY_ITEM) then
            return self.inventories[INVENTORY_BACKPACK].slots[slotIndex]
        elseif(slotType == SLOT_TYPE_BANK_ITEM) then
            return self.inventories[INVENTORY_BANK].slots[slotIndex]
        end
    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
function ZO_InventoryManager:RefreshMoney(value)
    ZO_CurrencyControl_SetSimpleCurrency(ZO_PlayerInventoryInfoBarMoney, CURRENCY_TYPE_MONEY, value, INVENTORY_CURRENCY_OPTIONS)
    if self:IsBanking() then
        self:RefreshUpgradePossible()
    end
end
function ZO_InventoryManager:RefreshAlliancePoints(value)
    ZO_CurrencyControl_SetSimpleCurrency(ZO_PlayerInventoryInfoBarAlliancePoints, CURRENCY_TYPE_ALLIANCE_POINTS, value, INVENTORY_ALLIANCE_POINTS_OPTIONS)
end
function ZO_InventoryManager:UpdateFreeSlots(inventoryType)
    local inventory = self.inventories[inventoryType]
    if(inventory.freeSlotsLabel) then
        local numUsedSlots, numSlots = self:GetNumSlots(inventoryType)
        if(numUsedSlots < numSlots) then
            inventory.freeSlotsLabel:SetText(zo_strformat(inventory.freeSlotsStringId, numUsedSlots, numSlots))
        else
            inventory.freeSlotsLabel:SetText(zo_strformat(inventory.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_GUILD_BANK].filterBar, ITEMFILTERTYPE_ALL)
end
function ZO_InventoryManager:SetTradingHouseModeEnabled(enabled)
    local inventory = self.inventories[INVENTORY_BACKPACK]
    if(enabled) then    
        inventory.previousFilter = inventory.currentFilter
        inventory.currentFilter = TradingHouseFilter
    else
        inventory.currentFilter = inventory.previousFilter or ITEMFILTERTYPE_ALL
        inventory.previousFilter = nil
    end
    ZO_PlayerInventorySearchBox:SetHidden(not enabled)
    ZO_PlayerInventoryTabs:SetHidden(enabled)
    ZO_MenuBar_SelectDescriptor(inventory.filterBar, inventory.currentFilter)
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
--Inventory Item
----------------
function ZO_InventoryManager:AddInventoryItem(inventoryType, slotIndex)
    local inventory = self.inventories[inventoryType]
    local bagId = inventory.backingBag
    inventory.slots[slotIndex] = SHARED_INVENTORY:GenerateSingleSlotData(bagId, slotIndex)
end
function ZO_InventoryManager:UpdateNewStatus(inventoryType, slotIndex)
    local inventory = self.inventories[inventoryType]
    -- 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)
    local slot = inventory.slots[slotIndex]
    if(slot and slot.age ~= 0) then
        slot.clearAgeOnClose = true
    end
end
function ZO_InventoryManager:GetNumSlots(inventoryType)
    local inventory = self.inventories[inventoryType]
    return GetNumBagUsedSlots(inventory.backingBag), GetBagSize(inventory.backingBag)
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.hasAnyQuickSlottableItems == nil then
            inventory.hasAnyQuickSlottableItems = HasAnyQuickSlottableItems(inventory.slots)
        end
        return inventory.hasAnyQuickSlottableItems
    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)
    local inventory = self.inventories[inventoryType]
    local list = inventory.listView
    if(list) 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
            local slots = inventory.slots
            for slotIndex, slotData in pairs(slots) do
                if(self:ShouldAddSlotToList(inventory, slotData)) then
                    scrollData[#scrollData + 1] = ZO_ScrollList_CreateDataEntry(inventory.listDataType, slotData)
                end
            end
        end
        self.cachedSearchText = nil
        self:ApplySort(inventoryType)
        KEYBIND_STRIP:UpdateKeybindButtonGroup(self.bankWithdrawTabKeybindButtonGroup)
        if inventory.sortHeaders then
            inventory.sortHeaders.headerContainer:SetHidden(#scrollData == 0)
        end
    end
end
function ZO_InventoryManager:RefreshAllInventorySlots(inventoryType)
    local inventory = self.inventories[inventoryType]
    --Reset
    inventory.slots = {}
    inventory.hasAnyQuickSlottableItems = nil
    local search = inventory.stringSearch
    if(search) then
        search:RemoveAll()
    end
    self.suppressItemAddedAlert = true
    --Add items
    local bagSlots = GetBagSize(inventory.backingBag)
    for slotIndex = 0, bagSlots - 1 do
        self:AddInventoryItem(inventoryType, slotIndex)
    end
    if(inventoryType == INVENTORY_BACKPACK) then
        CALLBACK_MANAGER:FireCallbacks("BackpackFullUpdate")
    end
    self:LayoutInventoryItems(inventoryType)
    self.suppressItemAddedAlert = nil
end
function ZO_InventoryManager:RefreshInventorySlot(inventoryType, slotIndex)
    local inventory = self.inventories[inventoryType]
    inventory.hasAnyQuickSlottableItems = nil
    self:AddInventoryItem(inventoryType, slotIndex)
    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[slotIndex]
    if(slot and slot.slotControl) then
        CALLBACK_MANAGER:FireCallbacks("InventorySlotUpdate", GetControl(slot.slotControl, "Button"))
    end
end
function ZO_InventoryManager:LayoutInventoryItems(inventoryType)
    self:UpdateList(inventoryType)
    self:UpdateFreeSlots(inventoryType)
end
function ZO_InventoryManager:RefreshAllInventoryOverlays(inventoryType)
    local numSlots = GetBagSize(self.inventories[inventoryType].backingBag)
    for slotIndex = 0, numSlots - 1 do
        self:RefreshInventorySlotOverlay(inventoryType, slotIndex)
    end
end
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
function ZO_InventoryManager:ClearNewStatusOnItemsThePlayerHasSeen(inventoryType)
    local inventory = self.inventories[inventoryType]
    local numSlots = GetBagSize(inventory.backingBag)
    for slotIndex = 0, numSlots - 1 do
        local slot = inventory.slots[slotIndex]
        if ShouldClearAgeOnClose(slot, self) then
            slot.age = 0
            slot.clearAgeOnClose = nil
            slot.brandNew = false
        end
    end
    self:ApplySort(inventoryType)
    if(inventory.listView) then
        ZO_ScrollList_RefreshVisible(inventory.listView, slot, UpdateStatusControl)
    end
end
function ZO_InventoryManager:RefreshInventorySlotLocked(inventoryType, slotIndex, locked)
    local inventory = self.inventories[inventoryType]
    local slot = inventory.slots[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", button)
        end
    end
end
function ZO_InventoryManager:RefreshInventorySlotOverlay(inventoryType, slotIndex)
    local inventory = self.inventories[inventoryType]
    local slot = inventory.slots[slotIndex]
    if slot then
        local _, _, _, meetsUsageRequirement, _ = GetItemInfo(inventory.backingBag, 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", button)
            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[slotIndex]
    return ((slot ~= nil) and (slot.stackCount > 0))
end
function ZO_InventoryManager:GenerateListOfVirtualStackedItems(inventoryType, predicate, itemIds)
    local inventory = self.inventories[inventoryType]
    itemIds = itemIds or {}
    local bagSlots = GetBagSize(inventory.backingBag)
    for i = 0, bagSlots - 1 do
        if not predicate or predicate(inventory.backingBag, i) then
            local itemId = GetItemInstanceId(inventory.backingBag, i)
            if itemId then
                local _, stackCount = GetItemInfo(inventory.backingBag, i)
                if itemIds[itemId] then
                    itemIds[itemId].stack = itemIds[itemId].stack + stackCount
                else
                    itemIds[itemId] = { bag = inventory.backingBag, index = i, stack = stackCount }
                end
            end
        end
    end
    return itemIds
end
--Backpack
----------
function ZO_InventoryManager:GetNumBackpackSlots()
    local inventory = self.inventories[INVENTORY_BACKPACK]
    return GetBagSize(inventory.backingBag)
end
function ZO_InventoryManager:GetBackpackItem(slotIndex)
    local inventory = self.inventories[INVENTORY_BACKPACK]
    return inventory.slots[slotIndex]
end
function ZO_InventoryManager:ApplyBackpackLayout(layoutData)
    if(layoutData == self.appliedLayout and not layoutData.alwaysReapplyLayout) then
        return
    end
    
    self.appliedLayout = layoutData
    local inventoryControl = ZO_PlayerInventory
    inventoryControl:ClearAnchors()
    inventoryControl:SetAnchor(TOPLEFT, ZO_SharedRightPanelBackground, TOPLEFT, 0, layoutData.inventoryTopOffsetY)
    inventoryControl:SetAnchor(BOTTOMLEFT, ZO_SharedRightPanelBackground, BOTTOMLEFT, 0, layoutData.inventoryBottomOffsetY)
    local backpack = inventoryControl:GetNamedChild("Backpack")
    backpack:SetWidth(layoutData.width)
    backpack:ClearAnchors()
    backpack:SetAnchor(TOPRIGHT, nil, TOPRIGHT, 0, layoutData.backpackOffsetY)
    backpack:SetAnchor(BOTTOMRIGHT)
    ZO_ScrollList_SetHeight(backpack, backpack:GetHeight())
    ZO_ScrollList_Commit(backpack)
    local sortHeaders = inventoryControl:GetNamedChild("SortBy")
    sortHeaders:ClearAnchors()
    sortHeaders:SetAnchor(TOPRIGHT, nil, TOPRIGHT, 0, layoutData.sortByOffsetY)
    sortHeaders:SetWidth(layoutData.width)
    local sortByName = sortHeaders:GetNamedChild("Name")
    sortByName:SetWidth(layoutData.sortByNameWidth)
    
    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
    ZO_MenuBar_SelectDescriptor(self.inventories[INVENTORY_BACKPACK].filterBar, ITEMFILTERTYPE_ALL)
    ZO_PlayerInventoryInfoBarAlliancePoints:SetHidden(layoutData.hideAlliancePoints)
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
    if not inventory.slots[questItem.questIndex] then
        inventory.slots[questItem.questIndex] = {}
    end
    table.insert(inventory.slots[questItem.questIndex], questItem)
    local index = #inventory.slots[questItem.questIndex]
    if(searchType == SEARCH_TYPE_QUEST_ITEM) then
        questItem.searchData = {type = SEARCH_TYPE_QUEST_ITEM, questIndex = questItem.questIndex, stepIndex = questItem.stepIndex, conditionIndex = questItem.conditionIndex, index = index }
    else
        questItem.searchData = {type = SEARCH_TYPE_QUEST_TOOL, questIndex = questItem.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_BankDepositWithdrawDialog = ZO_Object:Subclass()
function ZO_BankDepositWithdrawDialog:New(...)
    local obj = ZO_Object.New(self)
    obj:Initialize(...)
    return obj
end
function ZO_BankDepositWithdrawDialog:Initialize(prefix, control, queryFunction, depositFunction, withdrawFunction)
    self.control = control
    self.depositWithdrawCurrency = control:GetNamedChild("DepositWithdrawCurrency")
    ZO_Dialogs_RegisterCustomDialog(prefix.."_WITHDRAW_GOLD",
    {
        customControl = control,
        title =
        {
            text = SI_BANK_WITHDRAW_GOLD_TITLE,
        },
        setup = function(dialog)
            self:SetupWithdraw(dialog)
        end,
        buttons =
        {
            {
                control = ZO_PlayerBankDepositWithdrawGold:GetNamedChild("DepositWithdraw"),
                text = SI_BANK_WITHDRAW_GOLD,
                callback = function(dialog)
                                local amount = ZO_DefaultMoneyInputField_GetMoney(self.depositWithdrawCurrency)
                                if amount > 0 then
                                    withdrawFunction(amount)
                                end
                            end,
            },
            {
                control = ZO_PlayerBankDepositWithdrawGold:GetNamedChild("Cancel"),
                text = SI_DIALOG_CANCEL,
            }
        }
    })
    ZO_Dialogs_RegisterCustomDialog(prefix.."_DEPOSIT_GOLD",
    {
        customControl = control,
        title =
        {
            text = SI_BANK_DEPOSIT_GOLD_TITLE,
        },
        setup = function(dialog)
            self:SetupDeposit(dialog)
        end,
        buttons =
        {
            {
                control = ZO_PlayerBankDepositWithdrawGold:GetNamedChild("DepositWithdraw"),
                text = SI_BANK_DEPOSIT_GOLD,
                callback = function(dialog)
                                local amount = ZO_DefaultMoneyInputField_GetMoney(self.depositWithdrawCurrency)
                                if amount > 0 then
                                    depositFunction(amount)
                                end
                            end,
            },
            {
                control = ZO_PlayerBankDepositWithdrawGold:GetNamedChild("Cancel"),
                text = SI_DIALOG_CANCEL,
            }
        }
    })
end
function ZO_BankDepositWithdrawDialog:UpdateDepositWithdrawGold()
    self.control:GetNamedChild("CarriedGold"):SetText(zo_strformat(SI_BANK_GOLD_AMOUNT_CARRIED, ZO_CurrencyControl_FormatCurrency(GetCurrentMoney())))
    self.control:GetNamedChild("BankedGold"):SetText(zo_strformat(SI_BANK_GOLD_AMOUNT_BANKED, ZO_CurrencyControl_FormatCurrency(self.queryFunction())))
end
function ZO_BankDepositWithdrawDialog:SetupDeposit(dialog)
    dialog:GetNamedChild("Text"):SetText(GetString(SI_BANK_GOLD_AMOUNT_TO_DEPOSIT))
    ZO_DefaultMoneyInputField_Initialize(self.depositWithdrawCurrency)
    ZO_DefaultMoneyInputField_SetUsePlayerGoldAsMax(self.depositWithdrawCurrency, true)
    self.depositWithdrawCurrency.OnBeginInput()
end
function ZO_BankDepositWithdrawDialog:SetupWithdraw(dialog)
    dialog:GetNamedChild("Text"):SetText(GetString(SI_BANK_GOLD_AMOUNT_TO_WITHDRAW))
    ZO_DefaultMoneyInputField_Initialize(self.depositWithdrawCurrency)
    ZO_DefaultMoneyInputField_SetGoldMax(self.depositWithdrawCurrency, self.queryFunction())
    self.depositWithdrawCurrency.OnBeginInput()
end
function ZO_InventoryManager:CreateBankScene()
    BANK_FRAGMENT = ZO_FadeSceneFragment:New(ZO_PlayerBank)
    local bankingInteraction =
    {
        type = "Banking",
        interactTypes = { INTERACTION_BANK },
    }
    ZO_BankDepositWithdrawDialog:New("BANK", ZO_PlayerBankDepositWithdrawGold, GetBankedMoney, DepositMoneyIntoBank, WithdrawMoneyFromBank)
    self.bankWithdrawTabKeybindButtonGroup = {
        alignment = KEYBIND_STRIP_ALIGN_CENTER,
        {
            name = function()
                local iconTexture = "EsoUI/Art/currency/currency_gold.dds"
                local iconMarkup = zo_iconFormat(iconTexture, 24, 24)
                local cost = GetNextBankUpgradePrice()
                if GetCurrentMoney() >= cost then
                    return zo_strformat(SI_BANK_UPGRADE_TEXT, ZO_CurrencyControl_FormatCurrency(cost), iconMarkup)
                end
                return zo_strformat(SI_BANK_UPGRADE_TEXT, ZO_ERROR_COLOR:Colorize(ZO_CurrencyControl_FormatCurrency(cost)), iconMarkup)
            end,
            keybind = "UI_SHORTCUT_TERTIARY",
            visible = IsBankUpgradeAvailable,
            callback = DisplayBankUpgrade,
        },
        {
            name = GetString(SI_BANK_WITHDRAW_GOLD_BIND),
            keybind = "UI_SHORTCUT_SECONDARY",
            callback = function() ZO_Dialogs_ShowDialog("BANK_WITHDRAW_GOLD") end,
        }
    }
    self.bankDepositTabKeybindButtonGroup = {
        alignment = KEYBIND_STRIP_ALIGN_CENTER,
        {
            name = GetString(SI_BANK_DEPOSIT_GOLD_BIND),
            keybind = "UI_SHORTCUT_SECONDARY",
            callback = function() ZO_Dialogs_ShowDialog("BANK_DEPOSIT_GOLD") end,
        }
    }
    local function CreateButtonData(normal, pressed, highlight)
        return {
            normal = normal,
            pressed = pressed,
            highlight = highlight,
        }
    end
    local bankFragmentBar = ZO_SceneFragmentBar:New(ZO_PlayerBankMenuBar)
    --Withdraw Button
    local withdrawButtonData = CreateButtonData("EsoUI/Art/Bank/bank_tabIcon_withdraw_up.dds",
                                               "EsoUI/Art/Bank/bank_tabIcon_withdraw_down.dds",
                                               "EsoUI/Art/Bank/bank_tabIcon_withdraw_over.dds")
    bankFragmentBar:Add(SI_BANK_WITHDRAW, { BANK_FRAGMENT }, withdrawButtonData, self.bankWithdrawTabKeybindButtonGroup)
    --Deposit Button
    local depositButtonData = CreateButtonData("EsoUI/Art/Bank/bank_tabIcon_deposit_up.dds",
                                                "EsoUI/Art/Bank/bank_tabIcon_deposit_down.dds", 
                                                "EsoUI/Art/Bank/bank_tabIcon_deposit_over.dds")
    bankFragmentBar:Add(SI_BANK_DEPOSIT, { INVENTORY_FRAGMENT, BACKPACK_BANK_LAYOUT_FRAGMENT }, depositButtonData, self.bankDepositTabKeybindButtonGroup)
    
    local bankScene = ZO_InteractScene:New("bank", SCENE_MANAGER, bankingInteraction)
    bankScene:RegisterCallback("StateChange",   function(oldState, newState)
                                                    if(newState == SCENE_SHOWING) then
                                                        self:RefreshAllInventorySlots(INVENTORY_BANK)
                                                        self:RefreshMoney(GetCurrentMoney())
                                                        self:RefreshBankedMoney(GetBankedMoney())
                                                        self:RefreshAlliancePoints(GetAlliancePoints())
                                                        bankFragmentBar:SelectFragment(SI_BANK_WITHDRAW)                                                        
                                                    elseif(newState == SCENE_HIDDEN) then
                                                        ZO_InventorySlot_RemoveMouseOverKeybinds()                                                       
                                                        ZO_PlayerInventory_EndSearch(ZO_PlayerBankSearchBox)
                                                        bankFragmentBar:Clear()
                                                    end
                                                end)
end
function ZO_InventoryManager:IsBanking()
    return GetInteractionType() == INTERACTION_BANK
end
function ZO_InventoryManager:RefreshUpgradePossible()
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.bankDepositTabKeybindButtonGroup)
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.bankWithdrawTabKeybindButtonGroup)
end
function ZO_InventoryManager:GetBankItem(slotIndex)
    return self.inventories[INVENTORY_BANK].slots[slotIndex]
end
function ZO_InventoryManager:RefreshBankedMoney(value)
    if self:IsBanking() then
        ZO_CurrencyControl_SetSimpleCurrency(ZO_PlayerBankInfoBarMoney, CURRENCY_TYPE_MONEY, value, INVENTORY_BANKED_CURRENCY_OPTIONS)
    end
end
--Guild Bank
--------------
function ZO_InventoryManager:CreateGuildBankScene()
    GUILD_BANK_FRAGMENT = ZO_FadeSceneFragment:New(ZO_GuildBank)
    ZO_BankDepositWithdrawDialog:New("GUILD_BANK", ZO_PlayerBankDepositWithdrawGold, GetGuildBankedMoney, DepositMoneyIntoGuildBank, WithdrawMoneyFromGuildBank)
    self.guildBankWithdrawTabKeybindButtonGroup = {
        alignment = KEYBIND_STRIP_ALIGN_CENTER,
        {
            name = function()
                local selectedGuildId = GetSelectedGuildBankId()
                if(selectedGuildId) then
                    return GetGuildName(selectedGuildId)
                end
            end,
            keybind = "UI_SHORTCUT_TERTIARY",
            visible =   function()
                            return GetSelectedGuildBankId() ~= nil
                        end,
            callback =  function()
                            ZO_Dialogs_ShowDialog("SELECT_GUILD_BANK")
                        end,
        },
        {
            name = GetString(SI_BANK_WITHDRAW_GOLD_BIND),
            keybind = "UI_SHORTCUT_SECONDARY",
            callback = function() ZO_Dialogs_ShowDialog("GUILD_BANK_WITHDRAW_GOLD") end,
            visible =   function()
                            local guildId = GetSelectedGuildBankId()
                            return guildId ~= nil and DoesPlayerHaveGuildPermission(guildId, GUILD_PERMISSION_BANK_WITHDRAW_GOLD)
                        end,
        }
    }
    self.guildBankDepositTabKeybindButtonGroup = {
        alignment = KEYBIND_STRIP_ALIGN_CENTER,
        {
            name = function()
                local selectedGuild = GetSelectedGuildBankId()
                if(selectedGuild) then
                    return GetGuildName(selectedGuild)
                end
            end,
            keybind = "UI_SHORTCUT_TERTIARY",
            visible =   function()
                            return GetSelectedGuildBankId() ~= nil
                        end,
            callback =  function()
                            ZO_Dialogs_ShowDialog("SELECT_GUILD_BANK")
                        end,
        },
        {
            name = GetString(SI_BANK_DEPOSIT_GOLD_BIND),
            keybind = "UI_SHORTCUT_SECONDARY",
            callback = function() ZO_Dialogs_ShowDialog("GUILD_BANK_DEPOSIT_GOLD") end,
            visible =   function()
                            return DoesGuildHavePrivilege(GetSelectedGuildBankId(), GUILD_PRIVILEGE_BANK_DEPOSIT)
                        end,
        }
    }
    local function CreateButtonData(normal, pressed, highlight)
        return {
            normal = normal,
            pressed = pressed,
            highlight = highlight,
        }
    end
    local guildBankFragmentBar = ZO_SceneFragmentBar:New(ZO_GuildBankMenuBar)
    --Withdraw Button
    local withdrawButtonData = CreateButtonData("EsoUI/Art/Bank/bank_tabIcon_withdraw_up.dds",
                                               "EsoUI/Art/Bank/bank_tabIcon_withdraw_down.dds",
                                               "EsoUI/Art/Bank/bank_tabIcon_withdraw_over.dds")
    guildBankFragmentBar:Add(SI_BANK_WITHDRAW, { GUILD_BANK_FRAGMENT }, withdrawButtonData, self.guildBankWithdrawTabKeybindButtonGroup)
    --Deposit Button
    local depositButtonData = CreateButtonData("EsoUI/Art/Bank/bank_tabIcon_deposit_up.dds",
                                                "EsoUI/Art/Bank/bank_tabIcon_deposit_down.dds", 
                                                "EsoUI/Art/Bank/bank_tabIcon_deposit_over.dds")
    guildBankFragmentBar:Add(SI_BANK_DEPOSIT, { INVENTORY_FRAGMENT, BACKPACK_BANK_LAYOUT_FRAGMENT }, depositButtonData, self.guildBankDepositTabKeybindButtonGroup)
    local guildBankScene = ZO_InteractScene:New("guildBank", SCENE_MANAGER, GUILD_BANKING_INTERACTION)
    guildBankScene:RegisterCallback("StateChange",  function(oldState, newState)
                                                        if(newState == SCENE_SHOWING) then
                                                            self:RefreshMoney(GetCurrentMoney())
                                                            self:RefreshAlliancePoints(GetAlliancePoints())
                                                            guildBankFragmentBar:SelectFragment(SI_BANK_WITHDRAW)
                                                            ZO_SharedInventory_SelectAccessibleGuildBank(self.lastSuccessfulGuildBankId)
                                                        elseif(newState == SCENE_HIDDEN) then
                                                            guildBankFragmentBar:Clear()
                                                            ZO_InventorySlot_RemoveMouseOverKeybinds()
                                                            ZO_PlayerInventory_EndSearch(ZO_PlayerBankSearchBox)
                                                        end
                                                    end)
end
function ZO_InventoryManager:OpenGuildBank()
    SCENE_MANAGER:Show("guildBank")
end
function ZO_InventoryManager:IsGuildBanking()
    return GetSelectedGuildBankId() ~= nil
end
function ZO_InventoryManager:CloseGuildBank()
    SCENE_MANAGER:Hide("guildBank")
    ZO_GuildBankBackpackLoading:SetHidden(true)
end
function ZO_InventoryManager:RefreshAllGuildBankItems()
    local inventory = self.inventories[INVENTORY_GUILD_BANK]
    --Reset
    inventory.slots = {}
    inventory.hasAnyQuickSlottableItems = nil
    local search = inventory.stringSearch
    if(search) then
        search:RemoveAll()
    end
    self.suppressItemAddedAlert = true
    --Add items
    local bagSlots = GetBagSize(BAG_GUILDBANK)
    local slotId = GetNextGuildBankSlotId()
    while slotId do
        self:AddInventoryItem(INVENTORY_GUILD_BANK, slotId)
        slotId = GetNextGuildBankSlotId(slotId)
    end 
    self:LayoutInventoryItems(INVENTORY_GUILD_BANK)
    self.suppressItemAddedAlert = nil   
end
function ZO_InventoryManager:ClearAllGuildBankItems()
    local inventory = self.inventories[INVENTORY_GUILD_BANK]
    
    --Reset
    inventory.slots = {}
    local search = inventory.stringSearch
    if(search) then
        search:RemoveAll()
    end
    self:LayoutInventoryItems(INVENTORY_GUILD_BANK)
end
function ZO_InventoryManager:SetGuildBankLoading(guildId)
    self.loadingGuildBank = true
    ZO_GuildBankBackpackLoading:Show()
    if GUILD_BANK_FRAGMENT:IsShowing() then
        KEYBIND_STRIP:UpdateKeybindButtonGroup(self.guildBankWithdrawTabKeybindButtonGroup)
    else
        KEYBIND_STRIP:UpdateKeybindButtonGroup(self.guildBankDepositTabKeybindButtonGroup)
    end
end
function ZO_InventoryManager:SetGuildBankLoaded()
    self.loadingGuildBank = false
    self.lastSuccessfulGuildBankId = GetSelectedGuildBankId()
    ZO_GuildBankBackpackLoading:Hide()
end
function ZO_InventoryManager:OnGuildBankOpenError(error)
    if(self.loadingGuildBank) then
        self.loadingGuildBank = false
        ZO_GuildBankBackpackLoading:Hide()
    end
    ZO_SharedInventory_SelectAccessibleGuildBank(self.lastSuccessfulGuildBankId)
end
function ZO_InventoryManager:OnGuildBankDeselected()
    ZO_SharedInventory_SelectAccessibleGuildBank(self.lastSuccessfulGuildBankId)
    ZO_Dialogs_ReleaseDialog("GUILD_BANK_WITHDRAW_GOLD")
    ZO_Dialogs_ReleaseDialog("GUILD_BANK_DEPOSIT_GOLD")
end
function ZO_InventoryManager:RefreshGuildBankedMoney()
    if self:IsGuildBanking() then
        ZO_GuildBankInfoBarMoney:SetHidden(false)
        ZO_CurrencyControl_SetSimpleCurrency(ZO_GuildBankInfoBarMoney, CURRENCY_TYPE_MONEY, GetGuildBankedMoney(), INVENTORY_BANKED_CURRENCY_OPTIONS)
    else
        ZO_GuildBankInfoBarMoney:SetHidden(true)
    end
end
function ZO_InventoryManager:RefreshGuildBankMoneyOperationsPossible(guildId)
    if(GetSelectedGuildBankId() == guildId) then
        if(not DoesPlayerHaveGuildPermission(guildId, GUILD_PERMISSION_BANK_WITHDRAW_GOLD)) then
            ZO_Dialogs_ReleaseDialog("GUILD_BANK_WITHDRAW_GOLD")
        end
        KEYBIND_STRIP:UpdateKeybindButtonGroup(self.guildBankWithdrawTabKeybindButtonGroup)
    end
end
function ZO_InventoryManager:GuildSizeChanged()
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.guildBankDepositTabKeybindButtonGroup)
end
------------
--Global API
------------
function ZO_InventoryManager_SetQuestToolData(slotControl, questIndex, toolIndex)
    local questItems = PlayerInventory.inventories[INVENTORY_QUEST_ITEM].slots[questIndex]
    if(questItems) then
        for i = 1, #questItems do
            if(questItems[i].toolIndex == toolIndex) then
                local questItem = questItems[i]
                ZO_Inventory_SetupQuestSlot(slotControl, questItem.questIndex, questItem.toolIndex, questItem.stepIndex, questItem.conditionIndex)
                ZO_InventorySlot_SetType(slotControl, SLOT_TYPE_QUEST_ITEM)
                ZO_InventorySlot_UpdateCooldowns(slotControl)
            end
        end
    end
end
----------------
--Event Handlers
----------------
local function OnPlayerActivated()
    PlayerInventory:RefreshAllInventorySlots(INVENTORY_BACKPACK)
end
local function OnFullInventoryUpdated(bagId)
    if bagId == BAG_BACKPACK or bagId == BAG_BANK then
        PlayerInventory:RefreshAllInventorySlots(INVENTORY_BACKPACK)
        if(PlayerInventory:IsBanking()) then
            PlayerInventory:RefreshAllInventorySlots(INVENTORY_BANK)
            PlayerInventory:RefreshUpgradePossible()
        end
    end
end
local function OnInventorySlotUpdated(bagId, slotIndex)
    if(bagId == PlayerInventory.inventories[INVENTORY_BACKPACK].backingBag) then
        PlayerInventory:RefreshInventorySlot(INVENTORY_BACKPACK, slotIndex)
    elseif(PlayerInventory:IsBanking() and bagId == PlayerInventory.inventories[INVENTORY_BANK].backingBag) then
        PlayerInventory:RefreshInventorySlot(INVENTORY_BANK, slotIndex)
    elseif bagId == PlayerInventory.inventories[INVENTORY_GUILD_BANK].backingBag then
        PlayerInventory:RefreshInventorySlot(INVENTORY_GUILD_BANK, slotIndex)
    end
end
local function OnInventorySlotLocked(eventCode, bagId, slotIndex)
    if(bagId == PlayerInventory.inventories[INVENTORY_BACKPACK].backingBag) then
        PlayerInventory:RefreshInventorySlotLocked(INVENTORY_BACKPACK, slotIndex, true)
    elseif(PlayerInventory:IsBanking() and bagId == PlayerInventory.inventories[INVENTORY_BANK].backingBag) then
        PlayerInventory:RefreshInventorySlotLocked(INVENTORY_BANK, slotIndex, true)
    end
end
local function OnInventorySlotUnlocked(eventCode, bagId, slotIndex)
    if(bagId == PlayerInventory.inventories[INVENTORY_BACKPACK].backingBag) then
        PlayerInventory:RefreshInventorySlotLocked(INVENTORY_BACKPACK, slotIndex, false)
    elseif(PlayerInventory:IsBanking() and bagId == PlayerInventory.inventories[INVENTORY_BANK].backingBag) then
        PlayerInventory:RefreshInventorySlotLocked(INVENTORY_BANK, slotIndex, false)
    end
end
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 itemLink = GetItemLink(bag, slot)
    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 = {itemLink, itemCount, GetString(SI_DESTROY_ITEM_CONFIRMATION)}})
    else
        ZO_Dialogs_ShowPlatformDialog("DESTROY_ITEM_PROMPT", nil, {mainTextParams = {itemLink, itemCount}})
    end
end
local function OnCancelRequestDestroyItem()
    ZO_Dialogs_ReleaseDialog("DESTROY_ITEM_PROMPT")
    ZO_Dialogs_ReleaseDialog("CONFIRM_DESTROY_ITEM_PROMPT")
    ZO_Dialogs_ReleaseDialog(ZO_GAMEPAD_CONFIRM_DESTROY_DIALOG)
end
local function OnLevelUpdate(eventCode, tag, level)
    if(tag == "player") then
        PlayerInventory:RefreshAllInventoryOverlays(INVENTORY_BACKPACK)
    end
end
local function OnQuestsUpdated()
    --the quest we were planning to abandon may be gone, kill the prompt
    ZO_Dialogs_ReleaseDialog("ABANDON_QUEST")
    PlayerInventory:RefreshAllQuests()
    CALLBACK_MANAGER:FireCallbacks("QuestUpdate")
end
local function OnSingleQuestUpdated(journalIndex)
    PlayerInventory:RefreshQuest(journalIndex)
    CALLBACK_MANAGER:FireCallbacks("QuestUpdate")
end
local function OnUpdateCooldowns(eventCode)
    PlayerInventory:UpdateItemCooldowns(INVENTORY_BACKPACK)
    PlayerInventory:UpdateItemCooldowns(INVENTORY_QUEST_ITEM)
end
local function OnOpenBank()
    if not IsInGamepadPreferredMode() then
        SCENE_MANAGER:Show("bank")
    end
end
local function OnCloseBank()
    if not IsInGamepadPreferredMode() then
        SCENE_MANAGER:Hide("bank")
    end
end
local function OnOpenGuildBank()
    if not IsInGamepadPreferredMode() then
        PlayerInventory:OpenGuildBank()
    end
end
local function OnCloseGuildBank()
    if not IsInGamepadPreferredMode() then
        PlayerInventory:CloseGuildBank()
    end
end
local function OnGuildBankSelected(eventCode, guildId)
    PlayerInventory:SetGuildBankLoading(guildId)
end
local function OnGuildBankDeselected()
    PlayerInventory:OnGuildBankDeselected()
end
local function OnGuildBankItemsReady()
    PlayerInventory:SetGuildBankLoaded()
end
local function OnGuildBankOpenError(eventCode, error)
    PlayerInventory:OnGuildBankOpenError(error)
end
local function OnMoneyUpdated(eventCode, newMoney, oldMoney, reason)
    PlayerInventory:RefreshMoney(newMoney)
    local wasInitialize = (reason == CURRENCY_CHANGE_REASON_PLAYER_INIT)
    local wasItemPurchased = (reason == CURRENCY_CHANGE_REASON_VENDOR) and (newMoney < oldMoney)
    if(not (wasItemPurchased or wasInitialize)) then
        PlaySound(SOUNDS.ITEM_MONEY_CHANGED)
    end
end
local function OnBankedMoneyUpdated(eventCode, newMoney, oldMoney)
    PlayerInventory:RefreshBankedMoney(newMoney)
end
local function OnGuildSizeChanged()
    PlayerInventory:GuildSizeChanged()
end
local function OnGuildBankedMoneyUpdated(eventCode, newMoney, oldMoney)
    PlayerInventory:RefreshGuildBankedMoney()
end
local function OnAlliancePointsUpdated(eventCode, alliancePoints, playSound, difference)
    PlayerInventory:RefreshAlliancePoints(alliancePoints)
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 OnBoughtBagSpace()
    PLAYER_INVENTORY:UpdateFreeSlots(INVENTORY_BACKPACK)
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 OnBoughtBankSpace()
    PLAYER_INVENTORY:UpdateFreeSlots(INVENTORY_BANK)
end
local function OnCloseBuySpace()
    ZO_Dialogs_ReleaseDialog("BUY_BAG_SPACE")
    ZO_Dialogs_ReleaseDialog("BUY_BANK_SPACE")
    BUY_BAG_SPACE_GAMEPAD:Hide()
end
local function OnPlayerDead()
    PlayerInventory:RefreshAllInventoryOverlays(INVENTORY_BACKPACK)
    PlayerInventory.itemsLockedDueToDeath = true
end
local function OnPlayerAlive()
    PlayerInventory:RefreshAllInventoryOverlays(INVENTORY_BACKPACK)
    PlayerInventory.itemsLockedDueToDeath = false
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_PlayerInventoryBackpackLandingArea, false, SI_INVENTORY_LANDING_AREA_MOVE_TO_BACKPACK)
    elseif(cursorType == MOUSE_CONTENT_STORE_ITEM) then
        ZO_InventoryLandingArea_SetHidden(ZO_PlayerInventoryBackpackLandingArea, false, SI_INVENTORY_LANDING_AREA_BUY_ITEM)
    elseif(cursorType == MOUSE_CONTENT_STORE_BUYBACK_ITEM) then
        ZO_InventoryLandingArea_SetHidden(ZO_PlayerInventoryBackpackLandingArea, 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_PlayerInventoryBackpackLandingArea, true)
end
local function OnGuildRanksChanged(_, guildId)
    PlayerInventory:RefreshGuildBankMoneyOperationsPossible(guildId)
end
local function OnGuildRankChanged(_, guildId)
    PlayerInventory:RefreshGuildBankMoneyOperationsPossible(guildId)
end
local function OnGuildMemberRankChanged(_, guildId, displayName)
    if(displayName == GetDisplayName()) then
        PlayerInventory:RefreshGuildBankMoneyOperationsPossible(guildId)
    end
end
--------------
--XML Handlers
--------------
--Inventory
-----------
    if(editBox == ZO_PlayerInventorySearchBox) then
        PlayerInventory:UpdateList(PlayerInventory.selectedTabType)
    else
        PlayerInventory:UpdateList(INVENTORY_BANK)
    end
end
function ZO_PlayerInventory_BeginSearch(editBox)
    editBox:TakeFocus()
end
function ZO_PlayerInventory_EndSearch(editBox)
    editBox:SetText("")
    editBox:LoseFocus()
end
    -- Do not clear the search, just unfocus the box, the appropriate items are now highlighted and should stay that way
    editBox:LoseFocus()
end
    InitializeTooltip(InformationTooltip, self, BOTTOM, 0, -10)
    SetTooltipText(InformationTooltip, ZO_MenuBarButtonTemplate_GetData(self).tooltipText)
end
    ClearTooltip(InformationTooltip)
end
--Bank
------
function ZO_PlayerInventory_InitSortHeader(header, stringId, textAlignment, sortKey)
    ZO_SortHeader_Initialize(header, GetString(stringId), sortKey, ZO_SORT_ORDER_UP, textAlignment or TEXT_ALIGN_LEFT, "ZoFontHeader")
end
function ZO_PlayerInventory_InitSortHeaderIcon(header, icon, sortUpIcon, sortDownIcon, mouseoverIcon, sortKey)
    ZO_SortHeader_InitializeIconHeader(header, icon, sortUpIcon, sortDownIcon, mouseoverIcon, sortKey, ZO_SORT_ORDER_UP)
end
    PlayerInventory = ZO_InventoryManager:New()
    PLAYER_INVENTORY = PlayerInventory
    PlayerInventory.itemsLockedDueToDeath = IsUnitDead("player")
    PlayerInventory:SetupInitialFilter()
    --inventory events
    SHARED_INVENTORY:RegisterCallback("FullInventoryUpdate", OnFullInventoryUpdated)
    SHARED_INVENTORY:RegisterCallback("SingleSlotInventoryUpdate", OnInventorySlotUpdated)
    ZO_PlayerInventory:RegisterForEvent(EVENT_INVENTORY_SLOT_LOCKED, OnInventorySlotLocked)
    ZO_PlayerInventory:RegisterForEvent(EVENT_INVENTORY_SLOT_UNLOCKED, OnInventorySlotUnlocked)
    ZO_PlayerInventory:RegisterForEvent(EVENT_MOUSE_REQUEST_DESTROY_ITEM, OnRequestDestroyItem)
    ZO_PlayerInventory:RegisterForEvent(EVENT_CANCEL_MOUSE_REQUEST_DESTROY_ITEM, OnCancelRequestDestroyItem)
    ZO_PlayerInventory:RegisterForEvent(EVENT_LEVEL_UPDATE, OnLevelUpdate)
    ZO_PlayerInventory:RegisterForEvent(EVENT_CURSOR_PICKUP, HandleCursorPickup)
    ZO_PlayerInventory:RegisterForEvent(EVENT_CURSOR_DROPPED, HandleCursorCleared)
    ZO_PlayerInventory:RegisterForEvent(EVENT_PLAYER_ACTIVATED, OnPlayerActivated)
    ZO_PlayerInventory:RegisterForEvent(EVENT_MONEY_UPDATE, OnMoneyUpdated)
    ZO_PlayerInventory:RegisterForEvent(EVENT_ALLIANCE_POINT_UPDATE, OnAlliancePointsUpdated)
    --quest item events
    SHARED_INVENTORY:RegisterCallback("FullQuestUpdate", OnQuestsUpdated)
    SHARED_INVENTORY:RegisterCallback("SingleQuestUpdate", OnSingleQuestUpdated)
    ZO_PlayerInventory:RegisterForEvent(EVENT_ACTION_UPDATE_COOLDOWNS, OnUpdateCooldowns)
    --bank events
    ZO_PlayerInventory:RegisterForEvent(EVENT_OPEN_BANK, OnOpenBank)
    ZO_PlayerInventory:RegisterForEvent(EVENT_CLOSE_BANK, OnCloseBank)
    ZO_PlayerInventory:RegisterForEvent(EVENT_BANKED_MONEY_UPDATE, OnBankedMoneyUpdated)
    --guild bank events
    ZO_PlayerInventory:RegisterForEvent(EVENT_OPEN_GUILD_BANK, OnOpenGuildBank)
    ZO_PlayerInventory:RegisterForEvent(EVENT_CLOSE_GUILD_BANK, OnCloseGuildBank)
    ZO_PlayerInventory:RegisterForEvent(EVENT_GUILD_BANK_SELECTED, OnGuildBankSelected)
    ZO_PlayerInventory:RegisterForEvent(EVENT_GUILD_BANK_DESELECTED, OnGuildBankDeselected)
    ZO_PlayerInventory:RegisterForEvent(EVENT_GUILD_BANK_ITEMS_READY, OnGuildBankItemsReady)
    ZO_PlayerInventory:RegisterForEvent(EVENT_GUILD_BANK_OPEN_ERROR, OnGuildBankOpenError)
    ZO_PlayerInventory:RegisterForEvent(EVENT_GUILD_BANKED_MONEY_UPDATE, OnGuildBankedMoneyUpdated)
    ZO_PlayerInventory:RegisterForEvent(EVENT_GUILD_RANKS_CHANGED, OnGuildRanksChanged)
    ZO_PlayerInventory:RegisterForEvent(EVENT_GUILD_RANK_CHANGED, OnGuildRankChanged)
    ZO_PlayerInventory:RegisterForEvent(EVENT_GUILD_MEMBER_RANK_CHANGED, OnGuildMemberRankChanged)
    ZO_PlayerInventory:RegisterForEvent(EVENT_GUILD_MEMBER_ADDED, OnGuildSizeChanged)
    ZO_PlayerInventory:RegisterForEvent(EVENT_GUILD_MEMBER_REMOVED, OnGuildSizeChanged)
    
    --inventory upgrade events
    ZO_PlayerInventory:RegisterForEvent(EVENT_INVENTORY_BUY_BAG_SPACE, OnBuyBagSpace)
    ZO_PlayerInventory:RegisterForEvent(EVENT_INVENTORY_BOUGHT_BAG_SPACE, OnBoughtBagSpace)
    ZO_PlayerInventory:RegisterForEvent(EVENT_INVENTORY_BUY_BANK_SPACE, OnBuyBankSpace)
    ZO_PlayerInventory:RegisterForEvent(EVENT_INVENTORY_BOUGHT_BANK_SPACE, OnBoughtBankSpace)
    ZO_PlayerInventory:RegisterForEvent(EVENT_INVENTORY_CLOSE_BUY_SPACE, OnCloseBuySpace)
    --player events
    ZO_PlayerInventory:RegisterForEvent(EVENT_PLAYER_DEAD, OnPlayerDead)
    ZO_PlayerInventory:RegisterForEvent(EVENT_PLAYER_ALIVE, OnPlayerAlive)
    PlayerInventory:RefreshAllInventorySlots(INVENTORY_BACKPACK)
    PlayerInventory:RefreshAllQuests()
    PlayerInventory:RefreshMoney(GetCurrentMoney())
    PlayerInventory:RefreshAlliancePoints(GetAlliancePoints())
    PlayerInventory:CreateBankScene()
    PlayerInventory:CreateGuildBankScene()
end
--Select Guild Bank Dialog
----------------------
    local dialog = ZO_SelectGuildDialog:New(self, "SELECT_GUILD_BANK", SelectGuildBank)
    dialog:SetTitle(GetString(SI_PROMPT_TITLE_SELECT_GUILD_BANK))
    dialog:SetPrompt(GetString(SI_SELECT_GUILD_BANK_INSTRUCTIONS))
end