- remember selected widget of the parent menu and properly restore that

selection when coming back to that menu


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1324 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
thebohemian 2007-12-07 15:46:50 +00:00
parent e483fa32b8
commit 12cee75a0f
2 changed files with 42 additions and 10 deletions

View File

@ -50,6 +50,8 @@
#include "user_config.hpp"
#include "widget_manager.hpp"
using namespace std;
MenuManager* menu_manager= new MenuManager();
MenuManager::MenuManager()
@ -66,9 +68,18 @@ MenuManager::~MenuManager()
}
//-----------------------------------------------------------------------------
/** Puts the given menu into the menu stack and saves the widgetToken of
* the last selected widget for later reactivation.
*/
void MenuManager::pushMenu(MenuManagerIDs id)
{
// used to suppress select-sound on startup
// If there is already an element then this is the one for the menu
// which is still visible. We store its currently selected widget
// therein.
if (m_menu_stack.size())
m_menu_stack.back().second = widget_manager->get_selected_wgt();
// used to suppress select-sound on startup
static bool is_startup = true;
if( MENUID_EXITGAME == id )
@ -80,14 +91,21 @@ void MenuManager::pushMenu(MenuManagerIDs id)
if( !is_startup ) sound_manager->playSfx(SOUND_SELECT_MENU);
else is_startup = false;
}
m_menu_stack.push_back(id);
// Creates a new entry for the to be displayed menu.
pair <MenuManagerIDs, int> element;
element.first = id;
element.second = WidgetManager::WGT_NONE;
m_menu_stack.push_back(element);
}
//-----------------------------------------------------------------------------
void MenuManager::popMenu()
{
sound_manager->playSfx(SOUND_BACK_MENU);
m_menu_stack.pop_back();
m_menu_stack.pop_back();
}
//-----------------------------------------------------------------------------
@ -109,7 +127,10 @@ void MenuManager::update()
m_handled_size= m_menu_stack.size();
if (m_handled_size > 0)
{
MenuManagerIDs id= m_menu_stack.back();
pair<MenuManagerIDs, int> saved = m_menu_stack.back();
MenuManagerIDs id = saved.first;
int saved_widget = saved.second;
switch (id)
{
case MENUID_MAINMENU:
@ -191,7 +212,13 @@ void MenuManager::update()
break;
} // switch
if( widget_manager->get_selected_wgt() != WidgetManager::WGT_NONE )
// Restores the previously selected widget if there was one.
if (saved_widget != WidgetManager::WGT_NONE)
{
widget_manager->lighten_wgt_color( saved_widget );
widget_manager->pulse_wgt( saved_widget );
widget_manager->set_selected_wgt(saved_widget);
} else if( widget_manager->get_selected_wgt() != WidgetManager::WGT_NONE )
{
widget_manager->lighten_wgt_color(widget_manager->get_selected_wgt());
}
@ -244,8 +271,13 @@ void MenuManager::switchToRace()
// if the config_display menu was called from the race_gui, or main_menu
bool MenuManager::isSomewhereOnStack(MenuManagerIDs id)
{
return std::find(m_menu_stack.begin(), m_menu_stack.end(), id) !=
m_menu_stack.end();
for(vector<pair<MenuManagerIDs,int> >::iterator i = m_menu_stack.begin(); i != m_menu_stack.end(); i++)
{
if ((*i).first == id)
return true;
}
return false;
} // isSomewhereOnStack
// -----------------------------------------------------------------------------

View File

@ -76,12 +76,12 @@ public:
void refreshMenu();
// use this function within menu classes
void pushMenu(MenuManagerIDs id);
void pushMenu(MenuManagerIDs);
void popMenu();
int getMenuStackSize() {return (int)m_menu_stack.size();}
bool isCurrentMenu(MenuManagerIDs id) {return (m_menu_stack.back() == id);}
bool isCurrentMenu(MenuManagerIDs id) {return (m_menu_stack.back().first == id);}
bool isSomewhereOnStack(MenuManagerIDs id);
BaseGUI* getCurrentMenu() const {return m_current_menu;}
RaceGUI* getRaceMenu () const {return (RaceGUI*)m_RaceGUI;}
@ -89,7 +89,7 @@ public:
void update();
private:
std::vector<MenuManagerIDs> m_menu_stack;
std::vector< std::pair<MenuManagerIDs, int> > m_menu_stack;
BaseGUI* m_current_menu;
BaseGUI* m_RaceGUI;
unsigned int m_handled_size;