The Battle for Wesnoth  1.19.3+dev
preferences.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2024 - 2024
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 #pragma once
16 
17 #include "config.hpp"
19 #include "filesystem.hpp"
20 #include "game_config.hpp"
21 #include "gui/sort_order.hpp"
24 #include "team.hpp"
25 #include "terrain/translation.hpp"
26 #include "lua/wrapper_lua.h" // for lua_State arguments to friend functions
27 #include "log.hpp"
28 #include <set>
29 
30 struct point;
31 class unit_map;
32 class game_board;
33 
34 namespace pref_constants
35 {
36 const int min_window_width = 800;
37 const int min_window_height = 540;
38 
39 const int def_window_width = 1280;
40 const int def_window_height = 720;
41 
42 const int max_window_width = 1920;
43 const int max_window_height = 1080;
44 
45 const int min_font_scaling = 80;
46 const int max_font_scaling = 150;
47 
48 const int min_pixel_scale = 1;
49 const int max_pixel_scale = 4;
50 
51 const int TRANSITION_UPDATE_OFF = 0;
52 const int TRANSITION_UPDATE_ON = 1;
55 
56 const unsigned char CREDENTIAL_SEPARATOR = '\f';
57 const std::string EMPTY_LOGIN = "@@";
58 
59 const int INFINITE_AUTO_SAVES = 61;
60 
61 const std::string default_addons_server = "add-ons.wesnoth.org";
62 
64 
66 };
67 
68 namespace preferences
69 {
71 {
72 public:
74  {
75  }
76 
77  explicit acquaintance(const config& cfg)
78  {
79  nick_ = cfg["nick"].str();
80  status_ = cfg["status"].str();
81  notes_ = cfg["notes"].str();
82  }
83 
84  acquaintance(const std::string& nick, const std::string& status, const std::string& notes)
85  : nick_(nick)
86  , status_(status)
87  , notes_(notes)
88  {
89  }
90 
91  const std::string& get_nick() const { return nick_; }
92  const std::string& get_status() const { return status_; }
93  const std::string& get_notes() const { return notes_; }
94 
95  void save(config& item)
96  {
97  item["nick"] = nick_;
98  item["status"] = status_;
99  item["notes"] = notes_;
100  }
101 
102 private:
103  /** acquaintance's MP nick */
104  std::string nick_;
105 
106  /**status (e.g., "friend", "ignore") */
107  std::string status_;
108 
109  /** notes on the acquaintance */
110  std::string notes_;
111 };
112 
113 class secure_buffer : public std::vector<unsigned char>
114 {
115 public:
116  template<typename... T> secure_buffer(T&&... args)
117  : vector<unsigned char>(std::forward<T>(args)...)
118  {}
120  {
121  std::fill(begin(), end(), '\0');
122  }
123 };
124 
126 {
127  std::string username, server;
129  login_info(const std::string& username, const std::string& server, const secure_buffer& key)
131  {}
132  login_info(const std::string& username, const std::string& server)
134  {}
135  std::size_t size() const
136  {
137  return 3 + username.size() + server.size() + key.size();
138  }
139 };
140 
141 struct option
142 {
143  option(const config& pref)
144  : type()
145  , name(pref["name"].t_str())
146  , description(pref["description"].t_str())
147  , field(pref["field"].str())
148  , cfg(pref)
149  {
150  const std::string p_type = cfg["type"];
151 
152  if(p_type == "boolean") {
154  } else if(p_type == "int") {
156  } else if(p_type == "combo") {
158  } else if(p_type == "custom") {
160  } else {
161  throw std::invalid_argument("Unknown type '" + p_type + "' for advanced preference " + name);
162  }
163  }
164 
165  enum class avd_type { TOGGLE, SLIDER, COMBO, SPECIAL };
166 
167  /** The preference type. */
169 
170  /** Displayed name. */
172 
173  /** Displayed description. */
175 
176  /** The actual field saved in the prefs file and by which this preference may be accessed. */
177  std::string field;
178 
179  /** The full config, including type-specific options. */
181 };
182 };
183 
184 #define PREF_GETTER_SETTER(pref, type, def) \
185 void set_##pref(const type& value) { \
186  preferences_[prefs_list::pref] = value; \
187 } \
188 type pref() const { \
189  return preferences_[prefs_list::pref].to(def); \
190 }
191 
192 class prefs
193 {
195  friend int impl_preferences_set(lua_State* L);
196  friend int impl_preferences_get(lua_State* L);
197 
198  public:
199  static prefs& get()
200  {
201  static prefs prefs_manager;
202  return prefs_manager;
203  }
204 
205  ~prefs();
206 
207  void write_preferences();
208  void load_advanced_prefs(const game_config_view& gc);
209  void migrate_preferences(const std::string& prefs_dir);
210  void reload_preferences();
211  std::set<std::string> all_attributes();
212 
213  // Proxies for preferences_dialog
214  void load_hotkeys();
215  void save_hotkeys();
216  void clear_hotkeys();
217 
218  // not actually preferences
219  bool show_fps();
220  void set_show_fps(bool value);
221 
222  bool message_private();
223  void set_message_private(bool value);
224 
225  static void disable_preferences_save() {
226  no_preferences_save = true;
227  }
228 
229  static bool preferences_save() {
230  return no_preferences_save;
231  }
232 
233  // getter-only
234  bool message_bell();
235  bool middle_click_scrolls();
236  /** Gets the threshold for when to scroll. This scrolling happens when the mouse is in the application and near the border. */
242  bool get_show_deprecation(bool def);
243  bool get_scroll_when_mouse_outside(bool def);
245  bool show_combat();
246  std::string get_chat_timestamp(const std::time_t& t);
248  std::vector<std::string>* get_history(const std::string& id);
249  std::vector<preferences::option>& get_advanced_preferences() {return advanced_prefs_;}
250 
251  // non-trivial getters+setters
252  point resolution();
253  void set_resolution(const point& res);
254 
255  int pixel_scale();
256  void set_pixel_scale(const int scale);
257 
258  bool turbo();
259  void set_turbo(bool ison);
260 
261  int font_scaling();
262  void set_font_scaling(int scale);
263  int font_scaled(int size);
264 
265  int keepalive_timeout();
266  void keepalive_timeout(int seconds);
267 
268  bool sound();
269  bool set_sound(bool ison);
270 
271  unsigned int sample_rate();
272  void save_sample_rate(const unsigned int rate);
273 
274  std::size_t sound_buffer_size();
275  void save_sound_buffer_size(const std::size_t size);
276 
277  int sound_volume();
278  void set_sound_volume(int vol);
279 
280  int bell_volume();
281  void set_bell_volume(int vol);
282 
283  int ui_volume();
284  void set_ui_volume(int vol);
285 
286  bool music_on();
287  bool set_music(bool ison);
288 
289  int music_volume();
290  void set_music_volume(int vol);
291 
292  bool turn_bell();
293  bool set_turn_bell(bool ison);
294 
295  bool ui_sound_on();
296  bool set_ui_sound(bool ison);
297 
298  void add_alias(const std::string& alias, const std::string& command);
300 
301  std::string allied_color();
302  void set_allied_color(const std::string& color_id);
303 
304  std::string enemy_color();
305  void set_enemy_color(const std::string& color_id);
306 
307  std::string unmoved_color();
308  void set_unmoved_color(const std::string& color_id);
309 
310  std::string partial_color();
311  void set_partial_color(const std::string& color_id);
312 
313  std::string moved_color();
314  void set_moved_color(const std::string& color_id);
315 
316  int scroll_speed();
317  void set_scroll_speed(const int scroll);
318 
319  void set_dir_bookmarks(const config& cfg);
321 
322  std::size_t editor_mru_limit();
323  std::vector<std::string> do_read_editor_mru();
324  void do_commit_editor_mru(const std::vector<std::string>& mru);
325  /** Retrieves the list of recently opened files. */
326  std::vector<std::string> recent_files();
327  /** Adds an entry to the recent files list. */
328  void add_recent_files_entry(const std::string& path);
329 
330  bool use_color_cursors();
331  void set_color_cursors(bool value);
332 
334  void set_show_standing_animations(bool value);
335 
337  bool show_theme_dialog();
338 
339  void set_theme(const std::string& theme);
340  std::string theme();
341 
342  void set_mp_server_program_name(const std::string&);
343  std::string get_mp_server_program_name();
344 
345  bool parse_should_show_lobby_join(const std::string& sender, const std::string& message);
348 
349  const std::map<std::string, preferences::acquaintance>& get_acquaintances();
350  const std::string get_ignored_delim();
351  std::map<std::string, std::string> get_acquaintances_nice(const std::string& filter);
352  std::pair<preferences::acquaintance*, bool> add_acquaintance(const std::string& nick, const std::string& mode, const std::string& notes);
353  void add_completed_campaign(const std::string&campaign_id, const std::string& difficulty_level);
354  bool remove_acquaintance(const std::string& nick);
355  bool is_friend(const std::string& nick);
356  bool is_ignored(const std::string& nick);
357  bool is_campaign_completed(const std::string& campaign_id);
358  bool is_campaign_completed(const std::string& campaign_id, const std::string& difficulty_level);
359 
360  const std::vector<game_config::server_info>& builtin_servers_list();
361  std::vector<game_config::server_info> user_servers_list();
362  void set_user_servers_list(const std::vector<game_config::server_info>& value);
363 
364  std::string network_host();
365  void set_network_host(const std::string& host);
366 
367  std::string campaign_server();
368  void set_campaign_server(const std::string& host);
369 
370  const config& options();
371  void set_options(const config& values);
372 
373  int countdown_init_time();
374  void set_countdown_init_time(int value);
376 
377  int countdown_turn_bonus();
378  void set_countdown_turn_bonus(int value);
380 
382  void set_countdown_reservoir_time(int value);
384 
386  void set_countdown_action_bonus(int value);
388 
389  int village_gold();
390  void set_village_gold(int value);
391 
392  int village_support();
393  void set_village_support(int value);
394 
395  int xp_modifier();
396  void set_xp_modifier(int value);
397 
398  bool remember_password();
399  void set_remember_password(bool remember);
400 
401  std::string login();
402  void set_login(const std::string& login);
403 
404  std::string password(const std::string& server, const std::string& login);
405  void set_password(const std::string& server, const std::string& login, const std::string& key);
406 
407  const std::vector<std::string>& modifications(bool mp = true);
408  void set_modifications(const std::vector<std::string>& value, bool mp = true);
409 
410  std::set<std::string>& encountered_units();
411  std::set<t_translation::terrain_code>& encountered_terrains();
412 
413  // Ask for end turn confirmation
414  bool yellow_confirm();
415  bool green_confirm();
416  bool confirm_no_moves();
417 
418  // Add all recruitable units as encountered so that information
419  // about them are displayed to the user in the help system.
420  void encounter_recruitable_units(const std::vector<team>& teams);
421 
422  // Add all units that exist at the start to the encountered units so
423  // that information about them are displayed to the user in the help
424  // system.
425  void encounter_start_units(const unit_map& units);
426 
427  // Add all units that are recallable as encountered units.
428  void encounter_recallable_units(const std::vector<team>& teams);
429 
430  // Add all terrains on the map as encountered terrains.
431  void encounter_map_terrain(const gamemap& map);
432 
433  // Calls all of the above functions on the current game board
434  void encounter_all_content(const game_board& gb);
435 
436  /**
437  * @param content_for The achievement group the achievement is part of.
438  * @param id The ID of the achievement within the achievement group.
439  * @return True if the achievement exists and is completed, false otherwise.
440  */
441  bool achievement(const std::string& content_for, const std::string& id);
442  /**
443  * Marks the specified achievement as completed.
444  *
445  * @param content_for The achievement group the achievement is part of.
446  * @param id The ID of the achievement within the achievement group.
447  */
448  void set_achievement(const std::string& content_for, const std::string& id);
449 
450  /**
451  * Increments the achievement's current progress by @a amount if it hasn't already been completed.
452  * If you only want to check the achievement's current progress, then omit the last three arguments.
453  * @a amount defaults to 0, which will result in the current progress value being returned without being changed (x + 0 == x).
454  *
455  * Note that this uses the same [in_progress] as is used for set_sub_achievement().
456  *
457  * @param content_for The id of the achievement group this achievement is in.
458  * @param id The id for the specific achievement in the achievement group.
459  * @param limit The maximum value that a specific call to this function can increase the achievement progress value.
460  * @param max_progress The value when the achievement is considered completed.
461  * @param amount The amount to progress the achievement.
462  * @return The achievement's current progress, or -1 if it has already been completed.
463  */
464  int progress_achievement(const std::string& content_for, const std::string& id, int limit = 999999, int max_progress = 999999, int amount = 0);
465 
466  /**
467  * @param content_for The achievement group the achievement is part of.
468  * @param id The ID of the achievement within the achievement group.
469  * @param sub_id The ID of the sub-achievement within the achievement.
470  * @return True if the sub-achievement exists and is completed, false otherwise.
471  */
472  bool sub_achievement(const std::string& content_for, const std::string& id, const std::string& sub_id);
473 
474  /**
475  * Marks the specified sub-achievement as completed.
476  *
477  * Note that this uses the same [in_progress] as is used for progress_achievement().
478  *
479  * @param content_for The achievement group the achievement is part of.
480  * @param id The ID of the achievement within the achievement group.
481  * @param sub_id The ID of the sub-achievement within the achievement.
482  */
483  void set_sub_achievement(const std::string& content_for, const std::string& id, const std::string& sub_id);
484 
492  PREF_GETTER_SETTER(core, std::string, std::string("default"))
493  PREF_GETTER_SETTER(scroll_to_action, bool, true)
494  PREF_GETTER_SETTER(auto_pixel_scale, bool, true)
495  PREF_GETTER_SETTER(maximized, bool, !fullscreen())
496  PREF_GETTER_SETTER(fullscreen, bool, true)
497  PREF_GETTER_SETTER(vsync, bool, true)
498  PREF_GETTER_SETTER(turbo_speed, double, 2.0)
499  PREF_GETTER_SETTER(idle_anim, bool, true)
500  PREF_GETTER_SETTER(idle_anim_rate, int, 0)
501  PREF_GETTER_SETTER(locale, std::string, std::string(""))
502  PREF_GETTER_SETTER(gui2_theme, std::string, std::string(""))
503  PREF_GETTER_SETTER(stop_music_in_background, bool, false)
504  PREF_GETTER_SETTER(tile_size, unsigned, 0)
505  PREF_GETTER_SETTER(mouse_scrolling, bool, true)
506  PREF_GETTER_SETTER(draw_delay, int, -1)
507  PREF_GETTER_SETTER(animate_map, bool, true)
508  PREF_GETTER_SETTER(animate_water, bool, true)
509  PREF_GETTER_SETTER(minimap_movement_coding, bool, true)
510  PREF_GETTER_SETTER(minimap_terrain_coding, bool, true)
511  PREF_GETTER_SETTER(minimap_draw_units, bool, true)
512  PREF_GETTER_SETTER(minimap_draw_villages, bool, true)
513  PREF_GETTER_SETTER(minimap_draw_terrain, bool, true)
514  PREF_GETTER_SETTER(show_side_colors, bool, true)
515  PREF_GETTER_SETTER(grid, bool, false)
516  PREF_GETTER_SETTER(disable_auto_moves, bool, false)
517  PREF_GETTER_SETTER(damage_prediction_allow_monte_carlo_simulation, bool, true)
518  PREF_GETTER_SETTER(addon_manager_saved_order_name, std::string, std::string(""))
519  PREF_GETTER_SETTER(selected_achievement_group, std::string, std::string(""))
520  /** The most recently selected add-on id from the editor. May be an empty string. */
521  PREF_GETTER_SETTER(editor_chosen_addon, std::string, std::string(""))
522  PREF_GETTER_SETTER(_last_cache_cleaned_ver, std::string, std::string(""))
523  PREF_GETTER_SETTER(lobby_whisper_friends_only, bool, false)
524  PREF_GETTER_SETTER(fi_invert, bool, false)
525  PREF_GETTER_SETTER(fi_vacant_slots, bool, false)
526  PREF_GETTER_SETTER(fi_friends_in_game, bool, false)
527  PREF_GETTER_SETTER(fi_blocked_in_game, bool, false)
528  PREF_GETTER_SETTER(editor_auto_update_transitions, int, pref_constants::TRANSITION_UPDATE_PARTIAL)
529  PREF_GETTER_SETTER(editor_draw_terrain_codes, bool, false)
530  PREF_GETTER_SETTER(editor_draw_hex_coordinates, bool, false)
531  PREF_GETTER_SETTER(editor_draw_num_of_bitmaps, bool, false)
532  PREF_GETTER_SETTER(turn_dialog, bool, false)
533  PREF_GETTER_SETTER(enable_planning_mode_on_start, bool, false)
534  PREF_GETTER_SETTER(hide_whiteboard, bool, false)
535  PREF_GETTER_SETTER(allow_observers, bool, true)
536  PREF_GETTER_SETTER(shuffle_sides, bool, false)
537  PREF_GETTER_SETTER(random_faction_mode, std::string, std::string(""))
538  PREF_GETTER_SETTER(mp_use_map_settings, bool, true)
539  PREF_GETTER_SETTER(mp_server_warning_disabled, int, 0)
540  PREF_GETTER_SETTER(mp_random_start_time, bool, true)
541  PREF_GETTER_SETTER(mp_fog, bool, true)
542  PREF_GETTER_SETTER(mp_shroud, bool, true)
543  PREF_GETTER_SETTER(mp_turns, int, 0)
544  PREF_GETTER_SETTER(skip_mp_replay, bool, false)
545  PREF_GETTER_SETTER(blindfold_replay, bool, false)
546  PREF_GETTER_SETTER(mp_countdown, bool, false)
547  PREF_GETTER_SETTER(mp_era, std::string, std::string(""))
548  PREF_GETTER_SETTER(mp_level, std::string, std::string(""))
549  PREF_GETTER_SETTER(mp_level_type, int, 0)
550  PREF_GETTER_SETTER(skip_ai_moves, bool, false)
551  PREF_GETTER_SETTER(save_replays, bool, true)
552  PREF_GETTER_SETTER(delete_saves, bool, false)
553  PREF_GETTER_SETTER(ask_delete, bool, true)
554  PREF_GETTER_SETTER(ally_sighted_interrupts, bool, true)
555  PREF_GETTER_SETTER(auto_save_max, int, 10)
556  PREF_GETTER_SETTER(floating_labels, bool, true)
557  PREF_GETTER_SETTER(chat_timestamp, bool, false)
558  PREF_GETTER_SETTER(chat_lines, int, 6)
559  PREF_GETTER_SETTER(chat_message_aging, int, 20)
560  PREF_GETTER_SETTER(show_all_units_in_help, bool, false)
561  PREF_GETTER_SETTER(custom_command, std::string, std::string(""))
562  PREF_GETTER_SETTER(player_joins_sound, bool, true)
563  PREF_GETTER_SETTER(player_joins_lobby, bool, false)
564  PREF_GETTER_SETTER(player_joins_notif, bool, false)
565  PREF_GETTER_SETTER(player_leaves_sound, bool, true)
566  PREF_GETTER_SETTER(player_leaves_lobby, bool, false)
567  PREF_GETTER_SETTER(player_leaves_notif, bool, false)
568  PREF_GETTER_SETTER(private_message_sound, bool, true)
569  PREF_GETTER_SETTER(private_message_lobby, bool, desktop::notifications::available())
570  PREF_GETTER_SETTER(private_message_notif, bool, true)
571  PREF_GETTER_SETTER(friend_message_sound, bool, false)
572  PREF_GETTER_SETTER(friend_message_lobby, bool, false)
573  PREF_GETTER_SETTER(friend_message_notif, bool, false)
574  PREF_GETTER_SETTER(public_message_sound, bool, false)
575  PREF_GETTER_SETTER(public_message_lobby, bool, false)
576  PREF_GETTER_SETTER(public_message_notif, bool, false)
577  PREF_GETTER_SETTER(server_message_sound, bool, true)
578  PREF_GETTER_SETTER(server_message_lobby, bool, false)
579  PREF_GETTER_SETTER(server_message_notif, bool, true)
580  PREF_GETTER_SETTER(ready_for_start_sound, bool, true)
581  PREF_GETTER_SETTER(ready_for_start_lobby, bool, desktop::notifications::available())
582  PREF_GETTER_SETTER(ready_for_start_notif, bool, false)
583  PREF_GETTER_SETTER(game_has_begun_sound, bool, true)
584  PREF_GETTER_SETTER(game_has_begun_lobby, bool, desktop::notifications::available())
585  PREF_GETTER_SETTER(game_has_begun_notif, bool, false)
586  PREF_GETTER_SETTER(turn_changed_sound, bool, true)
587  PREF_GETTER_SETTER(turn_changed_lobby, bool, desktop::notifications::available())
588  PREF_GETTER_SETTER(turn_changed_notif, bool, false)
589  PREF_GETTER_SETTER(game_created_sound, bool, true)
590  PREF_GETTER_SETTER(game_created_lobby, bool, desktop::notifications::available())
591  PREF_GETTER_SETTER(game_created_notif, bool, true)
592  PREF_GETTER_SETTER(editor_help_text_shown, bool, true)
593 #undef PREF_GETTER_SETTER
594  void clear_mp_alert_prefs();
595 
596  private:
597  prefs();
598  // don't move, assign, or copy a singleton
599  prefs(const prefs& p) = delete;
600  prefs& operator=(const prefs& p) = delete;
601  prefs(const prefs&& p) = delete;
602  prefs& operator=(const prefs&& p) = delete;
603 
604  inline static bool no_preferences_save = false;
605 
607  bool fps_;
608  std::map<std::string, std::set<std::string>> completed_campaigns_;
609  std::set<std::string> encountered_units_set_;
610  std::set<t_translation::terrain_code> encountered_terrains_set_;
611  std::map<std::string, std::vector<std::string>> history_map_;
612  std::map<std::string, preferences::acquaintance> acquaintances_;
615  std::vector<std::string> mp_modifications_;
617  std::vector<std::string> sp_modifications_;
620  std::vector<preferences::login_info> credentials_;
621  std::vector<preferences::option> advanced_prefs_;
622 
623  void load_preferences();
625  void load_credentials();
626  void save_credentials();
627  void clear_credentials();
628 
629  void set_child(const std::string& key, const config& val);
630  optional_const_config get_child(const std::string &key);
631  std::string get(const std::string& key, const std::string& def);
632  config::attribute_value get_as_attribute(const std::string& key);
633 
634  std::string get_system_username();
635  /**
636  * Encrypts the value of @a text using @a key and a hard coded IV using AES.
637  * Max size of @a text must not be larger than 1008 bytes.
638  *
639  * NOTE: This is not meant to provide strong protections against a determined attacker.
640  * This is meant to hide the passwords from malware scanning files for passwords, family/friends poking around, etc.
641  *
642  * @param text The original unencrypted data.
643  * @param key The value to use to encrypt the data. See build_key() for key generation.
644  * @return secure_buffer The encrypted data.
645  */
647  /**
648  * Same as aes_encrypt(), except of course it takes encrypted data as an argument and returns decrypted data.
649  */
651  /**
652  * Fills a secure_buffer with 32 bytes of deterministically generated bytes, then overwrites it with the system login name, server login name, and server name.
653  * If this is more than 32 bytes, then it's truncated. If it's less than 32 bytes, then the pre-generated bytes are used to pad it.
654  *
655  * @param server The server being logged into.
656  * @param login The username being used to login.
657  * @return secure_buffer The data to be used as the encryption key.
658  */
659  preferences::secure_buffer build_key(const std::string& server, const std::string& login);
662 
663  std::set<std::string> unknown_synced_attributes_;
664  std::set<std::string> unknown_unsynced_attributes_;
665  std::set<std::string> unknown_synced_children_;
666  std::set<std::string> unknown_unsynced_children_;
667 
668  // a bit verbose, but it being a compile time error if a preference hasn't been added is nice
669  static constexpr std::array synced_attributes_{
670  prefs_list::player_joins_sound,
671  prefs_list::player_joins_notif,
672  prefs_list::player_joins_lobby,
673  prefs_list::player_leaves_sound,
674  prefs_list::player_leaves_notif,
675  prefs_list::player_leaves_lobby,
676  prefs_list::private_message_sound,
677  prefs_list::private_message_notif,
678  prefs_list::private_message_lobby,
679  prefs_list::friend_message_sound,
680  prefs_list::friend_message_notif,
681  prefs_list::friend_message_lobby,
682  prefs_list::public_message_sound,
683  prefs_list::public_message_notif,
684  prefs_list::public_message_lobby,
685  prefs_list::server_message_sound,
686  prefs_list::server_message_notif,
687  prefs_list::server_message_lobby,
688  prefs_list::ready_for_start_sound,
689  prefs_list::ready_for_start_notif,
690  prefs_list::ready_for_start_lobby,
691  prefs_list::game_has_begun_sound,
692  prefs_list::game_has_begun_notif,
693  prefs_list::game_has_begun_lobby,
694  prefs_list::turn_changed_sound,
695  prefs_list::turn_changed_notif,
696  prefs_list::turn_changed_lobby,
697  prefs_list::game_created_sound,
698  prefs_list::game_created_notif,
699  prefs_list::game_created_lobby,
700  prefs_list::_last_cache_cleaned_ver,
701  prefs_list::addon_manager_saved_order_direction,
702  prefs_list::addon_manager_saved_order_name,
703  prefs_list::alias,
704  prefs_list::allow_observers,
706  prefs_list::ally_sighted_interrupts,
707  prefs_list::auto_save_max,
708  prefs_list::blindfold_replay,
709  prefs_list::campaign_server,
710  prefs_list::chat_lines,
711  prefs_list::chat_timestamp,
712  prefs_list::confirm_end_turn,
713  prefs_list::custom_command,
714  prefs_list::delete_saves,
715  prefs_list::disable_auto_moves,
716  prefs_list::editor_auto_update_transitions,
717  prefs_list::editor_draw_hex_coordinates,
718  prefs_list::editor_draw_num_of_bitmaps,
719  prefs_list::editor_draw_terrain_codes,
720  prefs_list::enable_planning_mode_on_start,
721  prefs_list::encountered_terrain_list,
722  prefs_list::encountered_units,
724  prefs_list::fi_blocked_in_game,
725  prefs_list::fi_friends_in_game,
726  prefs_list::fi_invert,
727  prefs_list::fi_vacant_slots,
728  prefs_list::floating_labels,
729  prefs_list::grid,
730  prefs_list::hide_whiteboard,
731  prefs_list::host,
732  prefs_list::idle_anim,
733  prefs_list::idle_anim_rate,
735  prefs_list::lobby_whisper_friends_only,
736  prefs_list::locale,
737  prefs_list::login,
738  prefs_list::message_bell,
739  prefs_list::minimap_draw_terrain,
740  prefs_list::minimap_draw_units,
741  prefs_list::minimap_draw_villages,
742  prefs_list::minimap_movement_coding,
743  prefs_list::minimap_terrain_coding,
745  prefs_list::mp_countdown,
746  prefs_list::mp_countdown_action_bonus,
747  prefs_list::mp_countdown_init_time,
748  prefs_list::mp_countdown_reservoir_time,
749  prefs_list::mp_countdown_turn_bonus,
750  prefs_list::mp_fog,
751  prefs_list::mp_level_type,
752  prefs_list::mp_random_start_time,
753  prefs_list::mp_server_warning_disabled,
754  prefs_list::mp_shroud,
755  prefs_list::mp_turns,
756  prefs_list::mp_use_map_settings,
757  prefs_list::mp_village_gold,
758  prefs_list::mp_village_support,
759  prefs_list::mp_xp_modifier,
760  prefs_list::music,
763  prefs_list::remember_password,
764  prefs_list::save_replays,
765  prefs_list::scroll,
766  prefs_list::scroll_threshold,
772  prefs_list::show_side_colors,
775  prefs_list::shuffle_sides,
776  prefs_list::skip_ai_moves,
777  prefs_list::skip_mp_replay,
779  prefs_list::sample_rate,
780  prefs_list::stop_music_in_background,
781  prefs_list::turbo,
782  prefs_list::turbo_speed,
784  prefs_list::turn_dialog,
785  prefs_list::ui_sound,
786  prefs_list::unit_standing_animations,
788  prefs_list::ask_delete,
789  prefs_list::chat_message_aging,
790  prefs_list::color_cursors,
791  prefs_list::compress_saves,
792  prefs_list::confirm_load_save_from_different_version,
793  prefs_list::damage_prediction_allow_monte_carlo_simulation,
794  prefs_list::editor_max_recent_files,
795  prefs_list::keepalive_timeout,
796  prefs_list::lobby_auto_open_whisper_windows,
797  prefs_list::middle_click_scrolls,
798  prefs_list::mouse_scrolling,
799  prefs_list::scroll_to_action,
800  prefs_list::scroll_when_mouse_outside,
801  prefs_list::show_all_units_in_help,
802  prefs_list::show_combat,
803  prefs_list::show_deprecation,
804  prefs_list::use_twelve_hour_clock_format,
805  prefs_list::mp_era,
806  prefs_list::mp_level,
807  prefs_list::mp_modifications,
808  prefs_list::selected_achievement_group,
809  prefs_list::sp_modifications,
810  prefs_list::animate_map,
811  prefs_list::animate_water,
812  };
813  static constexpr std::array synced_children_{
814  prefs_list::achievements,
815  prefs_list::completed_campaigns,
816  prefs_list::history,
817  prefs_list::options,
818  };
819  static constexpr std::array unsynced_attributes_{
820  prefs_list::auto_pixel_scale,
821  prefs_list::core,
822  prefs_list::draw_delay,
823  prefs_list::editor_chosen_addon,
824  prefs_list::gui2_theme,
825  prefs_list::mp_server_program_name,
826  prefs_list::pixel_scale,
827  prefs_list::sound_buffer_size,
828  prefs_list::theme,
830  prefs_list::vsync,
831  prefs_list::xresolution,
832  prefs_list::yresolution,
833  prefs_list::font_scale,
838  prefs_list::fullscreen,
839  prefs_list::maximized,
840  };
841  static constexpr std::array unsynced_children_{
842  prefs_list::editor_recent_files,
843  prefs_list::dir_bookmarks,
844  };
845  static_assert(synced_attributes_.size() + synced_children_.size() + unsynced_attributes_.size() + unsynced_children_.size() == prefs_list::values.size(), "attribute missing from lists of synced or unsynced preferences!");
846 };
847 
848 //
849 // might be overkill, but it does best limit the private functionality being exposed
850 //
851 
853 {
854  friend class preferences_dialog;
855 
856  static void set(const std::string& pref, bool value)
857  {
858  prefs::get().preferences_[pref] = value;
859  }
860  static void set(const std::string& pref, int value)
861  {
862  prefs::get().preferences_[pref] = value;
863  }
864  static void set(const std::string& pref, const std::string& value)
865  {
866  prefs::get().preferences_[pref] = value;
867  }
868 
869  static bool get(const std::string& pref, bool def)
870  {
871  return prefs::get().preferences_[pref].to_bool(def);
872  }
873  static int get(const std::string& pref, int def)
874  {
875  return prefs::get().preferences_[pref].to_int(def);
876  }
877  static std::string get(const std::string& pref, const std::string& def)
878  {
879  return prefs::get().get(pref, def);
880  }
881 };
double t
Definition: astarsearch.cpp:63
Variant for storing WML attributes.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
void clear()
Definition: config.cpp:831
Game board class.
Definition: game_board.hpp:47
A class grating read only view to a vector of config objects, viewed as one config with all children ...
Encapsulates the map of the game.
Definition: map.hpp:172
std::string nick_
acquaintance's MP nick
void save(config &item)
Definition: preferences.hpp:95
acquaintance(const std::string &nick, const std::string &status, const std::string &notes)
Definition: preferences.hpp:84
std::string notes_
notes on the acquaintance
const std::string & get_status() const
Definition: preferences.hpp:92
const std::string & get_nick() const
Definition: preferences.hpp:91
std::string status_
status (e.g., "friend", "ignore")
const std::string & get_notes() const
Definition: preferences.hpp:93
acquaintance(const config &cfg)
Definition: preferences.hpp:77
void set_lobby_joins(pref_constants::lobby_joins show)
std::string enemy_color()
config::attribute_value get_as_attribute(const std::string &key)
void set_network_host(const std::string &host)
std::set< t_translation::terrain_code > & encountered_terrains()
const config & options()
bool set_music(bool ison)
void set_sound_volume(int vol)
void set_remember_password(bool remember)
const std::map< std::string, preferences::acquaintance > & get_acquaintances()
optional_const_config get_alias()
bool show_theme_dialog()
void set_turbo(bool ison)
std::string get_system_username()
prefs(const prefs &&p)=delete
bool mp_modifications_initialized_
std::map< std::string, std::vector< std::string > > history_map_
void save_hotkeys()
int village_support()
void set_addon_manager_saved_order_direction(sort_order::type value)
bool middle_click_scrolls()
bool turn_bell()
int countdown_init_time()
std::set< std::string > & encountered_units()
void add_alias(const std::string &alias, const std::string &command)
void set_countdown_reservoir_time(int value)
void write_preferences()
void clear_preferences()
std::vector< std::string > sp_modifications_
void clear_mp_alert_prefs()
The most recently selected add-on id from the editor.
void set_village_gold(int value)
bool confirm_load_save_from_different_version()
std::string network_host()
void clear_countdown_init_time()
std::set< std::string > unknown_unsynced_attributes_
bool set_ui_sound(bool ison)
void set_login(const std::string &login)
static prefs & get()
const std::string get_ignored_delim()
std::map< std::string, preferences::acquaintance > acquaintances_
friend int impl_preferences_set(lua_State *L)
The __newindex metamethod.
static constexpr std::array unsynced_children_
bool fps_
void set_countdown_action_bonus(int value)
int scroll_speed()
bool message_private()
void encounter_recallable_units(const std::vector< team > &teams)
std::map< std::string, std::set< std::string > > completed_campaigns_
bool show_combat()
std::string theme()
optional_const_config dir_bookmarks()
void set_theme(const std::string &theme)
void set_xp_modifier(int value)
void set_user_servers_list(const std::vector< game_config::server_info > &value)
preferences::secure_buffer build_key(const std::string &server, const std::string &login)
Fills a secure_buffer with 32 bytes of deterministically generated bytes, then overwrites it with the...
std::vector< preferences::option > & get_advanced_preferences()
int countdown_action_bonus()
bool sound()
bool is_campaign_completed(const std::string &campaign_id)
void set_allied_color(const std::string &color_id)
bool get_scroll_when_mouse_outside(bool def)
void show_wesnothd_server_search()
bool green_confirm()
int bell_volume()
int mouse_scroll_threshold()
Gets the threshold for when to scroll.
bool is_ignored(const std::string &nick)
std::vector< std::string > mp_modifications_
bool achievement(const std::string &content_for, const std::string &id)
std::set< std::string > unknown_synced_attributes_
void set_enemy_color(const std::string &color_id)
void save_credentials()
void set_password(const std::string &server, const std::string &login, const std::string &key)
bool sub_achievement(const std::string &content_for, const std::string &id, const std::string &sub_id)
void clear_credentials()
std::vector< preferences::login_info > credentials_
std::vector< std::string > do_read_editor_mru()
void encounter_recruitable_units(const std::vector< team > &teams)
bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
static bool preferences_save()
int progress_achievement(const std::string &content_for, const std::string &id, int limit=999999, int max_progress=999999, int amount=0)
Increments the achievement's current progress by amount if it hasn't already been completed.
sort_order::type addon_manager_saved_order_direction()
bool set_turn_bell(bool ison)
static constexpr std::array synced_attributes_
unsigned int sample_rate()
static constexpr std::array synced_children_
void set_options(const config &values)
void set_message_private(bool value)
std::vector< game_config::server_info > user_servers_list()
optional_const_config get_child(const std::string &key)
void load_credentials()
std::string unmoved_color()
void set_music_volume(int vol)
void load_advanced_prefs(const game_config_view &gc)
std::string allied_color()
void set_show_standing_animations(bool value)
void set_show_fps(bool value)
void set_pixel_scale(const int scale)
std::size_t editor_mru_limit()
void set_color_cursors(bool value)
std::vector< preferences::option > advanced_prefs_
void encounter_start_units(const unit_map &units)
void set_countdown_turn_bonus(int value)
pref_constants::lobby_joins get_lobby_joins()
bool show_fps()
void load_hotkeys()
void encounter_map_terrain(const gamemap &map)
int font_scaling()
void set_village_support(int value)
preferences::secure_buffer escape(const preferences::secure_buffer &text)
prefs & operator=(const prefs &&p)=delete
std::string moved_color()
bool confirm_no_moves()
void set_font_scaling(int scale)
std::size_t sound_buffer_size()
bool use_color_cursors()
bool yellow_confirm()
config option_values_
void migrate_preferences(const std::string &prefs_dir)
bool message_bell()
void set_dir_bookmarks(const config &cfg)
bool message_private_on_
std::set< t_translation::terrain_code > encountered_terrains_set_
friend int impl_preferences_get(lua_State *L)
The __index metamethod.
bool set_sound(bool ison)
bool is_friend(const std::string &nick)
void set_achievement(const std::string &content_for, const std::string &id)
Marks the specified achievement as completed.
preferences::secure_buffer aes_decrypt(const preferences::secure_buffer &text, const preferences::secure_buffer &key)
Same as aes_encrypt(), except of course it takes encrypted data as an argument and returns decrypted ...
int village_gold()
config preferences_
void clear_countdown_turn_bonus()
std::string login()
bool music_on()
int font_scaled(int size)
void set_scroll_speed(const int scroll)
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
prefs(const prefs &p)=delete
bool ui_sound_on()
bool options_initialized_
int music_volume()
int pixel_scale()
std::string partial_color()
preferences::secure_buffer unescape(const preferences::secure_buffer &text)
void set_resolution(const point &res)
static void disable_preferences_save()
void set_campaign_server(const std::string &host)
void set_countdown_init_time(int value)
void set_unmoved_color(const std::string &color_id)
bool remove_acquaintance(const std::string &nick)
void clear_countdown_reservoir_time()
void set_ui_volume(int vol)
bool turbo()
const std::vector< std::string > & modifications(bool mp=true)
void do_commit_editor_mru(const std::vector< std::string > &mru)
compression::format save_compression_format()
std::vector< std::string > recent_files()
Retrieves the list of recently opened files.
std::set< std::string > encountered_units_set_
void set_bell_volume(int vol)
std::string get_mp_server_program_name()
prefs & operator=(const prefs &p)=delete
void set_partial_color(const std::string &color_id)
void set_child(const std::string &key, const config &val)
static constexpr std::array unsynced_attributes_
std::set< std::string > all_attributes()
int keepalive_timeout()
void set_mp_server_program_name(const std::string &)
bool remember_password()
int ui_volume()
void add_recent_files_entry(const std::string &path)
Adds an entry to the recent files list.
void set_moved_color(const std::string &color_id)
std::string get_chat_timestamp(const std::time_t &t)
point resolution()
void save_sample_rate(const unsigned int rate)
bool use_twelve_hour_clock_format()
static bool no_preferences_save
int sound_volume()
void set_modifications(const std::vector< std::string > &value, bool mp=true)
void set_sub_achievement(const std::string &content_for, const std::string &id, const std::string &sub_id)
Marks the specified sub-achievement as completed.
int countdown_reservoir_time()
std::set< std::string > unknown_unsynced_children_
const std::vector< game_config::server_info > & builtin_servers_list()
void reload_preferences()
std::string campaign_server()
std::set< std::string > unknown_synced_children_
int countdown_turn_bonus()
void add_completed_campaign(const std::string &campaign_id, const std::string &difficulty_level)
void clear_hotkeys()
void save_sound_buffer_size(const std::size_t size)
int xp_modifier()
void encounter_all_content(const game_board &gb)
std::string password(const std::string &server, const std::string &login)
bool sp_modifications_initialized_
std::vector< std::string > * get_history(const std::string &id)
Returns a pointer to the history vector associated with given id making a new one if it doesn't exist...
preferences::secure_buffer aes_encrypt(const preferences::secure_buffer &text, const preferences::secure_buffer &key)
Encrypts the value of text using key and a hard coded IV using AES.
bool auto_open_whisper_windows()
void load_preferences()
std::map< std::string, std::string > get_acquaintances_nice(const std::string &filter)
bool get_show_deprecation(bool def)
bool show_standing_animations()
void clear_countdown_action_bonus()
Definition: theme.hpp:44
Container associating units to locations.
Definition: map.hpp:98
Definitions for the interface to Wesnoth Markup Language (WML).
Declarations for File-IO.
Standard logging facilities (interface).
void fill(const SDL_Rect &rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Fill an area with the given colour.
Definition: draw.cpp:50
std::string partial_orb_color
std::string moved_orb_color
std::string unmoved_orb_color
std::string ally_orb_color
std::string enemy_orb_color
std::string turn_bell
std::string path
Definition: filesystem.cpp:90
bool show_status_on_ally_orb
bool show_moved_orb
unsigned int tile_size
Definition: game_config.cpp:52
bool show_ally_orb
bool show_disengaged_orb
bool show_partial_orb
bool show_enemy_orb
bool show_unmoved_orb
void show(const std::string &window_id, const t_string &message, const point &mouse, const SDL_Rect &source_rect)
Shows a tip.
Definition: tooltip.cpp:65
static int bell_volume()
static int music_volume()
static bool sound()
static int ui_volume()
static int sound_volume()
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:411
Main entry points of multiplayer mode.
Definition: lobby_data.cpp:49
const int min_window_height
Definition: preferences.hpp:37
const int TRANSITION_UPDATE_ON
Definition: preferences.hpp:52
const int max_pixel_scale
Definition: preferences.hpp:49
const std::string EMPTY_LOGIN
Definition: preferences.hpp:57
const int min_pixel_scale
Definition: preferences.hpp:48
const std::string default_addons_server
Definition: preferences.hpp:61
const int def_window_width
Definition: preferences.hpp:39
const int min_font_scaling
Definition: preferences.hpp:45
const int TRANSITION_UPDATE_COUNT
Definition: preferences.hpp:54
const int min_window_width
Definition: preferences.hpp:36
const int TRANSITION_UPDATE_OFF
Definition: preferences.hpp:51
const int max_font_scaling
Definition: preferences.hpp:46
const int max_window_height
Definition: preferences.hpp:43
const int max_window_width
Definition: preferences.hpp:42
const int def_window_height
Definition: preferences.hpp:40
const int INFINITE_AUTO_SAVES
Definition: preferences.hpp:59
const unsigned char CREDENTIAL_SEPARATOR
Definition: preferences.hpp:56
const int TRANSITION_UPDATE_PARTIAL
Definition: preferences.hpp:53
Modify, read and display user preferences.
Definition: preferences.hpp:69
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:85
void scale(size_t factor, const uint32_t *src, uint32_t *trg, int srcWidth, int srcHeight, ColorFormat colFmt, const ScalerCfg &cfg=ScalerCfg(), int yFirst=0, int yLast=std::numeric_limits< int >::max())
Definition: xbrz.cpp:1170
#define PREF_GETTER_SETTER(pref, type, def)
string_enums::enum_base< random_faction_mode_defines > random_faction_mode
Holds a 2D point.
Definition: point.hpp:25
login_info(const std::string &username, const std::string &server, const secure_buffer &key)
std::size_t size() const
login_info(const std::string &username, const std::string &server)
t_string description
Displayed description.
avd_type type
The preference type.
option(const config &pref)
t_string name
Displayed name.
std::string field
The actual field saved in the prefs file and by which this preference may be accessed.
config cfg
The full config, including type-specific options.
static void set(const std::string &pref, int value)
friend class preferences_dialog
static void set(const std::string &pref, const std::string &value)
static int get(const std::string &pref, int def)
static std::string get(const std::string &pref, const std::string &def)
static bool get(const std::string &pref, bool def)
static void set(const std::string &pref, bool value)
The base template for associating string values with enum values.
Definition: enum_base.hpp:33
mock_party p