diff --git a/src/guiengine/engine.cpp b/src/guiengine/engine.cpp index c1495fdf7..63ec09d8e 100644 --- a/src/guiengine/engine.cpp +++ b/src/guiengine/engine.cpp @@ -668,6 +668,7 @@ namespace GUIEngine #include "guiengine/widget.hpp" #include "guiengine/dialog_queue.hpp" #include "modes/demo_world.hpp" +#include "modes/cutscene_world.hpp" #include "modes/world.hpp" #include "states_screens/race_gui_base.hpp" @@ -1210,6 +1211,12 @@ namespace GUIEngine } + if (gamestate == INGAME_MENU && dynamic_cast(World::getWorld()) != NULL) + { + RaceGUIBase* rg = World::getWorld()->getRaceGUI(); + if (rg != NULL) rg->renderGlobal(elapsed_time); + } + if (gamestate == MENU || gamestate == INGAME_MENU) { g_skin->drawTooltips(); diff --git a/src/guiengine/screen.hpp b/src/guiengine/screen.hpp index 951626a08..f55398c3d 100644 --- a/src/guiengine/screen.hpp +++ b/src/guiengine/screen.hpp @@ -309,6 +309,17 @@ namespace GUIEngine virtual void onDialogClose() {} }; + class CutsceneScreen : public Screen + { + public: + CutsceneScreen(const char* name) : Screen(name, false) + { + setNeeds3D(true); + m_throttle_FPS = false; + } + + virtual void onCutsceneEnd() = 0; + }; } #endif diff --git a/src/modes/cutscene_world.cpp b/src/modes/cutscene_world.cpp index 8a0d2960d..319f901e5 100644 --- a/src/modes/cutscene_world.cpp +++ b/src/modes/cutscene_world.cpp @@ -43,6 +43,7 @@ #include #include +#include #include bool CutsceneWorld::s_use_duration = false; @@ -187,12 +188,12 @@ void CutsceneWorld::update(float dt) { /* { - PtrVector& objects = m_track->getTrackObjectManager()->getObjects(); - TrackObject* curr; - for_in(curr, objects) - { - printf("* %s\n", curr->getType().c_str()); - } + PtrVector& objects = m_track->getTrackObjectManager()->getObjects(); + TrackObject* curr; + for_in(curr, objects) + { + printf("* %s\n", curr->getType().c_str()); + } } **/ @@ -235,18 +236,29 @@ void CutsceneWorld::update(float dt) dt = (float)(m_time - prev_time); } - float fade; + float fade = 0.0f; + float fadeIn = -1.0f; + float fadeOut = -1.0f; if (m_time < 2.0f) { - fade = 1.0f - (float)m_time / 2.0f; + fadeIn = 1.0f - (float)m_time / 2.0f; } - else if (m_time > m_duration - 2.0f) + if (m_time > m_duration - 2.0f) { - fade = (float)(m_time - (m_duration - 2.0f)) / 2.0f; + fadeOut = (float)(m_time - (m_duration - 2.0f)) / 2.0f; } - else + + if (fadeIn >= 0.0f && fadeOut >= 0.0f) { - fade = 0.0f; + fade = std::max(fadeIn, fadeOut); + } + else if (fadeIn >= 0.0f) + { + fade = fadeIn; + } + else if (fadeOut >= 0.0f) + { + fade = fadeOut; } dynamic_cast(m_race_gui)->setFadeLevel(fade); @@ -354,6 +366,15 @@ void CutsceneWorld::update(float dt) it++; } } + + bool isOver = (m_time > m_duration); + if (isOver && (s_use_duration || m_aborted)) + { + GUIEngine::CutsceneScreen* cs = dynamic_cast( + GUIEngine::getCurrentScreen()); + if (cs != NULL) + cs->onCutsceneEnd(); + } } // update //----------------------------------------------------------------------------- @@ -440,10 +461,12 @@ void CutsceneWorld::enterRaceOverState() */ bool CutsceneWorld::isRaceOver() { + bool isOver = (m_time > m_duration); + if (!s_use_duration && !m_aborted) return false; - return m_time > m_duration; + return isOver; } // isRaceOver //----------------------------------------------------------------------------- diff --git a/src/states_screens/grand_prix_lose.cpp b/src/states_screens/grand_prix_lose.cpp index 8f855108a..29b26e2eb 100644 --- a/src/states_screens/grand_prix_lose.cpp +++ b/src/states_screens/grand_prix_lose.cpp @@ -82,15 +82,18 @@ DEFINE_SCREEN_SINGLETON( GrandPrixLose ); // ------------------------------------------------------------------------------------- -GrandPrixLose::GrandPrixLose() : Screen("grand_prix_lose.stkgui", false /* pause race */) +GrandPrixLose::GrandPrixLose() : CutsceneScreen("grand_prix_lose.stkgui") { - setNeeds3D(true); - - m_throttle_FPS = false; } // GrandPrixLose // ------------------------------------------------------------------------------------- +void GrandPrixLose::onCutsceneEnd() +{ +} + +// ------------------------------------------------------------------------------------- + void GrandPrixLose::loadedFromFile() { m_kart_node[0] = NULL; diff --git a/src/states_screens/grand_prix_lose.hpp b/src/states_screens/grand_prix_lose.hpp index d1212d8fd..a407f27ee 100644 --- a/src/states_screens/grand_prix_lose.hpp +++ b/src/states_screens/grand_prix_lose.hpp @@ -33,7 +33,7 @@ class TrackObject; * \brief Screen shown at the end of a Grand Prix * \ingroup states_screens */ -class GrandPrixLose : public GUIEngine::Screen, public GUIEngine::ScreenSingleton +class GrandPrixLose : public GUIEngine::CutsceneScreen, public GUIEngine::ScreenSingleton { friend class GUIEngine::ScreenSingleton; @@ -53,6 +53,8 @@ class GrandPrixLose : public GUIEngine::Screen, public GUIEngine::ScreenSingleto public: + virtual void onCutsceneEnd() OVERRIDE; + /** \brief implement callback from parent class GUIEngine::Screen */ virtual void loadedFromFile() OVERRIDE; diff --git a/src/states_screens/grand_prix_win.cpp b/src/states_screens/grand_prix_win.cpp index 01c61c8aa..18bf4c927 100644 --- a/src/states_screens/grand_prix_win.cpp +++ b/src/states_screens/grand_prix_win.cpp @@ -66,12 +66,8 @@ DEFINE_SCREEN_SINGLETON( GrandPrixWin ); // ------------------------------------------------------------------------------------- -GrandPrixWin::GrandPrixWin() : Screen("grand_prix_win.stkgui", false /* pause race */) +GrandPrixWin::GrandPrixWin() : CutsceneScreen("grand_prix_win.stkgui") { - setNeeds3D(true); - - m_throttle_FPS = false; - m_kart_node[0] = NULL; m_kart_node[1] = NULL; m_kart_node[2] = NULL; @@ -84,6 +80,70 @@ GrandPrixWin::GrandPrixWin() : Screen("grand_prix_win.stkgui", false /* pause ra // ------------------------------------------------------------------------------------- +GrandPrixWin::~GrandPrixWin() +{ +} + +// ------------------------------------------------------------------------------------- + +void GrandPrixWin::onCutsceneEnd() +{ + for (unsigned int i = 0; igetTrack()->getTrackObjectManager(); + if (m_kart_node[0] != NULL) + m_kart_node[0]->getPresentation()->getNode()->remove(); + if (m_kart_node[1] != NULL) + m_kart_node[1]->getPresentation()->getNode()->remove(); + if (m_kart_node[2] != NULL) + m_kart_node[2]->getPresentation()->getNode()->remove(); + + m_kart_node[0] = NULL; + m_kart_node[1] = NULL; + m_kart_node[2] = NULL; + + m_podium_steps[0] = NULL; + m_podium_steps[1] = NULL; + m_podium_steps[2] = NULL; + + + + // un-set the GP mode so that after unlocking, it doesn't try to continue the GP + race_manager->setMajorMode(RaceManager::MAJOR_MODE_SINGLE); + + if (PlayerManager::getCurrentPlayer() + ->getRecentlyCompletedChallenges().size() > 0) + { + std::vector unlocked = + PlayerManager::getCurrentPlayer()->getRecentlyCompletedChallenges(); + PlayerManager::getCurrentPlayer()->clearUnlocked(); + + FeatureUnlockedCutScene* scene = FeatureUnlockedCutScene::getInstance(); + + assert(unlocked.size() > 0); + scene->addTrophy(race_manager->getDifficulty()); + scene->findWhatWasUnlocked(race_manager->getDifficulty()); + + StateManager::get()->replaceTopMostScreen(scene); + } + else + { + // we assume the main menu was pushed before showing this menu + StateManager::get()->popMenu(); + } +} + +// ------------------------------------------------------------------------------------- + void GrandPrixWin::loadedFromFile() { } // loadedFromFile @@ -161,29 +221,17 @@ void GrandPrixWin::init() // ------------------------------------------------------------------------------------- +bool GrandPrixWin::onEscapePressed() +{ + ((CutsceneWorld*)World::getWorld())->abortCutscene(); + return false; +} + +// ------------------------------------------------------------------------------------- + void GrandPrixWin::tearDown() { Screen::tearDown(); - ((CutsceneWorld*)World::getWorld())->abortCutscene(); - - for (unsigned int i = 0; isetMajorMode (RaceManager::MAJOR_MODE_SINGLE); - - if (PlayerManager::getCurrentPlayer() - ->getRecentlyCompletedChallenges().size() > 0) - { - std::vector unlocked = - PlayerManager::getCurrentPlayer()->getRecentlyCompletedChallenges(); - PlayerManager::getCurrentPlayer()->clearUnlocked(); - - FeatureUnlockedCutScene* scene = FeatureUnlockedCutScene::getInstance(); - - assert(unlocked.size() > 0); - scene->addTrophy(race_manager->getDifficulty()); - scene->findWhatWasUnlocked(race_manager->getDifficulty()); - - StateManager::get()->replaceTopMostScreen(scene); - } - else - { - // we assume the main menu was pushed before showing this menu - StateManager::get()->popMenu(); - } + ((CutsceneWorld*)World::getWorld())->abortCutscene(); } } // eventCallback diff --git a/src/states_screens/grand_prix_win.hpp b/src/states_screens/grand_prix_win.hpp index 89079306b..a702f134d 100644 --- a/src/states_screens/grand_prix_win.hpp +++ b/src/states_screens/grand_prix_win.hpp @@ -32,12 +32,14 @@ class TrackObject; * \brief Screen shown at the end of a Grand Prix * \ingroup states_screens */ -class GrandPrixWin : public GUIEngine::Screen, public GUIEngine::ScreenSingleton +class GrandPrixWin : public GUIEngine::CutsceneScreen, public GUIEngine::ScreenSingleton { friend class GUIEngine::ScreenSingleton; GrandPrixWin(); + virtual ~GrandPrixWin(); + /** Global evolution of time */ double m_global_time; @@ -61,6 +63,10 @@ class GrandPrixWin : public GUIEngine::Screen, public GUIEngine::ScreenSingleton public: + virtual void onCutsceneEnd() OVERRIDE; + + virtual bool onEscapePressed() OVERRIDE; + /** \brief implement callback from parent class GUIEngine::Screen */ virtual void loadedFromFile() OVERRIDE;