The Battle for Wesnoth  1.17.17+dev
mp_options_helper.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2023
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 class config;
21 
22 namespace gui2
23 {
24 
25 class styled_widget;
26 class menu_button;
27 class toggle_button;
28 class tree_view;
29 class tree_view_node;
30 class window;
31 
32 namespace dialogs
33 {
34 
36 {
37 public:
39 
40  void update_all_options();
41 
42  void update_game_options();
43  void update_era_options();
44  void update_mod_options();
45 
47 
48 private:
50  {
51  std::string level_type;
52  std::string id;
53 
54  friend bool operator<(const option_source& a, const option_source& b)
55  {
56  return std::tie(a.level_type, a.id) < std::tie(b.level_type, b.id);
57  }
58  };
59 
60  int remove_nodes_for_type(const std::string& type);
61 
63 
64  template <typename T>
65  std::pair<T*, config::attribute_value> add_node_and_get_widget(
66  tree_view_node& option_node, const std::string& id, data_map& data, const config& cfg);
67 
68  void display_custom_options(const std::string& type, int node_position, const config& data);
69 
70  template<typename T>
71  void update_options_data_map(T* widget, const option_source& source);
73 
74  // NOTE: this cannot be an overload of update_options_data_map since that's a templated function
76 
77  void reset_options_data(const option_source& source, bool& handled, bool& halt);
78 
79  void update_status_label();
80 
82 
85 
86  using node_vector = std::vector<tree_view_node*>;
87 
89  {
91 
93  int position;
94 
95  bool operator<(const type_node_data& data) {
96  return (*this).position < data.position;
97  }
98  };
99 
100  std::map<std::string, type_node_data> node_data_map_;
101 
102  std::vector<option_source> visible_options_;
103  std::map<std::string, config> options_data_;
104 };
105 
106 } // namespace dialogs
107 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:161
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)
A menu_button is a styled_widget to choose an element from a list of elements.
Definition: menu_button.hpp:62
Base class for all visible items.
Class for a toggle button.
A tree view is a control that holds several items of the same or different types.
Definition: tree_view.hpp:61
Base class for all widgets.
Definition: widget.hpp:54
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:67
Various uncategorised dialogs.
Generic file dialog.
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:35
std::string_view data
Definition: picture.cpp:199
friend bool operator<(const option_source &a, const option_source &b)
#define a
#define b