From f68c63703eb8ca5c84b1e2a2bcf93568c9e25db5 Mon Sep 17 00:00:00 2001 From: Arceveti <73617174+Arceveti@users.noreply.github.com> Date: Wed, 29 Sep 2021 12:00:37 -0700 Subject: [PATCH] Improve debug level select controls --- src/menu/title_screen.c | 85 ++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/src/menu/title_screen.c b/src/menu/title_screen.c index abe8f743..70827fa2 100644 --- a/src/menu/title_screen.c +++ b/src/menu/title_screen.c @@ -84,63 +84,68 @@ s32 run_level_id_or_demo(s32 level) { #endif #endif + +u8 gLevelSelectHoldKeyIndex = 0; +u8 gLevelSelectHoldKeyTimer = 0; + /** * Level select intro function, updates the selected stage * count if an input was received. signals the stage to be started * or the level select to be exited if start or the quit combo is pressed. */ -s16 intro_level_select(void) { //! this function runs and crashes on save+quit even if level select is disabled - s32 stageChanged = FALSE; - - // perform the ID updates per each button press. - // runs into a loop so after a button is pressed - // stageChanged goes back to FALSE - if (gPlayer1Controller->buttonPressed & A_BUTTON) { - ++gCurrLevelNum, stageChanged = TRUE; +s16 intro_level_select(void) { + u32 index = 0; + if ((gPlayer1Controller->rawStickY < -60) + || (gPlayer1Controller->rawStickX < -60) + || (gPlayer1Controller->buttonDown & (D_CBUTTONS | D_JPAD | L_CBUTTONS | L_JPAD))) index++; + if ((gPlayer1Controller->rawStickY > 60) + || (gPlayer1Controller->rawStickX > 60) + || (gPlayer1Controller->buttonDown & (U_CBUTTONS | U_JPAD | R_CBUTTONS | R_JPAD))) index += 2; + if (((index ^ gLevelSelectHoldKeyIndex) & index) == 2) { + if (gCurrLevelNum > LEVEL_MAX) { + gCurrLevelNum = LEVEL_MIN; + } else if (gPlayer3Controller->buttonDown & B_BUTTON) { + play_sound(SOUND_GENERAL_LEVEL_SELECT_CHANGE, gGlobalSoundSource); + gCurrLevelNum += 10; + } else { + play_sound(SOUND_GENERAL_LEVEL_SELECT_CHANGE, gGlobalSoundSource); + gCurrLevelNum++; + } } - if (gPlayer1Controller->buttonPressed & B_BUTTON) { - --gCurrLevelNum, stageChanged = TRUE; + if (((index ^ gLevelSelectHoldKeyIndex) & index) == 1) { + if (gCurrLevelNum < LEVEL_MIN) { + // Same applies to here as above + gCurrLevelNum = LEVEL_MAX; + } else if (gPlayer3Controller->buttonDown & B_BUTTON) { + play_sound(SOUND_GENERAL_LEVEL_SELECT_CHANGE, gGlobalSoundSource); + gCurrLevelNum -= 10; + } else { + play_sound(SOUND_GENERAL_LEVEL_SELECT_CHANGE, gGlobalSoundSource); + gCurrLevelNum--; + } } - if (gPlayer1Controller->buttonPressed & U_JPAD) { - --gCurrLevelNum, stageChanged = TRUE; + if (gLevelSelectHoldKeyTimer == 10) { + gLevelSelectHoldKeyTimer = 8; + gLevelSelectHoldKeyIndex = 0; + } else { + gLevelSelectHoldKeyTimer++; + gLevelSelectHoldKeyIndex = index; } - if (gPlayer1Controller->buttonPressed & D_JPAD) { - ++gCurrLevelNum, stageChanged = TRUE; - } - if (gPlayer1Controller->buttonPressed & L_JPAD) { - gCurrLevelNum -= 10, stageChanged = TRUE; - } - if (gPlayer1Controller->buttonPressed & R_JPAD) { - gCurrLevelNum += 10, stageChanged = TRUE; - } - - // if the stage was changed, play the sound for changing a stage. - if (stageChanged) { - play_sound(SOUND_GENERAL_LEVEL_SELECT_CHANGE, gGlobalSoundSource); - } - - if (gCurrLevelNum > LEVEL_MAX) { - gCurrLevelNum = LEVEL_MIN; // exceeded max. set to min. - } - - if (gCurrLevelNum < LEVEL_MIN) { - gCurrLevelNum = LEVEL_MAX; // exceeded min. set to max. - } - + if ((index & 0x3) == 0) gLevelSelectHoldKeyTimer = 0; + if (gCurrLevelNum > LEVEL_MAX) gCurrLevelNum = LEVEL_MIN; // exceeded max. set to min. + if (gCurrLevelNum < LEVEL_MIN) gCurrLevelNum = LEVEL_MAX; // exceeded min. set to max. // Use file 4 and last act as a test gCurrSaveFileNum = 4; - gCurrActNum = 6; - + gCurrActNum = 6; print_text_centered(160, 80, "SELECT STAGE"); print_text_centered(160, 30, "PRESS START BUTTON"); print_text_fmt_int(40, 60, "%2d", gCurrLevelNum); print_text(80, 60, sLevelSelectStageNames[gCurrLevelNum - 1]); // print stage name - // start being pressed signals the stage to be started. that is, unless... - if (gPlayer1Controller->buttonPressed & START_BUTTON) { + if (gPlayer1Controller->buttonPressed & (START_BUTTON | A_BUTTON)) { // ... the level select quit combo is being pressed, which uses START. If this // is the case, quit the menu instead. - if (gPlayer1Controller->buttonDown == (Z_TRIG | START_BUTTON | L_CBUTTONS | R_CBUTTONS)) { + if (gPlayer1Controller->buttonDown == (Z_TRIG | START_BUTTON | L_CBUTTONS)) { // quit level select gDebugLevelSelect = FALSE; return LEVEL_RESTART_GAME; }