The Battle for Wesnoth  1.15.1+dev
mp_options_helper.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 
18 
19 class config;
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 
61  using data_map = std::map<std::string, string_map>;
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  {
89  type_node_data() : nodes(), position(-1) {}
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
std::map< std::string, config > options_data_
void update_options_data_map(T *widget, const option_source &source)
const std::vector< node > & nodes
Simple push button.
Definition: menu_button.hpp:41
#define a
Base class for all widgets.
Definition: widget.hpp:47
void display_custom_options(const std::string &type, int node_position, const config &data)
std::vector< option_source > visible_options_
Generic file dialog.
Definition: field-fwd.hpp:22
void update_options_data_map_menu_button(menu_button *widget, const option_source &source, const config &cfg)
#define b
std::map< std::string, string_map > data_map
void reset_options_data(const option_source &source, bool &handled, bool &halt)
Various uncategorised dialogs.
std::map< std::string, type_node_data > node_data_map_
Base class for all visible items.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
std::vector< tree_view_node * > node_vector
int remove_nodes_for_type(const std::string &type)
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:63
mp_options_helper(window &window, ng::create_engine &create_engine)
friend bool operator<(const option_source &a, const option_source &b)
Class for a toggle button.
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)