Skip to content

Commit

Permalink
libcommon|Menu: Convenient method to change the menu to a named page
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Sep 16, 2014
1 parent a818726 commit c0e9e85
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
22 changes: 18 additions & 4 deletions doomsday/plugins/common/include/hu_menu.h
Expand Up @@ -126,23 +126,37 @@ bool Hu_MenuHasPage(de::String name);

/**
* Returns the currently configured menu Page.
* @see Hu_MenuHasActivePage()
* @see Hu_MenuHasPage()
*/
menu::Page &Hu_MenuPage();

inline menu::Page *Hu_MenuPagePtr() { return Hu_MenuHasPage()? &Hu_MenuPage() : 0; }
inline menu::Page *Hu_MenuPagePtr() {
return Hu_MenuHasPage()? &Hu_MenuPage() : 0;
}

/**
* Lookup a Page with the unique identifier @a name.
* @see Hu_MenuHasPage()
*/
menu::Page &Hu_MenuPage(de::String name);

inline menu::Page *Hu_MenuPagePtr(de::String name) { return Hu_MenuHasPage(name)? &Hu_MenuPage(name) : 0; }
inline menu::Page *Hu_MenuPagePtr(de::String name) {
return Hu_MenuHasPage(name)? &Hu_MenuPage(name) : 0;
}

/**
* Change the current menu Page to @a page.
* @see Hu_MenuPage(), Hu_MenuHasPage()
*/
void Hu_MenuSetPage(menu::Page *page, bool canReactivate = false);
void Hu_MenuSetPage(menu::Page *page, bool allowReactivate = false);

/**
* Convenient method for changing the current menu page to that with the @a name given.
* @see Hu_MenuSetPage()
*/
inline void Hu_MenuSetPage(de::String name, bool allowReactivate = false) {
Hu_MenuSetPage(Hu_MenuPagePtr(name), allowReactivate);
}

/**
* Lookup the unique identifier/name for the given @a page.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -2524,7 +2524,7 @@ D_CMD(SaveSession)
{
// No quick-save slot has been nominated - allow doing so now.
Hu_MenuCommand(MCMD_OPEN);
Hu_MenuSetPage(Hu_MenuPagePtr("SaveGame"));
Hu_MenuSetPage("SaveGame");
menuNominatingQuickSaveSlot = true;
return true;
}
Expand Down
20 changes: 10 additions & 10 deletions doomsday/plugins/common/src/hu_menu.cpp
Expand Up @@ -3453,7 +3453,7 @@ void Hu_MenuCommand(menucommand_e cmd)
menuTime = 0;

currentPage = NULL; // Always re-activate this page.
Hu_MenuSetPage(Hu_MenuPagePtr("Main"));
Hu_MenuSetPage("Main");

// Enable the menu binding class
DD_Execute(true, "activatebcontext menu");
Expand Down Expand Up @@ -3941,14 +3941,14 @@ void Hu_MenuSelectSingleplayer(Widget * /*wi*/, Widget::mn_actionid_t action)
DictionaryValue::Elements const &episodesById = Defs().episodes.lookup("id").elements();
mnEpisode = episodesById.begin()->second->as<RecordValue>().record()->gets("id");
#if __JHEXEN__
Hu_MenuSetPage(Hu_MenuPagePtr("PlayerClass"));
Hu_MenuSetPage("PlayerClass");
#else
Hu_MenuSetPage(Hu_MenuPagePtr("Skill"));
Hu_MenuSetPage("Skill");
#endif
}
else
{
Hu_MenuSetPage(Hu_MenuPagePtr("Episode"));
Hu_MenuSetPage("Episode");
}
}

Expand Down Expand Up @@ -4082,7 +4082,7 @@ void Hu_MenuSelectAcceptPlayerSetup(Widget *wi, Widget::mn_actionid_t action)
DD_Executef(false, "setcolor %i", cfg.netColor);
}

Hu_MenuSetPage(Hu_MenuPagePtr("Multiplayer"));
Hu_MenuSetPage("Multiplayer");
}

void Hu_MenuSelectQuitGame(Widget * /*wi*/, Widget::mn_actionid_t action)
Expand Down Expand Up @@ -4110,7 +4110,7 @@ void Hu_MenuSelectLoadGame(Widget * /*wi*/, Widget::mn_actionid_t action)
}
}

Hu_MenuSetPage(Hu_MenuPagePtr("LoadGame"));
Hu_MenuSetPage("LoadGame");
}

void Hu_MenuSelectSaveGame(Widget * /*wi*/, Widget::mn_actionid_t action)
Expand Down Expand Up @@ -4143,7 +4143,7 @@ void Hu_MenuSelectSaveGame(Widget * /*wi*/, Widget::mn_actionid_t action)
}

Hu_MenuCommand(MCMD_OPEN);
Hu_MenuSetPage(Hu_MenuPagePtr("SaveGame"));
Hu_MenuSetPage("SaveGame");
}

#if __JHEXEN__
Expand Down Expand Up @@ -4221,9 +4221,9 @@ void Hu_MenuSelectEpisode(Widget *wi, Widget::mn_actionid_t /*action*/)
DENG2_ASSERT(wi != 0);
mnEpisode = wi->as<ButtonWidget>().data().toString();
#if __JHEXEN__
Hu_MenuSetPage(Hu_MenuPagePtr("PlayerClass"));
Hu_MenuSetPage("PlayerClass");
#else
Hu_MenuSetPage(Hu_MenuPagePtr("Skill"));
Hu_MenuSetPage("Skill");
#endif
}

Expand Down Expand Up @@ -4336,7 +4336,7 @@ D_CMD(MenuOpen)
if(Hu_MenuHasPage(pageName))
{
Hu_MenuCommand(MCMD_OPEN);
Hu_MenuSetPage(Hu_MenuPagePtr(pageName));
Hu_MenuSetPage(pageName);
return true;
}
return false;
Expand Down

0 comments on commit c0e9e85

Please sign in to comment.