Back to Home

ESO Lua File v100032

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
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
local g_lastSelectedEntryData
local g_canPlayCharacter = 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 ENTRY_TYPE_CHAPTER = 4
local ENTRY_TYPE_EVENT = 5
local ENTRY_TYPE_ESO_PLUS = 6
local CREATE_NEW_ICON = "EsoUI/Art/Buttons/Gamepad/gp_plus_large.dds"
--[[ Character Select Delete Screen ]]--
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 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_Keybindings_GenerateIconKeyMarkup(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")
        local characterData = CHARACTER_SELECT_MANAGER:GetSelectedCharacterData()
        CHARACTER_SELECT_MANAGER:AttemptCharacterDelete(characterData.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,
            },
            {
                --Ethereal binds show no text, the name field is used to help identify the keybind when debugging. This text does not have to be localized.
                name = "Character Select Delete Left Shoulder",
                keybind = "DIALOG_LEFT_SHOULDER",
                handlesKeyUp = true,
                ethereal = true,
                callback = function(dialog, onUp)
                    ZO_CharacterSelectDelete_Gamepad_OnKeyChanged(KEY_GAMEPAD_LEFT_SHOULDER, not onUp)
                end,
            },
            {
                --Ethereal binds show no text, the name field is used to help identify the keybind when debugging. This text does not have to be localized.
                name = "Character Select Delete Right Shoulder",
                keybind = "DIALOG_RIGHT_SHOULDER",
                handlesKeyUp = true,
                ethereal = true,
                callback = function(dialog, onUp)
                    ZO_CharacterSelectDelete_Gamepad_OnKeyChanged(KEY_GAMEPAD_RIGHT_SHOULDER, not onUp)
                end,
            },
            {
                --Ethereal binds show no text, the name field is used to help identify the keybind when debugging. This text does not have to be localized.
                name = "Character Select Delete Left Trigger",
                keybind = "DIALOG_LEFT_TRIGGER",
                handlesKeyUp = true,
                ethereal = true,
                callback = function(dialog, onUp)
                    ZO_CharacterSelectDelete_Gamepad_OnKeyChanged(KEY_GAMEPAD_LEFT_TRIGGER, not onUp)
                end,
            },
            {
                --Ethereal binds show no text, the name field is used to help identify the keybind when debugging. This text does not have to be localized.
                name = "Character Select Delete Right Trigger",
                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 GetClassIconGamepad(classIdRequested)
    for i = 1, GetNumClasses() do
        local classId, _, _, _, _, _, _, _, _, gamepadPressedIcon = GetClassInfo(i)
        if classId == classIdRequested then
            return gamepadPressedIcon
        end
    end
    return nil
end
local function AddCharacterListEntry(template, entryData, list, prePadding, postPadding, preSelectedOffsetAdditionalPadding, postSelectedOffsetAdditionalPadding, selectedCenterOffset)
    entryData:SetFontScaleOnSelection(true)
    entryData:SetIconTintOnSelection(true)
    list:AddEntry(template, entryData, prePadding, postPadding, preSelectedOffsetAdditionalPadding, postSelectedOffsetAdditionalPadding, selectedCenterOffset)
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)
    local icon = ((data.name ~= nil) and data.class) and GetClassIconGamepad(data.class) or data.icon
    data:AddIcon(icon)
    ZO_SharedGamepadEntry_OnSetup(control, data, selected, selectedDuringRebuild, enabled, activated)
end
local function GamepadCharacterSelectMenuEntryHeader_Setup(headerControl, data, ...)
    local subHeader = headerControl:GetNamedChild("SubHeader")
    if subHeader then
        subHeader:SetText(data.subHeader or "")
    end
end
-- Extra Info Functions
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
    local numTokens = GetNumServiceTokens(data.serviceMode)
    control.tokenCount:SetText(numTokens)
    control.icon:SetDesaturation(numTokens > 0 and 0 or 1)
    if numTokens > 0 and data.MeetsRequirementsFunction and data.MeetsRequirementsFunction() == false then
        control.icon:SetColor(ZO_ERROR_COLOR:UnpackRGB())
    else
        control.icon:SetColor(ZO_WHITE:UnpackRGB())
    end
    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 = {}
    if self.serviceMode == SERVICE_TOKEN_NONE then
        local function ServiceTokenTooltipFunction(tokenType)
            ZO_CharacterSelect_GamepadCharacterDetails:SetHidden(true)
            GAMEPAD_TOOLTIPS:LayoutServiceTokenTooltip(GAMEPAD_LEFT_TOOLTIP, tokenType)
        end
        local function ServiceTokenHideTooltipFunction()
            ZO_CharacterSelect_GamepadCharacterDetails:SetHidden(false)
            GAMEPAD_TOOLTIPS:ClearTooltip(GAMEPAD_LEFT_TOOLTIP)
        end
        local serviceTokenData =
        {
            {
                keybindStripDesc = self.charListKeybindStripDescriptorServices,
                icon = "EsoUI/Art/Icons/Token_NameChange.dds",
                serviceMode = SERVICE_TOKEN_NAME_CHANGE,
                ShowTooltipFunction = function()
                    ServiceTokenTooltipFunction(SERVICE_TOKEN_NAME_CHANGE)
                end,
                HideTooltipFunction = ServiceTokenHideTooltipFunction,
            },
            {
                keybindStripDesc = self.charListKeybindStripDescriptorServices,
                icon = "EsoUI/Art/Icons/Token_RaceChange.dds",
                serviceMode = SERVICE_TOKEN_RACE_CHANGE,
                ShowTooltipFunction = function()
                    ServiceTokenTooltipFunction(SERVICE_TOKEN_RACE_CHANGE)
                end,
                HideTooltipFunction = ServiceTokenHideTooltipFunction,
            },
            {
                keybindStripDesc = self.charListKeybindStripDescriptorServices,
                icon = "EsoUI/Art/Icons/Token_AppearanceChange.dds",
                serviceMode = SERVICE_TOKEN_APPEARANCE_CHANGE,
                ShowTooltipFunction = function()
                    ServiceTokenTooltipFunction(SERVICE_TOKEN_APPEARANCE_CHANGE)
                end,
                HideTooltipFunction = ServiceTokenHideTooltipFunction,
            },
            {
                keybindStripDesc = self.charListKeybindStripDescriptorServices,
                icon = "EsoUI/Art/Icons/Token_AllianceChange.dds",
                serviceMode = SERVICE_TOKEN_ALLIANCE_CHANGE,
                ShowTooltipFunction = function()
                    ServiceTokenTooltipFunction(SERVICE_TOKEN_ALLIANCE_CHANGE)
                end,
                HideTooltipFunction = ServiceTokenHideTooltipFunction,
                MeetsRequirementsFunction = function()
                    return CanPlayAnyRaceAsAnyAlliance()
                end
            },
        }
        -- Add more extra info controls above this line
        for i, tokenData in ipairs(serviceTokenData) do
            local control = CreateExtraInfoEntry(self, tokenData)
            AddExtraInfoEntryToFocus(self, control)
        end
        CenterExtraInfoControls(self)
    end
end
    if control and control.data then
    end
end
    local headerVisible = self.serviceMode ~= SERVICE_TOKEN_NONE
    if headerVisible then
        local tokenCount = GetNumServiceTokens(self.serviceMode)
        self.serviceTokensLabel:SetText(tokenCount)
        local instructions = ""
        if self.serviceMode ~= SERVICE_TOKEN_NONE then
            instructions = zo_strformat(SI_SERVICE_TOKEN_INSTRUCTIONS, GetString("SI_SERVICETOKENTYPE", self.serviceMode))
        end
        self.serviceInstructions:SetText(instructions)
    end
    self.serviceHeader:SetHidden(not headerVisible)
end
-- End Extra Info functions
local g_hasNeedsRenameCharacter = false
local function CreateList(self, scrollToBest)
    self.characterList:Clear()
    local slot = 1
    if self.serviceMode == SERVICE_TOKEN_NONE then
        if not IsESOPlusSubscriber() then
            local data =
            {
                index = slot,
                type = ENTRY_TYPE_ESO_PLUS,
                header = GetString(SI_CHARACTER_SELECT_GAMEPAD_UPGRADES_HEADER),
                icon = "EsoUI/Art/CharacterSelect/gamepad/gp_characterSelect_ESOPlus.dds",
                text = GetString(SI_ESO_PLUS_JOIN_TEXT),
            }
            local newEntry = ZO_GamepadEntryData:New(data.text, data.icon)
            newEntry:SetDataSource(data)
            AddCharacterListEntry("ZO_GamepadMenuEntryTemplateWithHeader", newEntry, self.characterList)
            slot = slot + 1
        end
        local chapterUpgradeId = GetCurrentChapterUpgradeId()
        if chapterUpgradeId ~= 0 and not IsChapterOwned(chapterUpgradeId) then
            local chapterCollectibleId = GetChapterCollectibleId(chapterUpgradeId)
            local data =
            {
                index = slot,
                type = ENTRY_TYPE_CHAPTER,
                icon = GetCurrentChapterSmallLogoFileIndex(),
                text = zo_strformat(SI_CHARACTER_SELECT_CHAPTER_LOCKED_FORMAT, GetCollectibleName(chapterCollectibleId))
            }
            local newEntry = ZO_GamepadEntryData:New(data.text, data.icon)
            newEntry:SetDataSource(data)
            local entryTemplate = "ZO_GamepadMenuEntryTemplate"
            if slot == 1 then
                newEntry:SetHeader(GetString(SI_CHARACTER_SELECT_GAMEPAD_UPGRADES_HEADER))
                entryTemplate = "ZO_GamepadMenuEntryTemplateWithHeader"
            end
            AddCharacterListEntry(entryTemplate, newEntry, self.characterList)
            slot = slot + 1
        end
        -- Add entries for events into the parametric list
        local numEvents = CHARACTER_SELECT_MANAGER:GetNumEventAnnouncements()
        for i = 1, numEvents do
            local data = CHARACTER_SELECT_MANAGER:GetEventAnnouncementDataByIndex(i)
            local entryData =
            {
                index = data.index,
                name = data.name,
                description = data.description,
                image = data.image,
                startTime = data.startTime,
                remainingTime = data.remainingTime,
                type = ENTRY_TYPE_EVENT,
                text = data.name,
            }
            local newEntry = ZO_GamepadEntryData:New(entryData.text)
            newEntry:SetDataSource(entryData)
            local entryTemplate = "ZO_GamepadMenuEntryTemplate"
            if i == 1 then
                newEntry:SetHeader(GetString(SI_CHARACTER_SELECT_GAMEPAD_EVENTS_HEADER))
                entryTemplate = "ZO_GamepadMenuEntryTemplateWithHeader"
            end
            AddCharacterListEntry(entryTemplate, newEntry, self.characterList)
            slot = slot + 1
        end
    end
    local bestSelectionListIndex = nil
    local numCharacterSlotsAdded = 0
    local characterDataList = CHARACTER_SELECT_MANAGER:GetCharacterDataList()
    if #characterDataList > 0 then
        local bestSelectionData = CHARACTER_SELECT_MANAGER:GetBestSelectionData()
        local isFirstEntry = true
        -- Add Rename characters
        g_hasNeedsRenameCharacter = false
        if self.serviceMode ~= SERVICE_TOKEN_NAME_CHANGE then
            for i, characterData in ipairs(characterDataList) do
                if characterData.needsRename then
                    g_hasNeedsRenameCharacter = true
                    slot = slot + 1
                    numCharacterSlotsAdded = numCharacterSlotsAdded + 1
                    local template = "ZO_GamepadMenuEntryTemplateLowercase34"
                    local header = nil
                    if isFirstEntry then
                        header = GetString(SI_CHARACTER_SELECT_GAMEPAD_RENAME_HEADER)
                        template = "ZO_GamepadMenuEntryTemplateLowercase34WithHeader"
                        isFirstEntry = false
                    end
                    if characterData == bestSelectionData then
                        bestSelectionListIndex = slot
                    end
                    local text = ZO_CharacterSelect_Manager_GetFormattedCharacterName(characterData)
                    local renameCharacterEntry = ZO_GamepadEntryData:New(text, characterData.icon)
                    renameCharacterEntry.slot = slot
                    renameCharacterEntry.type = ENTRY_TYPE_CHARACTER
                    renameCharacterEntry:SetDataSource(characterData)
                    renameCharacterEntry:SetHeader(header)
                    AddCharacterListEntry(template, renameCharacterEntry, self.characterList)
                end
            end
        end
        isFirstEntry = true
        -- Add Selectable characters
        for i, characterData in ipairs(characterDataList) do
            if not characterData.needsRename then
                local template = "ZO_GamepadMenuEntryTemplateLowercase34"
                local header = nil
                local subHeader = nil
                local prePadding = nil
                local postPadding = nil
                local preSelectedOffsetAdditionalPadding = nil
                local postSelectedOffsetAdditionalPadding = nil
                if isFirstEntry then
                    header = zo_strformat(SI_CHARACTER_SELECT_GAMEPAD_CHARACTERS_HEADER, #characterDataList, CHARACTER_SELECT_MANAGER:GetMaxCharacters())
                    template = "ZO_GamepadMenuEntryTemplateLowercase34WithHeader"
                    isFirstEntry = false
                    if self.serviceMode == SERVICE_TOKEN_NONE and CHARACTER_SELECT_MANAGER:CanShowAdditionalSlotsInfo() then
                        prePadding = 80
                        postPadding = 0
                        preSelectedOffsetAdditionalPadding = 120
                        postSelectedOffsetAdditionalPadding = 0
                        subHeader = zo_strformat(SI_ADDITIONAL_CHARACTER_SLOTS_DESCRIPTION, CHARACTER_SELECT_MANAGER:GetAdditionalSlotsRemaining())
                    end
                end
                if characterData == bestSelectionData then
                    bestSelectionListIndex = slot
                end
                local text = ZO_CharacterSelect_Manager_GetFormattedCharacterName(characterData)
                local characterEntry = ZO_GamepadEntryData:New(text, characterData.icon)
                characterEntry:SetDataSource(characterData)
                characterEntry.slot = slot
                characterEntry.type = ENTRY_TYPE_CHARACTER
                characterEntry:SetHeader(header)
                characterEntry.subHeader = subHeader
                slot = slot + 1
                numCharacterSlotsAdded = numCharacterSlotsAdded + 1
                AddCharacterListEntry(template, characterEntry, self.characterList, prePadding, postPadding, preSelectedOffsetAdditionalPadding, postSelectedOffsetAdditionalPadding, selectedCenterOffset)
            end
        end
    end
    if self.serviceMode == SERVICE_TOKEN_NONE then
        -- Add Create New
        if CHARACTER_SELECT_MANAGER:CanCreateNewCharacters() then
            local newEntry = ZO_GamepadEntryData:New(GetString(SI_CHARACTER_SELECT_GAMEPAD_CREATE_NEW_ENTRY), CREATE_NEW_ICON)
            newEntry.index = slot
            newEntry.type = ENTRY_TYPE_CREATE_NEW
            newEntry:SetHeader(GetString(SI_CHARACTER_SELECT_GAMEPAD_CREATE_NEW_HEADER))
            AddCharacterListEntry("ZO_GamepadMenuEntryTemplateWithHeader", newEntry, self.characterList)
        end
    elseif numCharacterSlotsAdded == 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
    if scrollToBest and bestSelectionListIndex and not CHARACTER_SELECT_MANAGER:GetEventAnnouncementAutoShowIndex() then
        local ALLOW_EVEN_IF_DISABLED = true
        local FORCE_ANIMATION = false
        self.characterList:SetSelectedIndex(bestSelectionListIndex, ALLOW_EVEN_IF_DISABLED, FORCE_ANIMATION)
    end
    self.characterList:Commit()
end
local function RecreateList(self)
    CreateList(self, true)
end
local function RefreshKeybindStripForCharacterList(self, selectedData)
    if self.characterList:IsActive() then
        if self.serviceMode ~= SERVICE_TOKEN_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)
        elseif selectedData.type == ENTRY_TYPE_CHAPTER then
            ZO_CharacterSelect_Gamepad_RefreshKeybindStrip(self.charListKeybindStripDescriptorChapter)
        elseif selectedData.type == ENTRY_TYPE_EVENT then
            ZO_CharacterSelect_Gamepad_RefreshKeybindStrip(self.charListKeybindStripDescriptorEvent)
        elseif selectedData.type == ENTRY_TYPE_ESO_PLUS then
            ZO_CharacterSelect_Gamepad_RefreshKeybindStrip(self.charListKeybindStripDescriptorEsoPlus)
        else
            ZO_CharacterSelect_Gamepad_RefreshKeybindStrip(self.charListKeybindStripDescriptorDefault)
        end
    end
end
    local self = ZO_CharacterSelect_Gamepad
    if IsInGamepadPreferredMode() and selectedIndex then
        self.characterList:Deactivate()
        CHARACTER_SELECT_EVENT_BANNER_GAMEPAD:SetOnCloseCallback(function()
            CHARACTER_SELECT_MANAGER:ClearEventAnnouncementAutoShowIndex()
            DIRECTIONAL_INPUT:Activate(self, self)
            self.characterList:Activate()
            local selectedData = self.characterList:GetTargetData()
            RefreshKeybindStripForCharacterList(self, selectedData)
            ZO_CharacterSelect_GamepadCharacterViewport.Activate()
            end)
        DIRECTIONAL_INPUT:Deactivate(self, self)
        ZO_CharacterSelect_GamepadCharacterViewport.Deactivate()
        CHARACTER_SELECT_EVENT_BANNER_GAMEPAD:SetSelectedIndex(selectedIndex)
        SCENE_MANAGER:AddFragment(CHARACTER_SELECT_EVENT_BANNER_GAMEPAD:GetFragment())
    end
end
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" then
                SCENE_MANAGER:Push("gamepad_options_root")
            end
        end,
    }
    self.charListKeybindStripDescriptorDefault =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        -- Play
        {
            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,
        },
        -- Order Character Up
        {
            --Ethereal binds show no text, the name field is used to help identify the keybind when debugging. This text does not have to be localized.
            name = GetString(SI_CHARACTER_SELECT_ORDER_CHARACTER_UP),
            keybind = "UI_SHORTCUT_LEFT_SHOULDER",
            order = 101,
            callback = function()
                if not g_hasNeedsRenameCharacter then
                    local selectedData = self.characterList:GetTargetData()
                    if selectedData and selectedData.type == ENTRY_TYPE_CHARACTER and selectedData.order > 1 then
                        CHARACTER_SELECT_MANAGER:SwapCharacterOrderUp(selectedData.order)
                    end
                end
            end
        },
        -- Order Character Down
        {
            --Ethereal binds show no text, the name field is used to help identify the keybind when debugging. This text does not have to be localized.
            name = GetString(SI_CHARACTER_SELECT_ORDER_CHARACTER_DOWN),
            keybind = "UI_SHORTCUT_RIGHT_SHOULDER",
            order = 102,
            callback = function()
                if not g_hasNeedsRenameCharacter then
                    local selectedData = self.characterList:GetTargetData()
                    if selectedData and selectedData.order < CHARACTER_SELECT_MANAGER:GetNumCharacters() then
                        CHARACTER_SELECT_MANAGER:SwapCharacterOrderDown(selectedData.order)
                    end
                end
            end
        },
        deleteKeybind,
        optionsKeybind,
        KEYBIND_STRIP:GenerateGamepadBackButtonDescriptor(ZO_Disconnect),
    }
    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(ZO_Disconnect),
    }
    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(ZO_Disconnect),
    }
    ZO_Gamepad_AddListTriggerKeybindDescriptors(self.charListKeybindStripDescriptorCreateNew, self.characterList)
    self.charListKeybindStripDescriptorChapter =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        {
            name = GetString(SI_CHARACTER_SELECT_CHAPTER_UPGRADE_REGISTER),
            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("ChapterUpgrade")
            end,
        },
        optionsKeybind,
        KEYBIND_STRIP:GenerateGamepadBackButtonDescriptor(ZO_Disconnect),
    }
    ZO_Gamepad_AddListTriggerKeybindDescriptors(self.charListKeybindStripDescriptorChapter, self.characterList)
    self.charListKeybindStripDescriptorEvent =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        {
            name = GetString(SI_CHARACTER_SELECT_GAMEPAD_EVENTS_VIEW_KEYBIND),
            keybind = "UI_SHORTCUT_PRIMARY",
            disabledDuringSceneHiding = true,
            callback = function()
                PlaySound(SOUNDS.DIALOG_ACCEPT)
                local selectedData = self.characterList:GetTargetData()
                ZO_CharacterSelect_Gamepad_ShowEventAnnouncementsBanner(selectedData.index)
            end,
        },
        optionsKeybind,
        KEYBIND_STRIP:GenerateGamepadBackButtonDescriptor(ZO_Disconnect),
    }
    ZO_Gamepad_AddListTriggerKeybindDescriptors(self.charListKeybindStripDescriptorEvent, self.characterList)
    self.charListKeybindStripDescriptorEsoPlus =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        {
            name = GetString(SI_CHARACTER_SELECT_ESO_PLUS_READ_MORE),
            keybind = "UI_SHORTCUT_PRIMARY",
            disabledDuringSceneHiding = true,
            callback = function()
                ZO_ShowBuySubscriptionPlatformDialog()
            end,
        },
        optionsKeybind,
        KEYBIND_STRIP:GenerateGamepadBackButtonDescriptor(ZO_Disconnect),
    }
    ZO_Gamepad_AddListTriggerKeybindDescriptors(self.charListKeybindStripDescriptorEsoPlus, self.characterList)
    -- Keybinds for the additional character slot control
    self.charListKeybindStripDescriptorAdditionalSlots =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        optionsKeybind,
        KEYBIND_STRIP:GenerateGamepadBackButtonDescriptor(ZO_Disconnect),
    }
    -- 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 selectedEntryData = ZO_CharacterSelect_Gamepad_GetSelectedExtraInfoEntryData()
                if selectedEntryData == nil then
                    return false
                end
                if selectedEntryData.MeetsRequirementsFunction and selectedEntryData.MeetsRequirementsFunction() == false then
                    return false
                end
                if GetNumServiceTokens(selectedEntryData.serviceMode) == 0 then
                    return false
                end
                return true
            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(ZO_Disconnect),
    }
    -- 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_TOKEN_NAME_CHANGE then
                    ZO_CharacterSelect_Gamepad_BeginRename()
                elseif self.serviceMode == SERVICE_TOKEN_RACE_CHANGE then
                    ZO_CHARACTERCREATE_MANAGER:InitializeForRaceChange(CHARACTER_SELECT_MANAGER:GetSelectedCharacterData())
                    PregameStateManager_SetState("CharacterCreate_Barbershop")
                elseif self.serviceMode == SERVICE_TOKEN_APPEARANCE_CHANGE then
                    ZO_CHARACTERCREATE_MANAGER:InitializeForAppearanceChange(CHARACTER_SELECT_MANAGER:GetSelectedCharacterData())
                    PregameStateManager_SetState("CharacterCreate_Barbershop")
                elseif self.serviceMode == SERVICE_TOKEN_ALLIANCE_CHANGE then
                    ZO_CHARACTERCREATE_MANAGER:InitializeForAllianceChange(CHARACTER_SELECT_MANAGER:GetSelectedCharacterData())
                    PregameStateManager_SetState("CharacterCreate_Barbershop")
                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_TOKEN_NONE, RESET_LIST_TO_DEFAULT)
            end,
        },
    }
    ZO_Gamepad_AddListTriggerKeybindDescriptors(self.charListKeybindStripDescriptorUseServiceToken, self.characterList)
    self.charListKeybindStripDescriptorLogin =
    {
    }
    self.charListKeybindStripDescriptor = self.charListKeybindStripDescriptorDefault
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 gamepadIconString = "EsoUI/Art/Champion/Gamepad/gp_champion_icon.dds"
    local formattedIcon = zo_iconFormat(gamepadIconString, "100%", "100%")
    if characterData.championPoints and characterData.championPoints > 0 then
        return zo_strformat(SI_CHARACTER_SELECT_LEVEL_CHAMPION, formattedIcon, characterData.championPoints)
    else
        return zo_strformat(SI_CHARACTER_SELECT_LEVEL_VALUE, characterData.level)
    end
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
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
local function SelectedListDataChanged(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 shouldShowCharacterDetails = false
    if selectedData then
        g_canPlayCharacter = false
        if selectedData.type == ENTRY_TYPE_CHARACTER then
            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")
            characterName:SetText(ZO_CharacterSelect_Manager_GetFormattedCharacterName(selectedData))
            characterRace:SetText(ZO_CharacterSelect_Gamepad_GetFormattedRace(selectedData))
            characterLevel:SetText(ZO_CharacterSelect_Gamepad_GetFormattedLevel(selectedData))
            characterClass:SetText(ZO_CharacterSelect_Gamepad_GetFormattedClass(selectedData))
            characterAlliance:SetText(ZO_CharacterSelect_Gamepad_GetFormattedAlliance(selectedData))
            characterLocation:SetText(ZO_CharacterSelect_Gamepad_GetFormattedLocation(selectedData))
            g_canPlayCharacter = true
            -- Only show character details if the character is in a valid location
            shouldShowCharacterDetails = selectedData.location and selectedData.location ~= 0
        end
        RefreshKeybindStripForCharacterList(self, selectedData)
    else
        CHARACTER_SELECT_MANAGER:SetPlayerSelectedCharacterId(nil)
    end
    ZO_CharacterSelect_GamepadCharacterDetails:SetHidden(not shouldShowCharacterDetails)
    -- Handle needs rename text
    local needsRename = selectedData and selectedData.needsRename
    self.characterDetails:SetHidden(needsRename)
    self.characterNeedsRename:SetHidden(not needsRename)
    g_lastSelectedEntryData = selectedData
end
    local self = ZO_CharacterSelect_Gamepad
    SelectedListDataChanged(self, nil, g_lastSelectedEntryData, nil)
end
    local self = ZO_CharacterSelect_Gamepad
    local profileNameString = nil
    local profileLabelString = nil
    if IsHeronUI() then
        -- Use player's heron name
        profileNameString = GetExternalName()
        profileLabelString = GetString(SI_CHARACTER_SELECT_HERON_PROFILE_LABEL)
    elseif IsConsoleUI() then
        -- Use the console's active profile name
        profileNameString = GetOnlineIdForActiveProfile()
        profileLabelString = GetString(SI_CHARACTER_SELECT_PROFILE_LABEL)
    end
    local profileName = ZO_CharacterSelectProfile_Gamepad:GetNamedChild("ProfileName")
    local profileLabel = ZO_CharacterSelectProfile_Gamepad:GetNamedChild("ProfileLabel")
    if profileNameString and profileNameString ~= "" then
        profileName:SetHidden(false)
        profileLabel:SetHidden(false)
        profileName:SetText(profileNameString)
        profileLabel:SetText(profileLabelString)
    else
        profileName:SetHidden(true)
        profileLabel:SetHidden(true)
    end
end
local function OnCharacterConstructionReady()
    local self = ZO_CharacterSelect_Gamepad
    local selectedCharacterData = CHARACTER_SELECT_MANAGER:GetSelectedCharacterData()
    if GAMEPAD_CHARACTER_SELECT_SCENE:IsShowing() and not self.characterConstructed and selectedCharacterData then
        local ALLOW_EVEN_IF_DISABLED = true
        local FORCE_ANIMATION = false
        local listIndex = self.characterList:FindFirstIndexByEval(function(entry) return AreId64sEqual(selectedCharacterData.id, entry.id) end)
        self.characterList:SetSelectedIndexWithoutAnimation(listIndex, ALLOW_EVEN_IF_DISABLED, FORCE_ANIMATION)
        --if we're quick launching, then just select the first character we can.
        if GetCVar("QuickLaunch") == "1" then
            ZO_CharacterSelect_Gamepad_Login(CHARACTER_OPTION_EXISTING_AREA)
        end
        CHARACTER_SELECT_MANAGER:RefreshConstructedCharacter()
        self.characterConstructed = true
    end
end
local function OnPregameFullyLoaded()
    local self = ZO_CharacterSelect_Gamepad
    RecreateList(self)
    if self.active then
        if not CHARACTER_SELECT_MANAGER:GetEventAnnouncementAutoShowIndex() then
            self.characterList:Activate()
        end
        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 then
        if self.currentKeystrip ~= self.charListKeybindStripDescriptor then
            self.currentKeystrip = self.charListKeybindStripDescriptor
            KEYBIND_STRIP:RemoveDefaultExit()
            KEYBIND_STRIP:AddKeybindButtonGroup(self.charListKeybindStripDescriptor)
        else
            KEYBIND_STRIP:UpdateKeybindButtonGroup(self.currentKeystrip)
        end
    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
        local RESET_TO_DEFAULT = true
        ZO_CharacterSelect_Gamepad_ChangeServiceMode(SERVICE_TOKEN_NONE, RESET_TO_DEFAULT)
        ZO_CharacterSelect_GamepadCharacterViewport.Activate()
        SCENE_MANAGER:AddFragment(CHARACTER_SELECT_CHARACTERS_GAMEPAD_FRAGMENT)
        local characterDataReady = IsPregameCharacterConstructionReady()
        if characterDataReady and not CHARACTER_SELECT_MANAGER:GetEventAnnouncementAutoShowIndex() then
            self.characterList:RefreshVisible()
            self.characterList:Activate()
            self.extraInfoFocus:Deactivate()
        end
        if characterDataReady 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)
        if CHARACTER_SELECT_MANAGER:IsSavedDataReady() then
        else
            CHARACTER_SELECT_MANAGER:RegisterCallback("OnSavedDataReady", function() ZO_CharacterSelect_Gamepad_ShowEventAnnouncementsBanner(CHARACTER_SELECT_MANAGER:GetEventAnnouncementAutoShowIndex()) end)
        end
    elseif newState == SCENE_HIDDEN then
        self.characterConstructed = false
        DIRECTIONAL_INPUT:Deactivate(self, self)
        self.active = false
        ZO_CharacterSelect_GamepadCharacterViewport.StopAllInput()
        ZO_CharacterSelect_GamepadCharacterViewport.Deactivate()
        self.characterList:Deactivate()
        self.extraInfoFocus:Deactivate()
    end
