The Battle for Wesnoth  1.15.9+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/advanced.hpp"
24 #include "preferences/game.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. */
78 
79  typedef std::vector<const hotkey::hotkey_command*> visible_hotkeys_t;
80 
81 private:
82  /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
83  virtual const std::string& window_id() const override;
84 
85  /** Inherited from modal_dialog. */
86  virtual void post_build(window& window) override;
87  virtual void pre_show(window& window) override;
88  virtual void post_show(window& /*window*/) override;
89 
90  /** Initializers */
91  void initialize_tabs(listbox& selector);
92  void set_resolution_list(menu_button& res_list);
93  listbox& setup_hotkey_list();
94 
95  template<bool(*toggle_getter)(), bool(*toggle_setter)(bool), int(*vol_getter)(), void(*vol_setter)(int)>
96  void initialize_sound_option_group(const std::string& id_suffix);
97 
98  std::map<std::string, string_map> get_friends_list_row_data(const preferences::acquaintance& entry);
99 
100  void add_friend_list_entry(const bool is_friend, text_box& textbox);
101  void remove_friend_list_entry(listbox& friends_list, text_box& textbox);
102 
103  void on_friends_list_select(listbox& list, text_box& textbox);
104  void update_friends_list_controls(listbox& list);
105 
106  void set_visible_page(unsigned int page, const std::string& pager_id);
107 
108  /** Callback for selection changes */
109  void on_page_select();
110  void on_tab_select();
111  void on_advanced_prefs_list_select(listbox& tree);
112 
113  /** Special callback functions */
114  void handle_res_select();
115  void fullscreen_toggle_callback();
116  void add_hotkey_callback(listbox& hotkeys);
117  void remove_hotkey_callback(listbox& hotkeys);
118  void default_hotkey_callback();
119  void hotkey_filter_callback() const;
120 
121  group<preferences::LOBBY_JOINS> lobby_joins_group;
122 
123  const preferences::advanced_pref_list& adv_preferences_;
124 
125  std::vector<point> resolutions_;
126 
127  int last_selected_item_;
128 
129  std::vector<double> accl_speeds_;
130  visible_hotkeys_t visible_hotkeys_;
131 
132  std::map<hotkey::HOTKEY_CATEGORY, t_string> cat_names_;
133 
134  // The page/tab index pairs for setting visible pages
135  const std::pair<int, int>& initial_index_;
136 };
137 
138 } // namespace dialogs
139 } // namespace gui2
A menu_button is a styled_widget to choose an element from a list of elements.
Definition: menu_button.hpp:64
STL namespace.
std::vector< advanced_manager::option > advanced_pref_list
Definition: advanced.hpp:68
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:140
Generic file dialog.
Definition: field-fwd.hpp:22
The listbox class.
Definition: listbox.hpp:42
bool is_friend(const std::string &nick)
Definition: game.cpp:272
Modify, read and display user preferences.
std::vector< const hotkey::hotkey_command * > visible_hotkeys_t
The display function – see modal_dialog for more information.
Various uncategorised dialogs.
std::map< std::string, t_string > string_map
Definition: widget.hpp:26
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...
Abstract base class for all modal dialogs.
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:64