small load_game_exception refactor
* Moves load_game_exception to savegame.hpp and cleans some #includes * Removes the load_game_exception statis members and replaces them with a non-static load_game_metadata member. * Adds loadgame::DIALOG_TYPE to remove the gui1 dependency. * Fixes loading of replay saves. * Adds soem mising override specifers in savegame.hpp
This commit is contained in:
parent
54e879b183
commit
dcd037e530
20 changed files with 123 additions and 167 deletions
|
@ -39,7 +39,6 @@
|
|||
#include "game_board.hpp" // for game_board
|
||||
#include "game_config.hpp" // for debug
|
||||
#include "game_display.hpp" // for game_display
|
||||
#include "game_errors.hpp" // for throw
|
||||
#include "log.hpp" // for LOG_STREAM, logger, etc
|
||||
#include "map/map.hpp" // for gamemap
|
||||
#include "pathfind/pathfind.hpp" // for paths::dest_vect, paths, etc
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
#include "game_end_exceptions.hpp" // for ai_end_turn_exception
|
||||
#include "game_info.hpp" // for side_number, engine_ptr, etc
|
||||
#include "game_config.hpp" // for debug
|
||||
#include "game_errors.hpp" // for game_error
|
||||
#include "ai/lua/aspect_advancements.hpp"
|
||||
#include "ai/registry.hpp" // for init
|
||||
#include "util.hpp" // for lexical_cast
|
||||
|
|
|
@ -13,10 +13,3 @@
|
|||
*/
|
||||
|
||||
#include "game_errors.hpp"
|
||||
|
||||
std::string game::load_game_exception::game;
|
||||
bool game::load_game_exception::show_replay;
|
||||
bool game::load_game_exception::cancel_orders;
|
||||
bool game::load_game_exception::select_difficulty;
|
||||
std::string game::load_game_exception::difficulty;
|
||||
bool game::load_game_exception::skip_version_check;
|
||||
|
|
|
@ -55,49 +55,6 @@ struct lua_error : public error {
|
|||
lua_error(const std::string& msg, const std::string& context) : error(context + ":\n " + msg) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Exception used to signal that the user has decided to abort a game,
|
||||
* and to load another game instead.
|
||||
*/
|
||||
class load_game_exception
|
||||
: public tlua_jailbreak_exception
|
||||
{
|
||||
public:
|
||||
|
||||
load_game_exception()
|
||||
: tlua_jailbreak_exception()
|
||||
{
|
||||
}
|
||||
|
||||
load_game_exception(
|
||||
const std::string& game_
|
||||
, const bool show_replay_
|
||||
, const bool cancel_orders_
|
||||
, const bool select_difficulty_
|
||||
, const std::string& difficulty_
|
||||
, bool skip_version_check_ = false)
|
||||
: tlua_jailbreak_exception()
|
||||
{
|
||||
game = game_;
|
||||
show_replay = show_replay_;
|
||||
cancel_orders = cancel_orders_;
|
||||
select_difficulty = select_difficulty_;
|
||||
difficulty = difficulty_;
|
||||
skip_version_check = skip_version_check_;
|
||||
}
|
||||
|
||||
static std::string game;
|
||||
static bool show_replay;
|
||||
static bool cancel_orders;
|
||||
static bool select_difficulty;
|
||||
static std::string difficulty;
|
||||
static bool skip_version_check;
|
||||
|
||||
private:
|
||||
|
||||
IMPLEMENT_LUA_JAILBREAK_EXCEPTION(load_game_exception)
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#include "filesystem.hpp"
|
||||
#include "game_classification.hpp"
|
||||
#include "game_display.hpp"
|
||||
#include "game_errors.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "gui/dialogs/transient_message.hpp"
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "multiplayer_create.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "savegame.hpp"
|
||||
#include "saved_game.hpp"
|
||||
#include "scripting/plugins/context.hpp"
|
||||
#include "log.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
@ -322,9 +323,9 @@ void create::process_event_impl(const process_event_data & data)
|
|||
{
|
||||
savegame::loadgame load(video(),
|
||||
game_config_manager::get()->game_config(), engine_.get_state());
|
||||
|
||||
if (data.filename) {
|
||||
if (!load.load_game(*data.filename, false, false, false, "", true)) {
|
||||
load.data().filename = *data.filename;
|
||||
if (!load.load_game()) {
|
||||
return ;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "game_launcher.hpp"
|
||||
#include "global.hpp" // for false_, bool_
|
||||
#include "game_errors.hpp"
|
||||
|
||||
#include "about.hpp" //for show_about
|
||||
#include "commandline_options.hpp" // for commandline_options
|
||||
|
@ -121,7 +122,8 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts, const char
|
|||
multiplayer_server_(),
|
||||
jump_to_multiplayer_(false),
|
||||
jump_to_campaign_(false, -1, "", ""),
|
||||
jump_to_editor_(false)
|
||||
jump_to_editor_(false),
|
||||
load_data_()
|
||||
{
|
||||
bool no_music = false;
|
||||
bool no_sound = false;
|
||||
|
@ -178,15 +180,15 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts, const char
|
|||
if (cmdline_opts_.editor)
|
||||
{
|
||||
jump_to_editor_ = true;
|
||||
if(!cmdline_opts_.editor->empty())
|
||||
game::load_game_exception::game = *cmdline_opts_.editor;
|
||||
if (!cmdline_opts_.editor->empty())
|
||||
load_data_.reset(new savegame::load_game_metadata{ *cmdline_opts_.editor });
|
||||
}
|
||||
if (cmdline_opts_.fps)
|
||||
preferences::set_show_fps(true);
|
||||
if (cmdline_opts_.fullscreen)
|
||||
video().set_fullscreen(true);
|
||||
if (cmdline_opts_.load)
|
||||
game::load_game_exception::game = *cmdline_opts_.load;
|
||||
load_data_.reset(new savegame::load_game_metadata{ *cmdline_opts_.load });
|
||||
if (cmdline_opts_.max_fps) {
|
||||
int fps;
|
||||
//FIXME: remove the next line once the weird util.cpp specialized template lexical_cast_default() linking issue is solved
|
||||
|
@ -263,8 +265,8 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts, const char
|
|||
}
|
||||
if (cmdline_opts_.windowed)
|
||||
video().set_fullscreen(false);
|
||||
if (cmdline_opts_.with_replay)
|
||||
game::load_game_exception::show_replay = true;
|
||||
if (cmdline_opts_.with_replay && load_data_)
|
||||
load_data_->show_replay = true;
|
||||
|
||||
std::cerr
|
||||
<< "\nData directory: " << game_config::path
|
||||
|
@ -488,7 +490,8 @@ bool game_launcher::play_test()
|
|||
try {
|
||||
campaign_controller ccontroller(video(), state_, game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types());
|
||||
ccontroller.play_game();
|
||||
} catch (game::load_game_exception &) {
|
||||
} catch (savegame::load_game_exception &e) {
|
||||
load_data_.reset(new savegame::load_game_metadata(std::move(e.data_)));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -524,9 +527,6 @@ int game_launcher::unit_test()
|
|||
if (!(res == LEVEL_RESULT::VICTORY) || lg::broke_strict()) {
|
||||
return 1;
|
||||
}
|
||||
} catch (game::load_game_exception &) {
|
||||
std::cerr << "Load_game_exception encountered while loading the unit test!" << std::endl;
|
||||
return 1; //failed to load the unit test scenario
|
||||
} catch(twml_exception& e) {
|
||||
std::cerr << "Caught WML Exception:" << e.dev_message << std::endl;
|
||||
return 1;
|
||||
|
@ -540,14 +540,7 @@ int game_launcher::unit_test()
|
|||
savegame::replay_savegame save(state_, compression::NONE);
|
||||
save.save_game_automatic(video(), false, "unit_test_replay"); //false means don't check for overwrite
|
||||
|
||||
clear_loaded_game();
|
||||
|
||||
//game::load_game_exception::game = *cmdline_opts_.load
|
||||
game::load_game_exception::game = "unit_test_replay";
|
||||
// game::load_game_exception::game = "Unit_test_" + test_scenario_ + "_replay";
|
||||
|
||||
game::load_game_exception::show_replay = true;
|
||||
game::load_game_exception::cancel_orders = true;
|
||||
load_data_.reset(new savegame::load_game_metadata{ "unit_test_replay" , "", true, true, false });
|
||||
|
||||
if (!load_game()) {
|
||||
std::cerr << "Failed to load the replay!" << std::endl;
|
||||
|
@ -561,10 +554,6 @@ int game_launcher::unit_test()
|
|||
std::cerr << "Observed failure on replay" << std::endl;
|
||||
return 4;
|
||||
}
|
||||
clear_loaded_game();
|
||||
} catch (game::load_game_exception &) {
|
||||
std::cerr << "Load_game_exception encountered during play_replay!" << std::endl;
|
||||
return 3; //failed to load replay
|
||||
} catch(twml_exception& e) {
|
||||
std::cerr << "WML Exception while playing replay: " << e.dev_message << std::endl;
|
||||
return 4; //failed with an error during the replay
|
||||
|
@ -622,7 +611,7 @@ bool game_launcher::play_render_image_mode()
|
|||
|
||||
bool game_launcher::is_loading() const
|
||||
{
|
||||
return !game::load_game_exception::game.empty();
|
||||
return !!load_data_;
|
||||
}
|
||||
|
||||
bool game_launcher::load_game()
|
||||
|
@ -631,12 +620,14 @@ bool game_launcher::load_game()
|
|||
|
||||
DBG_GENERAL << "Current campaign type: " << state_.classification().campaign_type << std::endl;
|
||||
|
||||
savegame::loadgame load(video(), game_config_manager::get()->game_config(),
|
||||
state_);
|
||||
savegame::loadgame load(video(), game_config_manager::get()->game_config(), state_);
|
||||
if (load_data_) {
|
||||
std::unique_ptr<savegame::load_game_metadata> load_data = std::move(load_data_);
|
||||
load.data() = std::move(*load_data);
|
||||
}
|
||||
|
||||
try {
|
||||
if(!load.load_game(game::load_game_exception::game, game::load_game_exception::show_replay, game::load_game_exception::cancel_orders, game::load_game_exception::select_difficulty, game::load_game_exception::difficulty, game::load_game_exception::skip_version_check)) {
|
||||
clear_loaded_game();
|
||||
if(!load.load_game()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -767,12 +758,12 @@ bool game_launcher::goto_editor()
|
|||
{
|
||||
if(jump_to_editor_){
|
||||
jump_to_editor_ = false;
|
||||
if (start_editor(filesystem::normalize_path(game::load_game_exception::game)) ==
|
||||
std::unique_ptr<savegame::load_game_metadata> load_data = std::move(load_data_);
|
||||
if (start_editor(filesystem::normalize_path(load_data->filename)) ==
|
||||
editor::EXIT_QUIT_TO_DESKTOP)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
clear_loaded_game();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -878,7 +869,8 @@ bool game_launcher::play_multiplayer(mp_selection res)
|
|||
}
|
||||
} catch(incorrect_map_format_error& e) {
|
||||
gui2::show_error_message(video(), std::string(_("The game map could not be loaded: ")) + e.message);
|
||||
} catch (game::load_game_exception &) {
|
||||
} catch (savegame::load_game_exception & e) {
|
||||
load_data_.reset(new savegame::load_game_metadata(std::move(e.data_)));
|
||||
//this will make it so next time through the title screen loop, this game is loaded
|
||||
} catch(twml_exception& e) {
|
||||
e.show(video());
|
||||
|
@ -934,6 +926,7 @@ void game_launcher::show_preferences()
|
|||
|
||||
void game_launcher::launch_game(RELOAD_GAME_DATA reload)
|
||||
{
|
||||
assert(!load_data_);
|
||||
if(play_replay_)
|
||||
{
|
||||
play_replay();
|
||||
|
@ -965,9 +958,8 @@ void game_launcher::launch_game(RELOAD_GAME_DATA reload)
|
|||
about::show_about(video(),state_.classification().campaign);
|
||||
}
|
||||
}
|
||||
|
||||
clear_loaded_game();
|
||||
} catch (game::load_game_exception &) {
|
||||
} catch (savegame::load_game_exception &e) {
|
||||
load_data_.reset(new savegame::load_game_metadata(std::move(e.data_)));
|
||||
//this will make it so next time through the title screen loop, this game is loaded
|
||||
} catch(twml_exception& e) {
|
||||
e.show(video());
|
||||
|
@ -976,12 +968,12 @@ void game_launcher::launch_game(RELOAD_GAME_DATA reload)
|
|||
|
||||
void game_launcher::play_replay()
|
||||
{
|
||||
assert(!load_data_);
|
||||
try {
|
||||
campaign_controller ccontroller(video(), state_, game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types());
|
||||
ccontroller.play_replay();
|
||||
|
||||
clear_loaded_game();
|
||||
} catch (game::load_game_exception &) {
|
||||
} catch (savegame::load_game_exception &e) {
|
||||
load_data_.reset(new savegame::load_game_metadata(std::move(e.data_)));
|
||||
//this will make it so next time through the title screen loop, this game is loaded
|
||||
} catch(twml_exception& e) {
|
||||
e.show(video());
|
||||
|
@ -1007,6 +999,11 @@ editor::EXIT_STATUS game_launcher::start_editor(const std::string& filename)
|
|||
return editor::EXIT_ERROR; // not supposed to happen
|
||||
}
|
||||
|
||||
void game_launcher::clear_loaded_game()
|
||||
{
|
||||
load_data_.reset();
|
||||
}
|
||||
|
||||
game_launcher::~game_launcher()
|
||||
{
|
||||
try {
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "editor/editor_main.hpp" // for EXIT_STATUS
|
||||
#include "events.hpp" // for event_context
|
||||
#include "font.hpp" // for manager
|
||||
#include "game_errors.hpp" // for load_game_exception, etc
|
||||
#include "game_preferences.hpp" // for manager
|
||||
#include "hotkey/hotkey_manager.hpp" // for manager
|
||||
#include "image.hpp" // for manager
|
||||
|
@ -33,7 +32,7 @@
|
|||
class commandline_options;
|
||||
class config;
|
||||
class CVideo;
|
||||
|
||||
namespace savegame { struct load_game_metadata; }
|
||||
struct jump_to_campaign_info
|
||||
{
|
||||
public:
|
||||
|
@ -70,7 +69,7 @@ public:
|
|||
int unit_test();
|
||||
|
||||
bool is_loading() const;
|
||||
void clear_loaded_game() { game::load_game_exception::game.clear(); }
|
||||
void clear_loaded_game();
|
||||
bool load_game();
|
||||
void set_tutorial();
|
||||
|
||||
|
@ -130,6 +129,7 @@ private:
|
|||
jump_to_campaign_info jump_to_campaign_;
|
||||
|
||||
bool jump_to_editor_;
|
||||
std::unique_ptr<savegame::load_game_metadata> load_data_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "savegame.hpp"
|
||||
#include "save_index.hpp"
|
||||
#include "tstring.hpp"
|
||||
#include "gettext.hpp"
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
|
|
@ -531,5 +531,5 @@ hotkey::ACTION_STATE play_controller::hotkey_handler::get_action_state(hotkey::H
|
|||
|
||||
void play_controller::hotkey_handler::load_autosave(const std::string& filename)
|
||||
{
|
||||
throw game::load_game_exception(filename, false, false, false, "", true);
|
||||
throw savegame::load_game_exception({ filename });
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
* See also the command line switches --logdomains and --log-@<level@>="domain".
|
||||
*/
|
||||
|
||||
#include "game_errors.hpp"
|
||||
#include "global.hpp"
|
||||
|
||||
#include "log.hpp"
|
||||
|
|
|
@ -814,7 +814,7 @@ void play_controller::save_game()
|
|||
save_blocker::save_unblocker unblocker;
|
||||
scoped_savegame_snapshot snapshot(*this);
|
||||
savegame::ingame_savegame save(saved_game_, *gui_, preferences::save_compression_format());
|
||||
save.save_game_interactive(gui_->video(), "", gui::OK_CANCEL);
|
||||
save.save_game_interactive(gui_->video(), "", savegame::savegame::OK_CANCEL);
|
||||
} else {
|
||||
save_blocker::on_unblock(this,&play_controller::save_game);
|
||||
}
|
||||
|
@ -836,7 +836,7 @@ void play_controller::save_replay()
|
|||
if(save_blocker::try_block()) {
|
||||
save_blocker::save_unblocker unblocker;
|
||||
savegame::replay_savegame save(saved_game_, preferences::save_compression_format());
|
||||
save.save_game_interactive(gui_->video(), "", gui::OK_CANCEL);
|
||||
save.save_game_interactive(gui_->video(), "", savegame::savegame::OK_CANCEL);
|
||||
} else {
|
||||
save_blocker::on_unblock(this,&play_controller::save_replay);
|
||||
}
|
||||
|
@ -864,7 +864,7 @@ void play_controller::save_map()
|
|||
void play_controller::load_game()
|
||||
{
|
||||
savegame::loadgame load(gui_->video(), game_config_, saved_game_);
|
||||
load.load_game();
|
||||
load.load_game_ingame();
|
||||
}
|
||||
|
||||
void play_controller::undo()
|
||||
|
@ -992,7 +992,7 @@ void play_controller::process_oos(const std::string& msg) const
|
|||
|
||||
scoped_savegame_snapshot snapshot(*this);
|
||||
savegame::oos_savegame save(saved_game_, *gui_, ignore_replay_errors_);
|
||||
save.save_game_interactive(gui_->video(), message.str(), gui::YES_NO); // can throw quit_game_exception
|
||||
save.save_game_interactive(gui_->video(), message.str(), savegame::savegame::YES_NO); // can throw quit_game_exception
|
||||
}
|
||||
|
||||
void play_controller::update_gui_to_player(const int team_index, const bool observe)
|
||||
|
|
|
@ -255,7 +255,7 @@ void playmp_controller::linger()
|
|||
play_linger_turn();
|
||||
after_human_turn();
|
||||
LOG_NG << "finished human turn" << std::endl;
|
||||
} catch (game::load_game_exception&) {
|
||||
} catch (savegame::load_game_exception&) {
|
||||
LOG_NG << "caught load-game-exception" << std::endl;
|
||||
// this should not happen, the option to load a game is disabled
|
||||
throw;
|
||||
|
@ -372,7 +372,7 @@ void playmp_controller::process_oos(const std::string& err_msg) const {
|
|||
}
|
||||
scoped_savegame_snapshot snapshot(*this);
|
||||
savegame::oos_savegame save(saved_game_, *gui_, ignore_replay_errors_);
|
||||
save.save_game_interactive(gui_->video(), temp_buf.str(), gui::YES_NO);
|
||||
save.save_game_interactive(gui_->video(), temp_buf.str(), savegame::savegame::YES_NO);
|
||||
}
|
||||
|
||||
void playmp_controller::handle_generic_event(const std::string& name){
|
||||
|
|
|
@ -319,18 +319,15 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level)
|
|||
}
|
||||
persist_.end_transaction();
|
||||
return is_victory ? LEVEL_RESULT::VICTORY : LEVEL_RESULT::DEFEAT;
|
||||
} catch(const game::load_game_exception &) {
|
||||
} catch(const savegame::load_game_exception &) {
|
||||
// Loading a new game is effectively a quit.
|
||||
//
|
||||
if ( game::load_game_exception::game != "" ) {
|
||||
saved_game_ = saved_game();
|
||||
}
|
||||
saved_game_ = saved_game();
|
||||
throw;
|
||||
} catch(wesnothd_error& e) {
|
||||
|
||||
scoped_savegame_snapshot snapshot(*this);
|
||||
savegame::ingame_savegame save(saved_game_, *gui_, preferences::save_compression_format());
|
||||
save.save_game_interactive(gui_->video(), _("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_->video(), _("A network disconnection has occurred, and the game cannot continue. Do you want to save the game?"), savegame::savegame::YES_NO);
|
||||
if(dynamic_cast<ingame_wesnothd_error*>(&e)) {
|
||||
return LEVEL_RESULT::QUIT;
|
||||
} else {
|
||||
|
@ -484,11 +481,9 @@ void playsingle_controller::linger()
|
|||
play_slice();
|
||||
gui_->draw();
|
||||
}
|
||||
} catch(const game::load_game_exception &) {
|
||||
} catch(const savegame::load_game_exception &) {
|
||||
// Loading a new game is effectively a quit.
|
||||
if ( game::load_game_exception::game != "" ) {
|
||||
saved_game_ = saved_game();
|
||||
}
|
||||
saved_game_ = saved_game();
|
||||
throw;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "format_time_summary.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "game_end_exceptions.hpp"
|
||||
#include "game_errors.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "log.hpp"
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "formula/string_utils.hpp"
|
||||
#include "game_display.hpp"
|
||||
#include "game_end_exceptions.hpp"
|
||||
#include "game_errors.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "gui/dialogs/game_load.hpp"
|
||||
|
@ -35,17 +36,13 @@
|
|||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "log.hpp"
|
||||
#include "map/map.hpp"
|
||||
#include "map/label.hpp"
|
||||
#include "persist_manager.hpp"
|
||||
#include "replay.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "save_index.hpp"
|
||||
#include "saved_game.hpp"
|
||||
#include "serialization/binary_or_text.hpp"
|
||||
#include "serialization/parser.hpp"
|
||||
#include "statistics.hpp"
|
||||
//#include "units/unit.hpp"
|
||||
#include "units/id.hpp"
|
||||
#include "version.hpp"
|
||||
|
||||
static lg::log_domain log_engine("engine");
|
||||
|
@ -121,12 +118,14 @@ bool loadgame::show_difficulty_dialog()
|
|||
|
||||
// Called only by play_controller to handle in-game attempts to load. Instead of returning true,
|
||||
// throws a "load_game_exception" to signal a resulting load game request.
|
||||
bool loadgame::load_game()
|
||||
bool loadgame::load_game_ingame()
|
||||
{
|
||||
if(!video_.faked()) {
|
||||
if(!gui2::tgame_load::execute(game_config_, load_data_, video_)) {
|
||||
return false;
|
||||
}
|
||||
if (video_.faked()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!gui2::tgame_load::execute(game_config_, load_data_, video_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(load_data_.filename.empty()) {
|
||||
|
@ -153,28 +152,19 @@ bool loadgame::load_game()
|
|||
return false;
|
||||
}
|
||||
|
||||
throw game::load_game_exception(load_data_.filename, load_data_.show_replay, load_data_.cancel_orders, load_data_.select_difficulty, load_data_.difficulty, true);
|
||||
throw load_game_exception(std::move(load_data_));
|
||||
}
|
||||
|
||||
bool loadgame::load_game(
|
||||
const std::string& filename
|
||||
, const bool show_replay
|
||||
, const bool cancel_orders
|
||||
, const bool select_difficulty
|
||||
, const std::string& difficulty
|
||||
, bool skip_version_check)
|
||||
bool loadgame::load_game()
|
||||
{
|
||||
load_data_.filename = filename;
|
||||
load_data_.difficulty = difficulty;
|
||||
load_data_.select_difficulty = select_difficulty;
|
||||
bool skip_version_check = true;
|
||||
|
||||
if(load_data_.filename.empty()){
|
||||
if(!gui2::tgame_load::execute(game_config_, load_data_, video_)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
load_data_.show_replay = show_replay;
|
||||
load_data_.cancel_orders = cancel_orders;
|
||||
skip_version_check = false;
|
||||
load_data_.show_replay |= is_replay_save(load_data_.summary);
|
||||
}
|
||||
|
||||
if(load_data_.filename.empty()) {
|
||||
|
@ -276,6 +266,8 @@ bool loadgame::load_multiplayer_game()
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
load_data_.show_replay |= is_replay_save(load_data_.summary);
|
||||
if(load_data_.filename.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -347,15 +339,14 @@ bool savegame::save_game_automatic(CVideo& video, bool ask_for_overwrite, const
|
|||
|
||||
if (ask_for_overwrite){
|
||||
if (!check_overwrite(video)) {
|
||||
return save_game_interactive(video, "", gui::OK_CANCEL);
|
||||
return save_game_interactive(video, "", savegame::OK_CANCEL);
|
||||
}
|
||||
}
|
||||
|
||||
return save_game(&video);
|
||||
}
|
||||
|
||||
bool savegame::save_game_interactive(CVideo& video, const std::string& message,
|
||||
gui::DIALOG_TYPE dialog_type)
|
||||
bool savegame::save_game_interactive(CVideo& video, const std::string& message, DIALOG_TYPE dialog_type)
|
||||
{
|
||||
show_confirmation_ = true;
|
||||
create_filename();
|
||||
|
@ -373,16 +364,16 @@ bool savegame::save_game_interactive(CVideo& video, const std::string& message,
|
|||
return false;
|
||||
}
|
||||
|
||||
int savegame::show_save_dialog(CVideo& video, const std::string& message, const gui::DIALOG_TYPE dialog_type)
|
||||
int savegame::show_save_dialog(CVideo& video, const std::string& message, DIALOG_TYPE dialog_type)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
if (dialog_type == gui::OK_CANCEL){
|
||||
if (dialog_type == OK_CANCEL){
|
||||
gui2::tgame_save dlg(filename_, title_);
|
||||
dlg.show(video);
|
||||
res = dlg.get_retval();
|
||||
}
|
||||
else if (dialog_type == gui::YES_NO){
|
||||
else if (dialog_type == YES_NO){
|
||||
gui2::tgame_save_message dlg(filename_, title_, message);
|
||||
dlg.show(video);
|
||||
res = dlg.get_retval();
|
||||
|
@ -600,7 +591,7 @@ oos_savegame::oos_savegame(saved_game& gamestate, game_display& gui, bool& ignor
|
|||
, ignore_(ignore)
|
||||
{}
|
||||
|
||||
int oos_savegame::show_save_dialog(CVideo& video, const std::string& message, const gui::DIALOG_TYPE /*dialog_type*/)
|
||||
int oos_savegame::show_save_dialog(CVideo& video, const std::string& message, DIALOG_TYPE /*dialog_type*/)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
|
|
|
@ -16,12 +16,18 @@
|
|||
#ifndef SAVEGAME_H_INCLUDED
|
||||
#define SAVEGAME_H_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "saved_game.hpp"
|
||||
#include "show_dialog.hpp"
|
||||
#include "lua_jailbreak_exception.hpp"
|
||||
#include "serialization/compression.hpp"
|
||||
|
||||
#include <exception>
|
||||
|
||||
class config_writer;
|
||||
class game_display;
|
||||
class saved_game;
|
||||
class CVideo;
|
||||
class version_info;
|
||||
|
||||
namespace savegame {
|
||||
/** converts saves from older versions of wesnoth*/
|
||||
|
@ -55,6 +61,30 @@ struct load_game_metadata {
|
|||
config load_config;
|
||||
};
|
||||
|
||||
/**
|
||||
* Exception used to signal that the user has decided to abortt a game,
|
||||
* and to load another game instead.
|
||||
*/
|
||||
class load_game_exception
|
||||
: public tlua_jailbreak_exception, public std::exception
|
||||
{
|
||||
public:
|
||||
load_game_exception()
|
||||
: tlua_jailbreak_exception()
|
||||
{
|
||||
}
|
||||
|
||||
load_game_exception(load_game_metadata&& data)
|
||||
: tlua_jailbreak_exception()
|
||||
, data_(data)
|
||||
{
|
||||
}
|
||||
load_game_metadata data_;
|
||||
private:
|
||||
|
||||
IMPLEMENT_LUA_JAILBREAK_EXCEPTION(load_game_exception)
|
||||
};
|
||||
|
||||
/** The class for loading a savefile. */
|
||||
class loadgame
|
||||
{
|
||||
|
@ -66,22 +96,16 @@ public:
|
|||
some failure or abort of the load process */
|
||||
|
||||
/** Load a game without providing any information. */
|
||||
bool load_game();
|
||||
bool load_game_ingame();
|
||||
/** Load a game with pre-setting information for the load-game dialog. */
|
||||
bool load_game(
|
||||
const std::string& filename
|
||||
, const bool show_replay
|
||||
, const bool cancel_orders
|
||||
, const bool select_difficulty
|
||||
, const std::string& difficulty
|
||||
, bool skip_version_check);
|
||||
bool load_game();
|
||||
/** Loading a game from within the multiplayer-create dialog. */
|
||||
bool load_multiplayer_game();
|
||||
/** Generate the gamestate out of the loaded game config. */
|
||||
void set_gamestate();
|
||||
|
||||
// Getter-methods
|
||||
const load_game_metadata& data()
|
||||
load_game_metadata& data()
|
||||
{
|
||||
return load_data_;
|
||||
}
|
||||
|
@ -109,7 +133,6 @@ private:
|
|||
|
||||
load_game_metadata load_data_;
|
||||
};
|
||||
|
||||
/**
|
||||
* The base class for all savegame stuff.
|
||||
* This should not be used directly, as it does not directly produce usable saves.
|
||||
|
@ -123,6 +146,8 @@ protected:
|
|||
savegame(saved_game& gamestate, const compression::format compress_saves, const std::string& title = "Save");
|
||||
|
||||
public:
|
||||
enum DIALOG_TYPE { YES_NO, OK_CANCEL};
|
||||
|
||||
virtual ~savegame() {}
|
||||
|
||||
/** Saves a game without user interaction, unless the file exists and it should be asked
|
||||
|
@ -135,7 +160,7 @@ public:
|
|||
/** 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& video, const std::string& message,
|
||||
gui::DIALOG_TYPE dialog_type);
|
||||
DIALOG_TYPE dialog_type);
|
||||
|
||||
const std::string& filename() const { return filename_; }
|
||||
|
||||
|
@ -173,7 +198,7 @@ private:
|
|||
override this to take effect. */
|
||||
virtual void create_filename() {}
|
||||
/** Display the save game dialog. */
|
||||
virtual int show_save_dialog(CVideo& video, const std::string& message, const gui::DIALOG_TYPE dialog_type);
|
||||
virtual int show_save_dialog(CVideo& video, const std::string& message, DIALOG_TYPE dialog_type);
|
||||
/** Ask the user if an existing file should be overwritten. */
|
||||
bool check_overwrite(CVideo& video);
|
||||
|
||||
|
@ -210,10 +235,10 @@ public:
|
|||
|
||||
private:
|
||||
/** Create a filename for automatic saves */
|
||||
virtual void create_filename();
|
||||
virtual void create_filename() override;
|
||||
|
||||
|
||||
void write_game(config_writer &out);
|
||||
void write_game(config_writer &out) override;
|
||||
|
||||
protected:
|
||||
game_display& gui_;
|
||||
|
@ -227,9 +252,9 @@ public:
|
|||
|
||||
private:
|
||||
/** Create a filename for automatic saves */
|
||||
virtual void create_filename();
|
||||
virtual void create_filename() override;
|
||||
|
||||
void write_game(config_writer &out);
|
||||
void write_game(config_writer &out) override;
|
||||
};
|
||||
|
||||
/** Class for autosaves. */
|
||||
|
@ -242,7 +267,7 @@ public:
|
|||
void autosave(const bool disable_autosave, const int autosave_max, const int infinite_autosaves);
|
||||
private:
|
||||
/** Create a filename for automatic saves */
|
||||
virtual void create_filename();
|
||||
virtual void create_filename() override;
|
||||
};
|
||||
|
||||
class oos_savegame : public ingame_savegame
|
||||
|
@ -252,7 +277,7 @@ public:
|
|||
|
||||
private:
|
||||
/** Display the save game dialog. */
|
||||
virtual int show_save_dialog(CVideo& video, const std::string& message, const gui::DIALOG_TYPE dialog_type);
|
||||
virtual int show_save_dialog(CVideo& video, const std::string& message, DIALOG_TYPE dialog_type) override;
|
||||
bool& ignore_;
|
||||
};
|
||||
|
||||
|
@ -263,7 +288,7 @@ public:
|
|||
scenariostart_savegame(saved_game& gamestate, const compression::format compress_saves);
|
||||
|
||||
private:
|
||||
void write_game(config_writer &out);
|
||||
void write_game(config_writer &out) override;
|
||||
};
|
||||
|
||||
} //end of namespace savegame
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "game_errors.hpp"
|
||||
#include "exceptions.hpp"
|
||||
|
||||
class config_writer;
|
||||
class config;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#ifndef SERIALIZATION_VALIDATOR_HPP_INCLUDED
|
||||
#define SERIALIZATION_VALIDATOR_HPP_INCLUDED
|
||||
|
||||
#include "game_errors.hpp"
|
||||
#include "exceptions.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#define WB_MOVE_HPP_
|
||||
|
||||
#include "action.hpp"
|
||||
#include "game_errors.hpp"
|
||||
|
||||
struct temporary_unit_mover;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue