This is an automated email from the git hooks/post-receive script. odyx pushed a commit to branch upstream/latest in repository colobot.
commit b8103963c32f9ee303f8555a5fec578e3f70f416 Author: krzys-h <krzy...@interia.pl> Date: Tue Nov 11 12:08:19 2014 +0100 Sorting saved games list (#380) --- src/common/misc.cpp | 5 +++++ src/common/misc.h | 1 + src/object/robotmain.cpp | 4 ++++ src/ui/maindialog.cpp | 17 ++++++++++++++--- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/common/misc.cpp b/src/common/misc.cpp index 35a5560..1234f7b 100644 --- a/src/common/misc.cpp +++ b/src/common/misc.cpp @@ -28,6 +28,7 @@ #include <time.h> #include <sstream> #include <iomanip> +#include <chrono> // Returns a non-accented letter. @@ -254,3 +255,7 @@ void AddExt(char* filename, const char* ext) strcat(filename, ext); } +int GetCurrentTimestamp() +{ + return std::chrono::seconds(std::time(NULL)).count(); +} \ No newline at end of file diff --git a/src/common/misc.h b/src/common/misc.h index b53bbdd..86b3c0e 100644 --- a/src/common/misc.h +++ b/src/common/misc.h @@ -37,3 +37,4 @@ extern std::string TimeFormat(float time); extern void AddExt(char* filename, const char* ext); +extern int GetCurrentTimestamp(); diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 5a72d69..b44e704 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -5712,6 +5712,10 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char * line->AddParam("maj", new CLevelParserParam(0)); line->AddParam("min", new CLevelParserParam(1)); level->AddLine(line); + + line = new CLevelParserLine("Created"); + line->AddParam("date", new CLevelParserParam(GetCurrentTimestamp())); + level->AddLine(line); char* name = m_dialog->GetSceneName(); line = new CLevelParserLine("Mission"); diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 829fab4..69a9136 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -3945,6 +3945,7 @@ void CMainDialog::IOReadName() pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_IONAME)); if ( pe == nullptr ) return; + //TODO: CLevelParser sprintf(resume, "%s %d", m_sceneName, m_chap[m_index]+1); BuildSceneName(filename, m_sceneName, (m_chap[m_index]+1)*100); sprintf(op, "Title.E"); @@ -4004,7 +4005,10 @@ void CMainDialog::IOReadList() std::string userSaveDir = m_savegameDir + "/" + m_main->GetGamerName(); auto saveDirs = CResourceManager::ListDirectories(userSaveDir); - std::sort(saveDirs.begin(), saveDirs.end()); + //std::sort(saveDirs.begin(), saveDirs.end()); + + std::map<int, std::string> sortedSaveDirs; + std::map<int, std::string> names; for (auto dir : saveDirs) { @@ -4013,11 +4017,18 @@ void CMainDialog::IOReadList() { CLevelParser* level = new CLevelParser(savegameFile); level->Load(); - pl->SetItemName(m_saveList.size(), level->Get("Title")->GetParam("text")->AsString().c_str()); - m_saveList.push_back(userSaveDir + "/" + dir); + int time = level->Get("Created")->GetParam("date")->AsInt(); + sortedSaveDirs[time] = userSaveDir + "/" + dir; + names[time] = level->Get("Title")->GetParam("text")->AsString(); delete level; } } + + for (auto dir : sortedSaveDirs) + { + pl->SetItemName(m_saveList.size(), names[dir.first].c_str()); + m_saveList.push_back(dir.second); + } // invalid index if ( m_phase == PHASE_WRITE || m_phase == PHASE_WRITEs ) -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git _______________________________________________ Pkg-games-commits mailing list Pkg-games-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits