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