-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathmenus.c
2059 lines (1966 loc) · 87.4 KB
/
menus.c
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
#include <ultra64.h>
#include <macros.h>
#include <defines.h>
#include <common_structs.h>
#include <mk64.h>
#include <course.h>
#include "menus.h"
#include "main.h"
#include "code_800029B0.h"
#include "actors.h"
#include "audio/external.h"
#include "code_800029B0.h"
#include "cpu_vehicles_camera_path.h"
#include "menu_items.h"
#include "code_800AF9B0.h"
#include "save.h"
#include "staff_ghosts.h"
#include "save_data.h"
#include <sounds.h>
#include "spawn_players.h"
#if ENABLE_DEBUG_MODE
#define DEBUG_MODE_TOGGLE true
#define DEBUG_MENU_SELECTION DEBUG_MENU_DEBUG_MODE
#else
#define DEBUG_MODE_TOGGLE false
#define DEBUG_MENU_SELECTION DEBUG_MENU_DISABLED
#endif
/** BSS **/
// Variables used to maniplate the model for Intro Logo
// and checkerboard on the start screen
s32 gIntroModelZEye;
f32 gIntroModelScale; // XYZ scale on checkerboard flag, Z scale on intro logo
f32 gIntroModelRotX;
f32 gIntroModelRotY;
f32 gIntroModelRotZ;
f32 gIntroModelPosX;
f32 gIntroModelPosY;
f32 gIntroModelPosZ;
s32 gMenuFadeType;
s8 gCharacterGridSelections[4]; // Map from each player to current grid position (1-4 top, 5-8 bottom)
bool8 gCharacterGridIsSelected[4]; // Sets true if a character is selected for each player
s8 gSubMenuSelection; // Map Select states, Options and Ghost Data text selection
s8 gMainMenuSelection;
s8 gPlayerSelectMenuSelection;
s8 gDebugMenuSelection;
s8 gControllerPakMenuSelection;
s8 gScreenModeListIndex; // 0-4 index, selects a screen mode in sScreenModePlayerTable
u8 gSoundMode;
s8 gPlayerCount;
s8 gVersusResultCursorSelection; // 4 options indexed (10-13), gets set when selecting an option
s8 gTimeTrialsResultCursorSelection; // 5 options indexed (5-9), gets set when selecting an option (excluding Save
// Ghost)
s8 gBattleResultCursorSelection; // 4 options indexed (10-13), gets set when selecting an option
s8 gTimeTrialDataCourseIndex;
s8 gCourseRecordsMenuSelection; // Used for selecting an option in course record data
s8 gCourseRecordsSubMenuSelection; // Used for erase records and ghosts (Quit - Erase)
s8 gDebugGotoScene;
bool8 gGhostPlayerInit;
bool8 gCourseMapInit;
s32 gMenuTimingCounter;
s32 gMenuDelayTimer;
s8 gDemoUseController; // Sets true alongside gDemoMode, controller related
s8 gCupSelection;
s8 sTempCupSelection; // Same as gCupSelection but it's only set in map select, not referenced
s8 gCourseIndexInCup;
s8 unref_8018EE0C; // Set to 0 but never referenced
/** Data **/
s32 gMenuSelection = LOGO_INTRO_MENU;
s32 gFadeModeSelection = FADE_MODE_NONE;
// Default selected character for each player
s8 gCharacterSelections[4] = { MARIO, LUIGI, YOSHI, TOAD };
// The current row selected in the mode column for each player indexed
// 0-1 1p / 0-2 2p´/ 0-1 3p / 0-1 4p
s8 gGameModeMenuColumn[4] = { 0, 0, 0, 0 };
// For Grand Prix and Versus, this will be the CC mode selected. For Time Trials, it will
// be whether 'Begin' or 'Data' is selected. Not used for Battle.
// indexed as [column][row]
s8 gGameModeSubMenuColumn[4][3] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };
s8 gNextDemoId = 0;
s8 gControllerPakSelectedTableRow = 0; // 0-4 index, value of the current visible row select
// Numbers starting from the second 0 to number 6 get altered
// as you move up or down the page table of content (min value is 0, max value is 16
s8 gControllerPakVisibleTableRows[12] = { 0, 0, 1, 2, 3, 4, 5, 6, 0, 0, 0, 0 };
s8 gControllerPakScrollDirection = CONTROLLER_PAK_SCROLL_DIR_NONE; // 1 is down, 2 is up
s8 unref_D_800E86D4[12] = { 0 };
s8 unref_D_800E86E0[4] = { 0, 0, 0, 1 };
u32 sVIGammaOffDitherOn = (OS_VI_GAMMA_OFF | OS_VI_DITHER_FILTER_ON);
/** RoData **/
// Sets the actual screen mode based on values set in sScreenModePlayerCount
const s8 sScreenModePlayerTable[] = { SCREEN_MODE_1P, SCREEN_MODE_2P_SPLITSCREEN_HORIZONTAL,
SCREEN_MODE_2P_SPLITSCREEN_VERTICAL, SCREEN_MODE_3P_4P_SPLITSCREEN,
SCREEN_MODE_3P_4P_SPLITSCREEN };
// Sets how many players can load on each screen mode set in sScreenModePlayerTable
const s8 sScreenModePlayerCount[] = { 1, 2, 2, 3, 4 };
// Set indexed slots numbers for one-two-three-four mode selection
const s8 gPlayerModeSelection[] = { 1, 2, 1, 1 };
// Limit for each index column in one-two-three-four mode selection
const s8 sGameModePlayerColumnDefault[][3] = {
{ 2, 1, 0 }, // 1p (GP options, TT options, ...)
{ 2, 2, 0 }, // 2p (GP options, VS options, Battle)
{ 2, 0, 0 }, // 3p (VS options, Battle, ...)
{ 2, 0, 0 }, // 4p (VS options, Battle, ...)
};
// Limit for each index column in one-two-three-four mode selection
// for extra mode (mirror mode), hence the extra value (3 instead of 2)
const s8 sGameModePlayerColumnExtra[][3] = {
{ 3, 1, 0 }, // 1p (GP options, TT options, ...)
{ 3, 3, 0 }, // 2p (GP options, VS options, Battle)
{ 3, 0, 0 }, // 3p (VS options, Battle, ...)
{ 3, 0, 0 }, // 4p (VS options, Battle, ...)
};
// Modes to select in one-two-three-four mode selection
const s32 gGameModePlayerSelection[][3] = {
{ GRAND_PRIX, TIME_TRIALS, 0x00000000 }, // 1p game modes
{ GRAND_PRIX, VERSUS, BATTLE }, // 2p game modes
{ VERSUS, BATTLE, 0x00000000 }, // 3p game modes
{ VERSUS, BATTLE, 0x00000000 }, // 4p game modes
};
// Map from character grid position id to character id
// Note: changing order doesn't affect graphics, only the selection
const s8 sCharacterGridOrder[] = {
MARIO, LUIGI, PEACH, TOAD, YOSHI, DK, WARIO, BOWSER,
};
const s16 gCupCourseOrder[5][4] = {
// mushroom cup
{ COURSE_LUIGI_RACEWAY, COURSE_MOO_MOO_FARM, COURSE_KOOPA_BEACH, COURSE_KALAMARI_DESERT },
// flower cup
{ COURSE_TOADS_TURNPIKE, COURSE_FRAPPE_SNOWLAND, COURSE_CHOCO_MOUNTAIN, COURSE_MARIO_RACEWAY },
// star cup
{ COURSE_WARIO_STADIUM, COURSE_SHERBET_LAND, COURSE_ROYAL_RACEWAY, COURSE_BOWSER_CASTLE },
// special cup
{ COURSE_DK_JUNGLE, COURSE_YOSHI_VALLEY, COURSE_BANSHEE_BOARDWALK, COURSE_RAINBOW_ROAD },
// battle mode
{ COURSE_BIG_DONUT, COURSE_BLOCK_FORT, COURSE_DOUBLE_DECK, COURSE_SKYSCRAPER },
};
const s8 unref_800F2BDC[4] = { 1, 0, 0, 0 };
// Uses player count to set gScreenModeListIndex, the latter variable then selects a mode
// from sScreenModePlayerTable, note the 2 is not set since that's for vertical 2p screen
const s8 sScreenModeIdxFromPlayerMode[4] = { 0, 1, 3, 4 };
const union GameModePack sSoundMenuPack = { { SOUND_STEREO, SOUND_HEADPHONES, SOUND_UNUSED, SOUND_MONO } };
/**************************/
/**
* General menu main handler
* Includes opening logo and splash screens
*/
void update_menus(void) {
u16 controllerIdx;
if (gFadeModeSelection == FADE_MODE_NONE) {
for (controllerIdx = 0; controllerIdx < 4; controllerIdx++) {
// Debug, quick jump through menus using the start button.
if ((is_screen_being_faded() == 0) && (gEnableDebugMode) &&
((gControllers[controllerIdx].buttonPressed & START_BUTTON) != 0)) {
// this is certainly a way to write these...
switch (gMenuSelection) {
case COURSE_SELECT_MENU:
func_800CA330(0x19);
// deliberate (?) fallthru
case MAIN_MENU:
case CHARACTER_SELECT_MENU:
play_sound2(SOUND_MENU_OK_CLICKED);
break;
}
switch (gMenuSelection) {
case CONTROLLER_PAK_MENU:
case START_MENU:
break;
default:
func_8009E1C0();
}
}
osViSetSpecialFeatures(sVIGammaOffDitherOn);
switch (gMenuSelection) {
case OPTIONS_MENU:
options_menu_act(&gControllers[controllerIdx], controllerIdx);
break;
case DATA_MENU:
data_menu_act(&gControllers[controllerIdx], controllerIdx);
break;
case COURSE_DATA_MENU:
course_data_menu_act(&gControllers[controllerIdx], controllerIdx);
break;
case LOGO_INTRO_MENU:
logo_intro_menu_act(&gControllers[controllerIdx], controllerIdx);
break;
case CONTROLLER_PAK_MENU:
if (controllerIdx == PLAYER_ONE) {
controller_pak_menu_act(&gControllers[controllerIdx], controllerIdx);
}
break;
case START_MENU_FROM_QUIT:
case START_MENU:
splash_menu_act(&gControllers[controllerIdx], controllerIdx);
break;
case MAIN_MENU_FROM_QUIT:
case MAIN_MENU:
main_menu_act(&gControllers[controllerIdx], controllerIdx);
break;
case PLAYER_SELECT_MENU_FROM_QUIT:
case CHARACTER_SELECT_MENU:
player_select_menu_act(&gControllers[controllerIdx], controllerIdx);
break;
case COURSE_SELECT_MENU_FROM_QUIT:
case COURSE_SELECT_MENU:
course_select_menu_act(&gControllers[controllerIdx], controllerIdx);
break;
}
}
}
}
/**
* Navigation of the options menu
*/
void options_menu_act(struct Controller* controller, u16 controllerIdx) {
u16 btnAndStick; // sp3E
MenuItem* sp38;
s32 res;
struct_8018EE10_entry* sp30;
bool tempVar; // cursorWasMoved or communicateStoredAction
UNUSED u32 pad;
btnAndStick = (controller->buttonPressed | controller->stickPressed);
if (!gEnableDebugMode && (btnAndStick & START_BUTTON)) {
btnAndStick |= A_BUTTON;
}
if (!is_screen_being_faded()) {
sp38 = find_menu_items_dupe(0xF0);
sp30 = (struct_8018EE10_entry*) gSomeDLBuffer;
switch (gSubMenuSelection) {
case SUB_MENU_OPTION_RETURN_GAME_SELECT:
case SUB_MENU_OPTION_SOUND_MODE:
case SUB_MENU_OPTION_COPY_CONTROLLER_PAK:
case SUB_MENU_OPTION_ERASE_ALL_DATA: {
tempVar = false;
if ((btnAndStick & D_JPAD) && (gSubMenuSelection < SUB_MENU_OPTION_MAX)) {
gSubMenuSelection += 1;
play_sound2(SOUND_MENU_CURSOR_MOVE);
if (sp38->paramf < 4.2) {
sp38->paramf += 4.0;
}
sp38->subState = 1;
tempVar = true;
}
if ((btnAndStick & U_JPAD) && (gSubMenuSelection > SUB_MENU_OPTION_MIN)) {
gSubMenuSelection -= 1;
play_sound2(SOUND_MENU_CURSOR_MOVE);
if (sp38->paramf < 4.2) {
sp38->paramf += 4.0;
}
tempVar = true;
sp38->subState = -1;
}
if (tempVar && gSoundMode != sp38->state) {
gSaveData.main.saveInfo.soundMode = gSoundMode;
write_save_data_grand_prix_points_and_sound_mode();
update_save_data_backup();
sp38->state = gSoundMode;
}
if (btnAndStick & B_BUTTON) {
func_8009E280();
play_sound2(SOUND_MENU_GO_BACK);
if (gSoundMode != sp38->state) {
gSaveData.main.saveInfo.soundMode = gSoundMode;
write_save_data_grand_prix_points_and_sound_mode();
update_save_data_backup();
sp38->state = gSoundMode;
}
return;
}
if (btnAndStick & A_BUTTON) {
switch (gSubMenuSelection) {
case SUB_MENU_OPTION_SOUND_MODE:
if (gSoundMode < 3) {
gSoundMode += 1;
} else {
gSoundMode = SOUND_STEREO;
}
if (gSoundMode == SOUND_UNUSED) {
gSoundMode = SOUND_MONO;
}
set_sound_mode();
switch (gSoundMode) {
case SOUND_STEREO:
play_sound2(SOUND_MENU_STEREO);
return;
case SOUND_HEADPHONES:
play_sound2(SOUND_MENU_HEADPHONES);
return;
case SOUND_MONO:
play_sound2(SOUND_MENU_MONO);
return;
}
break;
case SUB_MENU_OPTION_COPY_CONTROLLER_PAK:
switch (controller_pak_2_status()) {
case PFS_INVALID_DATA:
gSubMenuSelection = SUB_MENU_COPY_PAK_ERROR_NO_GAME_DATA;
play_sound2(SOUND_MENU_FILE_NOT_FOUND);
return;
case PFS_NO_ERROR:
func_800B6798();
tempVar = controller_pak_1_status();
switch (tempVar) {
case PFS_INVALID_DATA:
gSubMenuSelection = SUB_MENU_COPY_PAK_CREATE_GAME_DATA_INIT;
sp38->state = 0;
play_sound2(SOUND_MENU_SELECT);
break;
case PFS_NO_ERROR:
func_800B6708();
break;
case PFS_NO_PAK_INSERTED:
gSubMenuSelection = SUB_MENU_COPY_PAK_ERROR_NO_PAK_1P;
play_sound2(SOUND_MENU_FILE_NOT_FOUND);
break;
case PFS_FILE_OVERFLOW:
gSubMenuSelection = SUB_MENU_COPY_PAK_ERROR_NO_PAGES_1P;
play_sound2(SOUND_MENU_FILE_NOT_FOUND);
break;
case PFS_PAK_BAD_READ:
case PFS_PAK_CORRUPTED: // unreachable, bad reads always returns previous case
default:
gSubMenuSelection = SUB_MENU_COPY_PAK_ERROR_BAD_READ_1P;
play_sound2(SOUND_MENU_FILE_NOT_FOUND);
break;
}
if (tempVar == PFS_INVALID_DATA && !sp30[PLAYER_ONE].ghostDataSaved &&
!sp30[PLAYER_TWO].ghostDataSaved) {
gSubMenuSelection = SUB_MENU_COPY_PAK_ERROR_NO_GHOST_DATA;
play_sound2(SOUND_MENU_FILE_NOT_FOUND);
return;
}
if (tempVar == PFS_NO_ERROR) {
if (sp30[PLAYER_ONE].ghostDataSaved) {
gSubMenuSelection = SUB_MENU_COPY_PAK_FROM_GHOST1_1P;
play_sound2(SOUND_MENU_SELECT);
} else if (sp30[PLAYER_TWO].ghostDataSaved) {
gSubMenuSelection = SUB_MENU_COPY_PAK_FROM_GHOST2_1P;
play_sound2(SOUND_MENU_SELECT);
} else {
gSubMenuSelection = SUB_MENU_COPY_PAK_ERROR_NO_GHOST_DATA;
play_sound2(SOUND_MENU_FILE_NOT_FOUND);
}
}
// else return?
return;
case PFS_NO_PAK_INSERTED:
gSubMenuSelection = SUB_MENU_COPY_PAK_ERROR_NO_PAK_2P;
play_sound2(SOUND_MENU_FILE_NOT_FOUND);
return;
case PFS_PAK_BAD_READ:
default:
gSubMenuSelection = SUB_MENU_COPY_PAK_ERROR_BAD_READ_2P;
play_sound2(SOUND_MENU_FILE_NOT_FOUND);
return;
}
case SUB_MENU_OPTION_ERASE_ALL_DATA: {
gSubMenuSelection = SUB_MENU_ERASE_QUIT;
play_sound2(SOUND_MENU_SELECT);
return;
}
case SUB_MENU_OPTION_RETURN_GAME_SELECT: {
func_8009E280();
play_sound2(SOUND_MENU_GO_BACK);
return;
}
}
}
// maybe else return?;
break;
}
case SUB_MENU_ERASE_QUIT:
case SUB_MENU_ERASE_ERASE: {
if ((btnAndStick & D_JPAD) && (gSubMenuSelection < SUB_MENU_ERASE_MAX)) {
gSubMenuSelection += 1;
play_sound2(SOUND_MENU_CURSOR_MOVE);
if (sp38->paramf < 4.2) {
sp38->paramf += 4.0;
}
sp38->subState = 1;
}
if ((btnAndStick & U_JPAD) && (gSubMenuSelection > SUB_MENU_ERASE_MIN)) {
gSubMenuSelection -= 1;
play_sound2(SOUND_MENU_CURSOR_MOVE);
if (sp38->paramf < 4.2) {
sp38->paramf += 4.0;
}
sp38->subState = -1;
}
if (btnAndStick & B_BUTTON) {
gSubMenuSelection = SUB_MENU_OPTION_ERASE_ALL_DATA;
play_sound2(SOUND_MENU_GO_BACK);
return;
}
if (btnAndStick & A_BUTTON) {
switch (gSubMenuSelection) {
case SUB_MENU_ERASE_QUIT:
gSubMenuSelection = SUB_MENU_OPTION_ERASE_ALL_DATA;
play_sound2(SOUND_MENU_GO_BACK);
break;
case SUB_MENU_ERASE_ERASE:
gSubMenuSelection = SUB_MENU_SAVE_DATA_ERASED;
func_800B46D0();
D_800DC5AC = 0;
play_sound2(SOUND_MENU_EXPLOSION);
break;
}
}
break; // or return?
}
case SUB_MENU_SAVE_DATA_ERASED: {
if (btnAndStick & (A_BUTTON | B_BUTTON | START_BUTTON)) {
gSubMenuSelection = SUB_MENU_OPTION_ERASE_ALL_DATA;
play_sound2(SOUND_MENU_GO_BACK);
}
break;
}
case SUB_MENU_COPY_PAK_FROM_GHOST1_1P:
case SUB_MENU_COPY_PAK_FROM_GHOST2_1P: {
if ((btnAndStick & D_JPAD) && (gSubMenuSelection < SUB_MENU_COPY_PAK_FROM_GHOST_MAX) &&
(sp30[PLAYER_TWO].ghostDataSaved)) {
gSubMenuSelection += 1;
play_sound2(SOUND_MENU_CURSOR_MOVE);
if (sp38->paramf < 4.2) {
sp38->paramf += 4.0;
}
sp38->subState = 1;
}
if ((btnAndStick & U_JPAD) && (gSubMenuSelection > SUB_MENU_COPY_PAK_FROM_GHOST_MIN) &&
sp30[PLAYER_ONE].ghostDataSaved) {
gSubMenuSelection -= 1;
play_sound2(SOUND_MENU_CURSOR_MOVE);
if (sp38->paramf < 4.2) {
sp38->paramf += 4.0;
}
sp38->subState = -1;
}
if (btnAndStick & B_BUTTON) {
gSubMenuSelection = SUB_MENU_OPTION_COPY_CONTROLLER_PAK;
play_sound2(SOUND_MENU_GO_BACK);
return;
}
if (btnAndStick & A_BUTTON) {
sp38->param2 = gSubMenuSelection - SUB_MENU_COPY_PAK_FROM_GHOST_MIN;
if (sp30[sp38->param2].courseIndex == D_8018EE10[PLAYER_TWO].courseIndex &&
D_8018EE10[PLAYER_TWO].ghostDataSaved) {
gSubMenuSelection = SUB_MENU_COPY_PAK_TO_GHOST2_2P;
} else {
gSubMenuSelection = SUB_MENU_COPY_PAK_TO_GHOST1_2P;
}
play_sound2(SOUND_MENU_SELECT);
}
break;
}
case SUB_MENU_COPY_PAK_TO_GHOST1_2P:
case SUB_MENU_COPY_PAK_TO_GHOST2_2P: {
// bit of a fake match, but if it works it works?
if ((sp30[sp38->param2].courseIndex !=
((0, (D_8018EE10 + (gSubMenuSelection - SUB_MENU_COPY_PAK_TO_GHOST_MIN))->courseIndex))) ||
((D_8018EE10 + (gSubMenuSelection - SUB_MENU_COPY_PAK_TO_GHOST_MIN))->ghostDataSaved == 0)) {
if ((btnAndStick & D_JPAD) && (gSubMenuSelection < SUB_MENU_COPY_PAK_TO_GHOST_MAX)) {
gSubMenuSelection += 1;
play_sound2(SOUND_MENU_CURSOR_MOVE);
if (sp38->paramf < 4.2) {
sp38->paramf += 4.0;
}
sp38->subState = 1;
}
if ((btnAndStick & U_JPAD) && (gSubMenuSelection > SUB_MENU_COPY_PAK_TO_GHOST_MIN)) {
gSubMenuSelection -= 1;
play_sound2(SOUND_MENU_CURSOR_MOVE);
if (sp38->paramf < 4.2) {
sp38->paramf += 4.0;
}
sp38->subState = -1;
}
}
if (btnAndStick & B_BUTTON) {
gSubMenuSelection = sp38->param2 + SUB_MENU_COPY_PAK_FROM_GHOST_MIN;
play_sound2(SOUND_MENU_GO_BACK);
} else if (btnAndStick & A_BUTTON) {
sp38->param1 = gSubMenuSelection - SUB_MENU_COPY_PAK_TO_GHOST_MIN;
if (D_8018EE10[(sp38->param1)].ghostDataSaved) {
gSubMenuSelection = SUB_MENU_COPY_PAK_PROMPT_QUIT;
} else {
gSubMenuSelection = SUB_MENU_COPY_PAK_START;
sp38->state = 0;
}
play_sound2(SOUND_MENU_SELECT);
}
break;
}
case SUB_MENU_COPY_PAK_ERROR_NO_GHOST_DATA:
case SUB_MENU_COPY_PAK_ERROR_NO_GAME_DATA:
case SUB_MENU_COPY_PAK_ERROR_NO_PAK_2P:
case SUB_MENU_COPY_PAK_ERROR_BAD_READ_2P:
case SUB_MENU_COPY_PAK_ERROR_NO_PAK_1P:
case SUB_MENU_COPY_PAK_ERROR_BAD_READ_1P:
case SUB_MENU_COPY_PAK_ERROR_NO_PAGES_1P:
case SUB_MENU_COPY_PAK_COMPLETED:
case SUB_MENU_COPY_PAK_UNABLE_COPY_FROM_1P:
case SUB_MENU_COPY_PAK_UNABLE_READ_FROM_2P: {
if (btnAndStick & (A_BUTTON | B_BUTTON | START_BUTTON)) {
gSubMenuSelection = SUB_MENU_OPTION_COPY_CONTROLLER_PAK;
play_sound2(SOUND_MENU_GO_BACK);
}
break;
}
case SUB_MENU_COPY_PAK_PROMPT_QUIT:
case SUB_MENU_COPY_PAK_PROMPT_COPY: {
if ((btnAndStick & R_JPAD) && gSubMenuSelection < SUB_MENU_COPY_PAK_PROMPT_MAX) {
gSubMenuSelection += 1;
play_sound2(SOUND_MENU_CURSOR_MOVE);
if (sp38->paramf < 4.2) {
sp38->paramf += 4.0;
}
sp38->subState = 1;
}
if ((btnAndStick & L_JPAD) && gSubMenuSelection > SUB_MENU_COPY_PAK_PROMPT_MIN) {
gSubMenuSelection -= 1;
play_sound2(SOUND_MENU_CURSOR_MOVE);
if (sp38->paramf < 4.2) {
sp38->paramf += 4.0;
}
sp38->subState = -1;
}
if (btnAndStick & B_BUTTON) {
gSubMenuSelection = sp38->param1 + SUB_MENU_COPY_PAK_TO_GHOST_MIN;
play_sound2(SOUND_MENU_GO_BACK);
return;
}
if (btnAndStick & A_BUTTON) {
if (gSubMenuSelection == SUB_MENU_COPY_PAK_PROMPT_QUIT) {
gSubMenuSelection = SUB_MENU_OPTION_COPY_CONTROLLER_PAK;
play_sound2(SOUND_MENU_GO_BACK);
} else {
gSubMenuSelection = SUB_MENU_COPY_PAK_START;
play_sound2(SOUND_MENU_SELECT);
sp38->state = 0;
}
}
// return?
break;
}
case SUB_MENU_COPY_PAK_START: {
if (controllerIdx == PLAYER_ONE) {
sp38->state += 1;
}
if (sp38->state >= 3) {
gSubMenuSelection = SUB_MENU_COPY_PAK_COPYING;
}
break;
}
case SUB_MENU_COPY_PAK_COPYING: {
res = controller_pak_2_status();
if (res == PFS_NO_ERROR) {
res = func_800B65F4(sp38->param2, sp38->param1);
}
if (res != 0) {
gSubMenuSelection = SUB_MENU_COPY_PAK_UNABLE_READ_FROM_2P;
play_sound2(SOUND_MENU_FILE_NOT_FOUND);
return;
}
res = osPfsFindFile(&gControllerPak1FileHandle, gCompanyCode, gGameCode, (u8*) gGameName,
(u8*) gExtCode, &gControllerPak1FileNote);
if (res == PFS_NO_ERROR) {
res = func_800B6178(sp38->param1);
}
if (res != 0) {
gSubMenuSelection = SUB_MENU_COPY_PAK_UNABLE_COPY_FROM_1P;
play_sound2(SOUND_MENU_FILE_NOT_FOUND);
return;
}
gSubMenuSelection = SUB_MENU_COPY_PAK_COMPLETED;
D_8018EE10[sp38->param1].courseIndex = (sp30 + sp38->param2)->courseIndex;
func_800B6088(sp38->param1);
break;
}
case SUB_MENU_COPY_PAK_CREATE_GAME_DATA_INIT: {
if (controllerIdx == PLAYER_ONE) {
sp38->state += 1;
}
if (sp38->state >= 3) {
gSubMenuSelection = SUB_MENU_COPY_PAK_CREATE_GAME_DATA_DONE;
}
break;
}
case SUB_MENU_COPY_PAK_CREATE_GAME_DATA_DONE: {
if (func_800B6A68()) {
gSubMenuSelection = SUB_MENU_COPY_PAK_ERROR_CANT_CREATE_1P;
play_sound2(SOUND_MENU_FILE_NOT_FOUND);
} else if (sp30[0].ghostDataSaved) {
gSubMenuSelection = SUB_MENU_COPY_PAK_FROM_GHOST1_1P;
} else {
gSubMenuSelection = SUB_MENU_COPY_PAK_FROM_GHOST2_1P;
}
break;
}
default:
break;
}
}
}
/**
* Navigation of the data menu
*/
void data_menu_act(struct Controller* controller, UNUSED u16 controllerIdx) {
u16 btnAndStick = (controller->buttonPressed | controller->stickPressed);
// Make pressing Start have the same effect as pressing A
if ((gEnableDebugMode == 0) && ((btnAndStick & START_BUTTON) != 0)) {
btnAndStick |= A_BUTTON;
}
if (is_screen_being_faded() == 0) {
if (gSubMenuSelection == SUB_MENU_DATA) {
// If DPad/Stick down pressed, move selection down if not already in bottom row
if ((btnAndStick & D_JPAD) != 0) {
if ((gTimeTrialDataCourseIndex % 4) != 3) {
++gTimeTrialDataCourseIndex;
play_sound2(SOUND_MENU_CURSOR_MOVE);
}
}
// If DPad/Stick up pressed, move selection up if not already in top row
if ((btnAndStick & U_JPAD) != 0) {
if ((gTimeTrialDataCourseIndex % 4) != 0) {
--gTimeTrialDataCourseIndex;
play_sound2(SOUND_MENU_CURSOR_MOVE);
}
}
// If DPad/Stick right pressed, move selection right if not already in right-most column
if ((btnAndStick & R_JPAD) != 0) {
if ((gTimeTrialDataCourseIndex / 4) != 3) {
gTimeTrialDataCourseIndex += 4;
play_sound2(SOUND_MENU_CURSOR_MOVE);
}
}
// If DPad/Stick left pressed, move selection left if not already in left-most column
if ((btnAndStick & L_JPAD) != 0) {
if ((gTimeTrialDataCourseIndex / 4) != 0) {
gTimeTrialDataCourseIndex -= 4;
play_sound2(SOUND_MENU_CURSOR_MOVE);
}
}
// If B pressed, go to main menu
if ((btnAndStick & B_BUTTON) != 0) {
func_8009E258();
play_sound2(SOUND_MENU_GO_BACK);
return;
}
// If A pressed, go to selected course's records
if ((btnAndStick & A_BUTTON) != 0) {
gCourseRecordsMenuSelection = COURSE_RECORDS_MENU_RETURN_MENU;
func_8009E1C0();
play_sound2(SOUND_MENU_OK_CLICKED);
}
}
// If gSubMenuSelection is not SUB_MENU_DATA and A pressed, go to main menu
// This condition is not reachable but this failsafe was added nonetheless
else if ((btnAndStick & A_BUTTON) != 0) {
func_8009E258();
play_sound2(SOUND_MENU_OK_CLICKED);
}
}
}
/**
* Navigation of the course records data menu
*/
void course_data_menu_act(struct Controller* controller, UNUSED u16 controllerIdx) {
u16 btnAndStick; // sp2E
MenuItem* sp28;
CourseTimeTrialRecords* sp24;
s32 res;
btnAndStick = (controller->buttonPressed | controller->stickPressed);
if (!gEnableDebugMode && (btnAndStick & START_BUTTON)) {
btnAndStick |= A_BUTTON;
}
if (!is_screen_being_faded()) {
switch (gSubMenuSelection) {
case SUB_MENU_DATA_OPTIONS: {
if ((btnAndStick & L_JPAD) && (gTimeTrialDataCourseIndex > 0)) {
gTimeTrialDataCourseIndex -= 1;
play_sound2(SOUND_MENU_CURSOR_MOVE);
}
if ((btnAndStick & R_JPAD) && (gTimeTrialDataCourseIndex < 15)) {
gTimeTrialDataCourseIndex += 1;
play_sound2(SOUND_MENU_CURSOR_MOVE);
}
sp28 = find_menu_items_dupe(0xE8);
sp24 = &gSaveData.allCourseTimeTrialRecords.cupRecords[gTimeTrialDataCourseIndex / 4]
.courseRecords[gTimeTrialDataCourseIndex % 4];
if (gCourseRecordsMenuSelection == COURSE_RECORDS_MENU_ERASE_GHOST &&
func_800B639C(gTimeTrialDataCourseIndex) < 0) {
gCourseRecordsMenuSelection -= 1;
}
if (gCourseRecordsMenuSelection == COURSE_RECORDS_MENU_ERASE_RECORDS && sp24->unknownBytes[0] == 0) {
gCourseRecordsMenuSelection -= 1;
}
if ((btnAndStick & U_JPAD) && (gCourseRecordsMenuSelection > COURSE_RECORDS_MENU_MIN)) {
gCourseRecordsMenuSelection -= 1;
if (gCourseRecordsMenuSelection == 1 && sp24->unknownBytes[0] == 0) {
gCourseRecordsMenuSelection -= 1;
}
play_sound2(SOUND_MENU_CURSOR_MOVE);
if (sp28->paramf < 4.2) {
sp28->paramf += 4.0;
}
sp28->subState = -1;
}
if ((btnAndStick & D_JPAD) && (gCourseRecordsMenuSelection < COURSE_RECORDS_MENU_MAX)) {
gCourseRecordsMenuSelection += 1;
if (gCourseRecordsMenuSelection == COURSE_RECORDS_MENU_ERASE_RECORDS &&
sp24->unknownBytes[0] == 0) {
gCourseRecordsMenuSelection += 1;
}
if (gCourseRecordsMenuSelection == COURSE_RECORDS_MENU_ERASE_GHOST &&
func_800B639C(gTimeTrialDataCourseIndex) < 0) {
if (sp24->unknownBytes[0] == 0) {
gCourseRecordsMenuSelection = COURSE_RECORDS_MENU_RETURN_MENU;
} else {
gCourseRecordsMenuSelection = COURSE_RECORDS_MENU_ERASE_RECORDS;
}
} else {
play_sound2(SOUND_MENU_CURSOR_MOVE);
if (sp28->paramf < 4.2) {
sp28->paramf += 4.0;
}
sp28->subState = 1;
}
}
if (btnAndStick & B_BUTTON) {
func_8009E208();
play_sound2(SOUND_MENU_GO_BACK);
} else if (btnAndStick & A_BUTTON) {
if (sp28->paramf < 4.2) {
sp28->paramf += 4.0;
}
if (gCourseRecordsMenuSelection == COURSE_RECORDS_MENU_RETURN_MENU) {
func_8009E208();
play_sound2(SOUND_MENU_GO_BACK);
} else {
gSubMenuSelection = SUB_MENU_DATA_ERASE_CONFIRM;
gCourseRecordsSubMenuSelection = COURSE_RECORDS_SUB_MENU_QUIT;
play_sound2(SOUND_MENU_SELECT);
}
}
break;
}
case SUB_MENU_DATA_ERASE_CONFIRM: {
sp28 = find_menu_items_dupe(0xE9);
if ((btnAndStick & U_JPAD) && (gCourseRecordsSubMenuSelection > COURSE_RECORDS_SUB_MENU_MIN)) {
gCourseRecordsSubMenuSelection -= 1;
play_sound2(SOUND_MENU_CURSOR_MOVE);
if (sp28->paramf < 4.2) {
sp28->paramf += 4.0;
}
sp28->subState = -1;
}
if ((btnAndStick & D_JPAD) && (gCourseRecordsSubMenuSelection < COURSE_RECORDS_SUB_MENU_MAX)) {
gCourseRecordsSubMenuSelection += 1;
play_sound2(SOUND_MENU_CURSOR_MOVE);
if (sp28->paramf < 4.2) {
sp28->paramf += 4.0;
}
sp28->subState = 1;
}
if (btnAndStick & B_BUTTON) {
gSubMenuSelection = SUB_MENU_DATA_OPTIONS;
play_sound2(SOUND_MENU_GO_BACK);
} else if (btnAndStick & A_BUTTON) {
if (gCourseRecordsSubMenuSelection != COURSE_RECORDS_SUB_MENU_QUIT) {
res = 0;
switch (gCourseRecordsMenuSelection) {
case COURSE_RECORDS_MENU_ERASE_RECORDS: {
func_800B4728(gTimeTrialDataCourseIndex);
func_800B559C(gTimeTrialDataCourseIndex);
play_sound2(SOUND_MENU_EXPLOSION);
res = -1;
break;
}
case COURSE_RECORDS_MENU_ERASE_GHOST: {
res = func_800B639C(gTimeTrialDataCourseIndex);
if (res >= 0) {
if (func_800B69BC(res) != 0) {
gSubMenuSelection = SUB_MENU_DATA_CANT_ERASE;
play_sound2(SOUND_MENU_FILE_NOT_FOUND);
} else {
play_sound2(SOUND_MENU_EXPLOSION);
gSubMenuSelection = SUB_MENU_DATA_OPTIONS;
}
}
break;
}
}
if (!(res + 1)) {
gSubMenuSelection = SUB_MENU_DATA_OPTIONS;
}
} else {
play_sound2(SOUND_MENU_GO_BACK);
gSubMenuSelection = SUB_MENU_DATA_OPTIONS;
}
}
break;
}
case SUB_MENU_DATA_CANT_ERASE: {
if (btnAndStick & (A_BUTTON | B_BUTTON | START_BUTTON)) {
gSubMenuSelection = SUB_MENU_DATA_OPTIONS;
}
break;
}
}
}
}
/**
* On input skip logo screen
**/
void logo_intro_menu_act(struct Controller* controller, UNUSED u16 controllerIdx) {
u16 btnAndStick = (controller->buttonPressed | controller->stickPressed);
// If any button is pressed then fade audio out
if ((is_screen_being_faded() == 0) && (btnAndStick)) {
// TODO: Label audio functions
func_800CA388(0x3C);
func_8009E1E4();
}
}
/**
* Navigation of the controller pak table data
*/
void controller_pak_menu_act(struct Controller* controller, UNUSED u16 controllerIdx) {
u16 btnAndStick;
OSPfsState* osPfsState;
s32 selectedTableRow;
UNUSED s8 pad;
btnAndStick = controller->buttonPressed | controller->stickPressed;
if (is_screen_being_faded() == 0) {
switch (gControllerPakMenuSelection) {
case CONTROLLER_PAK_MENU_SELECT_RECORD:
if ((btnAndStick & (A_BUTTON | START_BUTTON)) != 0) {
gControllerPakMenuSelection = CONTROLLER_PAK_MENU_TABLE_GAME_DATA;
play_sound2(SOUND_MENU_SELECT);
return;
}
if ((btnAndStick & (L_JPAD | R_JPAD)) != 0) {
gControllerPakMenuSelection = CONTROLLER_PAK_MENU_END;
play_sound2(SOUND_MENU_CURSOR_MOVE);
return;
}
break;
case CONTROLLER_PAK_MENU_END:
if ((btnAndStick & (A_BUTTON | START_BUTTON)) != 0) {
play_sound2(SOUND_MENU_SELECT);
func_8009E1C0();
gControllerPak1State = BAD;
return;
}
if ((btnAndStick & (L_JPAD | R_JPAD)) != 0) {
gControllerPakMenuSelection = CONTROLLER_PAK_MENU_SELECT_RECORD;
play_sound2(SOUND_MENU_CURSOR_MOVE);
return;
}
break;
case CONTROLLER_PAK_MENU_TABLE_GAME_DATA:
if ((btnAndStick & (A_BUTTON | START_BUTTON)) != 0) {
selectedTableRow = gControllerPakVisibleTableRows[gControllerPakSelectedTableRow + 2] - 1;
if (pfsError[selectedTableRow] == 0) {
gControllerPakMenuSelection = CONTROLLER_PAK_MENU_QUIT;
play_sound2(SOUND_MENU_SELECT);
return;
}
} else if ((btnAndStick & B_BUTTON) != 0) {
if (gControllerPakScrollDirection == CONTROLLER_PAK_SCROLL_DIR_NONE) {
gControllerPakMenuSelection = CONTROLLER_PAK_MENU_SELECT_RECORD;
play_sound2(SOUND_MENU_GO_BACK);
return;
}
} else if ((btnAndStick & U_JPAD) != 0) {
if (gControllerPakScrollDirection == CONTROLLER_PAK_SCROLL_DIR_NONE) {
--gControllerPakSelectedTableRow;
if (gControllerPakSelectedTableRow < 0) {
gControllerPakSelectedTableRow = 0;
if (gControllerPakVisibleTableRows[gControllerPakSelectedTableRow + 2] != 1) {
gControllerPakScrollDirection = CONTROLLER_PAK_SCROLL_DIR_UP;
play_sound2(SOUND_MENU_CURSOR_MOVE);
return;
}
} else {
play_sound2(SOUND_MENU_CURSOR_MOVE);
return;
}
}
} else if (((btnAndStick & D_JPAD) != 0) &&
(gControllerPakScrollDirection == CONTROLLER_PAK_SCROLL_DIR_NONE)) {
++gControllerPakSelectedTableRow;
if (gControllerPakSelectedTableRow >= CONTROLLER_PAK_MENU_TABLE_GAME_DATA) {
gControllerPakSelectedTableRow = CONTROLLER_PAK_MENU_QUIT;
if (gControllerPakVisibleTableRows[gControllerPakSelectedTableRow + 2] != 16) {
gControllerPakScrollDirection = CONTROLLER_PAK_SCROLL_DIR_DOWN;
play_sound2(SOUND_MENU_CURSOR_MOVE);
return;
}
} else {
play_sound2(SOUND_MENU_CURSOR_MOVE);
return;
}
}
break;
case CONTROLLER_PAK_MENU_QUIT:
if ((btnAndStick & (A_BUTTON | B_BUTTON | START_BUTTON)) != 0) {
gControllerPakMenuSelection = CONTROLLER_PAK_MENU_TABLE_GAME_DATA;
play_sound2(SOUND_MENU_GO_BACK);
return;
}
if ((btnAndStick & (L_JPAD | R_JPAD)) != 0) {
gControllerPakMenuSelection = CONTROLLER_PAK_MENU_ERASE;
play_sound2(SOUND_MENU_CURSOR_MOVE);
return;
}
break;
case CONTROLLER_PAK_MENU_ERASE:
if ((btnAndStick & (A_BUTTON | START_BUTTON)) != 0) {
gControllerPakMenuSelection = CONTROLLER_PAK_MENU_GO_TO_ERASING;
play_sound2(SOUND_MENU_SELECT);
return;
}
if ((btnAndStick & B_BUTTON) != 0) {
gControllerPakMenuSelection = CONTROLLER_PAK_MENU_TABLE_GAME_DATA;
play_sound2(SOUND_MENU_GO_BACK);
return;
}
if ((btnAndStick & (L_JPAD | R_JPAD)) != 0) {
gControllerPakMenuSelection = CONTROLLER_PAK_MENU_QUIT;
play_sound2(SOUND_MENU_CURSOR_MOVE);
return;
}
break;
case CONTROLLER_PAK_MENU_GO_TO_ERASING:
gControllerPakMenuSelection = CONTROLLER_PAK_MENU_ERASING;
return;
case CONTROLLER_PAK_MENU_ERASING:
selectedTableRow = gControllerPakVisibleTableRows[gControllerPakSelectedTableRow + 2] - 1;
osPfsState = &pfsState[selectedTableRow];
switch (osPfsDeleteFile(&gControllerPak1FileHandle, osPfsState->company_code, osPfsState->game_code,
(u8*) &osPfsState->game_name, (u8*) &osPfsState->ext_name)) {
default:
gControllerPakMenuSelection = CONTROLLER_PAK_MENU_ERASE_ERROR_NOT_ERASED;
return;
case 0:
pfsError[selectedTableRow] = -1;
gControllerPak1NumPagesFree += (((osPfsState->file_size + 0xFF) >> 8) & 0xFF);