Implement going in the garage to change kart
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10807 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
7711bab285
commit
65b4eed110
@ -248,6 +248,7 @@ void AbstractStateManager::resetAndGoToScreen(Screen* screen)
|
|||||||
if (m_game_mode != GAME) getCurrentScreen()->tearDown();
|
if (m_game_mode != GAME) getCurrentScreen()->tearDown();
|
||||||
m_menu_stack.clear();
|
m_menu_stack.clear();
|
||||||
|
|
||||||
|
if (!screen->isLoaded()) screen->loadFromFile();
|
||||||
m_menu_stack.push_back(name);
|
m_menu_stack.push_back(name);
|
||||||
setGameState(MENU);
|
setGameState(MENU);
|
||||||
|
|
||||||
|
@ -20,15 +20,57 @@
|
|||||||
#include "input/input.hpp"
|
#include "input/input.hpp"
|
||||||
#include "input/input_manager.hpp"
|
#include "input/input_manager.hpp"
|
||||||
#include "karts/kart.hpp"
|
#include "karts/kart.hpp"
|
||||||
|
#include "karts/kart_properties_manager.hpp"
|
||||||
#include "modes/overworld.hpp"
|
#include "modes/overworld.hpp"
|
||||||
#include "network/network_manager.hpp"
|
#include "network/network_manager.hpp"
|
||||||
#include "states_screens/dialogs/select_challenge.hpp"
|
#include "states_screens/dialogs/select_challenge.hpp"
|
||||||
|
#include "states_screens/kart_selection.hpp"
|
||||||
#include "states_screens/race_gui_overworld.hpp"
|
#include "states_screens/race_gui_overworld.hpp"
|
||||||
#include "tracks/track.hpp"
|
#include "tracks/track.hpp"
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/** Function to simplify the start process */
|
||||||
|
void OverWorld::enterOverWorld()
|
||||||
|
{
|
||||||
|
|
||||||
|
race_manager->setNumLocalPlayers(1);
|
||||||
|
race_manager->setMajorMode (RaceManager::MAJOR_MODE_SINGLE);
|
||||||
|
race_manager->setMinorMode (RaceManager::MINOR_MODE_OVERWORLD);
|
||||||
|
race_manager->setNumKarts( 1 );
|
||||||
|
race_manager->setTrack( "overworld" );
|
||||||
|
race_manager->setDifficulty(RaceManager::RD_HARD);
|
||||||
|
|
||||||
|
// Use keyboard 0 by default (FIXME: let player choose?)
|
||||||
|
InputDevice* device = input_manager->getDeviceList()->getKeyboard(0);
|
||||||
|
|
||||||
|
// Create player and associate player with keyboard
|
||||||
|
StateManager::get()->createActivePlayer(
|
||||||
|
UserConfigParams::m_all_players.get(0), device );
|
||||||
|
|
||||||
|
if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "[MainMenuScreen] WARNING: cannot find kart '%s', will revert to default\n",
|
||||||
|
UserConfigParams::m_default_kart.c_str());
|
||||||
|
UserConfigParams::m_default_kart.revertToDefaults();
|
||||||
|
}
|
||||||
|
race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart);
|
||||||
|
|
||||||
|
// ASSIGN should make sure that only input from assigned devices
|
||||||
|
// is read.
|
||||||
|
input_manager->getDeviceList()->setAssignMode(ASSIGN);
|
||||||
|
input_manager->getDeviceList()
|
||||||
|
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
|
||||||
|
|
||||||
|
StateManager::get()->enterGameState();
|
||||||
|
network_manager->setupPlayerKartInfo();
|
||||||
|
race_manager->startNew();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
OverWorld::OverWorld() : LinearWorld()
|
OverWorld::OverWorld() : LinearWorld()
|
||||||
{
|
{
|
||||||
|
m_return_to_garage = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -61,6 +103,16 @@ void OverWorld::update(float dt)
|
|||||||
{
|
{
|
||||||
m_karts[n]->setEnergy(100.0f);
|
m_karts[n]->setEnergy(100.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_return_to_garage)
|
||||||
|
{
|
||||||
|
m_return_to_garage = false;
|
||||||
|
race_manager->exitRace();
|
||||||
|
KartSelectionScreen* s = KartSelectionScreen::getInstance();
|
||||||
|
s->setMultiplayer(false);
|
||||||
|
s->setFromOverworld(true);
|
||||||
|
StateManager::get()->resetAndGoToScreen(s);
|
||||||
|
}
|
||||||
} // update
|
} // update
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -38,6 +38,8 @@ protected:
|
|||||||
/** Override from base class */
|
/** Override from base class */
|
||||||
virtual void createRaceGUI();
|
virtual void createRaceGUI();
|
||||||
|
|
||||||
|
bool m_return_to_garage;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OverWorld();
|
OverWorld();
|
||||||
/** call just after instanciating. can't be moved to the contructor as child
|
/** call just after instanciating. can't be moved to the contructor as child
|
||||||
@ -46,6 +48,8 @@ public:
|
|||||||
virtual void init();
|
virtual void init();
|
||||||
virtual ~OverWorld();
|
virtual ~OverWorld();
|
||||||
|
|
||||||
|
static void enterOverWorld();
|
||||||
|
|
||||||
virtual void update(float delta);
|
virtual void update(float delta);
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@ -69,6 +73,8 @@ public:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Override settings from base class */
|
/** Override settings from base class */
|
||||||
virtual bool computeChecklineRequirements() const { return false; }
|
virtual bool computeChecklineRequirements() const { return false; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
void scheduleReturnToGarage() { m_return_to_garage = true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -594,12 +594,14 @@ void World::updateWorld(float dt)
|
|||||||
m_phase == IN_GAME_MENU_PHASE )
|
m_phase == IN_GAME_MENU_PHASE )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
update(dt);
|
|
||||||
if( (!isFinishPhase()) && isRaceOver())
|
if( (!isFinishPhase()) && isRaceOver())
|
||||||
{
|
{
|
||||||
enterRaceOverState();
|
enterRaceOverState();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
update(dt);
|
||||||
|
}
|
||||||
} // updateWorld
|
} // updateWorld
|
||||||
|
|
||||||
#define MEASURE_FPS 0
|
#define MEASURE_FPS 0
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "items/item_manager.hpp"
|
#include "items/item_manager.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "karts/kart_properties_manager.hpp"
|
#include "karts/kart_properties_manager.hpp"
|
||||||
|
#include "modes/overworld.hpp"
|
||||||
#include "states_screens/race_setup_screen.hpp"
|
#include "states_screens/race_setup_screen.hpp"
|
||||||
#include "states_screens/state_manager.hpp"
|
#include "states_screens/state_manager.hpp"
|
||||||
#include "utils/translation.hpp"
|
#include "utils/translation.hpp"
|
||||||
@ -1598,7 +1599,15 @@ void KartSelectionScreen::eventCallback(Widget* widget,
|
|||||||
}
|
}
|
||||||
else if (name == "back")
|
else if (name == "back")
|
||||||
{
|
{
|
||||||
StateManager::get()->escapePressed();
|
if (m_from_overworld)
|
||||||
|
{
|
||||||
|
m_from_overworld = false; // valid once
|
||||||
|
OverWorld::enterOverWorld();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
StateManager::get()->escapePressed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1625,6 +1634,22 @@ void KartSelectionScreen::setMultiplayer(bool multiplayer)
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool KartSelectionScreen::onEscapePressed()
|
||||||
|
{
|
||||||
|
if (m_from_overworld)
|
||||||
|
{
|
||||||
|
m_from_overworld = false; // valid once
|
||||||
|
OverWorld::enterOverWorld();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
#pragma mark KartSelectionScreen (private)
|
#pragma mark KartSelectionScreen (private)
|
||||||
@ -1747,7 +1772,16 @@ void KartSelectionScreen::allPlayersDone()
|
|||||||
input_manager->getDeviceList()->setSinglePlayer( NULL );
|
input_manager->getDeviceList()->setSinglePlayer( NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
StateManager::get()->pushScreen( RaceSetupScreen::getInstance() );
|
// ---- Go to next screen or return to overworld
|
||||||
|
if (m_from_overworld)
|
||||||
|
{
|
||||||
|
m_from_overworld = false; // valid once
|
||||||
|
OverWorld::enterOverWorld();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
StateManager::get()->pushScreen( RaceSetupScreen::getInstance() );
|
||||||
|
}
|
||||||
} // allPlayersDone
|
} // allPlayersDone
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -51,6 +51,9 @@ class KartSelectionScreen : public GUIEngine::Screen,
|
|||||||
|
|
||||||
bool m_multiplayer;
|
bool m_multiplayer;
|
||||||
|
|
||||||
|
/** Whether this screen is being visited from overworld or not */
|
||||||
|
bool m_from_overworld;
|
||||||
|
|
||||||
KartSelectionScreen();
|
KartSelectionScreen();
|
||||||
|
|
||||||
/** Stores whether any player confirmed their choice; then, some things
|
/** Stores whether any player confirmed their choice; then, some things
|
||||||
@ -93,6 +96,9 @@ public:
|
|||||||
|
|
||||||
void setMultiplayer(bool multiplayer);
|
void setMultiplayer(bool multiplayer);
|
||||||
|
|
||||||
|
/** \brief Set whether this screen is being visited from overworld or not */
|
||||||
|
void setFromOverworld(bool from_overworld) { m_from_overworld = from_overworld; }
|
||||||
|
|
||||||
/** \brief Called when a player hits 'fire'/'select' on his device to
|
/** \brief Called when a player hits 'fire'/'select' on his device to
|
||||||
* join the game */
|
* join the game */
|
||||||
bool playerJoin(InputDevice* device, bool firstPlayer);
|
bool playerJoin(InputDevice* device, bool firstPlayer);
|
||||||
@ -122,4 +128,8 @@ public:
|
|||||||
/** \brief implement optional callback from parent
|
/** \brief implement optional callback from parent
|
||||||
* class GUIEngine::Screen */
|
* class GUIEngine::Screen */
|
||||||
virtual void unloaded();
|
virtual void unloaded();
|
||||||
|
|
||||||
|
/** \brief implement optional callback from parent
|
||||||
|
* class GUIEngine::Screen */
|
||||||
|
virtual bool onEscapePressed();
|
||||||
};
|
};
|
||||||
|
@ -256,6 +256,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
|
|||||||
{
|
{
|
||||||
KartSelectionScreen* s = KartSelectionScreen::getInstance();
|
KartSelectionScreen* s = KartSelectionScreen::getInstance();
|
||||||
s->setMultiplayer(false);
|
s->setMultiplayer(false);
|
||||||
|
s->setFromOverworld(false);
|
||||||
StateManager::get()->pushScreen( s );
|
StateManager::get()->pushScreen( s );
|
||||||
}
|
}
|
||||||
else if (selection == "multiplayer")
|
else if (selection == "multiplayer")
|
||||||
@ -283,41 +284,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
|
|||||||
}
|
}
|
||||||
else if (selection == "story")
|
else if (selection == "story")
|
||||||
{
|
{
|
||||||
/*
|
OverWorld::enterOverWorld();
|
||||||
StateManager::get()->pushScreen(ChallengesScreen::getInstance());
|
|
||||||
*/
|
|
||||||
|
|
||||||
race_manager->setNumLocalPlayers(1);
|
|
||||||
race_manager->setMajorMode (RaceManager::MAJOR_MODE_SINGLE);
|
|
||||||
race_manager->setMinorMode (RaceManager::MINOR_MODE_OVERWORLD);
|
|
||||||
race_manager->setNumKarts( 1 );
|
|
||||||
race_manager->setTrack( "overworld" );
|
|
||||||
race_manager->setDifficulty(RaceManager::RD_HARD);
|
|
||||||
|
|
||||||
// Use keyboard 0 by default (FIXME: let player choose?)
|
|
||||||
InputDevice* device = input_manager->getDeviceList()->getKeyboard(0);
|
|
||||||
|
|
||||||
// Create player and associate player with keyboard
|
|
||||||
StateManager::get()->createActivePlayer(
|
|
||||||
UserConfigParams::m_all_players.get(0), device );
|
|
||||||
|
|
||||||
if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "[MainMenuScreen] WARNING: cannot find kart '%s', will revert to default\n",
|
|
||||||
UserConfigParams::m_default_kart.c_str());
|
|
||||||
UserConfigParams::m_default_kart.revertToDefaults();
|
|
||||||
}
|
|
||||||
race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart);
|
|
||||||
|
|
||||||
// ASSIGN should make sure that only input from assigned devices
|
|
||||||
// is read.
|
|
||||||
input_manager->getDeviceList()->setAssignMode(ASSIGN);
|
|
||||||
input_manager->getDeviceList()
|
|
||||||
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
|
|
||||||
|
|
||||||
StateManager::get()->enterGameState();
|
|
||||||
network_manager->setupPlayerKartInfo();
|
|
||||||
race_manager->startNew();
|
|
||||||
}
|
}
|
||||||
else if (selection == "tutorial")
|
else if (selection == "tutorial")
|
||||||
{
|
{
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "io/xml_node.hpp"
|
#include "io/xml_node.hpp"
|
||||||
#include "items/item_manager.hpp"
|
#include "items/item_manager.hpp"
|
||||||
|
#include "modes/overworld.hpp"
|
||||||
#include "modes/world.hpp"
|
#include "modes/world.hpp"
|
||||||
#include "tracks/track.hpp"
|
#include "tracks/track.hpp"
|
||||||
|
|
||||||
@ -310,6 +311,15 @@ void TrackObject::onTriggerItemApproached(Item* who)
|
|||||||
}
|
}
|
||||||
else if (m_action.size() > 0)
|
else if (m_action.size() > 0)
|
||||||
{
|
{
|
||||||
printf("Action %s\n", m_action.c_str());
|
if (m_action == "garage")
|
||||||
|
{
|
||||||
|
World::getWorld()->schedulePause(World::IN_GAME_MENU_PHASE);
|
||||||
|
dynamic_cast<OverWorld*>(World::getWorld())->scheduleReturnToGarage();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "[TrackObject] WARNING: unknown action <%s>\n",
|
||||||
|
m_action.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user