The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
savegame::savegame Class Reference

The base class for all savegame stuff. More...

#include <savegame.hpp>

Inheritance diagram for savegame::savegame:
Inheritance graph

Public Member Functions

virtual ~savegame ()
 
bool save_game_automatic (CVideo &video, bool ask_for_overwrite=false, const std::string &filename="")
 Saves a game without user interaction, unless the file exists and it should be asked to overwrite it. More...
 
bool save_game_interactive (CVideo &video, const std::string &message, gui::DIALOG_TYPE dialog_type)
 Save a game interactively through the savegame dialog. More...
 
const std::stringfilename () const
 

Protected Member Functions

 savegame (saved_game &gamestate, const compression::format compress_saves, const std::string &title="Save")
 The only constructor of savegame. More...
 
bool save_game (CVideo *video=nullptr, const std::string &filename="")
 Save a game without any further user interaction. More...
 
void set_filename (std::string filename)
 Sets the filename and removes invalid characters. More...
 
bool check_filename (const std::string &filename, CVideo &video)
 Check, if the filename contains illegal constructs like ".gz". More...
 
void set_error_message (const std::string &error_message)
 Customize the standard error message. More...
 
const std::stringtitle ()
 
const saved_gamegamestate ()
 
void before_save ()
 If there needs to be some data fiddling before saving the game, this is the place to go. More...
 
virtual void write_game (config_writer &out)
 Writing the savegame config to a file. More...
 

Private Member Functions

virtual void create_filename ()
 Build the filename according to the specific savegame's needs. More...
 
virtual int show_save_dialog (CVideo &video, const std::string &message, const gui::DIALOG_TYPE dialog_type)
 Display the save game dialog. More...
 
bool check_overwrite (CVideo &video)
 Ask the user if an existing file should be overwritten. More...
 
void write_game_to_disk (const std::string &filename)
 The actual method for saving the game to disk. More...
 
void finish_save_game (const config_writer &out)
 Update the save_index. More...
 
filesystem::scoped_ostream open_save_game (const std::string &label)
 Throws game::save_game_failed. More...
 

Static Private Member Functions

static bool is_illegal_file_char (char c)
 Checks if a certain character is allowed in a savefile name. More...
 

Private Attributes

saved_gamegamestate_
 
std::string filename_
 Filename of the savegame file on disk. More...
 
const std::string title_
 
std::string error_message_
 Title of the savegame dialog. More...
 
bool show_confirmation_
 Error message to be displayed if the savefile could not be generated. More...
 
compression::format compress_saves_
 Determines if a confirmation of successful saving the game is shown. More...
 

Friends

class save_info
 

Detailed Description

The base class for all savegame stuff.

This should not be used directly, as it does not directly produce usable saves. Instead, use one of the derived classes.

Definition at line 101 of file savegame.hpp.

Constructor & Destructor Documentation

savegame::savegame::savegame ( saved_game gamestate,
const compression::format  compress_saves,
const std::string title = "Save" 
)
protected

The only constructor of savegame.

The title parameter is only necessary if you intend to do interactive saves.

Definition at line 341 of file savegame.cpp.

virtual savegame::savegame::~savegame ( )
inlinevirtual

Definition at line 109 of file savegame.hpp.

Member Function Documentation

void savegame::savegame::before_save ( )
protected

If there needs to be some data fiddling before saving the game, this is the place to go.

Definition at line 449 of file savegame.cpp.

bool savegame::savegame::check_filename ( const std::string filename,
CVideo video 
)
protected

Check, if the filename contains illegal constructs like ".gz".

Definition at line 422 of file savegame.cpp.

References _(), filesystem::is_compressed_file(), and gui2::show_error_message().

Referenced by savegame::oos_savegame::show_save_dialog().

bool savegame::savegame::check_overwrite ( CVideo video)
private

Ask the user if an existing file should be overwritten.

Definition at line 409 of file savegame.cpp.

References _(), filename_, gui2::twindow::OK, savegame::save_game_exists(), gui2::show_message(), and gui2::tmessage::yes_no_buttons.

virtual void savegame::savegame::create_filename ( )
inlineprivatevirtual

Build the filename according to the specific savegame's needs.

Subclasses will have to override this to take effect.

Reimplemented in savegame::autosave_savegame, savegame::replay_savegame, and savegame::ingame_savegame.

Definition at line 157 of file savegame.hpp.

const std::string& savegame::savegame::filename ( ) const
inline
void savegame::savegame::finish_save_game ( const config_writer out)
private
const saved_game& savegame::savegame::gamestate ( )
inlineprotected
bool savegame::savegame::is_illegal_file_char ( char  c)
staticprivate

