The Battle for Wesnoth  1.17.6+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 
508 bool idle_anim()
509 {
510  return get("idle_anim", true);
511 }
512 
513 void set_idle_anim(const bool ison)
514 {
515  prefs["idle_anim"] = ison;
516 }
517 
519 {
520  return prefs["idle_anim_rate"].to_double(1.0);
521 }
522 
523 void set_idle_anim_rate(const int rate)
524 {
525  prefs["idle_anim_rate"] = std::pow(2.0, -rate / 10.0);
526 }
527 
528 std::string language()
529 {
530  return prefs["locale"];
531 }
532 
533 void set_language(const std::string& s)
534 {
535  preferences::set("locale", s);
536 }
537 
538 std::string gui_theme()
539 {
540  return prefs["gui2_theme"];
541 }
542 
543 void set_gui_theme(const std::string& s)
544 {
545  preferences::set("gui2_theme", s);
546 }
547 
548 bool ellipses()
549 {
550  return get("show_side_colors", false);
551 }
552 
553 void set_ellipses(bool ison)
554 {
555  preferences::set("show_side_colors", ison);
556 }
557 
558 bool grid()
559 {
560  return get("grid", false);
561 }
562 
563 void set_grid(bool ison)
564 {
565  preferences::set("grid", ison);
566 }
567 
568 std::size_t sound_buffer_size()
569 {
570  // Sounds don't sound good on Windows unless the buffer size is 4k,
571  // but this seems to cause crashes on other systems...
572  #ifdef _WIN32
573  const std::size_t buf_size = 4096;
574  #else
575  const std::size_t buf_size = 1024;
576  #endif
577 
578  return prefs["sound_buffer_size"].to_int(buf_size);
579 }
580 
581 void save_sound_buffer_size(const std::size_t size)
582 {
583  #ifdef _WIN32
584  const char* buf_size = "4096";
585  #else
586  const char* buf_size = "1024";
587  #endif
588 
589  const std::string new_size = lexical_cast_default<std::string>(size, buf_size);
590  if (get("sound_buffer_size") == new_size)
591  return;
592 
593  preferences::set("sound_buffer_size", new_size);
594 
596 }
597 
599 {
600  return prefs["music_volume"].to_int(100);
601 }
602 
603 void set_music_volume(int vol)
604 {
605  if(music_volume() == vol) {
606  return;
607  }
608 
609  prefs["music_volume"] = vol;
611 }
612 
614 {
615  return prefs["sound_volume"].to_int(100);
616 }
617 
618 void set_sound_volume(int vol)
619 {
620  if(sound_volume() == vol) {
621  return;
622  }
623 
624  prefs["sound_volume"] = vol;
626 }
627 
629 {
630  return prefs["bell_volume"].to_int(100);
631 }
632 
633 void set_bell_volume(int vol)
634 {
635  if(bell_volume() == vol) {
636  return;
637  }
638 
639  prefs["bell_volume"] = vol;
641 }
642 
644 {
645  return prefs["UI_volume"].to_int(100);
646 }
647 
648 void set_UI_volume(int vol)
649 {
650  if(UI_volume() == vol) {
651  return;
652  }
653 
654  prefs["UI_volume"] = vol;
656 }
657 
658 unsigned int tile_size()
659 {
660  return prefs["tile_size"].to_unsigned();
661 }
662 
663 void set_tile_size(const unsigned int size)
664 {
665  prefs["tile_size"] = size;
666 }
667 
668 bool turn_bell()
669 {
670  return get("turn_bell", true);
671 }
672 
673 bool set_turn_bell(bool ison)
674 {
675  if(!turn_bell() && ison) {
676  preferences::set("turn_bell", true);
677  if(!music_on() && !sound_on() && !UI_sound_on()) {
678  if(!sound::init_sound()) {
679  preferences::set("turn_bell", false);
680  return false;
681  }
682  }
683  } else if(turn_bell() && !ison) {
684  preferences::set("turn_bell", false);
686  if(!music_on() && !sound_on() && !UI_sound_on())
688  }
689  return true;
690 }
691 
693 {
694  return get("UI_sound", true);
695 }
696 
697 bool set_UI_sound(bool ison)
698 {
699  if(!UI_sound_on() && ison) {
700  preferences::set("UI_sound", true);
701  if(!music_on() && !sound_on() && !turn_bell()) {
702  if(!sound::init_sound()) {
703  preferences::set("UI_sound", false);
704  return false;
705  }
706  }
707  } else if(UI_sound_on() && !ison) {
708  preferences::set("UI_sound", false);
710  if(!music_on() && !sound_on() && !turn_bell())
712  }
713  return true;
714 }
715 
717 {
718  return get("message_bell", true);
719 }
720 
721 bool sound_on()
722 {
723  return get("sound", true);
724 }
725 
726 bool set_sound(bool ison) {
727  if(!sound_on() && ison) {
728  preferences::set("sound", true);
729  if(!music_on() && !turn_bell() && !UI_sound_on()) {
730  if(!sound::init_sound()) {
731  preferences::set("sound", false);
732  return false;
733  }
734  }
735  } else if(sound_on() && !ison) {
736  preferences::set("sound", false);
738  if(!music_on() && !turn_bell() && !UI_sound_on())
740  }
741  return true;
742 }
743 
744 bool music_on()
745 {
746  return get("music", true);
747 }
748 
749 bool set_music(bool ison) {
750  if(!music_on() && ison) {
751  preferences::set("music", true);
752  if(!sound_on() && !turn_bell() && !UI_sound_on()) {
753  if(!sound::init_sound()) {
754  preferences::set("music", false);
755  return false;
756  }
757  }
758  else
760  } else if(music_on() && !ison) {
761  preferences::set("music", false);
762  if(!sound_on() && !turn_bell() && !UI_sound_on())
764  else
766  }
767  return true;
768 }
769 
771 {
772  return get("stop_music_in_background", false);
773 }
774 
776 {
777  preferences::set("stop_music_in_background", ison);
778 }
779 
780 namespace {
781  double scroll = 0.2;
782 }
783 
785 {
786  const int value = std::clamp<int>(lexical_cast_default<int>(get("scroll"), 50), 1, 100);
787  scroll = value/100.0;
788 
789  return value;
790 }
791 
792 void set_scroll_speed(const int new_speed)
793 {
794  prefs["scroll"] = new_speed;
795  scroll = new_speed / 100.0;
796 }
797 
799 {
800  return get("middle_click_scrolls", true);
801 }
802 
804 {
805  return get("mouse_scrolling", true);
806 }
807 
808 void enable_mouse_scroll(bool value)
809 {
810  set("mouse_scrolling", value);
811 }
812 
814 {
815  return prefs["scroll_threshold"].to_int(10);
816 }
817 
819 {
820  return preferences::get("animate_map", true);
821 }
822 
824 {
825  return preferences::get("animate_water", true);
826 }
827 
829 {
830  return preferences::get("minimap_movement_coding", true);
831 }
832 
834 {
835  set("minimap_movement_coding", !minimap_movement_coding());
836 }
837 
839 {
840  return preferences::get("minimap_terrain_coding", true);
841 }
842 
844 {
845  set("minimap_terrain_coding", !minimap_terrain_coding());
846 }
847 
849 {
850  return preferences::get("minimap_draw_units", true);
851 }
852 
854 {
855  set("minimap_draw_units", !minimap_draw_units());
856 }
857 
859 {
860  return preferences::get("minimap_draw_villages", true);
861 }
862 
864 {
865  set("minimap_draw_villages", !minimap_draw_villages());
866 }
867 
869 {
870  return preferences::get("minimap_draw_terrain", true);
871 }
872 
874 {
875  set("minimap_draw_terrain", !minimap_draw_terrain());
876 }
877 
878 void set_animate_map(bool value)
879 {
880  set("animate_map", value);
881 }
882 
883 void set_animate_water(bool value)
884 {
885  set("animate_water", value);
886 }
887 
888 bool show_fps()
889 {
890  return fps;
891 }
892 
893 void set_show_fps(bool value)
894 {
895  fps = value;
896 }
897 
899 {
900  return prefs["draw_delay"].to_int(-1);
901 }
902 
903 void set_draw_delay(int value)
904 {
905  prefs["draw_delay"] = value;
906 }
907 
909 {
910  return get("color_cursors", true);
911 }
912 
913 void _set_color_cursors(bool value)
914 {
915  preferences::set("color_cursors", value);
916 }
917 
919 {
921 }
922 
924 {
926 }
927 
929 {
931  prefs.clear_children("hotkey");
932 }
933 
934 void add_alias(const std::string &alias, const std::string &command)
935 {
936  config &alias_list = prefs.child_or_add("alias");
937  alias_list[alias] = command;
938 }
939 
940 
942 {
943  return get_child("alias");
944 }
945 
946 unsigned int sample_rate()
947 {
948  return prefs["sample_rate"].to_int(44100);
949 }
950 
951 void save_sample_rate(const unsigned int rate)
952 {
953  if (sample_rate() == rate)
954  return;
955 
956  prefs["sample_rate"] = static_cast<int>(rate);
957 
958  // If audio is open, we have to re set sample rate
960 }
961 
963 {
964  return get("confirm_load_save_from_different_version", true);
965 }
966 
968 {
969  return get("use_twelve_hour_clock_format", false);
970 }
971 
973 {
974  return get("disable_auto_moves", false);
975 }
976 
977 void set_disable_auto_moves(bool value)
978 {
979  preferences::set("disable_auto_moves", value);
980 }
981 
983 {
984  return get("damage_prediction_allow_monte_carlo_simulation", true);
985 }
986 
988 {
989  set("damage_prediction_allow_monte_carlo_simulation", value);
990 }
991 
993 {
994  return get("addon_manager_saved_order_name");
995 }
996 
997 void set_addon_manager_saved_order_name(const std::string& value)
998 {
999  set("addon_manager_saved_order_name", value);
1000 }
1001 
1003 {
1004  return sort_order::get_enum(get("addon_manager_saved_order_direction")).value_or(sort_order::type::none);
1005 }
1006 
1008 {
1009  set("addon_manager_saved_order_direction", sort_order::get_string(value));
1010 }
1011 
1012 
1013 } // end namespace preferences
bool disable_auto_moves()
Definition: general.cpp:972
void set_turbo(bool ison)
Definition: general.cpp:477
bool set_sound(bool ison)
Definition: general.cpp:726
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:563
int bell_volume()
Definition: general.cpp:628
bool turn_bell()
Definition: general.cpp:668
std::string addon_manager_saved_order_name()
Definition: general.cpp:992
bool show_unmoved_orb
void set_moved_color(const std::string &color_id)
Definition: general.cpp:351
void save_hotkeys()
Definition: general.cpp:923
bool minimap_draw_units()
Definition: general.cpp:848
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:888
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:813
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.
void _set_color_cursors(bool value)
Definition: general.cpp:913
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:898
void set_scroll_speed(const int new_speed)
Definition: general.cpp:792
bool minimap_movement_coding()
Definition: general.cpp:828
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:523
int scroll_speed()
Definition: general.cpp:784
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:808
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:387
bool idle_anim()
Definition: general.cpp:508
bool message_bell()
Definition: general.cpp:716
std::string gui_theme()
Definition: general.cpp:538
void set_tile_size(const unsigned int size)
Definition: general.cpp:663
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:946
sort_order::type addon_manager_saved_order_direction()
Definition: general.cpp:1002
double turbo_speed()
Definition: general.cpp:482
bool confirm_load_save_from_different_version()
Definition: general.cpp:962
bool animate_water()
Definition: general.cpp:823
std::string enemy_orb_color
void set_sound_volume(int vol)
Definition: general.cpp:618
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:548
void load_base_prefs()
Definition: general.cpp:240
bool sound_on()
Definition: general.cpp:721
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
#define ERR_FS
Definition: general.cpp:47
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:858
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
void load_hotkeys()
Definition: general.cpp:918
void toggle_minimap_draw_units()
Definition: general.cpp:853
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
static lg::log_domain log_config("config")
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:603
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:893
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:107
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:873
bool UI_sound_on()
Definition: general.cpp:692
void set_bell_volume(int vol)
Definition: general.cpp:633
void set_stop_music_in_background(bool ison)
Definition: general.cpp:775
bool animate_map()
Definition: general.cpp:818
const int max_pixel_scale
Definition: general.cpp:79
void set_idle_anim(const bool ison)
Definition: general.cpp:513
bool damage_prediction_allow_monte_carlo_simulation()
Definition: general.cpp:982
void set_animate_map(bool value)
Definition: general.cpp:878
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:903
void toggle_minimap_draw_villages()
Definition: general.cpp:863
#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:648
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:951
std::string allied_color()
Definition: general.cpp:315
void add_alias(const std::string &alias, const std::string &command)
Definition: general.cpp:934
static lg::log_domain log_filesystem("filesystem")
std::string unmoved_orb_color
double idle_anim_rate()
Definition: general.cpp:518
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:928
std::string moved_color()
Definition: general.cpp:345
unsigned int tile_size()
Definition: general.cpp:658
void toggle_minimap_terrain_coding()
Definition: general.cpp:843
bool middle_click_scrolls()
Definition: general.cpp:798
An exception object used when an IO error occurs.
Definition: filesystem.hpp:48
bool stop_music_in_background()
Definition: general.cpp:770
static map_location::DIRECTION s
bool music_on()
Definition: general.cpp:744
bool use_color_cursors()
Definition: general.cpp:908
void toggle_minimap_movement_coding()
Definition: general.cpp:833
Holds a 2D point.
Definition: point.hpp:24
bool set_UI_sound(bool ison)
Definition: general.cpp:697
std::string language()
Definition: general.cpp:528
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:553
void save_sound_buffer_size(const std::size_t size)
Definition: general.cpp:581
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:568
std::string core_id()
Definition: general.cpp:325
void set_language(const std::string &s)
Definition: general.cpp:533
bool grid()
Definition: general.cpp:558
const int def_window_height
Definition: general.cpp:70
bool mouse_scroll_enabled()
Definition: general.cpp:803
std::string partial_color()
Definition: general.cpp:365
int sound_volume()
Definition: general.cpp:613
bool have_setting(const std::string &key)
Definition: general.cpp:209
int font_scaling()
Definition: general.cpp:492
bool minimap_draw_terrain()
Definition: general.cpp:868
void set_show_disengaged_orb(bool show_orb)
Definition: general.cpp:300
void load_credentials()
bool set_music(bool ison)
Definition: general.cpp:749
Standard logging facilities (interface).
bool set_turn_bell(bool ison)
Definition: general.cpp:673
bool turbo()
Definition: general.cpp:468
point window_size()
Returns the size of the window in display units / screen coordinates.
Definition: video.cpp:373
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:643
bool show_unmoved_orb()
Definition: general.cpp:283
void set_damage_prediction_allow_monte_carlo_simulation(bool value)
Definition: general.cpp:987
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:941
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:1007
void set_animate_water(bool value)
Definition: general.cpp:883
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:997
virtual void join_global()
Definition: events.cpp:367
bool use_twelve_hour_clock_format()
Definition: general.cpp:967
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:598
void set_gui_theme(const std::string &s)
Definition: general.cpp:543
bool minimap_terrain_coding()
Definition: general.cpp:838
void set_auto_pixel_scale(bool choice)
Definition: general.cpp:427
void set_disable_auto_moves(bool value)
Definition: general.cpp:977
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
Definition: enum_base.hpp:46