From 12cee75a0f05f71846150fb5144ed9d38a28ccbb Mon Sep 17 00:00:00 2001 From: thebohemian Date: Fri, 7 Dec 2007 15:46:50 +0000 Subject: [PATCH] - 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 --- src/gui/menu_manager.cpp | 46 ++++++++++++++++++++++++++++++++++------ src/gui/menu_manager.hpp | 6 +++--- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/gui/menu_manager.cpp b/src/gui/menu_manager.cpp index ba9043213..2af6657f0 100644 --- a/src/gui/menu_manager.cpp +++ b/src/gui/menu_manager.cpp @@ -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 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 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 >::iterator i = m_menu_stack.begin(); i != m_menu_stack.end(); i++) + { + if ((*i).first == id) + return true; + } + + return false; } // isSomewhereOnStack // ----------------------------------------------------------------------------- diff --git a/src/gui/menu_manager.hpp b/src/gui/menu_manager.hpp index 391955d8b..daa8ee92f 100644 --- a/src/gui/menu_manager.hpp +++ b/src/gui/menu_manager.hpp @@ -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 m_menu_stack; + std::vector< std::pair > m_menu_stack; BaseGUI* m_current_menu; BaseGUI* m_RaceGUI; unsigned int m_handled_size;