The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
filter_options.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2016 by Ignacio Riquelme Morelle <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
19 #include "gui/auxiliary/field.hpp"
20 #include "gui/widgets/button.hpp"
21 #ifdef GUI2_EXPERIMENTAL_LISTBOX
22 #include "gui/widgets/list.hpp"
23 #else
24 #include "gui/widgets/listbox.hpp"
25 #endif
26 #include "gui/widgets/settings.hpp"
28 #include "gui/widgets/window.hpp"
29 #include "gettext.hpp"
30 
31 #include "utils/functional.hpp"
32 
33 namespace
34 {
35 bool unchecked_bool_field_finder(gui2::twindow& window,
36  gui2::tfield_bool* bool_field)
37 {
38  return bool_field->get_widget_value(window) == false;
39 }
40 }
41 
42 namespace gui2
43 {
44 
45 /*WIKI
46  * @page = GUIWindowDefinitionWML
47  * @order = 2_addon_filter_options
48  *
49  * == Add-on filter options ==
50  *
51  * Advanced filtering options for the legacy (GUI1) Add-ons Manager dialog.
52  *
53  * @begin{table}{dialog_widgets}
54  *
55  * statuses_list & & listbox & m &
56  * A listbox for displaying and selecting add-on installation status
57  * filter options. $
58  *
59  * toggle_all_displayed_types & & button & m &
60  * This button toggles the values for all the widgets used to control the
61  * following add-on display options. $
62  *
63  * show_unknown & & toggle_button & m &
64  * Whether to display add-ons of unknown type. $
65  *
66  * show_sp_campaigns & & toggle_button & m &
67  * Whether to display single-player campaign add-ons. $
68  *
69  * show_sp_scenarios & & toggle_button & m &
70  * Whether to display single-player scenario add-ons. $
71  *
72  * show_mp_campaigns & & toggle_button & m &
73  * Whether to display multiplayer campaign add-ons. $
74  *
75  * show_mp_scenarios & & toggle_button & m &
76  * Whether to display multiplayer scenario add-ons. $
77  *
78  * show_mp_maps & & toggle_button & m &
79  * Whether to display multiplayer map-pack add-ons. $
80  *
81  * show_mp_eras & & toggle_button & m &
82  * Whether to display multiplayer era add-ons. $
83  *
84  * show_mp_factions & & toggle_button & m &
85  * Whether to display multiplayer faction add-ons. $
86  *
87  * show_mp_mods & & toggle_button & m &
88  * Whether to display multiplayer mod add-ons. $
89  *
90  * show_media & & toggle_button & m &
91  * Whether to display author resource add-ons. $
92  *
93  * show_other & & toggle_button & m &
94  * Whether to display add-ons of indeterminate types. $
95  *
96  * sort_ascending & & toggle_button & m &
97  * Display add-ons in ascending order by default. $
98  *
99  * sort_descending & & toggle_button & m &
100  * Display add-ons in descending order by default. $
101  *
102  * sort_by_name & & toggle_button & m &
103  * Sort add-ons by name by default. $
104  *
105  * sort_by_last_updated & & toggle_button & m &
106  * Sort add-ons by last update time by default. $
107  *
108  * sort_by_first_upload & & toggle_button & m &
109  * Sort add-ons by creation time by default. $
110  *
111  * @end{table}
112  */
113 
114 REGISTER_DIALOG(addon_filter_options)
115 
117  : displayed_status_()
118  , displayed_types_()
119  , displayed_types_fields_()
120  , sort_()
121  , dir_()
122  , sort_tgroup_()
123  , dir_tgroup_()
124 {
125  displayed_types_.assign(true);
126 
127  // This part has to be hardcoded, sadly.
128 
129  register_displayed_type_field("show_unknown", ADDON_UNKNOWN);
130  register_displayed_type_field("show_cores", ADDON_CORE);
131  register_displayed_type_field("show_sp_campaigns", ADDON_SP_CAMPAIGN);
132  register_displayed_type_field("show_sp_mp_campaigns", ADDON_SP_MP_CAMPAIGN);
133  register_displayed_type_field("show_sp_scenarios", ADDON_SP_SCENARIO);
134  register_displayed_type_field("show_mp_campaigns", ADDON_MP_CAMPAIGN);
135  register_displayed_type_field("show_mp_scenarios", ADDON_MP_SCENARIO);
136  register_displayed_type_field("show_mp_maps", ADDON_MP_MAPS);
137  register_displayed_type_field("show_mp_eras", ADDON_MP_ERA);
138  register_displayed_type_field("show_mp_factions", ADDON_MP_FACTION);
139  register_displayed_type_field("show_mp_mods", ADDON_MP_MOD);
140  register_displayed_type_field("show_media", ADDON_MEDIA);
141  // FIXME: (also in WML) should this and Unknown be a single option in the
142  // UI?
143  register_displayed_type_field("show_other", ADDON_OTHER);
144 }
145 
147  const std::string& field_id, ADDON_TYPE addon_type)
148 {
149  displayed_types_fields_.push_back(
150  register_bool(field_id, true, displayed_types_[addon_type]));
151 }
152 
153 void taddon_filter_options::read_types_vector(const std::vector<bool>& v)
154 {
155  for(size_t k = 0; k < displayed_types_.size(); ++k) {
156  // All unspecified types default to visible.
157  displayed_types_[k] = k < v.size() ? v[k] : true;
158  }
159 }
160 
162  twindow& window)
163 {
164  const bool have_any_unchecked
166  == std::find_if(displayed_types_fields_.begin(),
168  std::bind(&unchecked_bool_field_finder,
169  std::ref(window),
170  _1));
171 
172  for(const auto field : displayed_types_fields_)
173  {
174  field->set_widget_value(window, !have_any_unchecked);
175  }
176 }
177 
179 {
181 }
182 
184 {
186 }
187 
189 {
190  tlistbox& list = find_widget<tlistbox>(&window, "statuses_list", false);
191  window.keyboard_capture(&list);
192 
193  for(unsigned k = ADDON_STATUS_FILTER(); k < FILTER_COUNT; ++k) {
194  std::map<std::string, string_map> row;
196 
197  column["label"] = status_label(ADDON_STATUS_FILTER(k));
198  row.insert(std::make_pair("status", column));
199 
200  list.add_row(row);
201  }
202 
204 
206  find_widget<tbutton>(&window, "toggle_all_displayed_types", false),
207  std::bind(&taddon_filter_options::
209  this,
210  std::ref(window)));
211 
213  register_sort_toggle(window, "by_name", SORT_NAMES);
214  register_sort_toggle(window, "by_last_updated", SORT_UPDATED);
215  register_sort_toggle(window, "by_first_upload", SORT_CREATED);
216 
217  dir_tgroup_.clear();
218  register_dir_toggle(window, "ascending", DIRECTION_ASCENDING);
219  register_dir_toggle(window, "descending", DIRECTION_DESCENDING);
220 }
221 
223  const std::string& toggle_id,
225 {
227  = &find_widget<ttoggle_button>(&window, "sort_" + toggle_id, false);
228 
229  b->set_value(value == sort_);
230 
231  sort_tgroup_.add_member(b, value);
232 
234  *b,
236 }
237 
239  const std::string& toggle_id,
241 {
243  = &find_widget<ttoggle_button>(&window, "sort_" + toggle_id, false);
244 
245  b->set_value(value == dir_);
246 
247  dir_tgroup_.add_member(b, value);
248 
250  *b,
252 }
253 
255 {
256  // Sorting and direction options are handled in widget
257  // callbacks.
259  dir_tgroup_.clear();
260 
261  tlistbox& list = find_widget<tlistbox>(&window, "statuses_list", false);
262  const int selected = list.get_selected_row();
263 
264  if(selected != -1) {
266  }
267 }
268 
270 {
271  switch(s) {
273  return _("addons_view^Not Installed");
274  case FILTER_UPGRADABLE:
275  return _("addons_view^Upgradable");
276  case FILTER_INSTALLED:
277  return _("addons_view^Installed");
278  default:
279  return _("addons_view^All Add-ons");
280  }
281 }
282 
283 } // end namespace gui2
ADDON_SORT_DIRECTION dir_
tgroup< ADDON_SORT > sort_tgroup_
void register_sort_toggle(twindow &window, const std::string &toggle_id, ADDON_SORT value)
Single-player scenario.
Definition: validation.hpp:45
boost::array< bool, ADDON_TYPES_COUNT > displayed_types_
ADDON_TYPE
Values used for add-on classification; UI-only at the moment, in the future it could be used for dire...
Definition: validation.hpp:41
an add-on that fits in no other category
Definition: validation.hpp:56
Total Conversion Core.
Definition: validation.hpp:43
ADDON_SORT
Add-on fallback/default sorting criteria for the user interface.
Definition: state.hpp:93
ADDON_STATUS_FILTER displayed_status_
tgroup< ADDON_SORT_DIRECTION > dir_tgroup_
This file contains the window object, this object is a top level container which has the event manage...
bool select_row(const unsigned row, const bool select=true)
Selectes a row.
Definition: listbox.cpp:228
REGISTER_DIALOG(label_settings)
Multiplayer faction.
Definition: validation.hpp:51
void connect_signal_mouse_left_click(tdispatcher &dispatcher, const tsignal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.hpp:710
void clear()
Clears the entire group of members.
Definition: group.hpp:63
T get_widget_value(twindow &window)
Gets the value of the field.
Definition: field.hpp:398
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed...
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
Class for a toggle button.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
static std::string status_label(ADDON_STATUS_FILTER s)
Sort by creation time.
Definition: state.hpp:96
ADDON_SORT_DIRECTION
Add-on fallback/default sorting direction.
Definition: state.hpp:102
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
This file contains the settings handling of the widget library.
Descending sort.
Definition: state.hpp:104
ADDON_STATUS_FILTER
Add-on installation status filters for the user interface.
Definition: state.hpp:82
void add_row(const string_map &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
Definition: listbox.cpp:74
const GLdouble * v
Definition: glew.h:1359
GLsizei const GLfloat * value
Definition: glew.h:1817
std::string selected
Definition: game_config.cpp:84
static void field(LexState *ls, struct ConsControl *cc)
Definition: lparser.cpp:707
Modification of the game for MP.
Definition: validation.hpp:53
std::map< std::string, t_string > string_map
Definition: generator.hpp:23
void post_show(twindow &window)
Inherited from tdialog.
Miscellaneous content/media (unit packs, terrain packs, music packs, etc.).
Definition: validation.hpp:55
Ascending sort.
Definition: state.hpp:103
GLenum GLenum GLvoid GLvoid * column
Definition: glew.h:3805
Multiplayer scenario.
Definition: validation.hpp:48
Multiplayer era.
Definition: validation.hpp:50
std::vector< tfield_bool * > displayed_types_fields_
The listbox class.
Definition: listbox.hpp:39
T get_active_member_value()
Returns the value paired with the currently activiely toggled member of the group.
Definition: group.hpp:97
Sort by add-on name.
Definition: state.hpp:94
Multiplayer plain (no WML) map pack.
Definition: validation.hpp:49
Sort by last upload time.
Definition: state.hpp:95
GLenum GLenum GLvoid * row
Definition: glew.h:3805
GLenum GLint ref
Definition: glew.h:1813
Hybrid campaign.
Definition: validation.hpp:46
void register_dir_toggle(twindow &window, const std::string &toggle_id, ADDON_SORT_DIRECTION value)
void register_displayed_type_field(const std::string &field_id, ADDON_TYPE addon_type)
tfield_bool * register_bool(const std::string &id, const bool mandatory, const std::function< bool()> &callback_load_value=std::function< bool()>(), const std::function< void(const bool)> &callback_save_value=std::function< void(const bool)>(), const std::function< void(twidget &)> &callback_change=std::function< void(twidget &)>())
Creates a new boolean field.
Definition: dialog.cpp:74
void add_member(tselectable_ *widget, const T &value)
Adds a widget/value pair to the group vector.
Definition: group.hpp:43
void pre_show(twindow &window)
Inherited from tdialog.
void set_value(const unsigned selected)
Inherited from tselectable_.
GLdouble s
Definition: glew.h:1358
void toggle_all_displayed_types_button_callback(twindow &window)
Specialized field class for boolean.
Definition: field.hpp:547
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:237
Single-player campaign.
Definition: validation.hpp:44
void read_types_vector(const std::vector< bool > &v)
GLsizei const GLcharARB ** string
Definition: glew.h:4503
Multiplayer campaign.
Definition: validation.hpp:47