Back to Home

ESO Lua File v101042

ingame/restyle/keyboard/restylesheetwindow_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
ZO_RestyleSheetWindow_Keyboard = ZO_InitializingCallbackObject:Subclass()
function ZO_RestyleSheetWindow_Keyboard:Initialize(control)
    self.control = control
    self.isPreviewAvailable = true
    self.sheetsContainer = control:GetNamedChild("Containers")
    self.sheetsByMode = {}
    self.currentSheet = self.equipmentSheet
    self.outfitSelectorTutorialAnchor = ZO_Anchor:New(LEFT, self.modeSelectorDropdownControl, RIGHT, 10, 0)
    self.control:SetHandler("OnUpdate", function() self:OnUpdate() end)
    local function OnRefreshOutfitName(actorCategory, outfitIndex)
        local KEEP_CURRENT_SELECTION = true
        if self.currentSheet == self.equipmentSheet or self.currentSheet == self.outfitStylesSheet then
            self:PopulateEquipmentModeDropdown(KEEP_CURRENT_SELECTION)
        end
    end
    local function UpdateEquippedOutfit()
        if self.currentSheet ~= self.collectiblesSheet and self.currentSheet ~= self.companionCollectiblesSheet then
            if self.currentSheet == self.equipmentSheet or self.currentSheet == self.outfitStylesSheet then
                self:PopulateEquipmentModeDropdown()
            elseif self.currentSheet == self.companionEquipmentSheet or self.currentSheet == self.companionOutfitStylesSheet then
                self:PopulateCompanionOutfitsModeDropdown()
            end
        end
    end
    ZO_RESTYLE_SHEET_WINDOW_FRAGMENT = ZO_FadeSceneFragment:New(control)
    ZO_RESTYLE_SHEET_WINDOW_FRAGMENT:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_FRAGMENT_SHOWING then
            self:OnShowing()
            ZO_OUTFIT_MANAGER:RegisterCallback("RefreshOutfitName", OnRefreshOutfitName)
            ZO_OUTFIT_MANAGER:RegisterCallback("RefreshEquippedOutfitIndex", UpdateEquippedOutfit)
        elseif newState == SCENE_FRAGMENT_HIDING then
            ZO_OUTFIT_MANAGER:UnregisterCallback("RefreshOutfitName", OnRefreshOutfitName)
            ZO_OUTFIT_MANAGER:UnregisterCallback("RefreshEquippedOutfitIndex", UpdateEquippedOutfit)
            self:OnHiding()
        elseif newState == SCENE_FRAGMENT_HIDDEN then
            self:OnHidden()
        end
    end)
