Back to Home

ESO Lua File v100035

pregame/charactercreate/keyboard/zo_charactercreate_keyboard.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
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
local KEYBOARD_BUCKET_MANAGER
--[[ Slider Randomization Helper...all sliders share the sliderObject from the top control, so this just helps cut down on duplicate functions ]]--
local function RandomizeSlider(control, randomizeType)
    control.sliderObject:Randomize(randomizeType)
end
--[[ Character Create Slider and Appearance Slider Managers ]]--
-- Manages a collection of sliders with a pool
local CharacterCreateSliderManager = ZO_Object:Subclass()
function CharacterCreateSliderManager:New(...)
    local manager = ZO_Object.New(self)
    manager:Initialize(...)
    return manager
end
function CharacterCreateSliderManager:Initialize(parent)
    local function CreateSlider(pool)
        local control = ZO_ObjectPool_CreateNamedControl("CharacterCreateSlider", "ZO_CharacterCreateSlider_Keyboard", pool, parent)
        return ZO_CharacterCreateSlider_Keyboard:New(control)
    end
    local function CreateAppearanceSlider(pool)
        local control = ZO_ObjectPool_CreateNamedControl("CharacterCreateAppearanceSlider", "ZO_CharacterCreateSlider_Keyboard", pool, parent)
        return ZO_CharacterCreateAppearanceSlider_Keyboard:New(control)
    end
    local function CreateColorPicker(pool)
        local control = ZO_ObjectPool_CreateNamedControl("CharacterCreateColorPicker", "ZO_CharacterCreateColorSlider_Keyboard", pool, parent)
        return ZO_CharacterCreateColorSlider_Keyboard:New(control)
    end
    local function CreateDropdown(pool)
        local control = ZO_ObjectPool_CreateNamedControl("CharacterCreateDropdown", "ZO_CharacterCreateDropDownSlider_Keyboard", pool, parent)
        return ZO_CharacterCreateDropdownSlider_Keyboard:New(control)
    end
    local function ResetSlider(slider)
        local sliderControl = slider.control
        KEYBOARD_BUCKET_MANAGER:RemoveControl(sliderControl)
        sliderControl:SetHidden(true)
        slider:SetLocked(false)
    end
    local function ResetColorPicker(slider)
        local sliderControl = slider.control
        KEYBOARD_BUCKET_MANAGER:RemoveControl(sliderControl)
        ZO_ColorSwatchPicker_Clear(sliderControl:GetNamedChild("Slider"))
        sliderControl:SetHidden(true)
        slider:SetLocked(false)
    end
    self.pools =
    {
        [CHARACTER_CREATE_SLIDER_TYPE_SLIDER] = ZO_ObjectPool:New(CreateSlider, ResetSlider),
        [CHARACTER_CREATE_SLIDER_TYPE_ICON] = ZO_ObjectPool:New(CreateAppearanceSlider, ResetSlider),
        [CHARACTER_CREATE_SLIDER_TYPE_COLOR] = ZO_ObjectPool:New(CreateColorPicker, ResetColorPicker),
        [CHARACTER_CREATE_SLIDER_TYPE_NAMED] = ZO_ObjectPool:New(CreateDropdown, ResetSlider),
    }
end
function CharacterCreateSliderManager:AcquireObject(objectType)
    local pool = self.pools[objectType]
    if pool then
        return pool:AcquireObject()
    end
end
function CharacterCreateSliderManager:ReleaseAllObjects()
    for poolType, pool in pairs(self.pools) do
        pool:ReleaseAllObjects()
    end
end
--[[ Creator Control Initialization ]]--
local function FindOrdering(orderingTable, name)
    for i = 1, #orderingTable do
        if orderingTable[i] == name then
            return i
        end
    end
    return 1
end
--[[ Character Create Keyboard ]]--
local ZO_CharacterCreate_Keyboard = ZO_CharacterCreate_Base:Subclass()
function ZO_CharacterCreate_Keyboard:New(...)
    return ZO_CharacterCreate_Base.New(self, ...)
end
function ZO_CharacterCreate_Keyboard:Initialize(...)
    ZO_CharacterCreate_Base.Initialize(self, ...)
    local function HandleZoomChanged(eventCode, zoomInAllowed, zoomOutAllowed)
        ZO_CharacterCreateZoomIn:SetEnabled(zoomInAllowed)
        ZO_CharacterCreateZoomOut:SetEnabled(zoomOutAllowed)
    end
    EVENT_MANAGER:RegisterForEvent("ZO_CharacterCreate", EVENT_CHARACTER_CREATE_ZOOM_CHANGED, HandleZoomChanged)
    local function OnStateChanged(oldState, newState)
        if newState == SCENE_FRAGMENT_SHOWING then
            self:ResetControls()
        elseif newState == SCENE_FRAGMENT_HIDING then
            self:UpdateUnsavedSettings()
        end
    end
    CHARACTER_CREATE_FRAGMENT = ZO_FadeSceneFragment:New(self.control, 300)
    CHARACTER_CREATE_FRAGMENT:RegisterCallback("StateChange", OnStateChanged)
end
function ZO_CharacterCreate_Keyboard:UpdateUnsavedSettings()
    for name, nameTable in pairs(self.controlsByNameCategory) do
        for category, slider in pairs(nameTable) do
            ZO_CHARACTERCREATE_MANAGER:SetCharacterUnsavedSetting(name, category, slider:GetValue(), slider:IsLocked())
        end
    end
    local UNUSED_VALUE = nil
    ZO_CHARACTERCREATE_MANAGER:SetCharacterUnsavedSetting("triangle", "physique", UNUSED_VALUE, self.physiqueTriangle:IsLocked())
    ZO_CHARACTERCREATE_MANAGER:SetCharacterUnsavedSetting("triangle", "face", UNUSED_VALUE, self.faceTriangle:IsLocked())
end
function ZO_CharacterCreate_Keyboard:OnCharacterCreateRequested()
    self.createButton:SetEnabled(false)
end
do
    local reasonsThatDisableCreateButton =
    {
        [CHARACTER_CREATE_EDIT_ERROR_INVALID_NAME] = true,
        [CHARACTER_CREATE_EDIT_ERROR_DUPLICATE_NAME] = true,
        [CHARACTER_CREATE_EDIT_ERROR_NAME_TOO_SHORT] = true,
        [CHARACTER_CREATE_EDIT_ERROR_NAME_TOO_LONG] = true,
    }
    function ZO_CharacterCreate_Keyboard:OnCharacterCreateFailed(reason)
        local errorReason = GetString("SI_CHARACTERCREATEEDITERROR", reason)
        -- Show the fact that the character could not be created.
        ZO_Dialogs_ShowDialog("CHARACTER_CREATE_FAILED_REASON", nil, { mainTextParams = { errorReason } })
        if reasonsThatDisableCreateButton[reason] then
            self.createButton:SetEnabled(false)
        end
    end
