summaryrefslogtreecommitdiff
path: root/src/fios_gui.cpp
diff options
context:
space:
mode:
authorNiels Martin Hansen <nielsm@indvikleren.dk>2019-02-01 20:17:28 +0100
committerPeterN <peter@fuzzle.org>2019-02-01 21:49:36 +0000
commit0bca36340147c3d2411ad473624b28df3b670fbe (patch)
treeb471952c9454e151ccd88b892f71e0ba5d7684e9 /src/fios_gui.cpp
parent5a5861f245a25ea4e2b3ad56640d1d8728324383 (diff)
downloadopenttd-0bca36340147c3d2411ad473624b28df3b670fbe.tar.xz
Add: Warn before overwriting an existing save file
Diffstat (limited to 'src/fios_gui.cpp')
-rw-r--r--src/fios_gui.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp
index e149d07b4..63bb589d7 100644
--- a/src/fios_gui.cpp
+++ b/src/fios_gui.cpp
@@ -281,6 +281,18 @@ private:
QueryString filter_editbox; ///< Filter editbox;
SmallVector<bool, 32> fios_items_shown; ///< Map of the filtered out fios items
+ static void SaveGameConfirmationCallback(Window *w, bool confirmed)
+ {
+ /* File name has already been written to _file_to_saveload */
+ if (confirmed) _switch_mode = SM_SAVE_GAME;
+ }
+
+ static void SaveHeightmapConfirmationCallback(Window *w, bool confirmed)
+ {
+ /* File name has already been written to _file_to_saveload */
+ if (confirmed) _switch_mode = SM_SAVE_HEIGHTMAP;
+ }
+
public:
/** Generate a default save filename. */
@@ -731,11 +743,19 @@ 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 (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 {
- _switch_mode = SM_SAVE_HEIGHTMAP;
FiosMakeHeightmapName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name));
+ if (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;
+ }
}
/* In the editor set up the vehicle engines correctly (date might have changed) */