Savegame reorganization Step 1: a simpler interface to saving and loading.

Some more savegame.cpp refactoring.
This commit is contained in:
Jörg Hinrichs 2009-04-27 22:25:43 +00:00
parent e30131bd39
commit ffa6fde8bb
3 changed files with 21 additions and 13 deletions

View file

@ -154,6 +154,7 @@
[button]
id = "quit_game"
definition = "default"
return_value = "2"
label = _ "Quit Game"
[/button]

View file

@ -477,7 +477,6 @@ bool savegame::save_game_interactive(display& gui, const std::string& message,
int res = 0;
int overwrite = 0;
bool exit = true;
static bool ignore_all = false;
@ -512,17 +511,8 @@ bool savegame::save_game_interactive(display& gui, const std::string& message,
set_filename(filename);
}
std::string filename = filename_;
if (res == gui2::twindow::OK && 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;
overwrite = gui::dialog(gui,_("Overwrite?"),
s.str(), gui::YES_NO).show();
exit = (overwrite == 0);
} else {
exit = true;
}
if (res == gui2::twindow::OK)
exit = check_overwrite(gui);
}
catch (illegal_filename_exception){
exit = false;
@ -530,7 +520,7 @@ bool savegame::save_game_interactive(display& gui, const std::string& message,
}
while (!exit);
if (res == 2)
if (res == 2) //Quit game
throw end_level_exception(QUIT);
if (res != gui2::twindow::OK)
@ -763,6 +753,21 @@ void savegame::extract_summary_data_from_save(config& out)
}
}
bool savegame::check_overwrite(display& gui)
{
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;
} else {
return true;
}
}
void savegame::check_filename(const std::string& filename, display& gui)
{
if (is_gzip_file(filename)) {

View file

@ -174,6 +174,8 @@ private:
virtual void create_filename() {}
/** Check, if the filename contains illegal constructs like ".gz". */
void check_filename(const std::string& filename, display& gui);
/** Ask the user if an existing file should be overwritten. */
bool savegame::check_overwrite(display& gui);
/** The actual method for saving the game to disk. All interactive filename choosing and
data manipulation has to happen before calling this method. */