1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-10-16 16:46:34 +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)) << ")";
const MyGUI::UString playerDesc = MyGUI::LanguageManager::getInstance().replaceTags(title.str());
mCharacterSelection->addItem(playerDesc, signature.mPlayerName);
mCharacterSelection->addItem(playerDesc, &*it);
if (mCurrentCharacter == &*it
|| (!mCurrentCharacter && !mSaving
&& Misc::StringUtils::ciEqual(
directory, Files::pathToUnicodeString(it->begin()->mPath.parent_path().filename()))))
&& Misc::StringUtils::ciEqual(directory, Files::pathToUnicodeString(it->getPath().filename()))))
{
mCurrentCharacter = &*it;
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);
if (selectedIndex == MyGUI::ITEM_NONE)
mCharacterSelection->setCaptionWithReplacing("#{OMWEngine:SelectCharacter}");
@ -322,16 +326,7 @@ namespace MWGui
void SaveGameDialog::onCharacterSelected(MyGUI::ComboBox* sender, size_t pos)
{
MWBase::StateManager* mgr = MWBase::Environment::get().getStateManager();
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");
const MWState::Character* character = *mCharacterSelection->getItemDataAt<const MWState::Character*>(pos);
mCurrentCharacter = character;
mCurrentSlot = nullptr;
@ -402,7 +397,7 @@ namespace MWGui
mSaveNameEdit->setCaption(sender->getItemNameAt(pos));
mCurrentSlot = nullptr;
unsigned int i = 0;
size_t i = 0;
for (MWState::Character::SlotIterator it = mCurrentCharacter->begin(); it != mCurrentCharacter->end();
++it, ++i)
{
@ -416,8 +411,9 @@ namespace MWGui
const size_t profileIndex = mCharacterSelection->getIndexSelected();
const std::string& slotPlayerName = mCurrentSlot->mProfile.mPlayerName;
const std::string& profilePlayerName = *mCharacterSelection->getItemDataAt<std::string>(profileIndex);
if (slotPlayerName != profilePlayerName)
const ESM::SavedGame& profileSavedGame
= (*mCharacterSelection->getItemDataAt<const MWState::Character*>(profileIndex))->getSignature();
if (slotPlayerName != profileSavedGame.mPlayerName)
text << slotPlayerName << "\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;
}
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)
{
if (Misc::StringUtils::ciEndsWith(c, ".esm") || Misc::StringUtils::ciEndsWith(c, ".omwgame"))
return c;
}
return "";
return {};
}
void MWState::Character::addSlot(const std::filesystem::path& path, const std::string& game)

View file

@ -2,6 +2,7 @@
#define GAME_STATE_CHARACTER_H
#include <filesystem>
#include <string_view>
#include <components/esm3/savedgame.hpp>
@ -14,9 +15,7 @@ namespace MWState
std::filesystem::file_time_type mTimeStamp;
};
bool operator<(const Slot& left, const Slot& right);
std::string getFirstGameFile(const std::vector<std::string>& contentFiles);
std::string_view getFirstGameFile(const std::vector<std::string>& contentFiles);
class Character
{
@ -63,7 +62,12 @@ namespace MWState
///< Return signature information for this character.
///
/// \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

View file

@ -18,10 +18,8 @@ MWState::CharacterManager::CharacterManager(std::filesystem::path saves, const s
}
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))
{
Character character(characterDir, mGame);
@ -30,6 +28,7 @@ MWState::CharacterManager::CharacterManager(std::filesystem::path saves, const s
mCharacters.push_back(character);
}
}
mCharacters.sort();
}
}