diff --git a/apps/openmw/mwbase/statemanager.hpp b/apps/openmw/mwbase/statemanager.hpp index f1f130824..f376d72c1 100644 --- a/apps/openmw/mwbase/statemanager.hpp +++ b/apps/openmw/mwbase/statemanager.hpp @@ -63,7 +63,8 @@ namespace MWBase /// /// \note \a slot must belong to \a character. - virtual MWState::Character *getCurrentCharacter() = 0; + virtual MWState::Character *getCurrentCharacter (bool create = true) = 0; + ///< \param create Create a new character, if there is no current character. virtual CharacterIterator characterBegin() = 0; ///< Any call to SaveGame and getCurrentCharacter can invalidate the returned diff --git a/apps/openmw/mwgui/savegamedialog.cpp b/apps/openmw/mwgui/savegamedialog.cpp index 38574e2fd..2ce0f0fbf 100644 --- a/apps/openmw/mwgui/savegamedialog.cpp +++ b/apps/openmw/mwgui/savegamedialog.cpp @@ -91,9 +91,10 @@ namespace MWGui if (mgr->characterBegin() == mgr->characterEnd()) return; - mCurrentCharacter = mgr->getCurrentCharacter(); + mCurrentCharacter = mgr->getCurrentCharacter (false); mCharacterSelection->removeAllItems(); + for (MWBase::StateManager::CharacterIterator it = mgr->characterBegin(); it != mgr->characterEnd(); ++it) { if (it->begin()!=it->end()) @@ -104,7 +105,7 @@ namespace MWGui mCharacterSelection->addItem (title.str()); - if (mgr->getCurrentCharacter() == &*it) + if (mCurrentCharacter == &*it) mCharacterSelection->setIndexSelected(mCharacterSelection->getItemCount()-1); } } @@ -123,7 +124,7 @@ namespace MWGui if (!load) { - mCurrentCharacter = MWBase::Environment::get().getStateManager()->getCurrentCharacter(); + mCurrentCharacter = MWBase::Environment::get().getStateManager()->getCurrentCharacter (false); } center(); @@ -139,10 +140,14 @@ namespace MWGui // Get the selected slot, if any unsigned int i=0; const MWState::Slot* slot = NULL; - for (MWState::Character::SlotIterator it = mCurrentCharacter->begin(); it != mCurrentCharacter->end(); ++it,++i) + + if (mCurrentCharacter) { - if (i == mSaveList->getIndexSelected()) - slot = &*it; + for (MWState::Character::SlotIterator it = mCurrentCharacter->begin(); it != mCurrentCharacter->end(); ++it,++i) + { + if (i == mSaveList->getIndexSelected()) + slot = &*it; + } } if (mSaving) @@ -151,7 +156,8 @@ namespace MWGui } else { - MWBase::Environment::get().getStateManager()->loadGame (mCurrentCharacter, slot); + if (mCurrentCharacter && slot) + MWBase::Environment::get().getStateManager()->loadGame (mCurrentCharacter, slot); } setVisible(false); diff --git a/apps/openmw/mwstate/charactermanager.cpp b/apps/openmw/mwstate/charactermanager.cpp index 2b9c49fcc..cb64da2c2 100644 --- a/apps/openmw/mwstate/charactermanager.cpp +++ b/apps/openmw/mwstate/charactermanager.cpp @@ -38,9 +38,9 @@ MWState::CharacterManager::CharacterManager (const boost::filesystem::path& save } } -MWState::Character *MWState::CharacterManager::getCurrentCharacter() +MWState::Character *MWState::CharacterManager::getCurrentCharacter (bool create) { - if (!mCurrent) + if (!mCurrent && create) createCharacter(); return mCurrent; diff --git a/apps/openmw/mwstate/charactermanager.hpp b/apps/openmw/mwstate/charactermanager.hpp index 9995393aa..a02927d58 100644 --- a/apps/openmw/mwstate/charactermanager.hpp +++ b/apps/openmw/mwstate/charactermanager.hpp @@ -26,8 +26,8 @@ namespace MWState CharacterManager (const boost::filesystem::path& saves); - Character *getCurrentCharacter(); - ///< A character is implicitly created, if there is none. + Character *getCurrentCharacter (bool create = true); + ///< \param create Create a new character, if there is no current character. void createCharacter(); ///< Create new character within saved game management diff --git a/apps/openmw/mwstate/statemanagerimp.cpp b/apps/openmw/mwstate/statemanagerimp.cpp index 9d8cf2a81..9a7e3d158 100644 --- a/apps/openmw/mwstate/statemanagerimp.cpp +++ b/apps/openmw/mwstate/statemanagerimp.cpp @@ -138,9 +138,9 @@ void MWState::StateManager::loadGame (const Character *character, const Slot *sl mState = State_Running; } -MWState::Character *MWState::StateManager::getCurrentCharacter() +MWState::Character *MWState::StateManager::getCurrentCharacter (bool create) { - return mCharacterManager.getCurrentCharacter(); + return mCharacterManager.getCurrentCharacter (create); } MWState::StateManager::CharacterIterator MWState::StateManager::characterBegin() diff --git a/apps/openmw/mwstate/statemanagerimp.hpp b/apps/openmw/mwstate/statemanagerimp.hpp index abf7e123b..8bf1fab20 100644 --- a/apps/openmw/mwstate/statemanagerimp.hpp +++ b/apps/openmw/mwstate/statemanagerimp.hpp @@ -42,7 +42,8 @@ namespace MWState /// /// \note \a slot must belong to \a character. - virtual Character *getCurrentCharacter(); + virtual Character *getCurrentCharacter (bool create = true); + ///< \param create Create a new character, if there is no current character. virtual CharacterIterator characterBegin(); ///< Any call to SaveGame and getCurrentCharacter can invalidate the returned