The Battle for Wesnoth  1.17.14+dev
preferences_dialog.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2022
3  by Charles Dang <exodia339gmail.com>
4  Copyright (C) 2011, 2015 by Iris Morelle <shadowm2006@gmail.com>
5  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY.
13 
14  See the COPYING file for more details.
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 private:
78  virtual const std::string& window_id() const override;
79 
80  virtual void pre_show(window& window) override;
81  virtual void post_show(window& /*window*/) override;
82 
83  /** Initializers */
84  void initialize_callbacks();
85  void initialize_tabs(listbox& selector);
86  void set_resolution_list(menu_button& res_list);
87  listbox& setup_hotkey_list();
88 
89  template<bool(*toggle_getter)(), bool(*toggle_setter)(bool), int(*vol_getter)(), void(*vol_setter)(int)>
90  void initialize_sound_option_group(const std::string& id_suffix);
91 
92  void apply_pixel_scale();
93 
94  widget_data 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();
116 
118 
120 
121  std::vector<point> resolutions_;
122 
124 
125  std::vector<double> accl_speeds_;
126 
127  std::vector<const hotkey::hotkey_command*> visible_hotkeys_;
128 
129  std::set<hotkey::HOTKEY_CATEGORY> visible_categories_;
130 
131  // The page/tab index pairs for setting visible pages
132  const std::pair<int, int>& initial_index_;
133 };
134 
135 } // namespace dialogs
136 } // namespace gui2
const preferences::advanced_pref_list & adv_preferences_
A menu_button is a styled_widget to choose an element from a list of elements.
Definition: menu_button.hpp:61
std::vector< const hotkey::hotkey_command * > visible_hotkeys_
std::vector< advanced_manager::option > advanced_pref_list
Definition: advanced.hpp:69
Definitions for the interface to Wesnoth Markup Language (WML).
const std::pair< int, int > & initial_index_
Keyboard shortcuts for game actions.
Class for a single line text area.
Definition: text_box.hpp:141
Generic file dialog.
The listbox class.
Definition: listbox.hpp:45
bool is_friend(const std::string &nick)
Definition: game.cpp:264
Modify, read and display user preferences.
Various uncategorised dialogs.
std::set< hotkey::HOTKEY_CATEGORY > visible_categories_
Holds a 2D point.
Definition: point.hpp:24
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...
group< preferences::lobby_joins > lobby_joins_group
Abstract base class for all modal dialogs.
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:35
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:66