From 3816a09c6fd98d4d0b4ede58b8891c9ee845df26 Mon Sep 17 00:00:00 2001 From: mrcheko Date: Thu, 19 Dec 2013 22:08:34 +0200 Subject: [PATCH] bug 428 ask to load recent saved game --- apps/openmw/mwbase/statemanager.hpp | 2 ++ apps/openmw/mwmechanics/character.cpp | 6 ++-- apps/openmw/mwstate/statemanagerimp.cpp | 44 ++++++++++++++++++++++++- apps/openmw/mwstate/statemanagerimp.hpp | 3 ++ 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwbase/statemanager.hpp b/apps/openmw/mwbase/statemanager.hpp index 8548a74f7b..cd907408a5 100644 --- a/apps/openmw/mwbase/statemanager.hpp +++ b/apps/openmw/mwbase/statemanager.hpp @@ -44,6 +44,8 @@ namespace MWBase virtual bool hasQuitRequest() const = 0; + virtual void askLoadRecent() = 0; + virtual State getState() const = 0; virtual void newGame (bool bypass = false) = 0; diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 9a19ac7fa3..614d697ec5 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -32,6 +32,7 @@ #include "../mwbase/world.hpp" #include "../mwbase/soundmanager.hpp" #include "../mwbase/windowmanager.hpp" +#include "../mwbase/statemanager.hpp" #include "../mwworld/player.hpp" #include "../mwworld/class.hpp" @@ -1057,11 +1058,10 @@ bool CharacterController::kill() if( isDead() ) { //player's death animation is over - if( mPtr.getRefData().getHandle()=="player" && !isAnimPlaying(mCurrentDeath) - && MWBase::Environment::get().getWindowManager()->getMode() != MWGui::GM_MainMenu ) + if( mPtr.getRefData().getHandle()=="player" && !isAnimPlaying(mCurrentDeath) ) { MWWorld::Class::get(mPtr).getCreatureStats(mPtr).setHealth(0); - MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_MainMenu); + MWBase::Environment::get().getStateManager()->askLoadRecent(); } return false; } diff --git a/apps/openmw/mwstate/statemanagerimp.cpp b/apps/openmw/mwstate/statemanagerimp.cpp index bad4de03d5..9e6395812a 100644 --- a/apps/openmw/mwstate/statemanagerimp.cpp +++ b/apps/openmw/mwstate/statemanagerimp.cpp @@ -32,7 +32,7 @@ void MWState::StateManager::cleanup() } MWState::StateManager::StateManager (const boost::filesystem::path& saves, const std::string& game) -: mQuitRequest (false), mState (State_NoGame), mCharacterManager (saves, game), mTimePlayed (0) +: mQuitRequest (false), mAskLoadRecent(false), mState (State_NoGame), mCharacterManager (saves, game), mTimePlayed (0) { } @@ -47,6 +47,48 @@ bool MWState::StateManager::hasQuitRequest() const return mQuitRequest; } +void MWState::StateManager::askLoadRecent() +{ + if (MWBase::Environment::get().getWindowManager()->getMode() == MWGui::GM_MainMenu) + return; + + if( !mAskLoadRecent ) + { + if(MWBase::Environment::get().getStateManager()->getCurrentCharacter()->begin() + == MWBase::Environment::get().getStateManager()->getCurrentCharacter()->end() )//no saves + { + MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_MainMenu); + } + else + { + MWState::Slot lastSave = *getCurrentCharacter()->begin(); + std::vector buttons; + buttons.push_back("Yes"); + buttons.push_back("No"); + std::string message = "The most recent Save Game is '" + lastSave.mProfile.mDescription + "'.\n Would you like to load it?"; + MWBase::Environment::get().getWindowManager()->messageBox(message, buttons); + mAskLoadRecent = true; + } + } + else + { + int iButton = MWBase::Environment::get().getWindowManager()->readPressedButton(); + if(iButton==0) + { + mAskLoadRecent = false; + //Load last saved game for current character + MWState::Character *curCharacter = getCurrentCharacter(); + MWState::Slot lastSave = *curCharacter->begin(); + loadGame(curCharacter, &lastSave); + } + else if(iButton==1) + { + mAskLoadRecent = false; + MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_MainMenu); + } + } +} + MWState::StateManager::State MWState::StateManager::getState() const { return mState; diff --git a/apps/openmw/mwstate/statemanagerimp.hpp b/apps/openmw/mwstate/statemanagerimp.hpp index 78b5787660..a2abcfd1bd 100644 --- a/apps/openmw/mwstate/statemanagerimp.hpp +++ b/apps/openmw/mwstate/statemanagerimp.hpp @@ -12,6 +12,7 @@ namespace MWState class StateManager : public MWBase::StateManager { bool mQuitRequest; + bool mAskLoadRecent; State mState; CharacterManager mCharacterManager; double mTimePlayed; @@ -28,6 +29,8 @@ namespace MWState virtual bool hasQuitRequest() const; + virtual void askLoadRecent(); + virtual State getState() const; virtual void newGame (bool bypass = false);