mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-18 20:31:19 +00:00
Savegame reorganization Step 1: a simpler interface to saving and loading.
Further refactoring savegame.cpp and slightly simplifying the interface.
This commit is contained in:
parent
84fa740084
commit
4809396dc2
@ -2764,11 +2764,11 @@ private:
|
||||
}
|
||||
void console_handler::do_save() {
|
||||
savegame save(menu_handler_.gamestate_, preferences::compress_saves());
|
||||
save.save_game(get_data());
|
||||
save.save_game(&menu_handler_.gui_->video(), get_data());
|
||||
}
|
||||
void console_handler::do_save_quit() {
|
||||
savegame save(menu_handler_.gamestate_, preferences::compress_saves());
|
||||
save.save_game(get_data());
|
||||
save.save_game(&menu_handler_.gui_->video(), get_data());
|
||||
throw end_level_exception(QUIT);
|
||||
}
|
||||
void console_handler::do_quit() {
|
||||
|
@ -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.video(), "", gui::OK_CANCEL, false, false);
|
||||
save.save_game_interactive(disp.video(), "", gui::OK_CANCEL, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -538,8 +538,8 @@ void playmp_controller::process_oos(const std::string& err_msg){
|
||||
temp_buf << " \n";
|
||||
}
|
||||
|
||||
game_savegame save(gamestate_, level_, *gui_, teams_, units_, status_, map_, preferences::compress_saves());
|
||||
save.save_game_interactive((*gui_).video(), temp_buf.str(), gui::YES_NO, true);
|
||||
oos_savegame save(gamestate_, level_, *gui_, teams_, units_, status_, map_, preferences::compress_saves());
|
||||
save.save_game_interactive((*gui_).video(), temp_buf.str(), gui::YES_NO);
|
||||
}
|
||||
|
||||
void playmp_controller::handle_generic_event(const std::string& name){
|
||||
|
@ -476,8 +476,7 @@ savegame::savegame(game_state& gamestate, const bool compress_saves, const std::
|
||||
{}
|
||||
|
||||
bool savegame::save_game_interactive(CVideo& video, const std::string& message,
|
||||
gui::DIALOG_TYPE dialog_type, const bool has_exit_button,
|
||||
bool ask_for_filename)
|
||||
gui::DIALOG_TYPE dialog_type, bool ask_for_filename)
|
||||
{
|
||||
show_confirmation_ = ask_for_filename;
|
||||
create_filename();
|
||||
@ -488,7 +487,7 @@ bool savegame::save_game_interactive(CVideo& video, const std::string& message,
|
||||
do{
|
||||
try{
|
||||
if (ask_for_filename){
|
||||
res = show_save_dialog(video, has_exit_button, message, dialog_type);
|
||||
res = show_save_dialog(video, message, dialog_type);
|
||||
exit = true;
|
||||
}
|
||||
|
||||
@ -516,33 +515,23 @@ bool savegame::save_game_interactive(CVideo& video, const std::string& message,
|
||||
return save_game(&video);
|
||||
}
|
||||
|
||||
int savegame::show_save_dialog(CVideo& video, bool is_oos, const std::string& message, const gui::DIALOG_TYPE dialog_type)
|
||||
int savegame::show_save_dialog(CVideo& video, const std::string& message, const gui::DIALOG_TYPE dialog_type)
|
||||
{
|
||||
static bool ignore_all = false;
|
||||
int res = 0;
|
||||
|
||||
std::string filename = filename_;
|
||||
|
||||
if (is_oos && (!ignore_all)){
|
||||
gui2::tgame_save_oos dlg(title_, filename, message);
|
||||
if (dialog_type == gui::OK_CANCEL){
|
||||
gui2::tgame_save dlg(title_, filename);
|
||||
dlg.show(video);
|
||||
filename = dlg.filename();
|
||||
ignore_all = dlg.ignore_all();
|
||||
res = dlg.get_retval();
|
||||
}
|
||||
else{
|
||||
if (dialog_type == gui::OK_CANCEL){
|
||||
gui2::tgame_save dlg(title_, filename);
|
||||
dlg.show(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(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(video);
|
||||
filename = dlg.filename();
|
||||
res = dlg.get_retval();
|
||||
}
|
||||
|
||||
check_filename(filename, video);
|
||||
@ -593,18 +582,15 @@ void savegame::before_save()
|
||||
gamestate_.replay_data = recorder.get_replay_data();
|
||||
}
|
||||
|
||||
bool savegame::save_game(const std::string& filename)
|
||||
{
|
||||
filename_ = filename;
|
||||
return save_game();
|
||||
}
|
||||
|
||||
bool savegame::save_game(CVideo* video)
|
||||
bool savegame::save_game(CVideo* video, const std::string& filename)
|
||||
{
|
||||
try {
|
||||
Uint32 start, end;
|
||||
start = SDL_GetTicks();
|
||||
|
||||
if (filename_ == "")
|
||||
filename_ = filename;
|
||||
|
||||
before_save();
|
||||
save_game_internal(filename_);
|
||||
|
||||
@ -870,6 +856,34 @@ void autosave_savegame::create_filename()
|
||||
set_filename(filename);
|
||||
}
|
||||
|
||||
oos_savegame::oos_savegame(game_state &gamestate, const config& level_cfg,
|
||||
game_display& gui, const std::vector<team>& teams,
|
||||
const unit_map& units, const gamestatus& gamestatus,
|
||||
const gamemap& map, const bool compress_saves)
|
||||
: game_savegame(gamestate, level_cfg, gui, teams, units, gamestatus, map, compress_saves)
|
||||
{}
|
||||
|
||||
int oos_savegame::show_save_dialog(CVideo& video, const std::string& message, const gui::DIALOG_TYPE dialog_type)
|
||||
{
|
||||
static bool ignore_all = false;
|
||||
int res = 0;
|
||||
|
||||
std::string filename = this->filename();
|
||||
|
||||
if (!ignore_all){
|
||||
gui2::tgame_save_oos dlg(title(), filename, message);
|
||||
dlg.show(video);
|
||||
filename = dlg.filename();
|
||||
ignore_all = dlg.ignore_all();
|
||||
res = dlg.get_retval();
|
||||
}
|
||||
|
||||
check_filename(filename, video);
|
||||
set_filename(filename);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
game_savegame::game_savegame(game_state &gamestate, const config& level_cfg,
|
||||
game_display& gui, const std::vector<team>& teams,
|
||||
const unit_map& units, const gamestatus& gamestatus,
|
||||
|
@ -136,7 +136,7 @@ public:
|
||||
|
||||
/** Save a game without any further user interaction. Atm, this is only used by the
|
||||
console_handler save actions. The return value denotes, if the save was successful or not. */
|
||||
bool save_game(const std::string& filename);
|
||||
//bool save_game(const std::string& filename);
|
||||
|
||||
/**
|
||||
Save a game without any further user interaction. This is used by autosaves and
|
||||
@ -144,24 +144,26 @@ public:
|
||||
to appear, you have to provide the gui parameter.
|
||||
The return value denotes, if the save was successful or not.
|
||||
*/
|
||||
bool save_game(CVideo* video = NULL);
|
||||
bool save_game(CVideo* video = NULL, const std::string& filename = "");
|
||||
|
||||
/** 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(CVideo& gui, const std::string& message,
|
||||
gui::DIALOG_TYPE dialog_type, const bool has_exit_button = false,
|
||||
bool ask_for_filename = true);
|
||||
gui::DIALOG_TYPE dialog_type, bool ask_for_filename = true);
|
||||
|
||||
const std::string filename() const { return filename_; }
|
||||
const std::string& filename() const { return filename_; }
|
||||
|
||||
protected:
|
||||
/** Sets the filename and removes invalid characters. Don't set the filename directly but
|
||||
use this method instead. */
|
||||
void set_filename(std::string filename);
|
||||
/** Check, if the filename contains illegal constructs like ".gz". */
|
||||
void check_filename(const std::string& filename, CVideo& video);
|
||||
|
||||
/** Customize the standard error message */
|
||||
void set_error_message(const std::string error_message) { error_message_ = error_message; }
|
||||
|
||||
const std::string& title() const { return title_; }
|
||||
game_state& gamestate() const { return gamestate_; }
|
||||
config& snapshot() { return snapshot_; }
|
||||
|
||||
@ -175,10 +177,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, CVideo& video);
|
||||
/** Display the save game dialog. */
|
||||
int show_save_dialog(CVideo& video, bool is_oos, const std::string& message, const gui::DIALOG_TYPE dialog_type);
|
||||
virtual int show_save_dialog(CVideo& video, const std::string& message, const gui::DIALOG_TYPE dialog_type);
|
||||
/** Ask the user if an existing file should be overwritten. */
|
||||
bool check_overwrite(CVideo& video);
|
||||
|
||||
@ -257,9 +257,9 @@ class autosave_savegame : public game_savegame
|
||||
{
|
||||
public:
|
||||
autosave_savegame(game_state &gamestate, const config& level_cfg,
|
||||
game_display& gui, const std::vector<team>& teams,
|
||||
const unit_map& units, const gamestatus& gamestatus,
|
||||
const gamemap& map, const bool compress_saves);
|
||||
game_display& gui, const std::vector<team>& teams,
|
||||
const unit_map& units, const gamestatus& gamestatus,
|
||||
const gamemap& map, const bool compress_saves);
|
||||
|
||||
void autosave(const bool disable_autosave, const int autosave_max, const int infinite_autosaves);
|
||||
private:
|
||||
@ -267,6 +267,19 @@ private:
|
||||
virtual void create_filename();
|
||||
};
|
||||
|
||||
class oos_savegame : public game_savegame
|
||||
{
|
||||
public:
|
||||
oos_savegame(game_state &gamestate, const config& level_cfg,
|
||||
game_display& gui, const std::vector<team>& teams,
|
||||
const unit_map& units, const gamestatus& gamestatus,
|
||||
const gamemap& map, const bool compress_saves);
|
||||
|
||||
private:
|
||||
/** Display the save game dialog. */
|
||||
virtual int show_save_dialog(CVideo& video, const std::string& message, const gui::DIALOG_TYPE dialog_type);
|
||||
};
|
||||
|
||||
/** Class for start-of-scenario saves */
|
||||
class scenariostart_savegame : public savegame
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user