Back to Home

ESO Lua File v100021

ingame/storewindow/keyboard/storewindow_keyboard.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
local ITEM_BUY_CURRENCY_OPTIONS =
{
    showTooltips = false,
    font = "ZoFontGameShadow",
    iconSide = RIGHT,
}
local MEET_BUY_REQS_FAIL_COLOR = ZO_ColorDef:New(1, 0, 0, 1)
local COMPUTE_HAS_ENOUGH = true
local DATA_TYPE_STORE_ITEM = 1
local STORE_ITEMS = false
-------------------
--Store Manager
-------------------
ZO_StoreManager = ZO_SharedStoreManager:Subclass()
function ZO_StoreManager:New(...)
    return ZO_SharedStoreManager.New(self, ...)
end
function ZO_StoreManager:Initialize(control)
    ZO_SharedStoreManager.Initialize(self, control)
    
    STORE_FRAGMENT = ZO_FadeSceneFragment:New(control)
    STORE_FRAGMENT:RegisterCallback("StateChange",   function(oldState, newState)
                                                    if newState == SCENE_FRAGMENT_SHOWING then
                                                        self:RefreshCurrency()
                                                        self:GetStoreItems()
                                                        self:UpdateList()
                                                        self:UpdateFreeSlots()
                                                    elseif newState == SCENE_FRAGMENT_HIDING then
                                                        if ITEM_PREVIEW_KEYBOARD:IsInteractionCameraPreviewEnabled() then
                                                            self:TogglePreviewMode()
                                                        end
                                                    end
                                                end)
    
    self:InitializeTabs()
    self.currentMoney = 0
    self.currency1Display = GetControl(control, "InfoBarCurrency1")
    self.currency2Display = GetControl(control, "InfoBarCurrency2")
    self.currenyMoneyDisplay = GetControl(control, "InfoBarMoney")
    self.freeSlotsLabel = GetControl(control, "InfoBarFreeSlots")
    ZO_CurrencyControl_InitializeDisplayTypes(self.currenyMoneyDisplay, CURT_MONEY)
    self.activeTab = GetControl(control, "TabsActive")
    self.multipleDialog = ZO_BuyMultipleDialog
    ZO_Dialogs_RegisterCustomDialog("BUY_MULTIPLE",
    {
        customControl = ZO_BuyMultipleDialog,
        title =
        {
            text = SI_PROMPT_TITLE_BUY_MULTIPLE,
        },
        buttons =
        {
            [1] =
            {
                control = GetControl(self.multipleDialog, "Purchase"),
                text =  SI_DIALOG_PURCHASE,
                callback =  function(dialog)
                                STORE_WINDOW:BuyMultiplePurchase()
                            end,
            },
        
            [2] =
            {
                control =   GetControl(self.multipleDialog, "Cancel"),
                text =      SI_DIALOG_CANCEL,
            }
        }
    })
    local function GetBuyMultipleMaximum()
        local entryIndex = self.multipleDialog.index
        return zo_min(zo_max(GetStoreEntryMaxBuyable(entryIndex), 1), MAX_STORE_WINDOW_STACK_QUANTITY) -- always attempt to let one item be bought, just to show the error; ensure that the quantity can't go above 999
    end
    local spinnerControl = GetControl(ZO_BuyMultipleDialog, "Spinner")
    self.buyMultipleSpinner = ZO_Spinner:New(spinnerControl, 1, GetBuyMultipleMaximum)
    self.buyMultipleSpinner:RegisterCallback("OnValueChanged", function() self:RefreshBuyMultiple() end)
    self.list = GetControl(control, "List")
    ZO_ScrollList_AddDataType(self.list, DATA_TYPE_STORE_ITEM, "ZO_StoreEntrySlot", 52, function(control, data) self:SetUpBuySlot(control, data) end, nil, nil, ZO_InventorySlot_OnPoolReset)
    self.landingArea = GetControl(self.list, "SellToVendorArea")
    self.sortHeaders = ZO_SortHeaderGroup:New(control:GetNamedChild("SortBy"), true)
    self.sortOrder = ZO_SORT_ORDER_UP
    self.sortKey = "name"
    local function OnSortHeaderClicked(key, order)
        self.sortKey = key
        self.sortOrder = order
        self:ApplySort()
    end
    self.sortHeaders:RegisterCallback(ZO_SortHeaderGroup.HEADER_CLICKED, OnSortHeaderClicked)
    self.sortHeaders:AddHeadersFromContainer()
    -- We are using shared sort headers from the inventory, but store sorts its entries by value
    -- differently, so we need to swap out the sort key
    self.sortHeaders:ReplaceKey("stackSellPrice", "stackBuyPrice")
    self.sortHeaders:SelectHeaderByKey("name", ZO_SortHeaderGroup.SUPPRESS_CALLBACKS)
    self.tabs = GetControl(control, "Tabs")
    local typicalHiddenColumns =
    {
        ["statusSortOrder"] = true,
        ["traitInformationSortOrder"] = true,
    }
    local gearHiddenColumns =
    {
        ["statusSortOrder"] = true,
    }
    local function CreateNewTabFilterData(filterType, normal, pressed, highlight, hiddenColumns)
        local filterString = GetString("SI_ITEMFILTERTYPE", filterType)
        local tabData =
        {
            -- Custom data
            filterType = filterType,
            hiddenColumns = hiddenColumns,
            activeTabText = filterString,
            tooltipText = filterString,
            -- Menu bar data
            descriptor = filterType,
            normal = normal,
            pressed = pressed,
            highlight = highlight,
            callback = function(tabData) self:ChangeFilter(tabData) end,
        }
        return tabData
    end
    self.storeFilters =
    {
        CreateNewTabFilterData(ITEMFILTERTYPE_MISCELLANEOUS, "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, "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, "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, "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, "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, "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_COLLECTIBLE, "EsoUI/Art/MainMenu/menuBar_collections_up.dds", "EsoUI/Art/MainMenu/menuBar_collections_down.dds", "EsoUI/Art/MainMenu/menuBar_collections_over.dds", typicalHiddenColumns),
        CreateNewTabFilterData(ITEMFILTERTYPE_ALL, "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 menuBarData =
    {
        initialButtonAnchorPoint = RIGHT,
        buttonTemplate = "ZO_StoreTab",
        normalSize = 51,
        downSize = 64,
        buttonPadding = -15,
        animationDuration = 180,
    }
    ZO_MenuBar_SetData(self.tabs, menuBarData)
    self.currentFilter = ITEMFILTERTYPE_ALL
    self.hiddenColumns = typicalHiddenColumns
    local function ShowStoreWindow()
        if not IsInGamepadPreferredMode() then
            SCENE_MANAGER:Show("store")
        end
    end
    local function CloseStoreWindow()
        if not IsInGamepadPreferredMode() then
            -- Ensure that all dialogs related to the store also close when interaction ends
            ZO_Dialogs_ReleaseDialog("REPAIR_ALL")
            ZO_Dialogs_ReleaseDialog("BUY_MULTIPLE")
            ZO_Dialogs_ReleaseDialog("SELL_ALL_JUNK")
            SCENE_MANAGER:Hide("store")
        end
    end
    local function RefreshStoreWindow()
        if not STORE_FRAGMENT:IsHidden() then
            self:RefreshCurrency()
            self:GetStoreItems()
            self:UpdateList()
        end
    end
    local function OnInventoryUpdated()
        if not STORE_FRAGMENT:IsHidden() then
            KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
            self:UpdateFreeSlots()
        elseif not INVENTORY_FRAGMENT:IsHidden() then
            KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
            self.modeBar:UpdateActiveKeybind()
        end
    end
    local OnBuySuccess = function(...)
        if not control:IsControlHidden() then
            ZO_StoreManager_OnPurchased(...)
        end
    end
    local function HandleCursorPickup(eventCode, cursorType)
        if cursorType == MOUSE_CONTENT_INVENTORY_ITEM then
            ZO_InventoryLandingArea_SetHidden(self.landingArea, false, SI_INVENTORY_LANDING_AREA_SELL_ITEM)
        end
    end
    local function HandleCursorCleared(eventCode, oldCursorType)
        ZO_InventoryLandingArea_SetHidden(self.landingArea, true)
    end
    local storeScene = ZO_InteractScene:New("store", SCENE_MANAGER, STORE_INTERACTION)
    storeScene:RegisterCallback("StateChange",   function(oldState, newState)
                                                    if newState == SCENE_SHOWING then
                                                        self:InitializeStore()
                                                        PLAYER_INVENTORY:SelectAndChangeSort("traitInformationSortOrder", INVENTORY_BACKPACK, ZO_SORT_ORDER_DOWN)
                                                    elseif newState == SCENE_HIDDEN then
                                                        ZO_InventorySlot_RemoveMouseOverKeybinds()
                                                        KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
                                                        self.modeBar:Clear()
                                                        PLAYER_INVENTORY:SelectAndChangeSort("statusSortOrder", INVENTORY_BACKPACK, ZO_SORT_ORDER_DOWN)
                                                        if GetCursorContentType() == MOUSE_CONTENT_STORE_ITEM then
                                                            ClearCursor()
                                                        end
                                                    end
                                                end)
    control:RegisterForEvent(EVENT_OPEN_STORE, ShowStoreWindow)
    control:RegisterForEvent(EVENT_CLOSE_STORE, CloseStoreWindow)
    control:RegisterForEvent(EVENT_MONEY_UPDATE, RefreshStoreWindow)
    control:RegisterForEvent(EVENT_BUY_RECEIPT, OnBuySuccess)
    control:RegisterForEvent(EVENT_ALLIANCE_POINT_UPDATE, RefreshStoreWindow)
    control:RegisterForEvent(EVENT_TELVAR_STONE_UPDATE, RefreshStoreWindow)
    control:RegisterForEvent(EVENT_WRIT_VOUCHER_UPDATE, RefreshStoreWindow)
    control:RegisterForEvent(EVENT_INVENTORY_FULL_UPDATE, OnInventoryUpdated)
    control:RegisterForEvent(EVENT_INVENTORY_SINGLE_SLOT_UPDATE, OnInventoryUpdated)
    control:RegisterForEvent(EVENT_CURSOR_PICKUP, HandleCursorPickup)
    control:RegisterForEvent(EVENT_CURSOR_DROPPED, HandleCursorCleared)
    control:RegisterForEvent(EVENT_COLLECTION_UPDATED, RefreshStoreWindow)
    control:RegisterForEvent(EVENT_COLLECTIBLE_UPDATED, RefreshStoreWindow)
    local function OnItemRepaired(bagId, slotIndex)
        KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
    end
    SHARED_INVENTORY:RegisterCallback("ItemRepaired", OnItemRepaired)
end
function ZO_StoreManager:InitializeStore(overrideMode)
    ZO_SharedStoreManager.InitializeStore(self)
    self.windowMode = overrideMode or ZO_STORE_WINDOW_MODE_NORMAL
    self:RebuildTabs()
    if IsStoreEmpty() then
        self.modeBar:SelectFragment(SI_STORE_MODE_SELL)
    elseif self.windowMode == ZO_STORE_WINDOW_MODE_NORMAL then
        self.modeBar:SelectFragment(SI_STORE_MODE_BUY)
        KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor)
    end
    self:GetStoreItems()
    self:UpdateFilters()
    self:UpdateList(STORE_ITEMS)
end
function ZO_StoreManager:InitializeTabs()
    local function CreateButtonData(normal, pressed, highlight)
        return {
            normal = normal,
            pressed = pressed,
            highlight = highlight,
        }
    end
    
    self.stackAllButton =
    {
        alignment = KEYBIND_STRIP_ALIGN_CENTER,
        {
            name = GetString(SI_ITEM_ACTION_STACK_ALL),
            keybind = "UI_SHORTCUT_STACK_ALL",
            callback = function()
                StackBag(BAG_BACKPACK)
            end,
        }
    }
    self.modeBar = ZO_SceneFragmentBar:New(ZO_StoreWindowMenuBar)
    --Buy Button
    self.buyButtonData = CreateButtonData("EsoUI/Art/Vendor/vendor_tabIcon_buy_up.dds",
                                            "EsoUI/Art/Vendor/vendor_tabIcon_buy_down.dds",
                                            "EsoUI/Art/Vendor/vendor_tabIcon_buy_over.dds")
    --Sell Button
    self.sellButtonData = CreateButtonData("EsoUI/Art/Vendor/vendor_tabIcon_sell_up.dds",
                                            "EsoUI/Art/Vendor/vendor_tabIcon_sell_down.dds",
                                            "EsoUI/Art/Vendor/vendor_tabIcon_sell_over.dds")
    --Buy Back Button
    self.buyBackButtonData = CreateButtonData("EsoUI/Art/Vendor/vendor_tabIcon_buyBack_up.dds",
                                               "EsoUI/Art/Vendor/vendor_tabIcon_buyBack_down.dds",
                                               "EsoUI/Art/Vendor/vendor_tabIcon_buyBack_over.dds")
    --Repair Button
    self.repairButtonData = CreateButtonData("EsoUI/Art/Vendor/vendor_tabIcon_repair_up.dds",
                                                "EsoUI/Art/Vendor/vendor_tabIcon_repair_down.dds",
                                                "EsoUI/Art/Vendor/vendor_tabIcon_repair_over.dds")
end
function ZO_StoreManager:RebuildTabs()
    self.modeBar:RemoveAll()
    if not IsStoreEmpty() then
        self.modeBar:Add(SI_STORE_MODE_BUY, { STORE_FRAGMENT }, self.buyButtonData)
    end
    self.modeBar:Add(SI_STORE_MODE_SELL, { INVENTORY_FRAGMENT, BACKPACK_STORE_LAYOUT_FRAGMENT }, self.sellButtonData, self.stackAllButton)
    self.modeBar:Add(SI_STORE_MODE_BUY_BACK, { BUY_BACK_FRAGMENT }, self.buyBackButtonData)
    if CanStoreRepair() then
        self.modeBar:Add(SI_STORE_MODE_REPAIR, { REPAIR_FRAGMENT }, self.repairButtonData)
    end
end
do
    local DONT_COUNT_STOLEN_ITEMS = true
    function ZO_StoreManager:InitializeKeybindStripDescriptors()
        self.keybindStripDescriptor =
        {
            alignment = KEYBIND_STRIP_ALIGN_CENTER,
            -- Repair All
            {
                name = function()
                    local cost = GetRepairAllCost()
                    if GetCurrencyAmount(CURT_MONEY, CURRENCY_LOCATION_CHARACTER) >= cost then
                        return zo_strformat(SI_REPAIR_ALL_KEYBIND_TEXT, ZO_Currency_FormatKeyboard(CURT_MONEY, cost, ZO_CURRENCY_FORMAT_WHITE_AMOUNT_ICON))
                    end
                    return zo_strformat(SI_REPAIR_ALL_KEYBIND_TEXT, ZO_Currency_FormatKeyboard(CURT_MONEY, cost, ZO_CURRENCY_FORMAT_AMOUNT_ERROR_ICON))
                end,
                keybind = "UI_SHORTCUT_SECONDARY",
                visible = function() return CanStoreRepair() and GetRepairAllCost() > 0 end,
                callback = function()
                    ZO_Dialogs_ShowDialog("REPAIR_ALL", {cost = GetRepairAllCost()})
                end,
            },
            -- Sell All Junk
            {
                name = GetString(SI_SELL_ALL_JUNK_KEYBIND_TEXT),
                keybind = "UI_SHORTCUT_NEGATIVE",
                visible =   function()
                                return HasAnyJunk(BAG_BACKPACK, DONT_COUNT_STOLEN_ITEMS)
                            end,
                callback =  function()
                                ZO_Dialogs_ShowDialog("SELL_ALL_JUNK")
                            end,
            },
            --End Preview
            {
                name = GetString(SI_CRAFTING_EXIT_PREVIEW_MODE),
                keybind = "UI_SHORTCUT_QUATERNARY",
                visible =   function()
                                return ITEM_PREVIEW_KEYBOARD:IsInteractionCameraPreviewEnabled()
                            end,
                callback =  function()
                                self:TogglePreviewMode()
                            end,
            },
        }
    end
end
function ZO_StoreManager:UpdateFreeSlots()
    if self.windowMode ~= ZO_STORE_WINDOW_MODE_STABLE then
        local numUsedSlots, numSlots = PLAYER_INVENTORY:GetNumSlots(INVENTORY_BACKPACK)
        if self.numUsedSlots ~= numUsedSlots or self.numSlots ~= numSlots then
            self.numUsedSlots = numUsedSlots
            self.numSlots = numSlots
            if numUsedSlots < numSlots then
                self.freeSlotsLabel:SetText(zo_strformat(SI_INVENTORY_BACKPACK_REMAINING_SPACES, numUsedSlots, numSlots))
            else
                self.freeSlotsLabel:SetText(zo_strformat(SI_INVENTORY_BACKPACK_COMPLETELY_FULL, numUsedSlots, numSlots))
            end
        end
    end
end
function ZO_StoreManager:ChangeFilter(filterData)
    self.currentFilter = filterData.filterType
    self.hiddenColumns = filterData.hiddenColumns
    self.activeTab:SetText(filterData.activeTabText)
    -- 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. Currently this always falls back to the name key.
    if self.sortHeaders then
        self.sortHeaders:SetHeadersHiddenFromKeyList(self.hiddenColumns, true)
        if self.hiddenColumns[self.sortKey] then
            -- User wanted to sort by a column that's gone!
            -- Fallback to name.
            self.sortHeaders:SelectHeaderByKey("name")
        end
    end
    --Hide inventory capacity for collectibles since they don't take up space
    self.freeSlotsLabel:SetHidden(self.currentFilter == ITEMFILTERTYPE_COLLECTIBLE)
    self:UpdateList()
end
function ZO_StoreManager:ShouldAddItemToList(itemData)
    if self.currentFilter == ITEMFILTERTYPE_ALL then return true end
    for i = 1, #itemData.filterData do
        if itemData.filterData[i] == self.currentFilter then
            return true
        end
    end
    return false
end
local sortKeys =
{
    name = { },
    stackBuyPrice = { tiebreaker = "stackBuyPriceCurrency1", isNumeric = true },
    stackBuyPriceCurrency1 = { tiebreaker = "stackBuyPriceCurrency2", isNumeric = true },
    stackBuyPriceCurrency2 = { tiebreaker = "name", isNumeric = true },
    traitInformationSortOrder = { tiebreaker = "name", isNumeric = true },
}
function ZO_StoreManager:SortData()
    local scrollData = ZO_ScrollList_GetDataList(self.list)
    self.sortFunction = self.sortFunction or function(entry1, entry2)
        return ZO_TableOrderingFunction(entry1.data, entry2.data, self.sortKey, sortKeys, self.sortOrder)
    end
    table.sort(scrollData, self.sortFunction)
end
function ZO_StoreManager:ApplySort()
    self:SortData()
end
function ZO_StoreManager:SetCurrencyControl(currencyType, currencyValue, currencyOptions)
    local control = (not self.currency1Display.isInUse and self.currency1Display) or 
                    (not self.currency2Display.isInUse and self.currency2Display) or nil
    if control then
        ZO_CurrencyControl_SetSimpleCurrency(control, currencyType, currencyValue, currencyOptions)
        control:SetHidden(false)
        control.isInUse = true
    end
end
function ZO_StoreManager:RefreshCurrency()
    ZO_SharedStoreManager.RefreshCurrency(self)
    local repairAllCost = GetRepairAllCost()
    local gold = (self.storeUsesMoney or repairAllCost > 0) and self.currentMoney or 0
    ZO_CurrencyControl_SetCurrencyData(self.currenyMoneyDisplay, CURT_MONEY, gold, self.storeUsesMoney)
    ZO_CurrencyControl_SetCurrency(self.currenyMoneyDisplay, ZO_KEYBOARD_CURRENCY_OPTIONS)
    -- We're laying out the player alternate currency labels this way to ensure that we never display more than two labels, even if
    -- more than two are applicable to this store, and to ensure that they maintain a consistent priority
    self.currency1Display:SetHidden(true)
    self.currency1Display.isInUse = false
    self.currency2Display:SetHidden(true)
    self.currency2Display.isInUse = false
    
    if self.storeUsesAP then
        self:SetCurrencyControl(CURT_ALLIANCE_POINTS, self.currentAP or 0, ZO_KEYBOARD_CURRENCY_OPTIONS)
    end
    if self.storeUsesTelvarStones then
        self:SetCurrencyControl(CURT_TELVAR_STONES, self.currentTelvarStones or 0, ZO_KEYBOARD_CURRENCY_OPTIONS)
    end 
    if self.storeUsesWritVouchers then
        self:SetCurrencyControl(CURT_WRIT_VOUCHERS, self.currentWritVouchers or 0, ZO_KEYBOARD_CURRENCY_OPTIONS)
    end 
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
function ZO_StoreManager:UpdateFilters()
    --The last filter added is the farthest left, so to the player it should be "first"
    local lastFilter
    for _, data in ipairs(self.storeFilters) do
        if (data.filterType == ITEMFILTERTYPE_ALL and self.showAllFilter) or self.usedFilterTypes[data.filterType] then
            ZO_MenuBar_AddButton(self.tabs, data)
            lastFilter = data.filterType
        end
    end
    if lastFilter then
        ZO_MenuBar_SelectDescriptor(self.tabs, lastFilter)
    end
end
function ZO_StoreManager:GetStoreItems()
    self.items, self.usedFilterTypes = ZO_StoreManager_GetStoreItems()
    local numUsedStoreFilters = 0
    for _, data in ipairs(self.storeFilters) do
        if self.usedFilterTypes[data.filterType] then
            numUsedStoreFilters = numUsedStoreFilters + 1
        end
    end
    -- We only want to show the all filter if we aren't showing one specific filter
    -- because then all and the specific filter would have the same contents
    self.showAllFilter = numUsedStoreFilters ~= 1 
end
function ZO_StoreManager:UpdateList()
    local scrollData = ZO_ScrollList_GetDataList(self.list)
    
    for index = 1, #self.items do
        local itemData = self.items[index]
        if self:ShouldAddItemToList(itemData) then
            scrollData[#scrollData + 1] = ZO_ScrollList_CreateDataEntry(DATA_TYPE_STORE_ITEM, itemData)
        end
    end
    self:ApplySort()
end
function ZO_StoreManager:SetUpBuySlot(control, data)
    local newStatusControl = GetControl(control, "Status")
    local slotControl = GetControl(control, "Button")
    local iconControl = GetControl(control, "ButtonIcon")
    local quantityControl = GetControl(control, "ButtonStackCount")
    local nameControl = GetControl(control, "Name")
    local priceControl = GetControl(control, "SellPrice")
    newStatusControl:SetHidden(true)
    -- Set info about what slot this is, on the top level slot control
    ZO_InventorySlot_SetType(slotControl, SLOT_TYPE_STORE_BUY)
    local slotIndex = data.slotIndex
    slotControl.index = slotIndex
    slotControl.moneyCost = data.stackBuyPrice
    slotControl.specialCurrencyQuantity1 = data.currencyQuantity1
    slotControl.specialCurrencyQuantity2 = data.currencyQuantity2
    slotControl.specialCurrencyType1 = data.currencyType1
    slotControl.specialCurrencyType2 = data.currencyType2
    slotControl.isCollectible = data.filterData[1] == ITEMFILTERTYPE_COLLECTIBLE
    slotControl.isUnique = data.isUnique
    ZO_InventorySlot_SetType(control, SLOT_TYPE_STORE_BUY)
    control.index = slotIndex
    control.moneyCost = data.stackBuyPrice
    local meetsReqs = data.meetsRequirementsToBuy and data.meetsRequirementsToEquip
    local isLocked = false
    if slotControl.isCollectible then
        isLocked = select(2, GetStoreCollectibleInfo(slotIndex))
    end
    slotControl.locked = isLocked
    ZO_ItemSlot_SetupSlotBase(slotControl, data.stack, data.icon, meetsReqs)
    nameControl:SetText(zo_strformat(SI_TOOLTIP_ITEM_NAME, data.name))
    if data.meetsRequirementsToBuy then
        if data.questNameColor then
            nameControl:SetColor(GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_TOOLTIP, ITEM_TOOLTIP_COLOR_QUEST_ITEM_NAME))
        elseif slotControl.isCollectible then
            nameControl:SetColor(ZO_SELECTED_TEXT:UnpackRGBA())
        else
            nameControl:SetColor(GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_QUALITY_COLORS, data.quality))
        end
    else
        nameControl:SetColor(MEET_BUY_REQS_FAIL_COLOR:UnpackRGBA())
    end
    ZO_CurrencyControl_InitializeDisplayTypes(priceControl, CURT_MONEY, CURT_ALLIANCE_POINTS, CURT_TELVAR_STONES, CURT_WRIT_VOUCHERS)
    local currencyType1 = data.currencyType1
    local currencyType2 = data.currencyType2
    ZO_CurrencyControl_SetCurrencyData(priceControl, CURT_MONEY, data.stackBuyPrice, CURRENCY_DONT_SHOW_ALL, not self:HasEnoughCurrencyToBuyItem(CURT_MONEY, data.stackBuyPrice))
    ZO_CurrencyControl_SetCurrencyData(priceControl, currencyType1, data.currencyQuantity1, CURRENCY_DONT_SHOW_ALL, not self:HasEnoughCurrencyToBuyItem(currencyType1, data.stackBuyPriceCurrency1), data.slotIndex, 1)
    ZO_CurrencyControl_SetCurrencyData(priceControl, currencyType2, data.currencyQuantity2, CURRENCY_DONT_SHOW_ALL, not self:HasEnoughCurrencyToBuyItem(currencyType2, data.stackBuyPriceCurrency2), data.slotIndex, 2)
    ZO_CurrencyControl_SetCurrency(priceControl, ITEM_BUY_CURRENCY_OPTIONS)
