22 #define GETTEXT_DOMAIN "wesnoth-lib"
36 #include <boost/concept_check.hpp>
42 #define ERR_CFG LOG_STREAM(err , log_config)
45 #define ERR_FS LOG_STREAM(err, log_filesystem)
49 bool no_preferences_save =
false;
74 #ifdef DEFAULT_PREFS_PATH
80 read(user_prefs, *stream);
82 prefs.merge_with(user_prefs);
88 ERR_CFG <<
"Error loading preference, message: "
97 if (no_preferences_save)
return;
115 if (event.type != SDL_WINDOWEVENT)
return;
117 switch(event.window.event) {
118 case SDL_WINDOWEVENT_RESIZED:
119 _set_resolution(std::make_pair(event.window.data1,event.window.data2));
123 case SDL_WINDOWEVENT_MAXIMIZED:
128 case SDL_WINDOWEVENT_RESTORED:
145 write(*prefs_file, prefs);
153 if(!prefs_file_existed) {
188 prefs.recursive_clear_value(key);
192 prefs.clear_children(key);
193 prefs.add_child(key, val);
198 return prefs.
child(key);
202 prefs.remove_attribute(key);
206 return prefs.has_attribute(key);
214 return prefs[key].empty() ? def : prefs[key];
219 return prefs[key].to_bool(def);
223 no_preferences_save =
true;
236 prefs[
"show_ally_orb"] = show_orb;
243 prefs[
"show_enemy_orb"] = show_orb;
250 prefs[
"show_moved_orb"] = show_orb;
257 prefs[
"show_unmoved_orb"] = show_orb;
264 prefs[
"show_partial_orb"] = show_orb;
269 if (color.substr(0,4) ==
"orb_") {
270 if(color[4] >=
'0' && color[4] <=
'9') {
271 return color.substr(5);
273 return color.substr(4);
281 if (ally_color.empty())
286 prefs[
"ally_orb_color"] = color_id;
301 if (enemy_color.empty())
306 prefs[
"enemy_orb_color"] = color_id;
311 if (moved_color.empty())
316 prefs[
"moved_orb_color"] = color_id;
321 if (unmoved_color.empty())
326 prefs[
"unmoved_orb_color"] = color_id;
330 std::string partmoved_color =
get(
"partial_orb_color");
331 if (partmoved_color.empty())
336 prefs[
"partial_orb_color"] = color_id;
341 return get(
"scroll_to_action",
true);
346 prefs[
"scroll_to_action"] = ison;
361 const std::string&
x = prefs[
"xresolution"],
y = prefs[
"yresolution"];
363 if (!x.empty() && !y.empty()) {
364 return std::make_pair(
368 return std::pair<int,int>(1024,768);
379 return get(
"fullscreen",
false);
390 prefs[
"maximized"] = ison;
395 prefs[
"fullscreen"] = ison;
404 return get(
"turbo",
false);
409 prefs[
"turbo"] = ison;
414 return prefs[
"turbo_speed"].to_double(2.0);
419 prefs[
"turbo_speed"] = speed;
425 return std::max<int>(50, prefs[
"font_scale"].to_int(100));
430 prefs[
"font_scale"] =
scale;
440 return get(
"idle_anim",
true);
445 prefs[
"idle_anim"] = ison;
450 return prefs[
"idle_anim_rate"];
455 prefs[
"idle_anim_rate"] = rate;
460 return prefs[
"locale"];
470 return get(
"show_side_colors",
false);
480 return get(
"grid",
false);
493 const size_t buf_size = 4096;
495 const size_t buf_size = 1024;
498 return prefs[
"sound_buffer_size"].to_int(buf_size);
504 const char* buf_size =
"4096";
506 const char* buf_size =
"1024";
509 const std::string new_size = lexical_cast_default<std::string>(
size, buf_size);
510 if (
get(
"sound_buffer_size") == new_size)
520 return prefs[
"music_volume"].to_int(100);
529 prefs[
"music_volume"] = vol;
535 return prefs[
"sound_volume"].to_int(100);
544 prefs[
"sound_volume"] = vol;
550 return prefs[
"bell_volume"].to_int(100);
559 prefs[
"bell_volume"] = vol;
565 return prefs[
"UI_volume"].to_int(100);
574 prefs[
"UI_volume"] = vol;
580 return get(
"turn_bell",
true);
604 return get(
"UI_sound",
true);
628 return get(
"message_bell",
true);
633 return get(
"sound",
true);
656 return get(
"music",
true);
686 return get(
"joystick_support_enabled",
false);
691 const int value = lexical_cast_in_range<int>(
get(
"joystick_scroll_deadzone"), 1500, 0, 16000);
697 const int value = lexical_cast_in_range<int>(
get(
"joystick_num_scroll_xaxis"), 0, -1, 3);
703 const int value = lexical_cast_in_range<int>(
get(
"joystick_scroll_xaxis_num"), 0, 0, 7);
709 const int value = lexical_cast_in_range<int>(
get(
"joystick_num_scroll_yaxis"), 0, -1, 3);
715 const int value = lexical_cast_in_range<int>(
get(
"joystick_scroll_yaxis_num"), 1, 0, 7);
721 const int value = lexical_cast_in_range<int>(
get(
"joystick_scroll_deadzone"), 1500, 0, 16000);
727 const int value = lexical_cast_in_range<int>(
get(
"joystick_cursor_deadzone"), 1500, 0, 16000);
733 const int value = lexical_cast_in_range<int>(
get(
"joystick_thrusta_deadzone"), 1500, 0, 16000);
739 const int value = lexical_cast_in_range<int>(
get(
"joystick_thrustb_deadzone"), 1500, 0, 16000);
745 const int value = lexical_cast_in_range<int>(
get(
"joystick_cursor_threshold"), 10000, 0, 16000);
751 const int value = lexical_cast_in_range<int>(
get(
"joystick_num_scroll_xaxis"), 0, -1, 3);
757 const int value = lexical_cast_in_range<int>(
get(
"joystick_scroll_xaxis_num"), 0, 0, 7);
763 const int value = lexical_cast_in_range<int>(
get(
"joystick_num_scroll_yaxis"), 0, -1, 3);
769 const int value = lexical_cast_in_range<int>(
get(
"joystick_scroll_yaxis_num"), 1, 0, 7);
775 const int value = lexical_cast_in_range<int>(
get(
"joystick_num_cursor_xaxis"), 0, -1, 3);
781 const int value = lexical_cast_in_range<int>(
get(
"joystick_cursor_xaxis_num"), 3, 0, 7);
787 const int value = lexical_cast_in_range<int>(
get(
"joystick_num_cursor_yaxis"), 0, -1, 3);
793 const int value = lexical_cast_in_range<int>(
get(
"joystick_cursor_yaxis_num"), 4, 0, 7);
799 const int value = lexical_cast_in_range<int>(
get(
"joystick_num_thrusta_axis"), 0, -1, 3);
805 const int value = lexical_cast_in_range<int>(
get(
"joystick_thrusta_axis_num"), 2, 0, 7);
811 const int value = lexical_cast_in_range<int>(
get(
"joystick_num_thrustb_axis"), 0, -1, 3);
817 const int value = lexical_cast_in_range<int>(
get(
"joystick_thrustb_axis_num"), 2, 0, 7);
824 const int value = lexical_cast_in_range<int>(
get(
"scroll"), 50, 1, 100);
825 scroll = value/100.0;
832 prefs[
"scroll"] = new_speed;
833 scroll = new_speed / 100.0;
838 return get(
"middle_click_scrolls",
true);
843 return get(
"mouse_scrolling",
true);
848 set(
"mouse_scrolling", value);
853 return prefs[
"scroll_threshold"].to_int(10);
918 set(
"animate_map", value);
923 set(
"animate_water", value);
933 set(
"unit_standing_animations", value);
958 return get(
"color_cursors",
true);
979 prefs.clear_children(
"hotkey");
985 alias_list[alias] = command;
996 return prefs[
"sample_rate"].to_int(44100);
1004 prefs[
"sample_rate"] =
int(rate);
1012 return get(
"confirm_load_save_from_different_version",
true);
1017 return get(
"use_twelve_hour_clock_format",
false);
1022 return get(
"disable_auto_moves",
false);
1032 return get(
"disable_loadingscreen_animation",
false);
1037 set(
"disable_loadingscreen_animation", value);
int joystick_mouse_xaxis_num()
bool disable_auto_moves()
void _set_turbo(bool ison)
int joystick_thrustb_axis_num()
bool set_sound(bool ison)
void set_show_enemy_orb(bool show_orb)
std::string unmoved_color()
void _set_fullscreen(bool ison)
int joystick_mouse_yaxis_num()
void _set_grid(bool ison)
void _set_resolution(const std::pair< int, int > &res)
void set_moved_color(const std::string &color_id)
int joystick_num_mouse_xaxis()
bool minimap_draw_units()
void set_allied_color(const std::string &color_id)
void set_unmoved_color(const std::string &color_id)
void set_show_standing_animations(bool value)
GLenum GLenum GLenum GLenum GLenum scale
void _set_maximized(bool ison)
int mouse_scroll_threshold()
Gets the threshold for when to scroll.
void disable_preferences_save()
void save_hotkeys(config &cfg)
Save the non-default hotkeys to the config.
const char * what() const
void set_show_unmoved_orb(bool show_orb)
int joystick_thrusta_axis_num()
void _set_color_cursors(bool value)
void set_disable_loadingscreen_animation(bool value)
config & child_or_add(const std::string &key)
Returns a reference to the first child with the given key.
void set_scroll_speed(const int new_speed)
bool minimap_movement_coding()
int joystick_num_cursor_yaxis()
void set_UI_volume(int vol)
void save_turbo_speed(const double speed)
prefs_event_handler event_handler_
void enable_mouse_scroll(bool value)
void clear(const std::string &key)
int joystick_thrustb_deadzone()
GLuint const GLfloat * val
int joystick_num_mouse_yaxis()
static CVideo & get_singleton()
void set(const std::string &key, bool value)
int joystick_num_thrustb_axis()
unsigned int sample_rate()
GLint GLint GLint GLint GLint GLint y
bool confirm_load_save_from_different_version()
std::string enemy_orb_color
void set_sound_volume(int vol)
int joystick_num_scroll_xaxis()
Definitions for the interface to Wesnoth Markup Language (WML).
int joystick_num_cursor_xaxis()
void save_sound_buffer_size(const size_t size)
int joystick_cursor_yaxis_num()
bool minimap_draw_villages()
int joystick_thrusta_deadzone()
std::string ally_orb_color
bool joystick_support_enabled()
void set_bell_volume(int vol)
std::string get(const std::string &key)
void set_enemy_color(const std::string &color_id)
void toggle_minimap_draw_units()
int joystick_scroll_yaxis_num()
virtual void handle_window_event(const SDL_Event &event)
GLsizei const GLfloat * value
void set_font_scaling(int scale)
std::istream * istream_file(const std::string &fname, bool treat_failure_as_error=true)
void set_music_volume(int vol)
int font_scaled(int size)
void set_show_fps(bool value)
std::ostream * ostream_file(std::string const &fname, bool create_directory=true)
void set_partial_color(const std::string &color_id)
void erase(const std::string &key)
std::pair< int, int > resolution()
void set_show_partial_orb(bool show_orb)
void set_core_id(const std::string &core_id)
Modify, read and display user preferences.
void toggle_minimap_draw_terrain()
void set_bell_volume(int vol)
bool show_standing_animations()
void set_animate_map(bool value)
std::string moved_orb_color
int joystick_scroll_xaxis_num()
void _set_idle_anim(const bool ison)
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
Templates and utility-routines for strings and numbers.
void set_sound_volume(int vol)
std::string get_default_prefs_file()
GLsizei const GLvoid * pointer
void set_show_moved_orb(bool show_orb)
void set_music_volume(int vol)
void set_draw_delay(int value)
void toggle_minimap_draw_villages()
int joystick_num_thrusta_axis()
void set_UI_volume(int vol)
void set_child(const std::string &key, const config &val)
static std::string fix_orb_color_name(const std::string &color)
GLuint GLint GLboolean GLint GLenum access
void save_sample_rate(const unsigned int rate)
static lg::log_domain log_filesystem("filesystem")
size_t sound_buffer_size()
std::string allied_color()
void add_alias(const std::string &alias, const std::string &command)
std::string unmoved_orb_color
std::string moved_color()
void toggle_minimap_terrain_coding()
bool middle_click_scrolls()
An exception object used when an IO error occurs.
GLint GLint GLint GLint GLint x
void toggle_minimap_movement_coding()
bool set_UI_sound(bool ison)
Declarations for File-IO.
void read(config &cfg, std::istream &in, abstract_validator *validator)
void set_scroll_to_action(bool ison)
void set_ellipses(bool ison)
const config & get_child(const std::string &key)
void reset_default_hotkeys()
Reset all hotkeys to the defaults.
int joystick_cursor_xaxis_num()
int joystick_cursor_threshold()
void set_language(const std::string &s)
sdl_handler(const bool auto_join=true)
bool mouse_scroll_enabled()
bool disable_loadingscreen_animation()
std::string partial_color()
bool have_setting(const std::string &key)
bool minimap_draw_terrain()
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...
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
bool set_music(bool ison)
Standard logging facilities (interface).
int joystick_scroll_deadzone()
bool set_turn_bell(bool ison)
virtual void handle_event(const SDL_Event &)
int joystick_mouse_deadzone()
int joystick_cursor_deadzone()
std::string partial_orb_color
std::string get_prefs_file()
A config object defines a single node in a WML file, with access to child nodes.
const config & get_alias()
int joystick_num_scroll_yaxis()
void set_animate_water(bool value)
void write(std::ostream &out, configr_of const &cfg, unsigned int level)
static lg::log_domain log_config("config")
void _set_idle_anim_rate(const int rate)
GLsizei const GLcharARB ** string
virtual void join_global()
bool use_twelve_hour_clock_format()
void set_show_allied_orb(bool show_orb)
std::string enemy_color()
bool minimap_terrain_coding()
void set_disable_auto_moves(bool value)