end
function ZO_RestyleSheetWindow_Keyboard:InitializeModeSelector()
    local modeSelector = self.control:GetNamedChild("ModeSelector")
    self.modeSelectorHeader = modeSelector:GetNamedChild("Header")
    self.modeSelectorDropdownControl = modeSelector:GetNamedChild("Dropdown")
    self.modeSelectorDropdown = ZO_ComboBox_ObjectFromContainer(self.modeSelectorDropdownControl)
    self.modeSelectorDropdown:SetSortsItems(false)
    self.modeSelectorDropdown:SetPreshowDropdownCallback(function()
        TUTORIAL_SYSTEM:RemoveTutorialByTrigger(TUTORIAL_TYPE_POINTER_BOX, TUTORIAL_TRIGGER_OUTFIT_SELECTOR_SHOWN_POINTER_BOX)
    end)
    local UNEQUIP_OUTFIT = nil
    self.setEquipmentGearSelectedFunction = function()
        self:DisplaySheet(self.equipmentSheet)
        ZO_OUTFIT_STYLES_PANEL_KEYBOARD:SetCurrentOutfitManipulator(UNEQUIP_OUTFIT)
        self.pendingEquipOutfitManipulator = UNEQUIP_OUTFIT
        ITEM_PREVIEW_KEYBOARD:PreviewUnequipOutfit(GAMEPLAY_ACTOR_CATEGORY_PLAYER)
        self:FireCallbacks("ModeSelectorDropdownChanged")
    end
        self:DisplaySheet(self.companionEquipmentSheet)
        ZO_OUTFIT_STYLES_PANEL_KEYBOARD:SetCurrentOutfitManipulator(UNEQUIP_OUTFIT)
        self.pendingEquipOutfitManipulator = UNEQUIP_OUTFIT
        ITEM_PREVIEW_KEYBOARD:PreviewUnequipOutfit(GAMEPLAY_ACTOR_CATEGORY_COMPANION)
        self:FireCallbacks("ModeSelectorDropdownChanged")
    end
    local IGNORE_CALLBACK = true
    local function TrySetEquipmentGearSelected(_, _, entry, selectionChanged, oldEntry)
        if selectionChanged then
            if self:AreChangesPending() then
                local function Decline()
                    self.modeSelectorDropdown:SelectItem(oldEntry, IGNORE_CALLBACK)
                end
                self:ShowRevertRestyleChangesDialog("CONFIRM_REVERT_OUTFIT_ON_CHANGE", self.setEquipmentGearSelectedFunction, Decline)
            else
                self.setEquipmentGearSelectedFunction()
            end
        end
    end
    local function TrySetCompanionEquipmentGearSelected(_, _, entry, selectionChanged, oldEntry)
        if selectionChanged then
            if self:AreChangesPending() then
                local function Decline()
                    self.modeSelectorDropdown:SelectItem(oldEntry, IGNORE_CALLBACK)
                end
                self:ShowRevertRestyleChangesDialog("CONFIRM_REVERT_OUTFIT_ON_CHANGE", self.setCompanionEquipmentGearSelectedFunction, Decline)
            else
                self.setCompanionEquipmentGearSelectedFunction()
            end
        end
    end
    self.equipmentGearModeEntry = self.modeSelectorDropdown:CreateItemEntry(GetString(SI_NO_OUTFIT_EQUIP_ENTRY), TrySetEquipmentGearSelected)
    self.equipmentGearModeEntry.selectFunction = self.setEquipmentGearSelectedFunction
    self.collectiblesModeEntry = self.modeSelectorDropdown:CreateItemEntry("", function()
        self:DisplaySheet(self.collectiblesSheet)
    end)
    self.companionEquipmentGearModeEntry = self.modeSelectorDropdown:CreateItemEntry(GetString(SI_NO_OUTFIT_EQUIP_ENTRY), TrySetCompanionEquipmentGearSelected)
    self.companionEquipmentGearModeEntry.selectFunction = self.setCompanionEquipmentGearSelectedFunction
    self.companionCollectiblesModeEntry = self.modeSelectorDropdown:CreateItemEntry("", function()
        self:DisplaySheet(self.companionCollectiblesSheet)
    end)
    local function OnPurchaseAdditionalOutfitsEntry(_, _, entry, selectionChanged, oldEntry)
        local exitDestinationData =
        {
            crownStoreSearch = GetString(SI_CROWN_STORE_SEARCH_ADDITIONAL_OUTFITS),
            crownStoreOpenOperation = MARKET_OPEN_OPERATION_UNLOCK_NEW_OUTFIT,
        }
        ZO_RESTYLE_STATION_KEYBOARD:AttemptExit(exitDestinationData)
        self.modeSelectorDropdown:SelectItem(oldEntry, true)
    end
    self.purchaseAdditionalOutfitsEntry = self.modeSelectorDropdown:CreateItemEntry(GetString(SI_OUTFIT_PURCHASE_MORE_ENTRY), OnPurchaseAdditionalOutfitsEntry)
end
function ZO_RestyleSheetWindow_Keyboard:InitializeSheet(sheetClassTemplate, slotGridData)
    local function OnDyeSlotClicked(...)
        self:OnDyeSlotClicked(...)
    end
    local function OnDyeSlotEnter(...)
        self:OnDyeSlotEnter(...)
    end
    local function OnDyeSlotExit(...)
        self:OnDyeSlotExit(...)
    end
    local sheet = sheetClassTemplate:New(self.sheetsContainer, slotGridData)
    self.sheetsByMode[sheet:GetRestyleMode()] = sheet
    return sheet
