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