Skip to content

Commit

Permalink
Pass savegame summary config to loadgame class
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Feb 29, 2016
1 parent 032ab45 commit fb904c6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
18 changes: 9 additions & 9 deletions src/gui/dialogs/game_load.cpp
Expand Up @@ -40,17 +40,12 @@
#include "gui/widgets/window.hpp"
#include "language.hpp"
#include "preferences_display.hpp"
#include "savegame.hpp"
#include "utils/foreach.tpp"

#include <cctype>
#include <boost/bind.hpp>

/* Helper function for determining if the selected save is a replay */
static bool is_replay_save(const config& cfg)
{
return cfg["replay"].to_bool() && !cfg["snapshot"].to_bool(true);
}

namespace gui2
{

Expand Down Expand Up @@ -105,6 +100,7 @@ tgame_load::tgame_load(const config& cache_config)
, games_()
, cache_config_(cache_config)
, last_words_()
, summary_()
{
}

Expand Down Expand Up @@ -251,9 +247,13 @@ bool tgame_load::filter_text_changed(ttext_* textbox, const std::string& text)

void tgame_load::post_show(twindow& window)
{
const int index =
find_widget<tlistbox>(&window, "savegame_list", false).get_selected_row();

change_difficulty_ = chk_change_difficulty_->get_widget_value(window);
show_replay_ = chk_show_replay_->get_widget_value(window);
cancel_orders_ = chk_cancel_orders_->get_widget_value(window);
summary_ = games_[index].summary();
}

void tgame_load::display_savegame(twindow& window)
Expand Down Expand Up @@ -290,13 +290,13 @@ void tgame_load::display_savegame(twindow& window)
ttoggle_button& cancel_orders_toggle =
find_widget<ttoggle_button>(&window, "cancel_orders", false);

const bool is_replay = is_replay_save(summary);
const bool is_replay = savegame::loadgame::is_replay_save(summary);
const bool is_scenario_start = summary["turn"].empty();

// Always toggle show_replay on if the save is a replay
replay_toggle.set_value(is_replay);
replay_toggle.set_active(!is_replay && !is_scenario_start);

// Cancel orders doesnt make sense on replay saves or start-of-scenario saves.
cancel_orders_toggle.set_active(!is_replay && !is_scenario_start);

Expand Down Expand Up @@ -366,7 +366,7 @@ void tgame_load::evaluate_summary_string(std::stringstream& str,

str << "\n";

if(is_replay_save(cfg_summary)) {
if(savegame::loadgame::is_replay_save(cfg_summary)) {
str << _("Replay");
} else if(!cfg_summary["turn"].empty()) {
str << _("Turn") << " " << cfg_summary["turn"];
Expand Down
6 changes: 6 additions & 0 deletions src/gui/dialogs/game_load.hpp
Expand Up @@ -45,6 +45,10 @@ class tgame_load : public tdialog
{
return cancel_orders_;
}
const config& summary()
{
return summary_;
}

protected:
/** Inherited from tdialog. */
Expand Down Expand Up @@ -87,6 +91,8 @@ class tgame_load : public tdialog
const config& cache_config_;

std::vector<std::string> last_words_;

config summary_;
};
}

Expand Down
12 changes: 5 additions & 7 deletions src/savegame.cpp
Expand Up @@ -93,6 +93,7 @@ loadgame::loadgame(CVideo& video, const config& game_config, saved_game& gamesta
, show_replay_(false)
, cancel_orders_(false)
, select_difficulty_(false)
, summary_()
{}

void loadgame::show_dialog()
Expand All @@ -114,21 +115,18 @@ void loadgame::show_dialog()
filename_ = load_dialog.filename();
show_replay_ = load_dialog.show_replay();
cancel_orders_ = load_dialog.cancel_orders();

summary_ = load_dialog.summary();
}
}

void loadgame::show_difficulty_dialog()
{
create_save_info creator;
save_info info = creator(filename_);
const config& cfg_summary = info.summary();

if ( cfg_summary["corrupt"].to_bool() || (cfg_summary["replay"].to_bool() && !cfg_summary["snapshot"].to_bool(true))
|| (!cfg_summary["turn"].empty()) ) {
if(summary_["corrupt"].to_bool() || (is_replay_save(summary_)) || (!summary_["turn"].empty())) {
return;
}

std::string campaign_id = cfg_summary["campaign"];
std::string campaign_id = summary_["campaign"];

BOOST_FOREACH(const config &campaign, game_config_.child_range("campaign"))
{
Expand Down
6 changes: 6 additions & 0 deletions src/savegame.hpp
Expand Up @@ -65,6 +65,11 @@ class loadgame
/** GUI Dialog sequence which confirms attempts to load saves from previous game versions. */
static bool check_version_compatibility(const version_info & version, CVideo & video);

static bool is_replay_save(const config& cfg)
{
return cfg["replay"].to_bool() && !cfg["snapshot"].to_bool(true);
}

private:
/** Display the load-game dialog. */
void show_dialog();
Expand All @@ -85,6 +90,7 @@ class loadgame
bool show_replay_; /** State of the "show_replay" checkbox in the load-game dialog. */
bool cancel_orders_; /** State of the "cancel_orders" checkbox in the load-game dialog. */
bool select_difficulty_; /** State of the "change_difficulty" checkbox in the load-game dialog. */
config summary_; /** Summary config of the save selected in the load game dialog. */
};

/**
Expand Down

0 comments on commit fb904c6

Please sign in to comment.