end
function ZO_RestyleSheetWindow_Keyboard:InitializeEquipmentSheet()
    local slotGridData =
    {
        [ZO_RESTYLE_SHEET_CONTAINER.PRIMARY] =
        {
            [EQUIP_SLOT_HEAD] = { row = 1, column = 1, controlName = "Head" },
            [EQUIP_SLOT_SHOULDERS] = { row = 2, column = 1, controlName = "Shoulders" }, [EQUIP_SLOT_CHEST] = { row = 2, column = 2, controlName = "Chest" },
            [EQUIP_SLOT_HAND] = { row = 3, column = 1, controlName = "Hand" }, [EQUIP_SLOT_WAIST] = { row = 3, column = 2, controlName = "Waist" },
            [EQUIP_SLOT_LEGS] = { row = 4, column = 1, controlName = "Legs" }, [EQUIP_SLOT_FEET] = { row = 4, column = 2, controlName = "Feet" },
        },
        [ZO_RESTYLE_SHEET_CONTAINER.SECONDARY] =
        {
            -- Switches with Shield on show based on ActiveWeaponPair
            [EQUIP_SLOT_OFF_HAND] = { row = 1, column = 2, controlName = "Shield" },
            [EQUIP_SLOT_BACKUP_OFF] = { row = 1, column = 2, controlName = "ShieldB" },
        }
    }
    self.equipmentSheet = self:InitializeSheet(ZO_RestyleEquipmentSlotsSheet, slotGridData)
end
function ZO_RestyleSheetWindow_Keyboard:InitializeCollectibleSheet()
    local slotGridData =
    {
        [ZO_RESTYLE_SHEET_CONTAINER.PRIMARY] =
        {
            [COLLECTIBLE_CATEGORY_TYPE_HAT] = { row = 1, column = 1, controlName = "Hat" }, [COLLECTIBLE_CATEGORY_TYPE_COSTUME] = { row = 1, column = 2, controlName = "Costume" },
        },
    }
    self.collectiblesSheet = self:InitializeSheet(ZO_RestyleCollectibleSlotsSheet, slotGridData)
end
function ZO_RestyleSheetWindow_Keyboard:InitializeOutfitStylesSheet()
    local slotGridData =
    {
        [ZO_RESTYLE_SHEET_CONTAINER.PRIMARY] =
        {
            [OUTFIT_SLOT_HEAD] = { row = 1, column = 1, controlName = "Head" },
            [OUTFIT_SLOT_SHOULDERS] = { row = 2, column = 1, controlName = "Shoulders" }, [OUTFIT_SLOT_CHEST] = { row = 2, column = 2, controlName = "Chest" },
            [OUTFIT_SLOT_HANDS] = { row = 3, column = 1, controlName = "Hands" }, [OUTFIT_SLOT_WAIST] = { row = 3, column = 2, controlName = "Waist" },
            [OUTFIT_SLOT_LEGS] = { row = 4, column = 1, controlName = "Legs" }, [OUTFIT_SLOT_FEET] = { row = 4, column = 2, controlName = "Feet" },
        },
        [ZO_RESTYLE_SHEET_CONTAINER.SECONDARY] =
        {
            -- Switches with Shield on show based on ActiveWeaponPair and equipped weapon type
            [OUTFIT_SLOT_WEAPON_TWO_HANDED] = { row = 1, column = 1, controlName = "TwoHanded" }, [OUTFIT_SLOT_SHIELD] = { row = 1, column = 2, controlName = "Shield" },
            [OUTFIT_SLOT_WEAPON_MAIN_HAND] = { row = 1, column = 1, controlName = "MainHand" }, [OUTFIT_SLOT_WEAPON_OFF_HAND] = { row = 1, column = 2, controlName = "OffHand" },
            [OUTFIT_SLOT_WEAPON_BOW] = { row = 1, column = 1, controlName = "Bow" },
            [OUTFIT_SLOT_WEAPON_STAFF] = { row = 1, column = 1, controlName = "Staff" },
            [OUTFIT_SLOT_WEAPON_TWO_HANDED_BACKUP] = { row = 1, column = 1, controlName = "TwoHandedB" }, [OUTFIT_SLOT_SHIELD_BACKUP] = { row = 1, column = 2, controlName = "ShieldB" },
            [OUTFIT_SLOT_WEAPON_MAIN_HAND_BACKUP] = { row = 1, column = 1, controlName = "MainHandB" }, [OUTFIT_SLOT_WEAPON_OFF_HAND_BACKUP] = { row = 1, column = 2, controlName = "OffHandB" },
            [OUTFIT_SLOT_WEAPON_BOW_BACKUP] = { row = 1, column = 1, controlName = "BowB" },
            [OUTFIT_SLOT_WEAPON_STAFF_BACKUP] = { row = 1, column = 1, controlName = "StaffB" },
        },
    }
    self.outfitStylesSheet = self:InitializeSheet(ZO_RestyleOutfitSlotsSheet, slotGridData)
