Back to Home

ESO Lua File v100032

ingame/crowncrates/crowncratespackchoosing.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
---------------------
--Crown Crates Pack--
---------------------
ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH = 1024
ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT = 1024
ZO_CROWN_CRATES_PACK_TEXTURE_LID_HEIGHT = 44
ZO_CROWN_CRATES_PACK_WIDTH_TO_HEIGHT_RATIO = 1
ZO_CROWN_CRATES_PACK_WIDTH_TO_DEPTH_RATIO = 1
ZO_CROWN_CRATES_PACK_HEIGHT_TO_LID_THICKNESS_RATIO = ZO_CROWN_CRATES_PACK_TEXTURE_LID_HEIGHT / (ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT * 0.5)
ZO_CROWN_CRATES_PACK_WIDTH_WORLD = 0.1
ZO_CROWN_CRATES_PACK_HEIGHT_WORLD = ZO_CROWN_CRATES_PACK_WIDTH_WORLD * ZO_CROWN_CRATES_PACK_WIDTH_TO_HEIGHT_RATIO
ZO_CROWN_CRATES_PACK_DEPTH_WORLD = ZO_CROWN_CRATES_PACK_WIDTH_WORLD * ZO_CROWN_CRATES_PACK_WIDTH_TO_DEPTH_RATIO
ZO_CROWN_CRATES_PACK_LID_THICKNESS_WORLD = ZO_CROWN_CRATES_PACK_HEIGHT_WORLD * ZO_CROWN_CRATES_PACK_HEIGHT_TO_LID_THICKNESS_RATIO
ZO_CROWN_CRATES_PACK_WIDTH_UI = 350
ZO_CROWN_CRATES_PACK_SPACING_UI = 75
ZO_CROWN_CRATES_PACK_OFFSET_Y_UI = 120
ZO_CROWN_CRATES_PACK_PLACEHOLDER_ALPHA = 0.4
ZO_CROWN_CRATES_PACK_NORMAL_ALPHA = 1
ZO_CROWN_CRATES_PACK_FRONT_MOUSE_PLANE_BUFFER_WORLD = 3
ZO_CROWN_CRATES_PACK_COUNT_LABEL_HEIGHT_UI = 42
ZO_CROWN_CRATES_PACK_COUNT_LABEL_INSET_X_PERCENT = 0.1
ZO_CROWN_CRATES_PACK_COUNT_LABEL_INSET_Y_PERCENT = 0.05
ZO_CROWN_CRATES_PACK_SHOW_MOVE_DURATION_MS = 800
ZO_CROWN_CRATES_PACK_SHOW_SPIN_DURATION_MS = 700
ZO_CROWN_CRATES_PACK_SHOW_SPIN_DELAY_MS = 100
ZO_CROWN_CRATES_PACK_SHOW_SPACING_MS = 100
ZO_CROWN_CRATES_PACK_SHOW_START_PITCH_RADIANS = math.rad(160)
ZO_CROWN_CRATES_PACK_SHOW_START_YAW_RADIANS = math.rad(0)
ZO_CROWN_CRATES_PACK_SHOW_START_ROLL_RADIANS = math.rad(0)
ZO_CROWN_CRATES_PACK_SHOW_END_PITCH_RADIANS = math.rad(-15)
ZO_CROWN_CRATES_PACK_SHOW_END_YAW_RADIANS = math.rad(0)
ZO_CROWN_CRATES_PACK_SHOW_END_ROLL_RADIANS = math.rad(0)
ZO_CROWN_CRATES_PACK_SELECTED_PITCH_RADIANS = math.rad(-8)
ZO_CROWN_CRATES_PACK_SELECTED_YAW_RADIANS = math.rad(0)
ZO_CROWN_CRATES_PACK_SELECTED_ROLL_RADIANS = math.rad(0)
ZO_CROWN_CRATES_PACK_SELECTION_DURATION_MS = 300
ZO_CROWN_CRATES_PACK_SELECTION_OFFSET_Y_UI = 40
ZO_CROWN_CRATES_PACK_SHOW_FROM_SIDE_MOVE_DURATION_MS = 500
ZO_CROWN_CRATES_PACK_HIDE_DURATION_MS = 200
ZO_CROWN_CRATES_PACK_HIDE_OFFSET_Y_UI = -40
ZO_CROWN_CRATES_PACK_CHOOSE_MOVE_DURATION_MS = 650
ZO_CROWN_CRATES_PACK_CHOOSE_ROTATE_DURATION_MS = 200
ZO_CROWN_CRATES_PACK_CHOOSE_HIDE_DELAY_MS = 450
ZO_CROWN_CRATES_PACK_CHOOSE_HIDE_DURATION_MS = 300
ZO_CROWN_CRATES_PACK_CHOOSE_OFFSET_Y_UI = 150
ZO_CROWN_CRATES_PACK_CHOOSEN_PITCH_RADIANS = math.rad(-8)
ZO_CROWN_CRATES_PACK_CHOOSEN_YAW_RADIANS = math.rad(0)
ZO_CROWN_CRATES_PACK_CHOOSEN_ROLL_RADIANS = math.rad(0)
ZO_CROWN_CRATES_PACK_OPEN_START_YAW_RADIANS = math.rad(0)
ZO_CROWN_CRATES_PACK_OPEN_END_YAW_RADIANS = math.rad(15)
ZO_CROWN_CRATES_PACK_HIDE_AND_EXIT_SIDE_DURATION_MS = 500
ZO_CROWN_CRATES_PACK_HIDE_AND_EXIT_SIDE_OFFSET_X_UI = -2000
--Show Info
ZO_CROWN_CRATES_PACK_INFO_AREA_HEIGHT_UI = ZO_CROWN_CRATES_PACK_OFFSET_Y_UI
ZO_CROWN_CRATES_PACK_SHOW_INFO_DURATION_MS = 220
--Hide Info
ZO_CROWN_CRATES_PACK_HIDE_INFO_DURATION_MS = 200
--Animations
ZO_CROWN_CRATES_ANIMATION_PACK_SHOW = "packShow"
ZO_CROWN_CRATES_ANIMATION_PACK_SHOW_INFO = "packShowInfo"
ZO_CROWN_CRATES_ANIMATION_PACK_HIDE_INFO = "packHideInfo"
ZO_CROWN_CRATES_ANIMATION_PACK_SELECT = "packSelect"
ZO_CROWN_CRATES_ANIMATION_PACK_DESELECT = "packDeselect"
ZO_CROWN_CRATES_ANIMATION_PACK_GLOW = "packGlow"
ZO_CROWN_CRATES_ANIMATION_PACK_HIDE = "packHide"
ZO_CROWN_CRATES_ANIMATION_PACK_CHOOSE = "packChoose"
ZO_CROWN_CRATES_ANIMATION_PACK_OPEN = "packOpen"
ZO_CROWN_CRATES_ANIMATION_PACK_SHOW_FROM_SIDE = "packShowFromSide"
ZO_CROWN_CRATES_ANIMATION_PACK_HIDE_AND_EXIT_SIDE = "packHideAndExitSide"
ZO_CROWN_CRATES_PAGE_CHANGE_ARROW_OFFSET_X_UI = 50
ZO_CROWN_CRATES_PAGE_LEFT = -1
ZO_CROWN_CRATES_PAGE_RIGHT = 1
ZO_CrownCratesPack = ZO_CrownCratesAnimatable:Subclass()
function ZO_CrownCratesPack:New(...)
    return ZO_CrownCratesAnimatable.New(self, ...)
