The Battle for Wesnoth  1.15.12+dev
sp_options_configure.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by the Battle for Wesnoth Project https://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #pragma once
15 
19 
22 
23 namespace gui2::dialogs
24 {
25 
27 {
28 public:
29  sp_options_configure(ng::create_engine& create_engine, ng::configure_engine& config_engine);
30 
31  /**
32  * Execute function. We only want to show the dialog if the campaign has options or if
33  * there are active mods and at least one of those mods has custom options.
34  */
35  static bool execute(ng::create_engine& create_engine, ng::configure_engine& config_engine)
36  {
37  // Check campaign options.
38  const auto& campaign_mods = create_engine.current_level().data().child_range("options");
39 
40  const bool have_campaign_options = std::any_of(campaign_mods.begin(), campaign_mods.end(), [](config& mod) {
41  return !mod.empty();
42  });
43 
44  // Check active mod options.
45  bool have_mod_options = false;
46 
47  for(const auto& mod : create_engine.active_mods_data()) {
48  if(!(*mod->cfg).has_child("options")) {
49  continue;
50  }
51 
52  const auto& opt_range = (*mod->cfg).child_range("options");
53 
54  if(std::any_of(opt_range.begin(), opt_range.end(), [](const config& options) {
55  return !options.empty();
56  })) {
57  have_mod_options = true;
58  break;
59  }
60  }
61 
62  // If we have no valid options whatsoever, just bypass this dialog.
63  if(!have_campaign_options && !have_mod_options) {
64  return true;
65  }
66 
67  return sp_options_configure(create_engine, config_engine).show();
68  }
69 
70 private:
71  virtual const std::string& window_id() const override;
72 
73  virtual void pre_show(window& window) override;
74 
75  virtual void post_show(window& window) override;
76 
79 
80  std::unique_ptr<mp_options_helper> options_manager_;
81 };
82 
83 } // namespace dialogs
configure_engine
sp_options_configure(ng::create_engine &create_engine, ng::configure_engine &config_engine)
child_itors child_range(config_key_type key)
Definition: config.cpp:356
const config & data() const
std::vector< extras_metadata_ptr > active_mods_data()
const config & options()
Definition: game.cpp:563
std::unique_ptr< mp_options_helper > options_manager_
static bool execute(ng::create_engine &create_engine, ng::configure_engine &config_engine)
Execute function.
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
level & current_level() const
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
virtual const std::string & window_id() const override
The id of the window to build.
Abstract base class for all modal dialogs.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:64
bool empty() const
Definition: config.cpp:916