6
6
7
7
#include " GUI.h"
8
8
#include " AllegroScreen.h"
9
+ #include " GAScripted.h"
9
10
#include " GUIInputWrapper.h"
10
11
#include " GUICollectionBox.h"
11
12
#include " GUILabel.h"
@@ -40,6 +41,7 @@ namespace RTE {
40
41
m_BackToMainButton->SetPositionAbs ((rootBox->GetWidth () - m_BackToMainButton->GetWidth ()) / 2 , saveGameMenuBox->GetYPos () + saveGameMenuBox->GetHeight () + 10 );
41
42
42
43
m_SaveGamesListBox = dynamic_cast <GUIListBox *>(m_GUIControlManager->GetControl (" ListBoxSaveGames" ));
44
+ m_SaveGamesListBox->SetFont (m_GUIControlManager->GetSkin ()->GetFont (" FontConsoleMonospace.png" ));
43
45
m_SaveGamesListBox->SetMouseScrolling (true );
44
46
m_SaveGamesListBox->SetScrollBarThickness (15 );
45
47
m_SaveGamesListBox->SetScrollBarPadding (2 );
@@ -56,26 +58,76 @@ namespace RTE {
56
58
57
59
void SaveLoadMenuGUI::PopulateSaveGamesList () {
58
60
m_SaveGames.clear ();
59
- m_SaveGamesListBox->ClearList ();
60
61
61
62
std::string saveFilePath = g_PresetMan.GetFullModulePath (c_UserScriptedSavesModuleName) + " /" ;
62
63
for (const auto &entry : std::filesystem::directory_iterator (saveFilePath)) {
63
64
if (entry.path ().extension () == " .ini" && entry.path ().filename () != " Index.ini" ) {
64
65
SaveRecord record;
65
- record.SaveName = entry.path (). stem (). string ();
66
+ record.SavePath = entry.path ();
66
67
record.SaveDate = entry.last_write_time ();
67
68
m_SaveGames.push_back (record);
68
69
}
69
70
}
70
71
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
+ {
71
110
std::sort (m_SaveGames.begin (), m_SaveGames.end ());
72
111
112
+ m_SaveGamesListBox->ClearList ();
73
113
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);
75
128
}
76
129
77
130
m_SaveGamesListBox->ScrollToTop ();
78
- m_SaveGamesFetched = true ;
79
131
}
80
132
81
133
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -127,7 +179,7 @@ namespace RTE {
127
179
if (guiEvent.GetControl () == m_SaveGamesListBox && (guiEvent.GetMsg () == GUIListBox::Select && m_SaveGamesListBox->GetSelectedIndex () > -1 )) {
128
180
const SaveRecord &record = m_SaveGames.at (m_SaveGamesListBox->GetSelected ()->m_ExtraIndex );
129
181
// m_DescriptionLabel->SetText(record.GetDisplayString());
130
- m_SaveGameName->SetText (record.SaveName );
182
+ m_SaveGameName->SetText (record.SavePath . stem (). string () );
131
183
}
132
184
}
133
185
}
0 commit comments