end
do
    local function CreateTriangle(control, setterFn, updaterFn, triangleStringId, topStringId, leftStringId, rightStringId)
        local triangle = ZO_CharacterCreateTriangle_Keyboard:New(control, setterFn, updaterFn, triangleStringId, topStringId, leftStringId, rightStringId)
        return triangle
    end
    function ZO_CharacterCreate_Keyboard:InitializeControls()
        self.control.fadeTimeline = ANIMATION_MANAGER:CreateTimelineFromVirtual("CharacterCreateMainControlsFade", self.control)
        self.bucketsControl = self.control:GetNamedChild("Buckets")
        self.sliderManager = CharacterCreateSliderManager:New(self.bucketsControl)
        -- create the radio button groups
        self.allianceRadioGroup = ZO_RadioButtonGroup:New()
        self.raceRadioGroup = ZO_RadioButtonGroup:New()
        self.classRadioGroup = ZO_RadioButtonGroup:New()
        self.genderRadioGroup = ZO_RadioButtonGroup:New()
        -- create the triangle controls
        self.physiqueTriangleControl = CreateControlFromVirtual("$(parent)PhysiqueSelection", self.control, "ZO_CharacterCreateTriangleTemplate_Keyboard")
        self.physiqueTriangle = CreateTriangle(self.physiqueTriangleControl, SetPhysique, GetPhysique, SI_CREATE_CHARACTER_BODY_TRIANGLE_LABEL, SI_CREATE_CHARACTER_TRIANGLE_MUSCULAR, SI_CREATE_CHARACTER_TRIANGLE_FAT, SI_CREATE_CHARACTER_TRIANGLE_THIN)
        self.faceTriangleControl = CreateControlFromVirtual("$(parent)FaceSelection", self.control, "ZO_CharacterCreateTriangleTemplate_Keyboard")
        self.faceTriangle = CreateTriangle(self.faceTriangleControl, SetFace, GetFace, SI_CREATE_CHARACTER_FACE_TRIANGLE_LABEL, SI_CREATE_CHARACTER_TRIANGLE_FACE_MUSCULAR, SI_CREATE_CHARACTER_TRIANGLE_FACE_FAT, SI_CREATE_CHARACTER_TRIANGLE_FACE_THIN)
        -- setup the create button and link it to the name control
        self.createButton = self.control:GetNamedChild("CreateButton")
        self.createButton:SetEnabled(false)
        self.instructionsControl = self.control:GetNamedChild("NameInstructions")
        self.nameInstructionsObject = ZO_ValidNameInstructions:New(self.instructionsControl)
        self.nameControl = self.control:GetNamedChild("CharacterName")
        SetupEditControlForNameValidation(self.nameControl)
        self.nameControl.linkedButton = self.createButton
        self.nameControl.linkedInstructions = self.nameInstructionsObject
        self.saveButton = self.control:GetNamedChild("SaveButton")
        self.templateControl = self.control:GetNamedChild("Template")
        self.raceSelectionControl = self.control:GetNamedChild("Race")
        self.classSelectionControl = self.control:GetNamedChild("ClassSelection")
        self.genderSelectionControl = self.control:GetNamedChild("GenderSelection")
    end
end
function ZO_CharacterCreate_Keyboard:InitializeSelectorButtonTextures(buttonControl, data)
    buttonControl:SetNormalTexture(data.normalIcon)
    buttonControl:SetPressedTexture(data.pressedIcon)
    buttonControl:SetMouseOverTexture(data.mouseoverIcon)
end
function ZO_CharacterCreate_Keyboard:InitializeSelectors()
end
function ZO_CharacterCreate_Keyboard:InitializeAllianceSelectors()
    local layoutTable =
    {
        ZO_CharacterCreateRaceAllianceSelector1,
        ZO_CharacterCreateRaceAllianceSelector2,
        ZO_CharacterCreateRaceAllianceSelector3,
    }
    local alliances = self.characterData:GetAllianceInfo()
    for _, alliance in ipairs(alliances) do
        local selector = layoutTable[alliance.position]
        self:InitializeAllianceSelector(selector, alliance)
    end
end
function ZO_CharacterCreate_Keyboard:InitializeRaceSelectors()
    local layoutTable =
    {
        ZO_CharacterCreateRaceColumn11,
        ZO_CharacterCreateRaceColumn21,
        ZO_CharacterCreateRaceColumn31,
        ZO_CharacterCreateRaceColumn12,
        ZO_CharacterCreateRaceColumn22,
        ZO_CharacterCreateRaceColumn32,
        ZO_CharacterCreateRaceColumn13,
        ZO_CharacterCreateRaceColumn23,
        ZO_CharacterCreateRaceColumn33,
        ZO_CharacterCreateRaceSingleButton,
    }
    local races = self.characterData:GetRaceInfo()
    for _, race in ipairs(races) do
        local raceButton = layoutTable[race.position]
        self:InitializeSelectorButton(raceButton, race, self.raceRadioGroup)
        self:AddRaceSelectionDataToSelector(raceButton, race)
    end
end
function ZO_CharacterCreate_Keyboard:InitializeGenderSelector()
    local maleSelector = self.genderSelectionControl:GetNamedChild("Male")
    maleSelector:GetNamedChild("Label"):SetText(GetString("SI_GENDER", GENDER_MALE))
    local femaleSelector = self.genderSelectionControl:GetNamedChild("Female")
    femaleSelector:GetNamedChild("Label"):SetText(GetString("SI_GENDER", GENDER_FEMALE))
    local maleSelectorButton = maleSelector:GetNamedChild("Button")
    maleSelectorButton.gender = GENDER_MALE
    local femaleSelectorButton = femaleSelector:GetNamedChild("Button")
    femaleSelectorButton.gender = GENDER_FEMALE
    self.genderRadioGroup:Add(maleSelectorButton)
    self.genderRadioGroup:Add(femaleSelectorButton)
end
function ZO_CharacterCreate_Keyboard:InitializeTemplateList()
    local comboBox = ZO_ComboBox_ObjectFromContainer(self.templateControl)
    comboBox:ClearItems()
    comboBox:SetSortsItems(false)
    comboBox:SetFont("ZoFontGame")
    comboBox:SetSpacing(4)
    local function OnTemplateChanged(comboBox, entryText, entry)
        if self:SetTemplate(entry.templateData.template) then
            KEYBOARD_BUCKET_MANAGER:UpdateControlsFromData()
        end
    end
    local defaultTemplate = GetDefaultTemplate()
    local function SelectDefaultTemplate(entry)
        return entry.templateData.template == defaultTemplate
    end
    local templatesAllowed = GetTemplateStatus()
    if templatesAllowed then
        local templates = self.characterData:GetTemplateInfo()
        for _, templateData in ipairs(templates) do
            if templateData.isSelectable then
                local entry = comboBox:CreateItemEntry(templateData.name, OnTemplateChanged)
                entry.templateData = templateData
                comboBox:AddItem(entry)
            end
        end
        if not comboBox:SetSelectedItemByEval(SelectDefaultTemplate) then
            comboBox:SelectFirstItem()
        end
        self.templateControl:SetHidden(false)
    else
        self.templateControl:SetHidden(true)
    end
