Savegame reorganization Step 1: a simpler interface to saving and loading.
Transfer save-game dialog to gui2 and use it within savegame.cpp.
This commit is contained in:
parent
ccf75ada55
commit
dce2a6c01e
14 changed files with 574 additions and 68 deletions
151
data/gui/default/window/game_save.cfg
Normal file
151
data/gui/default/window/game_save.cfg
Normal file
|
@ -0,0 +1,151 @@
|
|||
#textdomain wesnoth-lib
|
||||
###
|
||||
### Definition of the window to ask for the savegame filename
|
||||
###
|
||||
|
||||
[window]
|
||||
id = "game_save"
|
||||
description = "Save game dialog."
|
||||
|
||||
[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 = _ "Save Game"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
horizontal_grow = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
grow_factor = 0
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[label]
|
||||
definition = "default"
|
||||
|
||||
label = _ "Name:"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_grow = "true"
|
||||
|
||||
[text_box]
|
||||
id = "txtFilename"
|
||||
definition = "default"
|
||||
label = ""
|
||||
[/text_box]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/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 = _ "OK"
|
||||
label = _ "OK"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[button]
|
||||
id = "cancel"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Cancel"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/resolution]
|
||||
|
||||
[/window]
|
171
data/gui/default/window/game_save_message.cfg
Normal file
171
data/gui/default/window/game_save_message.cfg
Normal file
|
@ -0,0 +1,171 @@
|
|||
#textdomain wesnoth-lib
|
||||
###
|
||||
### Definition of the window to ask for the savegame filename
|
||||
###
|
||||
|
||||
[window]
|
||||
id = "game_save_message"
|
||||
description = "Save game dialog with additional message."
|
||||
|
||||
[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 = _ "Save Game"
|
||||
[/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 = _ "x"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
horizontal_grow = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
grow_factor = 0
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[label]
|
||||
definition = "default"
|
||||
|
||||
label = _ "Name:"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_grow = "true"
|
||||
|
||||
[text_box]
|
||||
id = "txtFilename"
|
||||
definition = "default"
|
||||
label = ""
|
||||
[/text_box]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/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 = _ "OK"
|
||||
label = _ "OK"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[button]
|
||||
id = "cancel"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Cancel"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/resolution]
|
||||
|
||||
[/window]
|
|
@ -239,6 +239,7 @@ SET(wesnoth-main_SRC
|
|||
gui/dialogs/addon_list.cpp
|
||||
gui/dialogs/campaign_selection.cpp
|
||||
gui/dialogs/dialog.cpp
|
||||
gui/dialogs/game_save.cpp
|
||||
gui/dialogs/language_selection.cpp
|
||||
gui/dialogs/message.cpp
|
||||
gui/dialogs/mp_connect.cpp
|
||||
|
|
|
@ -230,6 +230,7 @@ wesnoth_sources = Split("""
|
|||
gui/dialogs/addon_list.cpp
|
||||
gui/dialogs/campaign_selection.cpp
|
||||
gui/dialogs/dialog.cpp
|
||||
gui/dialogs/game_save.cpp
|
||||
gui/dialogs/language_selection.cpp
|
||||
gui/dialogs/message.cpp
|
||||
gui/dialogs/mp_connect.cpp
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "widgets/progressbar.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
#include "formula_string_utils.hpp"
|
||||
#include "gui/dialogs/game_save.hpp"
|
||||
|
||||
|
||||
//#ifdef _WIN32
|
||||
|
@ -241,73 +242,37 @@ bool is_illegal_file_char(char c)
|
|||
;
|
||||
}
|
||||
|
||||
int get_save_name(display & disp,const std::string& message, const std::string& txt_label,
|
||||
std::string* fname, gui::DIALOG_TYPE dialog_type, const std::string& title,
|
||||
const bool has_exit_button, const bool ask_for_filename)
|
||||
int get_save_name_oos(display & disp,const std::string& message, const std::string& txt_label,
|
||||
std::string* fname, gui::DIALOG_TYPE dialog_type, const std::string& title)
|
||||
{
|
||||
static int quit_prompt = 0;
|
||||
std::string tmp_title = title;
|
||||
if (tmp_title.empty()) tmp_title = _("Save Game");
|
||||
bool ignore_opt = false;
|
||||
int overwrite=0;
|
||||
int res=0;
|
||||
bool ask = ask_for_filename;
|
||||
do {
|
||||
if (ask) {
|
||||
gui::dialog d(disp, tmp_title, message, dialog_type);
|
||||
d.set_textbox(txt_label, *fname);
|
||||
if(has_exit_button) {
|
||||
d.add_button(new gui::dialog_button(disp.video(), _("Quit Game"),
|
||||
gui::button::TYPE_PRESS, 2), gui::dialog::BUTTON_STANDARD);
|
||||
if(quit_prompt < 0) {
|
||||
res = 1;
|
||||
} else if(quit_prompt > 5) {
|
||||
d.add_button(new gui::dialog_button(disp.video(), _("Ignore All"),
|
||||
gui::button::TYPE_CHECK), gui::dialog::BUTTON_CHECKBOX);
|
||||
res = d.show();
|
||||
ignore_opt = d.option_checked();
|
||||
} else {
|
||||
res = d.show();
|
||||
if(res == 1) {
|
||||
++quit_prompt;
|
||||
} else {
|
||||
quit_prompt = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res = d.show();
|
||||
}
|
||||
*fname = d.textbox_text();
|
||||
|
||||
gui::dialog d(disp, tmp_title, message, dialog_type);
|
||||
d.set_textbox(txt_label, *fname);
|
||||
|
||||
d.add_button(new gui::dialog_button(disp.video(), _("Quit Game"),
|
||||
gui::button::TYPE_PRESS, 2), gui::dialog::BUTTON_STANDARD);
|
||||
if(quit_prompt < 0) {
|
||||
res = 1;
|
||||
} else if(quit_prompt > 5) {
|
||||
d.add_button(new gui::dialog_button(disp.video(), _("Ignore All"),
|
||||
gui::button::TYPE_CHECK), gui::dialog::BUTTON_CHECKBOX);
|
||||
res = d.show();
|
||||
ignore_opt = d.option_checked();
|
||||
} else {
|
||||
res = d.show();
|
||||
if(res == 1) {
|
||||
++quit_prompt;
|
||||
} else {
|
||||
ask = true;
|
||||
quit_prompt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (std::count_if(fname->begin(),fname->end(),is_illegal_file_char)) {
|
||||
gui::message_dialog(disp, _("Error"),
|
||||
_("Save names may not contain colons, slashes, or backslashes. "
|
||||
"Please choose a different name.")).show();
|
||||
overwrite = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_gzip_file(*fname)) {
|
||||
gui::message_dialog(disp, _("Error"),
|
||||
_("Save names should not end on '.gz'. "
|
||||
"Please choose a different name.")).show();
|
||||
overwrite = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (res == 0 && savegame_manager::save_game_exists(*fname, preferences::compress_saves())) {
|
||||
std::stringstream s;
|
||||
s << _("Save already exists. Do you want to overwrite it?")
|
||||
<< std::endl << _("Name: ") << *fname;
|
||||
overwrite = gui::dialog(disp,_("Overwrite?"),
|
||||
s.str(), gui::YES_NO).show();
|
||||
} else {
|
||||
overwrite = 0;
|
||||
}
|
||||
} while ((res == 0) && (overwrite != 0));
|
||||
*fname = d.textbox_text();
|
||||
|
||||
if(ignore_opt) {
|
||||
quit_prompt = -1;
|
||||
|
|
|
@ -58,10 +58,9 @@ bool is_illegal_file_char(char c);
|
|||
* Ask user if I should really save the game and what name I should use returns
|
||||
* 0 if user wants to save the game.
|
||||
*/
|
||||
int get_save_name(display & disp,const std::string& message, const std::string& txt_label,
|
||||
int get_save_name_oos(display & disp,const std::string& message, const std::string& txt_label,
|
||||
std::string* fname, gui::DIALOG_TYPE dialog_type=gui::YES_NO,
|
||||
const std::string& title="", const bool has_exit_button=false,
|
||||
const bool ask_for_filename=true);
|
||||
const std::string& title="");
|
||||
|
||||
/**
|
||||
* Allow user to select the game they want to load. Returns the name of the
|
||||
|
|
87
src/gui/dialogs/game_save.cpp
Normal file
87
src/gui/dialogs/game_save.cpp
Normal file
|
@ -0,0 +1,87 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2008 - 2009 by Jörg Hinrichs <joerg.hinrichs@alice-dsl.de>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
||||
|
||||
#include "gui/dialogs/game_save.hpp"
|
||||
|
||||
#include "foreach.hpp"
|
||||
#include "gui/dialogs/field.hpp"
|
||||
#include "gui/widgets/button.hpp"
|
||||
#include "gui/widgets/label.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
/*WIKI
|
||||
* @page = GUIWindowDefinitionWML
|
||||
* @order = 2_game_save
|
||||
*
|
||||
* == Save a game ==
|
||||
*
|
||||
* This shows the dialog to create a savegame file.
|
||||
*
|
||||
* @start_table = container
|
||||
* txtFilename_ (text_box) The name of the savefile.
|
||||
* @end_table
|
||||
*/
|
||||
tgame_save::tgame_save(const std::string& title, const std::string& filename) :
|
||||
txtFilename_(register_text("txtFilename", false)),
|
||||
title_(title),
|
||||
filename_(filename)
|
||||
{
|
||||
}
|
||||
|
||||
twindow* tgame_save::build_window(CVideo& video)
|
||||
{
|
||||
return build(video, get_id(GAME_SAVE));
|
||||
}
|
||||
|
||||
void tgame_save::pre_show(CVideo& video, twindow& window)
|
||||
{
|
||||
assert(txtFilename_);
|
||||
|
||||
tlabel* lblTitle = dynamic_cast<tlabel*>(window.find_widget("lblTitle", false));
|
||||
VALIDATE(lblTitle, missing_widget("lblTitle"));
|
||||
lblTitle->set_label(title_);
|
||||
|
||||
txtFilename_->set_widget_value(window, filename_);
|
||||
window.keyboard_capture(txtFilename_->widget(window));
|
||||
}
|
||||
|
||||
void tgame_save::post_show(twindow& window)
|
||||
{
|
||||
filename_ = txtFilename_->get_widget_value(window);
|
||||
}
|
||||
|
||||
tgame_save_message::tgame_save_message(const std::string& title, const std::string& filename, const std::string& message)
|
||||
: tgame_save(title, filename),
|
||||
message_(message)
|
||||
{}
|
||||
|
||||
twindow* tgame_save_message::build_window(CVideo& video)
|
||||
{
|
||||
return build(video, get_id(GAME_SAVE_MESSAGE));
|
||||
}
|
||||
|
||||
void tgame_save_message::pre_show(CVideo& video, twindow& window)
|
||||
{
|
||||
tlabel* lblMessage = dynamic_cast<tlabel*>(window.find_widget("lblMessage", false));
|
||||
VALIDATE(lblMessage, missing_widget("lblMessage"));
|
||||
lblMessage->set_label(message_);
|
||||
|
||||
tgame_save::pre_show(video, window);
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
65
src/gui/dialogs/game_save.hpp
Normal file
65
src/gui/dialogs/game_save.hpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2008 - 2009 by Jörg Hinrichs <joerg.hinrichs@alice-dsl.de>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef GUI_DIALOGS_SAVE_GAME_HPP_INCLUDED
|
||||
#define GUI_DIALOGS_SAVE_GAME_HPP_INCLUDED
|
||||
|
||||
#include "gui/dialogs/dialog.hpp"
|
||||
#include "tstring.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
class tgame_save : public tdialog
|
||||
{
|
||||
public:
|
||||
tgame_save(const std::string& title, const std::string& filename="");
|
||||
|
||||
const std::string& filename() const { return filename_; }
|
||||
|
||||
protected:
|
||||
/** Inherited from tdialog. */
|
||||
void pre_show(CVideo& video, twindow& window);
|
||||
|
||||
private:
|
||||
/** Inherited from tdialog. */
|
||||
twindow* build_window(CVideo& video);
|
||||
|
||||
/** Inherited from tdialog. */
|
||||
void post_show(twindow& window);
|
||||
|
||||
|
||||
tfield_text* txtFilename_;
|
||||
std::string title_;
|
||||
std::string filename_;
|
||||
};
|
||||
|
||||
class tgame_save_message : public tgame_save
|
||||
{
|
||||
public:
|
||||
tgame_save_message(const std::string& title, const std::string& filename="", const std::string& message="");
|
||||
|
||||
private:
|
||||
/** Inherited from tgame_save. */
|
||||
twindow* build_window(CVideo& video);
|
||||
|
||||
/** Inherited from tgame_save. */
|
||||
void pre_show(CVideo& video, twindow& window);
|
||||
|
||||
std::string message_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -87,6 +87,8 @@ static void fill_window_types()
|
|||
window_type_list[MP_CMD_WRAPPER] = "mp_cmd_wrapper";
|
||||
window_type_list[MP_CREATE_GAME] = "mp_create_game";
|
||||
window_type_list[TITLE_SCREEN] = "title_screen";
|
||||
window_type_list[GAME_SAVE] = "game_save";
|
||||
window_type_list[GAME_SAVE_MESSAGE] = "game_save_message";
|
||||
#ifndef DISABLE_EDITOR2
|
||||
window_type_list[EDITOR_NEW_MAP] = "editor_new_map";
|
||||
window_type_list[EDITOR_GENERATE_MAP] = "editor_generate_map";
|
||||
|
|
|
@ -65,6 +65,8 @@ enum twindow_type {
|
|||
EDITOR_RESIZE_MAP, /**< Editor resize map dialog. */
|
||||
EDITOR_SETTINGS, /**< Editor settings dialog. */
|
||||
#endif
|
||||
GAME_SAVE, /**< Save game dialog. */
|
||||
GAME_SAVE_MESSAGE, /**< Save game dialog with additional message. */
|
||||
COUNT /**<
|
||||
* The last one to hold the number of items and as
|
||||
* sentinel.
|
||||
|
|
|
@ -540,7 +540,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);
|
||||
save.save_game_interactive(*gui_, temp_buf.str(), gui::YES_NO, true);
|
||||
}
|
||||
|
||||
void playmp_controller::handle_generic_event(const std::string& name){
|
||||
|
|
|
@ -506,7 +506,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 cannot continue. Do you want to save the game?"), gui::YES_NO);
|
||||
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);
|
||||
if(disconnect) {
|
||||
throw network::error();
|
||||
} else {
|
||||
|
|
|
@ -19,7 +19,10 @@
|
|||
#include "foreach.hpp"
|
||||
#include "game_end_exceptions.hpp"
|
||||
#include "game_events.hpp"
|
||||
#include "game_preferences.hpp" //FIXME: get rid of this one
|
||||
#include "gettext.hpp"
|
||||
#include "gui/dialogs/game_save.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "log.hpp"
|
||||
#include "map.hpp"
|
||||
#include "map_label.hpp"
|
||||
|
@ -471,12 +474,60 @@ void savegame::save_game_interactive(display& gui, const std::string& message,
|
|||
{
|
||||
show_confirmation_ = ask_for_filename;
|
||||
create_filename();
|
||||
const int res = dialogs::get_save_name(gui, message, _("Name: "), &filename_, dialog_type, title_, has_exit_button, ask_for_filename);
|
||||
|
||||
|
||||
int res = 0;
|
||||
int overwrite = 0;
|
||||
bool exit = true;
|
||||
|
||||
do{
|
||||
try{
|
||||
if (ask_for_filename){
|
||||
std::string filename = filename_;
|
||||
|
||||
if (has_exit_button)
|
||||
res = dialogs::get_save_name_oos(gui, message, _("Name: "), &filename_, dialog_type, title_);
|
||||
else{
|
||||
if (dialog_type == gui::OK_CANCEL){
|
||||
gui2::tgame_save dlg(title_, filename);
|
||||
dlg.show(gui.video());
|
||||
filename = dlg.filename();
|
||||
res = dlg.get_retval();
|
||||
}
|
||||
else if (dialog_type == gui::YES_NO){
|
||||
gui2::tgame_save_message dlg(title_, filename, message);
|
||||
dlg.show(gui.video());
|
||||
filename = dlg.filename();
|
||||
res = dlg.get_retval();
|
||||
}
|
||||
}
|
||||
|
||||
check_filename(filename, gui);
|
||||
set_filename(filename);
|
||||
}
|
||||
|
||||
std::string filename = filename_;
|
||||
if (res == gui2::twindow::OK && savegame_manager::save_game_exists(filename, preferences::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;
|
||||
}
|
||||
}
|
||||
catch (illegal_filename_exception){
|
||||
exit = false;
|
||||
}
|
||||
}
|
||||
while (!exit);
|
||||
|
||||
if (res == 2)
|
||||
throw end_level_exception(QUIT);
|
||||
|
||||
if (res != 0)
|
||||
if (res != gui2::twindow::OK)
|
||||
return;
|
||||
|
||||
save_game(&gui);
|
||||
|
@ -702,6 +753,16 @@ void savegame::extract_summary_data_from_save(config& out)
|
|||
}
|
||||
}
|
||||
|
||||
void savegame::check_filename(const std::string& filename, display& gui)
|
||||
{
|
||||
if (is_gzip_file(filename)) {
|
||||
gui::message_dialog(gui, _("Error"),
|
||||
_("Save names should not end on '.gz'. "
|
||||
"Please choose a different name.")).show();
|
||||
throw illegal_filename_exception();
|
||||
}
|
||||
}
|
||||
|
||||
void savegame::set_filename(std::string filename)
|
||||
{
|
||||
filename.erase(std::remove_if(filename.begin(), filename.end(),
|
||||
|
|
|
@ -23,9 +23,8 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
struct load_game_cancelled_exception
|
||||
{
|
||||
};
|
||||
struct load_game_cancelled_exception {};
|
||||
struct illegal_filename_exception {};
|
||||
|
||||
/** Filename and modification date for a file list */
|
||||
struct save_info {
|
||||
|
@ -170,6 +169,8 @@ private:
|
|||
/** Build the filename according to the specific savegame's needs. Subclasses will have to
|
||||
override this to take effect. */
|
||||
virtual void create_filename() {}
|
||||
/** Check, if the filename contains illegal constructs like ".gz". */
|
||||
void check_filename(const std::string& filename, 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. */
|
||||
|
|
Loading…
Add table
Reference in a new issue