From a10fe991f263f4a1d32286a06c1dc708ea175e05 Mon Sep 17 00:00:00 2001 From: pvictress Date: Sun, 10 Nov 2024 12:07:38 +0300 Subject: [PATCH] Allow to choose ESC key behaviour --- src/doom/m_menu.c | 35 ++++++++++++++++++++++++++++++++++- src/heretic/mn_menu.c | 35 ++++++++++++++++++++++++++++++++++- src/hexen/mn_menu.c | 35 ++++++++++++++++++++++++++++++++++- src/id_vars.c | 2 ++ src/id_vars.h | 1 + src/m_config.c | 2 ++ 6 files changed, 107 insertions(+), 3 deletions(-) diff --git a/src/doom/m_menu.c b/src/doom/m_menu.c index a7712f6..ff8dce3 100644 --- a/src/doom/m_menu.c +++ b/src/doom/m_menu.c @@ -750,6 +750,7 @@ static void M_Choose_ID_Misc (int choice); static void M_Draw_ID_Misc (void); static void M_ID_Misc_AutoloadWAD (int choice); static void M_ID_Misc_AutoloadDEH (int choice); +static void M_ID_Misc_MenuEscKey (int choice); static void M_Choose_ID_Level (int choice); static void M_Draw_ID_Level_1 (void); @@ -3795,11 +3796,13 @@ static menuitem_t ID_Menu_Misc[]= { { M_LFRT, "AUTOLOAD WAD FILES", M_ID_Misc_AutoloadWAD, 'a' }, { M_LFRT, "AUTOLOAD DEH FILES", M_ID_Misc_AutoloadDEH, 'a' }, + { M_SKIP, "", 0, '\0' }, + { M_LFRT, "ESC KEY BEHAVIOUR", M_ID_Misc_MenuEscKey, 'e' }, }; static menu_t ID_Def_Misc = { - 2, + 4, &ID_Def_Main, ID_Menu_Misc, M_Draw_ID_Misc, @@ -3833,6 +3836,13 @@ static void M_Draw_ID_Misc (void) M_Item_Glow(1, autoload_deh == 1 ? GLOW_YELLOW : autoload_deh == 2 ? GLOW_GREEN : GLOW_DARKRED)); + M_WriteTextCentered(36, "MENU SETTINGS", cr[CR_YELLOW]); + + // ESC key behaviour + sprintf(str, menu_esc_key ? "GO BACK" : "CLOSE MENU" ); + M_WriteText (M_ItemRightAlign(str), 45, str, + M_Item_Glow(3, menu_esc_key ? GLOW_GREEN : GLOW_DARKRED)); + // [PN] Added explanations for autoload variables if (itemOn == 0 || itemOn == 1) { @@ -3871,6 +3881,11 @@ static void M_ID_Misc_AutoloadDEH (int choice) autoload_deh = M_INT_Slider(autoload_deh, 0, 2, choice, false); } +static void M_ID_Misc_MenuEscKey (int choice) +{ + menu_esc_key ^= 1; +} + // ----------------------------------------------------------------------------- // Level select 1 // ----------------------------------------------------------------------------- @@ -6215,14 +6230,32 @@ boolean M_Responder (event_t* ev) } else if (key == key_menu_activate) { + // [JN] If ESC key behaviour is set to "go back": + if (menu_esc_key) + { + if (currentMenu == &MainDef || currentMenu == &SoundDef + || currentMenu == &LoadDef || currentMenu == &SaveDef) + { + goto id_close_menu; // [JN] Close menu imideatelly. + } + else + { + goto id_prev_menu; // [JN] Go to previous menu. + } + } + else + { + id_close_menu: // Deactivate menu currentMenu->lastOn = itemOn; M_ClearMenus(); S_StartSound(NULL,sfx_swtchx); + } return true; } else if (key == key_menu_back) { + id_prev_menu: // Go back to previous menu currentMenu->lastOn = itemOn; diff --git a/src/heretic/mn_menu.c b/src/heretic/mn_menu.c index 4928fed..e5040d6 100644 --- a/src/heretic/mn_menu.c +++ b/src/heretic/mn_menu.c @@ -627,6 +627,7 @@ static void M_DrawGameplayFooter (char *pagenum); static void M_Draw_ID_Misc (void); static void M_ID_Misc_AutoloadWAD (int choice); static void M_ID_Misc_AutoloadHHE (int choice); +static void M_ID_Misc_MenuEscKey (int choice); static void M_Draw_ID_Level_1 (void); static void M_ID_LevelSkill (int choice); @@ -3557,12 +3558,14 @@ static void M_DrawGameplayFooter (char *pagenum) static MenuItem_t ID_Menu_Misc[] = { { ITT_LRFUNC, "AUTOLOAD WAD FILES", M_ID_Misc_AutoloadWAD, 0, MENU_NONE }, { ITT_LRFUNC, "AUTOLOAD HHE FILES", M_ID_Misc_AutoloadHHE, 0, MENU_NONE }, + { ITT_EMPTY, NULL, NULL, 0, MENU_NONE }, + { ITT_LRFUNC, "ESC KEY BEHAVIOUR", M_ID_Misc_MenuEscKey, 0, MENU_NONE }, }; static Menu_t ID_Def_Misc = { ID_MENU_CTRLSOFFSET, ID_MENU_TOPOFFSET, M_Draw_ID_Misc, - 2, ID_Menu_Misc, + 4, ID_Menu_Misc, 0, SmallFont, false, true, MENU_ID_MAIN @@ -3588,6 +3591,13 @@ static void M_Draw_ID_Misc (void) M_Item_Glow(1, autoload_hhe == 1 ? GLOW_YELLOW : autoload_hhe == 2 ? GLOW_GREEN : GLOW_DARKRED)); + MN_DrTextACentered("MENU SETTINGS", 40, cr[CR_YELLOW]); + + // ESC key behaviour + sprintf(str, menu_esc_key ? "GO BACK" : "CLOSE MENU" ); + MN_DrTextA(str, M_ItemRightAlign(str), 50, + M_Item_Glow(3, menu_esc_key ? GLOW_GREEN : GLOW_DARKRED)); + // [PN] Added explanations for autoload variables if (CurrentItPos == 0 || CurrentItPos == 1) { @@ -3626,6 +3636,11 @@ static void M_ID_Misc_AutoloadHHE (int choice) autoload_hhe = M_INT_Slider(autoload_hhe, 0, 2, choice, false); } +static void M_ID_Misc_MenuEscKey (int choice) +{ + menu_esc_key ^= 1; +} + // ----------------------------------------------------------------------------- // Level select 1 // ----------------------------------------------------------------------------- @@ -6144,11 +6159,29 @@ boolean MN_Responder(event_t * event) } else if (key == key_menu_activate) // Toggle menu { + // [JN] If ESC key behaviour is set to "go back": + if (menu_esc_key) + { + if (CurrentMenu == &MainMenu || CurrentMenu == &Options2Menu + || CurrentMenu == &LoadMenu || CurrentMenu == &SaveMenu) + { + goto id_close_menu; // [JN] Close menu imideatelly. + } + else + { + goto id_prev_menu; // [JN] Go to previous menu. + } + } + else + { + id_close_menu: MN_DeactivateMenu(); + } return (true); } else if (key == key_menu_back) // Go back to previous menu { + id_prev_menu: S_StartSound(NULL, sfx_switch); if (CurrentMenu->prevMenu == MENU_NONE) { diff --git a/src/hexen/mn_menu.c b/src/hexen/mn_menu.c index 62edd01..59cfd5e 100644 --- a/src/hexen/mn_menu.c +++ b/src/hexen/mn_menu.c @@ -630,6 +630,7 @@ static void M_DrawGameplayFooter (char *pagenum); static void M_Draw_ID_Misc (void); static void M_ID_Misc_AutoloadWAD (int choice); +static void M_ID_Misc_MenuEscKey (int choice); static void M_ID_SettingReset (int choice); static void M_ID_ApplyReset (void); @@ -3457,12 +3458,14 @@ static void M_DrawGameplayFooter (char *pagenum) static MenuItem_t ID_Menu_Misc[] = { { ITT_LRFUNC, "AUTOLOAD WAD FILES", M_ID_Misc_AutoloadWAD, 0, MENU_NONE }, + { ITT_EMPTY, NULL, NULL, 0, MENU_NONE }, + { ITT_LRFUNC, "ESC KEY BEHAVIOUR", M_ID_Misc_MenuEscKey, 0, MENU_NONE }, }; static Menu_t ID_Def_Misc = { ID_MENU_CTRLSOFFSET, ID_MENU_TOPOFFSET, M_Draw_ID_Misc, - 1, ID_Menu_Misc, + 3, ID_Menu_Misc, 0, SmallFont, false, true, MENU_ID_MAIN @@ -3481,6 +3484,13 @@ static void M_Draw_ID_Misc (void) M_Item_Glow(0, autoload_wad == 1 ? GLOW_YELLOW : autoload_wad == 2 ? GLOW_GREEN : GLOW_DARKRED)); + MN_DrTextACentered("MENU SETTINGS", 30, cr[CR_YELLOW]); + + // ESC key behaviour + sprintf(str, menu_esc_key ? "GO BACK" : "CLOSE MENU" ); + MN_DrTextA(str, M_ItemRightAlign(str), 40, + M_Item_Glow(2, menu_esc_key ? GLOW_GREEN : GLOW_DARKRED)); + // [PN] Added explanations for autoload variables if (CurrentItPos == 0) { @@ -3513,6 +3523,11 @@ static void M_ID_Misc_AutoloadWAD (int choice) autoload_wad = M_INT_Slider(autoload_wad, 0, 2, choice, false); } +static void M_ID_Misc_MenuEscKey (int choice) +{ + menu_esc_key ^= 1; +} + // ----------------------------------------------------------------------------- // Reset settings @@ -5609,11 +5624,29 @@ boolean MN_Responder(event_t * event) } else if (key == key_menu_activate) { + // [JN] If ESC key behaviour is set to "go back": + if (menu_esc_key) + { + if (CurrentMenu == &MainMenu || CurrentMenu == &Options2Menu + || CurrentMenu == &LoadMenu || CurrentMenu == &SaveMenu) + { + goto id_close_menu; // [JN] Close menu imideatelly. + } + else + { + goto id_prev_menu; // [JN] Go to previous menu. + } + } + else + { + id_close_menu: MN_DeactivateMenu(); + } return (true); } else if (key == key_menu_back) { + id_prev_menu: S_StartSound(NULL, SFX_PICKUP_KEY); if (CurrentMenu->prevMenu == MENU_NONE) diff --git a/src/id_vars.c b/src/id_vars.c index fbe8ec9..7a9f169 100644 --- a/src/id_vars.c +++ b/src/id_vars.c @@ -180,6 +180,7 @@ int autoload_wad = 1; int autoload_deh = 1; int autoload_hhe = 1; int autoload_seh = 1; +int menu_esc_key = 0; // ----------------------------------------------------------------------------- // [JN] ID-specific config variables binding functions. @@ -413,4 +414,5 @@ void ID_BindVariables (GameMission_t mission) { M_BindIntVariable("autoload_seh", &autoload_seh); } + M_BindIntVariable("menu_esc_key", &menu_esc_key); } diff --git a/src/id_vars.h b/src/id_vars.h index 4276796..cb8aeef 100644 --- a/src/id_vars.h +++ b/src/id_vars.h @@ -151,6 +151,7 @@ extern int autoload_wad; extern int autoload_deh; extern int autoload_hhe; extern int autoload_seh; +extern int menu_esc_key; // Mouse look extern int mouse_look; diff --git a/src/m_config.c b/src/m_config.c index 59dd537..b60ac5e 100644 --- a/src/m_config.c +++ b/src/m_config.c @@ -585,6 +585,8 @@ static default_t doom_defaults_list[] = CONFIG_VARIABLE_INT(compat_pistol_start), CONFIG_VARIABLE_INT(compat_blockmap_fix), CONFIG_VARIABLE_INT(compat_vertical_aiming), + + CONFIG_VARIABLE_INT(menu_esc_key), }; static default_collection_t doom_defaults =