The Battle for Wesnoth  1.19.7+dev
mp_options_helper.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 
19 
20 
21 namespace gui2
22 {
23 
24 class styled_widget;
25 class menu_button;
26 class toggle_button;
27 class tree_view;
28 class tree_view_node;
29 class window;
30 
31 namespace dialogs
32 {
33 
35 {
36 public:
38 
39  void update_all_options();
40 
41  void update_game_options();
42  void update_era_options();
43  void update_mod_options();
44 
46 
47 private:
49  {
50  std::string level_type;
51  std::string id;
52 
53  friend bool operator<(const option_source& a, const option_source& b)
54  {
55  return std::tie(a.level_type, a.id) < std::tie(b.level_type, b.id);
56  }
57  };
58 
59  int remove_nodes_for_type(const std::string& type);
60 
62 
63  template <typename T>
64  std::pair<T*, config::attribute_value> add_node_and_get_widget(
65  tree_view_node& option_node, const std::string& id, data_map& data, const config& cfg);
66 
67  void display_custom_options(const std::string& type, int node_position, const config& data);
68 
69  template<typename T>
70  void update_options_data_map(T* widget, const option_source& source);
72 
73  // NOTE: this cannot be an overload of update_options_data_map since that's a templated function
75 
76  void reset_options_data(const option_source& source, bool& handled, bool& halt);
77 
78  void update_status_label();
79 
81 
84 
85  using node_vector = std::vector<tree_view_node*>;
86 
88  {
90 
92  int position;
93 
94  bool operator<(const type_node_data& data) {
95  return (*this).position < data.position;
96  }
97  };
98 
99  std::map<std::string, type_node_data> node_data_map_;
100 
101  std::vector<option_source> visible_options_;
102  std::map<std::string, config> options_data_;
103 };
104 
105 } // namespace dialogs
106 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
std::map< std::string, config > options_data_
void reset_options_data(const option_source &source, bool &handled, bool &halt)
mp_options_helper(window &window, ng::create_engine &create_engine)
void update_options_data_map(toggle_button *widget, const option_source &source)
void update_options_data_map_menu_button(menu_button *widget, const option_source &source, const config &cfg)
void display_custom_options(const std::string &type, int node_position, const config &data)
std::map< std::string, type_node_data > node_data_map_
std::vector< tree_view_node * > node_vector
std::pair< T *, config::attribute_value > add_node_and_get_widget(tree_view_node &option_node, const std::string &id, data_map &data, const config &cfg)
std::vector< option_source > visible_options_
int remove_nodes_for_type(const std::string &type)
void update_options_data_map(T *widget, const option_source &source)
Base class for all widgets.
Definition: widget.hpp:55
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:61
Various uncategorised dialogs.
Generic file dialog.
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:36
std::string_view data
Definition: picture.cpp:178
friend bool operator<(const option_source &a, const option_source &b)
#define b