Skip to content

Commit 65fef08

Browse files
committed
Added order-by to save list
1 parent 8dcf097 commit 65fef08

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

Menus/SaveLoadMenuGUI.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "GUIButton.h"
1414
#include "GUIListBox.h"
1515
#include "GUITextBox.h"
16+
#include "GUIComboBox.h"
1617

1718
namespace RTE {
1819

@@ -32,6 +33,12 @@ namespace RTE {
3233
saveGameMenuBox->CenterInParent(true, true);
3334
saveGameMenuBox->SetPositionAbs(saveGameMenuBox->GetXPos(), (rootBox->GetHeight() < 540) ? saveGameMenuBox->GetYPos() - 15 : 140);
3435

36+
m_OrderByComboBox = dynamic_cast<GUIComboBox*>(m_GUIControlManager->GetControl("ComboOrderBy"));
37+
m_OrderByComboBox->AddItem("Name");
38+
m_OrderByComboBox->AddItem("Date");
39+
m_OrderByComboBox->AddItem("Activity");
40+
m_OrderByComboBox->SetSelectedIndex(1); //order by Date by default
41+
3542
m_BackToMainButton = dynamic_cast<GUIButton *>(m_GUIControlManager->GetControl("ButtonBackToMainMenu"));
3643

3744
if (createForPauseMenu) {
@@ -107,7 +114,14 @@ namespace RTE {
107114

108115
void SaveLoadMenuGUI::UpdateSaveGamesGUIList()
109116
{
110-
std::sort(m_SaveGames.begin(), m_SaveGames.end());
117+
const std::string& currentOrder = m_OrderByComboBox->GetSelectedItem()->m_Name;
118+
if (currentOrder == "Name") {
119+
std::stable_sort(m_SaveGames.begin(), m_SaveGames.end(), [](const SaveRecord& lhs, const SaveRecord& rhs) { return lhs.SavePath.stem().string() < rhs.SavePath.stem().string(); });
120+
} else if (currentOrder == "Date") {
121+
std::stable_sort(m_SaveGames.begin(), m_SaveGames.end(), [](const SaveRecord& lhs, const SaveRecord& rhs) { return lhs.SaveDate > rhs.SaveDate; });
122+
} else if (currentOrder == "Activity") {
123+
std::stable_sort(m_SaveGames.begin(), m_SaveGames.end(), [](const SaveRecord& lhs, const SaveRecord& rhs) { return lhs.Activity < rhs.Activity; });
124+
}
111125

112126
m_SaveGamesListBox->ClearList();
113127
for (int i = 0; i < m_SaveGames.size(); i++) {
@@ -181,6 +195,10 @@ namespace RTE {
181195
//m_DescriptionLabel->SetText(record.GetDisplayString());
182196
m_SaveGameName->SetText(record.SavePath.stem().string());
183197
}
198+
199+
if (guiEvent.GetControl() == m_OrderByComboBox && guiEvent.GetMsg() == GUIComboBox::Closed) {
200+
UpdateSaveGamesGUIList();
201+
}
184202
}
185203
}
186204
return false;

Menus/SaveLoadMenuGUI.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace RTE {
1212
class GUIButton;
1313
class GUIListBox;
1414
class GUITextBox;
15+
class GUIComboBox;
1516

1617
/// <summary>
1718
/// Integrated savegame user interface composition and handling.
@@ -52,8 +53,6 @@ namespace RTE {
5253
std::filesystem::file_time_type SaveDate; //!< Last modified date.
5354
std::string Activity; //!< The activity name.
5455
std::string Scene; //!< The scene name.
55-
56-
bool operator<(const SaveRecord &rhs) const { return SaveDate > rhs.SaveDate; }
5756
};
5857

5958
std::unique_ptr<GUIControlManager> m_GUIControlManager; //!< The GUIControlManager which holds all the GUIControls of the SaveLoadMenuGUI.
@@ -70,7 +69,8 @@ namespace RTE {
7069
GUIButton *m_LoadButton;
7170
GUIButton *m_CreateButton;
7271
GUIListBox *m_SaveGamesListBox;
73-
GUILabel *m_DescriptionLabel;
72+
GUILabel* m_DescriptionLabel;
73+
GUIComboBox *m_OrderByComboBox;
7474

7575
#pragma region Mod and Script Handling
7676
/// <summary>

0 commit comments

Comments
 (0)