The Battle for Wesnoth  1.15.2+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 // This file is not named preferences.hpp in order -I conflicts with
29 // src/preferences.hpp.
30 
31 namespace hotkey {
32  struct hotkey_command;
33 }
34 
35 struct point;
36 
37 namespace preferences {
41  };
42 
43  /**
44  * Map containing page mappings that can be used to set the initially displayed page
45  * of the dialog. The pair is in an 0-indexed toplevel stack/substack format, where
46  * the first is the list of main Preference categories (such as General and Display)
47  * and the second is any sub-stack found on that page.
48  *
49  * TODO: this isn't the most optimal solution, since if the order or number of pages
50  * in either stack changes, this map needs to be updated. Optimally the stacked_widget
51  * widget would allow specifying page by string id, but that would require changes to
52  * generator. It's something to look into, however.
53  */
54  static std::map<PREFERENCE_VIEW, std::pair<int,int>> pef_view_map {
55  {VIEW_DEFAULT, {0,0}},
56  {VIEW_FRIENDS, {4,1}}
57  };
58 }
59 
60 namespace gui2
61 {
62 
63 class listbox;
64 class menu_button;
65 class slider;
66 class text_box;
67 
68 namespace dialogs
69 {
70 
72 {
73 public:
75 
76  /** The display function -- see @ref modal_dialog for more information. */
77  static void display(const config& game_cfg, const preferences::PREFERENCE_VIEW initial_view = preferences::VIEW_DEFAULT)
78  {
79  preferences_dialog(game_cfg, initial_view).show();
80  }
81 
82  typedef std::vector<const hotkey::hotkey_command*> visible_hotkeys_t;
83 
84 private:
85  /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
86  virtual const std::string& window_id() const override;
87 
88  /** Inherited from modal_dialog. */
89  virtual void post_build(window& window) override;
90  virtual void pre_show(window& window) override;
91  virtual void post_show(window& /*window*/) override;
92 
93  /** Initializers */
94  void initialize_tabs(window& window, listbox& selector);
95  void set_resolution_list(menu_button& res_list, CVideo& video);
96  listbox& setup_hotkey_list(window& window);
97 
98  template<bool(*toggle_getter)(), bool(*toggle_setter)(bool), int(*vol_getter)(), void(*vol_setter)(int)>
99  void initialize_sound_option_group(const std::string& id_suffix);
100 
101  std::map<std::string, string_map> get_friends_list_row_data(const preferences::acquaintance& entry);
102 
103  void add_friend_list_entry(const bool is_friend, text_box& textbox, window& window);
104  void remove_friend_list_entry(listbox& friends_list, text_box& textbox, window& window);
105 
106  void on_friends_list_select(listbox& list, text_box& textbox);
107  void update_friends_list_controls(window& window, listbox& list);
108 
109  void set_visible_page(window& window, unsigned int page, const std::string& pager_id);
110 
111  /** Callback for selection changes */
112  void on_page_select(window& window);
113  void on_tab_select(window& window);
114  void on_advanced_prefs_list_select(listbox& tree);
115  void on_filtertext_changed(text_box_base* textbox);
116 
117  /** Special callback functions */
118  void handle_res_select(window& window);
119  void fullscreen_toggle_callback(window& window);
120  void add_hotkey_callback(listbox& hotkeys);
121  void remove_hotkey_callback(listbox& hotkeys);
122  void default_hotkey_callback(window& window);
123  void hotkey_filter_callback(window& window) const;
124 
126 
127  MAKE_ENUM(ADVANCED_PREF_TYPE,
128  (TOGGLE, "boolean")
129  (SLIDER, "int")
130  (COMBO, "combo")
131  (SPECIAL, "custom")
132  )
133 
134  std::vector<point> resolutions_;
135  std::vector<config> adv_preferences_cfg_;
136 
137  int last_selected_item_;
138 
139  std::vector<double> accl_speeds_;
140  visible_hotkeys_t visible_hotkeys_;
141 
142  std::map<hotkey::HOTKEY_CATEGORY, t_string> cat_names_;
143 
144  // The page/tab index pairs for setting visible pages
145  const std::pair<int, int>& initial_index_;
146 };
147 
148 } // namespace dialogs
149 } // 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.
const config * game_cfg
Definition: help_impl.cpp:66
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:303
Modify, read and display user preferences.
std::vector< const hotkey::hotkey_command * > visible_hotkeys_t
Various uncategorised dialogs.
static void display(const config &game_cfg, const preferences::PREFERENCE_VIEW initial_view=preferences::VIEW_DEFAULT)
The display function – see modal_dialog for more information.
Holds a 2D point.
Definition: point.hpp:23
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:913
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