More event propagation cleanup

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@4139 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-10-20 18:25:14 +00:00
parent 584d203aa4
commit 0f775b8a8c
15 changed files with 44 additions and 42 deletions

View File

@ -157,7 +157,7 @@ EventPropagation EventHandler::onWidgetActivated(GUIEngine::Widget* w, const int
{ {
if (ModalDialog::isADialogActive()) if (ModalDialog::isADialogActive())
{ {
if (ModalDialog::getCurrent()->processEvent(w->m_properties[PROP_ID])) return EVENT_LET; if (ModalDialog::getCurrent()->processEvent(w->m_properties[PROP_ID]) == EVENT_BLOCK) return EVENT_BLOCK;
if (w->m_event_handler == NULL) return EVENT_LET; if (w->m_event_handler == NULL) return EVENT_LET;
} }
@ -296,6 +296,7 @@ void EventHandler::processAction(const int action, const unsigned int value, Inp
IGUIElement* element = GUIEngine::getGUIEnv()->getFocus(); IGUIElement* element = GUIEngine::getGUIEnv()->getFocus();
Widget* w = GUIEngine::getWidget( element->getID() ); Widget* w = GUIEngine::getWidget( element->getID() );
if (w == NULL) break; if (w == NULL) break;
// FIXME : consider returned value?
onWidgetActivated( w, playerID ); onWidgetActivated( w, playerID );
} }

View File

@ -20,6 +20,7 @@
#include "irrlicht.h" #include "irrlicht.h"
#include "utils/ptr_vector.hpp" #include "utils/ptr_vector.hpp"
#include "guiengine/event_handler.hpp"
#include "guiengine/skin.hpp" #include "guiengine/skin.hpp"
class PlayerProfile; class PlayerProfile;
@ -55,8 +56,8 @@ public:
virtual ~ModalDialog(); virtual ~ModalDialog();
/** Returns whether to block event propagation */ /** Returns whether to block event propagation (usually, you will want to block events you processed) */
virtual bool processEvent(std::string& eventSource){ return false; } virtual EventPropagation processEvent(std::string& eventSource){ return EVENT_LET; }
static void dismiss(); static void dismiss();
static void onEnterPressed(); static void onEnterPressed();

View File

@ -81,14 +81,14 @@ EnterPlayerNameDialog::~EnterPlayerNameDialog()
{ {
textCtrl->getIrrlichtElement()->remove(); textCtrl->getIrrlichtElement()->remove();
} }
bool EnterPlayerNameDialog::processEvent(std::string& eventSource) GUIEngine::EventPropagation EnterPlayerNameDialog::processEvent(std::string& eventSource)
{ {
if(eventSource == "cancel") if(eventSource == "cancel")
{ {
dismiss(); dismiss();
return true; return GUIEngine::EVENT_BLOCK;
} }
return false; return GUIEngine::EVENT_LET;
} }
void EnterPlayerNameDialog::onEnterPressedInternal() void EnterPlayerNameDialog::onEnterPressedInternal()
{ {

View File

@ -39,7 +39,7 @@ public:
~EnterPlayerNameDialog(); ~EnterPlayerNameDialog();
void onEnterPressedInternal(); void onEnterPressedInternal();
bool processEvent(std::string& eventSource); GUIEngine::EventPropagation processEvent(std::string& eventSource);
}; };
#endif #endif

View File

@ -182,7 +182,7 @@ void PlayerInfoDialog::onEnterPressedInternal()
{ {
} }
// ------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------
bool PlayerInfoDialog::processEvent(std::string& eventSource) GUIEngine::EventPropagation PlayerInfoDialog::processEvent(std::string& eventSource)
{ {
if (eventSource == "renameplayer") if (eventSource == "renameplayer")
{ {
@ -201,12 +201,12 @@ bool PlayerInfoDialog::processEvent(std::string& eventSource)
ModalDialog::dismiss(); ModalDialog::dismiss();
dismiss(); dismiss();
return true; return GUIEngine::EVENT_BLOCK;
} }
else if (eventSource == "removeplayer") else if (eventSource == "removeplayer")
{ {
showConfirmDialog(); showConfirmDialog();
return true; return GUIEngine::EVENT_BLOCK;
} }
else if (eventSource == "confirmremove") else if (eventSource == "confirmremove")
{ {
@ -218,12 +218,12 @@ bool PlayerInfoDialog::processEvent(std::string& eventSource)
GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window ); GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
ModalDialog::dismiss(); ModalDialog::dismiss();
return true; return GUIEngine::EVENT_BLOCK;
} }
else if(eventSource == "cancelremove") else if(eventSource == "cancelremove")
{ {
showRegularDialog(); showRegularDialog();
return true; return GUIEngine::EVENT_BLOCK;
} }
else if(eventSource == "cancel") else if(eventSource == "cancel")
{ {
@ -233,7 +233,7 @@ bool PlayerInfoDialog::processEvent(std::string& eventSource)
GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window ); GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
ModalDialog::dismiss(); ModalDialog::dismiss();
return true; return GUIEngine::EVENT_BLOCK;
} }
return false; return GUIEngine::EVENT_LET;
} }

View File

@ -41,7 +41,7 @@ public:
PlayerInfoDialog(PlayerProfile* PlayerInfoDialog, PlayerInfoDialog(PlayerProfile* PlayerInfoDialog,
const float percentWidth, const float percentHeight); const float percentWidth, const float percentHeight);
void onEnterPressedInternal(); void onEnterPressedInternal();
bool processEvent(std::string& eventSource); GUIEngine::EventPropagation processEvent(std::string& eventSource);
}; };

View File

@ -57,13 +57,13 @@ PressAKeyDialog::PressAKeyDialog(const float w, const float h) :
widget2->add(); widget2->add();
} }
// ------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------
bool PressAKeyDialog::processEvent(std::string& eventSource) GUIEngine::EventPropagation PressAKeyDialog::processEvent(std::string& eventSource)
{ {
if(eventSource == "cancel") if(eventSource == "cancel")
{ {
input_manager->setMode(InputManager::MENU); input_manager->setMode(InputManager::MENU);
dismiss(); dismiss();
return true; return GUIEngine::EVENT_BLOCK;
} }
return false; return GUIEngine::EVENT_LET;
} }

View File

@ -28,7 +28,7 @@ public:
* Creates a modal dialog with given percentage of screen width and height * Creates a modal dialog with given percentage of screen width and height
*/ */
PressAKeyDialog(const float percentWidth, const float percentHeight); PressAKeyDialog(const float percentWidth, const float percentHeight);
bool processEvent(std::string& eventSource); GUIEngine::EventPropagation processEvent(std::string& eventSource);
}; };
#endif #endif

View File

@ -241,7 +241,7 @@ void RaceOverDialog::onEnterPressedInternal()
{ {
} }
bool RaceOverDialog::processEvent(std::string& eventSource) GUIEngine::EventPropagation RaceOverDialog::processEvent(std::string& eventSource)
{ {
if (eventSource == "raceagainbtn") if (eventSource == "raceagainbtn")
{ {
@ -249,7 +249,7 @@ bool RaceOverDialog::processEvent(std::string& eventSource)
network_manager->setState(NetworkManager::NS_MAIN_MENU); network_manager->setState(NetworkManager::NS_MAIN_MENU);
RaceManager::getWorld()->unpause(); RaceManager::getWorld()->unpause();
race_manager->rerunRace(); race_manager->rerunRace();
return true; return GUIEngine::EVENT_BLOCK;
} }
else if (eventSource == "newracebtn") else if (eventSource == "newracebtn")
{ {
@ -258,7 +258,7 @@ bool RaceOverDialog::processEvent(std::string& eventSource)
race_manager->exitRace(); race_manager->exitRace();
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
StateManager::get()->pushScreen(KartSelectionScreen::getInstance()); StateManager::get()->pushScreen(KartSelectionScreen::getInstance());
return true; return GUIEngine::EVENT_BLOCK;
} }
else if (eventSource == "backtomenu") else if (eventSource == "backtomenu")
{ {
@ -267,16 +267,16 @@ bool RaceOverDialog::processEvent(std::string& eventSource)
race_manager->exitRace(); race_manager->exitRace();
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
input_manager->setMode(InputManager::MENU); input_manager->setMode(InputManager::MENU);
return true; return GUIEngine::EVENT_BLOCK;
} }
else if (eventSource == "continuegp") else if (eventSource == "continuegp")
{ {
ModalDialog::dismiss(); ModalDialog::dismiss();
RaceManager::getWorld()->unpause(); RaceManager::getWorld()->unpause();
race_manager->next(); race_manager->next();
return true; return GUIEngine::EVENT_BLOCK;
} }
return false; return GUIEngine::EVENT_LET;
} }

View File

@ -30,7 +30,7 @@ public:
RaceOverDialog(const float percentWidth, const float percentHeight); RaceOverDialog(const float percentWidth, const float percentHeight);
void onEnterPressedInternal(); void onEnterPressedInternal();
bool processEvent(std::string& eventSource); GUIEngine::EventPropagation processEvent(std::string& eventSource);
}; };

View File

@ -214,7 +214,7 @@ void RacePausedDialog::onEnterPressedInternal()
{ {
} }
bool RacePausedDialog::processEvent(std::string& eventSource) GUIEngine::EventPropagation RacePausedDialog::processEvent(std::string& eventSource)
{ {
std::cout << "RacePausedDialog::processEvent(" << eventSource.c_str() << ")\n"; std::cout << "RacePausedDialog::processEvent(" << eventSource.c_str() << ")\n";
@ -222,7 +222,7 @@ bool RacePausedDialog::processEvent(std::string& eventSource)
{ {
// unpausing is done in the destructor so nothing more to do here // unpausing is done in the destructor so nothing more to do here
ModalDialog::dismiss(); ModalDialog::dismiss();
return true; return GUIEngine::EVENT_BLOCK;
} }
else if (eventSource == "choiceribbon") else if (eventSource == "choiceribbon")
{ {
@ -235,19 +235,19 @@ bool RacePausedDialog::processEvent(std::string& eventSource)
race_manager->exitRace(); race_manager->exitRace();
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
input_manager->setMode(InputManager::MENU); input_manager->setMode(InputManager::MENU);
return true; return GUIEngine::EVENT_BLOCK;
} }
else if (selection == "help") else if (selection == "help")
{ {
dismiss(); dismiss();
StateManager::get()->pushScreen(HelpScreen1::getInstance()); StateManager::get()->pushScreen(HelpScreen1::getInstance());
return true; return GUIEngine::EVENT_BLOCK;
} }
else if (selection == "options") else if (selection == "options")
{ {
dismiss(); dismiss();
StateManager::get()->pushScreen(OptionsScreenAV::getInstance()); StateManager::get()->pushScreen(OptionsScreenAV::getInstance());
return true; return GUIEngine::EVENT_BLOCK;
} }
else if (selection == "restart") else if (selection == "restart")
{ {
@ -255,14 +255,14 @@ bool RacePausedDialog::processEvent(std::string& eventSource)
network_manager->setState(NetworkManager::NS_MAIN_MENU); network_manager->setState(NetworkManager::NS_MAIN_MENU);
RaceManager::getWorld()->unpause(); RaceManager::getWorld()->unpause();
race_manager->rerunRace(); race_manager->rerunRace();
return true; return GUIEngine::EVENT_BLOCK;
} }
else if (selection == "newrace") else if (selection == "newrace")
{ {
// TODO return GUIEngine::EVENT_BLOCK;
} }
} }
return false; return GUIEngine::EVENT_LET;
} }
RacePausedDialog::~RacePausedDialog() RacePausedDialog::~RacePausedDialog()

View File

@ -36,7 +36,7 @@ public:
virtual ~RacePausedDialog(); virtual ~RacePausedDialog();
void onEnterPressedInternal(); void onEnterPressedInternal();
bool processEvent(std::string& eventSource); GUIEngine::EventPropagation processEvent(std::string& eventSource);
}; };
#endif #endif

View File

@ -233,13 +233,13 @@ void TrackInfoDialog::onEnterPressedInternal()
startGame(m_track_ident, num_laps); startGame(m_track_ident, num_laps);
} }
// ------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------
bool TrackInfoDialog::processEvent(std::string& eventSource) GUIEngine::EventPropagation TrackInfoDialog::processEvent(std::string& eventSource)
{ {
if (eventSource == "start" ) if (eventSource == "start" )
{ {
const int num_laps = m_spinner->getValue(); const int num_laps = m_spinner->getValue();
startGame(m_track_ident, num_laps); startGame(m_track_ident, num_laps);
return true; return GUIEngine::EVENT_BLOCK;
} }
return false; return GUIEngine::EVENT_LET;
} }

View File

@ -42,7 +42,7 @@ public:
TrackInfoDialog(const std::string& trackIdent, const irr::core::stringw& trackName, TrackInfoDialog(const std::string& trackIdent, const irr::core::stringw& trackName,
irr::video::ITexture* screenshot, const float percentWidth, const float percentHeight); irr::video::ITexture* screenshot, const float percentWidth, const float percentHeight);
void onEnterPressedInternal(); void onEnterPressedInternal();
bool processEvent(std::string& eventSource); GUIEngine::EventPropagation processEvent(std::string& eventSource);
}; };
#endif #endif