end
function ZO_CrownCratesPack:Initialize(control, owner)
    local crownCratesManager = owner:GetOwner()
    ZO_CrownCratesAnimatable.Initialize(self, control, crownCratesManager)
    self.stateMachine = owner:GetStateMachine()
    self.control = control
    self.owner = owner
    local box = CreateControl("", control, CT_CONTROL)
    box:Create3DRenderSpace()
    self.box = box
    --Because these textures use the depth buffer and can be transparent the order in which they render matters. If something closer to the camera is drawn
    --before something farther, then the farther plane will not appear under the closer one even if the closer one is transparent. We use this to simplify
    --the look of the transparent box.
    --Lid (Drawn First)
    local lid = owner:CreateRectagularPrism(self.box, ZO_CROWN_CRATES_PACK_WIDTH_WORLD, ZO_CROWN_CRATES_PACK_LID_THICKNESS_WORLD, ZO_CROWN_CRATES_PACK_DEPTH_WORLD, 0.5, 0, 1)
    lid:SetDrawTier(DT_LOW)
    self.lidRootOffsetY = 0.5 * ZO_CROWN_CRATES_PACK_HEIGHT_WORLD - ZO_CROWN_CRATES_PACK_LID_THICKNESS_WORLD
    lid:Set3DRenderSpaceOrigin(0, self.lidRootOffsetY, ZO_CROWN_CRATES_PACK_DEPTH_WORLD * 0.5)
    box.lid = lid
    --Draw the front and top first since they will remove the left/right/back planes from showing.
    lid.front:SetDrawLevel(0)
    lid.top:SetDrawLevel(1)
    lid.left:SetDrawLevel(2)
    lid.right:SetDrawLevel(3)
    lid.bottom:SetDrawLevel(4)
    lid.back:SetDrawLevel(5)
    lid.left:SetTextureCoords(512/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 1024/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 512/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT, (512 + ZO_CROWN_CRATES_PACK_TEXTURE_LID_HEIGHT)/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT)
    lid.front:SetTextureCoords(0/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 512/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 512/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT, (512 + ZO_CROWN_CRATES_PACK_TEXTURE_LID_HEIGHT)/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT)
    lid.right:SetTextureCoords(512/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 1024/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 512/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT, (512 + ZO_CROWN_CRATES_PACK_TEXTURE_LID_HEIGHT)/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT)
    lid.back:SetTextureCoords(0/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 512/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 512/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT, (512 + ZO_CROWN_CRATES_PACK_TEXTURE_LID_HEIGHT)/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT)
    lid.top:SetTextureCoords(0/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 512/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 0/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT, 512/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT)
    lid.bottom:SetTextureCoords(512/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 1024/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 512/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT, 1024/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT)
    
    --Body (Drawn Second)
    local body = owner:CreateRectagularPrism(self.box, ZO_CROWN_CRATES_PACK_WIDTH_WORLD, ZO_CROWN_CRATES_PACK_HEIGHT_WORLD - ZO_CROWN_CRATES_PACK_LID_THICKNESS_WORLD, ZO_CROWN_CRATES_PACK_DEPTH_WORLD, 0.5, 0.5, 0.5)
    body:SetDrawTier(DT_MEDIUM)
    --Draw the front and top first since they will remove the left/right/back planes from showing.
    body.front:SetDrawLevel(0)
    body.top:SetDrawLevel(1)
    body.left:SetDrawLevel(2)
    body.right:SetDrawLevel(3)
    body.bottom:SetDrawLevel(4)
    body.back:SetDrawLevel(5)
    body:Set3DRenderSpaceOrigin(0, -0.5 * ZO_CROWN_CRATES_PACK_LID_THICKNESS_WORLD, 0)
    box.body = body
    body.left:SetTextureCoords(512/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 1024/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, (512 + ZO_CROWN_CRATES_PACK_TEXTURE_LID_HEIGHT)/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT, 1024/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT)
    body.front:SetTextureCoords(0/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 512/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, (512 + ZO_CROWN_CRATES_PACK_TEXTURE_LID_HEIGHT)/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT, 1024/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT)
    body.right:SetTextureCoords(512/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 1024/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, (512 + ZO_CROWN_CRATES_PACK_TEXTURE_LID_HEIGHT)/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT, 1024/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT)
    body.back:SetTextureCoords(0/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 512/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, (512 + ZO_CROWN_CRATES_PACK_TEXTURE_LID_HEIGHT)/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT, 1024/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT)
    body.top:SetTextureCoords(0/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 512/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 0/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT, 512/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT)
    body.bottom:SetTextureCoords(512/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 1024/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 512/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT, 1024/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT)
    --"Shadow" the top surface
    body.top:SetColor(0.35, 0.35, 0.35)
    local glowFront = owner:CreateCenteredFace(body, ZO_CROWN_CRATES_PACK_WIDTH_WORLD, ZO_CROWN_CRATES_PACK_HEIGHT_WORLD - ZO_CROWN_CRATES_PACK_LID_THICKNESS_WORLD)
    local frontOriginX, frontOriginY, frontOriginZ = body.front:Get3DRenderSpaceOrigin()
    glowFront:SetBlendMode(TEX_BLEND_MODE_ADD)
    glowFront:Set3DRenderSpaceOrigin(frontOriginX, frontOriginY, frontOriginZ - 0.0001)
    body.glowFront = glowFront
    body.glowFront:SetTextureCoords(512/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, 1024/ZO_CROWN_CRATES_PACK_TEXTURE_WIDTH, ZO_CROWN_CRATES_PACK_TEXTURE_LID_HEIGHT/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT, 512/ZO_CROWN_CRATES_PACK_TEXTURE_HEIGHT)
    body.glowFront:SetDrawLevel(0)
    --Front Mouse Plane
    local frontMousePlaneHeightWorld = ZO_CROWN_CRATES_PACK_HEIGHT_WORLD + ZO_CROWN_CRATES_PACK_FRONT_MOUSE_PLANE_BUFFER_WORLD
    local frontMousePlane = owner:CreateCenteredFace(box, ZO_CROWN_CRATES_PACK_WIDTH_WORLD, frontMousePlaneHeightWorld)
    frontMousePlane:Set3DRenderSpaceOrigin(frontOriginX, frontOriginY - 0.5 * frontMousePlaneHeightWorld + 0.5 * ZO_CROWN_CRATES_PACK_HEIGHT_WORLD, frontOriginZ)
    frontMousePlane:SetAlpha(0)
    self.frontMousePlane = frontMousePlane
    self.infoControl = control:GetNamedChild("Info")
    self.infoNameLabel = self.infoControl:GetNamedChild("Name")
    frontMousePlane:SetMouseEnabled(true)
    lid.top:SetMouseEnabled(true)
    local function OnMouseEnter()
        owner:PackOnMouseEnter(self)
    end
    local function OnMouseExit()
        owner:PackOnMouseExit(self)
    end
    ZO_CrownCrates.AddBounceResistantMouseHandlersToControl(box, OnMouseEnter, OnMouseExit)    
    self.boxMouseInputGroup = ZO_MouseInputGroup:New(box)
    self.boxMouseInputGroup:Add(frontMousePlane, ZO_MOUSE_INPUT_GROUP_MOUSE_OVER)
    self.boxMouseInputGroup:Add(lid.top, ZO_MOUSE_INPUT_GROUP_MOUSE_OVER)
    --where ... is a list of controls to add the handlers to
    local function AddUpHandler(...)
        local function OnMouseUp() owner:PackOnMouseUp(self) end
        for i = 1, select("#", ...) do
            local control = select(i, ...)
            control:SetHandler("OnMouseUp", OnMouseUp)
        end
    end
    AddUpHandler(frontMousePlane, lid.top)
    self:Reset()
end
do
    local KEYBOARD_STYLE =
    {
        nameFonts =
        {
            {
                font = "ZoFontWinH1",
                lineLimit = 2,
            },
            {
                font = "ZoFontWinH2",
                lineLimit = 2,
            },
            {
                font = "ZoFontWinH3",
                lineLimit = 2,
                dontUseForAdjusting = true,
            },
        },
    }
    local GAMEPAD_STYLE =
    {
        nameFonts =
        {
            {
                font = "ZoFontGamepad42",
                lineLimit = 2,
            },
            {
                font = "ZoFontGamepad36",
                lineLimit = 2,
            },
            {
                font = "ZoFontGamepad34",
                lineLimit = 2,
            },
            {
                font = "ZoFontGamepad27",
                lineLimit = 2,
                dontUseForAdjusting = true,
            },
        },
    }
    function ZO_CrownCratesPack:InitializeStyles()
        ZO_PlatformStyle:New(function(style) self:ApplyStyle(style) end, KEYBOARD_STYLE, GAMEPAD_STYLE)
    end
