forked from mirror/openmw-tes3mp
improved character selection logic
This commit is contained in:
parent
67cd0887e6
commit
e3670cff8a
6 changed files with 23 additions and 15 deletions
|
@ -63,7 +63,8 @@ namespace MWBase
|
||||||
///
|
///
|
||||||
/// \note \a slot must belong to \a character.
|
/// \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;
|
virtual CharacterIterator characterBegin() = 0;
|
||||||
///< Any call to SaveGame and getCurrentCharacter can invalidate the returned
|
///< Any call to SaveGame and getCurrentCharacter can invalidate the returned
|
||||||
|
|
|
@ -91,9 +91,10 @@ namespace MWGui
|
||||||
if (mgr->characterBegin() == mgr->characterEnd())
|
if (mgr->characterBegin() == mgr->characterEnd())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mCurrentCharacter = mgr->getCurrentCharacter();
|
mCurrentCharacter = mgr->getCurrentCharacter (false);
|
||||||
|
|
||||||
mCharacterSelection->removeAllItems();
|
mCharacterSelection->removeAllItems();
|
||||||
|
|
||||||
for (MWBase::StateManager::CharacterIterator it = mgr->characterBegin(); it != mgr->characterEnd(); ++it)
|
for (MWBase::StateManager::CharacterIterator it = mgr->characterBegin(); it != mgr->characterEnd(); ++it)
|
||||||
{
|
{
|
||||||
if (it->begin()!=it->end())
|
if (it->begin()!=it->end())
|
||||||
|
@ -104,7 +105,7 @@ namespace MWGui
|
||||||
|
|
||||||
mCharacterSelection->addItem (title.str());
|
mCharacterSelection->addItem (title.str());
|
||||||
|
|
||||||
if (mgr->getCurrentCharacter() == &*it)
|
if (mCurrentCharacter == &*it)
|
||||||
mCharacterSelection->setIndexSelected(mCharacterSelection->getItemCount()-1);
|
mCharacterSelection->setIndexSelected(mCharacterSelection->getItemCount()-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +124,7 @@ namespace MWGui
|
||||||
|
|
||||||
if (!load)
|
if (!load)
|
||||||
{
|
{
|
||||||
mCurrentCharacter = MWBase::Environment::get().getStateManager()->getCurrentCharacter();
|
mCurrentCharacter = MWBase::Environment::get().getStateManager()->getCurrentCharacter (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
center();
|
center();
|
||||||
|
@ -139,10 +140,14 @@ namespace MWGui
|
||||||
// Get the selected slot, if any
|
// Get the selected slot, if any
|
||||||
unsigned int i=0;
|
unsigned int i=0;
|
||||||
const MWState::Slot* slot = NULL;
|
const MWState::Slot* slot = NULL;
|
||||||
for (MWState::Character::SlotIterator it = mCurrentCharacter->begin(); it != mCurrentCharacter->end(); ++it,++i)
|
|
||||||
|
if (mCurrentCharacter)
|
||||||
{
|
{
|
||||||
if (i == mSaveList->getIndexSelected())
|
for (MWState::Character::SlotIterator it = mCurrentCharacter->begin(); it != mCurrentCharacter->end(); ++it,++i)
|
||||||
slot = &*it;
|
{
|
||||||
|
if (i == mSaveList->getIndexSelected())
|
||||||
|
slot = &*it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSaving)
|
if (mSaving)
|
||||||
|
@ -151,7 +156,8 @@ namespace MWGui
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MWBase::Environment::get().getStateManager()->loadGame (mCurrentCharacter, slot);
|
if (mCurrentCharacter && slot)
|
||||||
|
MWBase::Environment::get().getStateManager()->loadGame (mCurrentCharacter, slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
|
|
|
@ -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();
|
createCharacter();
|
||||||
|
|
||||||
return mCurrent;
|
return mCurrent;
|
||||||
|
|
|
@ -26,8 +26,8 @@ namespace MWState
|
||||||
|
|
||||||
CharacterManager (const boost::filesystem::path& saves);
|
CharacterManager (const boost::filesystem::path& saves);
|
||||||
|
|
||||||
Character *getCurrentCharacter();
|
Character *getCurrentCharacter (bool create = true);
|
||||||
///< A character is implicitly created, if there is none.
|
///< \param create Create a new character, if there is no current character.
|
||||||
|
|
||||||
void createCharacter();
|
void createCharacter();
|
||||||
///< Create new character within saved game management
|
///< Create new character within saved game management
|
||||||
|
|
|
@ -138,9 +138,9 @@ void MWState::StateManager::loadGame (const Character *character, const Slot *sl
|
||||||
mState = State_Running;
|
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()
|
MWState::StateManager::CharacterIterator MWState::StateManager::characterBegin()
|
||||||
|
|
|
@ -42,7 +42,8 @@ namespace MWState
|
||||||
///
|
///
|
||||||
/// \note \a slot must belong to \a character.
|
/// \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();
|
virtual CharacterIterator characterBegin();
|
||||||
///< Any call to SaveGame and getCurrentCharacter can invalidate the returned
|
///< Any call to SaveGame and getCurrentCharacter can invalidate the returned
|
||||||
|
|
Loading…
Reference in a new issue