ESO Lua File v100015

pregame/characterselect/gamepad/zo_characterselect_gamepad.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
local g_currentlySelectedCharacterData
local g_lastSelectedData
local g_canPlayCharacter = true
local g_canCreateCharacter = true
ZO_CHARACTER_SELECT_DETAILS_VALUE_OFFSET_Y = -14
ZO_GAMEPAD_CHARACTER_SELECT_LIST_ENTRY_CHAMPION_ICON_X_OFFSET = -20
local ACTIVATE_VIEWPORT = true
local ENTRY_TYPE_EXTRA_INFO = 1
local ENTRY_TYPE_CHARACTER = 2
local ENTRY_TYPE_CREATE_NEW = 3
local SERVICE_MODE_NONE = 0
local SERVICE_MODE_NAME_CHANGE = 1
local CREATE_NEW_ICON = "EsoUI/Art/Buttons/Gamepad/gp_plus_large.dds"
local NAME_CHANGE_TOKEN_ICON = "EsoUI/Art/Icons/Token_NameChange.dds"
--[[ Character Select Delete Screen ]]--
local EXPECTED_ICON_SIZE = 64
local BASE_PERCENT = 100
local CHARACTER_DELETE_KEY_ICONS = {
    [true] = {    KEY_GAMEPAD_LEFT_SHOULDER_HOLD,
                KEY_GAMEPAD_RIGHT_SHOULDER_HOLD,
                KEY_GAMEPAD_LEFT_TRIGGER_HOLD,
                KEY_GAMEPAD_RIGHT_TRIGGER_HOLD },
    [false] = {   KEY_GAMEPAD_LEFT_SHOULDER,
                KEY_GAMEPAD_RIGHT_SHOULDER,
                KEY_GAMEPAD_LEFT_TRIGGER,
                KEY_GAMEPAD_RIGHT_TRIGGER },
}
local CHARACTER_DELETE_TEXT_ANIM = {
    ".",
    "..",
    "...",
}
local CHARACTER_DELETE_TEXT_ANIM_SPEED = 0.5
    local path, width, height = ZO_Keybindings_GetTexturePathForKey(key)
    if path then
        local widthPercent = (width / EXPECTED_ICON_SIZE) * BASE_PERCENT;
        local heightPercent = (height / EXPECTED_ICON_SIZE) * BASE_PERCENT;
        return ("|t%f%%:%f%%:%s|t"):format(widthPercent, heightPercent, path)
    end
    return ""
end
    local self = ZO_CharacterSelect_Gamepad
    SCENE_MANAGER:AddFragment(CHARACTER_SELECT_CHARACTERS_GAMEPAD_FRAGMENT)
    ZO_CharacterSelect_GamepadCharacterDetails:SetHidden(false)
    
    if activateViewPort then
        ZO_CharacterSelect_GamepadCharacterViewport.Activate()
    end
    
    self.characterList:Activate()
end
    local keys = ZO_CharacterSelect_Gamepad.deleteKeys
    local keyText = ""
    for i, enabled in ipairs(keys) do
        if (keyText ~= "") then
            keyText = keyText .. " "   -- Space out the icons
        end
        local keyCode = CHARACTER_DELETE_KEY_ICONS[enabled][i]
        keyText = keyText .. ZO_CharacterSelect_Gamepad_GetKeyText(keyCode)
    end
    return keyText
end
    local keys = ZO_CharacterSelect_Gamepad.deleteKeys
    for i = 1, #keys do
        keys[i] = false
    end