end
function ZO_CrownCratesPack:ApplyStyle(style)
    ZO_FontAdjustingWrapLabel_OnInitialized(self.infoNameLabel, style.nameFonts, TEXT_WRAP_MODE_ELLIPSIS)
end
function ZO_CrownCratesPack:Reset()
    ZO_CrownCratesAnimatable.Reset(self)
    self.crateId = nil
    self.visualCrateId = nil
    self.visualSlotIndex = nil
    self.control:SetAlpha(1)
    self.infoControl:SetAlpha(0)
    local box = self.box
    box.body.front:SetAlpha(1)
    box.body.glowFront:SetAlpha(0)
    box.lid:Set3DRenderSpaceOrientation(ZO_CROWN_CRATES_PACK_OPEN_START_YAW_RADIANS, 0, 0)
    self.visuallySelected = false
    self.rootX = nil
    self.rootY = nil
    self.rootZ = nil
    self:SetPackMouseEnabled(false)
end
function ZO_CrownCratesPack:InitializeForShow(crateId, visualSlotIndex)
    self:Reset()
    self.crateId = crateId
    local visualCrateId = crateId
    if not visualCrateId then
        visualCrateId = GetOnSaleCrownCrateId()
    end
    self.visualCrateId = visualCrateId
    self.visualSlotIndex = visualSlotIndex
    local isPlaceholderCrate = self:IsPlaceholderCrate()
    if visualCrateId then
        local normalTexture = GetCrownCratePackNormalTexture(visualCrateId)
        local box = self.box
        box:SetAlpha(isPlaceholderCrate and ZO_CROWN_CRATES_PACK_PLACEHOLDER_ALPHA or ZO_CROWN_CRATES_PACK_NORMAL_ALPHA)
        local body = box.body
        body.front:SetTexture(normalTexture)
        body.glowFront:SetTexture(normalTexture)
        body.back:SetTexture(normalTexture)
        body.left:SetTexture(normalTexture)
        body.right:SetTexture(normalTexture)
        body.top:SetTexture(normalTexture)
        body.bottom:SetTexture(normalTexture)
        local lid = box.lid
        lid.front:SetTexture(normalTexture)
        lid.back:SetTexture(normalTexture)
        lid.left:SetTexture(normalTexture)
        lid.right:SetTexture(normalTexture)
        lid.top:SetTexture(normalTexture)
        lid.bottom:SetTexture(normalTexture)
    end
    if isPlaceholderCrate then
        self.infoNameLabel:SetHidden(true)
    else
        self.infoNameLabel:SetHidden(false)
        local crateName = GetCrownCrateName(crateId)
        local crateCount = GetCrownCrateCount(crateId)
        if crateCount > 1 then
            self.infoNameLabel:SetText(zo_strformat(SI_CROWN_CRATE_PACK_WITH_STACK_NAME, crateName, crateCount))
        else
            self.infoNameLabel:SetText(zo_strformat(SI_CROWN_CRATE_PACK_NAME, crateName))
        end
    end
end
function ZO_CrownCratesPack:IsPlaceholderCrate()
    return self.crateId == nil
end
function ZO_CrownCratesPack:GetCrownCrateId()
    return self.crateId
end
function ZO_CrownCratesPack:IsSelected()
    return self.owner:GetSelectedPack() == self
end
function ZO_CrownCratesPack:OnSelect()
    if self:CanSelect() then
        self:Select()
    end
end
function ZO_CrownCratesPack:OnDeselect()
    if self:CanSelect() then
        self:Deselect()
    end
end
function ZO_CrownCratesPack:CanSelect()
    return self.stateMachine:IsCurrentState("MANIFEST")
end
function ZO_CrownCratesPack:SetPackMouseEnabled(enabled)
    self.frontMousePlane:SetMouseEnabled(enabled)
    self.box.lid.top:SetMouseEnabled(enabled)
end
function ZO_CrownCratesPack:Show(startX, startY, startZ, endX, endY, endZ)
    self.control:SetHidden(false)
    self.control:Set3DRenderSpaceOrientation(ZO_CROWN_CRATES_PACK_SHOW_START_PITCH_RADIANS, ZO_CROWN_CRATES_PACK_SHOW_START_YAW_RADIANS, ZO_CROWN_CRATES_PACK_SHOW_START_ROLL_RADIANS)
    local animationTimeline = self:AcquireAndApplyAnimationTimeline(ZO_CROWN_CRATES_ANIMATION_PACK_SHOW, self.control, function(timeline, completedPlaying)
        if completedPlaying then
            self.owner:OnManifestPackInComplete()
            --Mouse input on the crate is not enabled until it is finished showing. This will prevent the case where the mouse enters the
            --crate and then exits it again as it flips and then enters once more but we suppress the enter because of the bounce prevention logic.
            self:SetPackMouseEnabled(true)
        end
    end)
    local translateAnimation = animationTimeline:GetAnimation(1)
    translateAnimation:SetTranslateOffsets(startX, startY, startZ, endX, endY, endZ)
    local rotateAnimation = animationTimeline:GetAnimation(2)
    rotateAnimation:SetRotationValues(ZO_CROWN_CRATES_PACK_SHOW_START_PITCH_RADIANS, ZO_CROWN_CRATES_PACK_SHOW_START_YAW_RADIANS, ZO_CROWN_CRATES_PACK_SHOW_START_ROLL_RADIANS,
        ZO_CROWN_CRATES_PACK_SHOW_END_PITCH_RADIANS, ZO_CROWN_CRATES_PACK_SHOW_END_YAW_RADIANS, ZO_CROWN_CRATES_PACK_SHOW_END_ROLL_RADIANS)
    self:StartAnimation(animationTimeline)
    self.rootX = endX
    self.rootY = endY
    self.rootZ = endZ
end
function ZO_CrownCratesPack:ShowFromSide(endX, endY, endZ, direction)
    self.control:SetHidden(false)
    self.control:Set3DRenderSpaceOrientation(ZO_CROWN_CRATES_PACK_SHOW_END_PITCH_RADIANS, ZO_CROWN_CRATES_PACK_SHOW_START_YAW_RADIANS, ZO_CROWN_CRATES_PACK_SHOW_START_ROLL_RADIANS)
    local animationTimeline = self:AcquireAndApplyAnimationTimeline(ZO_CROWN_CRATES_ANIMATION_PACK_SHOW_FROM_SIDE, self.control, function(timeline, completedPlaying)
        if completedPlaying then
            self.owner:OnManifestPackInComplete()
            --Mouse input on the crate is not enabled until it is finished showing. This will prevent the case where the mouse enters the
            --crate and then exits it again as it flips and then enters once more but we suppress the enter because of the bounce prevention logic.
            self:SetPackMouseEnabled(true)
        end
    end)
    local translateAnimation = animationTimeline:GetAnimation(1)
    local startY = endY
    local startZ = endZ
    local offsetX = -ZO_CROWN_CRATES_PACK_HIDE_AND_EXIT_SIDE_OFFSET_X_UI * direction
    local manifestPlaneMetrics = self.owner:GetManifestCameraPlaneMetrics()
    local startX = endX + ZO_CrownCrates.ConvertUIUnitsToWorldUnits(manifestPlaneMetrics, offsetX)
    translateAnimation:SetTranslateOffsets(startX, startY, startZ, endX, endY, endZ)
    self:StartAnimation(animationTimeline)
    self.rootX = endX
    self.rootY = endY
    self.rootZ = endZ