Checks if a certain character is allowed in a savefile name.

Definition at line 433 of file savegame.cpp.

filesystem::scoped_ostream savegame::savegame::open_save_game ( const std::string label)
private
bool savegame::savegame::save_game ( CVideo video = nullptr,
const std::string filename = "" 
)
protected

Save a game without any further user interaction.

If you want notifying messages or error messages to appear, you have to provide the gui parameter. The return value denotes, if the save was successful or not.

Definition at line 453 of file savegame.cpp.

References _(), e, persist_manager::end_transaction(), ERR_SAVE, filename_, LOG_SAVE, game::error::message, resources::persist, gui2::show_error_message(), gui2::show_transient_message(), and persist_manager::start_transaction().

bool savegame::savegame::save_game_automatic ( CVideo video,
bool  ask_for_overwrite = false,
const std::string filename = "" 
)

Saves a game without user interaction, unless the file exists and it should be asked to overwrite it.

The return value denotes, if the save was successful or not. This is used by automatically generated replays, start-of-scenario saves, autosaves, and saves from the console (e.g. ":w").

Definition at line 350 of file savegame.cpp.

References filename_, and gui::OK_CANCEL.

Referenced by savegame::autosave_savegame::autosave(), play_controller::do_consolesave(), campaign_controller::play_game(), play_controller::save_game_auto(), play_controller::save_replay_auto(), and game_launcher::unit_test().

bool savegame::savegame::save_game_interactive ( CVideo video,
const std::string message,
gui::DIALOG_TYPE  dialog_type 
)

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.

Definition at line 366 of file savegame.cpp.

References gui2::twindow::OK, and throw_quit_game_exception().

Referenced by playsingle_controller::play_scenario(), playmp_controller::process_oos(), play_controller::process_oos(), play_controller::save_game(), and play_controller::save_replay().

void savegame::savegame::set_error_message ( const std::string error_message)
inlineprotected

Customize the standard error message.

Definition at line 140 of file savegame.hpp.

Referenced by savegame::autosave_savegame::autosave_savegame().

void savegame::savegame::set_filename ( std::string  filename)
protected

Sets the filename and removes invalid characters.

Don't set the filename directly but use this method instead.

Definition at line 442 of file savegame.cpp.

References filename_.

Referenced by savegame::ingame_savegame::create_filename(), savegame::replay_savegame::create_filename(), savegame::autosave_savegame::create_filename(), savegame::scenariostart_savegame::scenariostart_savegame(), and savegame::oos_savegame::show_save_dialog().

int savegame::savegame::show_save_dialog ( CVideo video,
const std::string message,
const gui::DIALOG_TYPE  dialog_type 
)
privatevirtual

Display the save game dialog.

Reimplemented in savegame::oos_savegame.

Definition at line 385 of file savegame.cpp.

References gui2::twindow::CANCEL, filename_, gui2::tdialog::get_retval(), gui::OK_CANCEL, gui2::tdialog::show(), and gui::YES_NO.

const std::string& savegame::savegame::title ( )
inlineprotected

Definition at line 142 of file savegame.hpp.

Referenced by savegame::oos_savegame::show_save_dialog().

void savegame::savegame::write_game ( config_writer out)
protectedvirtual
void savegame::savegame::write_game_to_disk ( const std::string filename)
private

The actual method for saving the game to disk.

All interactive filename choosing and data manipulation has to happen before calling this method.

Definition at line 489 of file savegame.cpp.

References _(), filename_, compression::format_extension(), and LOG_SAVE.

Friends And Related Function Documentation

friend class save_info
friend

Definition at line 171 of file savegame.hpp.

Member Data Documentation

compression::format savegame::savegame::compress_saves_
private

Determines if a confirmation of successful saving the game is shown.

Definition at line 183 of file savegame.hpp.

std::string savegame::savegame::error_message_
private

Title of the savegame dialog.

Definition at line 179 of file savegame.hpp.

std::string savegame::savegame::filename_
private

Filename of the savegame file on disk.

Definition at line 175 of file savegame.hpp.

saved_game& savegame::savegame::gamestate_
private

Definition at line 173 of file savegame.hpp.

bool savegame::savegame::show_confirmation_
private

Error message to be displayed if the savefile could not be generated.

Definition at line 181 of file savegame.hpp.

const std::string savegame::savegame::title_
private

Definition at line 177 of file savegame.hpp.


The documentation for this class was generated from the following files: