Skip to content

Commit

Permalink
libcommon: Rebuild the game menu on engine reset
Browse files Browse the repository at this point in the history
The game menu is now rebuilt following an engine reset. If the menu
was previously open it will be re-opened on the active page.

Todo: Remember the previously focused widget on the active page.
  • Loading branch information
danij-deng committed Jul 17, 2014
1 parent 298009a commit 3296ad7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
9 changes: 8 additions & 1 deletion doomsday/plugins/common/include/hu_menu.h
Expand Up @@ -111,7 +111,14 @@ void Hu_MenuTicker(timespan_t ticLength);
/// @return @c true if the menu is presently visible.
dd_bool Hu_MenuIsVisible();

menu::Page *Hu_MenuFindPageByName(char const *name);
menu::Page *Hu_MenuFindPageByName(de::String name);

/**
* Lookup the unique page identifier/name for the given @a page.
*
* @return Unique identifier/name of the page; otherwise an empty string.
*/
de::String Hu_MenuFindPageName(menu::Page const *page);

/**
* @param name Symbolic name.
Expand Down
43 changes: 38 additions & 5 deletions doomsday/plugins/common/src/hu_menu.cpp
Expand Up @@ -346,11 +346,11 @@ static menucommand_e chooseCloseMethod()
return Con_GetInteger("con-transition-tics") == 0? MCMD_CLOSE : MCMD_CLOSEFAST;
}

Page *Hu_MenuFindPageByName(char const *name)
Page *Hu_MenuFindPageByName(String name)
{
if(name && name[0])
if(!name.isEmpty())
{
Pages::iterator found = pages.find(String(name).toLower());
Pages::iterator found = pages.find(name.toLower());
if(found != pages.end())
{
return *found;
Expand All @@ -359,6 +359,22 @@ Page *Hu_MenuFindPageByName(char const *name)
return 0; // Not found.
}

String Hu_MenuFindPageName(Page const *page)
{
if(page)
{
Pages::const_iterator i = pages.constBegin();
while(i != pages.constEnd())
{
if(i.value() == page)
{
return i.key();
}
}
}
return "";
}

/// @todo Make this state an object property flag.
/// @return @c true if the rotation of a cursor on this object should be animated.
static dd_bool Hu_MenuHasCursorRotation(Widget *wi)
Expand Down Expand Up @@ -3558,8 +3574,18 @@ Page *Hu_MenuNewPage(char const *name, Point2Raw const *origin, int flags,
void Hu_MenuInit()
{
cvarbutton_t *cvb;
bool wasOpen = false;
String activePageName;

if(inited)
{
// Remember the previously open menu page, if any.
/// @todo Remember the previously focused widget on said page -ds
wasOpen = Hu_MenuIsActive();
activePageName = Hu_MenuFindPageName(Hu_MenuActivePage());

if(inited) return;
Hu_MenuShutdown();
}

mnAlpha = mnTargetAlpha = 0;
menuActivePage = 0;
Expand Down Expand Up @@ -3594,6 +3620,13 @@ void Hu_MenuInit()
}
#endif

// Are we re-opening?
if(wasOpen)
{
Hu_MenuCommand(MCMD_OPEN);
}
Hu_MenuSetActivePage(Hu_MenuFindPageByName(activePageName));

inited = true;
}

Expand Down Expand Up @@ -3686,7 +3719,7 @@ void Hu_MenuTicker(timespan_t ticLength)
#undef MENUALPHA_FADE_STEP
}

Page* Hu_MenuActivePage()
Page *Hu_MenuActivePage()
{
return menuActivePage;
}
Expand Down

0 comments on commit 3296ad7

Please sign in to comment.