Return to overworld when exiting a race if race was started from overworld

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11065 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2012-04-01 15:42:44 +00:00
parent 04efc6a1cf
commit 6f58350098
12 changed files with 69 additions and 21 deletions

View File

@ -1328,7 +1328,7 @@ int main(int argc, char *argv[] )
// This will setup the race manager etc.
history->Load();
network_manager->setupPlayerKartInfo();
race_manager->startNew();
race_manager->startNew(false);
main_loop->run();
// well, actually run() will never return, since
// it exits after replaying history (see history::GetNextDT()).
@ -1360,7 +1360,7 @@ int main(int argc, char *argv[] )
// ===============
// all defaults are set in InitTuxkart()
network_manager->setupPlayerKartInfo();
race_manager->startNew();
race_manager->startNew(false);
}
}
else // profile
@ -1371,7 +1371,7 @@ int main(int argc, char *argv[] )
race_manager->setMinorMode (RaceManager::MINOR_MODE_NORMAL_RACE);
race_manager->setDifficulty(RaceManager::RD_HARD);
network_manager->setupPlayerKartInfo();
race_manager->startNew();
race_manager->startNew(false);
}
main_loop->run();

View File

@ -63,8 +63,7 @@ void OverWorld::enterOverWorld()
StateManager::get()->enterGameState();
network_manager->setupPlayerKartInfo();
race_manager->startNew();
race_manager->startNew(false);
}
//-----------------------------------------------------------------------------

View File

@ -56,6 +56,7 @@ RaceManager::RaceManager()
m_minor_mode = MINOR_MODE_NORMAL_RACE;
m_track_number = 0;
m_coin_target = 0;
m_started_from_overworld = false;
setReverseTrack(false);
setTrack("jungle");
m_default_ai_list.clear();
@ -242,8 +243,10 @@ void RaceManager::computeRandomKartList()
//-----------------------------------------------------------------------------
void RaceManager::startNew()
void RaceManager::startNew(bool from_overworld)
{
m_started_from_overworld = from_overworld;
if(m_major_mode==MAJOR_MODE_GRAND_PRIX)
{
// GP: get tracks, laps and reverse info from grand prix
@ -619,7 +622,7 @@ void RaceManager::rerunRace()
//-----------------------------------------------------------------------------
void RaceManager::startGP(const GrandPrixData* gp)
void RaceManager::startGP(const GrandPrixData* gp, bool from_overworld)
{
assert(gp != NULL);
@ -629,13 +632,14 @@ void RaceManager::startGP(const GrandPrixData* gp)
network_manager->setupPlayerKartInfo();
setMajorMode(RaceManager::MAJOR_MODE_GRAND_PRIX);
startNew();
startNew(from_overworld);
}
//-----------------------------------------------------------------------------
void RaceManager::startSingleRace(const std::string trackIdent,
const int num_laps)
const int num_laps,
bool from_overworld)
{
StateManager::get()->enterGameState();
setTrack(trackIdent.c_str());
@ -647,7 +651,7 @@ void RaceManager::startSingleRace(const std::string trackIdent,
setCoinTarget( 0 ); // Might still be set from a previous challenge
network_manager->setupPlayerKartInfo();
startNew();
startNew(from_overworld);
}
/* EOF */

View File

@ -199,6 +199,8 @@ public:
enum KartType { KT_PLAYER, KT_NETWORK_PLAYER, KT_AI, KT_LEADER, KT_GHOST };
private:
bool m_started_from_overworld;
/** This data structure accumulates kart data and race result data from
* each race. */
struct KartStatus
@ -466,7 +468,7 @@ public:
* NetworkManager::setupPlayerKartInfo, but could be done differently
* (e.g. depending on user command line options to test certain AIs)
*/
void startNew();
void startNew(bool from_overworld);
/** \brief Start the next race or go back to the start screen
* If there are more races to do, starts the next race, otherwise
@ -489,7 +491,7 @@ public:
/**
* \brief Higher-level method to start a GP without having to care about the exact startup sequence
*/
void startGP(const GrandPrixData* gp);
void startGP(const GrandPrixData* gp, bool from_overworld);
/**
* \brief Higher-level method to start a GP without having to care about
@ -498,7 +500,10 @@ public:
* \param num_laps Number of laps to race, or -1 if number of laps is
* not relevant in current mode
*/
void startSingleRace(const std::string trackIdent, const int num_laps);
void startSingleRace(const std::string trackIdent, const int num_laps,
bool from_overworld);
bool raceWasStartedFromOverworld() const { return m_started_from_overworld; }
/** \} */

View File

@ -185,7 +185,7 @@ void GPInfoDialog::onEnterPressedInternal()
// Save the gp identifier, since dismiss will delete this object.
std::string gp_id = m_gp_ident;
ModalDialog::dismiss();
race_manager->startGP(grand_prix_manager->getGrandPrix(gp_id));
race_manager->startGP(grand_prix_manager->getGrandPrix(gp_id), false);
}
// ------------------------------------------------------------------------------------------------------
@ -197,7 +197,7 @@ GUIEngine::EventPropagation GPInfoDialog::processEvent(const std::string& eventS
// Save GP identifier, since dismiss will delete this object.
std::string gp_id = m_gp_ident;
ModalDialog::dismiss();
race_manager->startGP(grand_prix_manager->getGrandPrix(gp_id));
race_manager->startGP(grand_prix_manager->getGrandPrix(gp_id), false);
return GUIEngine::EVENT_BLOCK;
}
else if (eventSource == "cannot_start")

View File

@ -26,6 +26,7 @@
#include "karts/abstract_kart.hpp"
#include "karts/kart_properties.hpp"
#include "karts/kart_properties_manager.hpp"
#include "modes/overworld.hpp"
#include "modes/three_strikes_battle.hpp"
#include "modes/world.hpp"
#include "modes/world_with_rank.hpp"
@ -390,7 +391,14 @@ RaceOverDialog::RaceOverDialog(const float percentWidth,
whats_next_btn->m_h = button_h;
whats_next_btn->setParent(m_irrlicht_window);
whats_next_btn->setText( _("Back to the main menu") );
if (race_manager->raceWasStartedFromOverworld())
{
whats_next_btn->setText( _("Back to track selection") );
}
else
{
whats_next_btn->setText( _("Back to the main menu") );
}
whats_next_btn->m_properties[PROP_ID] = "backtomenu";
m_widgets.push_back(whats_next_btn);
@ -469,6 +477,12 @@ GUIEngine::EventPropagation RaceOverDialog::processEvent(const std::string& even
World::getWorld()->unpause();
race_manager->exitRace();
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
if (race_manager->raceWasStartedFromOverworld())
{
OverWorld::enterOverWorld();
}
return GUIEngine::EVENT_BLOCK;
}
else if (eventSource == "continuegp")

View File

@ -25,6 +25,7 @@
#include "guiengine/widgets/ribbon_widget.hpp"
#include "input/input_manager.hpp"
#include "io/file_manager.hpp"
#include "modes/overworld.hpp"
#include "modes/world.hpp"
#include "network/network_manager.hpp"
#include "race/race_manager.hpp"
@ -105,6 +106,12 @@ GUIEngine::EventPropagation
ModalDialog::dismiss();
race_manager->exitRace();
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
if (race_manager->raceWasStartedFromOverworld())
{
OverWorld::enterOverWorld();
}
return GUIEngine::EVENT_BLOCK;
}
else if (selection == "help")

View File

@ -196,7 +196,7 @@ GUIEngine::EventPropagation SelectChallengeDialog::processEvent(const std::strin
// Sets up kart info, including random list of kart for AI
network_manager->setupPlayerKartInfo();
race_manager->startNew();
race_manager->startNew(true);
return GUIEngine::EVENT_BLOCK;
}

View File

@ -247,7 +247,7 @@ void TrackInfoDialog::onEnterPressedInternal()
race_manager->setReverseTrack(reverse_track);
std::string track_ident = m_track_ident;
ModalDialog::dismiss();
race_manager->startSingleRace(track_ident, num_laps);
race_manager->startSingleRace(track_ident, num_laps, false);
} // onEnterPressedInternal
// ------------------------------------------------------------------------------------------------------