end
function ZO_RestyleSheetWindow_Keyboard:InitializeCompanionEquipmentSheet()
    local slotGridData =
    {
        [ZO_RESTYLE_SHEET_CONTAINER.PRIMARY] =
        {
            [EQUIP_SLOT_SHOULDERS] = { row = 2, column = 1, controlName = "Shoulders" }, [EQUIP_SLOT_CHEST] = { row = 2, column = 2, controlName = "Chest" },
            [EQUIP_SLOT_HAND] = { row = 3, column = 1, controlName = "Hand" }, [EQUIP_SLOT_WAIST] = { row = 3, column = 2, controlName = "Waist" },
            [EQUIP_SLOT_LEGS] = { row = 4, column = 1, controlName = "Legs" }, [EQUIP_SLOT_FEET] = { row = 4, column = 2, controlName = "Feet" },
        },
        [ZO_RESTYLE_SHEET_CONTAINER.SECONDARY] =
        {
            -- Switches with Shield on show based on ActiveWeaponPair
            [EQUIP_SLOT_OFF_HAND] = { row = 1, column = 2, controlName = "Shield" },
        }
    }
    self.companionEquipmentSheet = self:InitializeSheet(ZO_RestyleCompanionEquipmentSlotsSheet, slotGridData)
end
function ZO_RestyleSheetWindow_Keyboard:InitializeCompanionCollectibleSheet()
    local slotGridData =
    {
        [ZO_RESTYLE_SHEET_CONTAINER.PRIMARY] =
        {
            [COLLECTIBLE_CATEGORY_TYPE_COSTUME] = { row = 1, column = 2, controlName = "Costume" },
        },
    }
    self.companionCollectiblesSheet = self:InitializeSheet(ZO_RestyleCompanionCollectibleSlotsSheet, slotGridData)
end
function ZO_RestyleSheetWindow_Keyboard:InitializeCompanionOutfitStylesSheet()
    local slotGridData =
    {
        [ZO_RESTYLE_SHEET_CONTAINER.PRIMARY] =
        {
            [OUTFIT_SLOT_SHOULDERS] = { row = 2, column = 1, controlName = "Shoulders" }, [OUTFIT_SLOT_CHEST] = { row = 2, column = 2, controlName = "Chest" },
            [OUTFIT_SLOT_HANDS] = { row = 3, column = 1, controlName = "Hands" }, [OUTFIT_SLOT_WAIST] = { row = 3, column = 2, controlName = "Waist" },
            [OUTFIT_SLOT_LEGS] = { row = 4, column = 1, controlName = "Legs" }, [OUTFIT_SLOT_FEET] = { row = 4, column = 2, controlName = "Feet" },
        },
        [ZO_RESTYLE_SHEET_CONTAINER.SECONDARY] =
        {
            -- Switches with Shield on show based on ActiveWeaponPair and equipped weapon type
            [OUTFIT_SLOT_WEAPON_TWO_HANDED] = { row = 1, column = 1, controlName = "TwoHanded" }, [OUTFIT_SLOT_SHIELD] = { row = 1, column = 2, controlName = "Shield" },
            [OUTFIT_SLOT_WEAPON_MAIN_HAND] = { row = 1, column = 1, controlName = "MainHand" }, [OUTFIT_SLOT_WEAPON_OFF_HAND] = { row = 1, column = 2, controlName = "OffHand" },
            [OUTFIT_SLOT_WEAPON_BOW] = { row = 1, column = 1, controlName = "Bow" },
            [OUTFIT_SLOT_WEAPON_STAFF] = { row = 1, column = 1, controlName = "Staff" },
        },
    }
    self.companionOutfitStylesSheet = self:InitializeSheet(ZO_RestyleCompanionOutfitSlotsSheet, slotGridData)
end
function ZO_RestyleSheetWindow_Keyboard:OnShowing()
    TUTORIAL_SYSTEM:RegisterTriggerLayoutInfo(TUTORIAL_TYPE_POINTER_BOX, TUTORIAL_TRIGGER_OUTFIT_SELECTOR_SHOWN_POINTER_BOX, self.control, ZO_RESTYLE_SHEET_WINDOW_FRAGMENT, self.outfitSelectorTutorialAnchor)
end
function ZO_RestyleSheetWindow_Keyboard:BeginRestyling()
    BeginRestyling(self.currentSheet:GetRestyleMode())
