1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-17 01:10:10 +00:00

bug 428 ask to load recent saved game

This commit is contained in:
mrcheko 2013-12-19 22:08:34 +02:00
parent a854eb73db
commit 3816a09c6f
4 changed files with 51 additions and 4 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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<std::string> 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;

View File

@ -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);