end
function ZO_StoreManager:HasEnoughCurrencyToBuyItem(currencyType, itemCost)
    if currencyType == CURT_MONEY then
        return self.currentMoney >= itemCost
    elseif currencyType == CURT_ALLIANCE_POINTS then
        return self.currentAP >= itemCost
    elseif currencyType == CURT_TELVAR_STONES then
        return self.currentTelvarStones >= itemCost
    elseif currencyType == CURT_WRIT_VOUCHERS then
        return self.currentWritVouchers >= itemCost
    end
    return false
end
function ZO_StoreManager:OpenBuyMultiple(entryIndex)
    self.multipleDialog.index = entryIndex
    self.buyMultipleSpinner:SetValue(1, true)
    ZO_Dialogs_ShowDialog("BUY_MULTIPLE")
end
function ZO_StoreManager:BuyMultiplePurchase()
    local storeItemId = self.multipleDialog.index
    local quantity = self.buyMultipleSpinner:GetValue()
    if quantity ~= 0 then
        BuyStoreItem(storeItemId, quantity)
    end
end
function ZO_StoreManager:RefreshBuyMultiple()
    local quantity = self.buyMultipleSpinner:GetValue()
    local entryIndex = self.multipleDialog.index
    local slotControl = GetControl(self.multipleDialog, "Slot")
    local iconControl = GetControl(self.multipleDialog, "SlotIcon")
    local quantityControl = GetControl(self.multipleDialog, "SlotStackCount")
    local currencyControl = GetControl(self.multipleDialog, "Currency")
    local icon, name, stack, price, _, meetsRequirementsToBuy, meetsRequirementsToEquip, _, _, currencyType1, currencyQuantity1,
            currencyType2, currencyQuantity2 = GetStoreEntryInfo(entryIndex)
    -- Set info about what slot this is, on the top level slot control
    ZO_InventorySlot_SetType(slotControl, SLOT_TYPE_BUY_MULTIPLE)
    slotControl.index = entryIndex
    -- Fill in the rest of the controls.
    iconControl:SetTexture(icon)
    if stack ~= 1 then
        quantityControl:SetText(stack)
        quantityControl:SetHidden(false)
    else
        quantityControl:SetHidden(true)
    end
    ZO_ItemSlot_SetupUsableAndLockedColor(slotControl, meetsRequirementsToBuy and meetsRequirementsToEquip)
    ZO_CurrencyControl_InitializeDisplayTypes(currencyControl, CURT_MONEY, CURT_ALLIANCE_POINTS, CURT_TELVAR_STONES, CURT_WRIT_VOUCHERS)
    local total = quantity * price
    local type1Total = quantity * currencyQuantity1
    local type2Total = quantity * currencyQuantity2
    ZO_CurrencyControl_SetCurrencyData(currencyControl, CURT_MONEY, total, CURRENCY_DONT_SHOW_ALL, not self:HasEnoughCurrencyToBuyItem(CURT_MONEY, total))
    ZO_CurrencyControl_SetCurrencyData(currencyControl, currencyType1, type1Total, CURRENCY_DONT_SHOW_ALL, not self:HasEnoughCurrencyToBuyItem(currencyType1, type1Total), entryIndex, 1)
    ZO_CurrencyControl_SetCurrencyData(currencyControl, currencyType2, type2Total, CURRENCY_DONT_SHOW_ALL, not self:HasEnoughCurrencyToBuyItem(currencyType2, type2Total), entryIndex, 2)
    ZO_CurrencyControl_SetCurrency(currencyControl, ITEM_BUY_CURRENCY_OPTIONS)
end
function ZO_StoreManager:GetWindowMode()
    return self.windowMode
end
function ZO_StoreManager:TogglePreviewMode()
    ITEM_PREVIEW_KEYBOARD:ToggleInteractionCameraPreview(FRAME_TARGET_STORE_WINDOW_FRAGMENT, FRAME_PLAYER_ON_SCENE_HIDDEN_FRAGMENT, RIGHT_PANEL_BG_EMPTY_WORLD_ITEM_PREVIEW_OPTIONS_FRAGMENT)
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
function ZO_StoreManager:PreviewStoreEntry(storeEntryIndex)
    if not ITEM_PREVIEW_KEYBOARD:IsInteractionCameraPreviewEnabled() then
        self:TogglePreviewMode()
    end
    ITEM_PREVIEW_KEYBOARD:PreviewStoreEntryAsFurniture(storeEntryIndex)
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
-------------------
-- Global functions
-------------------
local function GetStoreEntryIndexForPreviewFromSlot(storeEntrySlot)
    local inventorySlot, listPart, multiIconPart = ZO_InventorySlot_GetInventorySlotComponents(storeEntrySlot)
    local slotType = ZO_InventorySlot_GetType(inventorySlot)
    if slotType == SLOT_TYPE_STORE_BUY then
        local storeEntryIndex = inventorySlot.index
        local itemLink = GetStoreItemLink(storeEntryIndex)
        if ZO_ItemPreview_Shared.CanItemLinkBePreviewedAsFurniture(itemLink) then
            return storeEntryIndex
        end
    end
    return nil
