Separated the difficulty dialog call...

...from the filename one when loading a savefile.
This commit is contained in:
Fabian Müller 2012-02-07 23:50:30 +00:00
parent cb630f1bc4
commit 3331efe103
6 changed files with 63 additions and 48 deletions

View file

@ -593,7 +593,7 @@ bool game_controller::load_game()
savegame::loadgame load(disp(), game_config(), state_);
try {
load.load_game(game::load_game_exception::game, game::load_game_exception::show_replay, game::load_game_exception::cancel_orders, game::load_game_exception::difficulty);
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);
cache_.clear_defines();
game_config::scoped_preproc_define dificulty_def(state_.classification().difficulty);

View file

@ -18,4 +18,5 @@
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;

View file

@ -66,18 +66,21 @@ public:
const std::string& game_
, const bool show_replay_
, const bool cancel_orders_
, const bool select_difficulty_
, const std::string& difficulty_)
: tlua_jailbreak_exception()
{
game = game_;
show_replay = show_replay_;
cancel_orders = cancel_orders_;
select_difficulty = select_difficulty_;
difficulty = difficulty_;
}
static std::string game;
static bool show_replay;
static bool cancel_orders;
static bool select_difficulty;
static std::string difficulty;
private:

View file

@ -773,7 +773,7 @@ bool play_controller::execute_command(hotkey::HOTKEY_COMMAND command, int index)
unsigned i = static_cast<unsigned>(index);
if(i < savenames_.size() && !savenames_[i].empty()) {
// Load the game by throwing load_game_exception
throw game::load_game_exception(savenames_[i],false,false,"");
throw game::load_game_exception(savenames_[i],false,false,false,"");
} else if (i < wml_commands_.size() && wml_commands_[i] != NULL) {
if(gamestate_.last_selected.valid() && wml_commands_[i]->needs_select) {

View file

@ -434,13 +434,12 @@ void loadgame::show_dialog(bool show_replay, bool cancel_orders)
{
//FIXME: Integrate the load_game dialog into this class
//something to watch for the curious, but not yet ready to go
bool select_difficulty = false;
if (gui2::new_widgets){
gui2::tgame_load load_dialog(game_config_);
load_dialog.show(gui_.video());
if (load_dialog.get_retval() == gui2::twindow::OK) {
select_difficulty = load_dialog.reselect_difficulty();
select_difficulty_ = load_dialog.reselect_difficulty();
filename_ = load_dialog.filename();
show_replay_ = load_dialog.show_replay();
@ -449,70 +448,76 @@ void loadgame::show_dialog(bool show_replay, bool cancel_orders)
} else {
bool show_replay_dialog = show_replay;
bool cancel_orders_dialog = cancel_orders;
filename_ = dialogs::load_game_dialog(gui_, game_config_, &select_difficulty, &show_replay_dialog, &cancel_orders_dialog);
filename_ = dialogs::load_game_dialog(gui_, game_config_, &select_difficulty_, &show_replay_dialog, &cancel_orders_dialog);
show_replay_ = show_replay_dialog;
cancel_orders_ = cancel_orders_dialog;
}
if (select_difficulty) {
config cfg_summary;
std::string dummy;
try {
manager::load_summary(filename_, cfg_summary, &dummy);
} catch(game::load_game_failed&) {
cfg_summary["corrupt"] = "yes";
}
if ( cfg_summary["corrupt"].to_bool() || (cfg_summary["replay"].to_bool() && !cfg_summary["snapshot"].to_bool(true))
|| (!cfg_summary["turn"].empty()) )
return;
const config::const_child_itors &campaigns = game_config_.child_range("campaign");
std::vector<std::string> difficulty_descriptions;
std::vector<std::string> difficulties;
foreach (const config &campaign, campaigns)
{
if (campaign["id"] == cfg_summary["campaign"]) {
difficulty_descriptions = utils::split(campaign["difficulty_descriptions"], ';');
difficulties = utils::split(campaign["difficulties"]);
break;
}
}
if (difficulty_descriptions.empty())
return;
gui2::tcampaign_difficulty difficulty_dlg(difficulty_descriptions);
difficulty_dlg.show(gui_.video());
if (difficulty_dlg.get_retval() != gui2::twindow::OK) {
filename_ = "";
return;
}
difficulty_ = difficulties[difficulty_dlg.selected_index()];
}
}
void loadgame::show_difficulty_dialog()
{
config cfg_summary;
std::string dummy;
try {
manager::load_summary(filename_, cfg_summary, &dummy);
} catch(game::load_game_failed&) {
cfg_summary["corrupt"] = "yes";
}
if ( cfg_summary["corrupt"].to_bool() || (cfg_summary["replay"].to_bool() && !cfg_summary["snapshot"].to_bool(true))
|| (!cfg_summary["turn"].empty()) )
return;
const config::const_child_itors &campaigns = game_config_.child_range("campaign");
std::vector<std::string> difficulty_descriptions;
std::vector<std::string> difficulties;
foreach (const config &campaign, campaigns)
{
if (campaign["id"] == cfg_summary["campaign"]) {
difficulty_descriptions = utils::split(campaign["difficulty_descriptions"], ';');
difficulties = utils::split(campaign["difficulties"]);
break;
}
}
if (difficulty_descriptions.empty())
return;
gui2::tcampaign_difficulty difficulty_dlg(difficulty_descriptions);
difficulty_dlg.show(gui_.video());
if (difficulty_dlg.get_retval() != gui2::twindow::OK) {
filename_ = "";
return;
}
difficulty_ = difficulties[difficulty_dlg.selected_index()];
}
void loadgame::load_game()
{
show_dialog(false, false);
// if (select_difficulty_)
// show_difficulty_dialog();
if(filename_ != "")
throw game::load_game_exception(filename_, show_replay_, cancel_orders_, difficulty_);
throw game::load_game_exception(filename_, show_replay_, cancel_orders_, select_difficulty_, difficulty_);
}
void loadgame::load_game(
const std::string& filename
, const bool show_replay
, const bool cancel_orders
, const bool select_difficulty
, const std::string& difficulty)
{
filename_ = filename;
difficulty_ = difficulty;
select_difficulty_ = select_difficulty;
if (filename_.empty()){
show_dialog(show_replay, cancel_orders);
@ -525,6 +530,9 @@ void loadgame::load_game(
if (filename_.empty())
throw load_game_cancelled_exception();
if (select_difficulty_)
show_difficulty_dialog();
std::string error_log;
manager::read_save_file(filename_, load_config_, &error_log);

View file

@ -106,6 +106,7 @@ public:
const std::string& filename
, const bool show_replay
, const bool cancel_orders
, const bool select_difficulty
, const std::string& difficulty);
/** Loading a game from within the multiplayer-create dialog. */
void load_multiplayer_game();
@ -122,6 +123,8 @@ public:
private:
/** Display the load-game dialog. */
void show_dialog(bool show_replay, bool cancel_orders);
/** Display the difficulty dialog. */
void show_difficulty_dialog();
/** Check if the version of the savefile is compatible with the current version. */
void check_version_compatibility();
/** Copy era information into the snapshot. */