end
function ZO_CrownCratesPack:StartGlowUp()
    local body = self.box.body
    local glowTimeline = self:AcquireAndApplyAnimationTimeline(ZO_CROWN_CRATES_ANIMATION_PACK_GLOW)
    local glowAlphaAnimation = glowTimeline:GetAnimation(1)
    glowAlphaAnimation:SetAnimatedControl(body.glowFront)
    glowAlphaAnimation:SetAlphaValues(body.glowFront:GetAlpha(), 1)
    self:StartAnimation(glowTimeline)
end
function ZO_CrownCratesPack:StartGlowDown()
    local body = self.box.body
    local glowTimeline = self:AcquireAndApplyAnimationTimeline(ZO_CROWN_CRATES_ANIMATION_PACK_GLOW)
    local glowAlphaAnimation = glowTimeline:GetAnimation(1)
    glowAlphaAnimation:SetAnimatedControl(body.glowFront)
    glowAlphaAnimation:SetAlphaValues(body.glowFront:GetAlpha(), 0)
    self:StartAnimation(glowTimeline)
end
function ZO_CrownCratesPack:StartSelectAnimation()
    local timeline = self:AcquireAndApplyAnimationTimeline(ZO_CROWN_CRATES_ANIMATION_PACK_SELECT, self.control, function(timeline, completedPlaying)
        if completedPlaying then
            self.visuallySelected = true
            if not self:IsSelected() then
                self:StartDeselectAnimation()
            end
        end
    end)
    local rotateAnimation = timeline:GetAnimation(1)
    rotateAnimation:SetRotationValues(ZO_CROWN_CRATES_PACK_SHOW_END_PITCH_RADIANS, ZO_CROWN_CRATES_PACK_SHOW_END_YAW_RADIANS, ZO_CROWN_CRATES_PACK_SHOW_END_ROLL_RADIANS,
        ZO_CROWN_CRATES_PACK_SELECTED_PITCH_RADIANS, ZO_CROWN_CRATES_PACK_SELECTED_YAW_RADIANS, ZO_CROWN_CRATES_PACK_SELECTED_ROLL_RADIANS)
    self:StartAnimation(timeline)
    local translateAnimation = timeline:GetAnimation(2)
    local offsetYWorld = ZO_CrownCrates.ConvertUIUnitsToWorldUnits(self.owner:GetManifestCameraPlaneMetrics(), ZO_CROWN_CRATES_PACK_SELECTION_OFFSET_Y_UI)
    self.control:Set3DRenderSpaceOrigin(self.rootX, self.rootY, self.rootZ)
    translateAnimation:SetTranslateOffsets(self.rootX, self.rootY, self.rootZ, self.rootX, self.rootY + offsetYWorld, self.rootZ)
    self:StartGlowUp()
    self:ShowInfo()
end
function ZO_CrownCratesPack:Select()
    if not self:GetOnePlayingAnimationOfType(ZO_CROWN_CRATES_ANIMATION_PACK_DESELECT) and
        not self:GetOnePlayingAnimationOfType(ZO_CROWN_CRATES_ANIMATION_PACK_SELECT) and
        not self.visuallySelected then
            self:StartSelectAnimation()
    end
    PlaySound(SOUNDS.CROWN_CRATES_MANIFEST_SELECTED)
end
function ZO_CrownCratesPack:StartDeselectAnimation()
    local timeline = self:AcquireAndApplyAnimationTimeline(ZO_CROWN_CRATES_ANIMATION_PACK_DESELECT, self.control, function(timeline, completedPlaying)
        self.visuallySelected = false
        if completedPlaying then
            if self:IsSelected() then
                self:StartSelectAnimation()
            end
        end
    end)
    local rotateAnimation = timeline:GetAnimation(1)
    rotateAnimation:SetRotationValues(ZO_CROWN_CRATES_PACK_SELECTED_PITCH_RADIANS, ZO_CROWN_CRATES_PACK_SELECTED_YAW_RADIANS, ZO_CROWN_CRATES_PACK_SELECTED_ROLL_RADIANS,
        ZO_CROWN_CRATES_PACK_SHOW_END_PITCH_RADIANS, ZO_CROWN_CRATES_PACK_SHOW_END_YAW_RADIANS, ZO_CROWN_CRATES_PACK_SHOW_END_ROLL_RADIANS)
    self:StartAnimation(timeline)
    local translateAnimation = timeline:GetAnimation(2)
    local offsetYWorld = ZO_CrownCrates.ConvertUIUnitsToWorldUnits(self.owner:GetManifestCameraPlaneMetrics(), ZO_CROWN_CRATES_PACK_SELECTION_OFFSET_Y_UI)
    self.control:Set3DRenderSpaceOrigin(self.rootX, self.rootY + offsetYWorld, self.rootZ)
    translateAnimation:SetTranslateOffsets(self.rootX, self.rootY + offsetYWorld, self.rootZ, self.rootX, self.rootY, self.rootZ)
    
    self:StartGlowDown()
    self:HideInfo()
end
function ZO_CrownCratesPack:Deselect()
    if not self:GetOnePlayingAnimationOfType(ZO_CROWN_CRATES_ANIMATION_PACK_SELECT) and
        not self:GetOnePlayingAnimationOfType(ZO_CROWN_CRATES_ANIMATION_PACK_DESELECT) and
        self.visuallySelected then
            self:StartDeselectAnimation()
    end
end
function ZO_CrownCratesPack:ShowInfo()
    local animationTimeline = self:AcquireAndApplyAnimationTimeline(ZO_CROWN_CRATES_ANIMATION_PACK_SHOW_INFO, self.infoControl)
    local infoX, infoY = ZO_CrownCrates.ComputeSlotBottomUIPosition(ZO_CROWN_CRATES_PACK_WIDTH_UI, ZO_CROWN_CRATES_PACK_SPACING_UI, self.visualSlotIndex, self.owner:GetVisualPackCount())
    self.infoControl:ClearAnchors()
    self.infoControl:SetAnchor(BOTTOM, GuiRoot, TOPLEFT, infoX, infoY)
    self:StartAnimation(animationTimeline)
end
function ZO_CrownCratesPack:HideInfo()
    self:StopAllAnimationsOfType(ZO_CROWN_CRATES_ANIMATION_PACK_SHOW_INFO)
    local animationTimeline = self:AcquireAndApplyAnimationTimeline(ZO_CROWN_CRATES_ANIMATION_PACK_HIDE_INFO, self.infoControl)
    local alphaAnimation = animationTimeline:GetAnimation(1)
    alphaAnimation:SetAlphaValues(self.infoControl:GetAlpha(), 0)
    self:StartAnimation(animationTimeline)
end
function ZO_CrownCratesPack:Hide()
    self:StopAllAnimationsOfType(ZO_CROWN_CRATES_ANIMATION_PACK_GLOW)
    self:StopAllAnimationsOfType(ZO_CROWN_CRATES_ANIMATION_PACK_SELECT)
    self:StopAllAnimationsOfType(ZO_CROWN_CRATES_ANIMATION_PACK_DESELECT)
    local timeline = self:AcquireAndApplyAnimationTimeline(ZO_CROWN_CRATES_ANIMATION_PACK_HIDE, self.control, function(timeline, completedPlaying)
        if completedPlaying then
            self.owner:OnManifestPackOutComplete()
        end
    end)
    local translateAnimation = timeline:GetAnimation(1)
    local startX, startY, startZ = self.control:Get3DRenderSpaceOrigin()
    local endX = startX
    local manifestPlaneMetrics = self.owner:GetManifestCameraPlaneMetrics()
    local endY = startY + ZO_CrownCrates.ConvertUIUnitsToWorldUnits(manifestPlaneMetrics, ZO_CROWN_CRATES_PACK_HIDE_OFFSET_Y_UI)
    local endZ = startZ
    translateAnimation:SetTranslateOffsets(startX, startY, startZ, endX, endY, endZ)
    self:StartAnimation(timeline)
    self:StartGlowDown()
    self:HideInfo()
