The Battle for Wesnoth  1.19.10+dev
sp_options_configure.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2025
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 
22 
23 namespace gui2::dialogs
24 {
25 
27 {
28 public:
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)
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).show();
68  }
69 
70 private:
71  virtual const std::string& window_id() const override;
72 
73  virtual void pre_show() override;
74 
75  virtual void post_show() override;
76 
78 
79  std::unique_ptr<mp_options_helper> options_manager_;
80 };
81 
82 } // namespace dialogs
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:158
child_itors child_range(config_key_type key)
Definition: config.cpp:268
Abstract base class for all modal dialogs.
virtual const std::string & window_id() const override
The ID of the window to build.
sp_options_configure(ng::create_engine &create_engine)
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_
static bool execute(ng::create_engine &create_engine)
Execute function.
std::vector< extras_metadata_ptr > active_mods_data()
level & current_level() const
const config & data() const