From 721d5d9da99e0cc544849270d1da97bd3d25cfd8 Mon Sep 17 00:00:00 2001 From: toaster Date: Tue, 27 Jun 2023 17:45:27 +0100 Subject: [PATCH] Improve M_HandlePauseMenuGametype and M_HandleHostMenuGametype Simplify massively by using IT_ARROWS --- src/k_menudraw.c | 2 +- src/menus/play-online-1.c | 2 +- src/menus/play-online-host.c | 38 ++++++++------------------------ src/menus/transient/pause-game.c | 34 ++++++++++++++-------------- 4 files changed, 27 insertions(+), 49 deletions(-) diff --git a/src/k_menudraw.c b/src/k_menudraw.c index 6df9183da..bd2ae614a 100644 --- a/src/k_menudraw.c +++ b/src/k_menudraw.c @@ -3065,7 +3065,7 @@ void M_DrawMPHost(void) } break; } - case IT_KEYHANDLER: + case IT_ARROWS: { if (currentMenu->menuitems[i].itemaction.routine != M_HandleHostMenuGametype) break; diff --git a/src/menus/play-online-1.c b/src/menus/play-online-1.c index 8a9b74234..7f9a9c294 100644 --- a/src/menus/play-online-1.c +++ b/src/menus/play-online-1.c @@ -80,8 +80,8 @@ void M_MPOptSelectInit(INT32 choice) memcpy(&mpmenu.modewinextend, &arrcpy, sizeof(mpmenu.modewinextend)); // Guarantee menugametype is good - M_NextMenuGametype(forbidden); M_PrevMenuGametype(forbidden); + M_NextMenuGametype(forbidden); if (choice != -1) { diff --git a/src/menus/play-online-host.c b/src/menus/play-online-host.c index 7ab684c5c..a7061a32a 100644 --- a/src/menus/play-online-host.c +++ b/src/menus/play-online-host.c @@ -18,7 +18,7 @@ menuitem_t PLAY_MP_Host[] = {IT_STRING | IT_CVAR, "Max. Players", "Set how many players can play at once. Others will spectate.", NULL, {.cvar = &cv_maxplayers}, 0, 0}, - {IT_STRING | IT_KEYHANDLER, "Gamemode", "Choose the type of play on your server.", + {IT_STRING | IT_ARROWS, "Gamemode", "Choose the type of play on your server.", NULL, {.routine = M_HandleHostMenuGametype}, 0, 0}, {IT_STRING | IT_CALL, "GO", "Select a map with the currently selected gamemode", @@ -54,41 +54,21 @@ void M_MPHostInit(INT32 choice) void M_HandleHostMenuGametype(INT32 choice) { - const UINT8 pid = 0; const UINT32 forbidden = GTR_FORBIDMP; - (void)choice; - - if (M_MenuBackPressed(pid)) - { - M_GoBack(0); - M_SetMenuDelay(pid); - return; - } - else if (menucmd[pid].dpad_lr > 0 || M_MenuConfirmPressed(pid)) + if (choice > 0) { M_NextMenuGametype(forbidden); - S_StartSound(NULL, sfx_s3k5b); - M_SetMenuDelay(pid); } - else if (menucmd[pid].dpad_lr < 0) + else if (choice == -1) + { + menugametype = GT_RACE; + M_PrevMenuGametype(forbidden); + M_NextMenuGametype(forbidden); + } + else { M_PrevMenuGametype(forbidden); - S_StartSound(NULL, sfx_s3k5b); - M_SetMenuDelay(pid); - } - - if (menucmd[pid].dpad_ud > 0) - { - M_NextOpt(); - S_StartSound(NULL, sfx_s3k5b); - M_SetMenuDelay(pid); - } - else if (menucmd[pid].dpad_ud < 0) - { - M_PrevOpt(); - S_StartSound(NULL, sfx_s3k5b); - M_SetMenuDelay(pid); } } diff --git a/src/menus/transient/pause-game.c b/src/menus/transient/pause-game.c index c3b640ea8..e43f05d5d 100644 --- a/src/menus/transient/pause-game.c +++ b/src/menus/transient/pause-game.c @@ -22,7 +22,7 @@ menuitem_t PAUSE_Main[] = {IT_STRING | IT_CALL, "STEREO MODE", "M_ICOSTM", NULL, {.routine = M_SoundTest}, 0, 0}, - {IT_STRING | IT_KEYHANDLER, "GAMETYPE", "M_ICOGAM", + {IT_STRING | IT_ARROWS, "GAMETYPE", "M_ICOGAM", NULL, {.routine = M_HandlePauseMenuGametype}, 0, 0}, {IT_STRING | IT_CALL, "CHANGE MAP", "M_ICOMAP", @@ -71,7 +71,7 @@ menu_t PAUSE_MainDef = { PAUSE_Main, 0, 0, 0, 0, - 0, + MBF_SOUNDLESS, NULL, 1, 10, // For transition with some menus! M_DrawPause, @@ -146,7 +146,7 @@ void M_OpenPauseMenu(void) if (server || IsPlayerAdmin(consoleplayer)) { - PAUSE_Main[mpause_changegametype].status = IT_STRING | IT_KEYHANDLER; + PAUSE_Main[mpause_changegametype].status = IT_STRING | IT_ARROWS; menugametype = gametype; PAUSE_Main[mpause_switchmap].status = IT_STRING | IT_CALL; @@ -267,12 +267,9 @@ boolean M_PauseInputs(INT32 ch) // Change gametype void M_HandlePauseMenuGametype(INT32 choice) { - const UINT8 pid = 0; const UINT32 forbidden = GTR_FORBIDMP; - (void)choice; - - if (M_MenuConfirmPressed(pid)) + if (choice == 2) { if (menugametype != gametype) { @@ -281,26 +278,27 @@ void M_HandlePauseMenuGametype(INT32 choice) return; } - M_SetMenuDelay(pid); S_StartSound(NULL, sfx_s3k7b); + + return; } - else if (M_MenuExtraPressed(pid)) + + if (choice == -1) { menugametype = gametype; - M_SetMenuDelay(pid); S_StartSound(NULL, sfx_s3k7b); + return; } - else if (menucmd[pid].dpad_lr > 0) - { - M_NextMenuGametype(forbidden); - S_StartSound(NULL, sfx_s3k5b); - M_SetMenuDelay(pid); - } - else if (menucmd[pid].dpad_lr < 0) + + if (choice == 0) { M_PrevMenuGametype(forbidden); S_StartSound(NULL, sfx_s3k5b); - M_SetMenuDelay(pid); + } + else + { + M_NextMenuGametype(forbidden); + S_StartSound(NULL, sfx_s3k5b); } }