Fixes getting input during menu switching.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1514 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
cosmosninja 2008-02-18 04:27:49 +00:00
parent 930a1ef2b5
commit 2d0f761ffe
3 changed files with 22 additions and 12 deletions

View File

@ -42,10 +42,11 @@ BaseGUI::animateWidget(const int PREV_SELECTED_WGT, const int SELECTED_WGT)
void
BaseGUI::handle(GameAction action, int value)
{
if( m_locked ) return;
// Skip on keypress, act on keyrelease only.
if (value)
return;
if (value) return;
int previous = widget_manager->getSelectedWgt();
switch ( action )
@ -53,7 +54,7 @@ BaseGUI::handle(GameAction action, int value)
case GA_CURSOR_LEFT:
animateWidget(previous,
widget_manager->handleLeft());
break;
case GA_CURSOR_RIGHT:
animateWidget(previous,
@ -100,6 +101,8 @@ BaseGUI::handle(GameAction action, int value)
void
BaseGUI::inputPointer(int x, int y)
{
if( m_locked ) return;
const int PREV_SELECTED_WGT = widget_manager->getSelectedWgt();
const int SELECTED_WGT = widget_manager->handlePointer( x, y );

View File

@ -28,7 +28,7 @@ class BaseGUI
void animateWidget(const int, const int);
public:
BaseGUI() {}
BaseGUI() : m_locked(false) {}
virtual ~BaseGUI() {}
virtual void update(float dt);
@ -42,9 +42,17 @@ public:
void inputPointer(int x, int y);
//At times, we want to make sure that we won't be getting any kind of
//input to the gui, for example, during transitions from one screen
//to another. At those times, it's best to lock the input and unlock it
//afterwards.
void lockInput() { m_locked = true; }
void unlockInput() { m_locked = false; }
void TimeToString(const double time, char *s);
protected:
bool m_locked;
int m_menu_id;
};

View File

@ -69,10 +69,9 @@ MenuManager::~MenuManager()
delete m_current_menu;
}
//-----------------------------------------------------------------------------
/** 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)
{
// If there is already an element then this is the one for the menu
@ -98,9 +97,10 @@ void MenuManager::pushMenu(MenuManagerIDs id)
pair <MenuManagerIDs, int> element;
element.first = id;
element.second = WidgetManager::WGT_NONE;
m_menu_stack.push_back(element);
if( m_current_menu) m_current_menu->lockInput();
m_change_menu = true;
}
@ -108,8 +108,9 @@ void MenuManager::pushMenu(MenuManagerIDs id)
void MenuManager::popMenu()
{
sound_manager->playSfx(SOUND_BACK_MENU);
m_menu_stack.pop_back();
if( m_current_menu ) m_current_menu->lockInput();
m_change_menu = true;
}
@ -136,7 +137,7 @@ void MenuManager::update()
pair<MenuManagerIDs, int> saved = m_menu_stack.back();
MenuManagerIDs id = saved.first;
int saved_widget = saved.second;
switch (id)
{
case MENUID_MAINMENU:
@ -264,7 +265,6 @@ void MenuManager::switchToGrandPrixEnding()
delete m_current_menu;
m_current_menu= NULL;
}
m_change_menu = true;
m_menu_stack.clear();
pushMenu(MENUID_GRANDPRIXEND);
@ -300,7 +300,6 @@ void MenuManager::switchToMainMenu()
delete m_current_menu;
m_current_menu= NULL;
}
m_change_menu = true;
m_menu_stack.clear();
pushMenu(MENUID_MAINMENU);