end
function ZO_CrownCratesPack:HideAndExitToSide(direction)
    self:StopAllAnimationsOfType(ZO_CROWN_CRATES_ANIMATION_PACK_GLOW)
    self:StopAllAnimationsOfType(ZO_CROWN_CRATES_ANIMATION_PACK_SELECT)
    self:StopAllAnimationsOfType(ZO_CROWN_CRATES_ANIMATION_PACK_DESELECT)
    local timeline = self:AcquireAndApplyAnimationTimeline(ZO_CROWN_CRATES_ANIMATION_PACK_HIDE_AND_EXIT_SIDE, self.control, function(timeline, completedPlaying)
        if completedPlaying then
            self.owner:OnManifestPackOutComplete()
        end
    end)
    local translateAnimation = timeline:GetAnimation(1)
    local startX, startY, startZ = self.control:Get3DRenderSpaceOrigin()
    local endY = startY
    local endZ = startZ
    local offsetX = ZO_CROWN_CRATES_PACK_HIDE_AND_EXIT_SIDE_OFFSET_X_UI * direction
    local manifestPlaneMetrics = self.owner:GetManifestCameraPlaneMetrics()
    local endX = startX + ZO_CrownCrates.ConvertUIUnitsToWorldUnits(manifestPlaneMetrics, offsetX)
    translateAnimation:SetTranslateOffsets(startX, startY, startZ, endX, endY, endZ)
    self:StartAnimation(timeline)
    self:StartGlowDown()
    self:HideInfo()
end
function ZO_CrownCratesPack:Choose()
    self:StopAllAnimationsOfType(ZO_CROWN_CRATES_ANIMATION_PACK_GLOW)
    self:StopAllAnimationsOfType(ZO_CROWN_CRATES_ANIMATION_PACK_SELECT)
    self:StopAllAnimationsOfType(ZO_CROWN_CRATES_ANIMATION_PACK_DESELECT)
    local timeline = self:AcquireAndApplyAnimationTimeline(ZO_CROWN_CRATES_ANIMATION_PACK_CHOOSE, self.control, function(timeline, completedPlaying)
        if completedPlaying then
            self.owner:OnManifestPackOutComplete()
        end
    end)
    local translateAnimation = timeline:GetAnimation(1)
    local startX, startY, startZ = self.control:Get3DRenderSpaceOrigin()
    local endX = startX
    local manifestPlaneMetrics = self.owner:GetManifestCameraPlaneMetrics()
    local endY = startY + ZO_CrownCrates.ConvertUIUnitsToWorldUnits(manifestPlaneMetrics, ZO_CROWN_CRATES_PACK_CHOOSE_OFFSET_Y_UI)
    local endZ = startZ
    translateAnimation:SetTranslateOffsets(startX, startY, startZ, endX, endY, endZ)
    local rotateAnimation = timeline:GetAnimation(2)
    local startPitch, startYaw, startRoll = self.control:Get3DRenderSpaceOrientation()
    rotateAnimation:SetRotationValues(startPitch, startYaw, startRoll, ZO_CROWN_CRATES_PACK_CHOOSEN_PITCH_RADIANS, ZO_CROWN_CRATES_PACK_CHOOSEN_YAW_RADIANS, ZO_CROWN_CRATES_PACK_CHOOSEN_ROLL_RADIANS)
    self:StartAnimation(timeline)
    self:StartGlowUp()
    local boxOpenTimeline = self:AcquireAndApplyAnimationTimeline(ZO_CROWN_CRATES_ANIMATION_PACK_OPEN, self.box.lid)
    self:StartAnimation(boxOpenTimeline)
    self:HideInfo()
end
------------------------------
--Crown Crates Pack Choosing--
------------------------------
ZO_CROWN_CRATES_PACK_CHOOSING_PACKS_PER_PAGE = 4
ZO_CrownCratesPackChoosing = ZO_Object:Subclass()
function ZO_CrownCratesPackChoosing:New(...)
    local obj = ZO_Object.New(self)
    obj:Initialize(...)
    return obj
end
function ZO_CrownCratesPackChoosing:Initialize(owner)
    self.owner = owner
    self.nextPackIndex = 1
    self.packsInVisualOrder = {}
    
    self.initialized = true
end
function ZO_CrownCratesPackChoosing:GetStateMachine()
    return self.stateMachine
end
function ZO_CrownCratesPackChoosing:SetStateMachine(stateMachine)
    self.stateMachine = stateMachine
end
function ZO_CrownCratesPackChoosing:GetOwner()
    return self.owner
end
function ZO_CrownCratesPackChoosing:InitializePackPool()
    local reset = function(pack)
        pack:Reset()
    end
    local factory = function(pool)
                        local pack = ZO_CrownCratesPack:New(CreateControlFromVirtual("$(parent)Pack", self.owner:GetControl(), "ZO_CrownCratePack", self.nextPackIndex), self)
                        self.nextPackIndex = self.nextPackIndex + 1
                        return pack
                    end
    self.packPool = ZO_ObjectPool:New(factory, reset)
    self.pageChangeFrameControl = CreateControlFromVirtual("$(parent)PageChangeFrame", self.owner:GetControl(), "ZO_PackChoosingPageChangeFrame")
    self.leftArrow = self.pageChangeFrameControl:GetNamedChild("LeftArrow")
    self.rightArrow = self.pageChangeFrameControl:GetNamedChild("RightArrow")
    self.leftArrowGamepadDirectionIndicator = self.leftArrow:GetNamedChild("GamepadDirectionIndicator")
    self.rightArrowGamepadDirectionIndicator = self.rightArrow:GetNamedChild("GamepadDirectionIndicator")
    self.leftArrow:SetHandler("OnClicked", function() self:RequestPreviousPage() end)
    self.rightArrow:SetHandler("OnClicked", function() self:RequestNextPage() end)
    self.pageIndicatorContainer = ZO_PackChoosingPageIndicator
    self.pageIndicatorLabel = self.pageIndicatorContainer.pageIndicator
    self.currentPage = 1
    self.numPages = 1
    ZO_PlatformStyle:New(function() self:RefreshPlatformStyle() end)
end
function ZO_CrownCratesPackChoosing:InitializeKeybinds()
    -- Keyboard --
    self.keyboardManifestKeybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_CENTER,
        {
            keybind = "UI_SHORTCUT_PRIMARY",
            name = GetString(SI_CROWN_CRATE_OPEN_NEXT_CRATE_KEYBIND),
            callback = function()
                local pack = self:GetPackInVisualOrder(1)
                self:Choose(pack)
            end,
            enabled = function()
                local pack = self:GetPackInVisualOrder(1)
                if pack and not pack:IsPlaceholderCrate() then
                    return true
                end
                return false, GetString("SI_LOOTCRATEOPENRESPONSE", LOOT_CRATE_OPEN_RESPONSE_OUT_OF_ALL_LOOT_CRATES)
            end
        },
        ZO_CROWN_CRATES_BUY_CRATES_KEYBIND_KEYBOARD,
    }
    -- Gamepad --
    self.gamepadManifestKeybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_CENTER,
        {
            keybind = "UI_SHORTCUT_PRIMARY",
            name = GetString(SI_CROWN_CRATE_OPEN_SELECTED_CRATE_KEYBIND),
            callback = function()
                local pack = self:GetSelectedPack()
                self:Choose(pack)
            end,
            enabled = function()
                local pack = self:GetSelectedPack()
                if pack and not pack:IsPlaceholderCrate() then
                    return true
                end
                return false, GetString("SI_LOOTCRATEOPENRESPONSE", LOOT_CRATE_OPEN_RESPONSE_OUT_OF_ALL_LOOT_CRATES)
            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 = "Crown Crates Next Page",
            ethereal = true,
            keybind = "UI_SHORTCUT_RIGHT_SHOULDER",
            callback = function() self:RequestNextPage() end,
            enabled = function() return self.showPagination 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 = "Crown Crates Previous Page",
            ethereal = true,
            keybind = "UI_SHORTCUT_LEFT_SHOULDER",
            callback = function() self:RequestPreviousPage() end,
            enabled = function() return self.showPagination end,
        },
        ZO_CROWN_CRATES_BUY_CRATES_KEYBIND_GAMEPAD,
    }
