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