end
local function ZO_CharacterSelectDelete_Gamepad_OnKeyChanged(key, onDown)
    local self = ZO_CharacterSelect_Gamepad
    local keys = self.deleteKeys
    if self.deleting then
        return
    end
    if (onDown) then
        PlaySound(SOUNDS.POSITIVE_CLICK)
    else
        PlaySound(SOUNDS.NEGATIVE_CLICK)
    end
    -- Change key if we pressed it
    for i, deleteKey in ipairs(CHARACTER_DELETE_KEY_ICONS[false]) do
        if deleteKey == key then
            keys[i] = onDown
        end
    end
    -- Are all of them activated?
    local activated = 0
    for i, deleteKey in ipairs(CHARACTER_DELETE_KEY_ICONS[false]) do
        if keys[i] then
            activated = activated + 1
        end
    end
    if (activated == #CHARACTER_DELETE_KEY_ICONS[false]) then
        -- Delete character and exit dialog
        PlaySound(SOUNDS.DIALOG_ACCEPT)
        self.deleting = true
        ZO_Dialogs_ReleaseDialog("CONFIRM_DELETE_SELECTED_CHARACTER_GAMEPAD")
        ZO_Dialogs_ShowGamepadDialog("CHARACTER_SELECT_DELETING", {characterId = g_currentlySelectedCharacterData.id})
    end
end
    ZO_Dialogs_RegisterCustomDialog("CONFIRM_DELETE_SELECTED_CHARACTER_GAMEPAD",
    {
        gamepadInfo =
        {
            dialogType = GAMEPAD_DIALOGS.BASIC,
        },
        setup = function()
        end,
        updateFn = function(dialog)
            ZO_Dialogs_RefreshDialogText("CONFIRM_DELETE_SELECTED_CHARACTER_GAMEPAD", dialog, { mainTextParams = { ZO_CharacterSelect_Gamepad_GetDeleteKeyText() }})
        end,
        mustChoose = true,
        title =
        {
            text = SI_CONFIRM_DELETE_CHARACTER_DIALOG_GAMEPAD_TITLE,
        },
        mainText =
        {
            text = SI_CONFIRM_DELETE_CHARACTER_DIALOG_GAMEPAD_TEXT,
        },
        blockDialogReleaseOnPress = true,
        buttons =
        {
            {
                text = GetString(SI_CHARACTER_SELECT_GAMEPAD_DELETE_CANCEL),
                keybind = "DIALOG_NEGATIVE",
                callback = function()
                    local self = ZO_CharacterSelect_Gamepad
                    local selectedData = self.characterList:GetTargetData()
                    PlaySound(SOUNDS.GAMEPAD_MENU_BACK)
                    ZO_CharacterSelect_Gamepad_ReturnToCharacterList(ACTIVATE_VIEWPORT)
                    if selectedData and selectedData.needsRename then
                        ZO_CharacterSelect_Gamepad_RefreshKeybindStrip(self.charListKeybindStripDescriptorRename)
                    else
                        ZO_CharacterSelect_Gamepad_RefreshKeybindStrip(self.charListKeybindStripDescriptorDefault)
                    end
                    ZO_Dialogs_ReleaseDialog("CONFIRM_DELETE_SELECTED_CHARACTER_GAMEPAD")
                end,
            },
            {
                keybind = "DIALOG_LEFT_SHOULDER",
                handlesKeyUp = true,
                ethereal = true,
                callback = function(dialog, onUp)
                    ZO_CharacterSelectDelete_Gamepad_OnKeyChanged(KEY_GAMEPAD_LEFT_SHOULDER, not onUp)
                end,
            },
            {
                keybind = "DIALOG_RIGHT_SHOULDER",
                handlesKeyUp = true,
                ethereal = true,
                callback = function(dialog, onUp)
                    ZO_CharacterSelectDelete_Gamepad_OnKeyChanged(KEY_GAMEPAD_RIGHT_SHOULDER, not onUp)
                end,
            },
            {
                keybind = "DIALOG_LEFT_TRIGGER",
                handlesKeyUp = true,
                ethereal = true,
                callback = function(dialog, onUp)
                    ZO_CharacterSelectDelete_Gamepad_OnKeyChanged(KEY_GAMEPAD_LEFT_TRIGGER, not onUp)
                end,
            },
            {
                keybind = "DIALOG_RIGHT_TRIGGER",
                handlesKeyUp = true,
                ethereal = true,
                callback = function(dialog, onUp)
                    ZO_CharacterSelectDelete_Gamepad_OnKeyChanged(KEY_GAMEPAD_RIGHT_TRIGGER, not onUp)
                end,
            },
        },
    })
end
    ZO_CharacterSelect_GamepadCharacterViewport.Deactivate()
    ZO_Dialogs_ShowGamepadDialog("CONFIRM_DELETE_SELECTED_CHARACTER_GAMEPAD")
end
--[[ Character Select Screen ]]--
local function InitKeybindingDescriptor(self)
    local deleteKeybind = {
        name = GetString(SI_CHARACTER_SELECT_GAMEPAD_DELETE),
        keybind = "UI_SHORTCUT_SECONDARY",
        disabledDuringSceneHiding = true,
        callback = function()
            self.characterList:Deactivate() -- So we can't select a different character
            PlaySound(SOUNDS.GAMEPAD_MENU_FORWARD)
            local numCharacterDeletesRemaining = GetNumCharacterDeletesRemaining()
            local selectedData = self.characterList:GetTargetData()
            if numCharacterDeletesRemaining == 0 then
                ZO_Dialogs_ShowGamepadDialog("DELETE_SELECTED_CHARACTER_NO_DELETES_LEFT_GAMEPAD", {keybindDescriptor = self.charListKeybindStripDescriptorDefault})
            elseif selectedData and selectedData.needsRename then
                ZO_Dialogs_ShowGamepadDialog("DELETE_SELECTED_CHARACTER_GAMEPAD", {keybindDescriptor = self.charListKeybindStripDescriptorRename}, {mainTextParams = {numCharacterDeletesRemaining}})
            else
                ZO_Dialogs_ShowGamepadDialog("DELETE_SELECTED_CHARACTER_GAMEPAD", {keybindDescriptor = self.charListKeybindStripDescriptorDefault}, {mainTextParams = {numCharacterDeletesRemaining}})
            end
        end,
    }
    local optionsKeybind = {
        name = GetString(SI_CHARACTER_SELECT_GAMEPAD_OPTIONS),
        keybind = "UI_SHORTCUT_TERTIARY",
        callback = function()
            -- fix to keep both buttons from being pushable in the time it takes for the state to change
            local state = PregameStateManager_GetCurrentState()
            if(state == "CharacterSelect" or state == "CharacterSelect_FromCinematic") then
                SCENE_MANAGER:Push("gamepad_options_root")
            end
        end,
    }
    self.charListKeybindStripDescriptorDefault =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        {
            name = GetString(SI_CHARACTER_SELECT_GAMEPAD_PLAY),
            keybind = "UI_SHORTCUT_PRIMARY",
            disabledDuringSceneHiding = true,
            callback = function()
                if ZO_CharacterSelect_Gamepad_Login(CHARACTER_OPTION_EXISTING_AREA) then
                    self.characterList:Deactivate() -- So we can't select a different character
                    PlaySound(SOUNDS.DIALOG_ACCEPT)
                    ZO_CharacterSelect_Gamepad_ClearKeybindStrip()
                end
            end,
        },
        deleteKeybind,
        optionsKeybind,
        KEYBIND_STRIP:GenerateGamepadBackButtonDescriptor(function() PregameStateManager_SetState("Disconnect") end),
    }
    ZO_Gamepad_AddListTriggerKeybindDescriptors(self.charListKeybindStripDescriptorDefault, self.characterList)
    self.charListKeybindStripDescriptorRename =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        {
            name = GetString(SI_CHARACTER_SELECT_GAMEPAD_RENAME),
            keybind = "UI_SHORTCUT_PRIMARY",
            disabledDuringSceneHiding = true,
            callback = function()
                self.characterList:Deactivate() -- So we can't select a different character
                PlaySound(SOUNDS.DIALOG_ACCEPT)
                SCENE_MANAGER:RemoveFragment(CHARACTER_SELECT_CHARACTERS_GAMEPAD_FRAGMENT)
                ZO_CharacterSelect_GamepadCharacterDetails:SetHidden(true)
                ZO_CharacterSelect_Gamepad_BeginRename()
            end,
        },
        deleteKeybind,
        optionsKeybind,
        KEYBIND_STRIP:GenerateGamepadBackButtonDescriptor(function() PregameStateManager_SetState("Disconnect") end),
    }
    ZO_Gamepad_AddListTriggerKeybindDescriptors(self.charListKeybindStripDescriptorRename, self.characterList)
    -- Different keybinding for Create New option
    self.charListKeybindStripDescriptorCreateNew =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        {
            name = GetString(SI_CHARACTER_SELECT_GAMEPAD_CREATE_NEW),
            keybind = "UI_SHORTCUT_PRIMARY",
            disabledDuringSceneHiding = true,
            callback = function()
                self.characterList:Deactivate() -- So we can't select a different character
                PlaySound(SOUNDS.DIALOG_ACCEPT)
                PlaySound(SOUNDS.GAMEPAD_MENU_FORWARD)
                PregameStateManager_SetState("CharacterCreate")
            end,
        },
        optionsKeybind,
        KEYBIND_STRIP:GenerateGamepadBackButtonDescriptor(function() PregameStateManager_SetState("Disconnect") end),
    }
    ZO_Gamepad_AddListTriggerKeybindDescriptors(self.charListKeybindStripDescriptorCreateNew, self.characterList)
    -- Keybinds for the additional character slot control
    self.charListKeybindStripDescriptorAdditionalSlots =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        optionsKeybind,
        KEYBIND_STRIP:GenerateGamepadBackButtonDescriptor(function() PregameStateManager_SetState("Disconnect") end),
    }
    -- Keybinds for service token controls
    self.charListKeybindStripDescriptorServices =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        -- Select service
        {
            name = GetString(SI_SERVICE_USE_SERVICE_KEYBIND),
            keybind = "UI_SHORTCUT_PRIMARY",
            disabledDuringSceneHiding = true,
            enabled = function()
                local requestedServiceMode = ZO_CharacterSelect_Gamepad_GetSelectedServiceMode()
                if requestedServiceMode == SERVICE_MODE_NAME_CHANGE then
                    return GetNumCharacterRenameTokens() > 0
                end
                return false
            end,
            callback = function()
                local newServiceMode = ZO_CharacterSelect_Gamepad_GetSelectedServiceMode()
                local RESET_LIST_TO_DEFAULT = true
                ZO_CharacterSelect_Gamepad_ChangeServiceMode(newServiceMode, RESET_LIST_TO_DEFAULT)
            end,
        },
        optionsKeybind,
        KEYBIND_STRIP:GenerateGamepadBackButtonDescriptor(function() PregameStateManager_SetState("Disconnect") end),
    }
    -- Keybinds for using service tokens on the character list
    self.charListKeybindStripDescriptorUseServiceToken =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        -- Use service token
        {
            name = GetString(SI_GAMEPAD_SELECT_OPTION),
            keybind = "UI_SHORTCUT_PRIMARY",
            disabledDuringSceneHiding = true,
            visible = function()
                return self.characterList:GetNumEntries() > 0
            end,
            callback = function()
                -- Perform a different function based on the currently selected service mode
                if self.serviceMode == SERVICE_MODE_NAME_CHANGE then
                    ZO_CharacterSelect_Gamepad_BeginRename()
                end
            end,
        },
        -- Custom back button behavior
        {
            name = GetString(SI_SERVICE_BACK_KEYBIND),
            keybind = "UI_SHORTCUT_NEGATIVE",
            disabledDuringSceneHiding = true,
            callback = function()
                -- If the back button is pressed before a service token is consumed, return the player back up to the extra info menu
                local RESET_LIST_TO_DEFAULT = true
                ZO_CharacterSelect_Gamepad_ChangeServiceMode(SERVICE_MODE_NONE, RESET_LIST_TO_DEFAULT)
            end,
        },
    }
    ZO_Gamepad_AddListTriggerKeybindDescriptors(self.charListKeybindStripDescriptorUseServiceToken, self.characterList)
    self.charListKeybindStripDescriptorLogin =
    {
    }
    self.charListKeybindStripDescriptor = self.charListKeybindStripDescriptorDefault
