Return to race and Exit race now both work in the paused dialog

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3999 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2009-09-05 01:50:37 +00:00
parent 4c2a826ab9
commit c9cbd546d4
14 changed files with 101 additions and 45 deletions

View File

@@ -153,10 +153,10 @@ bool EventHandler::onGUIEvent(const SEvent& event)
bool EventHandler::onWidgetActivated(GUIEngine::Widget* w, const int playerID)
{
if (ModalDialog::isADialogActive() && w->m_event_handler == NULL)
if (ModalDialog::isADialogActive())
{
ModalDialog::getCurrent()->processEvent(w->m_properties[PROP_ID]);
return false;
if (ModalDialog::getCurrent()->processEvent(w->m_properties[PROP_ID])) return false;
if (w->m_event_handler == NULL) return false;
}
std::cout << "**** widget activated : " << w->m_properties[PROP_ID].c_str() << " ****" << std::endl;

View File

@@ -54,7 +54,9 @@ public:
ptr_vector<Widget> m_children;
virtual ~ModalDialog();
virtual void processEvent(std::string& eventSource){}
/** Returns whether to block event propagation */
virtual bool processEvent(std::string& eventSource){ return false; }
static void dismiss();
static void onEnterPressed();

View File

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

View File

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

View File

@@ -181,7 +181,7 @@ void PlayerInfoDialog::onEnterPressedInternal()
{
}
// ------------------------------------------------------------------------------------------------------
void PlayerInfoDialog::processEvent(std::string& eventSource)
bool PlayerInfoDialog::processEvent(std::string& eventSource)
{
if(eventSource == "renameplayer")
{
@@ -200,11 +200,12 @@ void PlayerInfoDialog::processEvent(std::string& eventSource)
ModalDialog::dismiss();
dismiss();
return;
return true;
}
else if(eventSource == "removeplayer")
{
showConfirmDialog();
return true;
}
else if(eventSource == "confirmremove")
{
@@ -216,12 +217,12 @@ void PlayerInfoDialog::processEvent(std::string& eventSource)
GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
ModalDialog::dismiss();
return;
return true;
}
else if(eventSource == "cancelremove")
{
showRegularDialog();
return true;
}
else if(eventSource == "cancel")
{
@@ -231,8 +232,7 @@ void PlayerInfoDialog::processEvent(std::string& eventSource)
GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
ModalDialog::dismiss();
return;
return true;
}
return false;
}

View File

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

View File

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

View File

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

View File

@@ -235,7 +235,7 @@ void RaceOverDialog::onEnterPressedInternal()
{
}
void RaceOverDialog::processEvent(std::string& eventSource)
bool RaceOverDialog::processEvent(std::string& eventSource)
{
if (eventSource == "raceagainbtn")
{
@@ -243,6 +243,7 @@ void RaceOverDialog::processEvent(std::string& eventSource)
network_manager->setState(NetworkManager::NS_MAIN_MENU);
RaceManager::getWorld()->unpause();
race_manager->rerunRace();
return true;
}
else if (eventSource == "newracebtn")
{
@@ -251,6 +252,7 @@ void RaceOverDialog::processEvent(std::string& eventSource)
race_manager->exitRace();
StateManager::get()->resetAndGoToMenu("main.stkgui");
StateManager::get()->pushMenu("karts.stkgui");
return true;
}
else if (eventSource == "backtomenu")
{
@@ -258,14 +260,16 @@ void RaceOverDialog::processEvent(std::string& eventSource)
RaceManager::getWorld()->unpause();
race_manager->exitRace();
StateManager::get()->resetAndGoToMenu("main.stkgui");
return true;
}
else if (eventSource == "continuegp")
{
ModalDialog::dismiss();
RaceManager::getWorld()->unpause();
race_manager->next();
return true;
}
return false;
}

View File

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

View File

@@ -19,8 +19,11 @@
#include "guiengine/engine.hpp"
#include "guiengine/widgets.hpp"
#include "input/input_manager.hpp"
#include "io/file_manager.hpp"
#include "modes/world.hpp"
#include "race/race_manager.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/translation.hpp"
#include <string>
@@ -28,6 +31,8 @@ using namespace GUIEngine;
RacePausedDialog::RacePausedDialog(const float percentWidth, const float percentHeight) : ModalDialog(percentWidth, percentHeight)
{
RaceManager::getWorld()->pause();
IGUIFont* font = GUIEngine::getFont();
const int text_height = font->getDimension(L"X").Height;
@@ -40,7 +45,7 @@ RacePausedDialog::RacePausedDialog(const float percentWidth, const float percent
m_irrlicht_window);
caption->setTabStop(false);
caption->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER);
// ---- Back button
IconButtonWidget* back_btn = new IconButtonWidget();
back_btn->m_properties[PROP_ID] = "backbtn";
@@ -57,14 +62,14 @@ RacePausedDialog::RacePausedDialog(const float percentWidth, const float percent
GUIEngine::getGUIEnv()->setFocus( back_btn->getIrrlichtElement() );
// ---- Choice ribbon
RibbonWidget* choice_ribbon = new RibbonWidget(RIBBON_TOOLBAR);
choice_ribbon->m_properties[PROP_ID] = "choiceribbon";
choice_ribbon->x = 0;
choice_ribbon->y = text_height*2 + icon_size + 50;
choice_ribbon->w = m_area.getWidth();
choice_ribbon->h = icon_size + text_height;
choice_ribbon->setParent(m_irrlicht_window);
m_choice_ribbon = new RibbonWidget(RIBBON_TOOLBAR);
m_choice_ribbon->m_properties[PROP_ID] = "choiceribbon";
m_choice_ribbon->x = 0;
m_choice_ribbon->y = text_height*2 + icon_size + 50;
m_choice_ribbon->w = m_area.getWidth();
m_choice_ribbon->h = icon_size + text_height;
m_choice_ribbon->setParent(m_irrlicht_window);
if (race_manager->getMinorMode()==RaceManager::MINOR_MODE_QUICK_RACE)
{
@@ -75,7 +80,7 @@ RacePausedDialog::RacePausedDialog(const float percentWidth, const float percent
ribbon_item->m_properties[PROP_HEIGHT] = "128";
//I18N: In the 'paused' screen
ribbon_item->m_text = L"Setup New Race";
choice_ribbon->m_children.push_back(ribbon_item);
m_choice_ribbon->m_children.push_back(ribbon_item);
}
{
IconButtonWidget* ribbon_item = new IconButtonWidget();
@@ -85,7 +90,7 @@ RacePausedDialog::RacePausedDialog(const float percentWidth, const float percent
ribbon_item->m_properties[PROP_HEIGHT] = "128";
//I18N: In the 'paused' screen
ribbon_item->m_text = L"Restart Race";
choice_ribbon->m_children.push_back(ribbon_item);
m_choice_ribbon->m_children.push_back(ribbon_item);
}
{
IconButtonWidget* ribbon_item = new IconButtonWidget();
@@ -95,7 +100,7 @@ RacePausedDialog::RacePausedDialog(const float percentWidth, const float percent
ribbon_item->m_properties[PROP_HEIGHT] = "128";
//I18N: In the 'paused' screen
ribbon_item->m_text = L"Options";
choice_ribbon->m_children.push_back(ribbon_item);
m_choice_ribbon->m_children.push_back(ribbon_item);
}
{
IconButtonWidget* ribbon_item = new IconButtonWidget();
@@ -105,7 +110,7 @@ RacePausedDialog::RacePausedDialog(const float percentWidth, const float percent
ribbon_item->m_properties[PROP_HEIGHT] = "128";
//I18N: In the 'paused' screen
ribbon_item->m_text = L"Help";
choice_ribbon->m_children.push_back(ribbon_item);
m_choice_ribbon->m_children.push_back(ribbon_item);
}
{
IconButtonWidget* ribbon_item = new IconButtonWidget();
@@ -115,11 +120,11 @@ RacePausedDialog::RacePausedDialog(const float percentWidth, const float percent
ribbon_item->m_properties[PROP_HEIGHT] = "128";
//I18N: In the 'paused' screen
ribbon_item->m_text = L"Exit Race";
choice_ribbon->m_children.push_back(ribbon_item);
m_choice_ribbon->m_children.push_back(ribbon_item);
}
m_children.push_back(choice_ribbon);
choice_ribbon->add();
m_children.push_back(m_choice_ribbon);
m_choice_ribbon->add();
}
/*
@@ -178,7 +183,7 @@ RacePausedDialog::RacePausedDialog(const float percentWidth, const float percent
111 break;
112 }
113 }
*/
*/
/*
void RaceMenu::handle(GameAction ga, int value)
@@ -198,15 +203,49 @@ RacePausedDialog::RacePausedDialog(const float percentWidth, const float percent
130 break;
131 }
*/
/*
resetAndGoToMenu("main.stkgui");
input_manager->setMode(InputManager::MENU);
*/
void RacePausedDialog::onEnterPressedInternal()
{
}
void RacePausedDialog::processEvent(std::string& eventSource)
bool RacePausedDialog::processEvent(std::string& eventSource)
{
std::cout << "RacePausedDialog::processEvent(" << eventSource.c_str() << ")\n";
if (eventSource == "backbtn")
{
// unpausing is done in the destructor so nothing more to do here
ModalDialog::dismiss();
return true;
}
else if (eventSource == "exit")
{
ModalDialog::dismiss();
StateManager::get()->resetAndGoToMenu("main.stkgui");
input_manager->setMode(InputManager::MENU);
return true;
}
else if (eventSource == "help")
{
// TODO
}
else if (eventSource == "options")
{
// TODO
}
else if (eventSource == "restart")
{
// TODO
}
else if (eventSource == "newrace")
{
// TODO
}
return false;
}
RacePausedDialog::~RacePausedDialog()
{
RaceManager::getWorld()->unpause();
}

View File

@@ -20,17 +20,23 @@
#include "guiengine/modaldialog.hpp"
namespace GUIEngine
{
class RibbonWidget;
}
class RacePausedDialog : public GUIEngine::ModalDialog
{
GUIEngine::RibbonWidget* m_choice_ribbon;
public:
/**
* Creates a modal dialog with given percentage of screen width and height
*/
RacePausedDialog(const float percentWidth, const float percentHeight);
virtual ~RacePausedDialog();
void onEnterPressedInternal();
void processEvent(std::string& eventSource);
bool processEvent(std::string& eventSource);
};
#endif

View File

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

View File

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