1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-11-08 20:16:43 +00:00

Merge branch 'sortedsaves' into 'master'

Order characters by last save

Closes #8580

See merge request OpenMW/openmw!4730
This commit is contained in:
psi29a 2025-07-03 07:06:27 +00:00
commit ea147d78ed
4 changed files with 34 additions and 24 deletions

View file

@ -198,12 +198,11 @@ namespace MWGui
<< MyGUI::TextIterator::toTagsString(MyGUI::UString(className)) << ")"; << MyGUI::TextIterator::toTagsString(MyGUI::UString(className)) << ")";
const MyGUI::UString playerDesc = MyGUI::LanguageManager::getInstance().replaceTags(title.str()); const MyGUI::UString playerDesc = MyGUI::LanguageManager::getInstance().replaceTags(title.str());
mCharacterSelection->addItem(playerDesc, signature.mPlayerName); mCharacterSelection->addItem(playerDesc, &*it);
if (mCurrentCharacter == &*it if (mCurrentCharacter == &*it
|| (!mCurrentCharacter && !mSaving || (!mCurrentCharacter && !mSaving
&& Misc::StringUtils::ciEqual( && Misc::StringUtils::ciEqual(directory, Files::pathToUnicodeString(it->getPath().filename()))))
directory, Files::pathToUnicodeString(it->begin()->mPath.parent_path().filename()))))
{ {
mCurrentCharacter = &*it; mCurrentCharacter = &*it;
selectedIndex = mCharacterSelection->getItemCount() - 1; selectedIndex = mCharacterSelection->getItemCount() - 1;
@ -211,6 +210,11 @@ namespace MWGui
} }
} }
if (selectedIndex == MyGUI::ITEM_NONE && !mSaving && mCharacterSelection->getItemCount() != 0)
{
selectedIndex = 0;
mCurrentCharacter = *mCharacterSelection->getItemDataAt<const MWState::Character*>(0);
}
mCharacterSelection->setIndexSelected(selectedIndex); mCharacterSelection->setIndexSelected(selectedIndex);
if (selectedIndex == MyGUI::ITEM_NONE) if (selectedIndex == MyGUI::ITEM_NONE)
mCharacterSelection->setCaptionWithReplacing("#{OMWEngine:SelectCharacter}"); mCharacterSelection->setCaptionWithReplacing("#{OMWEngine:SelectCharacter}");
@ -322,16 +326,7 @@ namespace MWGui
void SaveGameDialog::onCharacterSelected(MyGUI::ComboBox* sender, size_t pos) void SaveGameDialog::onCharacterSelected(MyGUI::ComboBox* sender, size_t pos)
{ {
MWBase::StateManager* mgr = MWBase::Environment::get().getStateManager(); const MWState::Character* character = *mCharacterSelection->getItemDataAt<const MWState::Character*>(pos);
unsigned int i = 0;
const MWState::Character* character = nullptr;
for (MWBase::StateManager::CharacterIterator it = mgr->characterBegin(); it != mgr->characterEnd(); ++it, ++i)
{
if (i == pos)
character = &*it;
}
assert(character && "Can't find selected character");
mCurrentCharacter = character; mCurrentCharacter = character;
mCurrentSlot = nullptr; mCurrentSlot = nullptr;
@ -402,7 +397,7 @@ namespace MWGui
mSaveNameEdit->setCaption(sender->getItemNameAt(pos)); mSaveNameEdit->setCaption(sender->getItemNameAt(pos));
mCurrentSlot = nullptr; mCurrentSlot = nullptr;
unsigned int i = 0; size_t i = 0;
for (MWState::Character::SlotIterator it = mCurrentCharacter->begin(); it != mCurrentCharacter->end(); for (MWState::Character::SlotIterator it = mCurrentCharacter->begin(); it != mCurrentCharacter->end();
++it, ++i) ++it, ++i)
{ {
@ -416,8 +411,9 @@ namespace MWGui
const size_t profileIndex = mCharacterSelection->getIndexSelected(); const size_t profileIndex = mCharacterSelection->getIndexSelected();
const std::string& slotPlayerName = mCurrentSlot->mProfile.mPlayerName; const std::string& slotPlayerName = mCurrentSlot->mProfile.mPlayerName;
const std::string& profilePlayerName = *mCharacterSelection->getItemDataAt<std::string>(profileIndex); const ESM::SavedGame& profileSavedGame
if (slotPlayerName != profilePlayerName) = (*mCharacterSelection->getItemDataAt<const MWState::Character*>(profileIndex))->getSignature();
if (slotPlayerName != profileSavedGame.mPlayerName)
text << slotPlayerName << "\n"; text << slotPlayerName << "\n";
text << "#{OMWEngine:Level} " << mCurrentSlot->mProfile.mPlayerLevel << "\n"; text << "#{OMWEngine:Level} " << mCurrentSlot->mProfile.mPlayerLevel << "\n";

View file

@ -18,14 +18,25 @@ bool MWState::operator<(const Slot& left, const Slot& right)
return left.mTimeStamp < right.mTimeStamp; return left.mTimeStamp < right.mTimeStamp;
} }
std::string MWState::getFirstGameFile(const std::vector<std::string>& contentFiles) bool MWState::operator<(const Character& left, const Character& right)
{
if (left.mSlots.empty() && right.mSlots.empty())
return left.mPath < right.mPath;
else if (left.mSlots.empty())
return false;
else if (right.mSlots.empty())
return true;
return right.mSlots.back() < left.mSlots.back();
}
std::string_view MWState::getFirstGameFile(const std::vector<std::string>& contentFiles)
{ {
for (const std::string& c : contentFiles) for (const std::string& c : contentFiles)
{ {
if (Misc::StringUtils::ciEndsWith(c, ".esm") || Misc::StringUtils::ciEndsWith(c, ".omwgame")) if (Misc::StringUtils::ciEndsWith(c, ".esm") || Misc::StringUtils::ciEndsWith(c, ".omwgame"))
return c; return c;
} }
return ""; return {};
} }
void MWState::Character::addSlot(const std::filesystem::path& path, const std::string& game) void MWState::Character::addSlot(const std::filesystem::path& path, const std::string& game)

View file

@ -2,6 +2,7 @@
#define GAME_STATE_CHARACTER_H #define GAME_STATE_CHARACTER_H
#include <filesystem> #include <filesystem>
#include <string_view>
#include <components/esm3/savedgame.hpp> #include <components/esm3/savedgame.hpp>
@ -14,9 +15,7 @@ namespace MWState
std::filesystem::file_time_type mTimeStamp; std::filesystem::file_time_type mTimeStamp;
}; };
bool operator<(const Slot& left, const Slot& right); std::string_view getFirstGameFile(const std::vector<std::string>& contentFiles);
std::string getFirstGameFile(const std::vector<std::string>& contentFiles);
class Character class Character
{ {
@ -63,7 +62,12 @@ namespace MWState
///< Return signature information for this character. ///< Return signature information for this character.
/// ///
/// \attention This function must not be called if there are no slots. /// \attention This function must not be called if there are no slots.
friend bool operator<(const Character& left, const Character& right);
}; };
bool operator<(const Slot& left, const Slot& right);
bool operator<(const Character& left, const Character& right);
} }
#endif #endif

View file

@ -18,10 +18,8 @@ MWState::CharacterManager::CharacterManager(std::filesystem::path saves, const s
} }
else else
{ {
for (std::filesystem::directory_iterator iter(mPath); iter != std::filesystem::directory_iterator(); ++iter) for (const std::filesystem::path& characterDir : std::filesystem::directory_iterator(mPath))
{ {
std::filesystem::path characterDir = *iter;
if (std::filesystem::is_directory(characterDir)) if (std::filesystem::is_directory(characterDir))
{ {
Character character(characterDir, mGame); Character character(characterDir, mGame);
@ -30,6 +28,7 @@ MWState::CharacterManager::CharacterManager(std::filesystem::path saves, const s
mCharacters.push_back(character); mCharacters.push_back(character);
} }
} }
mCharacters.sort();
} }
} }