Skip to content

Commit 79e0a79

Browse files
committed
Cleanup and consistency with listbox selection. Show "Overwrite" when overwriting vs creating a save.
1 parent dd02bc4 commit 79e0a79

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

Menus/SaveLoadMenuGUI.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ namespace RTE {
6060
m_SaveGameName = dynamic_cast<GUITextBox *>(m_GUIControlManager->GetControl("SaveGameName"));
6161
m_LoadButton = dynamic_cast<GUIButton *>(m_GUIControlManager->GetControl("ButtonLoad"));
6262
m_CreateButton = dynamic_cast<GUIButton *>(m_GUIControlManager->GetControl("ButtonCreate"));
63+
m_OverwriteButton = dynamic_cast<GUIButton *>(m_GUIControlManager->GetControl("ButtonOverwrite"));
6364
m_DeleteButton = dynamic_cast<GUIButton *>(m_GUIControlManager->GetControl("ButtonDelete"));
6465
m_ActivityCannotBeSavedLabel = dynamic_cast<GUILabel *>(m_GUIControlManager->GetControl("ActivityCannotBeSavedWarning"));
6566

@@ -210,13 +211,31 @@ namespace RTE {
210211

211212
void SaveLoadMenuGUI::UpdateButtonEnabledStates() {
212213
bool allowSave = g_ActivityMan.GetActivityAllowsSaving() && m_SaveGameName->GetText() != "";
213-
bool allowLoad = m_SaveGamesListBox->GetSelectedIndex() > -1 && m_SaveGameName->GetText() != "" && m_SaveGameName->GetText() == m_SaveGames[m_SaveGamesListBox->GetSelected()->m_ExtraIndex].SavePath.stem().string();
214-
bool allowDelete = allowLoad;
215214

216-
m_CreateButton->SetVisible(allowSave);
217-
m_CreateButton->SetEnabled(allowSave);
218-
m_LoadButton->SetEnabled(allowLoad);
219-
m_DeleteButton->SetEnabled(allowDelete);
215+
int existingSaveItemIndex = -1;
216+
for (int i = 0; i < m_SaveGamesListBox->GetItemList()->size(); ++i) {
217+
SaveRecord& save = m_SaveGames[m_SaveGamesListBox->GetItem(i)->m_ExtraIndex];
218+
if (save.SavePath.stem().string() == m_SaveGameName->GetText()) {
219+
existingSaveItemIndex = i;
220+
break;
221+
}
222+
}
223+
224+
// Select the item in the list - selecting -1 unselects all
225+
m_SaveGamesListBox->SetSelectedIndex(existingSaveItemIndex);
226+
227+
bool saveExists = existingSaveItemIndex != -1;
228+
229+
bool allowCreate = allowSave && !saveExists;
230+
m_CreateButton->SetVisible(allowCreate);
231+
m_CreateButton->SetEnabled(allowCreate);
232+
233+
bool allowOverwrite = allowSave && saveExists;
234+
m_OverwriteButton->SetVisible(allowOverwrite);
235+
m_OverwriteButton->SetEnabled(allowOverwrite);
236+
237+
m_LoadButton->SetEnabled(saveExists);
238+
m_DeleteButton->SetEnabled(saveExists);
220239

221240
m_ActivityCannotBeSavedLabel->SetVisible(g_ActivityMan.GetActivity() && !g_ActivityMan.GetActivityAllowsSaving());
222241
}
@@ -244,7 +263,7 @@ namespace RTE {
244263
}
245264
return true;
246265
}
247-
} else if (guiEvent.GetControl() == m_CreateButton) {
266+
} else if (guiEvent.GetControl() == m_CreateButton || guiEvent.GetControl() == m_OverwriteButton) {
248267
CreateSave();
249268
} else if (guiEvent.GetControl() == m_DeleteButton) {
250269
DeleteSave();

Menus/SaveLoadMenuGUI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ namespace RTE {
7171
GUITextBox *m_SaveGameName;
7272
GUIButton *m_LoadButton;
7373
GUIButton *m_CreateButton;
74+
GUIButton *m_OverwriteButton;
7475
GUIButton *m_DeleteButton;
7576
GUIListBox *m_SaveGamesListBox;
7677
GUILabel *m_ActivityCannotBeSavedLabel;

0 commit comments

Comments
 (0)