From 3a77f75bf6b69f40a3941941882ef08193764665 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 2 Feb 2019 02:09:40 +0000 Subject: [PATCH] Add GUI setting to control savegame overwrite confirmation dialog Adjust game ID indications in save window UI --- src/fios_gui.cpp | 22 +++++++++++++--------- src/lang/english.txt | 10 +++++++++- src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/table/gameopt_settings.ini | 1 + src/table/settings.ini | 13 +++++++++++++ 6 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 95bdafab0a..5ec87be1eb 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -478,11 +478,14 @@ public: y, r.bottom - WD_FRAMERECT_BOTTOM, _load_check_data.error, TC_RED); } else { /* Warning if save unique id differ when saving */ - if (this->fop == SLO_SAVE && - _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) { - y = DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, - y, r.bottom - WD_FRAMERECT_BOTTOM, STR_SAVELOAD_DIFFERENT_ID); + if (this->fop == SLO_SAVE) { + if (_load_check_data.settings.game_creation.generation_unique_id == 0) { + DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y_max, STR_SAVELOAD_UNKNOWN_ID); + y_max -= FONT_HEIGHT_NORMAL; + } else if (_load_check_data.settings.game_creation.generation_unique_id != _settings_game.game_creation.generation_unique_id) { + DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y_max, STR_SAVELOAD_DIFFERENT_ID); + y_max -= FONT_HEIGHT_NORMAL; + } } /* Mapsize */ @@ -754,19 +757,20 @@ public: } else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO) { 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) { + const bool known_id = _load_check_data.settings.game_creation.generation_unique_id != 0; + const bool different_id = known_id && _load_check_data.settings.game_creation.generation_unique_id != _settings_game.game_creation.generation_unique_id; + if (_settings_client.gui.savegame_overwrite_confirm >= 1 && different_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_SAVELOAD_OVERWRITE_TITLE_DIFFERENT_ID, STR_SAVELOAD_OVERWRITE_WARNING_DIFFERENT_ID, this, SaveLoadWindow::SaveGameConfirmationCallback); - } else if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) { + } else if (_settings_client.gui.savegame_overwrite_confirm >= (known_id ? 3 : 2) && FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) { ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING, this, SaveLoadWindow::SaveGameConfirmationCallback); } else { _switch_mode = SM_SAVE_GAME; } } else { FiosMakeHeightmapName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name)); - if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) { + if (_settings_client.gui.savegame_overwrite_confirm >= 1 && FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) { ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING, this, SaveLoadWindow::SaveHeightmapConfirmationCallback); } else { _switch_mode = SM_SAVE_HEIGHTMAP; diff --git a/src/lang/english.txt b/src/lang/english.txt index e473f8eea8..77d2816404 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1478,6 +1478,13 @@ STR_CONFIG_SETTING_DATE_FORMAT_IN_SAVE_NAMES_LONG :long (31st Dec STR_CONFIG_SETTING_DATE_FORMAT_IN_SAVE_NAMES_SHORT :short (31-12-2008) STR_CONFIG_SETTING_DATE_FORMAT_IN_SAVE_NAMES_ISO :ISO (2008-12-31) +STR_CONFIG_SETTING_SAVEGAME_OVERWRITE_CONFIRM :Warn before overwriting an existing savegame file: {STRING} +STR_CONFIG_SETTING_SAVEGAME_OVERWRITE_CONFIRM_HELPTEXT :If saving a savegame or heightmap would overwrite an existing save file, display a confirmation dialog. +STR_CONFIG_SETTING_SAVEGAME_OVERWRITE_CONFIRM_DISABLED :No +STR_CONFIG_SETTING_SAVEGAME_OVERWRITE_CONFIRM_DIFFERENT :Only if different +STR_CONFIG_SETTING_SAVEGAME_OVERWRITE_CONFIRM_DIFFERENT_UNKNOWN :Only if different or unknown +STR_CONFIG_SETTING_SAVEGAME_OVERWRITE_CONFIRM_ENABLED :Yes + STR_CONFIG_SETTING_PAUSE_ON_NEW_GAME :Automatically pause when starting a new game: {STRING2} STR_CONFIG_SETTING_PAUSE_ON_NEW_GAME_HELPTEXT :When enabled, the game will automatically pause when starting a new game, allowing for closer study of the map STR_CONFIG_SETTING_COMMAND_PAUSE_LEVEL :When paused allow: {STRING2} @@ -3300,7 +3307,8 @@ STR_SAVELOAD_DETAIL_GRFSTATUS :{SILVER}NewGRF: STR_SAVELOAD_FILTER_TITLE :{BLACK}Filter string: STR_SAVELOAD_OVERWRITE_TITLE :{WHITE}Overwrite File STR_SAVELOAD_OVERWRITE_WARNING :{YELLOW}Are you sure you want to overwrite the existing file? -STR_SAVELOAD_DIFFERENT_ID :{YELLOW}This file is from a different game.{} +STR_SAVELOAD_UNKNOWN_ID :{YELLOW}This file may be from a different game. +STR_SAVELOAD_DIFFERENT_ID :{YELLOW}This file is from a different game. STR_SAVELOAD_OVERWRITE_TITLE_DIFFERENT_ID :{WHITE}Overwrite File (Different Game) STR_SAVELOAD_OVERWRITE_WARNING_DIFFERENT_ID :{YELLOW}Are you sure you want to overwrite the existing file?{}{}The file is from a different game. diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 6e462b474d..5b6e88aa9d 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1605,6 +1605,7 @@ static SettingsContainer &GetSettingsTree() interface->Add(new SettingEntry("gui.autosave")); interface->Add(new SettingEntry("gui.autosave_on_network_disconnect")); + interface->Add(new SettingEntry("gui.savegame_overwrite_confirm")); interface->Add(new SettingEntry("gui.toolbar_pos")); interface->Add(new SettingEntry("gui.statusbar_pos")); interface->Add(new SettingEntry("gui.prefer_teamchat")); diff --git a/src/settings_type.h b/src/settings_type.h index bc0e656917..a62ed65c7c 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -117,6 +117,7 @@ struct GUISettings { bool autosave_on_network_disconnect; ///< save an autosave when you get disconnected from a network game with an error? uint8 date_format_in_default_names; ///< should the default savegame/screenshot name use long dates (31th Dec 2008), short dates (31-12-2008) or ISO dates (2008-12-31) byte max_num_autosaves; ///< controls how many autosavegames are made before the game starts to overwrite (names them 0 to max_num_autosaves - 1) + uint8 savegame_overwrite_confirm; ///< Mode for when to warn about overwriting an existing savegame bool population_in_label; ///< show the population of a town in his label? uint8 right_mouse_btn_emulation; ///< should we emulate right mouse clicking? uint8 scrollwheel_scrolling; ///< scrolling using the scroll wheel? diff --git a/src/table/gameopt_settings.ini b/src/table/gameopt_settings.ini index 798a6c9083..4a258bc359 100644 --- a/src/table/gameopt_settings.ini +++ b/src/table/gameopt_settings.ini @@ -21,6 +21,7 @@ static const char *_climates = "temperate|arctic|tropic|toyland"; static const char *_autosave_interval = "off|monthly|quarterly|half year|yearly"; static const char *_roadsides = "left|right"; static const char *_savegame_date = "long|short|iso"; +static const char *_savegame_overwrite_confirm = "no|different|not same|yes"; #ifdef ENABLE_NETWORK static const char *_server_langs = "ANY|ENGLISH|GERMAN|FRENCH|BRAZILIAN|BULGARIAN|CHINESE|CZECH|DANISH|DUTCH|ESPERANTO|FINNISH|HUNGARIAN|ICELANDIC|ITALIAN|JAPANESE|KOREAN|LITHUANIAN|NORWEGIAN|POLISH|PORTUGUESE|ROMANIAN|RUSSIAN|SLOVAK|SLOVENIAN|SPANISH|SWEDISH|TURKISH|UKRAINIAN|AFRIKAANS|CROATIAN|CATALAN|ESTONIAN|GALICIAN|GREEK|LATVIAN"; #endif /* ENABLE_NETWORK */ diff --git a/src/table/settings.ini b/src/table/settings.ini index d11c5698a1..ec0ccd3594 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -4023,6 +4023,19 @@ def = 16 min = 0 max = 255 +[SDTC_OMANY] +var = gui.savegame_overwrite_confirm +type = SLE_UINT8 +flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC +str = STR_CONFIG_SETTING_SAVEGAME_OVERWRITE_CONFIRM +strhelp = STR_CONFIG_SETTING_SAVEGAME_OVERWRITE_CONFIRM_HELPTEXT +strval = STR_CONFIG_SETTING_SAVEGAME_OVERWRITE_CONFIRM_DISABLED +guiflags = SGF_MULTISTRING +full = _savegame_overwrite_confirm +def = 3 +min = 0 +max = 3 + [SDTC_BOOL] var = gui.auto_euro flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC