Skip to content

Commit

Permalink
Attempt to fix bugs #25524 and #25525
Browse files Browse the repository at this point in the history
In order to fix use_map_settings not being set, we create a configure_engine object in the sp game setup
and pass it to the sp options dialog.

I also added checks for the presence of [options] tags in [campaign], as well as check to ensure empty tags
don't cause the dialog to show.

@gfgtdf please confirm fix
  • Loading branch information
Vultraz committed Feb 20, 2017
1 parent d46d8c3 commit de8e322
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
9 changes: 8 additions & 1 deletion src/game_initialization/singleplayer.cpp
Expand Up @@ -119,7 +119,14 @@ bool enter_create_mode(CVideo& video, const config& game_config, saved_game& sta

bool enter_configure_mode(CVideo& video, const config& game_config, saved_game& state, ng::create_engine& create_eng, bool local_players_only)
{
if(!gui2::dialogs::sp_options_configure::execute(create_eng, video)) {
// We create the config engine here in order to ensure values like use_map_settings are set correctly
// TODO: should this be passed to this function instead of created here?
ng::configure_engine config_eng(create_eng.get_state());

// TODO: needed?
config_eng.update_initial_cfg(create_eng.current_level().data());

if(!gui2::dialogs::sp_options_configure::execute(create_eng, config_eng, video)) {
return false;
}

Expand Down
9 changes: 3 additions & 6 deletions src/gui/dialogs/sp_options_configure.cpp
Expand Up @@ -24,15 +24,12 @@ namespace dialogs

REGISTER_DIALOG(sp_options_configure)

sp_options_configure::sp_options_configure(ng::create_engine& create_engine)
sp_options_configure::sp_options_configure(ng::create_engine& create_engine, ng::configure_engine& config_engine)
: create_engine_(create_engine)
, config_engine_()
, config_engine_(config_engine)
, options_manager_()
{
set_restore(true);

config_engine_.reset(new ng::configure_engine(create_engine_.get_state()));
config_engine_->update_initial_cfg(create_engine_.current_level().data());
}

void sp_options_configure::pre_show(window& window)
Expand All @@ -44,7 +41,7 @@ void sp_options_configure::pre_show(window& window)
void sp_options_configure::post_show(window& window)
{
if(window.get_retval() == window::OK) {
config_engine_->set_options(options_manager_->get_options_config());
config_engine_.set_options(options_manager_->get_options_config());
}
}

Expand Down
51 changes: 34 additions & 17 deletions src/gui/dialogs/sp_options_configure.hpp
Expand Up @@ -29,29 +29,45 @@ namespace dialogs
class sp_options_configure : public modal_dialog, private plugin_executor
{
public:
explicit sp_options_configure(ng::create_engine& create_engine);
sp_options_configure(ng::create_engine& create_engine, ng::configure_engine& config_engine);

/**
* Execute function. We only want to show the dialog if there are active mods and
* those active mods all have custom options.
* Execute function. We only want to show the dialog if the campaign has options or if
* there are active mods and at least one of those mods has custom options.
*/
static bool execute(ng::create_engine& create_engine, CVideo& video)
static bool execute(ng::create_engine& create_engine, ng::configure_engine& config_engine, CVideo& video)
{
using mod_type = ng::create_engine::extras_metadata_ptr;

const std::vector<mod_type>& activemods = create_engine.active_mods_data();
// FIXME: this code is wrogn in multiple ways:
// 1) It only searches in modifications but [olptions] can also appear in [campaign]
// 2) It also triggers on empty [options] which it shouldn't
if(std::none_of(activemods.begin(), activemods.end(), [](mod_type mod) {
return (*mod->cfg).has_child("options");
})) {
//FIXME: in this case no configure_engine::set_use_map_settings(use_map_settings_default()); was not called
// so that mp_game_settings::use_map_settings has a wrong value so that the connect engine will mess up the scenarios settings
// Check campaign options.
const auto& campaign_mods = create_engine.current_level().data().child_range("options");

const bool have_campaign_options = std::any_of(campaign_mods.begin(), campaign_mods.end(), [](config& mod) {
return !mod.empty();
});

// Check active mod options.
bool have_mod_options = false;

for(const auto& mod : create_engine.active_mods_data()) {
if(!(*mod->cfg).has_child("options")) {
continue;
}

const auto& opt_range = (*mod->cfg).child_range("options");

if(std::any_of(opt_range.begin(), opt_range.end(), [](const config& options) {
return !options.empty();
})) {
have_mod_options = true;
break;
}
}

// If we have no valid options whatsoever, just bypass this dialog.
if(!have_campaign_options && !have_mod_options) {
return true;
}

return sp_options_configure(create_engine).show(video);
return sp_options_configure(create_engine, config_engine).show(video);
}

private:
Expand All @@ -65,7 +81,8 @@ class sp_options_configure : public modal_dialog, private plugin_executor
void post_show(window& window);

ng::create_engine& create_engine_;
std::unique_ptr<ng::configure_engine> config_engine_;
ng::configure_engine& config_engine_;

std::unique_ptr<mp_options_helper> options_manager_;
};

Expand Down

0 comments on commit de8e322

Please sign in to comment.