end
function ZO_RestyleSheetWindow_Keyboard:OnHiding()
    local currentEquippedIndex = ZO_OUTFIT_MANAGER:GetEquippedOutfitIndex(ZO_OUTFIT_MANAGER.GetActorCategoryByRestyleMode(self.currentSheet:GetRestyleMode()))
    if (not self.pendingEquipOutfitManipulator and currentEquippedIndex) or (self.pendingEquipOutfitManipulator and self.pendingEquipOutfitManipulator:GetOutfitIndex() ~= currentEquippedIndex) then
        self:EquipSelectedOutfit()
    end
end
function ZO_RestyleSheetWindow_Keyboard:OnHidden()
    EndRestyling()
end
do
    local IGNORE_CALLBACK = true
    function ZO_RestyleSheetWindow_Keyboard:PopulateEquipmentModeDropdown(keepCurrentSelection)
        if self.currentSheet ~= self.equipmentSheet and self.currentSheet ~= self.outfitStylesSheet then
            self:EquipSelectedOutfit()
            ITEM_PREVIEW_KEYBOARD:ResetOutfitPreview()
        end
        self.modeSelectorHeader:SetText(GetString(SI_RESTYLE_SHEET_SELECT_OUTFIT_HEADER))
        local actorCategory = GAMEPLAY_ACTOR_CATEGORY_PLAYER
        local reselectOutfitIndex = nil
        if keepCurrentSelection then
            local selectedData = self.modeSelectorDropdown:GetSelectedItemData()
            if selectedData and selectedData.outfitManipulator then
                reselectOutfitIndex = selectedData.outfitManipulator:GetOutfitIndex()
                actorCategory = selectedData.outfitManipulator:GetActorCategory()
            end
        end
        self.modeSelectorDropdown:ClearItems()
        self.modeSelectorDropdown:AddItem(self.equipmentGearModeEntry, ZO_COMBOBOX_SUPPRESS_UPDATE)
        local function SetSelectedOutfit(entry)
            local outfitManipulator = entry.outfitManipulator
            self.outfitStylesSheet:SetOutfitManipulator(outfitManipulator)
            ZO_OUTFIT_STYLES_PANEL_KEYBOARD:SetCurrentOutfitManipulator(outfitManipulator)
            self.pendingEquipOutfitManipulator = outfitManipulator
            self:DisplaySheet(self.outfitStylesSheet)
            ITEM_PREVIEW_KEYBOARD:PreviewOutfit(outfitManipulator:GetActorCategory(), outfitManipulator:GetOutfitIndex())
            self:FireCallbacks("ModeSelectorDropdownChanged")
        end
        local function TrySetSelectedOutfit(_, _, entry, selectionChanged, oldEntry)
            if selectionChanged then
                if self:AreChangesPending() then
                    local function Confirm()
                        SetSelectedOutfit(entry)
                    end
                    local function Decline()
                        self.modeSelectorDropdown:SelectItem(oldEntry, IGNORE_CALLBACK)
                    end
                    self:ShowRevertRestyleChangesDialog("CONFIRM_REVERT_OUTFIT_ON_CHANGE", Confirm, Decline)
                else
                    SetSelectedOutfit(entry)
                end
            end
        end
        local equippedOutfitIndex = ZO_OUTFIT_MANAGER:GetEquippedOutfitIndex(actorCategory)
        local defaultEntry = self.equipmentGearModeEntry
        local autoSelectIndex = keepCurrentSelection and reselectOutfitIndex or equippedOutfitIndex
        local numOutfits = ZO_OUTFIT_MANAGER:GetNumOutfits(actorCategory)
        for outfitIndex = 1, numOutfits do
            local outfitManipulator = ZO_OUTFIT_MANAGER:GetOutfitManipulator(actorCategory, outfitIndex)
            local entry = self.modeSelectorDropdown:CreateItemEntry(outfitManipulator:GetOutfitName(), TrySetSelectedOutfit)
            entry.outfitManipulator = outfitManipulator
            entry.selectFunction = SetSelectedOutfit
            self.modeSelectorDropdown:AddItem(entry, ZO_COMBOBOX_SUPPRESS_UPDATE)
            if autoSelectIndex == outfitIndex then
                defaultEntry = entry
            end
        end
        if numOutfits < MAX_OUTFIT_UNLOCKS then
            self.modeSelectorDropdown:AddItem(self.purchaseAdditionalOutfitsEntry, ZO_COMBOBOX_SUPPRESS_UPDATE)
        end
        self.modeSelectorDropdown:UpdateItems()
        self.modeSelectorDropdown:SelectItem(defaultEntry, true)
        defaultEntry.selectFunction(defaultEntry)
    end
end
function ZO_RestyleSheetWindow_Keyboard:PopulateCollectiblesModeDropdown()
    if self.currentSheet ~= self.collectiblesSheet or self.currentSheet ~= self.companionCollectiblesSheet then
        self:EquipSelectedOutfit()
        ITEM_PREVIEW_KEYBOARD:ResetOutfitPreview()
    end
    self.modeSelectorDropdown:ClearItems()
    self.modeSelectorDropdown:AddItem(self.collectiblesModeEntry, ZO_COMBOBOX_SUPPRESS_UPDATE)
    self.modeSelectorDropdown:UpdateItems()
    self.modeSelectorDropdown:SelectFirstItem()
    ITEM_PREVIEW_KEYBOARD:ClearPreviewCollection();
end
function ZO_RestyleSheetWindow_Keyboard:PopulateCompanionOutfitsModeDropdown()
    if self.currentSheet ~= self.companionEquipmentSheet and self.currentSheet ~= self.companionOutfitStylesSheet then
        self:EquipSelectedOutfit()
        ITEM_PREVIEW_KEYBOARD:ResetOutfitPreview()
    end
    self.modeSelectorHeader:SetText(GetString(SI_RESTYLE_SHEET_SELECT_OUTFIT_HEADER))
    local actorCategory = GAMEPLAY_ACTOR_CATEGORY_COMPANION
    local reselectOutfitIndex = nil
    if keepCurrentSelection then
        local selectedData = self.modeSelectorDropdown:GetSelectedItemData()
        if selectedData and selectedData.outfitManipulator then
            reselectOutfitIndex = selectedData.outfitManipulator:GetOutfitIndex()
            actorCategory = selectedData.outfitManipulator:GetActorCategory()
        end
    end
    self.modeSelectorDropdown:ClearItems()
    self.modeSelectorDropdown:AddItem(self.companionEquipmentGearModeEntry, ZO_COMBOBOX_SUPPRESS_UPDATE)
    local function SetSelectedOutfit(entry)
        local outfitManipulator = entry.outfitManipulator
        self.companionOutfitStylesSheet:SetOutfitManipulator(outfitManipulator)
        ZO_OUTFIT_STYLES_PANEL_KEYBOARD:SetCurrentOutfitManipulator(outfitManipulator)
        self.pendingEquipOutfitManipulator = outfitManipulator
        self:DisplaySheet(self.companionOutfitStylesSheet)
        ITEM_PREVIEW_KEYBOARD:PreviewOutfit(outfitManipulator:GetActorCategory(), outfitManipulator:GetOutfitIndex())
        self:FireCallbacks("ModeSelectorDropdownChanged")
    end
    local function TrySetSelectedOutfit(_, _, entry, selectionChanged, oldEntry)
        if selectionChanged then
            if self:AreChangesPending() then
                local function Confirm()
                    SetSelectedOutfit(entry)
                end
                local function Decline()
                    self.modeSelectorDropdown:SelectItem(oldEntry, IGNORE_CALLBACK)
                end
                self:ShowRevertRestyleChangesDialog("CONFIRM_REVERT_OUTFIT_ON_CHANGE", Confirm, Decline)
            else
                SetSelectedOutfit(entry)
            end
        end
    end
    local equippedOutfitIndex = ZO_OUTFIT_MANAGER:GetEquippedOutfitIndex(actorCategory)
    local defaultEntry = self.companionEquipmentGearModeEntry
    local autoSelectIndex = keepCurrentSelection and reselectOutfitIndex or equippedOutfitIndex
    local numOutfits = ZO_OUTFIT_MANAGER:GetNumOutfits(GAMEPLAY_ACTOR_CATEGORY_COMPANION)
    for outfitIndex = 1, numOutfits do
        local outfitManipulator = ZO_OUTFIT_MANAGER:GetOutfitManipulator(actorCategory, outfitIndex)
        local entry = self.modeSelectorDropdown:CreateItemEntry(outfitManipulator:GetOutfitName(), TrySetSelectedOutfit)
        entry.outfitManipulator = outfitManipulator
        entry.selectFunction = SetSelectedOutfit
        self.modeSelectorDropdown:AddItem(entry, ZO_COMBOBOX_SUPPRESS_UPDATE)
        if autoSelectIndex == outfitIndex then
            defaultEntry = entry
        end
    end
    self.modeSelectorDropdown:UpdateItems()
    self.modeSelectorDropdown:SelectItem(defaultEntry, true)
    defaultEntry.selectFunction(defaultEntry)
end
function ZO_RestyleSheetWindow_Keyboard:PopulateCompanionCollectiblesModeDropdown()
    if self.currentSheet ~= self.collectiblesSheet or self.currentSheet ~= self.companionCollectiblesSheet then
        self:EquipSelectedOutfit()
        ITEM_PREVIEW_KEYBOARD:ResetOutfitPreview()
    end
    self.modeSelectorDropdown:ClearItems()
    self.modeSelectorDropdown:AddItem(self.companionCollectiblesModeEntry, ZO_COMBOBOX_SUPPRESS_UPDATE)
    self.modeSelectorDropdown:UpdateItems()
    self.modeSelectorDropdown:SelectFirstItem()
    ITEM_PREVIEW_KEYBOARD:ClearPreviewCollection();
end
function ZO_RestyleSheetWindow_Keyboard:OnUpdate()
    local isPreviewingAvailable = IsCharacterPreviewingAvailable()
    if self.isPreviewAvailable ~= isPreviewingAvailable then
        self.isPreviewAvailable = isPreviewingAvailable
        self.modeSelectorDropdown:SetEnabled(self.isPreviewAvailable)
    end
end
function ZO_RestyleSheetWindow_Keyboard:OnUpdateModeSelectorDropdown()
    local isEthereal = self.modeSelectorDropdown:GetNumItems() == 1
    self.modeSelectorHeader:SetHidden(isEthereal)
    self.modeSelectorDropdownControl:SetHidden(isEthereal)
end
function ZO_RestyleSheetWindow_Keyboard:DisplaySheet(newSheet)
    local isPreviewUpdated = false
    if self.currentSheet ~= newSheet then
        if self.currentSheet then
            SCENE_MANAGER:RemoveFragment(self.currentSheet:GetFragment())
        end
        local oldSheet = self.currentSheet
        self.currentSheet = newSheet
        if newSheet then
            -- make sure the current sheet has the latest dye data for its slots
            SetRestylePreviewMode(newSheet:GetRestyleMode())
            isPreviewUpdated = true
        end
        self:FireCallbacks("SheetChanged", newSheet, oldSheet)
    end
    if newSheet then
        if not isPreviewUpdated then
            -- make sure the current sheet has the latest dye data for its slots
            SetRestylePreviewMode(newSheet:GetRestyleMode())
        end
        SCENE_MANAGER:AddFragment(newSheet:GetFragment())
        if self.pendingEquipOutfitManipulator and self.pendingEquipOutfitManipulator:IsMarkedForPreservation() then
            local interactType = GetInteractionType()
            if interactType == INTERACTION_DYE_STATION then
                self.pendingEquipOutfitManipulator:RestorePreservedDyeData()
                self.pendingEquipOutfitManipulator:UpdatePreviews()
            else
                self.pendingEquipOutfitManipulator:SetMarkedForPreservation(false)
                self.pendingEquipOutfitManipulator:ClearPendingChanges(true)
            end
        end
    end
end
function ZO_RestyleSheetWindow_Keyboard:OnSheetSlotRefreshed(restyleSlotData)
    self:FireCallbacks("SheetSlotRefreshed", restyleSlotData)
end
function ZO_RestyleSheetWindow_Keyboard:OnSheetMouseoverDataChanged(newData)
    self:FireCallbacks("SheetMouseoverDataChanged", newData)
end
function ZO_RestyleSheetWindow_Keyboard:NavigateToCollectibleCategoryFromRestyleSlotData(restyleSlotData)
    self:FireCallbacks("NavigateToCollectibleCategoryFromRestyleSlotData", restyleSlotData)
end
function ZO_RestyleSheetWindow_Keyboard:ShowRevertRestyleChangesDialog(dialogName, confirmCallback, declineCallback)
    local function Confirm()
        self:UndoPendingChanges()
        if confirmCallback then
            confirmCallback()
        end
    end
end
function ZO_RestyleSheetWindow_Keyboard:GetCurrentSheet()
    return self.currentSheet
end
function ZO_RestyleSheetWindow_Keyboard:GetSheetByMode(restyleMode)
    return self.sheetsByMode[restyleMode]
