Add: Message popup when trying to overwrite a different savegame

pull/78/head
damfr 6 years ago
parent 1b3ce25c07
commit 5d8b9de482

@ -265,6 +265,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:
static const uint EDITBOX_MAX_SIZE = 50;
@ -281,6 +283,8 @@ private:
QueryString filter_editbox; ///< Filter editbox;
SmallVector<bool, 32> fios_items_shown; ///< Map of the filtered out fios items
friend void SaveGameConfirmationCallback(Window *w, bool confirmed);
public:
/** Generate a default save filename. */
@ -739,8 +743,15 @@ public:
}
} 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));
@ -872,6 +883,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.

@ -4150,6 +4150,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

Loading…
Cancel
Save