From ec5b2e9a7e90f3e9c3eb8ebb59f3d50995845dad Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 16 Nov 2013 12:22:28 +0100 Subject: [PATCH] added running flag; moved new game code to MWState --- apps/openmw/engine.cpp | 2 ++ apps/openmw/mwbase/statemanager.hpp | 7 +++++ apps/openmw/mwgui/mainmenu.cpp | 5 +--- apps/openmw/mwstate/statemanagerimp.cpp | 34 +++++++++++++++++++++++-- apps/openmw/mwstate/statemanagerimp.hpp | 8 ++++++ 5 files changed, 50 insertions(+), 6 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index cfb5522f1..c013cdaae 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -488,6 +488,8 @@ void OMW::Engine::go() // start in main menu if (!mSkipMenu) MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_MainMenu); + else + MWBase::Environment::get().getStateManager()->newGame (true); // Start the main rendering loop while (!mEnvironment.get().getStateManager()->hasQuitRequest()) diff --git a/apps/openmw/mwbase/statemanager.hpp b/apps/openmw/mwbase/statemanager.hpp index e90687293..076e66b8c 100644 --- a/apps/openmw/mwbase/statemanager.hpp +++ b/apps/openmw/mwbase/statemanager.hpp @@ -23,6 +23,13 @@ namespace MWBase virtual void requestQuit() = 0; virtual bool hasQuitRequest() const = 0; + + virtual bool isGameRunning() const = 0; + + virtual void newGame (bool bypass = false) = 0; + ///< Start a new game. + /// + /// \param bypass Skip new game mechanics. }; } diff --git a/apps/openmw/mwgui/mainmenu.cpp b/apps/openmw/mwgui/mainmenu.cpp index a58a3d0eb..cb3436715 100644 --- a/apps/openmw/mwgui/mainmenu.cpp +++ b/apps/openmw/mwgui/mainmenu.cpp @@ -81,10 +81,7 @@ namespace MWGui MWBase::Environment::get().getStateManager()->requestQuit(); else if (sender == mButtons["newgame"]) { - MWBase::Environment::get().getWorld()->startNewGame(); - MWBase::Environment::get().getWindowManager()->setNewGame(true); - MWBase::Environment::get().getDialogueManager()->clear(); - MWBase::Environment::get().getJournal()->clear(); + MWBase::Environment::get().getStateManager()->newGame(); } else if (sender == mButtons["loadgame"]) diff --git a/apps/openmw/mwstate/statemanagerimp.cpp b/apps/openmw/mwstate/statemanagerimp.cpp index f5e71d0ce..a226b166d 100644 --- a/apps/openmw/mwstate/statemanagerimp.cpp +++ b/apps/openmw/mwstate/statemanagerimp.cpp @@ -1,8 +1,14 @@ #include "statemanagerimp.hpp" +#include "../mwbase/environment.hpp" +#include "../mwbase/world.hpp" +#include "../mwbase/journal.hpp" +#include "../mwbase/dialoguemanager.hpp" +#include "../mwbase/windowmanager.hpp" + MWState::StateManager::StateManager() -: mQuitRequest (false) +: mQuitRequest (false), mRunning (false) { } @@ -15,4 +21,28 @@ void MWState::StateManager::requestQuit() bool MWState::StateManager::hasQuitRequest() const { return mQuitRequest; -} \ No newline at end of file +} + +bool MWState::StateManager::isGameRunning() const +{ + return mRunning; +} + +void MWState::StateManager::newGame (bool bypass) +{ + if (mRunning) + { + MWBase::Environment::get().getDialogueManager()->clear(); + MWBase::Environment::get().getJournal()->clear(); + mRunning = false; + } + + if (!bypass) + { + /// \todo extract cleanup code + MWBase::Environment::get().getWorld()->startNewGame(); + MWBase::Environment::get().getWindowManager()->setNewGame (true); + } + + mRunning = true; +} diff --git a/apps/openmw/mwstate/statemanagerimp.hpp b/apps/openmw/mwstate/statemanagerimp.hpp index 271403ce5..9f8096a4a 100644 --- a/apps/openmw/mwstate/statemanagerimp.hpp +++ b/apps/openmw/mwstate/statemanagerimp.hpp @@ -8,6 +8,7 @@ namespace MWState class StateManager : public MWBase::StateManager { bool mQuitRequest; + bool mRunning; public: @@ -16,6 +17,13 @@ namespace MWState virtual void requestQuit(); virtual bool hasQuitRequest() const; + + virtual bool isGameRunning() const; + + virtual void newGame (bool bypass = false); + ///< Start a new game. + /// + /// \param bypass Skip new game mechanics. }; }