The Battle for Wesnoth  1.17.4+dev
general.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2022
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://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 /**
17  * @file
18  * Get and set user-preferences.
19  */
20 
21 #define GETTEXT_DOMAIN "wesnoth-lib"
22 
23 #include "preferences/general.hpp"
24 
25 #include "config.hpp"
26 #include "credentials.hpp"
27 #include "filesystem.hpp"
28 #include "game_config.hpp"
29 #include "hotkey/hotkey_item.hpp"
30 #include "lexical_cast.hpp"
31 #include "log.hpp"
32 #include "sdl/point.hpp"
33 #include "serialization/parser.hpp"
34 #include "sound.hpp"
35 #include "video.hpp" // non_interactive()
36 #include "game_config_view.hpp"
37 
38 #include <sys/stat.h> // for setting the permissions of the preferences file
39 #ifndef _WIN32
40 #include <unistd.h>
41 #endif
42 
43 static lg::log_domain log_config("config");
44 #define ERR_CFG LOG_STREAM(err , log_config)
45 
46 static lg::log_domain log_filesystem("filesystem");
47 #define ERR_FS LOG_STREAM(err, log_filesystem)
48 
49 namespace {
50 
51 bool no_preferences_save = false;
52 
53 bool fps = false;
54 
56 }
57 
58 namespace preferences {
59 
60 /*
61  * Stores all the static, default values for certain game preferences. The values
62  * are kept here for easy modification without a lengthy rebuild.
63  *
64  * Add any variables of similar type here.
65  */
66 const int min_window_width = 800;
67 const int min_window_height = 540;
68 
69 const int def_window_width = 1280;
70 const int def_window_height = 720;
71 
72 const int max_window_width = 1920;
73 const int max_window_height = 1080;
74 
75 const int min_font_scaling = 80;
76 const int max_font_scaling = 150;
77 
78 const int min_pixel_scale = 1;
79 const int max_pixel_scale = 4;
80 
82 public:
83  virtual void handle_event(const SDL_Event &) {}
84  virtual void handle_window_event(const SDL_Event &event);
86 };
87 
89 
91 {
92  event_handler_.join_global();
93 
96 }
97 
99 {
100  event_handler_.leave_global();
101 
102  try {
103  if (no_preferences_save) return;
104 
105  // Set the 'hidden' preferences.
106  prefs["scroll_threshold"] = mouse_scroll_threshold();
107 
109  } catch (...) {}
110 }
111 
112 /*
113  * Hook for setting window state variables on window resize and maximize
114  * events. Since there is no fullscreen window event, that setter is called
115  * from the CVideo function instead.
116  */
117 void prefs_event_handler::handle_window_event(const SDL_Event& event)
118 {
119 
120  // Safety check to make sure this is a window event
121  if (event.type != SDL_WINDOWEVENT) return;
122 
123  switch(event.window.event) {
124  case SDL_WINDOWEVENT_RESIZED:
125  _set_resolution(CVideo::get_singleton().window_size());
126 
127  break;
128 
129  case SDL_WINDOWEVENT_MAXIMIZED:
130  _set_maximized(true);
131 
132  break;
133 
134  case SDL_WINDOWEVENT_RESTORED:
135  _set_maximized(fullscreen() || false);
136 
137  break;
138  }
139 }
140 
142 {
143 #ifndef _WIN32
144  bool prefs_file_existed = access(filesystem::get_prefs_file().c_str(), F_OK) == 0;
145 #endif
146 
147  try {
149  write(*prefs_file, prefs);
150  } catch(const filesystem::io_exception&) {
151  ERR_FS << "error writing to preferences file '" << filesystem::get_prefs_file() << "'" << std::endl;
152  }
153 
155 
156 #ifndef _WIN32
157  if(!prefs_file_existed) {
158 
159  if(chmod(filesystem::get_prefs_file().c_str(), 0600) == -1) {
160  ERR_FS << "error setting permissions of preferences file '" << filesystem::get_prefs_file() << "'" << std::endl;
161  }
162 
163  }
164 #endif
165 }
166 
167 void set(const std::string &key, bool value)
168 {
169  prefs[key] = value;
170 }
171 
172 void set(const std::string &key, int value)
173 {
174  prefs[key] = value;
175 }
176 
177 void set(const std::string &key, char const *value)
178 {
179  prefs[key] = value;
180 }
181 
182 void set(const std::string &key, const std::string &value)
183 {
184  prefs[key] = value;
185 }
186 
187 void set(const std::string &key, const config::attribute_value &value)
188 {
189  prefs[key] = value;
190 }
191 
192 void clear(const std::string& key)
193 {
194  prefs.recursive_clear_value(key);
195 }
196 
197 void set_child(const std::string& key, const config& val) {
198  prefs.clear_children(key);
199  prefs.add_child(key, val);
200 }
201 
202 const config &get_child(const std::string& key)
203 {
204  return prefs.child(key);
205 }
206 
207 void erase(const std::string& key) {
208  prefs.remove_attribute(key);
209 }
210 
211 bool have_setting(const std::string& key) {
212  return prefs.has_attribute(key);
213 }
214 
215 std::string get(const std::string& key) {
216  return prefs[key];
217 }
218 
219 std::string get(const std::string& key, const std::string& def) {
220  return prefs[key].empty() ? def : prefs[key];
221 }
222 
223 bool get(const std::string &key, bool def)
224 {
225  return prefs[key].to_bool(def);
226 }
227 
229 {
230  return prefs[key];
231 }
232 
234  no_preferences_save = true;
235 }
236 
238  config* pointer = &prefs;
239  return pointer;
240 }
241 
243  try{
244 #ifdef DEFAULT_PREFS_PATH
246  read(prefs, *stream);
247 
248  config user_prefs;
250  read(user_prefs, *stream);
251 
252  prefs.merge_with(user_prefs);
253 #else
254  prefs.clear();
256  read(prefs, *stream);
257 #endif
258  } catch(const config::error& e) {
259  ERR_CFG << "Error loading preference, message: "
260  << e.what()
261  << std::endl;
262  }
263 }
264 
265 
267  return get("show_ally_orb", game_config::show_ally_orb);
268 }
269 void set_show_allied_orb(bool show_orb) {
270  prefs["show_ally_orb"] = show_orb;
271 }
272 
274  return get("show_enemy_orb", game_config::show_enemy_orb);
275 }
276 void set_show_enemy_orb(bool show_orb) {
277  prefs["show_enemy_orb"] = show_orb;
278 }
279 
281  return get("show_moved_orb", game_config::show_moved_orb);
282 }
283 void set_show_moved_orb(bool show_orb) {
284  prefs["show_moved_orb"] = show_orb;
285 }
286 
288  return get("show_unmoved_orb", game_config::show_unmoved_orb);
289 }
290 void set_show_unmoved_orb(bool show_orb) {
291  prefs["show_unmoved_orb"] = show_orb;
292 }
293 
295  return get("show_partial_orb", game_config::show_partial_orb);
296 }
297 void set_show_partial_orb(bool show_orb) {
298  prefs["show_partial_orb"] = show_orb;
299 }
300 
302  return get("show_disengaged_orb", game_config::show_disengaged_orb);
303 }
304 void set_show_disengaged_orb(bool show_orb) {
305  prefs["show_disengaged_orb"] = show_orb;
306 }
307 
308 static std::string fix_orb_color_name(const std::string& color) {
309  if (color.substr(0,4) == "orb_") {
310  if(color[4] >= '0' && color[4] <= '9') {
311  return color.substr(5);
312  } else {
313  return color.substr(4);
314  }
315  }
316  return color;
317 }
318 
319 std::string allied_color() {
320  std::string ally_color = get("ally_orb_color");
321  if (ally_color.empty())
323  return fix_orb_color_name(ally_color);
324 }
325 void set_allied_color(const std::string& color_id) {
326  prefs["ally_orb_color"] = color_id;
327 }
328 
329 std::string core_id() {
330  std::string core_id = get("core");
331  if (core_id.empty())
332  return "default";
333  return core_id;
334 }
335 void set_core_id(const std::string& core_id) {
336  prefs["core"] = core_id;
337 }
338 
339 std::string enemy_color() {
340  std::string enemy_color = get("enemy_orb_color");
341  if (enemy_color.empty())
343  return fix_orb_color_name(enemy_color);
344 }
345 void set_enemy_color(const std::string& color_id) {
346  prefs["enemy_orb_color"] = color_id;
347 }
348 
349 std::string moved_color() {
350  std::string moved_color = get("moved_orb_color");
351  if (moved_color.empty())
353  return fix_orb_color_name(moved_color);
354 }
355 void set_moved_color(const std::string& color_id) {
356  prefs["moved_orb_color"] = color_id;
357 }
358 
359 std::string unmoved_color() {
360  std::string unmoved_color = get("unmoved_orb_color");
361  if (unmoved_color.empty())
363  return fix_orb_color_name(unmoved_color);
364 }
365 void set_unmoved_color(const std::string& color_id) {
366  prefs["unmoved_orb_color"] = color_id;
367 }
368 
369 std::string partial_color() {
370  std::string partmoved_color = get("partial_orb_color");
371  if (partmoved_color.empty())
373  return fix_orb_color_name(partmoved_color);
374 }
375 void set_partial_color(const std::string& color_id) {
376  prefs["partial_orb_color"] = color_id;
377 }
378 
379 std::string disengaged_color() {
380  std::string disengaged_color = get("disengaged_orb_color");
381  if (disengaged_color.empty())
383  return fix_orb_color_name(disengaged_color);
384 }
385 void set_disengaged_color(const std::string& color_id) {
386  prefs["disengaged_orb_color"] = color_id;
387 }
388 
390 {
391  return get("scroll_to_action", true);
392 }
393 
394 void set_scroll_to_action(bool ison)
395 {
396  prefs["scroll_to_action"] = ison;
397 }
398 
400 {
401  const unsigned x_res = prefs["xresolution"].to_unsigned();
402  const unsigned y_res = prefs["yresolution"].to_unsigned();
403 
404  // Either resolution was unspecified, return default.
405  if(x_res == 0 || y_res == 0) {
406  return point(def_window_width, def_window_height);
407  }
408 
409  return point(
410  std::max<unsigned>(x_res, min_window_width),
411  std::max<unsigned>(y_res, min_window_height)
412  );
413 }
414 
416 {
417  // For now this has a minimum value of 1 and a maximum of 4.
418  return std::max<int>(std::min<int>(prefs["pixel_scale"].to_int(1), max_pixel_scale), min_pixel_scale);
419 }
420 
421 void set_pixel_scale(const int scale)
422 {
423  prefs["pixel_scale"] = std::clamp(scale, min_pixel_scale, max_pixel_scale);
424 }
425 
427 {
428  return get("auto_pixel_scale", true);
429 }
430 
431 void set_auto_pixel_scale(bool choice)
432 {
433  prefs["auto_pixel_scale"] = choice;
434 }
435 
436 bool maximized()
437 {
438  return get("maximized", !fullscreen());
439 }
440 
442 {
443  return get("fullscreen", true);
444 }
445 
446 bool vsync()
447 {
448  return get("vsync", true);
449 }
450 
451 void _set_resolution(const point& res)
452 {
453  preferences::set("xresolution", std::to_string(res.x));
454  preferences::set("yresolution", std::to_string(res.y));
455 }
456 
457 void _set_maximized(bool ison)
458 {
459  prefs["maximized"] = ison;
460 }
461 
462 void _set_fullscreen(bool ison)
463 {
464  prefs["fullscreen"] = ison;
465 }
466 
467 void set_vsync(bool ison)
468 {
469  prefs["vsync"] = ison;
470 }
471 
472 bool turbo()
473 {
474  if(CVideo::get_singleton().non_interactive()) {
475  return true;
476  }
477 
478  return get("turbo", false);
479 }
480 
481 void set_turbo(bool ison)
482 {
483  prefs["turbo"] = ison;
484 }
485 
486 double turbo_speed()
487 {
488  return prefs["turbo_speed"].to_double(2.0);
489 }
490 
491 void set_turbo_speed(const double speed)
492 {
493  prefs["turbo_speed"] = speed;
494 }
495 
497 {
498  // Clip at 80 because if it's too low it'll cause crashes
499  return std::max<int>(std::min<int>(prefs["font_scale"].to_int(100), max_font_scaling), min_font_scaling);
500 }
501 
503 {
504  prefs["font_scale"] = std::clamp(scale, min_font_scaling, max_font_scaling);
505 }
506 
508 {
509  return (size * font_scaling()) / 100;
510 }
511 
512 bool idle_anim()
513 {
514  return get("idle_anim", true);
515 }
516 
517 void set_idle_anim(const bool ison)
518 {
519  prefs["idle_anim"] = ison;
520 }
521 
523 {
524  return prefs["idle_anim_rate"].to_double(1.0);
525 }
526 
527 void set_idle_anim_rate(const int rate)
528 {
529  prefs["idle_anim_rate"] = std::pow(2.0, -rate / 10.0);
530 }
531 
532 std::string language()
533 {
534  return prefs["locale"];
535 }
536 
537 void set_language(const std::string& s)
538 {
539  preferences::set("locale", s);
540 }
541 
542 std::string gui_theme()
543 {
544  return prefs["gui2_theme"];
545 }
546 
547 void set_gui_theme(const std::string& s)
548 {
549  preferences::set("gui2_theme", s);
550 }
551 
552 bool ellipses()
553 {
554  return get("show_side_colors", false);
555 }
556 
557 void set_ellipses(bool ison)
558 {
559  preferences::set("show_side_colors", ison);
560 }
561 
562 bool grid()
563 {
564  return get("grid", false);
565 }
566 
567 void set_grid(bool ison)
568 {
569  preferences::set("grid", ison);
570 }
571 
572 std::size_t sound_buffer_size()
573 {
574  // Sounds don't sound good on Windows unless the buffer size is 4k,
575  // but this seems to cause crashes on other systems...
576  #ifdef _WIN32
577  const std::size_t buf_size = 4096;
578  #else
579  const std::size_t buf_size = 1024;
580  #endif
581 
582  return prefs["sound_buffer_size"].to_int(buf_size);
583 }
584 
585 void save_sound_buffer_size(const std::size_t size)
586 {
587  #ifdef _WIN32
588  const char* buf_size = "4096";
589  #else
590  const char* buf_size = "1024";
591  #endif
592 
593  const std::string new_size = lexical_cast_default<std::string>(size, buf_size);
594  if (get("sound_buffer_size") == new_size)
595  return;
596 
597  preferences::set("sound_buffer_size", new_size);
598 
600 }
601 
603 {
604  return prefs["music_volume"].to_int(100);
605 }
606 
607 void set_music_volume(int vol)
608 {
609  if(music_volume() == vol) {
610  return;
611  }
612 
613  prefs["music_volume"] = vol;
615 }
616 
618 {
619  return prefs["sound_volume"].to_int(100);
620 }
621 
622 void set_sound_volume(int vol)
623 {
624  if(sound_volume() == vol) {
625  return;
626  }
627 
628  prefs["sound_volume"] = vol;
630 }
631 
633 {
634  return prefs["bell_volume"].to_int(100);
635 }
636 
637 void set_bell_volume(int vol)
638 {
639  if(bell_volume() == vol) {
640  return;
641  }
642 
643  prefs["bell_volume"] = vol;
645 }
646 
648 {
649  return prefs["UI_volume"].to_int(100);
650 }
651 
652 void set_UI_volume(int vol)
653 {
654  if(UI_volume() == vol) {
655  return;
656  }
657 
658  prefs["UI_volume"] = vol;
660 }
661 
662 unsigned int tile_size()
663 {
664  return prefs["tile_size"].to_unsigned();
665 }
666 
667 void set_tile_size(const unsigned int size)
668 {
669  prefs["tile_size"] = size;
670 }
671 
672 bool turn_bell()
673 {
674  return get("turn_bell", true);
675 }
676 
677 bool set_turn_bell(bool ison)
678 {
679  if(!turn_bell() && ison) {
680  preferences::set("turn_bell", true);
681  if(!music_on() && !sound_on() && !UI_sound_on()) {
682  if(!sound::init_sound()) {
683  preferences::set("turn_bell", false);
684  return false;
685  }
686  }
687  } else if(turn_bell() && !ison) {
688  preferences::set("turn_bell", false);
690  if(!music_on() && !sound_on() && !UI_sound_on())
692  }
693  return true;
694 }
695 
697 {
698  return get("UI_sound", true);
699 }
700 
701 bool set_UI_sound(bool ison)
702 {
703  if(!UI_sound_on() && ison) {
704  preferences::set("UI_sound", true);
705  if(!music_on() && !sound_on() && !turn_bell()) {
706  if(!sound::init_sound()) {
707  preferences::set("UI_sound", false);
708  return false;
709  }
710  }
711  } else if(UI_sound_on() && !ison) {
712  preferences::set("UI_sound", false);
714  if(!music_on() && !sound_on() && !turn_bell())
716  }
717  return true;
718 }
719 
721 {
722  return get("message_bell", true);
723 }
724 
725 bool sound_on()
726 {
727  return get("sound", true);
728 }
729 
730 bool set_sound(bool ison) {
731  if(!sound_on() && ison) {
732  preferences::set("sound", true);
733  if(!music_on() && !turn_bell() && !UI_sound_on()) {
734  if(!sound::init_sound()) {
735  preferences::set("sound", false);
736  return false;
737  }
738  }
739  } else if(sound_on() && !ison) {
740  preferences::set("sound", false);
742  if(!music_on() && !turn_bell() && !UI_sound_on())
744  }
745  return true;
746 }
747 
748 bool music_on()
749 {
750  return get("music", true);
751 }
752 
753 bool set_music(bool ison) {
754  if(!music_on() && ison) {
755  preferences::set("music", true);
756  if(!sound_on() && !turn_bell() && !UI_sound_on()) {
757  if(!sound::init_sound()) {
758  preferences::set("music", false);
759  return false;
760  }
761  }
762  else
764  } else if(music_on() && !ison) {
765  preferences::set("music", false);
766  if(!sound_on() && !turn_bell() && !UI_sound_on())
768  else
770  }
771  return true;
772 }
773 
775 {
776  return get("stop_music_in_background", false);
777 }
778 
780 {
781  preferences::set("stop_music_in_background", ison);
782 }
783 
784 namespace {
785  double scroll = 0.2;
786 }
787 
789 {
790  const int value = std::clamp<int>(lexical_cast_default<int>(get("scroll"), 50), 1, 100);
791  scroll = value/100.0;
792 
793  return value;
794 }
795 
796 void set_scroll_speed(const int new_speed)
797 {
798  prefs["scroll"] = new_speed;
799  scroll = new_speed / 100.0;
800 }
801 
803 {
804  return get("middle_click_scrolls", true);
805 }
806 
808 {
809  return get("mouse_scrolling", true);
810 }
811 
812 void enable_mouse_scroll(bool value)
813 {
814  set("mouse_scrolling", value);
815 }
816 
818 {
819  return prefs["scroll_threshold"].to_int(10);
820 }
821 
823 {
824  return preferences::get("animate_map", true);
825 }
826 
828 {
829  return preferences::get("animate_water", true);
830 }
831 
833 {
834  return preferences::get("minimap_movement_coding", true);
835 }
836 
838 {
839  set("minimap_movement_coding", !minimap_movement_coding());
840 }
841 
843 {
844  return preferences::get("minimap_terrain_coding", true);
845 }
846 
848 {
849  set("minimap_terrain_coding", !minimap_terrain_coding());
850 }
851 
853 {
854  return preferences::get("minimap_draw_units", true);
855 }
856 
858 {
859  set("minimap_draw_units", !minimap_draw_units());
860 }
861 
863 {
864  return preferences::get("minimap_draw_villages", true);
865 }
866 
868 {
869  set("minimap_draw_villages", !minimap_draw_villages());
870 }
871 
873 {
874  return preferences::get("minimap_draw_terrain", true);
875 }
876 
878 {
879  set("minimap_draw_terrain", !minimap_draw_terrain());
880 }
881 
882 void set_animate_map(bool value)
883 {
884  set("animate_map", value);
885 }
886 
887 void set_animate_water(bool value)
888 {
889  set("animate_water", value);
890 }
891 
892 bool show_fps()
893 {
894  return fps;
895 }
896 
897 void set_show_fps(bool value)
898 {
899  fps = value;
900 }
901 
903 {
904  return prefs["draw_delay"].to_int(-1);
905 }
906 
907 void set_draw_delay(int value)
908 {
909  prefs["draw_delay"] = value;
910 }
911 
913 {
914  return get("color_cursors", true);
915 }
916 
917 void _set_color_cursors(bool value)
918 {
919  preferences::set("color_cursors", value);
920 }
921 
923 {
925 }
926 
928 {
930 }
931 
933 {
935  prefs.clear_children("hotkey");
936 }
937 
938 void add_alias(const std::string &alias, const std::string &command)
939 {
940  config &alias_list = prefs.child_or_add("alias");
941  alias_list[alias] = command;
942 }
943 
944 
946 {
947  return get_child("alias");
948 }
949 
950 unsigned int sample_rate()
951 {
952  return prefs["sample_rate"].to_int(44100);
953 }
954 
955 void save_sample_rate(const unsigned int rate)
956 {
957  if (sample_rate() == rate)
958  return;
959 
960  prefs["sample_rate"] = static_cast<int>(rate);
961 
962  // If audio is open, we have to re set sample rate
964 }
965 
967 {
968  return get("confirm_load_save_from_different_version", true);
969 }
970 
972 {
973  return get("use_twelve_hour_clock_format", false);
974 }
975 
977 {
978  return get("disable_auto_moves", false);
979 }
980 
981 void set_disable_auto_moves(bool value)
982 {
983  preferences::set("disable_auto_moves", value);
984 }
985 
987 {
988  return get("damage_prediction_allow_monte_carlo_simulation", true);
989 }
990 
992 {
993  set("damage_prediction_allow_monte_carlo_simulation", value);
994 }
995 
997 {
998  return get("addon_manager_saved_order_name");
999 }
1000 
1001 void set_addon_manager_saved_order_name(const std::string& value)
1002 {
1003  set("addon_manager_saved_order_name", value);
1004 }
1005 
1007 {
1008  return sort_order::get_enum(get("addon_manager_saved_order_direction")).value_or(sort_order::type::none);
1009 }
1010 
1012 {
1013  set("addon_manager_saved_order_direction", sort_order::get_string(value));
1014 }
1015 
1016 
1017 } // end namespace preferences
bool disable_auto_moves()
Definition: general.cpp:976
void set_turbo(bool ison)
Definition: general.cpp:481
bool set_sound(bool ison)
Definition: general.cpp:730
void set_show_enemy_orb(bool show_orb)
Definition: general.cpp:276
std::string unmoved_color()
Definition: general.cpp:359
void close_sound()
Definition: sound.cpp:495
void _set_fullscreen(bool ison)
Definition: general.cpp:462
void set_grid(bool ison)
Definition: general.cpp:567
int bell_volume()
Definition: general.cpp:632
bool turn_bell()
Definition: general.cpp:672
std::string addon_manager_saved_order_name()
Definition: general.cpp:996
bool show_unmoved_orb
void set_moved_color(const std::string &color_id)
Definition: general.cpp:355
void save_hotkeys()
Definition: general.cpp:927
bool minimap_draw_units()
Definition: general.cpp:852
const int min_window_height
Definition: general.cpp:67
void set_allied_color(const std::string &color_id)
Definition: general.cpp:325
bool show_fps()
Definition: general.cpp:892
void set_unmoved_color(const std::string &color_id)
Definition: general.cpp:365
void stop_music()
Definition: sound.cpp:557
void write_preferences()
Definition: general.cpp:141
void _set_maximized(bool ison)
Definition: general.cpp:457
int mouse_scroll_threshold()
Gets the threshold for when to scroll.
Definition: general.cpp:817
void disable_preferences_save()
Definition: general.cpp:233
void save_hotkeys(config &cfg)
Save the non-default hotkeys to the config.
void set_show_unmoved_orb(bool show_orb)
Definition: general.cpp:290
Variant for storing WML attributes.
void _set_color_cursors(bool value)
Definition: general.cpp:917
const int min_window_width
Definition: general.cpp:66
static game_config_view wrap(const config &cfg)
New lexcical_cast header.
int draw_delay()
Definition: general.cpp:902
void set_scroll_speed(const int new_speed)
Definition: general.cpp:796
bool minimap_movement_coding()
Definition: general.cpp:832
const int max_window_width
Definition: general.cpp:72
void set_UI_volume(int vol)
Definition: sound.cpp:1120
bool show_enemy_orb()
Definition: general.cpp:273
void set_idle_anim_rate(const int rate)
Definition: general.cpp:527
int scroll_speed()
Definition: general.cpp:788
bool vsync()
Definition: general.cpp:446
prefs_event_handler event_handler_
Definition: general.cpp:88
filesystem::scoped_istream istream_file(const std::string &fname, bool treat_failure_as_error)
void _set_resolution(const point &res)
Definition: general.cpp:451
void enable_mouse_scroll(bool value)
Definition: general.cpp:812
bool show_allied_orb()
Definition: general.cpp:266
void clear(const std::string &key)
Definition: general.cpp:192
virtual void leave_global()
Definition: events.cpp:383
bool idle_anim()
Definition: general.cpp:512
bool message_bell()
Definition: general.cpp:720
std::string gui_theme()
Definition: general.cpp:542
void set_tile_size(const unsigned int size)
Definition: general.cpp:667
void stop_sound()
Definition: sound.cpp:565
static CVideo & get_singleton()
Definition: video.hpp:52
void set(const std::string &key, bool value)
Definition: general.cpp:167
unsigned int sample_rate()
Definition: general.cpp:950
sort_order::type addon_manager_saved_order_direction()
Definition: general.cpp:1006
double turbo_speed()
Definition: general.cpp:486
bool confirm_load_save_from_different_version()
Definition: general.cpp:966
bool animate_water()
Definition: general.cpp:827
std::string enemy_orb_color
void set_sound_volume(int vol)
Definition: general.cpp:622
void save_credentials()
bool show_enemy_orb
std::string disengaged_color()
Definition: general.cpp:379
Definitions for the interface to Wesnoth Markup Language (WML).
bool ellipses()
Definition: general.cpp:552
void load_base_prefs()
Definition: general.cpp:242
bool sound_on()
Definition: general.cpp:725
filesystem::scoped_ostream ostream_file(const std::string &fname, std::ios_base::openmode mode, bool create_directory)
bool show_ally_orb
bool maximized()
Definition: general.cpp:436
std::string disengaged_orb_color
int x
x coordinate.
Definition: point.hpp:45
bool init_sound()
Definition: sound.cpp:443
#define ERR_FS
Definition: general.cpp:47
void reset_sound()
Definition: sound.cpp:526
bool minimap_draw_villages()
Definition: general.cpp:862
void write(std::ostream &out, const configr_of &cfg, unsigned int level)
Definition: parser.cpp:764
std::string ally_orb_color
void set_bell_volume(int vol)
Definition: sound.cpp:1108
std::string get(const std::string &key)
Definition: general.cpp:215
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:87
void set_enemy_color(const std::string &color_id)
Definition: general.cpp:345
void scale(size_t factor, const uint32_t *src, uint32_t *trg, int srcWidth, int srcHeight, const ScalerCfg &cfg=ScalerCfg(), int yFirst=0, int yLast=std::numeric_limits< int >::max())
Definition: xbrz.cpp:1190
void load_hotkeys()
Definition: general.cpp:922
void toggle_minimap_draw_units()
Definition: general.cpp:857
virtual void handle_window_event(const SDL_Event &event)
Definition: general.cpp:117
void read(config &cfg, std::istream &in, abstract_validator *validator)
Definition: parser.cpp:627
bool show_disengaged_orb()
Definition: general.cpp:301
const int min_font_scaling
Definition: general.cpp:75
static lg::log_domain log_config("config")
void stop_UI_sound()
Definition: sound.cpp:592
bool fullscreen()
Definition: general.cpp:441
const int min_pixel_scale
Definition: general.cpp:78
void set_font_scaling(int scale)
Definition: general.cpp:502
void set_music_volume(int vol)
Definition: general.cpp:607
void play_music()
Definition: sound.cpp:617
int font_scaled(int size)
Definition: general.cpp:507
void set_vsync(bool ison)
Definition: general.cpp:467
void set_show_fps(bool value)
Definition: general.cpp:897
void set_partial_color(const std::string &color_id)
Definition: general.cpp:375
void erase(const std::string &key)
Definition: general.cpp:207
std::unique_ptr< std::istream > scoped_istream
Definition: filesystem.hpp:39
sdl_handler(sdl_handler &&)=delete
void set_show_partial_orb(bool show_orb)
Definition: general.cpp:297
void set_core_id(const std::string &core_id)
Definition: general.cpp:335
config::attribute_value get_as_attribute(const std::string &key)
Definition: general.cpp:228
Modify, read and display user preferences.
void toggle_minimap_draw_terrain()
Definition: general.cpp:877
bool UI_sound_on()
Definition: general.cpp:696
void set_bell_volume(int vol)
Definition: general.cpp:637
void set_stop_music_in_background(bool ison)
Definition: general.cpp:779
bool animate_map()
Definition: general.cpp:822
const int max_pixel_scale
Definition: general.cpp:79
void set_idle_anim(const bool ison)
Definition: general.cpp:517
bool damage_prediction_allow_monte_carlo_simulation()
Definition: general.cpp:986
void set_animate_map(bool value)
Definition: general.cpp:882
const char * what() const noexcept
Definition: exceptions.hpp:36
std::string moved_orb_color
int pixel_scale()
Definition: general.cpp:415
void set_sound_volume(int vol)
Definition: sound.cpp:1088
std::string get_default_prefs_file()
void set_show_moved_orb(bool show_orb)
Definition: general.cpp:283
bool show_moved_orb()
Definition: general.cpp:280
void set_music_volume(int vol)
Definition: sound.cpp:1068
void set_draw_delay(int value)
Definition: general.cpp:907
void toggle_minimap_draw_villages()
Definition: general.cpp:867
#define ERR_CFG
Definition: general.cpp:44
const int max_font_scaling
Definition: general.cpp:76
void set_UI_volume(int vol)
Definition: general.cpp:652
void set_child(const std::string &key, const config &val)
Definition: general.cpp:197
static std::string fix_orb_color_name(const std::string &color)
Definition: general.cpp:308
std::unique_ptr< std::ostream > scoped_ostream
Definition: filesystem.hpp:40
const int def_window_width
Definition: general.cpp:69
void save_sample_rate(const unsigned int rate)
Definition: general.cpp:955
std::string allied_color()
Definition: general.cpp:319
void add_alias(const std::string &alias, const std::string &command)
Definition: general.cpp:938
static lg::log_domain log_filesystem("filesystem")
std::string unmoved_orb_color
double idle_anim_rate()
Definition: general.cpp:522
void clear_hotkeys()
Definition: general.cpp:932
std::string moved_color()
Definition: general.cpp:349
unsigned int tile_size()
Definition: general.cpp:662
void toggle_minimap_terrain_coding()
Definition: general.cpp:847
bool middle_click_scrolls()
Definition: general.cpp:802
An exception object used when an IO error occurs.
Definition: filesystem.hpp:48
bool stop_music_in_background()
Definition: general.cpp:774
static map_location::DIRECTION s
static std::string get_string(typename T::type key)
Uses the int value of the provided enum to get the associated index of the values array in the implem...
Definition: enum_base.hpp:41
bool music_on()
Definition: general.cpp:748
bool use_color_cursors()
Definition: general.cpp:912
void toggle_minimap_movement_coding()
Definition: general.cpp:837
Holds a 2D point.
Definition: point.hpp:24
bool set_UI_sound(bool ison)
Definition: general.cpp:701
std::string language()
Definition: general.cpp:532
config * get_prefs()
Definition: general.cpp:237
bool show_moved_orb
Declarations for File-IO.
void stop_bell()
Definition: sound.cpp:580
void set_turbo_speed(const double speed)
Definition: general.cpp:491
void set_scroll_to_action(bool ison)
Definition: general.cpp:394
void set_ellipses(bool ison)
Definition: general.cpp:557
void save_sound_buffer_size(const std::size_t size)
Definition: general.cpp:585
const config & get_child(const std::string &key)
Definition: general.cpp:202
void reset_default_hotkeys()
Reset all hotkeys to the defaults.
std::size_t sound_buffer_size()
Definition: general.cpp:572
std::string core_id()
Definition: general.cpp:329
void set_language(const std::string &s)
Definition: general.cpp:537
bool grid()
Definition: general.cpp:562
const int def_window_height
Definition: general.cpp:70
bool mouse_scroll_enabled()
Definition: general.cpp:807
std::string partial_color()
Definition: general.cpp:369
int sound_volume()
Definition: general.cpp:617
bool have_setting(const std::string &key)
Definition: general.cpp:211
int font_scaling()
Definition: general.cpp:496
static std::optional< typename T::type > get_enum(const std::string value)
Convert a string into its enum equivalent.
Definition: enum_base.hpp:52
bool minimap_draw_terrain()
Definition: general.cpp:872
void set_show_disengaged_orb(bool show_orb)
Definition: general.cpp:304
void load_credentials()
bool set_music(bool ison)
Definition: general.cpp:753
Standard logging facilities (interface).
bool set_turn_bell(bool ison)
Definition: general.cpp:677
bool turbo()
Definition: general.cpp:472
bool scroll_to_action()
Definition: general.cpp:389
virtual void handle_event(const SDL_Event &)
Definition: general.cpp:83
point resolution()
Definition: general.cpp:399
#define e
bool show_partial_orb
void load_hotkeys(const game_config_view &cfg, bool set_as_default)
Iterates through all hotkeys present in the config struct and creates and adds them to the hotkey lis...
int UI_volume()
Definition: general.cpp:647
bool show_unmoved_orb()
Definition: general.cpp:287
void set_damage_prediction_allow_monte_carlo_simulation(bool value)
Definition: general.cpp:991
std::string partial_orb_color
void set_pixel_scale(const int scale)
Definition: general.cpp:421
std::string get_prefs_file()
bool show_partial_orb()
Definition: general.cpp:294
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:60
const config & get_alias()
Definition: general.cpp:945
void set_disengaged_color(const std::string &color_id)
Definition: general.cpp:385
void set_addon_manager_saved_order_direction(sort_order::type value)
Definition: general.cpp:1011
void set_animate_water(bool value)
Definition: general.cpp:887
bool show_disengaged_orb
int y
y coordinate.
Definition: point.hpp:48
const int max_window_height
Definition: general.cpp:73
void set_addon_manager_saved_order_name(const std::string &value)
Definition: general.cpp:1001
virtual void join_global()
Definition: events.cpp:363
bool use_twelve_hour_clock_format()
Definition: general.cpp:971
void set_show_allied_orb(bool show_orb)
Definition: general.cpp:269
bool auto_pixel_scale()
Definition: general.cpp:426
std::string enemy_color()
Definition: general.cpp:339
int music_volume()
Definition: general.cpp:602
void set_gui_theme(const std::string &s)
Definition: general.cpp:547
bool minimap_terrain_coding()
Definition: general.cpp:842
void set_auto_pixel_scale(bool choice)
Definition: general.cpp:431
void set_disable_auto_moves(bool value)
Definition: general.cpp:981