-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
preferences_dialog.hpp
143 lines (111 loc) · 4.38 KB
/
preferences_dialog.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
Copyright (C) 2011, 2015 by Ignacio R. Morelle <shadowm2006@gmail.com>
Copyright (C) 2016 - 2017 by Charles Dang <exodia339gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
#include "config.hpp"
#include "preferences/game.hpp"
#include "utils/make_enum.hpp"
#include "gui/dialogs/modal_dialog.hpp"
#include "gui/widgets/group.hpp"
#include <boost/dynamic_bitset.hpp>
// This file is not named preferences.hpp in order -I conflicts with
// src/preferences.hpp.
namespace hotkey {
struct hotkey_command;
}
namespace preferences {
enum PREFERENCE_VIEW {
VIEW_DEFAULT,
VIEW_FRIENDS
};
/**
* Map containing page mappings that can be used to set the initally displayed page
* of the dialog. The pair is in an 0-indexed toplevel stack/substack format, where
* the first is the list of main Preference categories (such as General and Display)
* and the second is any sub-stack found on that page.
*
* TODO: this isn't the most optimal solution, since if the order or number of pages
* in either stack changes, this map needs to be updated. Optimally the stacked_widget
* widget would allow specifying page by string id, but that would require changes to
* generator. It's something to look into, however.
*/
static std::map<PREFERENCE_VIEW, std::pair<int,int>> pef_view_map {
{VIEW_DEFAULT, {0,0}},
{VIEW_FRIENDS, {4,1}}
};
}
namespace gui2
{
class listbox;
class menu_button;
class styled_widget;
class slider;
class text_box;
class toggle_button;
namespace dialogs
{
class preferences_dialog : public modal_dialog
{
public:
preferences_dialog(const config& game_cfg, const preferences::PREFERENCE_VIEW& initial_view);
/** The display function -- see @ref modal_dialog for more information. */
static void display(const config& game_cfg, const preferences::PREFERENCE_VIEW initial_view = preferences::VIEW_DEFAULT)
{
preferences_dialog(game_cfg, initial_view).show();
}
typedef std::vector<const hotkey::hotkey_command*> t_visible_hotkeys;
private:
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const override;
/** Inherited from modal_dialog. */
virtual void post_build(window& window) override;
virtual void pre_show(window& window) override;
virtual void post_show(window& /*window*/) override;
/** Initializers */
void initialize_tabs(window& window, listbox& selector);
void set_resolution_list(menu_button& res_list, CVideo& video);
listbox& setup_hotkey_list(window& window);
std::map<std::string, string_map> get_friends_list_row_data(const preferences::acquaintance& entry);
void add_friend_list_entry(const bool is_friend, text_box& textbox, window& window);
void remove_friend_list_entry(listbox& friends_list, text_box& textbox, window& window);
void on_friends_list_select(listbox& list, text_box& textbox);
void update_friends_list_controls(window& window, listbox& list);
void set_visible_page(window& window, unsigned int page, const std::string& pager_id);
/** Callback for selection changes */
void on_page_select(window& window);
void on_tab_select(window& window);
void on_advanced_prefs_list_select(listbox& tree);
/** Special callback functions */
void handle_res_select(window& window);
void fullscreen_toggle_callback(window& window);
void add_hotkey_callback(listbox& hotkeys);
void remove_hotkey_callback(listbox& hotkeys);
void default_hotkey_callback(window& window);
void hotkey_type_filter_callback(window& window) const;
group<preferences::LOBBY_JOINS> lobby_joins_group;
MAKE_ENUM(ADVANCED_PREF_TYPE,
(TOGGLE, "boolean")
(SLIDER, "int")
(COMBO, "combo")
(SPECIAL, "custom")
)
std::vector<std::pair<int,int> > resolutions_;
std::vector<config> adv_preferences_cfg_;
int last_selected_item_;
std::vector<double> accl_speeds_;
t_visible_hotkeys visible_hotkeys_;
std::vector<t_string> cat_names_;
// The page/tab index pairs for setting visible pages
const std::pair<int, int>& initial_index_;
};
} // namespace dialogs
} // namespace gui2