Skip to content

Commit 1f10ab7

Browse files
committed
Added confirmation dialog for overwrite/delete
1 parent 79e0a79 commit 1f10ab7

File tree

2 files changed

+70
-6
lines changed

2 files changed

+70
-6
lines changed

Menus/SaveLoadMenuGUI.cpp

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ namespace RTE {
3333
GUICollectionBox *rootBox = dynamic_cast<GUICollectionBox *>(m_GUIControlManager->GetControl("root"));
3434
rootBox->Resize(rootBoxMaxWidth, g_WindowMan.GetResY());
3535

36-
GUICollectionBox *saveGameMenuBox = dynamic_cast<GUICollectionBox *>(m_GUIControlManager->GetControl("CollectionBoxSaveGameMenu"));
37-
saveGameMenuBox->CenterInParent(true, true);
38-
saveGameMenuBox->SetPositionAbs(saveGameMenuBox->GetXPos(), (rootBox->GetHeight() < 540) ? saveGameMenuBox->GetYPos() - 15 : 140);
36+
m_SaveGameMenuBox = dynamic_cast<GUICollectionBox *>(m_GUIControlManager->GetControl("CollectionBoxSaveGameMenu"));
37+
m_SaveGameMenuBox->CenterInParent(true, true);
38+
m_SaveGameMenuBox->SetPositionAbs(m_SaveGameMenuBox->GetXPos(), (rootBox->GetHeight() < 540) ? m_SaveGameMenuBox->GetYPos() - 15 : 140);
3939

4040
m_OrderByComboBox = dynamic_cast<GUIComboBox*>(m_GUIControlManager->GetControl("ComboOrderBy"));
4141
m_OrderByComboBox->AddItem("Name");
@@ -49,7 +49,7 @@ namespace RTE {
4949
m_BackToMainButton->SetSize(120, 20);
5050
m_BackToMainButton->SetText("Back to Pause Menu");
5151
}
52-
m_BackToMainButton->SetPositionAbs((rootBox->GetWidth() - m_BackToMainButton->GetWidth()) / 2, saveGameMenuBox->GetYPos() + saveGameMenuBox->GetHeight() + 10);
52+
m_BackToMainButton->SetPositionAbs((rootBox->GetWidth() - m_BackToMainButton->GetWidth()) / 2, m_SaveGameMenuBox->GetYPos() + m_SaveGameMenuBox->GetHeight() + 10);
5353

5454
m_SaveGamesListBox = dynamic_cast<GUIListBox *>(m_GUIControlManager->GetControl("ListBoxSaveGames"));
5555
m_SaveGamesListBox->SetFont(m_GUIControlManager->GetSkin()->GetFont("FontConsoleMonospace.png"));
@@ -64,6 +64,15 @@ namespace RTE {
6464
m_DeleteButton = dynamic_cast<GUIButton *>(m_GUIControlManager->GetControl("ButtonDelete"));
6565
m_ActivityCannotBeSavedLabel = dynamic_cast<GUILabel *>(m_GUIControlManager->GetControl("ActivityCannotBeSavedWarning"));
6666

67+
m_ConfirmationBox = dynamic_cast<GUICollectionBox *>(m_GUIControlManager->GetControl("ConfirmDialog"));
68+
m_ConfirmationBox->CenterInParent(true, true);
69+
70+
m_ConfirmationLabel = dynamic_cast<GUILabel *>(m_GUIControlManager->GetControl("ConfirmLabel"));
71+
m_ConfirmationButton = dynamic_cast<GUIButton *>(m_GUIControlManager->GetControl("ConfirmButton"));
72+
m_CancelButton = dynamic_cast<GUIButton *>(m_GUIControlManager->GetControl("CancelButton"));
73+
74+
SwitchToConfirmDialogMode(ConfirmDialogMode::None);
75+
6776
m_SaveGamesFetched = false;
6877
}
6978

@@ -240,6 +249,27 @@ namespace RTE {
240249
m_ActivityCannotBeSavedLabel->SetVisible(g_ActivityMan.GetActivity() && !g_ActivityMan.GetActivityAllowsSaving());
241250
}
242251

252+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
253+
254+
void SaveLoadMenuGUI::SwitchToConfirmDialogMode(ConfirmDialogMode mode)
255+
{
256+
m_ConfirmDialogMode = mode;
257+
258+
bool dialogOpen = m_ConfirmDialogMode != ConfirmDialogMode::None;
259+
m_SaveGameMenuBox->SetEnabled(!dialogOpen);
260+
m_ConfirmationBox->SetEnabled(dialogOpen);
261+
m_ConfirmationBox->SetVisible(dialogOpen);
262+
263+
switch (m_ConfirmDialogMode) {
264+
case ConfirmDialogMode::ConfirmOverwrite:
265+
m_ConfirmationLabel->SetText("Are you sure you want to overwrite this savegame?");
266+
break;
267+
case ConfirmDialogMode::ConfirmDelete:
268+
m_ConfirmationLabel->SetText("Are you sure you want to delete this savegame?");
269+
break;
270+
}
271+
}
272+
243273
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
244274

245275
bool SaveLoadMenuGUI::HandleInputEvents(PauseMenuGUI *pauseMenu) {
@@ -263,10 +293,24 @@ namespace RTE {
263293
}
264294
return true;
265295
}
266-
} else if (guiEvent.GetControl() == m_CreateButton || guiEvent.GetControl() == m_OverwriteButton) {
296+
} else if (guiEvent.GetControl() == m_CreateButton) {
267297
CreateSave();
298+
} else if (guiEvent.GetControl() == m_OverwriteButton) {
299+
SwitchToConfirmDialogMode(ConfirmDialogMode::ConfirmOverwrite);
268300
} else if (guiEvent.GetControl() == m_DeleteButton) {
269-
DeleteSave();
301+
SwitchToConfirmDialogMode(ConfirmDialogMode::ConfirmDelete);
302+
} else if (guiEvent.GetControl() == m_ConfirmationButton) {
303+
switch (m_ConfirmDialogMode) {
304+
case ConfirmDialogMode::ConfirmOverwrite:
305+
CreateSave();
306+
break;
307+
case ConfirmDialogMode::ConfirmDelete:
308+
DeleteSave();
309+
break;
310+
}
311+
SwitchToConfirmDialogMode(ConfirmDialogMode::None);
312+
} else if (guiEvent.GetControl() == m_CancelButton) {
313+
SwitchToConfirmDialogMode(ConfirmDialogMode::None);
270314
}
271315
} else if (guiEvent.GetType() == GUIEvent::Notification) {
272316
if (guiEvent.GetMsg() == GUIButton::Focused && dynamic_cast<GUIButton *>(guiEvent.GetControl())) {

Menus/SaveLoadMenuGUI.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace RTE {
1515
class GUIListBox;
1616
class GUITextBox;
1717
class GUIComboBox;
18+
class GUICollectionBox;
1819

1920
/// <summary>
2021
/// Integrated savegame user interface composition and handling.
@@ -48,6 +49,12 @@ namespace RTE {
4849
#pragma endregion
4950

5051
private:
52+
enum class ConfirmDialogMode {
53+
None,
54+
ConfirmOverwrite,
55+
ConfirmDelete
56+
};
57+
5158
/// <summary>
5259
/// Struct containing information about a valid Savegame.
5360
/// </summary>
@@ -67,6 +74,7 @@ namespace RTE {
6774
/// <summary>
6875
/// GUI elements that compose the Mod Manager menu screen.
6976
/// </summary>
77+
GUICollectionBox *m_SaveGameMenuBox;
7078
GUIButton *m_BackToMainButton;
7179
GUITextBox *m_SaveGameName;
7280
GUIButton *m_LoadButton;
@@ -77,6 +85,13 @@ namespace RTE {
7785
GUILabel *m_ActivityCannotBeSavedLabel;
7886
GUIComboBox *m_OrderByComboBox;
7987

88+
// The confirmation box and its controls
89+
ConfirmDialogMode m_ConfirmDialogMode;
90+
GUICollectionBox *m_ConfirmationBox;
91+
GUILabel *m_ConfirmationLabel;
92+
GUIButton* m_ConfirmationButton;
93+
GUIButton *m_CancelButton;
94+
8095
#pragma region Savegame Handling
8196
/// <summary>
8297
/// Gets whether both lists were fetched, even if nothing valid was added to them.
@@ -116,6 +131,11 @@ namespace RTE {
116131
/// </summary>
117132
void UpdateButtonEnabledStates();
118133

134+
/// <summary>
135+
/// Shows confirmation box for overwrite or delete.
136+
/// </summary>
137+
void SwitchToConfirmDialogMode(ConfirmDialogMode mode);
138+
119139
// Disallow the use of some implicit methods.
120140
SaveLoadMenuGUI(const SaveLoadMenuGUI &reference) = delete;
121141
SaveLoadMenuGUI & operator=(const SaveLoadMenuGUI &rhs) = delete;

0 commit comments

Comments
 (0)