end
local function GetClassIconGamepad(classIdRequested)
    for i = 1, GetNumClasses() do
        local classId, _, _, _, _, _, _, _, gamepadNormalIcon, gamepadPressedIcon = GetClassInfo(i)
        if classId == classIdRequested then
            return gamepadPressedIcon
        end
    end
    return nil
end
local function AddCharacterListEntry(template, data, list)
    local text = (data.name ~= nil) and zo_strformat(SI_CHARACTER_SELECT_NAME, data.name) or data.text
    local newEntry = ZO_GamepadEntryData:New(text, data.icon)
    if data.header then
        newEntry:SetHeader(data.header)
    end
    newEntry:SetFontScaleOnSelection(true)
    -- character select stores a bunch of data that we need on this entry to function correctly
    newEntry:SetDataSource(data)
    newEntry:SetIconTintOnSelection(true)
    list:AddEntry(template, newEntry)
end
local function CharacterListEntry_OnSetup(control, data, selected, selectedDuringRebuild, enabled, activated)
    data:ClearIcons()
    -- we can't set these up at list creation time as the character data isn't fully loaded yet (GetNumClasses() returns 0, which makes GetClassIconGamepad(...) results all nil)
    icon = ((data.name ~= nil) and data.class) and GetClassIconGamepad(data.class) or data.icon
    data:AddIcon(icon)
    ZO_SharedGamepadEntry_OnSetup(control, data, selected, reselectingDuringRebuild, enabled, activated)
end
local function GamepadCharacterSelectMenuEntryHeader_Setup(headerControl, data, ...)
    local subHeader = headerControl:GetNamedChild("SubHeader")
    if subHeader then
        subHeader:SetText(data.subHeader or "")
    end
end
    return g_maxCharacters
end
local function ZO_CharacterSelect_Gamepad_SetMaxCharacters(characterLimit)
    g_maxCharacters = characterLimit
end
-- Extra Info Functions
local function CanShowExtraInfo(self)
    return self.serviceMode == SERVICE_MODE_NONE
end
local function CreateExtraInfoEntry(self, data)
    local control, key = self.extraInfoControlPool:AcquireObject()
    control.key = key
    control.owner = self
    control.data = data
    control.icon = control:GetNamedChild("Icon")
    control.frame = control:GetNamedChild("Frame")
    control.tokenCount = control:GetNamedChild("TokenCount")
    if data.icon then
        control.icon:AddIcon(data.icon)
        control.icon:SetHidden(false)
    end
    if data.tokenCount then
        control.tokenCount:SetText(data.tokenCount)
    end
    control.tokenCount:SetHidden(data.tokenCount == nil)
    return control
end
local function ActivateFocusEntry(control)
    control.frame:SetEdgeColor(ZO_SELECTED_TEXT:UnpackRGB())
    if control.data.ShowTooltipFunction then
        control.data.ShowTooltipFunction()
    end
end
local function DeactivateFocusEntry(control)
    control.frame:SetEdgeColor(ZO_NORMAL_TEXT:UnpackRGB())
    if control.data.HideTooltipFunction then
        control.data.HideTooltipFunction()
    end
end
    local focusEntry = {
        control = control,
        activate = ActivateFocusEntry,
        deactivate = DeactivateFocusEntry,
    }
    self.extraInfoFocus:AddEntry(focusEntry)
    table.insert(self.extraInfoControls, control)
end
local PADDING_X = 8
local PADDING_Y = 3
local function CenterExtraInfoControls(self)
    local numControls = #self.extraInfoControls
    
    if numControls > 0 then
        local controlWidth = self.extraInfoControls[1]:GetWidth()
        local stride = controlWidth + PADDING_X
        local currentOffsetX = (stride * (numControls - 1)) / -2
        for i = 1, numControls do
            self.extraInfoControls[i]:SetAnchor(CENTER, self.extraInfoCenterer, CENTER, currentOffsetX, PADDING_Y)
            currentOffsetX = currentOffsetX + stride
        end
    end
end
local function CreateExtraInfoControls(self)
    self.extraInfoFocus:RemoveAllEntries()
    if self.extraInfoControls then
        for i, control in ipairs(self.extraInfoControls) do
            self.extraInfoControlPool:ReleaseObject(control.key)
        end
    end
    self.extraInfoControls = {}
    
    local showExtraInfo = CanShowExtraInfo(self)
    if showExtraInfo then
        local data = {}
        -- Name Change Tokens
        table.insert(data, {
                                keybindStripDesc = self.charListKeybindStripDescriptorServices,
                                icon = NAME_CHANGE_TOKEN_ICON,
                                tokenCount = GetNumCharacterRenameTokens(),
                                serviceMode = SERVICE_MODE_NAME_CHANGE,
                                ShowTooltipFunction = function()
                                        self.extraInfoDetails:SetHidden(false)
                                        
                                        local title = GetString(SI_SERVICE_TOOLTIP_NAME_CHANGE_TOKEN_HEADER)
                                        local body1 = GetString(SI_SERVICE_TOOLTIP_NAME_CHANGE_TOKEN_DESCRIPTION)
                                        local body2
                                        local body2Color
                                        local numTokens = GetNumCharacterRenameTokens()
                                        if numTokens ~= 0 then
                                            body2 = zo_strformat(SI_SERVICE_TOOLTIP_NAME_CHANGE_TOKENS_AVAILABLE, numTokens)
                                            body2Color = ZO_SUCCEEDED_TEXT
                                        else
                                            body2 = GetString(SI_SERVICE_TOOLTIP_NO_NAME_CHANGE_TOKENS_AVAILABLE)
                                            body2Color = ZO_ERROR_COLOR
                                        end
                                        ZO_CharacterSelect_Gamepad_SetExtraInfoDetails(title, body1, nil, body2, body2Color)
                                    end,
                                HideTooltipFunction = function()
                                        self.extraInfoDetails:SetHidden(true)
                                    end,
                           })
        -- Add more extra info controls above this line
        for i=1, #data do
            local control = CreateExtraInfoEntry(self, data[i])
            AddExtraInfoEntryToFocus(self, control)
        end
        CenterExtraInfoControls(self)
    end
    self.extraInfoContainer:SetHidden(true)
end
    if control and control.data then
    end
end
    local headerVisible = self.serviceMode ~= SERVICE_MODE_NONE
    if headerVisible then
        local tokenCount = 0
        local instructions = ""
        if self.serviceMode == SERVICE_MODE_NAME_CHANGE then
            tokenCount = GetNumCharacterRenameTokens()
            instructions = GetString(SI_SERVICE_NAME_CHANGE_TOKEN_INSTRUCTIONS)
        end
        self.serviceTokensLabel:SetText(tostring(tokenCount))
        self.serviceInstructions:SetText(instructions)
    end
    self.serviceHeader:SetHidden(true)
end
local function SetExtraInfoLabel(self, labelName, text, color)
    local label = self.extraInfoDetails:GetNamedChild(labelName)
    label:SetText(text or "")
    if color then
        label:SetColor(color:UnpackRGBA())
    else
        label:SetColor(ZO_NORMAL_TEXT:UnpackRGBA())
    end
end
function ZO_CharacterSelect_Gamepad_SetExtraInfoDetails(title, body1, body1Color, body2, body2Color)
    local self = ZO_CharacterSelect_Gamepad
    self.extraInfoDetails:GetNamedChild("Title"):SetText(title or "")
    SetExtraInfoLabel(self, "Description1", body1, body1Color)
    SetExtraInfoLabel(self, "Description2", body2, body2Color)