end
local function CharacterDeleted(eventCode, charId)
    if ZO_CharacterSelect_Gamepad.deleting then
        -- 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.refreshAfterCharacterDeleted = true
        ZO_Dialogs_ReleaseDialog("CHARACTER_SELECT_DELETING")
    end
end
local g_requestedRename = ""
local function ContextFilter(callback)
    -- This will wrap the callback so that it gets called in the appropriate context
    return function(...)
        if IsGamepadUISupported() then
            callback(...)
        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
            self.extraInfoFocus:Deactivate()
            self.characterList:Activate()
            SelectedListDataChanged(self, self.characterList, g_lastSelectedEntryData)
            PlaySound(SOUNDS.GAMEPAD_MENU_DOWN)
        elseif self.characterList:IsActive() then
            self.characterList:MoveNext()
        end
    elseif result == MOVEMENT_CONTROLLER_MOVE_PREVIOUS then
        if self.characterList:IsActive() then
            if self.characterList:GetSelectedIndex() ~= 1 then
                self.characterList:MovePrevious()
            elseif not self.extraInfoContainer:IsHidden() then
                self.extraInfoFocus:Activate()
                self.characterList:Deactivate()
                SelectedListDataChanged(self, self.characterList, { type = ENTRY_TYPE_EXTRA_INFO })
                PlaySound(SOUNDS.GAMEPAD_MENU_UP)
            end
        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:SetHandleDynamicViewProperties(true)
    self.characterList:SetDirectionalInputEnabled(false)
    self.characterDetails = self:GetNamedChild("CharacterDetails"):GetNamedChild("Container")
    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
        end
    end)
    self.extraInfoControlPool = ZO_ControlPool:New("ZO_CharacterSelect_ExtraInfo_Entry", self.extraInfoCenterer)
    -- Service header controls
    self.serviceMode = SERVICE_TOKEN_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)
        if selectedData.type == ENTRY_TYPE_CHARACTER then
            CHARACTER_SELECT_MANAGER:SetSelectedCharacter(selectedData:GetDataSource())
        end
        SelectedListDataChanged(self, list, selectedData, oldSelectedData)
    end
    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))
    self:RegisterForEvent(EVENT_CHARACTER_DELETED, ContextFilter(CharacterDeleted))
    CHARACTER_SELECT_MANAGER:RegisterCallback("EventAnnouncementsReceived", function()
        if PregameIsFullyLoaded() then
        end
    end)
    CHARACTER_SELECT_MANAGER:RegisterCallback("CharacterListUpdated", function()
        if self.refreshAfterCharacterDeleted then
            if CHARACTER_SELECT_MANAGER:GetNumCharacters() == 0 then
                return -- We are going to the character create screen
            end
            PlaySound(SOUNDS.GAMEPAD_MENU_BACK)
            ZO_CharacterSelect_Gamepad_ReturnToCharacterList(ACTIVATE_VIEWPORT)
            self.characterList:Clear()
            self.refreshAfterCharacterDeleted = false
        end
        RecreateList(self)
    end)
    CHARACTER_SELECT_MANAGER:RegisterCallback("CharacterOrderChanged", function(targetCharacterData)
        CreateList(self)
        local listIndex = self.characterList:FindFirstIndexByEval(function(entry) return AreId64sEqual(targetCharacterData.id, entry.id) end)
        local ALLOW_EVEN_IF_DISABLED = true
        local FORCE_ANIMATION = false
        self.characterList:SetSelectedIndexWithoutAnimation(listIndex, ALLOW_EVEN_IF_DISABLED, FORCE_ANIMATION)
    end)
    self.control:AddFragment(KEYBIND_STRIP_GAMEPAD_BACKDROP_FRAGMENT)
    local function OnRenameResult(success)
        if success then
            -- 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_TOKEN_NONE then
                ZO_CharacterSelect_Gamepad_ReturnToCharacterList(ACTIVATE_VIEWPORT)
            else
                local DONT_RESET_TO_DEFAULT = false
                ZO_CharacterSelect_Gamepad_ChangeServiceMode(SERVICE_TOKEN_NONE, DONT_RESET_TO_DEFAULT)
            end
        else
            -- restart flow
            ZO_CharacterSelect_Gamepad_BeginRename()
        end
    end
    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()
                -- viewport was never deactivated, so don't reactivate
                local DONT_ACTIVATE_VIEWPORT = false
                ZO_CharacterSelect_Gamepad_ReturnToCharacterList(DONT_ACTIVATE_VIEWPORT)
            end,
            onFinish = function(dialog)
                g_requestedRename = dialog.selectedName
                if g_requestedRename and g_requestedRename ~= "" then
                    local selectedCharacterData = CHARACTER_SELECT_MANAGER:GetSelectedCharacterData()
                    CHARACTER_SELECT_MANAGER:AttemptCharacterRename(selectedCharacterData.id, g_requestedRename, OnRenameResult)
                end
            end,
            createHeaderDataFunction = function(dialog, data)
                local headerData = {}
                if data then
                    if data.renameFromToken then
                        headerData.data1 =
                        {
                            value = GetNumServiceTokens(SERVICE_TOKEN_NAME_CHANGE),
                            header = GetString(SI_SERVICE_TOKEN_COUNT_TOKENS_HEADER),
                        }
                    end
                end
                return headerData
            end,
        })
end
    local selectedCharacterData = CHARACTER_SELECT_MANAGER:GetSelectedCharacterData()
    if selectedCharacterData then
        local dialogData =
        {
            originalCharacterName = selectedCharacterData.name,
            -- Dialog displays additional info if a player is spending a token to rename
            renameFromToken = not selectedCharacterData.needsRename,
        }
        ZO_Dialogs_ShowGamepadDialog("CHARACTER_SELECT_RENAME_CHARACTER_GAMEPAD", dialogData)
        ZO_CharacterSelect_GamepadCharacterDetails:SetHidden(true)
    end
end
    local state = PregameStateManager_GetCurrentState()
    if state == "CharacterSelect" then
        local selectedCharacterData = CHARACTER_SELECT_MANAGER:GetSelectedCharacterData()
        if selectedCharacterData then
            PregameStateManager_PlayCharacter(selectedCharacterData.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
    local self = ZO_CharacterSelect_Gamepad
    local selectedFocus = self.extraInfoFocus:GetFocusItem()
    if selectedFocus then
        if selectedFocus.control and selectedFocus.control.data then
            return selectedFocus.control.data
        end
    end
    return nil
end
    local selectedEntryData = ZO_CharacterSelect_Gamepad_GetSelectedExtraInfoEntryData()
    if selectedEntryData then
        return selectedEntryData.serviceMode
    end
    return SERVICE_TOKEN_NONE
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
        self.extraInfoContainer:SetHidden(serviceMode ~= SERVICE_TOKEN_NONE)
        -- Update Header Text and rebuild the list to filter out invalid options
        local characterListHeader
        if serviceMode == SERVICE_TOKEN_NAME_CHANGE then
            characterListHeader = GetString(SI_CHARACTER_SELECT_RENAME_CHARACTER_FROM_TOKEN_TITLE)
        elseif serviceMode == SERVICE_TOKEN_RACE_CHANGE then
            characterListHeader = GetString(SI_CHARACTER_SELECT_RACE_CHANGE_FROM_TOKEN_TITLE)
        elseif serviceMode == SERVICE_TOKEN_APPEARANCE_CHANGE then
            characterListHeader = GetString(SI_CHARACTER_SELECT_APPEARANCE_CHANGE_FROM_TOKEN_TITLE)
        elseif serviceMode == SERVICE_TOKEN_ALLIANCE_CHANGE then
            characterListHeader = GetString(SI_CHARACTER_SELECT_ALLIANCE_CHANGE_FROM_TOKEN_TITLE)
        else
            characterListHeader = GetString(SI_CHARACTER_SELECT_GAMEPAD_SELECT_CHARACTER)
        end
        self.headerData.titleText = characterListHeader
        RecreateList(self)
        -- Update list positions
        if resetListToDefault and not CHARACTER_SELECT_MANAGER:GetEventAnnouncementAutoShowIndex() then
            if serviceMode == SERVICE_TOKEN_NONE then
                self.characterList:SetSelectedIndex(1)
                SelectedListDataChanged(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()
                
                -- after activating the character list select the first character
                -- if this is done before activation, the keybinds won't refresh correctly
                self.characterList:SetSelectedIndex(1)
            end
        end
    end
end