diff --git a/data/gui/default/window/game_save_overwrite.cfg b/data/gui/default/window/game_save_overwrite.cfg new file mode 100644 index 00000000000..bf4d8137f2b --- /dev/null +++ b/data/gui/default/window/game_save_overwrite.cfg @@ -0,0 +1,120 @@ +#textdomain wesnoth-lib +### +### Definition of the window to ask for the savegame filename +### + +[window] + id = "game_save_overwrite" + description = "Ask if an existing savefile should be overwritten." + + [resolution] + definition = "default" + + automatic_placement = "true" + vertical_placement = "center" + horizontal_placement = "center" + + [grid] + + [row] + grow_factor = 0 + + [column] + grow_factor = 1 + + border = "all" + border_size = 5 + horizontal_alignment = "left" + [label] + id = "lblTitle" + definition = "title" + + label = _ "Overwrite?" + [/label] + + [/column] + + [/row] + + [row] + grow_factor = 0 + + [column] + grow_factor = 1 + + border = "all" + border_size = 5 + horizontal_alignment = "left" + [label] + id = "lblMessage" + definition = "default" + + label = _ "Save already exists. Do you want to overwrite it?" + [/label] + + [/column] + + [/row] + + [row] + grow_factor = 0 + + [column] + grow_factor = 1 + horizontal_grow = "true" + + [grid] + + [row] + grow_factor = 0 + + [column] + + [spacer] + definition = "default" + [/spacer] + + [/column] + + [column] + border = "all" + border_size = 5 + horizontal_alignment = "right" + + [button] + id = "ok" + definition = "default" + + size_text = _ "Yes" + label = _ "Yes" + [/button] + + [/column] + + [column] + border = "all" + border_size = 5 + horizontal_alignment = "right" + + [button] + id = "cancel" + definition = "default" + + label = _ "No" + [/button] + + [/column] + + [/row] + + [/grid] + + [/column] + + [/row] + + [/grid] + + [/resolution] + +[/window] diff --git a/src/gui/dialogs/game_save.cpp b/src/gui/dialogs/game_save.cpp index e7cdd336bf0..7d908eea103 100644 --- a/src/gui/dialogs/game_save.cpp +++ b/src/gui/dialogs/game_save.cpp @@ -17,6 +17,7 @@ #include "gui/dialogs/game_save.hpp" #include "foreach.hpp" +#include "gettext.hpp" #include "gui/dialogs/field.hpp" #include "gui/widgets/button.hpp" #include "gui/widgets/label.hpp" @@ -101,5 +102,21 @@ void tgame_save_oos::post_show(twindow& window) ignore_all_ = btnIgnoreAll_->get_widget_value(window); } +tgame_save_overwrite::tgame_save_overwrite(const std::string& filename) + : filename_(filename) +{} + +twindow* tgame_save_overwrite::build_window(CVideo& video) +{ + return build(video, get_id(GAME_SAVE_OVERWRITE)); +} + +void tgame_save_overwrite::pre_show(CVideo& video, twindow& window) +{ + tlabel* lblMessage = dynamic_cast(window.find_widget("lblMessage", false)); + VALIDATE(lblMessage, missing_widget("lblMessage")); + lblMessage->set_label(lblMessage->label() + "\n" + _("Name: ") + filename_); +} + } // namespace gui2 diff --git a/src/gui/dialogs/game_save.hpp b/src/gui/dialogs/game_save.hpp index 8b61362a309..d4b73a4276e 100644 --- a/src/gui/dialogs/game_save.hpp +++ b/src/gui/dialogs/game_save.hpp @@ -76,6 +76,22 @@ private: bool ignore_all_; }; +class tgame_save_overwrite : public tdialog +{ +public: + tgame_save_overwrite(const std::string& filename); + +private: + /** Inherited from tdialog. */ + twindow* build_window(CVideo& video); + + /** Inherited from tgame_save. */ + void pre_show(CVideo& video, twindow& window); + + + std::string filename_; +}; + } #endif diff --git a/src/gui/widgets/settings.cpp b/src/gui/widgets/settings.cpp index d7f14411e08..27d90394c0a 100644 --- a/src/gui/widgets/settings.cpp +++ b/src/gui/widgets/settings.cpp @@ -90,6 +90,7 @@ static void fill_window_types() window_type_list[GAME_SAVE] = "game_save"; window_type_list[GAME_SAVE_MESSAGE] = "game_save_message"; window_type_list[GAME_SAVE_OOS] = "game_save_oos"; + window_type_list[GAME_SAVE_OVERWRITE] = "game_save_overwrite"; #ifndef DISABLE_EDITOR2 window_type_list[EDITOR_NEW_MAP] = "editor_new_map"; window_type_list[EDITOR_GENERATE_MAP] = "editor_generate_map"; diff --git a/src/gui/widgets/settings.hpp b/src/gui/widgets/settings.hpp index 0f3223bae51..310fdbce650 100644 --- a/src/gui/widgets/settings.hpp +++ b/src/gui/widgets/settings.hpp @@ -68,6 +68,7 @@ enum twindow_type { GAME_SAVE, /**< Save game dialog. */ GAME_SAVE_MESSAGE, /**< Save game dialog with additional message. */ GAME_SAVE_OOS, /**< Save game dialog for processing OOS. */ + GAME_SAVE_OVERWRITE, /**< Ask for overwriting an existing savegame. */ COUNT /**< * The last one to hold the number of items and as * sentinel. diff --git a/src/savegame.cpp b/src/savegame.cpp index 1b613c8d25f..5d50dc9f841 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -39,6 +39,16 @@ static lg::log_domain log_engine("engine"); #define ERR_SAVE LOG_STREAM(err, log_engine) #ifdef _WIN32 + #ifdef INADDR_ANY + #undef INADDR_ANY + #endif + #ifdef INADDR_BROADCAST + #undef INADDR_BROADCAST + #endif + #ifdef INADDR_NONE + #undef INADDR_NONE + #endif + #include /** @@ -481,11 +491,13 @@ bool savegame::save_game_interactive(display& gui, const std::string& message, do{ try{ - if (ask_for_filename) + if (ask_for_filename){ res = show_save_dialog(gui.video(), has_exit_button, message, dialog_type); + exit = true; + } if (res == gui2::twindow::OK) - exit = check_overwrite(gui); + exit = check_overwrite(gui.video()); } catch (illegal_filename_exception){ exit = false; @@ -537,16 +549,13 @@ int savegame::show_save_dialog(CVideo& video, bool is_oos, const std::string& me return res; } -bool savegame::check_overwrite(display& gui) +bool savegame::check_overwrite(CVideo& video) { std::string filename = filename_; if (savegame_manager::save_game_exists(filename, compress_saves_)) { - std::stringstream s; - s << _("Save already exists. Do you want to overwrite it?") - << std::endl << _("Name: ") << filename; - int overwrite = gui::dialog(gui,_("Overwrite?"), - s.str(), gui::YES_NO).show(); - return overwrite == 0; + gui2::tgame_save_overwrite dlg(filename); + dlg.show(video); + return dlg.get_retval() == gui2::twindow::OK; } else { return true; } @@ -557,9 +566,6 @@ void savegame::check_filename(const std::string& filename, CVideo& video) if (is_gzip_file(filename)) { gui2::show_message(video, _("Error"), _("Save names should not end on '.gz'. " "Please choose a different name.")); - //gui::message_dialog(gui, _("Error"), - // _("Save names should not end on '.gz'. " - // "Please choose a different name.")).show(); throw illegal_filename_exception(); } } diff --git a/src/savegame.hpp b/src/savegame.hpp index a53ac57755c..55c131b6c85 100644 --- a/src/savegame.hpp +++ b/src/savegame.hpp @@ -177,7 +177,7 @@ private: /** Display the save game dialog. */ int show_save_dialog(CVideo& video, bool is_oos, const std::string& message, const gui::DIALOG_TYPE dialog_type); /** Ask the user if an existing file should be overwritten. */ - bool check_overwrite(display& gui); + bool check_overwrite(CVideo& video); /** The actual method for saving the game to disk. All interactive filename choosing and data manipulation has to happen before calling this method. */