end
-- End Extra Info functions
local function CreateList(self)
    self.characterList:Clear()
    local characterDataList = ZO_CharacterSelect_GetCharacterDataList()
    local slot = 1
    if(#characterDataList > 0) then
        local isFirstEntry = true
        
        -- Add Rename characters
        if self.serviceMode ~= SERVICE_MODE_NAME_CHANGE then
            for i, data in ipairs(characterDataList) do
                if data.needsRename then
                    local template = "ZO_GamepadMenuEntryTemplateLowercase34"
                    if isFirstEntry then
                        data.header = GetString(SI_CHARACTER_SELECT_GAMEPAD_RENAME_HEADER)
                        template = "ZO_GamepadMenuEntryTemplateLowercase34WithHeader"
                        isFirstEntry = false
                    end
                    data.slot = slot
                    data.type = ENTRY_TYPE_CHARACTER
                    slot = slot + 1
                    AddCharacterListEntry(template , data, self.characterList)
                end
            end
        end
        isFirstEntry = true
        -- Add Selectable characters
        for i, data in ipairs(characterDataList) do
            if not data.needsRename then
                local template = "ZO_GamepadMenuEntryTemplateLowercase34"
                if isFirstEntry then
                    data.header = GetString(SI_CHARACTER_SELECT_GAMEPAD_CHARACTERS_HEADER)
                    template = "ZO_GamepadMenuEntryTemplateLowercase34WithHeader"
                    isFirstEntry = false
                    if self.serviceMode == SERVICE_MODE_NONE and ZO_CharacterSelect_CanShowAdditionalSlotsInfo() then
                        data.subHeader = zo_strformat(SI_ADDITIONAL_CHARACTER_SLOTS_DESCRIPTION, ZO_CharacterSelect_GetAdditionalSlotsRemaining())
                    else
                        data.subHeader = nil
                    end
                end
                data.slot = slot
                data.type = ENTRY_TYPE_CHARACTER
                slot = slot + 1
                AddCharacterListEntry(template, data, self.characterList)
            end
        end
    end
    if self.serviceMode == SERVICE_MODE_NONE then
        -- Add Create New
        if (slot <= ZO_CharacterSelect_Gamepad_GetMaxCharacters()) then
            local data = { index = slot, type = ENTRY_TYPE_CREATE_NEW, header = GetString(SI_CHARACTER_SELECT_GAMEPAD_CREATE_NEW_HEADER), icon = CREATE_NEW_ICON, text = GetString(SI_CHARACTER_SELECT_GAMEPAD_CREATE_NEW_ENTRY)}
            AddCharacterListEntry("ZO_GamepadMenuEntryTemplateWithHeader", data, self.characterList)
        end
    elseif self.characterList:GetNumEntries() == 0 then
        -- In a service mode, but no characters qualify for the service
        self.characterList:SetNoItemText(GetString(SI_SERVICE_NO_ELIGIBLE_CHARACTERS))
        ZO_CharacterSelect_Gamepad_RefreshKeybindStrip(self.charListKeybindStripDescriptorUseServiceToken)
    end
    g_currentlySelectedCharacterData = nil
    local bestSelection = ZO_CharacterSelect_GetBestSelectionData()
    if bestSelection then
        local ALLOW_EVEN_IF_DISABLED = true
        local FORCE_ANIMATION = false
        ZO_CharacterSelect_Gamepad.characterList:SetSelectedIndex(bestSelection.slot, ALLOW_EVEN_IF_DISABLED, FORCE_ANIMATION)
    end
    self.characterList:Commit()
end
local function DoCharacterSelection(index)
    -- Get character select first random selection loaded in so not waiting for it
    -- when move to Create
        SelectClothing(DRESSING_OPTION_STARTING_GEAR)
    end
    SetCharacterManagerMode(CHARACTER_MODE_SELECTION)
    SelectCharacterToView(index)
end
local function SelectCharacter(characterData)
    if characterData then
        if IsPregameCharacterConstructionReady() and (g_currentlySelectedCharacterData == nil or g_currentlySelectedCharacterData.index ~= characterData.index) then
            g_currentlySelectedCharacterData = characterData
            DoCharacterSelection(g_currentlySelectedCharacterData.index)
        end
    end
end
local function RecreateList(self)
    CreateList(self)
end
local function ZO_CharacterSelect_Gamepad_GetFormattedRace(characterData)
    local raceName = characterData.race and GetRaceName(characterData.gender, characterData.race) or GetString(SI_UNKNOWN_RACE)
    return zo_strformat(SI_CHARACTER_SELECT_RACE, raceName)
end
local function ZO_CharacterSelect_Gamepad_GetFormattedClass(characterData)
    local className = characterData.class and GetClassName(characterData.gender, characterData.class) or GetString(SI_UNKNOWN_CLASS)
    return zo_strformat(SI_CHARACTER_SELECT_CLASS, className)
end
local function ZO_CharacterSelect_Gamepad_GetFormattedAlliance(characterData)
    local allianceName = GetAllianceName(characterData.alliance) or GetString(SI_UNKNOWN_CLASS)
    return zo_strformat(SI_CHARACTER_SELECT_ALLIANCE, allianceName)
end
    return zo_iconFormat(GetAvARankIcon(rank), 32, 32)
end
local function ZO_CharacterSelect_Gamepad_GetFormattedLocation(characterData)
    local locationName = characterData.location ~= 0 and GetLocationName(characterData.location) or GetString(SI_UNKNOWN_LOCATION)
    return zo_strformat(SI_CHARACTER_SELECT_LOCATION, locationName)
end
do
    SetupCharacterList = function (self, eventCode, numCharacters, maxCharacters, mostRecentlyPlayedCharacterId, numCharacterDeletesRemaining)
        ZO_CharacterSelect_OnCharacterListReceivedCommon(eventCode, numCharacters, maxCharacters, mostRecentlyPlayedCharacterId, numCharacterDeletesRemaining, maxCharacterDeletes)
        g_canCreateCharacter = numCharacters < maxCharacters
        ZO_CharacterSelect_Gamepad_SetMaxCharacters(maxCharacters)
        RecreateList(self)
    end
    SelectedCharacterChanged = function(self, list, selectedData, oldSelectedData)
        if selectedData and selectedData.type == ENTRY_TYPE_EXTRA_INFO then
            g_canPlayCharacter = false
            self.characterNeedsRename:SetHidden(true)
            self.characterDetails:SetHidden(true)
            return
        end
        
        local characterName = self.characterDetails:GetNamedChild("Name")
        local characterRace = self.characterDetails:GetNamedChild("RaceContainer"):GetNamedChild("Race")
        local characterLevel = self.characterDetails:GetNamedChild("LevelContainer"):GetNamedChild("Level")
        local characterClass = self.characterDetails:GetNamedChild("ClassContainer"):GetNamedChild("Class")
        local characterAlliance = self.characterDetails:GetNamedChild("AllianceContainer"):GetNamedChild("Alliance")
        local characterLocation = self.characterDetails:GetNamedChild("LocationContainer"):GetNamedChild("Location")
        local locationName = ""
        if selectedData then
            characterName:SetText(ZO_CharacterSelect_GetFormattedCharacterName(selectedData))
            characterRace:SetText(ZO_CharacterSelect_Gamepad_GetFormattedRace(selectedData))
            characterLevel:SetText(ZO_CharacterSelect_GetFormattedLevel(selectedData))
            characterClass:SetText(ZO_CharacterSelect_Gamepad_GetFormattedClass(selectedData))
            characterAlliance:SetText(ZO_CharacterSelect_Gamepad_GetFormattedAlliance(selectedData))
            -- Location Name isn't always valid
            locationName = ZO_CharacterSelect_Gamepad_GetFormattedLocation(selectedData)
            characterLocation:SetText(locationName)
            if selectedData.name then
                ZO_CharacterSelect_SetPlayerSelectedCharacterId(selectedData.id)
                SelectCharacter(selectedData)
            end
            -- Change the keybind strip if we have create new selected
            local self = ZO_CharacterSelect_Gamepad
            g_canPlayCharacter = false
            if self.serviceMode ~= SERVICE_MODE_NONE then
                ZO_CharacterSelect_Gamepad_RefreshKeybindStrip(self.charListKeybindStripDescriptorUseServiceToken)
            elseif selectedData.needsRename then
                ZO_CharacterSelect_Gamepad_RefreshKeybindStrip(self.charListKeybindStripDescriptorRename)
            elseif selectedData.type == ENTRY_TYPE_CREATE_NEW then
                ZO_CharacterSelect_Gamepad_RefreshKeybindStrip(self.charListKeybindStripDescriptorCreateNew)
            else
                g_canPlayCharacter = true
                ZO_CharacterSelect_Gamepad_RefreshKeybindStrip(self.charListKeybindStripDescriptorDefault)
            end
        else
        end
        -- Only show the character details if the slot is valid
        ZO_CharacterSelect_GamepadCharacterDetails:SetHidden(not (selectedData and selectedData.name and locationName ~= ""))
        -- Handle needs rename text
        local needsRename = selectedData and selectedData.needsRename
        self.characterDetails:SetHidden(needsRename)
        self.characterNeedsRename:SetHidden(not needsRename)
        g_lastSelectedData = selectedData
    end
end
    local self = ZO_CharacterSelect_Gamepad
    SelectedCharacterChanged(self, nil, g_lastSelectedData, nil)
end
local function GetPlayerCountString()
    local characterDataList = ZO_CharacterSelect_GetCharacterDataList()
    return zo_strformat(SI_CHARACTER_SELECT_GAMEPAD_CHARACTERS_COUNTER, #characterDataList, ZO_CharacterSelect_Gamepad_GetMaxCharacters())
end
    local self = ZO_CharacterSelect_Gamepad
    ZO_CharacterSelectProfile_Gamepad:GetNamedChild("CharacterCount"):SetText(GetPlayerCountString())
    ZO_CharacterSelectProfile_Gamepad:GetNamedChild("Profile"):SetText(GetOnlineIdForActiveProfile())
    local accountChampionPoints = ZO_CharacterSelect_GetAccountChampionPoints()
    local championPointsContainer = ZO_CharacterSelectProfile_Gamepad:GetNamedChild("ChampionPointsContainer")
    if accountChampionPoints > 0 then
        championPointsContainer:SetHidden(false)
        championPointsContainer:GetNamedChild("ChampionPointsCount"):SetText(accountChampionPoints)
    else
        championPointsContainer:SetHidden(true)
    end
end
local function OnCharacterConstructionReady()
    if(GetNumCharacters() > 0) then
        g_currentlySelectedCharacterData = g_currentlySelectedCharacterData or ZO_CharacterSelect_GetBestSelectionData()
        if g_currentlySelectedCharacterData then
            DoCharacterSelection(g_currentlySelectedCharacterData.index)
            local ALLOW_EVEN_IF_DISABLED = true
            local FORCE_ANIMATION = false
            ZO_CharacterSelect_Gamepad.characterList:SetSelectedIndexWithoutAnimation(g_currentlySelectedCharacterData.slot, ALLOW_EVEN_IF_DISABLED, FORCE_ANIMATION)
        end
    end
end
local function OnPregameFullyLoaded()
    local self = ZO_CharacterSelect_Gamepad
    RecreateList(self)
    
    if self.active then
        self.characterList:Activate()
        self.characterList:RefreshVisible()
        if IsPregameCharacterConstructionReady() then
            OnCharacterConstructionReady()
        end
    end
end
    local self = ZO_CharacterSelect_Gamepad
    if self.currentKeystrip then
        KEYBIND_STRIP:RemoveKeybindButtonGroup(self.currentKeystrip)
        self.currentKeystrip = nil
    end
end
    local self = ZO_CharacterSelect_Gamepad
    if (keybindStrip) then
        self.charListKeybindStripDescriptor = keybindStrip
    end
    if self.active and self.currentKeystrip ~= self.charListKeybindStripDescriptor then
        self.currentKeystrip = self.charListKeybindStripDescriptor
        KEYBIND_STRIP:RemoveDefaultExit()
        KEYBIND_STRIP:AddKeybindButtonGroup(self.charListKeybindStripDescriptor)
    end
end
local function ZO_CharacterSelect_Gamepad_StateChanged(oldState, newState)
    local self = ZO_CharacterSelect_Gamepad
    if newState == SCENE_SHOWING then
        self.active = true
        self.deleting = false
        self.serviceMode = SERVICE_MODE_NONE
        ZO_CharacterSelect_GamepadCharacterViewport.Activate()
        SCENE_MANAGER:AddFragment(CHARACTER_SELECT_CHARACTERS_GAMEPAD_FRAGMENT)
        if(PregameIsFullyLoaded()) then
            self.characterList:RefreshVisible()
            self.characterList:Activate()
            self.extraInfoFocus:Deactivate()
        end
        if IsPregameCharacterConstructionReady() then
            OnCharacterConstructionReady()  -- So that if we come to this screen from Character Create, it will load a different scene.
        end
        DIRECTIONAL_INPUT:Activate(self, self)
    elseif newState == SCENE_HIDDEN then
        DIRECTIONAL_INPUT:Deactivate(self, self)
        self.active = false
        ZO_CharacterSelect_GamepadCharacterViewport.StopAllInput()
        ZO_CharacterSelect_GamepadCharacterViewport.Deactivate()
        self.characterList:Deactivate()
    end
end
local function CharacterDeleted(eventCode, charId)
    -- We need to release the dialog to make sure the keybinds are cleared.
    -- Releasing this dialog will request the character list
    ZO_CharacterSelect_Gamepad.deleting = false
    ZO_CharacterSelect_Gamepad.refresh = true
    ZO_Dialogs_ReleaseDialog("CHARACTER_SELECT_DELETING")
end
local g_requestedRename = ""
    local DONT_RESET_TO_DEFAULT = false
    local self = ZO_CharacterSelect_Gamepad
    -- there are multiple ways to rename a character, some of which do not change the servicemode, so we will
    -- check if this is from a service use or not, and update the appropriate items
    if self.serviceMode == SERVICE_MODE_NONE then
        ZO_CharacterSelect_Gamepad_ReturnToCharacterList(ACTIVATE_VIEWPORT)
    else
        ZO_CharacterSelect_Gamepad_ChangeServiceMode(SERVICE_MODE_NONE, DONT_RESET_TO_DEFAULT)
    end
end
end
local function OnCharacterRenamed(eventCode, charId, result)
end
local function ContextFilter(callback)
    -- This will wrap the callback so that it gets called in the appropriate context
    return function(...)
        if IsConsoleUI() then
            callback(...)
        end
    end
end
local function OnPregameCharacterListReceived(characterCount, previousCharacterCount)
    if (characterCount > 0) then
        local currentState = PregameStateManager_GetCurrentState()
        -- The character list is received a second time once a character is renamed, which prevents the rename success dialog from
        -- displaying if we're already at CharacterSelect
        if currentState ~= "CharacterSelect" and currentState ~= "WaitForPregameFullyLoaded" then
            PregameStateManager_SetState("WaitForPregameFullyLoaded")
        end
    end
end
    local self = ZO_CharacterSelect_Gamepad
    local result = self.movementController:CheckMovement()
    if result == MOVEMENT_CONTROLLER_MOVE_NEXT then
        if self.extraInfoFocus.active then
            SelectedCharacterChanged(self, self.characterList, g_lastSelectedData)
            self.extraInfoFocus:Deactivate()
            self.characterList:Activate()
            PlaySound(SOUNDS.GAMEPAD_MENU_DOWN)
        else
            self.characterList:MoveNext()
        end
    elseif result == MOVEMENT_CONTROLLER_MOVE_PREVIOUS then 
        if self.characterList:GetSelectedIndex() ~= 1 then
            self.characterList:MovePrevious()
        elseif not self.extraInfoContainer:IsHidden() then
            SelectedCharacterChanged(self, self.characterList, { type = ENTRY_TYPE_EXTRA_INFO })
            self.extraInfoFocus:Activate()
            self.characterList:Deactivate()
            PlaySound(SOUNDS.GAMEPAD_MENU_UP)
        end
    end
end
    self.deleteKeys = {false, false, false, false}
    self.movementController = ZO_MovementController:New(MOVEMENT_CONTROLLER_DIRECTION_VERTICAL)
    self.characterList = ZO_GamepadVerticalParametricScrollList:New(self:GetNamedChild("Mask"):GetNamedChild("Characters"):GetNamedChild("List"))
    self.characterList:AddDataTemplateWithHeader("ZO_GamepadMenuEntryTemplate", CharacterListEntry_OnSetup, ZO_GamepadMenuEntryTemplateParametricListFunction, nil, "ZO_GamepadMenuEntryHeaderTemplate")
    self.characterList:AddDataTemplate("ZO_GamepadMenuEntryTemplateLowercase34", CharacterListEntry_OnSetup, ZO_GamepadMenuEntryTemplateParametricListFunction)
    self.characterList:AddDataTemplateWithHeader("ZO_GamepadMenuEntryTemplateLowercase34", CharacterListEntry_OnSetup, ZO_GamepadMenuEntryTemplateParametricListFunction, nil, "ZO_GamepadCharacterSelectMenuEntryHeaderTemplate", GamepadCharacterSelectMenuEntryHeader_Setup)
    self.characterList:SetAlignToScreenCenter(true)
    self.characterList:SetDirectionalInputEnabled(false)
    self.characterDetails = self:GetNamedChild("CharacterDetails"):GetNamedChild("Container")
    self.extraInfoDetails = self:GetNamedChild("CharacterDetails"):GetNamedChild("ExtraInfoDetails")
    self.characterNeedsRename = self:GetNamedChild("CharacterDetails"):GetNamedChild("NeedsRename")
    self.header = self:GetNamedChild("Mask"):GetNamedChild("Characters"):GetNamedChild("HeaderContainer"):GetNamedChild("Header")
    ZO_GamepadGenericHeader_Initialize(self.header, ZO_GAMEPAD_HEADER_TABBAR_DONT_CREATE)
    self.headerData = {
        titleText = GetString(SI_CHARACTER_SELECT_GAMEPAD_SELECT_CHARACTER),
    }
    -- Extra Info controls
    self.extraInfoContainer = self:GetNamedChild("Mask"):GetNamedChild("Characters"):GetNamedChild("HeaderContainer"):GetNamedChild("ExtraInfo")
    self.extraInfoCenterer = self.extraInfoContainer:GetNamedChild("Centerer")
    self.extraInfoFocus = ZO_GamepadFocus:New(self.extraInfoCenterer, nil, MOVEMENT_CONTROLLER_DIRECTION_HORIZONTAL)
    self.extraInfoFocus.onPlaySoundFunction = function() PlaySound(SOUNDS.HOR_LIST_ITEM_SELECTED) end
    self.extraInfoFocus:SetFocusChangedCallback(function(focusItem)
            if focusItem then
                ZO_CharacterSelect_Gamepad_UpdateExtraInfoKeybinds(focusItem.control)
            end
        end)
    self.extraInfoControlPool = ZO_ControlPool:New("ZO_CharacterSelect_ExtraInfo_Entry", self.extraInfoCenterer)
    -- Service header controls
    self.serviceMode = SERVICE_MODE_NONE
    self.serviceHeader = self:GetNamedChild("Mask"):GetNamedChild("Characters"):GetNamedChild("HeaderContainer"):GetNamedChild("CurrentServiceInfo")
    self.serviceTokensLabel = self.serviceHeader:GetNamedChild("Tokens")
    self.serviceInstructions = self.serviceHeader:GetNamedChild("Instructions")
    InitKeybindingDescriptor(self) -- Depends on self.characterList since we bind to it.
    local function OnCharacterSelectionChanged(list, selectedData, oldSelectedData)
        SelectedCharacterChanged(self, list, selectedData, oldSelectedData)
    end
    local function OnCharacterListReceived(eventCode, numCharacters, maxCharacters, mostRecentlyPlayedCharacterId, numCharacterDeletesRemaining, maxCharacterDeletes)
        if ZO_CharacterSelect_Gamepad.refresh then
            if numCharacters == 0 then
                return -- We are going to the character create screen
            end
            PlaySound(SOUNDS.GAMEPAD_MENU_BACK)
            ZO_CharacterSelect_Gamepad_ReturnToCharacterList(ACTIVATE_VIEWPORT)
            ZO_CharacterSelect_Gamepad.refresh = false
            ZO_CharacterSelect_Gamepad.characterList:Clear()
        end
        SetupCharacterList(self, eventCode, numCharacters, maxCharacters, mostRecentlyPlayedCharacterId, numCharacterDeletesRemaining, maxCharacterDeletes)
    end
    self:RegisterForEvent(EVENT_CHARACTER_LIST_RECEIVED, ContextFilter(OnCharacterListReceived))
    
    local ALWAYS_ANIMATE = true
    CHARACTER_SELECT_GAMEPAD_FRAGMENT = ZO_FadeSceneFragment:New(self, ALWAYS_ANIMATE)
    CHARACTER_SELECT_PROFILE_GAMEPAD_FRAGMENT = ZO_FadeSceneFragment:New(ZO_CharacterSelectProfile_Gamepad, ALWAYS_ANIMATE)
    CHARACTER_SELECT_RENAME_ERROR_GAMEPAD_FRAGMENT = ZO_FadeSceneFragment:New(ZO_CharacterSelect_GamepadRenameError, ALWAYS_ANIMATE)
    GAMEPAD_CHARACTER_SELECT_SCENE = ZO_Scene:New("gamepadCharacterSelect", SCENE_MANAGER)
    GAMEPAD_CHARACTER_SELECT_SCENE:AddFragment(CHARACTER_SELECT_GAMEPAD_FRAGMENT)
    GAMEPAD_CHARACTER_SELECT_SCENE:AddFragment(KEYBIND_STRIP_GAMEPAD_FRAGMENT)
    GAMEPAD_CHARACTER_SELECT_SCENE:AddFragment(CHARACTER_SELECT_PROFILE_GAMEPAD_FRAGMENT)
    self.control = GAMEPAD_CHARACTER_SELECT_SCENE
    CHARACTER_SELECT_CHARACTERS_GAMEPAD_FRAGMENT = ZO_CreateQuadrantConveyorFragment(ZO_CharacterSelect_GamepadMaskCharacters)
    GAMEPAD_CHARACTER_SELECT_SCENE:RegisterCallback("StateChange", ZO_CharacterSelect_Gamepad_StateChanged)
    CALLBACK_MANAGER:RegisterCallback("OnCharacterConstructionReady", ContextFilter(OnCharacterConstructionReady))
    CALLBACK_MANAGER:RegisterCallback("PregameFullyLoaded", ContextFilter(OnPregameFullyLoaded))
    CALLBACK_MANAGER:RegisterCallback("PregameCharacterListReceived", ContextFilter(OnPregameCharacterListReceived))
    self:RegisterForEvent(EVENT_CHARACTER_DELETED, ContextFilter(CharacterDeleted))
    self:RegisterForEvent(EVENT_CHARACTER_RENAME_RESULT, ContextFilter(OnCharacterRenamed))
    self.control:AddFragment(KEYBIND_STRIP_GAMEPAD_BACKDROP_FRAGMENT)
    ZO_CharacterNaming_Gamepad_CreateDialog(ZO_CharacterSelect_Gamepad,
        {
            errorControl = ZO_CharacterSelect_GamepadRenameError,
            errorFragment = CHARACTER_SELECT_RENAME_ERROR_GAMEPAD_FRAGMENT,
            dialogName = "CHARACTER_SELECT_RENAME_CHARACTER_GAMEPAD",
            dialogTitle = function(dialog)
                local titleText = SI_CHARACTER_SELECT_RENAME_CHARACTER_TITLE
                if dialog and dialog.data and dialog.data.renameFromToken then
                    titleText = SI_CHARACTER_SELECT_RENAME_CHARACTER_FROM_TOKEN_TITLE
                end
                return GetString(titleText)
            end,
            dialogMainText = function(dialog)
                local mainText = ""
                if dialog.data and dialog.data.originalCharacterName then
                    mainText = zo_strformat(SI_RENAME_CHARACTER_NAME_LABEL, dialog.data.originalCharacterName)
                end
                return mainText
            end,
            onBack = function() ZO_CharacterSelect_Gamepad_ReturnToCharacterList(ACTIVATE_VIEWPORT) end,
            onFinish = function(dialog)
                g_requestedRename = dialog.selectedName
                if g_requestedRename and #g_requestedRename > 0 then
                    AttemptCharacterRename(g_currentlySelectedCharacterData.id, g_requestedRename)
                    ZO_Dialogs_ShowGamepadDialog("CHARACTER_SELECT_CHARACTER_RENAMING")
                end
            end,
            createHeaderDataFunction = function(dialog, data)
                local headerData = {}
                if data then
                    if data.renameFromToken then
                        headerData.data1 = {
                                                value = GetNumCharacterRenameTokens(),
                                                header = GetString(SI_SERVICE_TOKEN_COUNT_TOKENS_HEADER)
                                           }
                    end
                end
                return headerData
            end,
        })
end
    if g_currentlySelectedCharacterData then
        local dialogData = {
                                originalCharacterName = g_currentlySelectedCharacterData.name,
                                -- Dialog displays additional info if a player is spending a token to rename
                                renameFromToken = not g_currentlySelectedCharacterData.needsRename,
                           }
        ZO_Dialogs_ShowGamepadDialog("CHARACTER_SELECT_RENAME_CHARACTER_GAMEPAD", dialogData)
        ZO_CharacterSelect_GamepadCharacterDetails:SetHidden(true)
    end
end
    local state = PregameStateManager_GetCurrentState()
    if(state == "CharacterSelect" or state == "CharacterSelect_FromCinematic") then
        if(g_currentlySelectedCharacterData) then
            PregameStateManager_PlayCharacter(g_currentlySelectedCharacterData.id, option)
            return true
        end
    end
    return false
end
    return g_canPlayCharacter
end
    local self = ZO_CharacterSelect_Gamepad
    ZO_CharacterSelect_GamepadCharacterViewport.Deactivate()
    SCENE_MANAGER:RemoveFragment(CHARACTER_SELECT_CHARACTERS_GAMEPAD_FRAGMENT)
    ZO_CharacterSelect_Gamepad_RefreshKeybindStrip(self.charListKeybindStripDescriptorLogin)
    -- Show the fact that the login has been requested
    ZO_Dialogs_ShowGamepadDialog("CHARACTER_SELECT_LOGIN")
end
function ZO_CharacterSelect_Gamepad_SetLabelMaxWidth(labelControl, siblingName)
    local siblingControl = labelControl:GetParent():GetNamedChild(siblingName)
    local isValid, anchor, _, _, offsetX = labelControl:GetAnchor(0)
    local maxConstraintX = ZO_GAMEPAD_CONTENT_WIDTH - offsetX
    if siblingControl then
        maxConstraintX = maxConstraintX - siblingControl:GetWidth()
    end
    labelControl:SetDimensionConstraints(maxConstraintX, 0)
end
    local self = ZO_CharacterSelect_Gamepad
    local selectedFocus = self.extraInfoFocus:GetFocusItem()
    local serviceMode = SERVICE_MODE_NONE
    if selectedFocus then
        if selectedFocus.control and selectedFocus.control.data then
            serviceMode = selectedFocus.control.data.serviceMode
        end
    end
    return serviceMode
end
function ZO_CharacterSelect_Gamepad_ChangeServiceMode(serviceMode, resetListToDefault)
    local self = ZO_CharacterSelect_Gamepad
    if self.serviceMode ~= serviceMode then
        local previousService = self.serviceMode
        self.serviceMode = serviceMode
        -- Update Header Text and rebuild the list to filter out invalid options
        local characterListHeader
        if serviceMode == SERVICE_MODE_NAME_CHANGE then
            characterListHeader = GetString(SI_CHARACTER_SELECT_RENAME_CHARACTER_FROM_TOKEN_TITLE)
        else
            characterListHeader = GetString(SI_CHARACTER_SELECT_GAMEPAD_SELECT_CHARACTER)
        end
        self.headerData.titleText = characterListHeader
        RecreateList(self)
        -- Update list positions
        if resetListToDefault then
            self.characterList:SetSelectedIndex(1)
            if serviceMode == SERVICE_MODE_NONE then
                SelectedCharacterChanged(self, self.characterList, { type = ENTRY_TYPE_EXTRA_INFO })
                self.characterList:Deactivate()
                self.extraInfoFocus:Activate()
                -- Select the previously selected service in the extra info control, if it exists
                for i = 1, self.extraInfoFocus:GetItemCount() do
                    local item = self.extraInfoFocus:GetItem(i)
                    if item and item.control then
                        if item.control.data.serviceMode == previousService then
                            self.extraInfoFocus:SetFocusByIndex(i)
                            break
                        end
                    end
                end
            else
                self.characterList:Activate()
                self.extraInfoFocus:Deactivate()
            end
        end
    end
end