The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
preferences_dialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011, 2015 by Ignacio R. Morelle <[email protected]>
3  Copyright (C) 2016 by Charles Dang <exodia339gmail.com>
4  Part of the Battle for Wesnoth Project http://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 #define GETTEXT_DOMAIN "wesnoth-lib"
17 
19 
20 #include "game_preferences.hpp"
22 #include "hotkey/hotkey_item.hpp"
23 #include "preferences.hpp"
24 #include "preferences_display.hpp"
25 #include "lobby_preferences.hpp"
26 #include "gettext.hpp"
27 #include "video.hpp"
28 #include "formula/string_utils.hpp"
29 #include "filesystem.hpp"
30 #include "gui/dialogs/message.hpp"
32 
33 // Sub-dialog includes
36 #include "gui/dialogs/logging.hpp"
39 
40 #include "gui/dialogs/helper.hpp"
42 #include "gui/widgets/button.hpp"
43 #include "gui/widgets/combobox.hpp"
44 #include "gui/widgets/grid.hpp"
45 #include "gui/widgets/image.hpp"
46 #include "gui/widgets/label.hpp"
47 #ifdef GUI2_EXPERIMENTAL_LISTBOX
48 #include "gui/widgets/list.hpp"
49 #else
50 #include "gui/widgets/listbox.hpp"
51 #endif
53 #include "gui/widgets/settings.hpp"
54 #include "gui/widgets/slider.hpp"
56 #include "gui/widgets/text_box.hpp"
58 #include "gui/widgets/window.hpp"
59 #include "util.hpp"
60 
61 #include "gettext.hpp"
62 
63 #include <sstream>
64 #include "utils/functional.hpp"
65 #include <boost/math/common_factor_rt.hpp>
66 
67 namespace {
68 
69 struct advanced_preferences_sorter
70 {
71  bool operator()(const config& lhs, const config& rhs) const
72  {
73  return lhs["name"].t_str().str() < rhs["name"].t_str().str();
74  }
75 };
76 template<hotkey::scope scope, bool reverse>
77 struct hotkey_sort_by_type
78 {
79  hotkey_sort_by_type(const gui2::tpreferences::t_visible_hotkeys& l) : hotkey_commands_(&l) {}
80  bool operator()(int lhs, int rhs) const
81  {
82  return reverse ? (*hotkey_commands_)[lhs]->scope[scope] < (*hotkey_commands_)[rhs]->scope[scope]
83  : (*hotkey_commands_)[lhs]->scope[scope] > (*hotkey_commands_)[rhs]->scope[scope];
84  }
85  const gui2::tpreferences::t_visible_hotkeys* hotkey_commands_;
86 };
87 template<bool reverse>
88 struct hotkey_sort_by_desc
89 {
90  hotkey_sort_by_desc(const gui2::tpreferences::t_visible_hotkeys& l) : hotkey_commands_(&l) {}
91  bool operator()(int lhs, int rhs) const
92  {
93  return reverse ? (*hotkey_commands_)[lhs]->description.str() < (*hotkey_commands_)[rhs]->description.str()
94  : (*hotkey_commands_)[lhs]->description.str() > (*hotkey_commands_)[rhs]->description.str();
95  }
96  const gui2::tpreferences::t_visible_hotkeys* hotkey_commands_;
97 };
98 const std::string bool_to_display_string(bool value)
99 {
100  return value ? _("yes") : _("no");
101 }
102 
103 } // end anon namespace
104 
105 
106 namespace gui2 {
107 
108 using namespace preferences;
109 
111 
113  : resolutions_(video.get_available_resolutions(true))
114  , adv_preferences_cfg_()
115  , friend_names_()
116  , last_selected_item_(0)
117  , accl_speeds_(
118  // IMPORTANT: NEVER have trailing zeroes here, or else the cast from doubles
119  // to string will not match, since lexical_cast strips trailing zeroes.
120  {"0.25", "0.5", "0.75", "1", "1.25", "1.5", "1.75", "2", "3", "4", "8", "16" })
121  , visible_hotkeys_()
122  , font_scaling_(font_scaling())
123  , index_(0,0)
124 {
125  for(const config& adv : game_cfg.child_range("advanced_preference")) {
126  adv_preferences_cfg_.push_back(adv);
127  }
128 
129  std::sort(adv_preferences_cfg_.begin(), adv_preferences_cfg_.end(),
130  advanced_preferences_sorter());
131 }
132 
133 // Determine the template type in order to use the correct value getter
135 {
136  return bool_to_display_string(parent_widget.get_value_bool());
137 }
138 
139 static std::string disambiguate_widget_value(const tcombobox& parent_widget)
140 {
141  return parent_widget.get_value_string();
142 }
143 
144 static std::string disambiguate_widget_value(const tslider& parent_widget)
145 {
146  return parent_widget.get_value_label();
147 }
148 
149 // Parse the max atosaves slider value. Max value means infinte autosaves.
151 {
152  std::string label;
153  const int value = slider.get_value();
154 
155  // INFINITE_AUTO_SAVES is hardcoded as 61 in game_preferences.hpp
156  if(value == INFINITE_AUTO_SAVES) {
157  // label = _("∞"); Doesn't look good on Windows. Restore when it does
158  label = _("infinite");
159  } else {
160  label = disambiguate_widget_value(slider);
161  }
162 
163  return label;
164 }
165 
166 // Helper function to refresh resolution list
167 static void set_resolution_list(tcombobox& res_list, CVideo& video)
168 {
169  const std::vector<std::pair<int,int> > resolutions = video.get_available_resolutions(true);
170 
171  std::vector<std::string> options;
172  for(const auto& res : resolutions)
173  {
174  std::ostringstream option;
175  option << res.first << utils::unicode_multiplication_sign << res.second;
176 
177  const int div = boost::math::gcd(res.first, res.second);
178  const int ratio[2] = {res.first/div, res.second/div};
179  if (ratio[0] <= 10 || ratio[1] <= 10) {
180  option << " <span color='#777777'>("
181  << ratio[0] << ':' << ratio[1] << ")</span>";
182  }
183 
184  options.push_back(option.str());
185  }
186 
187  const unsigned current_res = std::find(resolutions.begin(), resolutions.end(),
188  video.current_resolution()) - resolutions.begin();
189 
190  res_list.set_values(options, current_res);
191 }
192 
194  const std::string& widget_id,
195  const bool start_value,
196  std::function<void(bool)> callback,
197  twidget& find_in,
198  const bool inverted)
199 {
200  ttoggle_button& widget =
201  find_widget<ttoggle_button>(&find_in, widget_id, false);
202 
203  widget.set_value(start_value);
204 
205  connect_signal_mouse_left_click(widget, std::bind(
207  this, std::ref(widget), callback, inverted));
208 }
209 
211  const std::string& toggle_widget,
212  const std::string& slider_widget,
213  const bool toggle_start_value,
214  const int slider_state_value,
215  std::function<void(bool)> toggle_callback,
216  std::function<void(int)> slider_callback,
217  twidget& find_in)
218 {
219  ttoggle_button& button =
220  find_widget<ttoggle_button>(&find_in, toggle_widget, false);
221  tslider& slider =
222  find_widget<tslider>(&find_in, slider_widget, false);
223 
224  button.set_value(toggle_start_value);
225  slider.set_value(slider_state_value);
226  slider.set_active(toggle_start_value);
227 
228  connect_signal_mouse_left_click(button, std::bind(
230  this, std::ref(button), std::ref(slider),
231  toggle_callback));
232 
233  connect_signal_notify_modified(slider, std::bind(
235  this, std::ref(slider),
236  slider_callback));
237 }
238 
240  const std::string& widget_id,
241  const int start_value,
242  std::function<void(int)> slider_callback,
243  twidget& find_in)
244 {
245  tslider& widget = find_widget<tslider>(&find_in, widget_id, false);
246  widget.set_value(start_value);
247 
248  connect_signal_notify_modified(widget, std::bind(
250  this, std::ref(widget),
251  slider_callback));
252 }
253 
255  const std::string& widget_id,
256  const combo_data& options,
257  const unsigned start_value,
258  std::function<void(std::string)> callback,
259  twidget& find_in)
260 {
261  tcombobox& widget =
262  find_widget<tcombobox>(&find_in, widget_id, false);
263 
264  widget.set_use_markup(true);
265  widget.set_values(options.first, start_value);
266 
267  connect_signal_mouse_left_click(widget, std::bind(
269  this, std::ref(widget),
270  callback, options.second));
271 }
272 
273 template <typename T>
275  const std::string& toggle_id,
276  const T& enum_value,
277  const int start_value,
278  tgroup<T>& group,
279  std::function<void(int)> callback,
280  twindow& window)
281 {
282  ttoggle_button& button = find_widget<ttoggle_button>(&window, toggle_id, false);
283 
284  button.set_value(enum_value == start_value);
285 
286  group.add_member(&button, enum_value);
287 
288  connect_signal_mouse_left_click(button, std::bind(
289  &tpreferences::toggle_radio_callback<T>,
290  this, group, callback));
291 }
292 
293 template <typename T>
294 void tpreferences::bind_status_label(T& parent, const std::string& label_id,
295  twidget& find_in)
296 {
297  tcontrol& label = find_widget<tcontrol>(&find_in, label_id, false);
298  label.set_label(disambiguate_widget_value(parent));
299 
300  parent.set_callback_state_change(std::bind(
301  &tpreferences::status_label_callback<T>,
302  this, std::ref(parent), std::ref(label), ""));
303 }
304 
306  twidget& find_in, const std::string& suffix)
307 {
308  tcontrol& label = find_widget<tcontrol>(&find_in, label_id, false);
309  label.set_label(lexical_cast<std::string>(parent.get_value_label()) + suffix);
310 
311  connect_signal_notify_modified(parent, std::bind(
312  &tpreferences::status_label_callback<tslider>,
313  this, std::ref(parent), std::ref(label), suffix));
314 }
315 
317 {
318  tlistbox& friends_list = find_widget<tlistbox>(&window, "friends_list", false);
319 
320  const std::map<std::string, acquaintance>& acquaintances = get_acquaintances();
321 
322  std::map<std::string, string_map> data;
323 
324  find_widget<tbutton>(&window, "remove", false).set_active(!acquaintances.empty());
325 
326  friends_list.clear();
327  friend_names_.clear();
328 
329  if (acquaintances.empty()) {
330  data["friend_icon"]["label"] = "misc/status-neutral.png";
331  data["friend_name"]["label"] = _("Empty list");
332  friends_list.add_row(data);
333 
334  return;
335  }
336 
337  for(const auto& acquaintence : acquaintances)
338  {
339  std::string image = "friend.png";
340  std::string descriptor = _("friend");
341  std::string notes;
342 
343  if(acquaintence.second.get_status() == "ignore") {
344  image = "ignore.png";
345  descriptor = _("ignored");
346  }
347 
348  if(!acquaintence.second.get_notes().empty()) {
349  notes = " <small>(" + acquaintence.second.get_notes() + ")</small>";
350  }
351 
352  data["friend_icon"]["label"] = "misc/status-" + image;
353 
354  data["friend_name"]["label"] = acquaintence.second.get_nick() + notes;
355  data["friend_name"]["use_markup"] = "true";
356 
357  data["friend_status"]["label"] = "<small>" + descriptor + "</small>";
358  data["friend_status"]["use_markup"] = "true";
359  friends_list.add_row(data);
360 
361  friend_names_.push_back(acquaintence.first);
362  }
363 }
364 
366  ttext_box& textbox, twindow& window)
367 {
368  std::string reason;
369  std::string username = textbox.text();
370  size_t pos = username.find_first_of(' ');
371 
372  if (pos != std::string::npos) {
373  reason = username.substr(pos + 1);
374  username = username.substr(0, pos);
375  }
376 
377  const bool added_sucessfully = is_friend ?
378  add_friend(username, reason) :
379  add_ignore(username, reason) ;
380 
381  if (!added_sucessfully) {
382  gui2::show_transient_message(window.video(), _("Error"), _("Invalid username"),
383  std::string(), false, false, true);
384  return;
385  }
386 
387  textbox.clear();
388  setup_friends_list(window);
389 }
390 
392  ttext_box& textbox)
393 {
394  const int num_available = get_acquaintances().size();
395  const int sel = friends.get_selected_row();
396  if(sel < 0 || sel >= num_available) {
397  return;
398  }
399  std::map<std::string, acquaintance>::const_iterator who = get_acquaintances().begin();
400  std::advance(who, sel);
401  textbox.set_value(who->second.get_nick() + " " + who->second.get_notes());
402 }
403 
405  ttext_box& textbox, twindow& window)
406 {
407  std::string to_remove = textbox.text();
408 
409  if (to_remove.empty()) {
410  const int selected_row = std::max(0, friends_list.get_selected_row());
411  to_remove = friend_names_[selected_row];
412  }
413 
414  if(!remove_acquaintance(to_remove)) {
415  gui2::show_transient_error_message(window.video(), _("Not on friends or ignore lists"));
416  return;
417  }
418 
419  textbox.clear();
420  setup_friends_list(window);
421 }
422 
423 // Helper function to get the main grid in each row of the advanced section
424 // lisbox, which contains the value and setter widgets.
425 static tgrid* get_advanced_row_grid(tlistbox& list, const int selected_row)
426 {
427  return dynamic_cast<tgrid*>(
428  list.get_row_grid(selected_row)->find("pref_main_grid", false));
429 }
430 
431 /**
432  * Sets up states and callbacks for each of the widgets
433  */
435 {
436  //
437  // GENERAL PANEL
438  //
439 
440  /* SCROLL SPEED */
441  setup_single_slider("scroll_speed",
442  scroll_speed(), set_scroll_speed, window);
443 
444  /* ACCELERATED SPEED */
445  ttoggle_button& accl_toggle =
446  find_widget<ttoggle_button>(&window, "turbo_toggle", false);
447  tslider& accl_slider =
448  find_widget<tslider>(&window, "turbo_slider", false);
449 
450  const int selected_speed = std::find(
451  (accl_speeds_.begin()), accl_speeds_.end(), lexical_cast<std::string>(turbo_speed()))
452  - (accl_speeds_.begin());
453 
454  accl_slider.set_value_labels(accl_speeds_);
455 
456  const bool is_turbo = turbo();
457 
458  accl_toggle.set_value(is_turbo);
459  accl_slider.set_value(selected_speed + 1);
460  accl_slider.set_active(is_turbo);
461 
462  connect_signal_mouse_left_click(accl_toggle, std::bind(
464  this, std::ref(accl_toggle), std::ref(accl_slider),
465  set_turbo));
466 
467  connect_signal_notify_modified(accl_slider, std::bind(
469  this,
470  std::ref(accl_slider)));
471 
472  bind_status_label(accl_slider, "turbo_value", window);
473 
474  /* SKIP AI MOVES */
475  setup_single_toggle("skip_ai_moves",
476  !show_ai_moves(), set_show_ai_moves, window, true);
477 
478  /* DISABLE AUTO MOVES */
479  setup_single_toggle("disable_auto_moves",
481 
482  /* TURN DIALOG */
483  setup_single_toggle("show_turn_dialog",
484  turn_dialog(), set_turn_dialog, window);
485 
486  /* ENABLE PLANNING MODE */
487  setup_single_toggle("whiteboard_on_start",
489 
490  /* HIDE ALLY PLANS */
491  setup_single_toggle("whiteboard_hide_allies",
493 
494  /* INTERRUPT ON SIGHTING */
495  setup_single_toggle("interrupt_move_when_ally_sighted",
497 
498  /* SAVE REPLAYS */
499  setup_single_toggle("save_replays",
500  save_replays(), set_save_replays, window);
501 
502  /* DELETE AUTOSAVES */
503  setup_single_toggle("delete_saves",
504  delete_saves(), set_delete_saves, window);
505 
506  /* MAX AUTO SAVES */
507  tslider& autosaves_slider = find_widget<tslider>(&window, "max_saves_slider", false);
508  tcontrol& autosaves_label = find_widget<tcontrol>(&window, "max_saves_value", false);
509 
510  autosaves_slider.set_value(autosavemax());
511 
512  autosaves_label.set_label(get_max_autosaves_status_label(autosaves_slider));
513  autosaves_label.set_use_markup(true);
514 
515  connect_signal_notify_modified(autosaves_slider, std::bind(
517  this, std::ref(autosaves_slider), std::ref(autosaves_label)));
518 
519  /* CACHE MANAGE */
520  connect_signal_mouse_left_click(find_widget<tbutton>(&window, "cachemg", false),
522  std::ref(window.video())));
523 
524  //
525  // DISPLAY PANEL
526  //
527 
528  /* FULLSCREEN TOGGLE */
529  ttoggle_button& toggle_fullscreen =
530  find_widget<ttoggle_button>(&window, "fullscreen", false);
531 
532  toggle_fullscreen.set_value(fullscreen());
533 
534  // We bind a special callback function, so setup_single_toggle() is not used
535  connect_signal_mouse_left_click(toggle_fullscreen, std::bind(
537  this, std::ref(window)));
538 
539  /* SET RESOLUTION */
540  tcombobox& res_list = find_widget<tcombobox>(&window, "resolution_set", false);
541 
542  res_list.set_use_markup(true);
543  res_list.set_active(!fullscreen());
544  set_resolution_list(res_list, window.video());
545 
546  res_list.connect_click_handler(
548  this, std::ref(window)));
549 
550  /* SHOW FLOATING LABELS */
551  setup_single_toggle("show_floating_labels",
553 
554  /* SHOW HALOES */
555  setup_single_toggle("show_halos",
556  show_haloes(), set_show_haloes, window);
557 
558  /* SHOW TEAM COLORS */
559  setup_single_toggle("show_ellipses",
561 
562  /* SHOW GRID */
563  setup_single_toggle("show_grid",
564  grid(), set_grid, window);
565 
566  /* ANIMATE MAP */
567  ttoggle_button& animate_map_toggle =
568  find_widget<ttoggle_button>(&window, "animate_terrains", false);
569 
570  ttoggle_button& animate_water_toggle =
571  find_widget<ttoggle_button>(&window, "animate_water", false);
572 
573  animate_map_toggle.set_value(animate_map());
574  animate_water_toggle.set_active(animate_map_toggle.get_value_bool());
575 
576  connect_signal_mouse_left_click(animate_map_toggle, std::bind(
578  this, std::ref(animate_map_toggle), std::ref(animate_water_toggle)));
579 
580  /* ANIMATE WATER */
581  setup_single_toggle("animate_water",
582  animate_water(), set_animate_water, window);
583 
584  /* SHOW UNIT STANDING ANIMS */
585  setup_single_toggle("animate_units_standing",
587 
588  /* SHOW UNIT IDLE ANIMS */
589  setup_toggle_slider_pair("animate_units_idle", "idle_anim_frequency",
592 
593  /* FONT SCALING */
594  tslider& scale_slider = find_widget<tslider>(&window, "scaling_slider", false);
595 
596  scale_slider.set_value(font_scaling());
597 
598  connect_signal_notify_modified(scale_slider, std::bind(
600  this, std::ref(scale_slider)));
601 
602  bind_status_label(scale_slider, "scaling_value", window, "%");
603 
604  /* SELECT THEME */
606  find_widget<tbutton>(&window, "choose_theme", false),
608  std::ref(window.video())));
609 
610 
611  //
612  // SOUND PANEL
613  //
614 
615  /* SOUND FX */
616  setup_toggle_slider_pair("sound_toggle_sfx", "sound_volume_sfx",
617  sound_on(), sound_volume(),
618  bind_void(set_sound, _1), set_sound_volume, window);
619 
620  /* MUSIC */
621  setup_toggle_slider_pair("sound_toggle_music", "sound_volume_music",
622  music_on(), music_volume(),
623  bind_void(set_music, _1), set_music_volume, window);
624 
625  /* TURN BELL */
626  setup_toggle_slider_pair("sound_toggle_bell", "sound_volume_bell",
627  turn_bell(), bell_volume(),
628  bind_void(set_turn_bell, _1), set_bell_volume, window);
629 
630  /* UI FX */
631  setup_toggle_slider_pair("sound_toggle_uisfx", "sound_volume_uisfx",
632  UI_sound_on(), UI_volume(),
633  bind_void(set_UI_sound, _1), set_UI_volume, window);
634 
635 
636  //
637  // MULTIPLAYER PANEL
638  //
639 
640  /* CHAT LINES */
641  setup_single_slider("chat_lines",
642  chat_lines(), set_chat_lines, window);
643 
644  /* CHAT TIMESTAMPPING */
645  setup_single_toggle("chat_timestamps",
647 
648  /* SAVE PASSWORD */
649  setup_single_toggle("remember_password",
651 
652  /* SORT LOBBY LIST */
653  setup_single_toggle("lobby_sort_players",
654  sort_list(), _set_sort_list, window);
655 
656  /* ICONIZE LOBBY LIST */
657  setup_single_toggle("lobby_player_icons",
658  iconize_list(), _set_iconize_list, window);
659 
660  /* WHISPERS FROM FRIENDS ONLY */
661  setup_single_toggle("lobby_whisper_friends_only",
663 
664  /* LOBBY JOIN NOTIFICATIONS */
665  setup_radio_toggle("lobby_joins_none", SHOW_NONE,
666  lobby_joins(), lobby_joins_group, _set_lobby_joins, window);
667  setup_radio_toggle("lobby_joins_friends", SHOW_FRIENDS,
668  lobby_joins(), lobby_joins_group, _set_lobby_joins, window);
669  setup_radio_toggle("lobby_joins_all", SHOW_ALL,
670  lobby_joins(), lobby_joins_group, _set_lobby_joins, window);
671 
672  /* FRIENDS LIST */
673  setup_friends_list(window);
674 
675  ttext_box& textbox = find_widget<ttext_box>(&window, "friend_name_box", false);
676  tlistbox& friend_list = find_widget<tlistbox>(&window, "friends_list", false);
677 
679  find_widget<tbutton>(&window, "add_friend", false), std::bind(
681  this, true,
682  std::ref(textbox),
683  std::ref(window)));
684 
686  find_widget<tbutton>(&window, "add_ignored", false), std::bind(
688  this, false,
689  std::ref(textbox),
690  std::ref(window)));
691 
693  find_widget<tbutton>(&window, "remove", false), std::bind(
695  this,
696  std::ref(friend_list),
697  std::ref(textbox),
698  std::ref(window)));
699 
700  friend_list.set_callback_value_change(std::bind(
702  this,
703  std::ref(friend_list),
704  std::ref(textbox)));
705 
706  friend_list.select_row(0);
707 
708  /* ALERTS */
710  find_widget<tbutton>(&window, "mp_alerts", false),
712  std::ref(window.video())));
713 
714  /* SET WESNOTHD PATH */
716  find_widget<tbutton>(&window, "mp_wesnothd", false), std::bind(
718  std::ref(window.video())));
719 
720 
721  //
722  // ADVANCED PANEL
723  //
724 
725  tlistbox& advanced = find_widget<tlistbox>(&window, "advanced_prefs", false);
726 
727  std::map<std::string, string_map> row_data;
728 
729  for(const config& option : adv_preferences_cfg_)
730  {
731  // Details about the current option
732  const ADVANCED_PREF_TYPE& pref_type = ADVANCED_PREF_TYPE::string_to_enum(
733  option["type"].str());
734  const std::string& pref_name = option["field"].str();
735 
736  row_data["pref_name"]["label"] = option["name"];
737  advanced.add_row(row_data);
738 
739  const int this_row = advanced.get_item_count() - 1;
740 
741  // Get the main grid from each row
742  tgrid* main_grid = get_advanced_row_grid(advanced, this_row);
743  assert(main_grid);
744 
745  tgrid* details_grid = &find_widget<tgrid>(main_grid, "prefs_setter_grid", false);
747 
748  // The toggle widget for toggle-type options (hidden for other types)
749  ttoggle_button& toggle_box = find_widget<ttoggle_button>(main_grid, "value_toggle", false);
751 
752  if(!option["description"].empty()) {
753  find_widget<tcontrol>(main_grid, "description", false).set_label(option["description"]);
754  }
755 
756  switch (pref_type.v) {
757  case ADVANCED_PREF_TYPE::TOGGLE: {
758  //main_grid->remove_child("setter");
759 
761 
762  // Needed to disambiguate overloaded function
763  typedef void (*setter) (const std::string &, bool);
764  setter set_ptr = &preferences::set;
765 
766  setup_single_toggle("value_toggle",
767  get(pref_name, option["default"].to_bool()),
768  std::bind(set_ptr, pref_name, _1),
769  *main_grid);
770 
771  bind_status_label(toggle_box, "value", *main_grid);
772 
773  break;
774  }
775 
776  case ADVANCED_PREF_TYPE::SLIDER: {
777  tslider* setter_widget = new tslider;
778  setter_widget->set_definition("minimal");
779  setter_widget->set_id("setter");
780  // Maximum must be set first or this will assert
781  setter_widget->set_maximum_value(option["max"].to_int());
782  setter_widget->set_minimum_value(option["min"].to_int());
783  setter_widget->set_step_size(
784  option["step"].empty() ? 1 : option["step"].to_int());
785 
786  delete details_grid->swap_child("setter", setter_widget, true);
787 
788  // Needed to disambiguate overloaded function
789  typedef void (*setter) (const std::string &, int);
790  setter set_ptr = &preferences::set;
791 
792  setup_single_slider("setter",
793  lexical_cast_default<int>(get(pref_name), option["default"].to_int()),
794  std::bind(set_ptr, pref_name, _1),
795  *details_grid);
796 
797  bind_status_label(*setter_widget, "value", *main_grid);
798 
799  break;
800  }
801 
802  case ADVANCED_PREF_TYPE::COMBO: {
803  combo_data combo_options;
804 
805  for(const config& choice : option.child_range("option"))
806  {
807  combo_options.first.push_back(choice["name"]);
808  combo_options.second.push_back(choice["id"]);
809  }
810 
811  const unsigned selected = std::find(
812  combo_options.second.begin(), combo_options.second.end(),
813  get(pref_name, option["default"].str())) - combo_options.second.begin();
814 
815  tcombobox* setter_widget = new tcombobox;
816  setter_widget->set_definition("default");
817  setter_widget->set_id("setter");
818 
819  delete details_grid->swap_child("setter", setter_widget, true);
820 
821  // Needed to disambiguate overloaded function
822  typedef void (*setter) (const std::string &, const std::string &);
823  setter set_ptr = &preferences::set;
824 
825  setup_combobox("setter",
826  combo_options, selected,
827  std::bind(set_ptr, pref_name, _1),
828  *details_grid);
829 
830  bind_status_label(*setter_widget, "value", *main_grid);
831 
832  break;
833  }
834 
835  case ADVANCED_PREF_TYPE::SPECIAL: {
836  //main_grid->remove_child("setter");
837 
838  timage* value_widget = new timage;
839  value_widget->set_definition("default");
840  value_widget->set_label("icons/arrows/arrows_blank_right_25.png~CROP(3,3,18,18)");
841 
842  delete main_grid->swap_child("value", value_widget, true);
843 
844  break;
845  }
846  }
847  }
848 
849 #ifdef GUI2_EXPERIMENTAL_LISTBOX
850  connect_signal_notify_modified(advanced, std::bind(
852  this,
853  std::ref(advanced),
854  std::ref(window)));
855 #else
856  advanced.set_callback_value_change(make_dialog_callback(
857  std::bind(
859  this,
860  std::ref(advanced),
861  std::ref(window))));
862 #endif
863 
864  advanced.select_row(0);
865 
866  //
867  // HOTKEYS PANEL
868  //
869 
870  row_data.clear();
871 
872  setup_hotkey_list(window);
873 
874  tlistbox& hotkey_list = find_widget<tlistbox>(&window, "list_hotkeys", false);
875 
876  std::vector<tgenerator_::torder_func> order_funcs(2);
877 
878  order_funcs[0] = hotkey_sort_by_desc<false>(visible_hotkeys_);
879  order_funcs[1] = hotkey_sort_by_desc<true>(visible_hotkeys_);
880 
881  hotkey_list.set_column_order(0, order_funcs);
882 
883  hotkey_list.set_column_order(1, order_funcs);
884  order_funcs[0] = hotkey_sort_by_type<hotkey::SCOPE_GAME, false>(visible_hotkeys_);
885  order_funcs[1] = hotkey_sort_by_type<hotkey::SCOPE_GAME, true>(visible_hotkeys_);
886  hotkey_list.set_column_order(2, order_funcs);
887 
888  order_funcs[0] = hotkey_sort_by_type<hotkey::SCOPE_EDITOR, false>(visible_hotkeys_);
889  order_funcs[1] = hotkey_sort_by_type<hotkey::SCOPE_EDITOR, true>(visible_hotkeys_);
890  hotkey_list.set_column_order(3, order_funcs);
891 
892  order_funcs[0] = hotkey_sort_by_type<hotkey::SCOPE_MAIN_MENU, false>(visible_hotkeys_);
893  order_funcs[1] = hotkey_sort_by_type<hotkey::SCOPE_MAIN_MENU, true>(visible_hotkeys_);
894  hotkey_list.set_column_order(4, order_funcs);
895 
897  find_widget<tbutton>(&window, "btn_add_hotkey", false), std::bind(
899  this,
900  std::ref(hotkey_list)));
901 
903  find_widget<tbutton>(&window, "btn_clear_hotkey", false), std::bind(
905  this,
906  std::ref(hotkey_list)));
907 
909  find_widget<tbutton>(&window, "btn_reset_hotkeys", false), std::bind(
911  this,
912  std::ref(window)));
913 }
914 
916 {
917  const std::string& default_icon = "misc/empty.png~CROP(0,0,15,15)";
918 
919  std::map<std::string, string_map> row_data;
920 
921  t_string& row_icon = row_data["img_icon"]["label"];
922  t_string& row_action = row_data["lbl_desc"]["label"];
923  t_string& row_hotkey = row_data["lbl_hotkey"]["label"];
924 
925  t_string& row_is_g = row_data["lbl_is_game"]["label"];
926  t_string& row_is_g_markup = row_data["lbl_is_game"]["use_markup"];
927  t_string& row_is_e = row_data["lbl_is_editor"]["label"];
928  t_string& row_is_e_markup = row_data["lbl_is_editor"]["use_markup"];
929  t_string& row_is_t = row_data["lbl_is_titlescreen"]["label"];
930  t_string& row_is_t_markup = row_data["lbl_is_titlescreen"]["use_markup"];
931 
932  tlistbox& hotkey_list = find_widget<tlistbox>(&window, "list_hotkeys", false);
933 
934  hotkey_list.clear();
935  visible_hotkeys_.clear();
936 
937  std::string text_feature_on = "<span color='#0f0'>" + _("&#9679;") + "</span>";
938 
939  for(const auto& hotkey_item : hotkey::get_hotkey_commands())
940  {
941  if (hotkey_item.hidden) {
942  continue;
943  }
944  visible_hotkeys_.push_back(&hotkey_item);
945 
946  if (filesystem::file_exists(game_config::path + "/images/icons/action/" + hotkey_item.command + "_25.png")) {
947  row_icon = "icons/action/" + hotkey_item.command + "_25.png~CROP(3,3,18,18)";
948  } else {
949  row_icon = default_icon;
950  }
951 
952  row_action = hotkey_item.description;
953  row_hotkey = hotkey::get_names(hotkey_item.command);
954 
955  row_is_g = hotkey_item.scope[hotkey::SCOPE_GAME] ? text_feature_on : "";
956  row_is_g_markup = "true";
957  row_is_e = hotkey_item.scope[hotkey::SCOPE_EDITOR] ? text_feature_on : "";
958  row_is_e_markup = "true";
959  row_is_t = hotkey_item.scope[hotkey::SCOPE_MAIN_MENU] ? text_feature_on : "";
960  row_is_t_markup = "true";
961 
962  hotkey_list.add_row(row_data);
963  }
964 }
965 
967 {
968  CVideo& video = hotkeys.get_window()->video();
969  int row_number = hotkeys.get_selected_row();
970  const hotkey::hotkey_command& hotkey_item = *visible_hotkeys_[row_number];
971  hotkey::hotkey_ptr newhk = hotkey::show_binding_dialog(video, hotkey_item.command);
972  hotkey::hotkey_ptr oldhk;
973 
974  // only if not cancelled.
975  if (newhk.get() == nullptr) {
976  return;
977  }
978 
979  for(const hotkey::hotkey_ptr& hk : hotkey::get_hotkeys()) {
980  if(!hk->is_disabled() && newhk->bindings_equal(hk)) {
981  oldhk = hk;
982  }
983  }
984 
985  hotkey::scope_changer scope_restorer;
986  hotkey::set_active_scopes(hotkey_item.scope);
987 
988  if(oldhk && oldhk->get_command() == hotkey_item.command) {
989  return;
990  }
991 
992  if (oldhk) {
993  utils::string_map symbols;
994  symbols["hotkey_sequence"] = oldhk->get_name();
995  symbols["old_hotkey_action"] = hotkey::get_description(oldhk->get_command());
996  symbols["new_hotkey_action"] = hotkey::get_description(newhk->get_command());
997 
998  std::string text = vgettext("“<b>$hotkey_sequence|</b>” is in use by “<b>$old_hotkey_action|</b>”.\nDo you wish to reassign it to “<b>$new_hotkey_action|</b>”?", symbols);
999 
1000  const int res = gui2::show_message(video, _("Reassign Hotkey"), text, gui2::tmessage::yes_no_buttons, true);
1001  if (res != gui2::twindow::OK) {
1002  return;
1003  }
1004  }
1005 
1006  hotkey::add_hotkey(newhk);
1007 
1008  // We need to recalculate all hotkey names in because we might have removed a hotkey from another command.
1009  for(size_t i = 0; i < hotkeys.get_item_count(); ++i) {
1010  const hotkey::hotkey_command& hotkey_item_row = *visible_hotkeys_[i];
1011  find_widget<tlabel>(hotkeys.get_row_grid(i), "lbl_hotkey", false).set_label(hotkey::get_names(hotkey_item_row.command));
1012  }
1013 }
1014 
1016 {
1017  gui2::show_transient_message(window.video(), _("Hotkeys Reset"), _("All hotkeys have been reset to their default values."),
1018  std::string(), false, false, true);
1019  clear_hotkeys();
1020  setup_hotkey_list(window);
1021  window.invalidate_layout();
1022 }
1024 {
1025  int row_number = hotkeys.get_selected_row();
1026  const hotkey::hotkey_command& hotkey_item = *visible_hotkeys_[row_number];
1027  hotkey::clear_hotkeys(hotkey_item.command);
1028  find_widget<tlabel>(hotkeys.get_row_grid(row_number), "lbl_hotkey", false).set_label(hotkey::get_names(hotkey_item.command));
1029 }
1030 
1032 {
1033  const int selected_row = list.get_selected_row();
1034 
1035  const ADVANCED_PREF_TYPE& selected_type = ADVANCED_PREF_TYPE::string_to_enum(
1036  adv_preferences_cfg_[selected_row]["type"].str());
1037 
1038  const std::string& selected_field = adv_preferences_cfg_[selected_row]["field"].str();
1039 
1040  if(selected_type == ADVANCED_PREF_TYPE::SPECIAL) {
1041  if (selected_field == "advanced_graphic_options") {
1043  } else if (selected_field == "logging") {
1044  gui2::tlogging::display(window.video());
1045  } else if (selected_field == "orb_color") {
1047  } else {
1048  WRN_GUI_L << "Invalid or unimplemented custom advanced prefs option: " << selected_field << "\n";
1049  }
1050 
1051  // Add more options here as needed
1052  }
1053 
1054  const bool has_description = !adv_preferences_cfg_[selected_row]["description"].empty();
1055 
1056  if(has_description || (selected_type != ADVANCED_PREF_TYPE::SPECIAL && selected_type != ADVANCED_PREF_TYPE::TOGGLE)) {
1057  find_widget<twidget>(get_advanced_row_grid(list, selected_row), "prefs_setter_grid", false)
1058  .set_visible(tcontrol::tvisible::visible);
1059  }
1060 
1061  if(last_selected_item_ != selected_row) {
1062  find_widget<twidget>(get_advanced_row_grid(list, last_selected_item_), "prefs_setter_grid", false)
1063  .set_visible(tcontrol::tvisible::invisible);
1064 
1065  last_selected_item_ = selected_row;
1066  }
1067 }
1068 
1069 void tpreferences::add_pager_row(tlistbox& selector, const std::string& icon, const std::string& label)
1070 {
1071  std::map<std::string, string_map> data;
1072  data["icon"]["label"] = "icons/icon-" + icon;
1073  data["label"]["label"] = label;
1074  selector.add_row(data);
1075 }
1076 
1077 void tpreferences::add_tab(tlistbox& tab_bar, const std::string& label)
1078 {
1079  std::map<std::string, string_map> data;
1080  data["tab_label"]["label"] = label;
1081  tab_bar.add_row(data);
1082 }
1083 
1084 void tpreferences::initialize_tabs(twindow& /*window*/, tlistbox& selector, const int index)
1085 {
1086  //
1087  // MULTIPLAYER TABS
1088  //
1089 
1090  if(index == 4) {
1091  add_tab(selector, _("Prefs tab^General"));
1092  add_tab(selector, _("Prefs tab^Friends"));
1093  }
1094 
1095 #ifdef GUI2_EXPERIMENTAL_LISTBOX
1096  connect_signal_notify_modified(selector, std::bind(
1098  this,
1099  std::ref(window)));
1100 #else
1103 #endif
1104 }
1105 
1106 static int index_in_pager_range(const int& first, const tstacked_widget& pager)
1107 {
1108  // Ensure the specified index is between 0 and one less than the max
1109  // number of pager layers (since get_layer_count returns one-past-end).
1110  return std::min<int>(std::max(0, first), pager.get_layer_count() - 1);
1111 }
1112 
1114 {
1115  tlistbox& selector = find_widget<tlistbox>(&window, "selector", false);
1116  tstacked_widget& pager = find_widget<tstacked_widget>(&window, "pager", false);
1117 
1118 #ifdef GUI2_EXPERIMENTAL_LISTBOX
1119  connect_signal_notify_modified(selector, std::bind(
1121  this,
1122  std::ref(window)));
1123 #else
1126 #endif
1127  window.keyboard_capture(&selector);
1128 
1129  add_pager_row(selector, "general.png", _("Prefs section^General"));
1130  add_pager_row(selector, "hotkeys.png", _("Prefs section^Hotkeys"));
1131  add_pager_row(selector, "display.png", _("Prefs section^Display"));
1132  add_pager_row(selector, "music.png", _("Prefs section^Sound"));
1133  add_pager_row(selector, "multiplayer.png", _("Prefs section^Multiplayer"));
1134  add_pager_row(selector, "advanced.png", _("Prefs section^Advanced"));
1135 
1136  // Initializes initial values and sets up callbacks. This needs to be
1137  // done before selecting the initial page, otherwise widgets from other
1138  // pages cannot be found afterwards.
1139  initialize_members(window);
1140 
1141  assert(selector.get_item_count() == pager.get_layer_count());
1142 
1143  const int main_index = index_in_pager_range(index_.first, pager);
1144 
1145  // Loops through each pager layer and checks if it has both a tab bar
1146  // and stack. If so, it initilizes the options for the former and
1147  // selects the specified layer of the latter.
1148  for(unsigned int i = 0; i < pager.get_layer_count(); ++i) {
1149  tlistbox* tab_selector = find_widget<tlistbox>(
1150  pager.get_layer_grid(i), "tab_selector", false, false);
1151 
1152  tstacked_widget* tab_pager = find_widget<tstacked_widget>(
1153  pager.get_layer_grid(i), "tab_pager", false, false);
1154 
1155  if(tab_pager && tab_selector) {
1156  const int ii = static_cast<int>(i);
1157  const int tab_index = index_in_pager_range(index_.second, *tab_pager);
1158  const int to_select = (ii == main_index ? tab_index : 0);
1159 
1160  // Initialize tabs for this page
1161  initialize_tabs(window, *tab_selector, ii);
1162 
1163  tab_selector->select_row(to_select);
1164  tab_pager->select_layer(to_select);
1165  }
1166  }
1167 
1168  // Finally, select the initial main page
1169  selector.select_row(main_index);
1170  pager.select_layer(main_index);
1171 }
1172 
1173 void tpreferences::set_visible_page(twindow& window, unsigned int page, const std::string& pager_id)
1174 {
1175  find_widget<tstacked_widget>(&window, pager_id, false).select_layer(page);
1176 }
1177 
1179  std::function<void(bool)> setter,
1180  const bool inverted)
1181 {
1182  setter(inverted ? !widget.get_value_bool() : widget.get_value_bool());
1183 }
1184 
1186  tslider& slider_widget, std::function<void(bool)> setter)
1187 {
1188  const bool ison = toggle_widget.get_value_bool();
1189  setter(ison);
1190 
1191  slider_widget.set_active(ison);
1192 }
1193 
1195  std::function<void(int)> setter)
1196 {
1197  setter(widget.get_value());
1198 }
1199 
1201  std::function<void(std::string)> setter, std::vector<std::string>& vec)
1202 {
1203  const unsigned index = widget.get_value();
1204  setter(vec[index]);
1205 }
1206 
1207 template <typename T>
1209  tcontrol& label_widget, const std::string& suffix)
1210 {
1211  label_widget.set_label(disambiguate_widget_value(parent_widget) + suffix);
1212 }
1213 
1214 // Special fullsceen callback
1216 {
1217  const bool ison =
1218  find_widget<ttoggle_button>(&window, "fullscreen", false).get_value_bool();
1219  window.video().set_fullscreen(ison);
1220 
1221  tcombobox& res_list = find_widget<tcombobox>(&window, "resolution_set", false);
1222  set_resolution_list(res_list, window.video());
1223  res_list.set_active(!ison);
1224 }
1225 
1227 {
1228  tcombobox& res_list = find_widget<tcombobox>(&window, "resolution_set", false);
1229  const int choice = res_list.get_value();
1230 
1231  if (resolutions_[static_cast<size_t>(choice)] == window.video().current_resolution()) {
1232  return;
1233  }
1234 
1235  window.video().set_resolution(resolutions_[static_cast<size_t>(choice)]);
1237  set_resolution_list(res_list, window.video());
1238 }
1239 
1240 // Special Accelerated Speed slider callback
1242 {
1243  const int index = slider.get_value();
1244  set_turbo_speed(lexical_cast<double>(accl_speeds_[index - 1]));
1245 }
1246 
1247 // Special Max Autosaves slider callback
1249 {
1250  set_autosavemax(slider.get_value());
1251  status_label.set_label(get_max_autosaves_status_label(slider));
1252 }
1253 
1255 {
1256  font_scaling_ = slider.get_value();
1257 }
1258 
1260  ttoggle_button& toggle_water)
1261 {
1262  const bool value = toggle.get_value_bool();
1263  set_animate_map(value);
1264  toggle_water.set_active(value);
1265 }
1266 
1267 template <typename T>
1269  tgroup<T>& group,
1270  std::function<void(int)> setter)
1271 {
1272  setter(group.get_active_member_value());
1273 }
1274 
1276 {
1277  const int selected_row =
1278  std::max(0, find_widget<tlistbox>(&window, "selector", false).get_selected_row());
1279  set_visible_page(window, static_cast<unsigned int>(selected_row), "pager");
1280 }
1281 
1283 {
1284  const int selected_row =
1285  std::max(0, find_widget<tlistbox>(&window, "tab_selector", false).get_selected_row());
1286  set_visible_page(window, static_cast<unsigned int>(selected_row), "tab_pager");
1287 }
1288 
1290 {
1291  // Handle the font scaling setter only once prefs is closed
1292  set_font_scaling(font_scaling_);
1293 
1294  save_hotkeys();
1295 }
1296 
1297 } // end namespace gui2
bool disable_auto_moves()
virtual void set_active(const bool active) override
See tcontrol::set_active.
void set_turbo(bool ison)
void raise_resize_event()
Definition: events.cpp:553
child_itors child_range(const std::string &key)
Definition: config.cpp:613
bool set_sound(bool ison)
std::vector< const hotkey::hotkey_command * > t_visible_hotkeys
void set_hide_whiteboard(bool value)
void set_grid(bool ison)
int bell_volume()
void setup_toggle_slider_pair(const std::string &toggle_widget, const std::string &slider_widget, const bool toggle_start_value, const int slider_state_value, std::function< void(bool)> toggle_callback, std::function< void(int)> slider_callback, twidget &find_in)
Sets the initial state and callback for a bool-state toggle button/slider pair.
void setup_combobox(const std::string &widget_id, const combo_data &options, const unsigned start_value, std::function< void(std::string)> callback, twidget &find_in)
Sets the initial state and callback for a combobox.
void simple_combobox_callback(const tcombobox &widget, std::function< void(std::string)> setter, std::vector< std::string > &vec)
void show_wesnothd_server_search(CVideo &video)
void set_step_size(const unsigned step_size)
Definition: scrollbar.hpp:150
bool remember_password()
void set_show_haloes(bool value)
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1806
void set_show_standing_animations(bool value)
void default_hotkey_callback(twindow &window)
void accl_speed_slider_callback(tslider &slider)
static std::string disambiguate_widget_value(const ttoggle_button &parent_widget)
std::pair< int, int > current_resolution()
Definition: video.cpp:615
void save_hotkeys(config &cfg)
Save the non-default hotkeys to the config.
void _set_sort_list(bool sort)
int pos
Definition: formula.cpp:800
std::pair< std::vector< std::string >, std::vector< std::string > > combo_data
CVideo & video()
Definition: window.hpp:411
scope
Available hotkey scopes.
unsigned int get_layer_count() const
Gets the total number of layers.
void set_remember_password(bool remember)
void set_show_floating_labels(bool value)
void fullscreen_toggle_callback(twindow &window)
Definition: video.hpp:58
void set_scroll_speed(const int new_speed)
void connect_signal_notify_modified(tdispatcher &dispatcher, const tsignal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.hpp:725
Base container class.
Definition: grid.hpp:29
void show_transient_error_message(CVideo &video, const std::string &message, const std::string &image, const bool message_use_markup)
Shows a transient error message to the user.
const std::map< std::string, acquaintance > & get_acquaintances()
const int INFINITE_AUTO_SAVES
This file contains the window object, this object is a top level container which has the event manage...
void set_show_side_colors(bool value)
int scroll_speed()
#define WRN_GUI_L
Definition: log.hpp:60
std::function< void(twidget &)> make_dialog_callback(dialog_member_func_type func)
Definition: helper.hpp:50
bool select_row(const unsigned row, const bool select=true)
Selectes a row.
Definition: listbox.cpp:228
REGISTER_DIALOG(label_settings)
virtual unsigned get_value() const override
Inherited from tselectable_.
Definition: combobox.hpp:72
void initialize_members(twindow &window)
Initializers.
void set_minimum_value(const int minimum_value)
Inherited from tinteger_selector_.
Definition: slider.cpp:92
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glew.h:3783
void clear_hotkeys(const std::string &command)
Unset the command bindings for all hotkeys matching the command.
void _set_lobby_joins(int show)
virtual void set_label(const t_string &label)
Definition: control.cpp:330
void set_chat_lines(int lines)
bool idle_anim()
hotkey_ptr show_binding_dialog(CVideo &video, const std::string &id)
Stores all information related to functions that can be bound to hotkeys.
std::vector< std::pair< int, int > > get_available_resolutions(const bool include_current=false)
Returns the list of available screen resolutions.
Definition: video.cpp:576
void setup_friends_list(twindow &window)
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 set_visible_page(twindow &window, unsigned int page, const std::string &pager_id)
void set(const std::string &key, bool value)
void show_transient_message(CVideo &video, const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup, const bool restore_background)
Shows a transient message to the user.
void set_maximum_value(const int maximum_value)
Inherited from tinteger_selector_.
Definition: slider.cpp:116
void remove_friend_list_entry(tlistbox &friends_list, ttext_box &textbox, twindow &window)
void on_tab_select(twindow &window)
const std::string unicode_multiplication_sign
double turbo_speed()
void set_value(const int value)
Inherited from tinteger_selector_.
Definition: slider.cpp:77
Class for a single line text area.
Definition: text_box.hpp:118
void toggle_radio_callback(tgroup< T > &group, std::function< void(int)> setter)
bool animate_water()
void set_sound_volume(int vol)
t_string get_value_label() const
Returns the label shown for the current value.
Definition: slider.cpp:138
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
GLuint GLenum option
Definition: glew.h:2815
bool show_theme_dialog(CVideo &video)
To lexical_cast(From value)
Lexical cast converts one type to another.
static tgrid * get_advanced_row_grid(tlistbox &list, const int selected_row)
const config * game_cfg
Definition: help_impl.cpp:64
-file util.hpp
bool remove_acquaintance(const std::string &nick)
void set_interrupt_when_ally_sighted(bool value)
virtual void set_value(const std::string &text)
The set_value is virtual for the tpassword_box class.
Definition: text.cpp:95
virtual void set_active(const bool active) override
See tcontrol::set_active.
Definition: scrollbar.cpp:110
bool sound_on()
void bind_status_label(T &parent, const std::string &label_id, twidget &find_in)
Sets up a label that always displays the value of another widget.
void set_active_scopes(hk_scopes s)
void add_friend_list_entry(const bool is_friend, ttext_box &textbox, twindow &window)
void add_hotkey_callback(tlistbox &hotkeys)
bool whisper_friends_only()
void post_show(twindow &)
Actions to be taken after the window has been shown.
void setup_single_toggle(const std::string &widget_id, const bool start_value, std::function< void(bool)> callback, twidget &find_in, const bool inverted=false)
Sets the initial state and callback for a simple bool-state toggle button In the callback, the bool value of the widget is passeed to the setter.
GLdouble l
Definition: glew.h:6966
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
void setup_single_slider(const std::string &widget_id, const int start_value, std::function< void(int)> slider_callback, twidget &find_in)
Sets the initial state and callback for a standalone slider In the callback, int value of the widget ...
Class for a toggle button.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
const hotkey_list & get_hotkeys()
Returns the list of hotkeys.
std::string turn_bell
void single_toggle_callback(const ttoggle_button &widget, std::function< void(bool)> setter, const bool inverted)
The user set the widget invisible, that means:
Definition: widget.hpp:103
virtual void set_use_markup(bool use_markup)
Definition: control.cpp:342
const config & options()
static void display(CVideo &video)
The display function.
void set_turn_dialog(bool ison)
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
Dialog is closed with ok button.
Definition: window.hpp:125
auto bind_void(F fcn, P...bindings) -> decltype(boost::bind(detail::make_apply(std::function< typename detail::function_base< F >::type >(fcn)), bindings...))
Definition: functional.hpp:94
std::map< std::string, t_string > string_map
static void display(CVideo &video)
The display function.
void set_save_replays(bool value)
bool is_friend(const std::string &nick)
void set_idle_anim_rate(int rate)
This file contains the settings handling of the widget library.
unsigned get_item_count() const
Returns the number of items in the listbox.
Definition: listbox.cpp:138
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
void remove_hotkey_callback(tlistbox &hotkeys)
int get_value() const
Inherited from tinteger_selector_.
Definition: slider.hpp:48
bool get_value_bool() const
Definition: selectable.hpp:48
GLsizei const GLfloat * value
Definition: glew.h:1817
void set_enable_whiteboard_mode_on_start(bool value)
void set_turbo_speed(double speed)
void set_font_scaling(int scale)
void edit_friend_list_entry(tlistbox &friends, ttext_box &textbox)
const boost::ptr_vector< hotkey_command > & get_hotkey_commands()
returns a container that contains all currently active hotkey_commands.
void show_message(CVideo &video, const std::string &title, const std::string &message, const std::string &button_caption, const bool auto_close, const bool message_use_markup)
Shows a message to the user.
Definition: message.cpp:143
std::string selected
Definition: game_config.cpp:84
void set_music_volume(int vol)
virtual void set_active(const bool active) override
See tcontrol::set_active.
Definition: combobox.cpp:64
void set_idle_anim(bool ison)
void set_column_order(unsigned col, const std::vector< tgenerator_::torder_func > &func)
Definition: listbox.cpp:596
The user sets the widget hidden, that means:
Definition: widget.hpp:91
std::string path
Modify, read and display user preferences.
void add_hotkey(const hotkey_ptr item)
Add a hotkey to the list of hotkeys.
void handle_res_select(twindow &window)
Special callback functions.
void single_slider_callback(const tslider &widget, std::function< void(int)> setter)
void set_id(const std::string &id)
Definition: widget.cpp:97
bool UI_sound_on()
void set_bell_volume(int vol)
bool animate_map()
void status_label_callback(T &parent_widget, tcontrol &label_widget, const std::string &suffix="")
bool show_standing_animations()
const hotkey::hk_scopes scope
The visibility scope of the command.
void font_scaling_slider_callback(tslider &slider)
void set_animate_map(bool value)
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
Templates and utility-routines for strings and numbers.
std::vector< hotkey::hotkey_ptr > hotkey_list
Definition: hotkey_item.hpp:37
static void display(CVideo &video)
The display function.
Definition: logging.hpp:37
std::string get_value_string() const
Returns the value of the selected row.
Definition: combobox.hpp:87
static std::string get_max_autosaves_status_label(const tslider &slider)
void set_chat_timestamping(bool value)
int idle_anim_rate()
void connect_click_handler(const event::tsignal_function &signal)
Inherited from tclickable.
Definition: combobox.hpp:48
bool add_friend(const std::string &nick, const std::string &notes)
bool add_ignore(const std::string &nick, const std::string &reason)
void set_UI_volume(int vol)
void animate_map_toggle_callback(ttoggle_button &toggle, ttoggle_button &toggle_water)
GLuint res
Definition: glew.h:9258
The user sets the widget visible, that means:
Definition: widget.hpp:79
static bool fullscreen(CVideo &video)
Definition: lobby.cpp:400
bool interrupt_when_ally_sighted()
void set_values(const std::vector< std::string > &values, int selected=0)
Definition: combobox.cpp:165
const std::string command
The command is unique.
GLuint index
Definition: glew.h:1782
void set_delete_saves(bool value)
void on_advanced_prefs_list_select(tlistbox &tree, twindow &window)
bool music_on()
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
size_t i
Definition: function.cpp:1057
twidget * swap_child(const std::string &id, twidget *widget, const bool recurse, twidget *new_parent=nullptr)
Exchanges a child in the grid.
Definition: grid.cpp:99
bool set_UI_sound(bool ison)
void set_whisper_friends_only(bool v)
Declarations for File-IO.
std::string get_names(std::string id)
Returns a comma-separated string of hotkey names.
static int sort(lua_State *L)
Definition: ltablib.cpp:246
static int index_in_pager_range(const int &first, const tstacked_widget &pager)
const std::string & get_description(const std::string &command)
void initialize_tabs(twindow &window, tlistbox &selector, const int index)
std::string vgettext(const char *msgid, const utils::string_map &symbols)
Base class for all visible items.
Definition: control.hpp:34
void set_autosavemax(int value)
Simple push button.
Definition: combobox.hpp:31
int sound_volume()
bool show_floating_labels()
void max_autosaves_slider_callback(tslider &slider, tcontrol &status_label)
void setup_hotkey_list(twindow &window)
void toggle_slider_pair_callback(const ttoggle_button &toggle_widget, tslider &slider_widget, std::function< void(bool)> setter)
int font_scaling()
void add_tab(tlistbox &tab_bar, const std::string &label)
GLenum GLint ref
Definition: glew.h:1813
GLboolean GLuint group
Definition: glew.h:2589
bool find(E event, F functor)
Tests whether an event handler is available.
bool enable_whiteboard_mode_on_start()
Base class for all widgets.
Definition: widget.hpp:49
this module manages the cache of images.
Definition: image.cpp:75
bool set_music(bool ison)
void setup_radio_toggle(const std::string &toggle_id, const T &enum_value, const int start_value, tgroup< T > &group, std::function< void(int)> callback, twindow &window)
bool set_turn_bell(bool ison)
GLint * first
Definition: glew.h:1496
void set_show_ai_moves(bool value)
void set_callback_value_change(const std::function< void(twidget &)> &callback)
Definition: listbox.hpp:225
static void set_label(twindow &window, const std::string &id, const std::string &label)
Definition: unit_attack.cpp:89
void add_pager_row(tlistbox &selector, const std::string &icon, const std::string &label)
twidget * find(const std::string &id, const bool must_be_active) override
See twidget::find.
Definition: grid.cpp:612
void add_member(tselectable_ *widget, const T &value)
Adds a widget/value pair to the group vector.
Definition: group.hpp:43
void on_page_select(twindow &window)
Callback for selection changes.
void set_definition(const std::string &definition)
Sets the definition.
Definition: control.cpp:318
const std::string & text() const
Definition: text.hpp:81
twindow * get_window()
Get the parent window.
Definition: widget.cpp:116
A slider.
Definition: slider.hpp:30
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
void set_value(const unsigned selected)
Inherited from tselectable_.
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:237
void set_animate_water(bool value)
bool file_exists(const std::string &name)
Returns true if a file or directory with such name already exists.
void set_visible(const tvisible::scoped_enum visible)
Definition: widget.cpp:445
static void set_resolution_list(tcombobox &res_list, CVideo &video)
GLsizei const GLcharARB ** string
Definition: glew.h:4503
static void display(CVideo &video)
The display function.
void dialog_callback(twidget &caller)
Template for dialog callbacks.
Definition: helper.hpp:31
void pre_show(twindow &window)
Inherited from tdialog.
Shows a yes and no button.
Definition: message.hpp:75
void clear()
Removes all the rows in the listbox, clearing it.
Definition: listbox.cpp:131
const tgrid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
Definition: listbox.cpp:215
int music_volume()
void invalidate_layout()
Updates the size of the window.
Definition: window.cpp:941
void set_disable_auto_moves(bool value)
static void display(CVideo &video)
The display function.
void _set_iconize_list(bool sort)