mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-21 10:13:55 +00:00
Refactor savegame.cpp:
...Get rid of display references for the savegame class and move messages to gui2.
This commit is contained in:
parent
9dee31d3ed
commit
3e266d6741
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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){
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user