end
function ZO_CharacterCreate_Keyboard:SetTemplate(templateId)
    local templateData = self.characterData:GetTemplate(templateId)
    if not templateData then
        return false
    end
    local characterMode = ZO_CHARACTERCREATE_MANAGER:GetCharacterMode()
    if not templateData.isSelectable or CharacterCreateGetTemplate(characterMode) == templateId then
        return false
    end
    CharacterCreateSetTemplate(templateId)
    local validRaces = {}
    self:UpdateSelectorsForTemplate(function(...) return self:UpdateRaceSelectorsForTemplate(...) end, self.characterData:GetRaceInfo(), templateData, self.raceRadioGroup, validRaces)
    self:UpdateSelectorsForTemplate(function(...) return self:UpdateClassSelectorsForTemplate(...) end, self.characterData:GetClassInfo(), templateData, self.classRadioGroup)
    local validAlliances = {}
    self.characterData:UpdateAllianceSelectability()
    self:UpdateSelectorsForTemplate(function(...) return self:UpdateAllianceSelectorsForTemplate(...) end, self.characterData:GetAllianceInfo(), templateData, self.allianceRadioGroup, validAlliances)
    self:UpdateGenderSelectorsForTemplate(templateData)
    -- Pick a race
    if templateData.race ~= 0 then
        CharacterCreateSetRace(templateData.race)
    else
        CharacterCreateSetRace(self.characterData:PickRandomRace(validRaces))
    end
    -- Pick an alliance
    if templateData.alliance ~= ALLIANCE_NONE then
        ZO_CharacterCreate_SetAlliance(templateData.alliance)
    else
        -- (never random unless a race without a fixed alliance is picked)
        local alliance = self.characterData:GetRaceForRaceDef(CharacterCreateGetRace(characterMode)).alliance
        if alliance ~= ALLIANCE_NONE then
            ZO_CharacterCreate_SetAlliance(alliance)
        else
            ZO_CharacterCreate_SetAlliance(self.characterData:PickRandomAlliance(validAlliances))
        end
    end
    -- Pick a class
    if templateData.class ~= 0 then
        self:SetClass(templateData.class)
    else
        -- UpdateSelectorsForTemplate() should be called prior to this function or unselectable classes might be set (which would result in no class being set).
        self:PickRandomSelectableClass()
    end
    -- Pick a gender
    if templateData.gender ~= GENDER_NEUTER then
        self:SetGender(templateData.gender)
    else
        self:PickRandomGender()
    end
    -- Make the controls match what you picked...
    self:ResetControls()
    if not templateData.overrideAppearance then
        ZO_CharacterCreate_RandomizeAppearance("initial")
    else
        InitializeAppearanceFromTemplate(templateId)
    end
    -- Disable appearance related controls if the appearance is overridden in the template.
    -- buckets need to be disabled after resetting the controls
    local enabled = not templateData.overrideAppearance
    KEYBOARD_BUCKET_MANAGER:EnableBucketTab(CREATE_BUCKET_BODY, enabled)
    KEYBOARD_BUCKET_MANAGER:EnableBucketTab(CREATE_BUCKET_FACE, enabled)
    ZO_CharacterCreateRandomizeAppearance:SetEnabled(enabled)
    return true