View File

@ -27,6 +27,7 @@
#include "io/file_manager.hpp"
#include "karts/kart_properties.hpp"
#include "karts/kart_properties_manager.hpp"
#include "modes/overworld.hpp"
#include "modes/world.hpp"
#include "race/grand_prix_manager.hpp"
#include "states_screens/main_menu_screen.hpp"
@ -715,9 +716,14 @@ void FeatureUnlockedCutScene::continueButtonPressed()
}
else
{
// back to menu
// back to menu or overworld
race_manager->exitRace();
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
if (race_manager->raceWasStartedFromOverworld())
{
OverWorld::enterOverWorld();
}
}
}

View File

@ -30,6 +30,7 @@
#include "karts/abstract_kart.hpp"
#include "karts/controller/controller.hpp"
#include "karts/kart_properties.hpp"
#include "modes/overworld.hpp"
#include "modes/world_with_rank.hpp"
#include "states_screens/dialogs/race_over_dialog.hpp"
#include "states_screens/feature_unlocked.hpp"
@ -125,7 +126,14 @@ void RaceResultGUI::enableAllButtons()
middle->setText( _("Restart") );
middle->setVisible(true);
bottom->setText( _("Back to the menu") );
if (race_manager->raceWasStartedFromOverworld())
{
bottom->setText( _("Back to track selection") );
}
else
{
bottom->setText( _("Back to the menu") );
}
bottom->setVisible(true);
bottom->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
@ -212,6 +220,11 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget,
{
race_manager->exitRace();
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
if (race_manager->raceWasStartedFromOverworld())
{
OverWorld::enterOverWorld();
}
}
else
{

View File

@ -190,7 +190,7 @@ void TutorialScreen::eventCallback(GUIEngine::Widget* widget, const std::string&
// Sets up kart info, including random list of kart for AI
network_manager->setupPlayerKartInfo();
race_manager->startNew();
race_manager->startNew(false);
}
else if (name == SHARP_TURN)
{