20 #define GETTEXT_DOMAIN "wesnoth-lib" 43 #define ERR_CFG LOG_STREAM(err , log_config) 46 #define ERR_FS LOG_STREAM(err, log_filesystem) 50 bool no_preferences_save =
false;
88 #ifdef DEFAULT_PREFS_PATH 94 read(user_prefs, *stream);
96 prefs.merge_with(user_prefs);
102 ERR_CFG <<
"Error loading preference, message: " 114 if (no_preferences_save)
return;
132 if (event.type != SDL_WINDOWEVENT)
return;
134 switch(event.window.event) {
135 case SDL_WINDOWEVENT_RESIZED:
140 case SDL_WINDOWEVENT_MAXIMIZED:
145 case SDL_WINDOWEVENT_RESTORED:
168 if(!prefs_file_existed) {
178 void set(
const std::string &key,
bool value)
183 void set(
const std::string &key,
int value)
188 void set(
const std::string &key,
char const *value)
193 void set(
const std::string &key,
const std::string &value)
205 prefs.recursive_clear_value(key);
209 prefs.clear_children(key);
210 prefs.add_child(key, val);
215 return prefs.child(key);
218 void erase(
const std::string& key) {
219 prefs.remove_attribute(key);
223 return prefs.has_attribute(key);
226 std::string
get(
const std::string& key) {
230 std::string
get(
const std::string& key,
const std::string& def) {
234 bool get(
const std::string &key,
bool def)
236 return prefs[key].to_bool(def);
245 no_preferences_save =
true;
258 prefs[
"show_ally_orb"] = show_orb;
265 prefs[
"show_enemy_orb"] = show_orb;
272 prefs[
"show_moved_orb"] = show_orb;
279 prefs[
"show_unmoved_orb"] = show_orb;
286 prefs[
"show_partial_orb"] = show_orb;
293 prefs[
"show_disengaged_orb"] = show_orb;
297 if (color.substr(0,4) ==
"orb_") {
298 if(color[4] >=
'0' && color[4] <=
'9') {
299 return color.substr(5);
301 return color.substr(4);
308 std::string ally_color =
get(
"ally_orb_color");
309 if (ally_color.empty())
314 prefs[
"ally_orb_color"] = color_id;
318 std::string
core_id =
get(
"core");
329 if (enemy_color.empty())
334 prefs[
"enemy_orb_color"] = color_id;
339 if (moved_color.empty())
344 prefs[
"moved_orb_color"] = color_id;
349 if (unmoved_color.empty())
354 prefs[
"unmoved_orb_color"] = color_id;
358 std::string partmoved_color =
get(
"partial_orb_color");
359 if (partmoved_color.empty())
364 prefs[
"partial_orb_color"] = color_id;
369 if (disengaged_color.empty())
374 prefs[
"disengaged_orb_color"] = color_id;
379 return get(
"scroll_to_action",
true);
384 prefs[
"scroll_to_action"] = ison;
389 const unsigned x_res =
prefs[
"xresolution"].to_unsigned();
390 const unsigned y_res =
prefs[
"yresolution"].to_unsigned();
393 if(x_res == 0 || y_res == 0) {
394 return point(def_window_width, def_window_height);
398 std::max<unsigned>(x_res, min_window_width),
399 std::max<unsigned>(y_res, min_window_height)
410 return get(
"fullscreen",
true);
421 prefs[
"maximized"] = ison;
426 prefs[
"fullscreen"] = ison;
435 return get(
"turbo",
false);
440 prefs[
"turbo"] = ison;
445 return prefs[
"turbo_speed"].to_double(2.0);
450 prefs[
"turbo_speed"] = speed;
456 return std::max<int>(std::min<int>(
prefs[
"font_scale"].to_int(100),
max_font_scaling), min_font_scaling);
461 prefs[
"font_scale"] = std::clamp(scale, min_font_scaling, max_font_scaling);
471 return get(
"idle_anim",
true);
476 prefs[
"idle_anim"] = ison;
481 return prefs[
"idle_anim_rate"];
486 prefs[
"idle_anim_rate"] = rate;
491 return prefs[
"locale"];
501 return prefs[
"gui2_theme"];
511 return get(
"show_side_colors",
false);
521 return get(
"grid",
false);
534 const std::size_t buf_size = 4096;
536 const std::size_t buf_size = 1024;
539 return prefs[
"sound_buffer_size"].to_int(buf_size);
545 const char* buf_size =
"4096";
547 const char* buf_size =
"1024";
550 const std::string new_size = lexical_cast_default<std::string>(
size, buf_size);
551 if (
get(
"sound_buffer_size") == new_size)
561 return prefs[
"music_volume"].to_int(100);
570 prefs[
"music_volume"] = vol;
576 return prefs[
"sound_volume"].to_int(100);
585 prefs[
"sound_volume"] = vol;
591 return prefs[
"bell_volume"].to_int(100);
600 prefs[
"bell_volume"] = vol;
606 return prefs[
"UI_volume"].to_int(100);
615 prefs[
"UI_volume"] = vol;
621 return prefs[
"tile_size"].to_unsigned();
631 return get(
"turn_bell",
true);
655 return get(
"UI_sound",
true);
679 return get(
"message_bell",
true);
684 return get(
"sound",
true);
707 return get(
"music",
true);
733 return get(
"stop_music_in_background",
false);
747 const int value = std::clamp<int>(lexical_cast_default<int>(
get(
"scroll"), 50), 1, 100);
748 scroll = value/100.0;
755 prefs[
"scroll"] = new_speed;
756 scroll = new_speed / 100.0;
761 return get(
"middle_click_scrolls",
true);
766 return get(
"mouse_scrolling",
true);
771 set(
"mouse_scrolling", value);
776 return prefs[
"scroll_threshold"].to_int(10);
841 set(
"animate_map", value);
846 set(
"animate_water", value);
861 return prefs[
"draw_delay"].to_int(-1);
866 prefs[
"draw_delay"] = value;
871 return get(
"color_cursors",
true);
892 prefs.clear_children(
"hotkey");
895 void add_alias(
const std::string &alias,
const std::string &command)
898 alias_list[alias] = command;
909 return prefs[
"sample_rate"].to_int(44100);
917 prefs[
"sample_rate"] =
static_cast<int>(rate);
925 return get(
"confirm_load_save_from_different_version",
true);
930 return get(
"use_twelve_hour_clock_format",
false);
935 return get(
"disable_auto_moves",
false);
945 return get(
"damage_prediction_allow_monte_carlo_simulation",
true);
950 set(
"damage_prediction_allow_monte_carlo_simulation", value);
955 return get(
"addon_manager_saved_order_name");
960 set(
"addon_manager_saved_order_name", value);
965 return SORT_ORDER::string_to_enum(
get(
"addon_manager_saved_order_direction"),
SORT_ORDER::NONE);
970 set(
"addon_manager_saved_order_direction", SORT_ORDER::enum_to_string(value));
bool disable_auto_moves()
void _set_turbo(bool ison)
bool set_sound(bool ison)
void set_show_enemy_orb(bool show_orb)
std::string unmoved_color()
void _set_fullscreen(bool ison)
void _set_grid(bool ison)
std::string addon_manager_saved_order_name()
void set_moved_color(const std::string &color_id)
bool minimap_draw_units()
const int min_window_height
void set_allied_color(const std::string &color_id)
void set_unmoved_color(const std::string &color_id)
void _set_maximized(bool ison)
int mouse_scroll_threshold()
Gets the threshold for when to scroll.
void disable_preferences_save()
void set_addon_manager_saved_order_direction(SORT_ORDER value)
void save_hotkeys(config &cfg)
Save the non-default hotkeys to the config.
SORT_ORDER addon_manager_saved_order_direction()
preferences::SORT_ORDER SORT_ORDER
void set_show_unmoved_orb(bool show_orb)
Variant for storing WML attributes.
void _set_color_cursors(bool value)
const int min_window_width
static game_config_view wrap(const config &cfg)
New lexcical_cast header.
void set_scroll_speed(const int new_speed)
bool minimap_movement_coding()
void set_UI_volume(int vol)
void save_turbo_speed(const double speed)
prefs_event_handler event_handler_
filesystem::scoped_istream istream_file(const std::string &fname, bool treat_failure_as_error)
void _set_resolution(const point &res)
void enable_mouse_scroll(bool value)
void clear(const std::string &key)
virtual void leave_global()
void set_tile_size(const unsigned int size)
static CVideo & get_singleton()
void set(const std::string &key, bool value)
unsigned int sample_rate()
bool confirm_load_save_from_different_version()
std::string enemy_orb_color
void set_sound_volume(int vol)
std::string disengaged_color()
Definitions for the interface to Wesnoth Markup Language (WML).
std::string disengaged_orb_color
bool minimap_draw_villages()
void write(std::ostream &out, const configr_of &cfg, unsigned int level)
std::string ally_orb_color
void set_bell_volume(int vol)
std::string get(const std::string &key)
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
void set_enemy_color(const std::string &color_id)
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())
void toggle_minimap_draw_units()
virtual void handle_window_event(const SDL_Event &event)
void read(config &cfg, std::istream &in, abstract_validator *validator)
bool show_disengaged_orb()
const int min_font_scaling
static lg::log_domain log_config("config")
void set_font_scaling(int scale)
void set_music_volume(int vol)
int font_scaled(int size)
void set_show_fps(bool value)
void set_partial_color(const std::string &color_id)
void erase(const std::string &key)
std::unique_ptr< std::istream > scoped_istream
sdl_handler(sdl_handler &&)=delete
void set_show_partial_orb(bool show_orb)
void set_core_id(const std::string &core_id)
config::attribute_value get_as_attribute(const std::string &key)
Modify, read and display user preferences.
void toggle_minimap_draw_terrain()
void set_bell_volume(int vol)
void set_stop_music_in_background(bool ison)
bool damage_prediction_allow_monte_carlo_simulation()
void set_animate_map(bool value)
const char * what() const noexcept
std::string moved_orb_color
void _set_idle_anim(const bool ison)
void set_sound_volume(int vol)
std::string get_default_prefs_file()
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()
const int max_font_scaling
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)
std::unique_ptr< std::ostream > scoped_ostream
const int def_window_width
void save_sample_rate(const unsigned int rate)
std::string allied_color()
void add_alias(const std::string &alias, const std::string &command)
static lg::log_domain log_filesystem("filesystem")
std::string unmoved_orb_color
Default, unset return value.
std::string moved_color()
void toggle_minimap_terrain_coding()
bool middle_click_scrolls()
An exception object used when an IO error occurs.
bool stop_music_in_background()
static map_location::DIRECTION s
void toggle_minimap_movement_coding()
bool set_UI_sound(bool ison)
Declarations for File-IO.
void set_scroll_to_action(bool ison)
void set_ellipses(bool ison)
void save_sound_buffer_size(const std::size_t size)
const config & get_child(const std::string &key)
void reset_default_hotkeys()
Reset all hotkeys to the defaults.
std::size_t sound_buffer_size()
void set_language(const std::string &s)
const int def_window_height
bool mouse_scroll_enabled()
std::string partial_color()
bool have_setting(const std::string &key)
bool minimap_draw_terrain()
void set_show_disengaged_orb(bool show_orb)
bool set_music(bool ison)
Standard logging facilities (interface).
bool set_turn_bell(bool ison)
virtual void handle_event(const SDL_Event &)
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...
void set_damage_prediction_allow_monte_carlo_simulation(bool value)
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()
void set_disengaged_color(const std::string &color_id)
void set_animate_water(bool value)
void _set_idle_anim_rate(const int rate)
void set_addon_manager_saved_order_name(const std::string &value)
virtual void join_global()
bool use_twelve_hour_clock_format()
void set_show_allied_orb(bool show_orb)
std::string enemy_color()
void set_gui_theme(const std::string &s)
bool minimap_terrain_coding()
void set_disable_auto_moves(bool value)
filesystem::scoped_ostream ostream_file(const std::string &fname, bool create_directory)