The Battle for Wesnoth  1.17.10+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"
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 video 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:
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() << "'";
152  }
153 
155 
156 #ifndef _WIN32
157  if(!prefs_file_existed) {
158  if(chmod(filesystem::get_prefs_file().c_str(), 0600) == -1) {
159  ERR_FS << "error setting permissions of preferences file '" << filesystem::get_prefs_file() << "'";
160  }
161  }
162 #endif
163 }
164 
165 void set(const std::string &key, bool value)
166 {
167  prefs[key] = value;
168 }
169 
170 void set(const std::string &key, int value)
171 {
172  prefs[key] = value;
173 }
174 
175 void set(const std::string &key, char const *value)
176 {
177  prefs[key] = value;
178 }
179 
180 void set(const std::string &key, const std::string &value)
181 {
182  prefs[key] = value;
183 }
184 
185 void set(const std::string &key, const config::attribute_value &value)
186 {
187  prefs[key] = value;
188 }
189 
190 void clear(const std::string& key)
191 {
192  prefs.recursive_clear_value(key);
193 }
194 
195 void set_child(const std::string& key, const config& val) {
196  prefs.clear_children(key);
197  prefs.add_child(key, val);
198 }
199 
200 const config &get_child(const std::string& key)
201 {
202  return prefs.child(key);
203 }
204 
205 void erase(const std::string& key) {
206  prefs.remove_attribute(key);
207 }
208 
209 bool have_setting(const std::string& key) {
210  return prefs.has_attribute(key);
211 }
212 
213 std::string get(const std::string& key) {
214  return prefs[key];
215 }
216 
217 std::string get(const std::string& key, const std::string& def) {
218  return prefs[key].empty() ? def : prefs[key];
219 }
220 
221 bool get(const std::string &key, bool def)
222 {
223  return prefs[key].to_bool(def);
224 }
225 
227 {
228  return prefs[key];
229 }
230 
232  no_preferences_save = true;
233 }
234 
236  config* pointer = &prefs;
237  return pointer;
238 }
239 
241  try{
242 #ifdef DEFAULT_PREFS_PATH
244  read(prefs, *stream);
245 
246  config user_prefs;
248  read(user_prefs, *stream);
249 
250  prefs.merge_with(user_prefs);
251 #else
252  prefs.clear();
254  read(prefs, *stream);
255 #endif
256  } catch(const config::error& e) {
257  ERR_CFG << "Error loading preference, message: " << e.what();
258  }
259 }
260 
261 
263  return get("show_ally_orb", game_config::show_ally_orb);
264 }
265 void set_show_allied_orb(bool show_orb) {
266  prefs["show_ally_orb"] = show_orb;
267 }
268 
270  return get("show_enemy_orb", game_config::show_enemy_orb);
271 }
272 void set_show_enemy_orb(bool show_orb) {
273  prefs["show_enemy_orb"] = show_orb;
274 }
275 
277  return get("show_moved_orb", game_config::show_moved_orb);
278 }
279 void set_show_moved_orb(bool show_orb) {
280  prefs["show_moved_orb"] = show_orb;
281 }
282 
284  return get("show_unmoved_orb", game_config::show_unmoved_orb);
285 }
286 void set_show_unmoved_orb(bool show_orb) {
287  prefs["show_unmoved_orb"] = show_orb;
288 }
289 
291  return get("show_partial_orb", game_config::show_partial_orb);
292 }
293 void set_show_partial_orb(bool show_orb) {
294  prefs["show_partial_orb"] = show_orb;
295 }
296 
298  return get("show_disengaged_orb", game_config::show_disengaged_orb);
299 }
300 void set_show_disengaged_orb(bool show_orb) {
301  prefs["show_disengaged_orb"] = show_orb;
302 }
303 
304 static std::string fix_orb_color_name(const std::string& color) {
305  if (color.substr(0,4) == "orb_") {
306  if(color[4] >= '0' && color[4] <= '9') {
307  return color.substr(5);
308  } else {
309  return color.substr(4);
310  }
311  }
312  return color;
313 }
314 
315 std::string allied_color() {
316  std::string ally_color = get("ally_orb_color");
317  if (ally_color.empty())
319  return fix_orb_color_name(ally_color);
320 }
321 void set_allied_color(const std::string& color_id) {
322  prefs["ally_orb_color"] = color_id;
323 }
324 
325 std::string core_id() {
326  std::string core_id = get("core");
327  if (core_id.empty())
328  return "default";
329  return core_id;
330 }
331 void set_core_id(const std::string& core_id) {
332  prefs["core"] = core_id;
333 }
334 
335 std::string enemy_color() {
336  std::string enemy_color = get("enemy_orb_color");
337  if (enemy_color.empty())
339  return fix_orb_color_name(enemy_color);
340 }
341 void set_enemy_color(const std::string& color_id) {
342  prefs["enemy_orb_color"] = color_id;
343 }
344 
345 std::string moved_color() {
346  std::string moved_color = get("moved_orb_color");
347  if (moved_color.empty())
349  return fix_orb_color_name(moved_color);
350 }
351 void set_moved_color(const std::string& color_id) {
352  prefs["moved_orb_color"] = color_id;
353 }
354 
355 std::string unmoved_color() {
356  std::string unmoved_color = get("unmoved_orb_color");
357  if (unmoved_color.empty())
359  return fix_orb_color_name(unmoved_color);
360 }
361 void set_unmoved_color(const std::string& color_id) {
362  prefs["unmoved_orb_color"] = color_id;
363 }
364 
365 std::string partial_color() {
366  std::string partmoved_color = get("partial_orb_color");
367  if (partmoved_color.empty())
369  return fix_orb_color_name(partmoved_color);
370 }
371 void set_partial_color(const std::string& color_id) {
372  prefs["partial_orb_color"] = color_id;
373 }
374 
375 std::string disengaged_color() {
376  std::string disengaged_color = get("disengaged_orb_color");
377  if (disengaged_color.empty())
379  return fix_orb_color_name(disengaged_color);
380 }
381 void set_disengaged_color(const std::string& color_id) {
382  prefs["disengaged_orb_color"] = color_id;
383 }
384 
386 {
387  return get("scroll_to_action", true);
388 }
389 
390 void set_scroll_to_action(bool ison)
391 {
392  prefs["scroll_to_action"] = ison;
393 }
394 
396 {
397  const unsigned x_res = prefs["xresolution"].to_unsigned();
398  const unsigned y_res = prefs["yresolution"].to_unsigned();
399 
400  // Either resolution was unspecified, return default.
401  if(x_res == 0 || y_res == 0) {
402  return point(def_window_width, def_window_height);
403  }
404 
405  return point(
406  std::max<unsigned>(x_res, min_window_width),
407  std::max<unsigned>(y_res, min_window_height)
408  );
409 }
410 
412 {
413  // For now this has a minimum value of 1 and a maximum of 4.
414  return std::max<int>(std::min<int>(prefs["pixel_scale"].to_int(1), max_pixel_scale), min_pixel_scale);
415 }
416 
417 void set_pixel_scale(const int scale)
418 {
419  prefs["pixel_scale"] = std::clamp(scale, min_pixel_scale, max_pixel_scale);
420 }
421 
423 {
424  return get("auto_pixel_scale", true);
425 }
426 
427 void set_auto_pixel_scale(bool choice)
428 {
429  prefs["auto_pixel_scale"] = choice;
430 }
431 
432 bool maximized()
433 {
434  return get("maximized", !fullscreen());
435 }
436 
438 {
439  return get("fullscreen", true);
440 }
441 
442 bool vsync()
443 {
444  return get("vsync", true);
445 }
446 
447 void _set_resolution(const point& res)
448 {
449  preferences::set("xresolution", std::to_string(res.x));
450  preferences::set("yresolution", std::to_string(res.y));
451 }
452 
453 void _set_maximized(bool ison)
454 {
455  prefs["maximized"] = ison;
456 }
457 
458 void _set_fullscreen(bool ison)
459 {
460  prefs["fullscreen"] = ison;
461 }
462 
463 void set_vsync(bool ison)
464 {
465  prefs["vsync"] = ison;
466 }
467 
468 bool turbo()
469 {
470  if(video::headless()) {
471  return true;
472  }
473 
474  return get("turbo", false);
475 }
476 
477 void set_turbo(bool ison)
478 {
479  prefs["turbo"] = ison;
480 }
481 
482 double turbo_speed()
483 {
484  return prefs["turbo_speed"].to_double(2.0);
485 }
486 
487 void set_turbo_speed(const double speed)
488 {
489  prefs["turbo_speed"] = speed;
490 }
491 
493 {
494  // Clip at 80 because if it's too low it'll cause crashes
495  return std::max<int>(std::min<int>(prefs["font_scale"].to_int(100), max_font_scaling), min_font_scaling);
496 }
497 
499 {
500  prefs["font_scale"] = std::clamp(scale, min_font_scaling, max_font_scaling);
501 }
502 
504 {
505  return (size * font_scaling()) / 100;
506 }
507 
509 {
510  return prefs["keepalive_timeout"].to_int(10);
511 }
512 
513 void keepalive_timeout(int seconds)
514 {
515  prefs["keepalive_timeout"] = std::abs(seconds);
516 }
517 
518 bool idle_anim()
519 {
520  return get("idle_anim", true);
521 }
522 
523 void set_idle_anim(const bool ison)
524 {
525  prefs["idle_anim"] = ison;
526 }
527 
529 {
530  return prefs["idle_anim_rate"].to_double(1.0);
531 }
532 
533 void set_idle_anim_rate(const int rate)
534 {
535  prefs["idle_anim_rate"] = std::pow(2.0, -rate / 10.0);
536 }
537 
538 std::string language()
539 {
540  return prefs["locale"];
541 }
542 
543 void set_language(const std::string& s)
544 {
545  preferences::set("locale", s);
546 }
547 
548 std::string gui_theme()
549 {
550  return prefs["gui2_theme"];
551 }
552 
553 void set_gui_theme(const std::string& s)
554 {
555  preferences::set("gui2_theme", s);
556 }
557 
558 bool ellipses()
559 {
560  return get("show_side_colors", false);
561 }
562 
563 void set_ellipses(bool ison)
564 {
565  preferences::set("show_side_colors", ison);
566 }
567 
568 bool grid()
569 {
570  return get("grid", false);
571 }
572 
573 void set_grid(bool ison)
574 {
575  preferences::set("grid", ison);
576 }
577 
578 std::size_t sound_buffer_size()
579 {
580  // Sounds don't sound good on Windows unless the buffer size is 4k,
581  // but this seems to cause crashes on other systems...
582  #ifdef _WIN32
583  const std::size_t buf_size = 4096;
584  #else
585  const std::size_t buf_size = 1024;
586  #endif
587 
588  return prefs["sound_buffer_size"].to_int(buf_size);
589 }
590 
591 void save_sound_buffer_size(const std::size_t size)
592 {
593  #ifdef _WIN32
594  const char* buf_size = "4096";
595  #else
596  const char* buf_size = "1024";
597  #endif
598 
599  const std::string new_size = lexical_cast_default<std::string>(size, buf_size);
600  if (get("sound_buffer_size") == new_size)
601  return;
602 
603  preferences::set("sound_buffer_size", new_size);
604 
606 }
607 
609 {
610  return prefs["music_volume"].to_int(100);
611 }
612 
613 void set_music_volume(int vol)
614 {
615  if(music_volume() == vol) {
616  return;
617  }
618 
619  prefs["music_volume"] = vol;
621 }
622 
624 {
625  return prefs["sound_volume"].to_int(100);
626 }
627 
628 void set_sound_volume(int vol)
629 {
630  if(sound_volume() == vol) {
631  return;
632  }
633 
634  prefs["sound_volume"] = vol;
636 }
637 
639 {
640  return prefs["bell_volume"].to_int(100);
641 }
642 
643 void set_bell_volume(int vol)
644 {
645  if(bell_volume() == vol) {
646  return;
647  }
648 
649  prefs["bell_volume"] = vol;
651 }
652 
654 {
655  return prefs["UI_volume"].to_int(100);
656 }
657 
658 void set_UI_volume(int vol)
659 {
660  if(UI_volume() == vol) {
661  return;
662  }
663 
664  prefs["UI_volume"] = vol;
666 }
667 
668 unsigned int tile_size()
669 {
670  return prefs["tile_size"].to_unsigned();
671 }
672 
673 void set_tile_size(const unsigned int size)
674 {
675  prefs["tile_size"] = size;
676 }
677 
678 bool turn_bell()
679 {
680  return get("turn_bell", true);
681 }
682 
683 bool set_turn_bell(bool ison)
684 {
685  if(!turn_bell() && ison) {
686  preferences::set("turn_bell", true);
687  if(!music_on() && !sound_on() && !UI_sound_on()) {
688  if(!sound::init_sound()) {
689  preferences::set("turn_bell", false);
690  return false;
691  }
692  }
693  } else if(turn_bell() && !ison) {
694  preferences::set("turn_bell", false);
696  if(!music_on() && !sound_on() && !UI_sound_on())
698  }
699  return true;
700 }
701 
703 {
704  return get("UI_sound", true);
705 }
706 
707 bool set_UI_sound(bool ison)
708 {
709  if(!UI_sound_on() && ison) {
710  preferences::set("UI_sound", true);
711  if(!music_on() && !sound_on() && !turn_bell()) {
712  if(!sound::init_sound()) {
713  preferences::set("UI_sound", false);
714  return false;
715  }
716  }
717  } else if(UI_sound_on() && !ison) {
718  preferences::set("UI_sound", false);
720  if(!music_on() && !sound_on() && !turn_bell())
722  }
723  return true;
724 }
725 
727 {
728  return get("message_bell", true);
729 }
730 
731 bool sound_on()
732 {
733  return get("sound", true);
734 }
735 
736 bool set_sound(bool ison) {
737  if(!sound_on() && ison) {
738  preferences::set("sound", true);
739  if(!music_on() && !turn_bell() && !UI_sound_on()) {
740  if(!sound::init_sound()) {
741  preferences::set("sound", false);
742  return false;
743  }
744  }
745  } else if(sound_on() && !ison) {
746  preferences::set("sound", false);
748  if(!music_on() && !turn_bell() && !UI_sound_on())
750  }
751  return true;
752 }
753 
754 bool music_on()
755 {
756  return get("music", true);
757 }
758 
759 bool set_music(bool ison) {
760  if(!music_on() && ison) {
761  preferences::set("music", true);
762  if(!sound_on() && !turn_bell() && !UI_sound_on()) {
763  if(!sound::init_sound()) {
764  preferences::set("music", false);
765  return false;
766  }
767  }
768  else
770  } else if(music_on() && !ison) {
771  preferences::set("music", false);
772  if(!sound_on() && !turn_bell() && !UI_sound_on())
774  else
776  }
777  return true;
778 }
779 
781 {
782  return get("stop_music_in_background", false);
783 }
784 
786 {
787  preferences::set("stop_music_in_background", ison);
788 }
789 
790 namespace {
791  double scroll = 0.2;
792 }
793 
795 {
796  const int value = std::clamp<int>(lexical_cast_default<int>(get("scroll"), 50), 1, 100);
797  scroll = value/100.0;
798 
799  return value;
800 }
801 
802 void set_scroll_speed(const int new_speed)
803 {
804  prefs["scroll"] = new_speed;
805  scroll = new_speed / 100.0;
806 }
807 
809 {
810  return get("middle_click_scrolls", true);
811 }
812 
814 {
815  return get("mouse_scrolling", true);
816 }
817 
818 void enable_mouse_scroll(bool value)
819 {
820  set("mouse_scrolling", value);
821 }
822 
824 {
825  return prefs["scroll_threshold"].to_int(10);
826 }
827 
829 {
830  return preferences::get("animate_map", true);
831 }
832 
834 {
835  return preferences::get("animate_water", true);
836 }
837 
839 {
840  return preferences::get("minimap_movement_coding", true);
841 }
842 
844 {
845  set("minimap_movement_coding", !minimap_movement_coding());
846 }
847 
849 {
850  return preferences::get("minimap_terrain_coding", true);
851 }
852 
854 {
855  set("minimap_terrain_coding", !minimap_terrain_coding());
856 }
857 
859 {
860  return preferences::get("minimap_draw_units", true);
861 }
862 
864 {
865  set("minimap_draw_units", !minimap_draw_units());
866 }
867 
869 {
870  return preferences::get("minimap_draw_villages", true);
871 }
872 
874 {
875  set("minimap_draw_villages", !minimap_draw_villages());
876 }
877 
879 {
880  return preferences::get("minimap_draw_terrain", true);
881 }
882 
884 {
885  set("minimap_draw_terrain", !minimap_draw_terrain());
886 }
887 
888 void set_animate_map(bool value)
889 {
890  set("animate_map", value);
891 }
892 
893 void set_animate_water(bool value)
894 {
895  set("animate_water", value);
896 }
897 
898 bool show_fps()
899 {
900  return fps;
901 }
902 
903 void set_show_fps(bool value)
904 {
905  fps = value;
906 }
907 
909 {
910  return prefs["draw_delay"].to_int(-1);
911 }
912 
913 void set_draw_delay(int value)
914 {
915  prefs["draw_delay"] = value;
916 }
917 
919 {
920  return get("color_cursors", true);
921 }
922 
923 void _set_color_cursors(bool value)
924 {
925  preferences::set("color_cursors", value);
926 }
927 
929 {
931 }
932 
934 {
936 }
937 
939 {
941  prefs.clear_children("hotkey");
942 }
943 
944 void add_alias(const std::string &alias, const std::string &command)
945 {
946  config &alias_list = prefs.child_or_add("alias");
947  alias_list[alias] = command;
948 }
949 
950 
952 {
953  return get_child("alias");
954 }
955 
956 unsigned int sample_rate()
957 {
958  return prefs["sample_rate"].to_int(44100);
959 }
960 
961 void save_sample_rate(const unsigned int rate)
962 {
963  if (sample_rate() == rate)
964  return;
965 
966  prefs["sample_rate"] = static_cast<int>(rate);
967 
968  // If audio is open, we have to re set sample rate
970 }
971 
973 {
974  return get("confirm_load_save_from_different_version", true);
975 }
976 
978 {
979  return get("use_twelve_hour_clock_format", false);
980 }
981 
983 {
984  return get("disable_auto_moves", false);
985 }
986 
987 void set_disable_auto_moves(bool value)
988 {
989  preferences::set("disable_auto_moves", value);
990 }
991 
993 {
994  return get("damage_prediction_allow_monte_carlo_simulation", true);
995 }
996 
998 {
999  set("damage_prediction_allow_monte_carlo_simulation", value);
1000 }
1001 
1003 {
1004  return get("addon_manager_saved_order_name");
1005 }
1006 
1007 void set_addon_manager_saved_order_name(const std::string& value)
1008 {
1009  set("addon_manager_saved_order_name", value);
1010 }
1011 
1013 {
1014  return sort_order::get_enum(get("addon_manager_saved_order_direction")).value_or(sort_order::type::none);
1015 }
1016 
1018 {
1019  set("addon_manager_saved_order_direction", sort_order::get_string(value));
1020 }
1021 
1022 
1023 } // end namespace preferences
bool disable_auto_moves()
Definition: general.cpp:982
void set_turbo(bool ison)
Definition: general.cpp:477
bool set_sound(bool ison)
Definition: general.cpp:736
void set_show_enemy_orb(bool show_orb)
Definition: general.cpp:272
std::string unmoved_color()
Definition: general.cpp:355
void close_sound()
Definition: sound.cpp:495
void _set_fullscreen(bool ison)
Definition: general.cpp:458
void set_grid(bool ison)
Definition: general.cpp:573
int bell_volume()
Definition: general.cpp:638
bool turn_bell()
Definition: general.cpp:678
std::string addon_manager_saved_order_name()
Definition: general.cpp:1002
bool show_unmoved_orb
void set_moved_color(const std::string &color_id)
Definition: general.cpp:351
void save_hotkeys()
Definition: general.cpp:933
bool minimap_draw_units()
Definition: general.cpp:858
const int min_window_height
Definition: general.cpp:67
void set_allied_color(const std::string &color_id)
Definition: general.cpp:321
bool show_fps()
Definition: general.cpp:898
void set_unmoved_color(const std::string &color_id)
Definition: general.cpp:361
void stop_music()
Definition: sound.cpp:557
void write_preferences()
Definition: general.cpp:141
void _set_maximized(bool ison)
Definition: general.cpp:453
int mouse_scroll_threshold()
Gets the threshold for when to scroll.
Definition: general.cpp:823
void disable_preferences_save()
Definition: general.cpp:231
void save_hotkeys(config &cfg)
Save the non-default hotkeys to the config.
void set_show_unmoved_orb(bool show_orb)
Definition: general.cpp:286
Variant for storing WML attributes.
#define ERR_FS
Definition: general.cpp:47
void _set_color_cursors(bool value)
Definition: general.cpp:923
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:908
void set_scroll_speed(const int new_speed)
Definition: general.cpp:802
bool minimap_movement_coding()
Definition: general.cpp:838
const int max_window_width
Definition: general.cpp:72
void set_UI_volume(int vol)
Definition: sound.cpp:1134
bool show_enemy_orb()
Definition: general.cpp:269
void set_idle_anim_rate(const int rate)
Definition: general.cpp:533
int scroll_speed()
Definition: general.cpp:794
bool vsync()
Definition: general.cpp:442
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:447
void enable_mouse_scroll(bool value)
Definition: general.cpp:818
bool show_allied_orb()
Definition: general.cpp:262
void clear(const std::string &key)
Definition: general.cpp:190
virtual void leave_global()
Definition: events.cpp:393
bool idle_anim()
Definition: general.cpp:518
bool message_bell()
Definition: general.cpp:726
std::string gui_theme()
Definition: general.cpp:548
void set_tile_size(const unsigned int size)
Definition: general.cpp:673
void stop_sound()
Definition: sound.cpp:565
void set(const std::string &key, bool value)
Definition: general.cpp:165
unsigned int sample_rate()
Definition: general.cpp:956
sort_order::type addon_manager_saved_order_direction()
Definition: general.cpp:1012
double turbo_speed()
Definition: general.cpp:482
bool confirm_load_save_from_different_version()
Definition: general.cpp:972
bool animate_water()
Definition: general.cpp:833
std::string enemy_orb_color
void set_sound_volume(int vol)
Definition: general.cpp:628
void save_credentials()
bool show_enemy_orb
std::string disengaged_color()
Definition: general.cpp:375
Definitions for the interface to Wesnoth Markup Language (WML).
bool ellipses()
Definition: general.cpp:558
void load_base_prefs()
Definition: general.cpp:240
bool sound_on()
Definition: general.cpp:731
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:432
std::string disengaged_orb_color
bool init_sound()
Definition: sound.cpp:443
void load_custom_hotkeys(const game_config_view &cfg)
Registers all hotkeys present in this config, overwriting any matching default hotkeys.
void reset_sound()
Definition: sound.cpp:526
bool minimap_draw_villages()
Definition: general.cpp:868
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:1122
std::string get(const std::string &key)
Definition: general.cpp:213
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:341
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
#define ERR_CFG
Definition: general.cpp:44
void load_hotkeys()
Definition: general.cpp:928
void toggle_minimap_draw_units()
Definition: general.cpp:863
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:297
const int min_font_scaling
Definition: general.cpp:75
void stop_UI_sound()
Definition: sound.cpp:592
bool fullscreen()
Definition: general.cpp:437
const int min_pixel_scale
Definition: general.cpp:78
void set_font_scaling(int scale)
Definition: general.cpp:498
void set_music_volume(int vol)
Definition: general.cpp:613
void play_music()
Definition: sound.cpp:617
int font_scaled(int size)
Definition: general.cpp:503
void set_vsync(bool ison)
Definition: general.cpp:463
void set_show_fps(bool value)
Definition: general.cpp:903
void set_partial_color(const std::string &color_id)
Definition: general.cpp:371
void erase(const std::string &key)
Definition: general.cpp:205
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:293
bool headless()
The game is running headless.
Definition: video.cpp:143
void set_core_id(const std::string &core_id)
Definition: general.cpp:331
config::attribute_value get_as_attribute(const std::string &key)
Definition: general.cpp:226
Modify, read and display user preferences.
void toggle_minimap_draw_terrain()
Definition: general.cpp:883
bool UI_sound_on()
Definition: general.cpp:702
void set_bell_volume(int vol)
Definition: general.cpp:643
void set_stop_music_in_background(bool ison)
Definition: general.cpp:785
bool animate_map()
Definition: general.cpp:828
const int max_pixel_scale
Definition: general.cpp:79
void set_idle_anim(const bool ison)
Definition: general.cpp:523
bool damage_prediction_allow_monte_carlo_simulation()
Definition: general.cpp:992
void set_animate_map(bool value)
Definition: general.cpp:888
const char * what() const noexcept
Definition: exceptions.hpp:36
std::string moved_orb_color
int pixel_scale()
Definition: general.cpp:411
void set_sound_volume(int vol)
Definition: sound.cpp:1102
std::string get_default_prefs_file()
void set_show_moved_orb(bool show_orb)
Definition: general.cpp:279
bool show_moved_orb()
Definition: general.cpp:276
void set_music_volume(int vol)
Definition: sound.cpp:1082
void set_draw_delay(int value)
Definition: general.cpp:913
void toggle_minimap_draw_villages()
Definition: general.cpp:873
const int max_font_scaling
Definition: general.cpp:76
void set_UI_volume(int vol)
Definition: general.cpp:658
void set_child(const std::string &key, const config &val)
Definition: general.cpp:195
static std::string fix_orb_color_name(const std::string &color)
Definition: general.cpp:304
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:961
std::string allied_color()
Definition: general.cpp:315
int keepalive_timeout()
Definition: general.cpp:508
void add_alias(const std::string &alias, const std::string &command)
Definition: general.cpp:944
std::string unmoved_orb_color
double idle_anim_rate()
Definition: general.cpp:528
static constexpr std::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.
Definition: enum_base.hpp:57
void clear_hotkeys()
Definition: general.cpp:938
std::string moved_color()
Definition: general.cpp:345
unsigned int tile_size()
Definition: general.cpp:668
void toggle_minimap_terrain_coding()
Definition: general.cpp:853
bool middle_click_scrolls()
Definition: general.cpp:808
An exception object used when an IO error occurs.
Definition: filesystem.hpp:48
bool stop_music_in_background()
Definition: general.cpp:780
static map_location::DIRECTION s
bool music_on()
Definition: general.cpp:754
bool use_color_cursors()
Definition: general.cpp:918
void toggle_minimap_movement_coding()
Definition: general.cpp:843
Holds a 2D point.
Definition: point.hpp:24
bool set_UI_sound(bool ison)
Definition: general.cpp:707
std::string language()
Definition: general.cpp:538
config * get_prefs()
Definition: general.cpp:235
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:487
void set_scroll_to_action(bool ison)
Definition: general.cpp:390
void set_ellipses(bool ison)
Definition: general.cpp:563
void save_sound_buffer_size(const std::size_t size)
Definition: general.cpp:591
const config & get_child(const std::string &key)
Definition: general.cpp:200
void reset_default_hotkeys()
Reset all hotkeys to the defaults.
std::size_t sound_buffer_size()
Definition: general.cpp:578
std::string core_id()
Definition: general.cpp:325
void set_language(const std::string &s)
Definition: general.cpp:543
bool grid()
Definition: general.cpp:568
const int def_window_height
Definition: general.cpp:70
bool mouse_scroll_enabled()
Definition: general.cpp:813
std::string partial_color()
Definition: general.cpp:365
int sound_volume()
Definition: general.cpp:623
bool have_setting(const std::string &key)
Definition: general.cpp:209
int font_scaling()
Definition: general.cpp:492
static lg::log_domain log_filesystem("filesystem")
bool minimap_draw_terrain()
Definition: general.cpp:878
void set_show_disengaged_orb(bool show_orb)
Definition: general.cpp:300
void load_credentials()
bool set_music(bool ison)
Definition: general.cpp:759
Standard logging facilities (interface).
bool set_turn_bell(bool ison)
Definition: general.cpp:683
bool turbo()
Definition: general.cpp:468
point window_size()
Returns the size of the window in display units / screen coordinates.
Definition: video.cpp:409
static lg::log_domain log_config("config")
bool scroll_to_action()
Definition: general.cpp:385
virtual void handle_event(const SDL_Event &)
Definition: general.cpp:83
void point(int x, int y)
Draw a single point.
Definition: draw.cpp:193
point resolution()
Definition: general.cpp:395
#define e
bool show_partial_orb
int UI_volume()
Definition: general.cpp:653
bool show_unmoved_orb()
Definition: general.cpp:283
void set_damage_prediction_allow_monte_carlo_simulation(bool value)
Definition: general.cpp:997
std::string partial_orb_color
void set_pixel_scale(const int scale)
Definition: general.cpp:417
std::string get_prefs_file()
bool show_partial_orb()
Definition: general.cpp:290
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:951
void set_disengaged_color(const std::string &color_id)
Definition: general.cpp:381
void set_addon_manager_saved_order_direction(sort_order::type value)
Definition: general.cpp:1017
void set_animate_water(bool value)
Definition: general.cpp:893
bool show_disengaged_orb
const int max_window_height
Definition: general.cpp:73
void set_addon_manager_saved_order_name(const std::string &value)
Definition: general.cpp:1007
virtual void join_global()
Definition: events.cpp:373
bool use_twelve_hour_clock_format()
Definition: general.cpp:977
void set_show_allied_orb(bool show_orb)
Definition: general.cpp:265
bool auto_pixel_scale()
Definition: general.cpp:422
std::string enemy_color()
Definition: general.cpp:335
int music_volume()
Definition: general.cpp:608
void set_gui_theme(const std::string &s)
Definition: general.cpp:553
bool minimap_terrain_coding()
Definition: general.cpp:848
void set_auto_pixel_scale(bool choice)
Definition: general.cpp:427
void set_disable_auto_moves(bool value)
Definition: general.cpp:987
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
Definition: enum_base.hpp:46