end
function ZO_RestyleSheetWindow_Keyboard:OnDyeSlotClicked(restyleSlotData, dyeChannel, button)
    self:FireCallbacks("DyeSlotClicked", restyleSlotData, dyeChannel, button)
end
do
    local UNKNOWN_DYE = false
    local IS_PLAYER_DYE = false
    local IS_NON_PLAYER_DYE = true
    local IS_LEFT_ANCHORED = false
    function ZO_RestyleSheetWindow_Keyboard:OnDyeSlotEnter(restyleSlotData, dyeChannel, dyeControl)
        if not self:FireCallbacks("DyeSlotEnter", restyleSlotData, dyeChannel, dyeControl) then
            local activeTool = ZO_DYEING_KEYBOARD:GetActiveTool()
            if activeTool then
                local highlightSlot, highlightDyeChannel = activeTool:GetHighlightRules(restyleSlotData:GetRestyleSlotType(), dyeChannel)
                self.currentSheet:ToggleDyeableSlotHightlight(highlightSlot, true, highlightDyeChannel)
                WINDOW_MANAGER:SetMouseCursor(activeTool:GetCursorType())
            end
            local dyeId = select(dyeChannel, restyleSlotData:GetPendingDyes())
            if dyeId ~= 0 then
                local playerDyeInfo = ZO_DYEING_MANAGER:GetPlayerDyeInfoById(dyeId)
                if playerDyeInfo then
                    local anchoringControl = dyeControl
                    local isRightAnchored = false
                    ZO_Dyeing_CreateTooltipOnMouseEnter(anchoringControl, playerDyeInfo.dyeName, playerDyeInfo.known, playerDyeInfo.achievementId, IS_PLAYER_DYE, isRightAnchored)
                else
                    local nonPlayerDye = ZO_DYEING_MANAGER:GetOrCreateNonPlayerDyeInfoById(dyeId)
                    if nonPlayerDye.dyeName ~= "" then
                        ZO_Dyeing_CreateTooltipOnMouseEnter(dyeControl, nonPlayerDye.dyeName, UNKNOWN_DYE, nonPlayerDye.achievementId, IS_NON_PLAYER_DYE, IS_LEFT_ANCHORED)
                    end
                end
            end
        end
    end
end
do
    local NO_SLOT = nil
    local NO_CHANNEL = nil
    function ZO_RestyleSheetWindow_Keyboard:OnDyeSlotExit(restyleSlotData, dyeChannel)
        if not self:FireCallbacks("DyeSlotExit", restyleSlotData, dyeChannel) then
            self.currentSheet:ToggleDyeableSlotHightlight(NO_SLOT, false, NO_CHANNEL)
            WINDOW_MANAGER:SetMouseCursor(MOUSE_CURSOR_DO_NOT_CARE)
            ZO_Dyeing_ClearTooltipOnMouseExit()
        end
    end
end
function ZO_RestyleSheetWindow_Keyboard:EquipSelectedOutfit()
    if self.pendingEquipOutfitManipulator then
        ZO_OUTFIT_MANAGER:EquipOutfit(self.pendingEquipOutfitManipulator:GetActorCategory(), self.pendingEquipOutfitManipulator:GetOutfitIndex())
    else
        local actorCategory = ZO_OUTFIT_MANAGER.GetActorCategoryByRestyleMode(self.currentSheet:GetRestyleMode())
        if actorCategory then
            ZO_OUTFIT_MANAGER:UnequipOutfit(actorCategory)
        end
    end
end
function ZO_RestyleSheetWindow_Keyboard:ShowUndoPendingChangesDialog()
    ZO_Dialogs_ShowDialog("CONFIRM_REVERT_OUTFIT_CHANGES", { confirmCallback = function() self.currentSheet:UndoPendingChanges() end})
end
function ZO_RestyleSheetWindow_Keyboard:UndoPendingChanges()
    self.currentSheet:UndoPendingChanges()
end
function ZO_RestyleSheetWindow_Keyboard:AreChangesPending()
    return self.currentSheet:AreChangesPending()
end
function ZO_RestyleSheetWindow_Keyboard:CanApplyChanges()
    return self.currentSheet:CanApplyChanges()
end
    ZO_RESTYLE_SHEET_WINDOW_KEYBOARD = ZO_RestyleSheetWindow_Keyboard:New(control)
end