end
function ZO_CharacterCreate_Keyboard:InitializeClassSelectors()
        local classes = self.characterData:GetClassInfo()
        if #classes > CHARACTER_CREATE_MAX_SUPPORTED_CLASSES then
            -- this assert is duplicated from the gamepad UI so that non-console builds will catch the issue as well
            local errorString = string.format("The gamepad UI currently only supports up to %d classes, but there are currently %d classes used", CHARACTER_CREATE_MAX_SUPPORTED_CLASSES, #classes)
            internalassert(false, errorString)
        end
        local parent = self.classSelectionControl:GetNamedChild("ButtonArea")
        local stride = 3
        local padX = 0
        local padY = 0
        local controlWidth = 120
        local controlHeight = 80
        local initialX = 0
        local initialY = 0
        local anchor = ZO_Anchor:New(TOPLEFT, parent, TOPLEFT, initialX, initialY)
        for i, classData in ipairs(classes) do
            local selectorName = "SelectClass" .. classData.class
            local selector = GetControl(selectorName)
            if not selector then
                selector = CreateControlFromVirtual(selectorName, parent, "ClassSelectorButton")
            end
            selector.nameFn = GetClassName
            selector.defId = classData.class
            self:InitializeSelectorButton(selector, classData, self.classRadioGroup)
            ZO_Anchor_BoxLayout(anchor, selector, i - 1, stride, padX, padY, controlWidth, controlHeight, initialX, initialY, GROW_DIRECTION_DOWN_RIGHT)
        end
    end
do
    -- This table defines how sliders should be ordered within their sub-categories.
    -- It's not needed for sub-categories where all the controls are added manually,
    -- but when sliders are added in loops (like characterSlider and appearanceSlider)
    -- this is used to assist building the ordering table which will be passed over
    -- to actually add the sliders.
    local CONTROL_ORDERING =
    {
        [SLIDER_SUBCAT_BODY_FEATURES] =
        {
            APPEARANCE_NAME_SKIN_TINT,
            APPEARANCE_NAME_BODY_MARKING,
            SLIDER_NAME_CHARACTER_HEIGHT,
        },
        [SLIDER_SUBCAT_BODY_UPPER] =
        {
            SLIDER_NAME_TORSO_SIZE,
            SLIDER_NAME_CHEST_SIZE,
            SLIDER_NAME_GUT_SIZE,
            SLIDER_NAME_WAIST_SIZE,
            SLIDER_NAME_ARM_SIZE,
            SLIDER_NAME_HAND_SIZE,
        },
        [SLIDER_SUBCAT_BODY_LOWER] =
        {
            SLIDER_NAME_TAIL_SIZE,
            SLIDER_NAME_HIP_SIZE,
            SLIDER_NAME_BUTTOCKS_SIZE,
            SLIDER_NAME_LEG_SIZE,
            SLIDER_NAME_FOOT_SIZE,
        },
        [SLIDER_SUBCAT_VOICE] =
        {
            APPEARANCE_NAME_VOICE,
        },
        [SLIDER_SUBCAT_FACE_HAIR] =
        {
            APPEARANCE_NAME_HAIR_STYLE,
            APPEARANCE_NAME_HAIR_TINT,
        },
        [SLIDER_SUBCAT_FACE_FEATURES] =
        {
            APPEARANCE_NAME_AGE,
            APPEARANCE_NAME_ACCESSORY,
            APPEARANCE_NAME_HEAD_MARKING,
        },
        [SLIDER_SUBCAT_FACE_FACE] =
        {
            SLIDER_NAME_FOREHEAD_SLOPE,
            SLIDER_NAME_CHEEK_BONE_SIZE,
            SLIDER_NAME_CHEEK_BONE_HEIGHT,
            SLIDER_NAME_JAW_SIZE,
            SLIDER_NAME_CHIN_SIZE,
            SLIDER_NAME_CHIN_HEIGHT,
            SLIDER_NAME_NECK_SIZE,
            SLIDER_NAME_TOOTH_SIZE,
        },
        [SLIDER_SUBCAT_FACE_EYES] =
        {
            APPEARANCE_NAME_EYE_TINT,
            SLIDER_NAME_EYE_SIZE,
            SLIDER_NAME_EYE_ANGLE,
            SLIDER_NAME_EYE_SEPARATION,
            SLIDER_NAME_EYE_HEIGHT,
            SLIDER_NAME_EYE_SQUINT,
        },
        [SLIDER_SUBCAT_FACE_BROW] =
        {
            APPEARANCE_NAME_EYEBROW,
            SLIDER_NAME_EYEBROW_HEIGHT,
            SLIDER_NAME_EYEBROW_ANGLE,
            SLIDER_NAME_EYEBROW_SKEW,
            SLIDER_NAME_EYEBROW_DEPTH,
        },
        [SLIDER_SUBCAT_FACE_NOSE] =
        {
            SLIDER_NAME_NOSE_SHAPE,
            SLIDER_NAME_NOSE_HEIGHT,
            SLIDER_NAME_NOSE_WIDTH,
            SLIDER_NAME_NOSE_LENGTH,
        },
        [SLIDER_SUBCAT_FACE_MOUTH] =
        {
            SLIDER_NAME_MOUTH_HEIGHT,
            SLIDER_NAME_MOUTH_WIDTH,
            SLIDER_NAME_MOUTH_CURVE,
            SLIDER_NAME_LIP_FULLNESS,
        },
        [SLIDER_SUBCAT_FACE_EARS] =
        {
            SLIDER_NAME_EAR_SIZE,
            SLIDER_NAME_EAR_ROTATION,
            SLIDER_NAME_EAR_HEIGHT,
            SLIDER_NAME_EAR_TIP_FLARE,
        },
    }
    local function SliderComparator(data1, data2)
        local name1 = data1.name
        local name2 = data2.name
        local subCat1 = data1.subCat
        local subCat2 = data2.subCat
        if subCat1 ~= subCat2 then
            return subCat1 < subCat2
        end
        return FindOrdering(CONTROL_ORDERING[subCat1], name1) < FindOrdering(CONTROL_ORDERING[subCat2], name2)
    end
    local SLIDER_CATEGORY_TO_CREATE_BUCKET =
    {
        [SLIDER_CATEGORY_AGE] = CREATE_BUCKET_BODY,
        [SLIDER_CATEGORY_BODY] = CREATE_BUCKET_BODY,
        [SLIDER_CATEGORY_FACE] = CREATE_BUCKET_FACE,
    }
    local APPEARANCE_NAME_TO_CREATE_BUCKET =
    {
        [APPEARANCE_NAME_HAIR_STYLE] = CREATE_BUCKET_FACE,
        [APPEARANCE_NAME_HAIR_TINT] = CREATE_BUCKET_FACE,
        [APPEARANCE_NAME_SKIN_TINT] = CREATE_BUCKET_BODY,
        [APPEARANCE_NAME_ACCESSORY] = CREATE_BUCKET_FACE,
        [APPEARANCE_NAME_HEAD_MARKING] = CREATE_BUCKET_FACE,
        [APPEARANCE_NAME_BODY_MARKING] = CREATE_BUCKET_BODY,
        [APPEARANCE_NAME_EYE_TINT] = CREATE_BUCKET_FACE,
        [APPEARANCE_NAME_AGE] = CREATE_BUCKET_FACE,
        [APPEARANCE_NAME_EYEBROW] = CREATE_BUCKET_FACE,
        [APPEARANCE_NAME_VOICE] = CREATE_BUCKET_FACE,
    }
    local SUBCATEGORY_FOR_SLIDER =
    {
        [SLIDER_NAME_FOREHEAD_SLOPE] = SLIDER_SUBCAT_FACE_FACE,
        [SLIDER_NAME_CHEEK_BONE_SIZE] = SLIDER_SUBCAT_FACE_FACE,
        [SLIDER_NAME_CHEEK_BONE_HEIGHT] = SLIDER_SUBCAT_FACE_FACE,
        [SLIDER_NAME_CHIN_HEIGHT] = SLIDER_SUBCAT_FACE_FACE,
        [SLIDER_NAME_CHIN_SIZE] = SLIDER_SUBCAT_FACE_FACE,
        [SLIDER_NAME_JAW_SIZE] = SLIDER_SUBCAT_FACE_FACE,
        [SLIDER_NAME_NECK_SIZE] = SLIDER_SUBCAT_FACE_FACE,
        [SLIDER_NAME_TOOTH_SIZE] = SLIDER_SUBCAT_FACE_FACE,
        [SLIDER_NAME_NOSE_SHAPE] = SLIDER_SUBCAT_FACE_NOSE,
        [SLIDER_NAME_NOSE_LENGTH] = SLIDER_SUBCAT_FACE_NOSE,
        [SLIDER_NAME_NOSE_HEIGHT] = SLIDER_SUBCAT_FACE_NOSE,
        [SLIDER_NAME_NOSE_WIDTH] = SLIDER_SUBCAT_FACE_NOSE,
        [SLIDER_NAME_EYE_HEIGHT] = SLIDER_SUBCAT_FACE_EYES,
        [SLIDER_NAME_EYE_SIZE] = SLIDER_SUBCAT_FACE_EYES,
        [SLIDER_NAME_EYE_SEPARATION] = SLIDER_SUBCAT_FACE_EYES,
        [SLIDER_NAME_EYE_ANGLE] = SLIDER_SUBCAT_FACE_EYES,
        [SLIDER_NAME_EYE_SQUINT] = SLIDER_SUBCAT_FACE_EYES,
        [SLIDER_NAME_MOUTH_HEIGHT] = SLIDER_SUBCAT_FACE_MOUTH,
        [SLIDER_NAME_MOUTH_WIDTH] = SLIDER_SUBCAT_FACE_MOUTH,
        [SLIDER_NAME_LIP_FULLNESS] = SLIDER_SUBCAT_FACE_MOUTH,
        [SLIDER_NAME_MOUTH_CURVE] = SLIDER_SUBCAT_FACE_MOUTH,
        [SLIDER_NAME_EAR_HEIGHT] = SLIDER_SUBCAT_FACE_EARS,
        [SLIDER_NAME_EAR_SIZE] = SLIDER_SUBCAT_FACE_EARS,
        [SLIDER_NAME_EAR_TIP_FLARE] = SLIDER_SUBCAT_FACE_EARS,
        [SLIDER_NAME_EAR_ROTATION] = SLIDER_SUBCAT_FACE_EARS,
        [SLIDER_NAME_EYEBROW_HEIGHT] = SLIDER_SUBCAT_FACE_BROW,
        [SLIDER_NAME_EYEBROW_ANGLE] = SLIDER_SUBCAT_FACE_BROW,
        [SLIDER_NAME_EYEBROW_SKEW] = SLIDER_SUBCAT_FACE_BROW,
        [SLIDER_NAME_EYEBROW_DEPTH] = SLIDER_SUBCAT_FACE_BROW,
        [SLIDER_NAME_LEG_SIZE] = SLIDER_SUBCAT_BODY_LOWER,
        [SLIDER_NAME_HIP_SIZE] = SLIDER_SUBCAT_BODY_LOWER,
    
        [SLIDER_NAME_FOOT_SIZE] = SLIDER_SUBCAT_BODY_LOWER,
        [SLIDER_NAME_BUTTOCKS_SIZE] = SLIDER_SUBCAT_BODY_LOWER,
        [SLIDER_NAME_TAIL_SIZE] = SLIDER_SUBCAT_BODY_LOWER,
        [SLIDER_NAME_TORSO_SIZE] = SLIDER_SUBCAT_BODY_UPPER,
        [SLIDER_NAME_HAND_SIZE] = SLIDER_SUBCAT_BODY_UPPER,
        [SLIDER_NAME_GUT_SIZE] = SLIDER_SUBCAT_BODY_UPPER,
        [SLIDER_NAME_ARM_SIZE] = SLIDER_SUBCAT_BODY_UPPER,
        [SLIDER_NAME_CHEST_SIZE] = SLIDER_SUBCAT_BODY_UPPER,
        [SLIDER_NAME_WAIST_SIZE] = SLIDER_SUBCAT_BODY_UPPER,
        [SLIDER_NAME_CHARACTER_HEIGHT] = SLIDER_SUBCAT_BODY_TYPE,
    }
    local SUBCATEGORY_FOR_APPEARANCE =
    {
        [APPEARANCE_NAME_HAIR_STYLE] = SLIDER_SUBCAT_FACE_HAIR,
        [APPEARANCE_NAME_HAIR_TINT] = SLIDER_SUBCAT_FACE_HAIR,
        [APPEARANCE_NAME_ACCESSORY] = SLIDER_SUBCAT_FACE_FEATURES,
        [APPEARANCE_NAME_HEAD_MARKING] = SLIDER_SUBCAT_FACE_FEATURES,
        [APPEARANCE_NAME_AGE] = SLIDER_SUBCAT_FACE_FEATURES,
        [APPEARANCE_NAME_BODY_MARKING] = SLIDER_SUBCAT_BODY_FEATURES,
        [APPEARANCE_NAME_SKIN_TINT] = SLIDER_SUBCAT_BODY_FEATURES,
        [APPEARANCE_NAME_EYE_TINT] = SLIDER_SUBCAT_FACE_EYES,
        [APPEARANCE_NAME_EYEBROW] = SLIDER_SUBCAT_FACE_BROW,
        [APPEARANCE_NAME_VOICE] = SLIDER_SUBCAT_VOICE,
    }
    local function UpdateSlider(slider)
        slider.sliderObject:Update()
    end
    function ZO_CharacterCreate_Keyboard:ResetControls()
        -- If this was being suppressed changes MUST be applied now or there will be no slider data to build
        SetSuppressCharacterChanges(false)
        self.sliderManager:ReleaseAllObjects()
        KEYBOARD_BUCKET_MANAGER:Reset()
        KEYBOARD_BUCKET_MANAGER:AddSubCategories()
        KEYBOARD_BUCKET_MANAGER:AddControl(self.genderSelectionControl, CREATE_BUCKET_RACE, function() self:UpdateGenderControl() end)
        KEYBOARD_BUCKET_MANAGER:AddControl(self.raceSelectionControl, CREATE_BUCKET_RACE, function() self:UpdateRaceControl() end)
        KEYBOARD_BUCKET_MANAGER:AddControl(self.classSelectionControl, CREATE_BUCKET_CLASS, function() self:UpdateClassControl() end)
        KEYBOARD_BUCKET_MANAGER:AddControl(self.physiqueTriangleControl, CREATE_BUCKET_BODY, UpdateSlider, RandomizeSlider, SLIDER_SUBCAT_BODY_TYPE)
        KEYBOARD_BUCKET_MANAGER:AddControl(self.faceTriangleControl, CREATE_BUCKET_FACE, UpdateSlider, RandomizeSlider, SLIDER_SUBCAT_FACE_TYPE)
        local _, physiqueIsLocked = ZO_CHARACTERCREATE_MANAGER:GetCharacterUnsavedSetting("triangle", "physique")
        if physiqueIsLocked ~= nil then
            self.physiqueTriangle:SetLocked(physiqueIsLocked)
        end
        local _, faceIsLocked = ZO_CHARACTERCREATE_MANAGER:GetCharacterUnsavedSetting("triangle", "face")
        if faceIsLocked ~= nil then
            self.faceTriangle:SetLocked(faceIsLocked)
        end
        -- TODO: this fixes a bug where the triangles don't reflect the correct data...there will be more fixes to pregameCharacterManager to address the real issue
        -- (where the triangle data needs to live on its own rather than being tied to the unit)
        self.physiqueTriangle:Update()
        self.faceTriangle:Update()
        self.controlsByNameCategory = {}
        local sliderData = {}
        for i = 1, GetNumSliders() do
            local name, category, steps, value, defaultValue = GetSliderInfo(i)
            if name then
                local slider = self.sliderManager:AcquireObject(CHARACTER_CREATE_SLIDER_TYPE_SLIDER)
                local unsavedValue, unsavedIsLocked = ZO_CHARACTERCREATE_MANAGER:GetCharacterUnsavedSetting(name, category)
                if unsavedValue and unsavedIsLocked then
                    slider:SetLocked(unsavedIsLocked)
                end
                slider:SetData(i, name, category, steps, unsavedValue or value, defaultValue)
                local bucket = SLIDER_CATEGORY_TO_CREATE_BUCKET[category]
                local subCat = SUBCATEGORY_FOR_SLIDER[name]
                sliderData[#sliderData + 1] =
                {
                    bucket = bucket,
                    subCat = subCat,
                    name = name,
                    control = slider.control,
                }
                if not self.controlsByNameCategory[name] then
                    self.controlsByNameCategory[name] = {}
                end
                self.controlsByNameCategory[name][category] = slider
            end
        end
        for i = 1, GetNumAppearances() do
            local appearanceName, appearanceType, numValues, displayName = GetAppearanceInfo(i)
            if numValues > 0 then
                local appearanceSlider = self.sliderManager:AcquireObject(appearanceType)
                local unsavedValue, unsavedIsLocked = ZO_CHARACTERCREATE_MANAGER:GetCharacterUnsavedSetting(appearanceName, appearanceType)
                if unsavedValue and unsavedIsLocked then
                    appearanceSlider:SetLocked(unsavedIsLocked)
                end
                appearanceSlider:SetData(appearanceName, numValues, displayName)
                local bucket = APPEARANCE_NAME_TO_CREATE_BUCKET[appearanceName]
                local subCat = SUBCATEGORY_FOR_APPEARANCE[appearanceName]
                sliderData[#sliderData + 1] =
                {
                    bucket = bucket,
                    subCat = subCat,
                    name = appearanceName,
                    control = appearanceSlider.control,
                }
                if not self.controlsByNameCategory[appearanceName] then
                    self.controlsByNameCategory[appearanceName] = {}
                end
                self.controlsByNameCategory[appearanceName][appearanceType] = appearanceSlider
            end
        end
        table.sort(sliderData, SliderComparator)
        for _, orderingData in ipairs(sliderData) do
            KEYBOARD_BUCKET_MANAGER:AddControl(orderingData.control, orderingData.bucket, UpdateSlider, RandomizeSlider, orderingData.subCat)
        end
        KEYBOARD_BUCKET_MANAGER:RemoveUnusedSubCategories()
        KEYBOARD_BUCKET_MANAGER:SwitchBuckets(CREATE_BUCKET_RACE)
        local appearanceControlsEnabled = self:DoesCurrentCharacterCreateModeAllowAppearanceChange()
        KEYBOARD_BUCKET_MANAGER:EnableBucketTab(CREATE_BUCKET_BODY, appearanceControlsEnabled)
        KEYBOARD_BUCKET_MANAGER:EnableBucketTab(CREATE_BUCKET_FACE, appearanceControlsEnabled)
        
        local classControlsEnabled = self:DoesCurrentCharacterCreateModeAllowClassChange()
        KEYBOARD_BUCKET_MANAGER:EnableBucketTab(CREATE_BUCKET_CLASS, classControlsEnabled)
        -- Update Gender Text
        self:UpdateGenderSpecificText()
    end
end
function ZO_CharacterCreate_Keyboard:ResetNameEdit()
    local nameEdit = self.nameControl
    nameEdit:TakeFocus() -- Fix an issue where the animated name text wouldn't display
    nameEdit:SetText("")
    nameEdit:LoseFocus()
    self.nameControl:GetNamedChild("Instructions"):SetHidden(false)
end
function ZO_CharacterCreate_Keyboard:Reset()
    -- Sanity check
    if not IsPregameCharacterConstructionReady() then
        return
    end
    SetCharacterCameraZoomAmount(-1) -- zoom all the way out when a reset happens
    SetSuppressCharacterChanges(true) -- this will be disabled later, right before controls are reset
    self:ResetNameEdit()
    local controlsInitialized = false
    local characterMode = ZO_CHARACTERCREATE_MANAGER:GetCharacterMode()
    if characterMode == CHARACTER_MODE_CREATION then
        self:InitializeTemplateList()
        -- assume that we have already initialized the controls because we have set the default template
        controlsInitialized = true
        local defaultTemplate = GetDefaultTemplate()
        if defaultTemplate == 0 then
            -- default template was undefined so see if we generated a new random character
            controlsInitialized = self:GenerateRandomCharacter()
        end
    end
    if not controlsInitialized then
        self:ResetControls()
    end
    KEYBOARD_BUCKET_MANAGER:SwitchBuckets(CREATE_BUCKET_RACE)
    KEYBOARD_BUCKET_MANAGER:UpdateControlsFromData()
    self.characterStartLocation = nil
    ZO_CHARACTERCREATE_MANAGER:SetShouldPromptForTutorialSkip(true)
    self.characterCreateOption = CHARACTER_CREATE_DEFAULT_LOCATION
end
function ZO_CharacterCreate_Keyboard:UpdateGenderSpecificText(currentGender)
    local characterMode = ZO_CHARACTERCREATE_MANAGER:GetCharacterMode()
    currentGender = currentGender or CharacterCreateGetGender(characterMode)
    self.raceSelectionControl:GetNamedChild("Name"):SetText(zo_strformat(SI_RACE_NAME, GetRaceName(currentGender, CharacterCreateGetRace(characterMode))))
    self.classSelectionControl:GetNamedChild("Name"):SetText(zo_strformat(SI_CLASS_NAME, GetClassName(currentGender, CharacterCreateGetClass(characterMode))))
end
function ZO_CharacterCreate_Keyboard:UpdateRaceControl()
    local characterMode = ZO_CHARACTERCREATE_MANAGER:GetCharacterMode()
    local currentRace = CharacterCreateGetRace(characterMode)
    local function IsRaceClicked(button)
        return button.defId == currentRace
    end
    self.raceRadioGroup:UpdateFromData(IsRaceClicked)
    local currentAlliance = CharacterCreateGetAlliance(characterMode)
    local function IsAllianceClicked(button)
        return button.defId == currentAlliance
    end
    self.allianceRadioGroup:UpdateFromData(IsAllianceClicked)
    local race = self.characterData:GetRaceForRaceDef(currentRace)
    if race then
        local allianceName, backdropTop, backdropBottom = self:GetCurrentAllianceData()
        self:UpdateGenderSpecificText()
        self.raceSelectionControl:GetNamedChild("Alliance"):SetText(zo_strformat(SI_ALLIANCE_NAME, allianceName))
        self.raceSelectionControl:GetNamedChild("Description"):SetText(race.lore)
        self.raceSelectionControl:GetNamedChild("AllianceBG"):SetTexture(backdropTop)
        self.raceSelectionControl:GetNamedChild("AllianceBGBottom"):SetTexture(backdropBottom)
    end
end
function ZO_CharacterCreate_Keyboard:UpdateGenderControl()
    local characterMode = ZO_CHARACTERCREATE_MANAGER:GetCharacterMode()
    local currentGender = CharacterCreateGetGender(characterMode)
    local function IsGenderClicked(button)
        return button.gender == currentGender
    end
    self.genderRadioGroup:UpdateFromData(IsGenderClicked)
end
function ZO_CharacterCreate_Keyboard:UpdateClassControl()
    local characterMode = ZO_CHARACTERCREATE_MANAGER:GetCharacterMode()
    local currentClass = CharacterCreateGetClass(characterMode)
    local function IsClassClicked(button)
        return button.defId == currentClass
    end
    self.classRadioGroup:UpdateFromData(IsClassClicked)
    local class = self.characterData:GetClassForClassDef(currentClass)
    if class then
        self:UpdateGenderSpecificText()
        self.classSelectionControl:GetNamedChild("Description"):SetText(class.lore)
    end
end
function ZO_CharacterCreate_Keyboard:OnGenerateRandomCharacter()
end
function ZO_CharacterCreate_Keyboard:CreateCharacter(startLocation, createOption)
    self.characterName = self.nameControl:GetText()
    ZO_CharacterCreate_Base.CreateCharacter(self, startLocation, createOption)
end
function ZO_CharacterCreate_Keyboard:OnCreateButtonClicked(startLocation)
    local characterName = self.nameControl:GetText()
    if characterName and #characterName > 0 then
        if ZO_CHARACTERCREATE_MANAGER:GetShouldPromptForTutorialSkip() and CanSkipTutorialArea() and startLocation ~= CHARACTER_OPTION_CLEAN_TEST_AREA and startLocation ~= "CharacterSelect_FromIngame" then
            ZO_CHARACTERCREATE_MANAGER:SetShouldPromptForTutorialSkip(false)
            -- color the character name white so it's highlighted in the dialog
            local characterMode = ZO_CHARACTERCREATE_MANAGER:GetCharacterMode()
            local genderDecoratedCharacterName = ZO_SELECTED_TEXT:Colorize(GetGrammarDecoratedName(characterName, CharacterCreateGetGender(characterMode)))
            ZO_Dialogs_ShowDialog("CHARACTER_CREATE_SKIP_TUTORIAL", { startLocation = startLocation }, {mainTextParams = { genderDecoratedCharacterName }})
        else
            self:CreateCharacter(startLocation, self.characterCreateOption)
        end
    end
end
function ZO_CharacterCreate_Keyboard:InitializeForEditChanges(characterInfo, mode)
    local raceTemplate = characterInfo
    if mode == CHARACTER_CREATE_MODE_EDIT_RACE then
        raceTemplate =
        {
            race = 0,
            alliance = characterInfo.alliance,
        }
    end
    local genderTemplate =
    {
        gender = GENDER_NEUTER
    }
    local allianceTemplate = characterInfo
    if mode == CHARACTER_CREATE_MODE_EDIT_ALLIANCE then
        allianceTemplate =
        {
            alliance = ALLIANCE_NONE,
        }
        genderTemplate = characterInfo
    end
    self:UpdateGenderSelectorsForTemplate(genderTemplate)
    self:UpdateSelectorsForTemplate(function(...) return self:UpdateRaceSelectorsForTemplate(...) end, self.characterData:GetRaceInfo(), raceTemplate, self.raceRadioGroup)
    self:UpdateSelectorsForTemplate(function(...) return self:UpdateClassSelectorsForTemplate(...) end, self.characterData:GetClassInfo(), characterInfo, self.classRadioGroup)
    self:UpdateSelectorsForTemplate(function(...) return self:UpdateAllianceSelectorsForTemplate(...) end, self.characterData:GetAllianceInfo(), allianceTemplate, self.allianceRadioGroup)
    self:Reset()
    local appearanceControlsEnabled = self:DoesCurrentCharacterCreateModeAllowAppearanceChange()
    ZO_CharacterCreateRandomizeAppearance:SetEnabled(appearanceControlsEnabled)
    self.templateControl:SetHidden(true)
    local name = zo_strformat(SI_CHARACTER_SELECT_NAME, characterInfo.name)
    self.nameControl:SetText(name)
    self.nameControl:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGB())
    self.nameControl:GetNamedChild("Instructions"):SetHidden(true)
    self.nameControl:SetEditEnabled(false)
    self.nameControl:SetMouseEnabled(false)
    self.saveButton:SetHidden(false)
    self.createButton:SetHidden(true)
end
function ZO_CharacterCreate_Keyboard:InitializeForCharacterCreate()
    self:SetCharacterCreateMode(CHARACTER_CREATE_MODE_CREATE)
    local characterMode = ZO_CHARACTERCREATE_MANAGER:GetCharacterMode()
    local templateData = self.characterData:GetTemplate(CharacterCreateGetTemplate(characterMode))
    -- we may not have any template selected or we have no templates
    -- so create a default template with no restrictions
    if templateData == nil then
        templateData = self.characterData:GetNoneTemplate()
    end
    ZO_CharacterCreateRandomizeAppearance:SetEnabled(true)
    self:UpdateGenderSelectorsForTemplate(templateData)
    self:UpdateSelectorsForTemplate(function(...) return self:UpdateRaceSelectorsForTemplate(...) end, self.characterData:GetRaceInfo(), templateData, self.raceRadioGroup)
    self:UpdateSelectorsForTemplate(function(...) return self:UpdateClassSelectorsForTemplate(...) end, self.characterData:GetClassInfo(), templateData, self.classRadioGroup)
    self.characterData:UpdateAllianceSelectability()
    self:UpdateSelectorsForTemplate(function(...) return self:UpdateAllianceSelectorsForTemplate(...) end, self.characterData:GetAllianceInfo(), templateData, self.allianceRadioGroup)
    self.nameControl:SetEditEnabled(true)
    self.nameControl:SetMouseEnabled(true)
    self.nameControl:SetColor(ZO_NORMAL_TEXT:UnpackRGB())
    self.saveButton:SetHidden(true)
    self.createButton:SetHidden(false)
    local currentAlliance = CharacterCreateGetAlliance(characterMode)
end
function ZO_CharacterCreate_Keyboard:UpdateGenderSelectorsForTemplate(templateData)
    for button in self.genderRadioGroup:IterateButtons() do
        local enabled = templateData.gender == GENDER_NEUTER or templateData.gender == button.gender
        self:SetSelectorButtonEnabled(button, self.genderRadioGroup, enabled)
    end
end
function ZO_CharacterCreate_Keyboard:ClickGenderButton(genderButton)
    self.genderRadioGroup:SetClickedButton(genderButton)
end
--
--[[ XML Handlers and global functions ]]--
--
function ZO_CharacterCreate_RandomizeAppearance(randomizeType)
    KEYBOARD_BUCKET_MANAGER:RandomizeAppearance(randomizeType)
end
    -- If a button is disabled, add any disable reasons to the tooltip
    if control:GetState() == BSTATE_DISABLED or control:GetState() == BSTATE_DISABLED_PRESSED then
        InitializeTooltip(InformationTooltip, control, BOTTOM, 0, -5, TOP)
        -- Check if disabled due to a barbershop mode
        local characterCreateMode = KEYBOARD_CHARACTER_CREATE_MANAGER:GetCharacterCreateMode()
        if characterCreateMode ~= CHARACTER_CREATE_MODE_CREATE then
            local tokenType = KEYBOARD_CHARACTER_CREATE_MANAGER:GetTokenTypeForCharacterCreateMode(characterCreateMode)
            local tokenString = GetString("SI_SERVICETOKENTYPE", tokenType)
            InformationTooltip:AddLine(zo_strformat(SI_CREATE_CHARACTER_SELECTOR_TOKEN_DISABLED, tokenString), "", ZO_NORMAL_TEXT:UnpackRGB())
        end
    end
end
    ClearTooltip(InformationTooltip)
end
    KEYBOARD_CHARACTER_CREATE_MANAGER = ZO_CharacterCreate_Keyboard:New(control)
    SYSTEMS:RegisterKeyboardObject(ZO_CHARACTER_CREATE_SYSTEM_NAME, KEYBOARD_CHARACTER_CREATE_MANAGER)
    KEYBOARD_BUCKET_MANAGER = ZO_CharacterCreateBucketManager_Keyboard:New(ZO_CharacterCreateBuckets)
end
    ZO_Dialogs_RegisterCustomDialog("CHARACTER_CREATE_SKIP_TUTORIAL",
    {
        customControl = control,
        canQueue = true,
        title =
        {
            text = SI_PROMPT_TITLE_SKIP_TUTORIAL,
        },
        mainText = 
        {
            text = SI_PROMPT_BODY_SKIP_TUTORIAL,
        },
        noChoiceCallback = function(dialog)
            ZO_CHARACTERCREATE_MANAGER:SetShouldPromptForTutorialSkip(true)
        end,
        buttons =
        {
            {
                control = control:GetNamedChild("Play"),
                text = SI_PROMPT_PLAY_TUTORIAL_BUTTON,
                keybind = "DIALOG_PRIMARY",
                callback = function(dialog)
                    KEYBOARD_CHARACTER_CREATE_MANAGER:CreateCharacter(dialog.data.startLocation, CHARACTER_CREATE_DEFAULT_LOCATION)
                end,
            },
            {
                control = control:GetNamedChild("Skip"),
                text = SI_PROMPT_SKIP_TUTORIAL_BUTTON,
                keybind = "DIALOG_SECONDARY",
                callback = function(dialog)
                    KEYBOARD_CHARACTER_CREATE_MANAGER:CreateCharacter(dialog.data.startLocation, CHARACTER_CREATE_SKIP_TUTORIAL)
                end,
            },
            {
                control = control:GetNamedChild("Back"),
                text = SI_PROMPT_BACK_TUTORIAL_BUTTON,
                keybind = "DIALOG_NEGATIVE",
                callback = function(dialog)
                    ZO_CHARACTERCREATE_MANAGER:SetShouldPromptForTutorialSkip(true)
                end,
            },
        }
    })
end
    KEYBOARD_CHARACTER_CREATE_MANAGER:OnCreateButtonClicked(startLocation)
end
    KEYBOARD_CHARACTER_CREATE_MANAGER:SaveCharacterChanges()
end
local function ValidateNameText(editControl)
    local nameText = editControl:GetText()
    local nameViolations = { IsValidCharacterName(nameText) }
    local nameIsValid = (#nameViolations == 0)
    if nameIsValid then
        editControl:SetColor(GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, INTERFACE_TEXT_COLOR_NORMAL))
    else
        editControl:SetColor(GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, INTERFACE_TEXT_COLOR_FAILED))
    end
    local oldPos = editControl:GetCursorPosition()
    editControl:SetText(CorrectCharacterNameCase(nameText))
    editControl:SetCursorPosition(oldPos)
    return nameIsValid, nameViolations
end
    -- Validation changes the text in the edit control, which causes this to be called again, bail if we're already validating to avoid recursion.
    if editControl.validating then
        return
    end
    editControl.validating = true
    local isValidName, nameViolations = ValidateNameText(editControl)
    if isValidName then
        editControl.linkedButton:SetState(BSTATE_NORMAL, false)
        editControl.linkedInstructions:Hide()
    else
        editControl.linkedButton:SetState(BSTATE_DISABLED, true)
        if editControl:HasFocus() then
            editControl.linkedInstructions:Show(editControl, nameViolations)
        else
            editControl.linkedInstructions:Hide()
        end
    end
    CALLBACK_MANAGER:FireCallbacks("OnCharacterCreateNameChanged", isValidName)
    editControl.validating = nil
end
    editControl:GetNamedChild("Instructions"):SetHidden(true)
    if WINDOW_MANAGER:IsHandlingHardwareEvent() then
        PlaySound(SOUNDS.EDIT_CLICK)
    end
end
    if #editControl:GetText() == 0 then
        editControl:GetNamedChild("Instructions"):SetHidden(false)
    end
    editControl.linkedInstructions:Hide()
end
do
    local SELECTOR_CLICK_HANDLERS =
    {
        [CHARACTER_CREATE_SELECTOR_RACE] = function(button)
            KEYBOARD_CHARACTER_CREATE_MANAGER:SetRace(button.defId)
            KEYBOARD_CHARACTER_CREATE_MANAGER:UpdateRaceControl()
        end,
        [CHARACTER_CREATE_SELECTOR_CLASS] = function(button)
            KEYBOARD_CHARACTER_CREATE_MANAGER:SetClass(button.defId)
            KEYBOARD_CHARACTER_CREATE_MANAGER:UpdateClassControl()
        end,
        [CHARACTER_CREATE_SELECTOR_ALLIANCE] = function(button)
            KEYBOARD_CHARACTER_CREATE_MANAGER:SetAlliance(button.defId)
            KEYBOARD_CHARACTER_CREATE_MANAGER:UpdateRaceControl()
        end,
        [CHARACTER_CREATE_SELECTOR_GENDER] = function(button)
            KEYBOARD_CHARACTER_CREATE_MANAGER:SetGender(button.gender)
        end,
    }
        local clickHandler = SELECTOR_CLICK_HANDLERS[button.selectorType]
        if clickHandler then
            OnCharacterCreateOptionChanged()
            clickHandler(button)
        end
    end
end
    InitializeTooltip(InformationTooltip, button, TOPRIGHT, 0, 0, TOPLEFT)
    if button.name then
        SetTooltipText(InformationTooltip, zo_strformat(button.tooltipFormatter, button.name))
    elseif button.nameFn then
        local characterMode = ZO_CHARACTERCREATE_MANAGER:GetCharacterMode()
        SetTooltipText(InformationTooltip, zo_strformat(button.tooltipFormatter, button.nameFn(CharacterCreateGetGender(characterMode), button.defId)))
    end
    -- If a button is disabled, add any disable reasons to the tooltip
    if button:GetState() == BSTATE_DISABLED or button:GetState() == BSTATE_DISABLED_PRESSED then
        -- Check if disabled due to a barbershop mode
        local characterCreateMode = KEYBOARD_CHARACTER_CREATE_MANAGER:GetCharacterCreateMode()
        if characterCreateMode ~= CHARACTER_CREATE_MODE_CREATE then
            local selectorType = button.selectorType
            local addDisableReason = false
            local tokenType = KEYBOARD_CHARACTER_CREATE_MANAGER:GetTokenTypeForCharacterCreateMode(characterCreateMode)
            if tokenType == SERVICE_TOKEN_APPEARANCE_CHANGE then
                addDisableReason = selectorType == CHARACTER_CREATE_SELECTOR_RACE or selectorType == CHARACTER_CREATE_SELECTOR_CLASS or selectorType == CHARACTER_CREATE_SELECTOR_ALLIANCE
            elseif tokenType == SERVICE_TOKEN_RACE_CHANGE then
                addDisableReason = selectorType == CHARACTER_CREATE_SELECTOR_CLASS or selectorType == CHARACTER_CREATE_SELECTOR_ALLIANCE
            elseif tokenType == SERVICE_TOKEN_ALLIANCE_CHANGE then
                addDisableReason = selectorType == CHARACTER_CREATE_SELECTOR_RACE or selectorType == CHARACTER_CREATE_SELECTOR_CLASS or selectorType == CHARACTER_CREATE_SELECTOR_GENDER
            end
            if addDisableReason then
                local tokenString = GetString("SI_SERVICETOKENTYPE", tokenType)
                InformationTooltip:AddLine(zo_strformat(SI_CREATE_CHARACTER_SELECTOR_TOKEN_DISABLED, tokenString), "", ZO_NORMAL_TEXT:UnpackRGB())
            end
        end
        local raceSelector = button.selectorType == CHARACTER_CREATE_SELECTOR_RACE
        local classSelector = button.selectorType == CHARACTER_CREATE_SELECTOR_CLASS
        -- Check for race/class specific disable reasons
        if raceSelector or classSelector then
            local restrictionReasonFunction = raceSelector and GetRaceRestrictionReason or GetClassRestrictionReason
            local restrictionReason, restrictingCollectible = restrictionReasonFunction(button.defId)
            local restrictionString = ZO_CHARACTERCREATE_MANAGER.GetOptionRestrictionString(restrictionReason, restrictingCollectible)
            if restrictionString ~= "" then
                InformationTooltip:AddLine(restrictionString, "", ZO_NORMAL_TEXT:UnpackRGB())
                if restrictingCollectible ~= 0 and IsCollectiblePurchasable(restrictingCollectible) then
                    InformationTooltip:AddLine(GetString(SI_CHARACTER_CREATE_RESTRICTION_COLLECTIBLE_PURCHASABLE), "", ZO_NORMAL_TEXT:UnpackRGB())
                end
            end
        end
    end
end
    ClearTooltip(InformationTooltip)
end
    local characterCreateMode = KEYBOARD_CHARACTER_CREATE_MANAGER:GetCharacterCreateMode()
    if characterCreateMode == CHARACTER_CREATE_MODE_EDIT_ALLIANCE then
        if button:GetState() == BSTATE_DISABLED or button:GetState() == BSTATE_DISABLED_PRESSED then
            InitializeTooltip(InformationTooltip, button, TOPRIGHT, 0, 0, TOPLEFT)
            local tokenString = GetString("SI_SERVICETOKENTYPE", SERVICE_TOKEN_ALLIANCE_CHANGE)
            InformationTooltip:AddLine(zo_strformat(SI_CREATE_CHARACTER_SELECTOR_TOKEN_DISABLED, tokenString), "", ZO_NORMAL_TEXT:UnpackRGB())
        end
    end
end
    ClearTooltip(InformationTooltip)
end
function ZO_CharacterCreateGenderSelectorLabel_OnMouseClicked(label, mouseButton, upInside)
    if mouseButton == MOUSE_BUTTON_INDEX_LEFT and upInside then
        local genderButton = label:GetParent():GetNamedChild("Button")
        KEYBOARD_CHARACTER_CREATE_MANAGER:ClickGenderButton(genderButton)
    end
end
function ZO_CharacterCreate_ChangeSlider(slider, changeAmount)
    slider:GetParent().sliderObject:ChangeValue(changeAmount)
end
function ZO_CharacterCreate_ChangePanel(direction)
    local currentTab = KEYBOARD_BUCKET_MANAGER:GetCurrentTab()
    if currentTab then
        KEYBOARD_BUCKET_MANAGER:SwitchBuckets(currentTab.windowData[direction])
    end
end
function ZO_CharacterCreate_PreviewClicked(previewButton)
    local slider = previewButton:GetParent()
    slider.sliderObject:Preview()
end
    --While we need a mouse down over the paper doll area to start spinning, the mouse up may not be delivered to this same control. If we press mouse left to start spinning (which starts
    --mouse tracking) then press mouse right this will release mouse left but it won't stop mouse tracking because tracking is locked when the up is delivered. So we catch it on the event instead
    --when tracking isn't locked. ESO-546877
    self:RegisterForEvent(EVENT_GLOBAL_MOUSE_UP, CharacterCreateStopMouseSpin)
end
    self:UnregisterForEvent(EVENT_GLOBAL_MOUSE_UP)
end