end
function ZO_BuyMultiple_OpenBuyMultiple(entryIndex)
    STORE_WINDOW:OpenBuyMultiple(entryIndex)
end
function ZO_Store_OnEntryMouseEnter(storeEntrySlot)
    ZO_InventorySlot_OnMouseEnter(storeEntrySlot)
    local storeEntryIndex = GetStoreEntryIndexForPreviewFromSlot(storeEntrySlot)
    local cursor = MOUSE_CURSOR_DO_NOT_CARE
    if storeEntryIndex ~= nil then
        cursor = MOUSE_CURSOR_PREVIEW
    end
    WINDOW_MANAGER:SetMouseCursor(cursor)
end
function ZO_Store_OnEntryMouseExit(storeEntrySlot)
    ZO_InventorySlot_OnMouseExit(storeEntrySlot)
    WINDOW_MANAGER:SetMouseCursor(MOUSE_CURSOR_DO_NOT_CARE)
end
function ZO_Store_OnEntryClicked(storeEntrySlot, button)
    
    -- left button for an inventory slot click will only try and drag and drop, but that
    -- should be handled for us by the OnReceiveDrag handler, so if we left click
    -- we'll do our custom behavior
    if button == MOUSE_BUTTON_INDEX_LEFT then
        local storeEntryIndex = GetStoreEntryIndexForPreviewFromSlot(storeEntrySlot)
        if storeEntryIndex ~= nil then
            STORE_WINDOW:PreviewStoreEntry(storeEntryIndex)
        end
    else
        ZO_InventorySlot_OnSlotClicked(storeEntrySlot, button)
    end
end
    InitializeTooltip(InformationTooltip, self, BOTTOM, 0, -10)
end
    ClearTooltip(InformationTooltip)
end
function ZO_Store_OnMouseUp(upInside)
    if upInside and GetCursorContentType() ~= MOUSE_CONTENT_EMPTY then
        PlaceInStoreWindow()
    end
end
    if GetCursorContentType() ~= MOUSE_CONTENT_EMPTY then
        PlaceInStoreWindow()
    end
end
function ZO_Store_IsShopping()
    return GetInteractionType() == INTERACTION_VENDOR
end
    STORE_WINDOW = ZO_StoreManager:New(control)
end