Skip to content

Commit

Permalink
Allow to choose ESC key behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
JNechaevsky committed Nov 10, 2024
1 parent 1ca6c5d commit a10fe99
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 3 deletions.
35 changes: 34 additions & 1 deletion src/doom/m_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -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;

Expand Down
35 changes: 34 additions & 1 deletion src/heretic/mn_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -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)
{
Expand Down
35 changes: 34 additions & 1 deletion src/hexen/mn_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/id_vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -413,4 +414,5 @@ void ID_BindVariables (GameMission_t mission)
{
M_BindIntVariable("autoload_seh", &autoload_seh);
}
M_BindIntVariable("menu_esc_key", &menu_esc_key);
}
1 change: 1 addition & 0 deletions src/id_vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/m_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit a10fe99

Please sign in to comment.