From 60fcb6527c95a59219664bf041178883a740c6fa Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Mon, 9 Oct 2017 07:36:55 +0000 Subject: [PATCH] Menus: If you open the Help menu with the F1 key, make Help the selected item on the main menu, if applicable. git-svn-id: https://svn.eduke32.com/eduke32@6466 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/game.cpp | 2 +- source/duke3d/src/menus.cpp | 41 ++++++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index ccd0369e3..6dd377467 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -4743,7 +4743,7 @@ void G_HandleLocalKeys(void) typebuf[0] = 0; } - if (!KXDWN && (KB_UnBoundKeyPressed(sc_F1)/* || (ud.show_help && I_AdvanceTrigger())*/)) + if (KB_UnBoundKeyPressed(sc_F1)/* || (ud.show_help && I_AdvanceTrigger())*/) { KB_ClearKeyDown(sc_F1); diff --git a/source/duke3d/src/menus.cpp b/source/duke3d/src/menus.cpp index 6d6e5f9bc..db93e7c80 100644 --- a/source/duke3d/src/menus.cpp +++ b/source/duke3d/src/menus.cpp @@ -322,8 +322,8 @@ static MenuLink_t MEO_MAIN_NEWGAME_NETWORK = { MENU_NETWORK, MA_Advance, }; MAKE_MENU_TOP_ENTRYLINK( s_SaveGame, MEF_MainMenu, MAIN_SAVEGAME, MENU_SAVE ); MAKE_MENU_TOP_ENTRYLINK( s_LoadGame, MEF_MainMenu, MAIN_LOADGAME, MENU_LOAD ); MAKE_MENU_TOP_ENTRYLINK( s_Options, MEF_MainMenu, MAIN_OPTIONS, MENU_OPTIONS ); -#ifndef EDUKE32_SIMPLE_MENU MAKE_MENU_TOP_ENTRYLINK( "Help", MEF_MainMenu, MAIN_HELP, MENU_STORY ); +#ifndef EDUKE32_SIMPLE_MENU MAKE_MENU_TOP_ENTRYLINK( s_Credits, MEF_MainMenu, MAIN_CREDITS, MENU_CREDITS ); #endif MAKE_MENU_TOP_ENTRYLINK( "End Game", MEF_MainMenu, MAIN_QUITTOTITLE, MENU_QUITTOTITLE ); @@ -336,8 +336,8 @@ static MenuEntry_t *MEL_MAIN[] = { &ME_MAIN_NEWGAME, &ME_MAIN_LOADGAME, &ME_MAIN_OPTIONS, -#ifndef EDUKE32_SIMPLE_MENU &ME_MAIN_HELP, +#ifndef EDUKE32_SIMPLE_MENU &ME_MAIN_CREDITS, #endif &ME_MAIN_QUIT, @@ -352,12 +352,10 @@ static MenuEntry_t *MEL_MAIN_INGAME[] = { &ME_MAIN_SAVEGAME, &ME_MAIN_LOADGAME, &ME_MAIN_OPTIONS, -#ifndef EDUKE32_SIMPLE_MENU &ME_MAIN_HELP, &ME_MAIN_QUITTOTITLE, +#ifndef EDUKE32_SIMPLE_MENU &ME_MAIN_QUITGAME, -#else - &ME_MAIN_QUITTOTITLE, #endif }; @@ -3613,6 +3611,28 @@ void Menu_AnimateChange(int32_t cm, MenuAnimationType_t animtype) } } +static void Menu_MaybeSetSelectionToChild(Menu_t * m, MenuID_t id) +{ + if (m->type == Menu) + { + MenuMenu_t * menu = (MenuMenu_t *)m->object; + + for (size_t i = 0, i_end = menu->numEntries; i < i_end; ++i) + { + MenuEntry_t const * entry = menu->entrylist[i]; + if (entry != NULL && entry->type == Link) + { + MenuLink_t const * link = (MenuLink_t const *)entry->entry; + if (link->linkID == id) + { + menu->currentEntry = i; + break; + } + } + } + } +} + static void Menu_AboutToStartDisplaying(Menu_t * m) { switch (m->menuID) @@ -3740,7 +3760,7 @@ static void Menu_ChangingTo(Menu_t * m) int Menu_Change(MenuID_t cm) { - Menu_t *search; + Menu_t * beginMenu = m_currentMenu; cm = VM_OnEventWithReturn(EVENT_CHANGEMENU, g_player[myconnectindex].ps->i, myconnectindex, cm); @@ -3753,7 +3773,7 @@ int Menu_Change(MenuID_t cm) Menu_Close(myconnectindex); else if (cm >= 0) { - search = Menu_FindFiltered(cm); + Menu_t * search = Menu_FindFiltered(cm); if (search == NULL) return 0; // intentional, so that users don't use any random value as "don't change" @@ -3776,8 +3796,15 @@ int Menu_Change(MenuID_t cm) } m_parentMenu = result; + + if (result) + { + Menu_MaybeSetSelectionToChild(result, m_currentMenu->menuID); + Menu_AboutToStartDisplaying(result); + } } + Menu_MaybeSetSelectionToChild(m_currentMenu, beginMenu->menuID); Menu_AboutToStartDisplaying(m_currentMenu); Menu_ChangingTo(m_currentMenu);