end
function ZO_CrownCratesPackChoosing:RefreshCameraPlaneMetrics()
    self.manifestCameraPlaneMetrics = self.owner:ComputeCameraPlaneMetrics(ZO_CROWN_CRATES_PACK_WIDTH_WORLD, ZO_CROWN_CRATES_PACK_WIDTH_UI)
end
function ZO_CrownCratesPackChoosing:OnLockLocalSpaceToCurrentCamera()
end
function ZO_CrownCratesPackChoosing:GetManifestCameraPlaneMetrics()
    return self.manifestCameraPlaneMetrics
end
do
    local KEYBOARD_ARROW_BUTTON_TEXTURES =
    {
        LEFT = {
            NORMAL = "EsoUI/Art/Buttons/large_leftArrow_up.dds",
            PRESSED = "EsoUI/Art/Buttons/large_leftArrow_down.dds",
            MOUSEOVER = "EsoUI/Art/Buttons/large_leftArrow_over.dds",
            DISABLED = "EsoUI/Art/Buttons/large_leftArrow_disabled.dds",
        },
        RIGHT = {
            NORMAL = "EsoUI/Art/Buttons/large_rightArrow_up.dds",
            PRESSED = "EsoUI/Art/Buttons/large_rightArrow_down.dds",
            MOUSEOVER = "EsoUI/Art/Buttons/large_rightArrow_over.dds",
            DISABLED = "EsoUI/Art/Buttons/large_rightArrow_disabled.dds",
        },
    }
    local GAMEPAD_ARROW_BUTTON_TEXTURES =
    {
        LEFT = {
            KEY_CODE = KEY_GAMEPAD_LEFT_SHOULDER,
        },
        RIGHT = {
            KEY_CODE = KEY_GAMEPAD_RIGHT_SHOULDER,
        },
    }
    local function SetButtonTextures(btn, textures)
        if textures.KEY_CODE then
            btn:SetKeyCode(textures.KEY_CODE)
        else
            btn:SetKeyCode(nil)
            btn:SetNormalTexture(textures.NORMAL)
            btn:SetPressedTexture(textures.PRESSED)
            btn:SetMouseOverTexture(textures.MOUSEOVER)
            btn:SetDisabledTexture(textures.DISABLED)
        end
    end
    function ZO_CrownCratesPackChoosing:RefreshPlatformStyle()
        self.leftArrow:ClearAnchors()
        self.rightArrow:ClearAnchors()
        self.pageIndicatorContainer:ClearAnchors()
        local buttonTextures
        local isGamepadMode = IsInGamepadPreferredMode()
        if isGamepadMode then
            buttonTextures = GAMEPAD_ARROW_BUTTON_TEXTURES
        else
            buttonTextures = KEYBOARD_ARROW_BUTTON_TEXTURES
        end
        self.leftArrowGamepadDirectionIndicator:SetHidden(not isGamepadMode)
        self.rightArrowGamepadDirectionIndicator:SetHidden(not isGamepadMode)
        -- we're aiming to get a point at the middle of the crates for anchoring, but we'll subtract 25 to get it to look a bit better
        local arrowYOffset = ZO_CROWN_CRATES_PACK_OFFSET_Y_UI + ZO_CrownCrates.GetBottomOffsetUI() + (ZO_CROWN_CRATES_PACK_WIDTH_UI* 0.5) - 25
        local arrowXOffset = ZO_CROWN_CRATES_PAGE_CHANGE_ARROW_OFFSET_X_UI
        self.leftArrow:SetAnchor(BOTTOMLEFT, nil, BOTTOMLEFT, arrowXOffset, -arrowYOffset)
        self.rightArrow:SetAnchor(BOTTOMRIGHT, nil, BOTTOMRIGHT, -arrowXOffset, -arrowYOffset)
        SetButtonTextures(self.leftArrow, buttonTextures.LEFT)
        SetButtonTextures(self.rightArrow, buttonTextures.RIGHT)
        ApplyTemplateToControl(self.pageIndicatorContainer, ZO_GetPlatformTemplate("ZO_PackChoosingPageIndicator"))
    end
end
function ZO_CrownCratesPackChoosing:HidePageControls(setHidden)
    self.pageChangeFrameControl:SetHidden(setHidden)
    self.pageIndicatorContainer:SetHidden(setHidden)
end
function ZO_CrownCratesPackChoosing:ResetPacks()
    self.packPool:ReleaseAllObjects()
    self.crateIds = nil
    self.chosenPack = nil
    ZO_ClearNumericallyIndexedTable(self.packsInVisualOrder)
    self.selectedPack = nil
    self:HidePageControls(true)
end
function ZO_CrownCratesPackChoosing:HasInitializedPacks()
    return self.crateIds ~= nil
end
function ZO_CrownCratesPackChoosing:CreateRectagularPrism(parentControl, width, height, depth, registrationX, registrationY, registrationZ, texture)
    local prism = CreateControl("", parentControl, CT_CONTROL)
    prism:Create3DRenderSpace()
    local centerX = width * (0.5 - registrationX)
    local centerY = height * (0.5 - registrationY)
    local centerZ = depth * (0.5 - registrationZ)
    --Front
    local frontFace = self:CreateCenteredFace(prism, width, height)
    frontFace:Set3DRenderSpaceOrigin(centerX, centerY, centerZ - depth * 0.5)
    prism.front = frontFace
    --Back
    local backFace = self:CreateCenteredFace(prism, width, height)
    backFace:Set3DRenderSpaceOrigin(centerX, centerY, centerZ + depth * 0.5)
    prism.back = backFace
    --Bottom
    local bottomFace = self:CreateCenteredFace(prism, width, depth)
    bottomFace:Set3DRenderSpaceOrientation(math.rad(90), 0, 0)
    bottomFace:Set3DRenderSpaceOrigin(centerX, centerY - height * 0.5 , centerZ)
    prism.bottom = bottomFace
    --Top
    local topFace = self:CreateCenteredFace(prism, width, depth)
    topFace:Set3DRenderSpaceOrientation(math.rad(90), 0, 0)
    topFace:Set3DRenderSpaceOrigin(centerX, centerY + height * 0.5 , centerZ)
    prism.top = topFace
    --Left
    local leftFace = self:CreateCenteredFace(prism, depth, height)
    leftFace:Set3DRenderSpaceOrientation(0, math.rad(90), 0)
    leftFace:Set3DRenderSpaceOrigin(centerX - width * 0.5, centerY, centerZ)
    prism.left = leftFace
    --Right
    local rightFace = self:CreateCenteredFace(prism, depth, height)
    rightFace:Set3DRenderSpaceOrientation(0, math.rad(90), 0)
    rightFace:Set3DRenderSpaceOrigin(centerX + width * 0.5, centerY, centerZ)
    prism.right = rightFace
    return prism
end
function ZO_CrownCratesPackChoosing:CreateCenteredFace(parentControl, width, height)
    local face = CreateControl("", parentControl, CT_TEXTURE)
    face:Create3DRenderSpace()
    face:Set3DLocalDimensions(width, height)
    return face
end
function ZO_CrownCratesPackChoosing:GetPack(packIndex)
    return self.packPool:AcquireObject(packIndex)
