From 6f278f6d1ef6206abbab2378cbefb57aa249e13e Mon Sep 17 00:00:00 2001 From: auria Date: Sun, 28 Feb 2010 00:52:41 +0000 Subject: [PATCH] Started implementing clicking on a challenge to start it git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4870 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/challenges/challenge.hpp | 5 +- src/challenges/challenge_data.hpp | 3 ++ src/challenges/unlock_manager.cpp | 2 +- src/challenges/unlock_manager.hpp | 3 +- src/states_screens/challenges.cpp | 52 +++++++++++++------ src/states_screens/dialogs/gp_info_dialog.cpp | 8 +-- .../dialogs/race_over_dialog.cpp | 2 +- .../dialogs/track_info_dialog.cpp | 10 +--- src/states_screens/race_gui.cpp | 4 ++ 9 files changed, 55 insertions(+), 34 deletions(-) diff --git a/src/challenges/challenge.hpp b/src/challenges/challenge.hpp index b6ff15622..26094628f 100644 --- a/src/challenges/challenge.hpp +++ b/src/challenges/challenge.hpp @@ -97,7 +97,10 @@ public: // the feature remains locked. virtual bool raceFinished() {return false;} // end of a race virtual bool grandPrixFinished() {return false;} // end of a GP - virtual void setRace() const = 0; // set race to use + + /** sets the right parameters in RaceManager to try this challenge */ + virtual void setRace() const = 0; + /** Checks if a challenge is valid. */ virtual void check() const = 0; }; diff --git a/src/challenges/challenge_data.hpp b/src/challenges/challenge_data.hpp index fed9daca2..56bc1aa57 100644 --- a/src/challenges/challenge_data.hpp +++ b/src/challenges/challenge_data.hpp @@ -54,7 +54,10 @@ public: #else ChallengeData(const std::string& filename) throw(std::runtime_error); #endif + + /** sets the right parameters in RaceManager to try this challenge */ void setRace() const; + virtual void check() const; virtual bool raceFinished(); virtual bool grandPrixFinished(); diff --git a/src/challenges/unlock_manager.cpp b/src/challenges/unlock_manager.cpp index e2111c8fa..a424c267b 100644 --- a/src/challenges/unlock_manager.cpp +++ b/src/challenges/unlock_manager.cpp @@ -210,7 +210,7 @@ std::vector UnlockManager::getActiveChallenges() } // getActiveChallenges //----------------------------------------------------------------------------- -Challenge* UnlockManager::getChallenge(const std::string& id) +const Challenge* UnlockManager::getChallenge(const std::string& id) { if(m_all_challenges.find(id)==m_all_challenges.end()) return NULL; return m_all_challenges[id]; diff --git a/src/challenges/unlock_manager.hpp b/src/challenges/unlock_manager.hpp index 74e791485..2fdb022ed 100644 --- a/src/challenges/unlock_manager.hpp +++ b/src/challenges/unlock_manager.hpp @@ -36,7 +36,6 @@ private: AllChallengesType m_all_challenges; std::map m_locked_features; std::vector m_unlocked_features; - Challenge *getChallenge (const std::string& id); void computeActive (); void load (); @@ -65,6 +64,8 @@ public: /** Returns the list of currently inaccessible (locked) challenges */ const std::vector getLockedChallenges(); + const Challenge *getChallenge (const std::string& id); + void raceFinished (); void grandPrixFinished (); void lockFeature (Challenge* challenge); diff --git a/src/states_screens/challenges.cpp b/src/states_screens/challenges.cpp index 73fd60ca2..1bc4c1aa7 100644 --- a/src/states_screens/challenges.cpp +++ b/src/states_screens/challenges.cpp @@ -18,7 +18,15 @@ #include "states_screens/challenges.hpp" + #include "challenges/unlock_manager.hpp" +#include "config/user_config.hpp" +#include "guiengine/engine.hpp" +#include "input/device_manager.hpp" +#include "input/input_manager.hpp" +#include "io/file_manager.hpp" +#include "network/network_manager.hpp" +#include "race/race_manager.hpp" #include "states_screens/state_manager.hpp" #include "utils/translation.hpp" @@ -28,11 +36,6 @@ using irr::core::stringw; using irr::core::stringc; -#include "config/user_config.hpp" -#include "guiengine/engine.hpp" -#include "io/file_manager.hpp" - - namespace GUIEngine { @@ -62,28 +65,20 @@ namespace GUIEngine const int solvedChallengeAmount = solvedChallenges.size(); const int lockedChallengeAmount = lockedChallenges.size(); - char buffer[64]; for (int n=0; ngetId().c_str() << ">\n"; w->addItem(activeChallenges[n]->getName() + L"\n" + activeChallenges[n]->getChallengeDescription(), - buffer, "/gui/challenge.png"); + activeChallenges[n]->getId(), "/gui/challenge.png"); } for (int n=0; naddItem(solvedChallenges[n]->getName(), buffer, "/textures/cup_gold.png"); - std::cout << "// Adding challenge " << buffer << " : <" << solvedChallenges[n]->getId().c_str() << ">\n"; - + w->addItem(solvedChallenges[n]->getName(), solvedChallenges[n]->getId(), "/textures/cup_gold.png"); } for (int n=0; naddItem( _("Locked : solve active challenges to gain access to more!"), "locked", "/gui/challenge.png", true); - std::cout << "// Adding locked challenge <" << lockedChallenges[n]->getId().c_str() << ">\n"; - } @@ -114,6 +109,33 @@ namespace GUIEngine { unlock_manager->playLockSound(); } + else + { + //FIXME: simplify and centralize race start sequence!! + + // Use latest used device + InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice(); + + // Create player and associate player with device (FIXME: ask for player ident) + StateManager::get()->createActivePlayer( UserConfigParams::m_all_players.get(0), device ); + + // Set up race manager appropriately + race_manager->setNumLocalPlayers(1); + 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); + + // Go straight to the race + StateManager::get()->enterGameState(); + + network_manager->initCharacterDataStructures(); + network_manager->setupPlayerKartInfo(); + + // Launch challenge + unlock_manager->getChallenge(selection)->setRace(); + race_manager->startNew(); + } } } diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index ec3308476..96e0b8487 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -185,13 +185,7 @@ void startGPGame(const GrandPrixData* gp) assert(gp != NULL); ModalDialog::dismiss(); - IVideoDriver* driver = GUIEngine::getDriver(); - - //TODO?: draw a loading screen - driver->endScene(); - driver->beginScene(true, false); - driver->endScene(); - + //FIXME: simplify and centralize race start sequence!! StateManager::get()->enterGameState(); //race_manager->setDifficulty(RaceManager::RD_HARD); diff --git a/src/states_screens/dialogs/race_over_dialog.cpp b/src/states_screens/dialogs/race_over_dialog.cpp index 44dfb4050..7e9203816 100644 --- a/src/states_screens/dialogs/race_over_dialog.cpp +++ b/src/states_screens/dialogs/race_over_dialog.cpp @@ -407,7 +407,7 @@ void RaceOverDialog::renderThreeStrikesGraph(const int x, const int y, const int irr_driver->getVideoDriver()->draw2DLine( core::position2d(x + w, y + h), core::position2d(x + w - 13, y + h + 7), black); irr_driver->getVideoDriver()->draw2DLine( core::position2d(x + w, y + h), - core::position2d(x + w - 13, y + h - 7), black); + core::position2d(x + w - 13, y + h - 7), black); float lastEventTime = 0.0f; int max_life_count = 0; diff --git a/src/states_screens/dialogs/track_info_dialog.cpp b/src/states_screens/dialogs/track_info_dialog.cpp index 3e2114db5..b2f6ac37c 100644 --- a/src/states_screens/dialogs/track_info_dialog.cpp +++ b/src/states_screens/dialogs/track_info_dialog.cpp @@ -274,16 +274,10 @@ void TrackInfoDialog::updateHighScores() */ void startGame(const std::string trackIdent, const int num_laps) { + //FIXME: simplify and centralize race start sequence!! + ModalDialog::dismiss(); - IVideoDriver* driver = GUIEngine::getDriver(); - - //TODO?: draw a loading screen - driver->endScene(); - driver->beginScene(true, false); - driver->endScene(); - - StateManager::get()->enterGameState(); //race_manager->setDifficulty(RaceManager::RD_HARD); race_manager->setTrack(trackIdent.c_str()); diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index 94817675b..ba7d5497b 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -128,7 +128,11 @@ void RaceGUI::createMarkerTexture() for(unsigned int i=0; igetKartIdent(i); + assert(kart_ident.size() > 0); + const KartProperties *kp = kart_properties_manager->getKart(kart_ident); + assert(kp != NULL); + core::vector2df center((float)((m_marker_rendered_size>>1)+i*m_marker_rendered_size), (float)(m_marker_rendered_size>>1) ); int count = kp->getShape();