Skip to content

Commit ece8b62

Browse files
committed
Added activity/scene/date info
1 parent 4d948f8 commit ece8b62

File tree

2 files changed

+67
-8
lines changed

2 files changed

+67
-8
lines changed

Menus/SaveLoadMenuGUI.cpp

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "GUI.h"
88
#include "AllegroScreen.h"
9+
#include "GAScripted.h"
910
#include "GUIInputWrapper.h"
1011
#include "GUICollectionBox.h"
1112
#include "GUILabel.h"
@@ -40,6 +41,7 @@ namespace RTE {
4041
m_BackToMainButton->SetPositionAbs((rootBox->GetWidth() - m_BackToMainButton->GetWidth()) / 2, saveGameMenuBox->GetYPos() + saveGameMenuBox->GetHeight() + 10);
4142

4243
m_SaveGamesListBox = dynamic_cast<GUIListBox *>(m_GUIControlManager->GetControl("ListBoxSaveGames"));
44+
m_SaveGamesListBox->SetFont(m_GUIControlManager->GetSkin()->GetFont("FontConsoleMonospace.png"));
4345
m_SaveGamesListBox->SetMouseScrolling(true);
4446
m_SaveGamesListBox->SetScrollBarThickness(15);
4547
m_SaveGamesListBox->SetScrollBarPadding(2);
@@ -56,26 +58,76 @@ namespace RTE {
5658

5759
void SaveLoadMenuGUI::PopulateSaveGamesList() {
5860
m_SaveGames.clear();
59-
m_SaveGamesListBox->ClearList();
6061

6162
std::string saveFilePath = g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/";
6263
for (const auto &entry : std::filesystem::directory_iterator(saveFilePath)) {
6364
if (entry.path().extension() == ".ini" && entry.path().filename() != "Index.ini") {
6465
SaveRecord record;
65-
record.SaveName = entry.path().stem().string();
66+
record.SavePath = entry.path();
6667
record.SaveDate = entry.last_write_time();
6768
m_SaveGames.push_back(record);
6869
}
6970
}
7071

72+
std::for_each(std::execution::par_unseq,
73+
m_SaveGames.begin(), m_SaveGames.end(),
74+
[](SaveRecord &record) {
75+
Reader reader(record.SavePath.string(), true, nullptr, true);
76+
77+
bool readActivity = false;
78+
bool readSceneName = false;
79+
80+
GAScripted activity;
81+
82+
std::string originalScenePresetName;
83+
while (reader.NextProperty()) {
84+
std::string propName = reader.ReadPropName();
85+
if (propName == "Activity") {
86+
reader >> activity;
87+
readActivity = true;
88+
} else if (propName == "OriginalScenePresetName") {
89+
reader >> originalScenePresetName;
90+
readSceneName = true;
91+
}
92+
93+
if (readActivity && readSceneName) {
94+
break;
95+
}
96+
}
97+
98+
record.Activity = activity.GetPresetName();
99+
record.Scene = originalScenePresetName;
100+
});
101+
102+
m_SaveGamesFetched = true;
103+
UpdateSaveGamesGUIList();
104+
}
105+
106+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
107+
108+
void SaveLoadMenuGUI::UpdateSaveGamesGUIList()
109+
{
71110
std::sort(m_SaveGames.begin(), m_SaveGames.end());
72111

112+
m_SaveGamesListBox->ClearList();
73113
for (int i = 0; i < m_SaveGames.size(); i++) {
74-
m_SaveGamesListBox->AddItem(m_SaveGames.at(i).SaveName, std::string(), nullptr, nullptr, i);
114+
const SaveRecord &save = m_SaveGames[i];
115+
116+
std::stringstream saveNameText;
117+
saveNameText << std::left << std::setfill(' ') << std::setw(32) << save.SavePath.stem().string();
118+
119+
// This is so much more fucking difficult than it has any right to be
120+
const auto saveFsTime = std::chrono::clock_cast<std::chrono::system_clock>(save.SaveDate);
121+
const auto saveTime = std::chrono::system_clock::to_time_t(saveFsTime);
122+
const auto saveTimeLocal = std::localtime(&saveTime);
123+
124+
std::stringstream saveDateTimeText;
125+
saveDateTimeText << std::put_time(saveTimeLocal, "%Y-%m-%d %X");
126+
127+
m_SaveGamesListBox->AddItem(" " + saveNameText.str() + "" + save.Scene + " - " + save.Activity + "", saveDateTimeText.str() + " ", nullptr, nullptr, i);
75128
}
76129

77130
m_SaveGamesListBox->ScrollToTop();
78-
m_SaveGamesFetched = true;
79131
}
80132

81133
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -127,7 +179,7 @@ namespace RTE {
127179
if (guiEvent.GetControl() == m_SaveGamesListBox && (guiEvent.GetMsg() == GUIListBox::Select && m_SaveGamesListBox->GetSelectedIndex() > -1)) {
128180
const SaveRecord &record = m_SaveGames.at(m_SaveGamesListBox->GetSelected()->m_ExtraIndex);
129181
//m_DescriptionLabel->SetText(record.GetDisplayString());
130-
m_SaveGameName->SetText(record.SaveName);
182+
m_SaveGameName->SetText(record.SavePath.stem().string());
131183
}
132184
}
133185
}

Menus/SaveLoadMenuGUI.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ namespace RTE {
4848
/// Struct containing information about a valid Savegame.
4949
/// </summary>
5050
struct SaveRecord {
51-
std::string SaveName; //!< Savegame name.
52-
std::filesystem::file_time_type SaveDate; //!< Savegame last modified date.
51+
std::filesystem::path SavePath; //!< Savegame filepath.
52+
std::filesystem::file_time_type SaveDate; //!< Last modified date.
53+
std::string Activity; //!< The activity name.
54+
std::string Scene; //!< The scene name.
5355

5456
bool operator<(const SaveRecord &rhs) const { return SaveDate > rhs.SaveDate; }
5557
};
@@ -78,10 +80,15 @@ namespace RTE {
7880
bool ListsFetched() const { return m_SaveGamesFetched; }
7981

8082
/// <summary>
81-
/// Fills the SaveGames list with all valid savegames, then fills the SaveGamesListBox using it.
83+
/// Fills the SaveGames list with all valid savegames.
8284
/// </summary>
8385
void PopulateSaveGamesList();
8486

87+
/// <summary>
88+
/// Updates the SaveGamesListBox GUI.
89+
/// </summary>
90+
void UpdateSaveGamesGUIList();
91+
8592
/// <summary>
8693
/// Loads the currently selected savefile.
8794
/// </summary>

0 commit comments

Comments
 (0)