The Battle for Wesnoth  1.15.5+dev
preferences_dialog.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011, 2015 by Iris Morelle <shadowm2006@gmail.com>
3  Copyright (C) 2016 - 2018 by Charles Dang <exodia339gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "config.hpp"
20 #include "gui/widgets/group.hpp"
21 #include "gui/widgets/text_box.hpp"
23 #include "preferences/game.hpp"
24 #include "utils/make_enum.hpp"
25 
26 #include <boost/dynamic_bitset.hpp>
27 
28 class game_config_view;
29 // This file is not named preferences.hpp in order -I conflicts with
30 // src/preferences.hpp.
31 
32 namespace hotkey {
33  struct hotkey_command;
34 }
35 
36 struct point;
37 
38 namespace preferences {
42  };
43 
44  /**
45  * Map containing page mappings that can be used to set the initially displayed page
46  * of the dialog. The pair is in an 0-indexed toplevel stack/substack format, where
47  * the first is the list of main Preference categories (such as General and Display)
48  * and the second is any sub-stack found on that page.
49  *
50  * TODO: this isn't the most optimal solution, since if the order or number of pages
51  * in either stack changes, this map needs to be updated. Optimally the stacked_widget
52  * widget would allow specifying page by string id, but that would require changes to
53  * generator. It's something to look into, however.
54  */
55  static std::map<PREFERENCE_VIEW, std::pair<int,int>> pef_view_map {
56  {VIEW_DEFAULT, {0,0}},
57  {VIEW_FRIENDS, {4,1}}
58  };
59 }
60 
61 namespace gui2
62 {
63 
64 class listbox;
65 class menu_button;
66 class slider;
67 class text_box;
68 
69 namespace dialogs
70 {
71 
73 {
74 public:
76 
77  /** The display function -- see @ref modal_dialog for more information. */
78  static void display(const game_config_view& game_cfg, const preferences::PREFERENCE_VIEW initial_view = preferences::VIEW_DEFAULT)
79  {
80  preferences_dialog(game_cfg, initial_view).show();
81  }
82 
83  typedef std::vector<const hotkey::hotkey_command*> visible_hotkeys_t;
84 
85 private:
86  /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
87  virtual const std::string& window_id() const override;
88 
89  /** Inherited from modal_dialog. */
90  virtual void post_build(window& window) override;
91  virtual void pre_show(window& window) override;
92  virtual void post_show(window& /*window*/) override;
93 
94  /** Initializers */
95  void initialize_tabs(window& window, listbox& selector);
96  void set_resolution_list(menu_button& res_list, CVideo& video);
97  listbox& setup_hotkey_list(window& window);
98 
99  template<bool(*toggle_getter)(), bool(*toggle_setter)(bool), int(*vol_getter)(), void(*vol_setter)(int)>
100  void initialize_sound_option_group(const std::string& id_suffix);
101 
102  std::map<std::string, string_map> get_friends_list_row_data(const preferences::acquaintance& entry);
103 
104  void add_friend_list_entry(const bool is_friend, text_box& textbox, window& window);
105  void remove_friend_list_entry(listbox& friends_list, text_box& textbox, window& window);
106 
107  void on_friends_list_select(listbox& list, text_box& textbox);
108  void update_friends_list_controls(window& window, listbox& list);
109 
110  void set_visible_page(window& window, unsigned int page, const std::string& pager_id);
111 
112  /** Callback for selection changes */
113  void on_page_select(window& window);
114  void on_tab_select(window& window);
115  void on_advanced_prefs_list_select(listbox& tree);
116  void on_filtertext_changed(text_box_base* textbox);
117 
118  /** Special callback functions */
119  void handle_res_select(window& window);
120  void fullscreen_toggle_callback(window& window);
121  void add_hotkey_callback(listbox& hotkeys);
122  void remove_hotkey_callback(listbox& hotkeys);
123  void default_hotkey_callback(window& window);
124  void hotkey_filter_callback(window& window) const;
125 
127 
128  MAKE_ENUM(ADVANCED_PREF_TYPE,
129  (TOGGLE, "boolean")
130  (SLIDER, "int")
131  (COMBO, "combo")
132  (SPECIAL, "custom")
133  )
134 
135  std::vector<point> resolutions_;
136  std::vector<config> adv_preferences_cfg_;
137 
138  int last_selected_item_;
139 
140  std::vector<double> accl_speeds_;
141  visible_hotkeys_t visible_hotkeys_;
142 
143  std::map<hotkey::HOTKEY_CATEGORY, t_string> cat_names_;
144 
145  // The page/tab index pairs for setting visible pages
146  const std::pair<int, int>& initial_index_;
147 };
148 
149 } // namespace dialogs
150 } // namespace gui2
Abstract base class for text items.
Simple push button.
Definition: menu_button.hpp:41
Definition: video.hpp:31
STL namespace.
bool show(const unsigned auto_close_time=0)
Shows the window.
Definitions for the interface to Wesnoth Markup Language (WML).
Keyboard shortcuts for game actions.
Class for a single line text area.
Definition: text_box.hpp:121
Generic file dialog.
Definition: field-fwd.hpp:22
The listbox class.
Definition: listbox.hpp:40
bool is_friend(const std::string &nick)
Definition: game.cpp:302
Modify, read and display user preferences.
std::vector< const hotkey::hotkey_command * > visible_hotkeys_t
Various uncategorised dialogs.
Holds a 2D point.
Definition: point.hpp:23
const game_config_view * game_cfg
Definition: help_impl.cpp:67
static std::map< PREFERENCE_VIEW, std::pair< int, int > > pef_view_map
Map containing page mappings that can be used to set the initially displayed page of the dialog...
MAKE_ENUM(ALIGNMENT_FEMALE_VARIATION,(LAWFUL, N_("female^lawful"))(FEMALE_NEUTRAL, N_("female^neutral"))(CHAOTIC, N_("female^chaotic"))(LIMINAL, N_("female^liminal"))) std
Implementation detail of unit_type::alignment_description.
Definition: types.cpp:808
static void display(const game_config_view &game_cfg, const preferences::PREFERENCE_VIEW initial_view=preferences::VIEW_DEFAULT)
The display function – see modal_dialog for more information.
Abstract base class for all modal dialogs.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
Defines the MAKE_ENUM macro.
group< preferences::LOBBY_JOINS > lobby_joins_group