From 3e266d6741c7339fa5f54b71c853404c641ada1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hinrichs?= Date: Tue, 28 Apr 2009 20:32:50 +0000 Subject: [PATCH] Refactor savegame.cpp: ...Get rid of display references for the savegame class and move messages to gui2. --- src/play_controller.cpp | 4 ++-- src/playcampaign.cpp | 2 +- src/playmp_controller.cpp | 2 +- src/playsingle_controller.cpp | 2 +- src/savegame.cpp | 21 ++++++++++----------- src/savegame.hpp | 4 ++-- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/play_controller.cpp b/src/play_controller.cpp index 93ecb2e7a81..b2c1a5f07d3 100644 --- a/src/play_controller.cpp +++ b/src/play_controller.cpp @@ -294,7 +294,7 @@ void play_controller::save_game(){ if(save_blocker::try_block()) { save_blocker::save_unblocker unblocker; game_savegame save(gamestate_, level_, *gui_, teams_, units_, status_, map_, preferences::compress_saves()); - save.save_game_interactive(*gui_, "", gui::OK_CANCEL); + save.save_game_interactive((*gui_).video(), "", gui::OK_CANCEL); } else { save_blocker::on_unblock(this,&play_controller::save_game); } @@ -304,7 +304,7 @@ void play_controller::save_replay(){ if(save_blocker::try_block()) { save_blocker::save_unblocker unblocker; replay_savegame save(gamestate_, preferences::compress_saves()); - save.save_game_interactive(*gui_, "", gui::OK_CANCEL); + save.save_game_interactive((*gui_).video(), "", gui::OK_CANCEL); } else { save_blocker::on_unblock(this,&play_controller::save_replay); } diff --git a/src/playcampaign.cpp b/src/playcampaign.cpp index 6243cdbcbc1..97bbad0f15c 100644 --- a/src/playcampaign.cpp +++ b/src/playcampaign.cpp @@ -395,7 +395,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_ if (preferences::save_replays()) { replay_savegame save(gamestate, preferences::compress_saves()); - save.save_game_interactive(disp, "", gui::OK_CANCEL, false, false); + save.save_game_interactive(disp.video(), "", gui::OK_CANCEL, false, false); } } diff --git a/src/playmp_controller.cpp b/src/playmp_controller.cpp index c7add05b858..78d846608a1 100644 --- a/src/playmp_controller.cpp +++ b/src/playmp_controller.cpp @@ -539,7 +539,7 @@ void playmp_controller::process_oos(const std::string& err_msg){ } game_savegame save(gamestate_, level_, *gui_, teams_, units_, status_, map_, preferences::compress_saves()); - save.save_game_interactive(*gui_, temp_buf.str(), gui::YES_NO, true); + save.save_game_interactive((*gui_).video(), temp_buf.str(), gui::YES_NO, true); } void playmp_controller::handle_generic_event(const std::string& name){ diff --git a/src/playsingle_controller.cpp b/src/playsingle_controller.cpp index 2a6543ab184..0f8f65d20b1 100644 --- a/src/playsingle_controller.cpp +++ b/src/playsingle_controller.cpp @@ -507,7 +507,7 @@ LEVEL_RESULT playsingle_controller::play_scenario( } game_savegame save(gamestate_, level_, *gui_, teams_, units_, status_, map_, preferences::compress_saves()); - save.save_game_interactive(*gui_, _("A network disconnection has occurred, and the game\ncannot continue. Do you want to save the game?"), gui::YES_NO); + save.save_game_interactive((*gui_).video(), _("A network disconnection has occurred, and the game\ncannot continue. Do you want to save the game?"), gui::YES_NO); if(disconnect) { throw network::error(); } else { diff --git a/src/savegame.cpp b/src/savegame.cpp index 5d50dc9f841..a1eb738e16c 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -479,7 +479,7 @@ savegame::savegame(game_state& gamestate, const bool compress_saves, const std:: , compress_saves_(compress_saves) {} -bool savegame::save_game_interactive(display& gui, const std::string& message, +bool savegame::save_game_interactive(CVideo& video, const std::string& message, gui::DIALOG_TYPE dialog_type, const bool has_exit_button, const bool ask_for_filename) { @@ -492,12 +492,12 @@ bool savegame::save_game_interactive(display& gui, const std::string& message, do{ try{ if (ask_for_filename){ - res = show_save_dialog(gui.video(), has_exit_button, message, dialog_type); + res = show_save_dialog(video, has_exit_button, message, dialog_type); exit = true; } if (res == gui2::twindow::OK) - exit = check_overwrite(gui.video()); + exit = check_overwrite(video); } catch (illegal_filename_exception){ exit = false; @@ -511,7 +511,7 @@ bool savegame::save_game_interactive(display& gui, const std::string& message, if (res != gui2::twindow::OK) return false; - return save_game(&gui); + return save_game(&video); } int savegame::show_save_dialog(CVideo& video, bool is_oos, const std::string& message, const gui::DIALOG_TYPE dialog_type) @@ -588,7 +588,7 @@ bool savegame::save_game(const std::string& filename) return save_game(); } -bool savegame::save_game(display* gui) +bool savegame::save_game(CVideo* video) { try { Uint32 start, end; @@ -600,14 +600,13 @@ bool savegame::save_game(display* gui) end = SDL_GetTicks(); LOG_SAVE << "Milliseconds to save " << filename_ << ": " << end - start << "\n"; - if (gui != NULL && show_confirmation_) - gui::message_dialog(*gui,_("Saved"),_("The game has been saved")).show(); + if (video != NULL && show_confirmation_) + gui2::show_message(*video, _("Saved"), _("The game has been saved")); return true; } catch(game::save_game_failed&) { - if (gui != NULL){ - gui::message_dialog to_show(*gui,_("Error"), error_message_); - to_show.show(); + if (video != NULL){ + gui2::show_message(*video,_("Error"), error_message_); //do not bother retrying, since the user can just try to save the game again //maybe show a yes-no dialog for "disable autosaves now"? } @@ -844,7 +843,7 @@ void autosave_savegame::autosave(const bool disable_autosave, const int autosave if(disable_autosave) return; - save_game(&gui_); + save_game(&gui_.video()); savegame_manager::remove_old_auto_saves(autosave_max, infinite_autosaves); } diff --git a/src/savegame.hpp b/src/savegame.hpp index 55c131b6c85..e9a88edad49 100644 --- a/src/savegame.hpp +++ b/src/savegame.hpp @@ -144,11 +144,11 @@ public: to appear, you have to provide the gui parameter. The return value denotes, if the save was successful or not. */ - bool save_game(display* gui = NULL); + bool save_game(CVideo* video = NULL); /** Save a game interactively through the savegame dialog. Used for manual midgame and replay saves. The return value denotes, if the save was successful or not. */ - bool save_game_interactive(display& gui, const std::string& message, + bool save_game_interactive(CVideo& gui, const std::string& message, gui::DIALOG_TYPE dialog_type, const bool has_exit_button = false, const bool ask_for_filename = true);