The Battle for Wesnoth  1.19.7+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::chrono::system_clock::time_point& t);
248  std::vector<std::string>* get_history(const std::string& id);
249  const 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  std::chrono::seconds countdown_init_time();
374  void set_countdown_init_time(const std::chrono::seconds& value);
376 
377  std::chrono::seconds countdown_turn_bonus();
378  void set_countdown_turn_bonus(const std::chrono::seconds& value);
380 
381  std::chrono::seconds countdown_reservoir_time();
382  void set_countdown_reservoir_time(const std::chrono::seconds& value);
384 
385  std::chrono::seconds countdown_action_bonus();
386  void set_countdown_action_bonus(const std::chrono::seconds& value);
388 
389  std::chrono::minutes chat_message_aging();
390  void set_chat_message_aging(const std::chrono::minutes& value);
391 
392  int village_gold();
393  void set_village_gold(int value);
394 
395  int village_support();
396  void set_village_support(int value);
397 
398  int xp_modifier();
399  void set_xp_modifier(int value);
400 
401  bool remember_password();
402  void set_remember_password(bool remember);
403 
404  std::string login();
405  void set_login(const std::string& login);
406 
407  std::string password(const std::string& server, const std::string& login);
408  void set_password(const std::string& server, const std::string& login, const std::string& key);
409 
410  const std::vector<std::string>& modifications(bool mp = true);
411  void set_modifications(const std::vector<std::string>& value, bool mp = true);
412 
413  std::set<std::string>& encountered_units();
414  std::set<t_translation::terrain_code>& encountered_terrains();
415 
416  // Ask for end turn confirmation
417  bool yellow_confirm();
418  bool green_confirm();
419  bool confirm_no_moves();
420 
421  // Add all recruitable units as encountered so that information
422  // about them are displayed to the user in the help system.
423  void encounter_recruitable_units(const std::vector<team>& teams);
424 
425  // Add all units that exist at the start to the encountered units so
426  // that information about them are displayed to the user in the help
427  // system.
428  void encounter_start_units(const unit_map& units);
429 
430  // Add all units that are recallable as encountered units.
431  void encounter_recallable_units(const std::vector<team>& teams);
432 
433  // Add all terrains on the map as encountered terrains.
434  void encounter_map_terrain(const gamemap& map);
435 
436  // Calls all of the above functions on the current game board
437  void encounter_all_content(const game_board& gb);
438 
439  /**
440  * @param content_for The achievement group the achievement is part of.
441  * @param id The ID of the achievement within the achievement group.
442  * @return True if the achievement exists and is completed, false otherwise.
443  */
444  bool achievement(const std::string& content_for, const std::string& id);
445  /**
446  * Marks the specified achievement as completed.
447  *
448  * @param content_for The achievement group the achievement is part of.
449  * @param id The ID of the achievement within the achievement group.
450  */
451  void set_achievement(const std::string& content_for, const std::string& id);
452 
453  /**
454  * Increments the achievement's current progress by @a amount if it hasn't already been completed.
455  * If you only want to check the achievement's current progress, then omit the last three arguments.
456  * @a amount defaults to 0, which will result in the current progress value being returned without being changed (x + 0 == x).
457  *
458  * Note that this uses the same [in_progress] as is used for set_sub_achievement().
459  *
460  * @param content_for The id of the achievement group this achievement is in.
461  * @param id The id for the specific achievement in the achievement group.
462  * @param limit The maximum value that a specific call to this function can increase the achievement progress value.
463  * @param max_progress The value when the achievement is considered completed.
464  * @param amount The amount to progress the achievement.
465  * @return The achievement's current progress, or -1 if it has already been completed.
466  */
467  int progress_achievement(const std::string& content_for, const std::string& id, int limit = 999999, int max_progress = 999999, int amount = 0);
468 
469  /**
470  * @param content_for The achievement group the achievement is part of.
471  * @param id The ID of the achievement within the achievement group.
472  * @param sub_id The ID of the sub-achievement within the achievement.
473  * @return True if the sub-achievement exists and is completed, false otherwise.
474  */
475  bool sub_achievement(const std::string& content_for, const std::string& id, const std::string& sub_id);
476 
477  /**
478  * Marks the specified sub-achievement as completed.
479  *
480  * Note that this uses the same [in_progress] as is used for progress_achievement().
481  *
482  * @param content_for The achievement group the achievement is part of.
483  * @param id The ID of the achievement within the achievement group.
484  * @param sub_id The ID of the sub-achievement within the achievement.
485  */
486  void set_sub_achievement(const std::string& content_for, const std::string& id, const std::string& sub_id);
487 
488  PREF_GETTER_SETTER(addon_icons, bool, true)
496  PREF_GETTER_SETTER(core, std::string, std::string("default"))
497  PREF_GETTER_SETTER(scroll_to_action, bool, true)
498  PREF_GETTER_SETTER(auto_pixel_scale, bool, true)
499  PREF_GETTER_SETTER(maximized, bool, !fullscreen())
500  PREF_GETTER_SETTER(fullscreen, bool, true)
501  PREF_GETTER_SETTER(vsync, bool, true)
502  PREF_GETTER_SETTER(turbo_speed, double, 2.0)
503  PREF_GETTER_SETTER(idle_anim, bool, true)
504  PREF_GETTER_SETTER(idle_anim_rate, int, 0)
505  PREF_GETTER_SETTER(locale, std::string, std::string(""))
506  PREF_GETTER_SETTER(gui2_theme, std::string, std::string(""))
507  PREF_GETTER_SETTER(stop_music_in_background, bool, false)
508  PREF_GETTER_SETTER(tile_size, unsigned, 0)
509  PREF_GETTER_SETTER(mouse_scrolling, bool, true)
510  PREF_GETTER_SETTER(refresh_rate, int, -1)
511  PREF_GETTER_SETTER(animate_map, bool, true)
512  PREF_GETTER_SETTER(animate_water, bool, true)
513  PREF_GETTER_SETTER(minimap_movement_coding, bool, true)
514  PREF_GETTER_SETTER(minimap_terrain_coding, bool, true)
515  PREF_GETTER_SETTER(minimap_draw_units, bool, true)
516  PREF_GETTER_SETTER(minimap_draw_villages, bool, true)
517  PREF_GETTER_SETTER(minimap_draw_terrain, bool, true)
518  PREF_GETTER_SETTER(show_side_colors, bool, true)
519  PREF_GETTER_SETTER(grid, bool, false)
520  PREF_GETTER_SETTER(disable_auto_moves, bool, false)
521  PREF_GETTER_SETTER(damage_prediction_allow_monte_carlo_simulation, bool, true)
522  PREF_GETTER_SETTER(addon_manager_saved_order_name, std::string, std::string(""))
523  PREF_GETTER_SETTER(selected_achievement_group, std::string, std::string(""))
524  /** The most recently selected add-on id from the editor. May be an empty string. */
525  PREF_GETTER_SETTER(editor_chosen_addon, std::string, std::string(""))
526  PREF_GETTER_SETTER(_last_cache_cleaned_ver, std::string, std::string(""))
527  PREF_GETTER_SETTER(lobby_whisper_friends_only, bool, false)
528  PREF_GETTER_SETTER(fi_invert, bool, false)
529  PREF_GETTER_SETTER(fi_vacant_slots, bool, false)
530  PREF_GETTER_SETTER(fi_friends_in_game, bool, false)
531  PREF_GETTER_SETTER(fi_blocked_in_game, bool, false)
532  PREF_GETTER_SETTER(editor_auto_update_transitions, int, pref_constants::TRANSITION_UPDATE_PARTIAL)
533  PREF_GETTER_SETTER(editor_draw_terrain_codes, bool, false)
534  PREF_GETTER_SETTER(editor_draw_hex_coordinates, bool, false)
535  PREF_GETTER_SETTER(editor_draw_num_of_bitmaps, bool, false)
536  PREF_GETTER_SETTER(turn_dialog, bool, false)
537  PREF_GETTER_SETTER(enable_planning_mode_on_start, bool, false)
538  PREF_GETTER_SETTER(hide_whiteboard, bool, false)
539  PREF_GETTER_SETTER(allow_observers, bool, true)
540  PREF_GETTER_SETTER(shuffle_sides, bool, false)
541  PREF_GETTER_SETTER(random_faction_mode, std::string, std::string(""))
542  PREF_GETTER_SETTER(mp_use_map_settings, bool, true)
543  PREF_GETTER_SETTER(mp_server_warning_disabled, int, 0)
544  PREF_GETTER_SETTER(mp_random_start_time, bool, true)
545  PREF_GETTER_SETTER(mp_fog, bool, true)
546  PREF_GETTER_SETTER(mp_shroud, bool, true)
547  PREF_GETTER_SETTER(mp_turns, int, 0)
548  PREF_GETTER_SETTER(skip_mp_replay, bool, false)
549  PREF_GETTER_SETTER(blindfold_replay, bool, false)
550  PREF_GETTER_SETTER(mp_countdown, bool, false)
551  PREF_GETTER_SETTER(mp_era, std::string, std::string(""))
552  PREF_GETTER_SETTER(mp_level, std::string, std::string(""))
553  PREF_GETTER_SETTER(mp_level_type, int, 0)
554  PREF_GETTER_SETTER(skip_ai_moves, bool, false)
555  PREF_GETTER_SETTER(save_replays, bool, true)
556  PREF_GETTER_SETTER(delete_saves, bool, false)
557  PREF_GETTER_SETTER(ask_delete, bool, true)
558  PREF_GETTER_SETTER(ally_sighted_interrupts, bool, true)
559  PREF_GETTER_SETTER(auto_save_max, int, 10)
560  PREF_GETTER_SETTER(floating_labels, bool, true)
561  PREF_GETTER_SETTER(chat_timestamp, bool, false)
562  PREF_GETTER_SETTER(chat_lines, int, 6)
563  PREF_GETTER_SETTER(show_all_units_in_help, bool, false)
564  PREF_GETTER_SETTER(custom_command, std::string, std::string(""))
565  PREF_GETTER_SETTER(player_joins_sound, bool, true)
566  PREF_GETTER_SETTER(player_joins_lobby, bool, false)
567  PREF_GETTER_SETTER(player_joins_notif, bool, false)
568  PREF_GETTER_SETTER(player_leaves_sound, bool, true)
569  PREF_GETTER_SETTER(player_leaves_lobby, bool, false)
570  PREF_GETTER_SETTER(player_leaves_notif, bool, false)
571  PREF_GETTER_SETTER(private_message_sound, bool, true)
572  PREF_GETTER_SETTER(private_message_lobby, bool, desktop::notifications::available())
573  PREF_GETTER_SETTER(private_message_notif, bool, true)
574  PREF_GETTER_SETTER(friend_message_sound, bool, false)
575  PREF_GETTER_SETTER(friend_message_lobby, bool, false)
576  PREF_GETTER_SETTER(friend_message_notif, bool, false)
577  PREF_GETTER_SETTER(public_message_sound, bool, false)
578  PREF_GETTER_SETTER(public_message_lobby, bool, false)
579  PREF_GETTER_SETTER(public_message_notif, bool, false)
580  PREF_GETTER_SETTER(server_message_sound, bool, true)
581  PREF_GETTER_SETTER(server_message_lobby, bool, false)
582  PREF_GETTER_SETTER(server_message_notif, bool, true)
583  PREF_GETTER_SETTER(ready_for_start_sound, bool, true)
584  PREF_GETTER_SETTER(ready_for_start_lobby, bool, desktop::notifications::available())
585  PREF_GETTER_SETTER(ready_for_start_notif, bool, false)
586  PREF_GETTER_SETTER(game_has_begun_sound, bool, true)
587  PREF_GETTER_SETTER(game_has_begun_lobby, bool, desktop::notifications::available())
588  PREF_GETTER_SETTER(game_has_begun_notif, bool, false)
589  PREF_GETTER_SETTER(turn_changed_sound, bool, true)
590  PREF_GETTER_SETTER(turn_changed_lobby, bool, desktop::notifications::available())
591  PREF_GETTER_SETTER(turn_changed_notif, bool, false)
592  PREF_GETTER_SETTER(game_created_sound, bool, true)
593  PREF_GETTER_SETTER(game_created_lobby, bool, desktop::notifications::available())
594  PREF_GETTER_SETTER(game_created_notif, bool, true)
595  PREF_GETTER_SETTER(editor_help_text_shown, bool, true)
596 #undef PREF_GETTER_SETTER
597  void clear_mp_alert_prefs();
598 
599 private:
600  prefs();
601  // don't move, assign, or copy a singleton
602  prefs(const prefs& p) = delete;
603  prefs& operator=(const prefs& p) = delete;
604  prefs(const prefs&& p) = delete;
605  prefs& operator=(const prefs&& p) = delete;
606 
607  inline static bool no_preferences_save = false;
608 
610  bool fps_;
611  std::map<std::string, std::set<std::string>> completed_campaigns_;
612  std::set<std::string> encountered_units_set_;
613  std::set<t_translation::terrain_code> encountered_terrains_set_;
614  std::map<std::string, std::vector<std::string>> history_map_;
615  std::map<std::string, preferences::acquaintance> acquaintances_;
618  std::vector<std::string> mp_modifications_;
620  std::vector<std::string> sp_modifications_;
623  std::vector<preferences::login_info> credentials_;
624  std::vector<preferences::option> advanced_prefs_;
625 
626  void load_preferences();
628  void load_credentials();
629  void save_credentials();
630  void clear_credentials();
631 
632  void set_child(const std::string& key, const config& val);
633  optional_const_config get_child(const std::string &key);
634  std::string get(const std::string& key, const std::string& def);
635  config::attribute_value get_as_attribute(const std::string& key);
636 
637  std::string get_system_username();
638  /**
639  * Encrypts the value of @a text using @a key and a hard coded IV using AES.
640  * Max size of @a text must not be larger than 1008 bytes.
641  *
642  * NOTE: This is not meant to provide strong protections against a determined attacker.
643  * This is meant to hide the passwords from malware scanning files for passwords, family/friends poking around, etc.
644  *
645  * @param text The original unencrypted data.
646  * @param key The value to use to encrypt the data. See build_key() for key generation.
647  * @return secure_buffer The encrypted data.
648  */
650  /**
651  * Same as aes_encrypt(), except of course it takes encrypted data as an argument and returns decrypted data.
652  */
654  /**
655  * 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.
656  * 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.
657  *
658  * @param server The server being logged into.
659  * @param login The username being used to login.
660  * @return secure_buffer The data to be used as the encryption key.
661  */
662  preferences::secure_buffer build_key(const std::string& server, const std::string& login);
665 
666  std::set<std::string> unknown_synced_attributes_;
667  std::set<std::string> unknown_unsynced_attributes_;
668  std::set<std::string> unknown_synced_children_;
669  std::set<std::string> unknown_unsynced_children_;
670 
671  // a bit verbose, but it being a compile time error if a preference hasn't been added is nice
672  static constexpr std::array synced_attributes_{
673  prefs_list::player_joins_sound,
674  prefs_list::player_joins_notif,
675  prefs_list::player_joins_lobby,
676  prefs_list::player_leaves_sound,
677  prefs_list::player_leaves_notif,
678  prefs_list::player_leaves_lobby,
679  prefs_list::private_message_sound,
680  prefs_list::private_message_notif,
681  prefs_list::private_message_lobby,
682  prefs_list::friend_message_sound,
683  prefs_list::friend_message_notif,
684  prefs_list::friend_message_lobby,
685  prefs_list::public_message_sound,
686  prefs_list::public_message_notif,
687  prefs_list::public_message_lobby,
688  prefs_list::server_message_sound,
689  prefs_list::server_message_notif,
690  prefs_list::server_message_lobby,
691  prefs_list::ready_for_start_sound,
692  prefs_list::ready_for_start_notif,
693  prefs_list::ready_for_start_lobby,
694  prefs_list::game_has_begun_sound,
695  prefs_list::game_has_begun_notif,
696  prefs_list::game_has_begun_lobby,
697  prefs_list::turn_changed_sound,
698  prefs_list::turn_changed_notif,
699  prefs_list::turn_changed_lobby,
700  prefs_list::game_created_sound,
701  prefs_list::game_created_notif,
702  prefs_list::game_created_lobby,
703  prefs_list::_last_cache_cleaned_ver,
704  prefs_list::addon_manager_saved_order_direction,
705  prefs_list::addon_manager_saved_order_name,
706  prefs_list::alias,
707  prefs_list::allow_observers,
709  prefs_list::ally_sighted_interrupts,
710  prefs_list::auto_save_max,
711  prefs_list::blindfold_replay,
712  prefs_list::campaign_server,
713  prefs_list::chat_lines,
714  prefs_list::chat_timestamp,
715  prefs_list::confirm_end_turn,
716  prefs_list::custom_command,
717  prefs_list::delete_saves,
718  prefs_list::disable_auto_moves,
719  prefs_list::editor_auto_update_transitions,
720  prefs_list::editor_draw_hex_coordinates,
721  prefs_list::editor_draw_num_of_bitmaps,
722  prefs_list::editor_draw_terrain_codes,
723  prefs_list::enable_planning_mode_on_start,
724  prefs_list::encountered_terrain_list,
725  prefs_list::encountered_units,
727  prefs_list::fi_blocked_in_game,
728  prefs_list::fi_friends_in_game,
729  prefs_list::fi_invert,
730  prefs_list::fi_vacant_slots,
731  prefs_list::floating_labels,
732  prefs_list::grid,
733  prefs_list::hide_whiteboard,
734  prefs_list::host,
735  prefs_list::idle_anim,
736  prefs_list::idle_anim_rate,
738  prefs_list::lobby_whisper_friends_only,
739  prefs_list::locale,
740  prefs_list::login,
741  prefs_list::message_bell,
742  prefs_list::minimap_draw_terrain,
743  prefs_list::minimap_draw_units,
744  prefs_list::minimap_draw_villages,
745  prefs_list::minimap_movement_coding,
746  prefs_list::minimap_terrain_coding,
748  prefs_list::mp_countdown,
749  prefs_list::mp_countdown_action_bonus,
750  prefs_list::mp_countdown_init_time,
751  prefs_list::mp_countdown_reservoir_time,
752  prefs_list::mp_countdown_turn_bonus,
753  prefs_list::mp_fog,
754  prefs_list::mp_level_type,
755  prefs_list::mp_random_start_time,
756  prefs_list::mp_server_warning_disabled,
757  prefs_list::mp_shroud,
758  prefs_list::mp_turns,
759  prefs_list::mp_use_map_settings,
760  prefs_list::mp_village_gold,
761  prefs_list::mp_village_support,
762  prefs_list::mp_xp_modifier,
763  prefs_list::music,
766  prefs_list::remember_password,
767  prefs_list::save_replays,
768  prefs_list::scroll,
769  prefs_list::scroll_threshold,
775  prefs_list::show_side_colors,
778  prefs_list::shuffle_sides,
779  prefs_list::skip_ai_moves,
780  prefs_list::skip_mp_replay,
782  prefs_list::sample_rate,
783  prefs_list::stop_music_in_background,
784  prefs_list::turbo,
785  prefs_list::turbo_speed,
787  prefs_list::turn_dialog,
788  prefs_list::ui_sound,
789  prefs_list::unit_standing_animations,
791  prefs_list::ask_delete,
792  prefs_list::chat_message_aging,
793  prefs_list::color_cursors,
794  prefs_list::compress_saves,
795  prefs_list::confirm_load_save_from_different_version,
796  prefs_list::damage_prediction_allow_monte_carlo_simulation,
797  prefs_list::editor_max_recent_files,
798  prefs_list::keepalive_timeout,
799  prefs_list::lobby_auto_open_whisper_windows,
800  prefs_list::middle_click_scrolls,
801  prefs_list::mouse_scrolling,
802  prefs_list::scroll_to_action,
803  prefs_list::scroll_when_mouse_outside,
804  prefs_list::show_all_units_in_help,
805  prefs_list::show_combat,
806  prefs_list::show_deprecation,
807  prefs_list::use_twelve_hour_clock_format,
808  prefs_list::mp_era,
809  prefs_list::mp_level,
810  prefs_list::mp_modifications,
811  prefs_list::selected_achievement_group,
812  prefs_list::sp_modifications,
813  prefs_list::animate_map,
814  prefs_list::animate_water,
815  prefs_list::addon_icons,
816  };
817  static constexpr std::array synced_children_{
818  prefs_list::acquaintance,
819  prefs_list::achievements,
820  prefs_list::completed_campaigns,
821  prefs_list::history,
822  prefs_list::options,
823  prefs_list::server,
824  };
825  static constexpr std::array unsynced_attributes_{
826  prefs_list::auto_pixel_scale,
827  prefs_list::core,
828  prefs_list::refresh_rate,
829  prefs_list::editor_chosen_addon,
830  prefs_list::gui2_theme,
831  prefs_list::mp_server_program_name,
832  prefs_list::pixel_scale,
833  prefs_list::sound_buffer_size,
834  prefs_list::theme,
836  prefs_list::vsync,
837  prefs_list::xresolution,
838  prefs_list::yresolution,
839  prefs_list::font_scale,
844  prefs_list::fullscreen,
845  prefs_list::maximized,
846  };
847  static constexpr std::array unsynced_children_{
848  prefs_list::editor_recent_files,
849  prefs_list::dir_bookmarks,
850  };
851  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!");
852 };
853 
854 //
855 // might be overkill, but it does best limit the private functionality being exposed
856 //
857 
859 {
860  friend class preferences_dialog;
861 
862  static void set(const std::string& pref, bool value)
863  {
864  prefs::get().preferences_[pref] = value;
865  }
866  static void set(const std::string& pref, int value)
867  {
868  prefs::get().preferences_[pref] = value;
869  }
870  static void set(const std::string& pref, const std::string& value)
871  {
872  prefs::get().preferences_[pref] = value;
873  }
874 
875  static bool get(const std::string& pref, bool def)
876  {
877  return prefs::get().preferences_[pref].to_bool(def);
878  }
879  static int get(const std::string& pref, int def)
880  {
881  return prefs::get().preferences_[pref].to_int(def);
882  }
883  static std::string get(const std::string& pref, const std::string& def)
884  {
885  return prefs::get().get(pref, def);
886  }
887 };
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:172
void clear()
Definition: config.cpp:828
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)
std::chrono::seconds countdown_turn_bonus()
bool middle_click_scrolls()
bool turn_bell()
void set_countdown_reservoir_time(const std::chrono::seconds &value)
std::set< std::string > & encountered_units()
void add_alias(const std::string &alias, const std::string &command)
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)
std::chrono::minutes chat_message_aging()
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_
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...
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.
std::string get_chat_timestamp(const std::chrono::system_clock::time_point &t)
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()
std::chrono::seconds countdown_init_time()
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()
void set_countdown_turn_bonus(const std::chrono::seconds &value)
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)
pref_constants::lobby_joins get_lobby_joins()
bool show_fps()
void load_hotkeys()
void set_chat_message_aging(const std::chrono::minutes &value)
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::chrono::seconds countdown_action_bonus()
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_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)
std::chrono::seconds countdown_reservoir_time()
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()
const std::vector< preferences::option > & get_advanced_preferences()
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)
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_countdown_init_time(const std::chrono::seconds &value)
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.
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_
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.
void set_countdown_action_bonus(const std::chrono::seconds &value)
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
Game configuration data as global variables.
Definition: build_info.cpp:61
std::string path
Definition: filesystem.cpp:91
bool show_status_on_ally_orb
bool show_moved_orb
unsigned int tile_size
Definition: game_config.cpp:55
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:64
static int bell_volume()
static int music_volume()
static bool sound()
static int ui_volume()
static int sound_volume()
Main entry points of multiplayer mode.
Definition: lobby_data.cpp:50
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(std::string_view 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