The Battle for Wesnoth  1.19.0-dev
preferences_dialog.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2024
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 
19 #include "gui/widgets/group.hpp"
21 #include "preferences/advanced.hpp"
22 #include "preferences/game.hpp"
23 #include "theme.hpp"
24 
25 // This file is not named preferences.hpp in order -I conflicts with
26 // src/preferences.hpp.
27 
28 //struct theme_info;
29 
30 namespace preferences {
34  };
35 
36  /**
37  * Map containing page mappings that can be used to set the initially displayed page
38  * of the dialog. The pair is in an 0-indexed toplevel stack/substack format, where
39  * the first is the list of main Preference categories (such as General and Display)
40  * and the second is any sub-stack found on that page.
41  *
42  * TODO: this isn't the most optimal solution, since if the order or number of pages
43  * in either stack changes, this map needs to be updated. Optimally the stacked_widget
44  * widget would allow specifying page by string id, but that would require changes to
45  * generator. It's something to look into, however.
46  */
47  static std::map<PREFERENCE_VIEW, std::pair<int,int>> pef_view_map {
48  {VIEW_DEFAULT, {0,0}},
49  {VIEW_FRIENDS, {4,1}}
50  };
51 }
52 
53 namespace gui2
54 {
55 
56 class listbox;
57 class menu_button;
58 class text_box;
59 
60 namespace dialogs
61 {
62 
64 {
65 public:
67 
68  /** The display function -- see @ref modal_dialog for more information. */
70 
71 private:
72  virtual const std::string& window_id() const override;
73 
74  virtual void pre_show(window& window) override;
75  virtual void post_show(window& /*window*/) override;
76 
77  /** Initializers */
78  void initialize_callbacks();
79  void initialize_tabs(listbox& selector);
80  void set_resolution_list(menu_button& res_list);
83 
84  template<bool(*toggle_getter)(), bool(*toggle_setter)(bool), int(*vol_getter)(), void(*vol_setter)(int)>
85  void initialize_sound_option_group(const std::string& id_suffix);
86 
87  void apply_pixel_scale();
88 
90 
91  void add_friend_list_entry(const bool is_friend, text_box& textbox);
92  void remove_friend_list_entry(listbox& friends_list, text_box& textbox);
93 
94  void on_friends_list_select(listbox& list, text_box& textbox);
96 
97  void set_visible_page(unsigned int page, const std::string& pager_id);
98 
99  /** Callback for selection changes */
100  void on_page_select();
101  void on_tab_select();
103 
104  /** Special callback functions */
105  void handle_res_select();
106  void handle_theme_select();
108  void add_hotkey_callback(listbox& hotkeys);
109  void remove_hotkey_callback(listbox& hotkeys);
111  void hotkey_filter_callback();
112 
114 
116 
117  std::vector<point> resolutions_;
118  std::vector<theme_info> themes_;
119 
121 
122  std::vector<double> accl_speeds_;
123 
124  std::vector<const hotkey::hotkey_command*> visible_hotkeys_;
125 
126  std::set<hotkey::HOTKEY_CATEGORY> visible_categories_;
127 
128  // The page/tab index pairs for setting visible pages
129  const std::pair<int, int>& initial_index_;
130 };
131 
132 } // namespace dialogs
133 } // namespace gui2
Abstract base class for all modal dialogs.
void set_visible_page(unsigned int page, const std::string &pager_id)
void set_theme_list(menu_button &theme_list)
void remove_hotkey_callback(listbox &hotkeys)
const std::pair< int, int > & initial_index_
virtual void post_show(window &) override
Actions to be taken after the window has been shown.
void set_resolution_list(menu_button &res_list)
void on_advanced_prefs_list_select(listbox &tree)
const preferences::advanced_pref_list & adv_preferences_
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
void on_page_select()
Callback for selection changes.
void on_friends_list_select(listbox &list, text_box &textbox)
void add_friend_list_entry(const bool is_friend, text_box &textbox)
group< preferences::lobby_joins > lobby_joins_group
std::vector< const hotkey::hotkey_command * > visible_hotkeys_
virtual const std::string & window_id() const override
The display function – see modal_dialog for more information.
widget_data get_friends_list_row_data(const preferences::acquaintance &entry)
std::set< hotkey::HOTKEY_CATEGORY > visible_categories_
void update_friends_list_controls(listbox &list)
void handle_res_select()
Special callback functions.
preferences_dialog(const preferences::PREFERENCE_VIEW initial_view=preferences::VIEW_DEFAULT)
void remove_friend_list_entry(listbox &friends_list, text_box &textbox)
void initialize_sound_option_group(const std::string &id_suffix)
void add_hotkey_callback(listbox &hotkeys)
Dialog for selecting a GUI theme.
Definition: theme_list.hpp:36
The listbox class.
Definition: listbox.hpp:43
A menu_button is a styled_widget to choose an element from a list of elements.
Definition: menu_button.hpp:59
Class for a single line text area.
Definition: text_box.hpp:142
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:63
#define DEFINE_SIMPLE_DISPLAY_WRAPPER(dialog)
Adds a bare-bones static display function to a dialog class that immediately invokes the dialogs's mo...
Various uncategorised dialogs.
Generic file dialog.
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:34
Modify, read and display user preferences.
std::vector< advanced_manager::option > advanced_pref_list
Definition: advanced.hpp:68
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.
bool is_friend(const std::string &nick)
Definition: game.cpp:261
Definitions related to theme-support.