Skip to content

Commit

Permalink
Add: Message popup when trying to overwrite a different savegame
Browse files Browse the repository at this point in the history
  • Loading branch information
damfr committed Nov 20, 2018
1 parent 0c48810 commit bdd47ed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/fios_gui.cpp
Expand Up @@ -225,6 +225,8 @@ static void SortSaveGameList(FileList &file_list)
QSortT(file_list.Get(sort_start), s_amount, CompareFiosItems);
}

void SaveGameConfirmationCallback(Window *w, bool confirmed);

struct SaveLoadWindow : public Window {
private:
QueryString filename_editbox; ///< Filename editbox.
Expand All @@ -234,6 +236,8 @@ struct SaveLoadWindow : public Window {
FiosItem o_dir;
const FiosItem *selected; ///< Selected game in #fios_items, or \c NULL.
Scrollbar *vscroll;

friend void SaveGameConfirmationCallback(Window *w, bool confirmed);
public:

/** Generate a default save filename. */
Expand Down Expand Up @@ -674,8 +678,15 @@ struct SaveLoadWindow : public Window {
}
} else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked
if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO) {
_switch_mode = SM_SAVE_GAME;
FiosMakeSavegameName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name));
if (_load_check_data.settings.game_creation.generation_unique_id != 0 && /* Don't warn if the save has no id (old save) */
_load_check_data.settings.game_creation.generation_unique_id != _settings_game.game_creation.generation_unique_id) {
/* The save has a different id to the current game */
/* Show a caption box asking whether the user is sure to overwrite the save */
ShowQuery(STR_SAVEGAME_UNMATCHING_ID_CAPTION, STR_SAVEGAME_UNMATCHING_ID_CONFIRMATION_TEXT, this, SaveGameConfirmationCallback);
} else {
/* We can safely overwrite the save */
SaveGameConfirmationCallback(this, true);
}
} else {
_switch_mode = SM_SAVE_HEIGHTMAP;
FiosMakeHeightmapName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name));
Expand Down Expand Up @@ -768,6 +779,19 @@ static WindowDesc _save_dialog_desc(
_nested_save_dialog_widgets, lengthof(_nested_save_dialog_widgets)
);

/**
* Callback function for the savegame 'are you sure you want to overwrite save' window
* @param w Window which is calling this callback
* @param confirmed boolean value, true when yes was clicked, false otherwise
*/
void SaveGameConfirmationCallback(Window *w, bool confirmed)
{
if (confirmed) {
_switch_mode = SM_SAVE_GAME;
FiosMakeSavegameName(_file_to_saveload.name, dynamic_cast<SaveLoadWindow*>(w)->filename_editbox.text.buf, lastof(_file_to_saveload.name));
}
}

/**
* Launch save/load dialog in the given mode.
* @param abstract_filetype Kind of file to handle.
Expand Down
2 changes: 2 additions & 0 deletions src/lang/english.txt
Expand Up @@ -4149,6 +4149,8 @@ STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE :File not writea
STR_GAME_SAVELOAD_ERROR_DATA_INTEGRITY_CHECK_FAILED :Data integrity check failed
STR_GAME_SAVELOAD_NOT_AVAILABLE :<not available>
STR_WARNING_LOADGAME_REMOVED_TRAMS :{WHITE}Game was saved in version without tram support. All trams have been removed
STR_SAVEGAME_UNMATCHING_ID_CAPTION :{WHITE}Caution!
STR_SAVEGAME_UNMATCHING_ID_CONFIRMATION_TEXT :{YELLOW}The savegame you are about to overwrite is not the same as the current one.{}Are you sure you want to do this?

# Map generation messages
STR_ERROR_COULD_NOT_CREATE_TOWN :{WHITE}Map generation aborted...{}... no suitable town locations
Expand Down

0 comments on commit bdd47ed

Please sign in to comment.