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