end
function ZO_CrownCratesPackChoosing:UpdatePackData()
    local crateIds = {}
    for crateId in ZO_GetNextOwnedCrownCrateIdIter do
        table.insert(crateIds, crateId)
    end
    -- sort so the newest crates should be at the front
    table.sort(crateIds, function(a, b) return a > b end)
    self.crateIds = crateIds
    if #self.crateIds > 0 then
        self:SetNumPages(zo_ceil(#self.crateIds / ZO_CROWN_CRATES_PACK_CHOOSING_PACKS_PER_PAGE))
    else
        self:SetNumPages(1)
    end
    if self.currentPage > self.numPages then
        self:SetCurrentPage(self.numPages)
    end
    self.showPagination = self.numPages > 1
end
function ZO_CrownCratesPackChoosing:Show()
    if not self:HasInitializedPacks() then
        self:UpdatePackData()
    end
end
function ZO_CrownCratesPackChoosing:AnimateChoice()
    self.chosenPack:Choose()
    for _, pack in ipairs(self.packsInVisualOrder) do
        if pack ~= self.chosenPack then
            pack:Hide()
        end
    end
    self:HidePageControls(true)
end
function ZO_CrownCratesPackChoosing:Hide()
    for _, pack in ipairs(self.packPool:GetActiveObjects()) do
        pack:Hide()
    end
    self:HidePageControls(true)
end
function ZO_CrownCratesPackChoosing:ComputeSlotCenterWorldPosition(planeMetrics, spacingUI, bottomOffsetUI, bottomOffsetWorld, slotIndex, totalSlots)
    local spacingWorldWidth = spacingUI * planeMetrics.worldUnitsPerUIUnit
    local totalWorldWidth = totalSlots * ZO_CROWN_CRATES_PACK_WIDTH_WORLD + (totalSlots - 1) * spacingWorldWidth
    local slotCenterX = ZO_CROWN_CRATES_PACK_WIDTH_WORLD * 0.5 + (slotIndex - 1) * (ZO_CROWN_CRATES_PACK_WIDTH_WORLD + spacingWorldWidth)
    local x = slotCenterX - totalWorldWidth * 0.5
    local y = planeMetrics.frustumHeightWorld * -0.5 + bottomOffsetUI * planeMetrics.worldUnitsPerUIUnit + bottomOffsetWorld + ZO_CROWN_CRATES_PACK_HEIGHT_WORLD * 0.5
    --we build the box from the center, but we choose its world width based on the front, so push it half its depth into the screen so its front is registered with manifest plane.
    local z = planeMetrics.depthFromCamera + ZO_CROWN_CRATES_PACK_DEPTH_WORLD * 0.5
    return x, y, z
end
function ZO_CrownCratesPackChoosing:GetCurrentPageIndices()
    local startIndex = 1 + (self.currentPage - 1) * ZO_CROWN_CRATES_PACK_CHOOSING_PACKS_PER_PAGE
    local pageEndIndex = self.currentPage * ZO_CROWN_CRATES_PACK_CHOOSING_PACKS_PER_PAGE
    local endIndex = zo_min(pageEndIndex, #self.crateIds)
    return startIndex, endIndex, pageEndIndex
end
function ZO_CrownCratesPackChoosing:StartPackShowAnimation(packIndex, numPacks, crateId)
    local pack = self:GetPack(packIndex)
    pack:InitializeForShow(crateId, packIndex)
    --20 more units off the bottom to start so the packs are just peeking above the bottom of the screen
    local ADDITIONAL_START_OFFSET_Y = -20
    local startX, startY, startZ = self:ComputeSlotCenterWorldPosition(self.manifestCameraPlaneMetrics, ZO_CROWN_CRATES_PACK_SPACING_UI, ADDITIONAL_START_OFFSET_Y, -ZO_CROWN_CRATES_PACK_HEIGHT_WORLD, packIndex, numPacks)
    local endX, endY, endZ = self:ComputeSlotCenterWorldPosition(self.manifestCameraPlaneMetrics, ZO_CROWN_CRATES_PACK_SPACING_UI, ZO_CROWN_CRATES_PACK_OFFSET_Y_UI + ZO_CrownCrates.GetBottomOffsetUI(), 0, packIndex, numPacks)
    pack:CallLater(function()
        pack:Show(startX, startY, startZ, endX, endY, endZ)
    end, (packIndex - 1) * ZO_CROWN_CRATES_PACK_SHOW_SPACING_MS + 1)
    self.packsInVisualOrder[packIndex] = pack
end
function ZO_CrownCratesPackChoosing:StartShowAnimation()
    if #self.crateIds > 0 then
        local startIndex, endIndex = self:GetCurrentPageIndices()
        ZO_ClearNumericallyIndexedTable(self.packsInVisualOrder)
        local packIndex = 1
        local numPacks = endIndex - startIndex + 1
        for i = startIndex, endIndex do
            local crateId = self.crateIds[i]
            self:StartPackShowAnimation(packIndex, numPacks, crateId)
            packIndex = packIndex + 1
        end
    else
        self:StartPackShowAnimation(1, 1)
    end
end
function ZO_CrownCratesPackChoosing:StartPackShowNewPageAnimation(packIndex, numPacks, crateId, direction)
    local pack = self:GetPack(packIndex)
    pack:InitializeForShow(crateId, packIndex)
    local endX, endY, endZ = self:ComputeSlotCenterWorldPosition(self.manifestCameraPlaneMetrics, ZO_CROWN_CRATES_PACK_SPACING_UI, ZO_CROWN_CRATES_PACK_OFFSET_Y_UI + ZO_CrownCrates.GetBottomOffsetUI(), 0, packIndex, numPacks)
    if not direction then
        direction = ZO_CROWN_CRATES_PAGE_RIGHT
    end
    local callbackDelay
    if direction == ZO_CROWN_CRATES_PAGE_RIGHT then
        callbackDelay = (packIndex - 1) * ZO_CROWN_CRATES_PACK_SHOW_SPACING_MS + 1
    else
        callbackDelay = (numPacks - packIndex) * ZO_CROWN_CRATES_PACK_SHOW_SPACING_MS + 1
    end
    pack:CallLater(function()
        pack:ShowFromSide(endX, endY, endZ, direction)
    end, callbackDelay)
    self.packsInVisualOrder[packIndex] = pack
end
function ZO_CrownCratesPackChoosing:StartPageShowAnimation()
    if #self.crateIds > 0 then
        local startIndex, endIndex = self:GetCurrentPageIndices()
        ZO_ClearNumericallyIndexedTable(self.packsInVisualOrder)
        local packIndex = 1
        local numPacks = endIndex - startIndex + 1
        for i = startIndex, endIndex do
            local crateId = self.crateIds[i]
            self:StartPackShowNewPageAnimation(packIndex, numPacks, crateId, self.pageDirection)
            packIndex = packIndex + 1
        end
    else
        self:StartPackShowAnimation(1, 1)
    end
end
function ZO_CrownCratesPackChoosing:Choose(chosenPack)
    if chosenPack:IsPlaceholderCrate() then
        ZO_AlertEvent(EVENT_CROWN_CRATE_OPEN_RESPONSE, nil, LOOT_CRATE_OPEN_RESPONSE_OUT_OF_ALL_LOOT_CRATES)
    else
        if chosenPack:CanSelect() then
            local crownCrateId = chosenPack:GetCrownCrateId()
            local numSlotsForCrate = GetInventorySpaceRequiredToOpenCrownCrate(crownCrateId)
            if CheckInventorySpaceSilently(numSlotsForCrate) then
                self.chosenPack = chosenPack
                self.stateMachine:FireCallbacks(ZO_CROWN_CRATE_TRIGGER_COMMANDS.DEAL_REQUESTED)
                SendCrownCrateOpenRequest(crownCrateId)
                PlaySound(SOUNDS.CROWN_CRATES_MANIFEST_CHOSEN)
            else
                ZO_AlertEvent(EVENT_CROWN_CRATE_OPEN_RESPONSE, crownCrateId, LOOT_CRATE_OPEN_RESPONSE_FAIL_NO_INVENTORY_SPACE)
            end
        end
    end
end
function ZO_CrownCratesPackChoosing:OnManifestPackInComplete()
    self.stateMachine:FireCallbacks(ZO_CROWN_CRATE_TRIGGER_COMMANDS.MANIFEST_IN_COMPLETE)
end
function ZO_CrownCratesPackChoosing:OnManifestPackOutComplete()
    self.stateMachine:FireCallbacks(ZO_CROWN_CRATE_TRIGGER_COMMANDS.MANIFEST_OUT_COMPLETE)
end
function ZO_CrownCratesPackChoosing:RefreshPageIndicator()
    self.pageIndicatorLabel:SetText(zo_strformat(SI_CROWN_CRATE_PAGE_INDICATOR_FORMAT, self.currentPage, self.numPages))
end
function ZO_CrownCratesPackChoosing:SetCurrentPage(newPage)
    if self.currentPage ~= newPage then
        self.currentPage = newPage
        self:RefreshPageIndicator()
    end
end
function ZO_CrownCratesPackChoosing:SetNumPages(pageCount)
    if self.numPages ~= pageCount then
        self.numPages = pageCount
        self:RefreshPageIndicator()
    end
end
function ZO_CrownCratesPackChoosing:GetCurrentPage()
    return self.currentPage
end
function ZO_CrownCratesPackChoosing:GetPreviousPage()
    local page = self.currentPage - 1
    return page == 0 and self.numPages or page
end
function ZO_CrownCratesPackChoosing:GetNextPage()
    local page = self.currentPage + 1
    return page > self.numPages and 1 or page
end
function ZO_CrownCratesPackChoosing:PageOutActivePacks(direction)
    local numPacks = #self.packsInVisualOrder
    for packIndex, pack in ipairs(self.packsInVisualOrder) do
        local callbackDelay
        if direction == ZO_CROWN_CRATES_PAGE_RIGHT then
            callbackDelay = (packIndex - 1) * ZO_CROWN_CRATES_PACK_SHOW_SPACING_MS + 1
        else
            callbackDelay = (numPacks - packIndex) * ZO_CROWN_CRATES_PACK_SHOW_SPACING_MS + 1
        end
        pack:CallLater(function()
                        pack:HideAndExitToSide(direction)
                    end, callbackDelay)
    end
    ZO_ClearNumericallyIndexedTable(self.packsInVisualOrder)
end
function ZO_CrownCratesPackChoosing:RequestPreviousPage()
    local previousPage = self:GetPreviousPage()
    if previousPage ~= self.currentPage then
        self.pageDirection = ZO_CROWN_CRATES_PAGE_LEFT
        self.stateMachine:FireCallbacks(ZO_CROWN_CRATE_TRIGGER_COMMANDS.MANIFEST_PAGE_OUT)
    end
end
function ZO_CrownCratesPackChoosing:RequestNextPage()
    local nextPage = self:GetNextPage()
    if nextPage ~= self.currentPage then
        self.pageDirection = ZO_CROWN_CRATES_PAGE_RIGHT
        self.stateMachine:FireCallbacks(ZO_CROWN_CRATE_TRIGGER_COMMANDS.MANIFEST_PAGE_OUT)
    end
end
function ZO_CrownCratesPackChoosing:ResetAllPacks()
   for _, pack in ipairs(self.packPool:GetActiveObjects()) do
        pack:Reset()
    end
end
function ZO_CrownCratesPackChoosing:SetupForPageIn()
    if self.pageDirection == ZO_CROWN_CRATES_PAGE_LEFT then
    else
        self:SetCurrentPage(self:GetNextPage())
    end
    self:ResetAllPacks()
end
function ZO_CrownCratesPackChoosing:StartPageOutAnimation()
    self:PageOutActivePacks(self.pageDirection)
end
function ZO_CrownCratesPackChoosing:GetNumPacksToDisplayOnPage(page)
    if self:HasInitializedPacks() then
        if page > 0 and page < self.numPages then
            return ZO_CROWN_CRATES_PACK_CHOOSING_PACKS_PER_PAGE
        elseif page == self.numPages then
            return zo_mod(#self.crateIds - 1, ZO_CROWN_CRATES_PACK_CHOOSING_PACKS_PER_PAGE) + 1
        end
    end
    return 0
end
function ZO_CrownCratesPackChoosing:AddManifestKeybinds()
    if self.initialized then
        if SCENE_MANAGER:IsCurrentSceneGamepad() then
            self:SetSelectedPack(self:GetPackInVisualOrder(1))
            KEYBIND_STRIP:AddKeybindButtonGroup(self.gamepadManifestKeybindStripDescriptor)
        else
            KEYBIND_STRIP:AddKeybindButtonGroup(self.keyboardManifestKeybindStripDescriptor)
        end
    end
end
function ZO_CrownCratesPackChoosing:RemoveManifestKeybinds()
    if self.initialized then
        if SCENE_MANAGER:IsCurrentSceneGamepad() then
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.gamepadManifestKeybindStripDescriptor)
        else
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keyboardManifestKeybindStripDescriptor)
        end
    end
end
function ZO_CrownCratesPackChoosing:OnActivate()
    self:HidePageControls(not self.showPagination)
    if self.showPagination then
        self.leftArrow:SetEnabled(true)
        self.rightArrow:SetEnabled(true)
    end
end
function ZO_CrownCratesPackChoosing:OnDeactivate()
    if self.showPagination then
        self.leftArrow:SetEnabled(false)
        self.rightArrow:SetEnabled(false)
    end
end
function ZO_CrownCratesPackChoosing:HandleDirectionalInput(selectedDirection)
    if self.stateMachine:IsCurrentState("MANIFEST") and selectedDirection then
        local selectedPack = self:GetSelectedPack()
        local nextPack
        if selectedPack then
            local nextVisualSlotIndex = selectedPack.visualSlotIndex + selectedDirection
            if nextVisualSlotIndex > self:GetVisualPackCount() then 
                nextVisualSlotIndex = 1
            elseif nextVisualSlotIndex < 1 then
                nextVisualSlotIndex = self:GetVisualPackCount()
            end
            nextPack = self:GetPackInVisualOrder(nextVisualSlotIndex)
        else
            -- this is specifically for players using the gamepad UI but using a mouse and gamepad to navigate this
            nextPack = self:GetPackInVisualOrder(1)
        end
        self:SetSelectedPack(nextPack)
        KEYBIND_STRIP:UpdateKeybindButtonGroup(self.gamepadManifestKeybindStripDescriptor)
    end
end
function ZO_CrownCratesPackChoosing:GetPackInVisualOrder(visualIndex)
    return self.packsInVisualOrder[visualIndex]
end
function ZO_CrownCratesPackChoosing:GetVisualPackCount()
    return #self.packsInVisualOrder
end
function ZO_CrownCratesPackChoosing:GetSelectedPack()
    return self.selectedPack
end
function ZO_CrownCratesPackChoosing:SetSelectedPack(pack)
    if self.selectedPack ~= pack then
        if self.selectedPack then
            self.selectedPack:OnDeselect()
        end
        self.selectedPack = pack
        if pack then
            pack:OnSelect()
        end
    end
end
function ZO_CrownCratesPackChoosing:RefreshSelectedPack()
    if self.selectedPack then
        self.selectedPack:OnSelect()
    end
end
--Pack Mouse Behavior
function ZO_CrownCratesPackChoosing:PackOnMouseEnter(pack)
    if not SCENE_MANAGER:IsCurrentSceneGamepad() then
        self:SetSelectedPack(pack)
    end
end
function ZO_CrownCratesPackChoosing:PackOnMouseExit(pack)
    if not SCENE_MANAGER:IsCurrentSceneGamepad() then
        self:SetSelectedPack(nil)
    end
end
function ZO_CrownCratesPackChoosing:PackOnMouseUp(pack)
    if not SCENE_MANAGER:IsCurrentSceneGamepad() then
        self:Choose(pack)
    end
end