The Battle for Wesnoth  1.19.0+dev
general.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "config.hpp"
19 #include "gui/sort_order.hpp"
20 #include "terrain/translation.hpp"
21 
22 struct point;
23 
24 namespace preferences {
25 
26  struct base_manager
27  {
28  base_manager();
29  ~base_manager();
30  };
31 
32  extern const int min_window_width;
33  extern const int min_window_height;
34 
35  extern const int def_window_width;
36  extern const int def_window_height;
37 
38  extern const int max_window_width;
39  extern const int max_window_height;
40 
41  extern const int min_font_scaling;
42  extern const int max_font_scaling;
43 
44  extern const int min_pixel_scale;
45  extern const int max_pixel_scale;
46 
47  void write_preferences();
48 
49  void set(const std::string& key, const std::string &value);
50  void set(const std::string& key, char const *value);
51  void set(const std::string& key, bool value);
52  void set(const std::string& key, int value);
53  void set(const std::string& key, const config::attribute_value& value);
54  void clear(const std::string& key);
55  void set_child(const std::string& key, const config& val);
56  optional_const_config get_child(const std::string &key);
57  std::string get(const std::string& key);
58  std::string get(const std::string& key, const std::string& def);
59  bool get(const std::string& key, bool def);
60  config::attribute_value get_as_attribute(const std::string& key);
61  void erase(const std::string& key);
62  bool have_setting(const std::string& key);
63 
65 
66  config* get_prefs();
67  void load_base_prefs();
68 
69  std::string core_id();
70  void set_core_id(const std::string& root);
71 
72  bool scroll_to_action();
73  void set_scroll_to_action(bool ison);
74 
75  point resolution();
76  void set_resolution(const point& res);
77 
78  int pixel_scale();
79  void set_pixel_scale(const int scale);
80 
81  bool auto_pixel_scale();
82  void set_auto_pixel_scale(bool choice);
83 
84  bool maximized();
85  void set_maximized(bool ison);
86 
87  bool fullscreen();
88  void set_fullscreen(bool ison);
89 
90  bool vsync();
91  void set_vsync(bool ison);
92 
93  bool turbo();
94  void set_turbo(bool ison);
95 
96  double turbo_speed();
97  void set_turbo_speed(const double speed);
98 
99  int font_scaling();
100  void set_font_scaling(int scale);
101  int font_scaled(int size);
102 
103  int keepalive_timeout();
104  void keepalive_timeout(int seconds);
105 
106  bool idle_anim();
107  void set_idle_anim(const bool ison);
108 
109  int idle_anim_rate();
110  void set_idle_anim_rate(int rate);
111 
112  std::string language();
113  void set_language(const std::string& s);
114 
115  std::string gui_theme();
116  void set_gui_theme(const std::string& s);
117 
118  // Don't rename it to sound() because of a gcc-3.3 branch bug,
119  // which will cause it to conflict with the sound namespace.
120  bool sound_on();
121  bool set_sound(bool ison);
122 
123  unsigned int sample_rate();
124  void save_sample_rate(const unsigned int rate);
125 
126  std::size_t sound_buffer_size();
127  void save_sound_buffer_size(const std::size_t size);
128 
129  int sound_volume();
130  void set_sound_volume(int vol);
131 
132  int bell_volume();
133  void set_bell_volume(int vol);
134 
135  int UI_volume();
136  void set_UI_volume(int vol);
137 
138  bool music_on();
139  bool set_music(bool ison);
140 
141  int music_volume();
142  void set_music_volume(int vol);
143 
145  void set_stop_music_in_background(bool ison);
146 
147  unsigned int tile_size();
148  void set_tile_size(const unsigned int size);
149 
150  bool turn_bell();
151  bool set_turn_bell(bool ison);
152 
153  bool UI_sound_on();
154  bool set_UI_sound(bool ison);
155 
156  bool message_bell();
157 
158  // Proxies for preferences_dialog
159  void load_hotkeys();
160  void save_hotkeys();
161  void clear_hotkeys();
162 
163  void add_alias(const std::string& alias, const std::string& command);
165 
166  std::string allied_color();
167  void set_allied_color(const std::string& color_id);
168 
169  std::string enemy_color();
170  void set_enemy_color(const std::string& color_id);
171 
172  std::string unmoved_color();
173  void set_unmoved_color(const std::string& color_id);
174 
175  std::string partial_color();
176  void set_partial_color(const std::string& color_id);
177 
178  std::string moved_color();
179  void set_moved_color(const std::string& color_id);
180 
181  bool show_ally_orb();
182  void set_show_ally_orb(bool show_orb);
183 
185  void set_show_status_on_ally_orb(bool show_orb);
186 
187  bool show_enemy_orb();
188  void set_show_enemy_orb(bool show_orb);
189 
190  bool show_moved_orb();
191  void set_show_moved_orb(bool show_orb);
192 
193  bool show_unmoved_orb();
194  void set_show_unmoved_orb(bool show_orb);
195 
196  bool show_partial_orb();
197  void set_show_partial_orb(bool show_orb);
198 
199  bool show_disengaged_orb();
200  void set_show_disengaged_orb(bool show_orb);
201 
202  int scroll_speed();
203  void set_scroll_speed(const int scroll);
204 
205  bool middle_click_scrolls();
206  bool mouse_scroll_enabled();
207  void enable_mouse_scroll(bool value);
208 
209  /**
210  * Gets the threshold for when to scroll.
211  *
212  * This scrolling happens when the mouse is in the application and near
213  * the border.
214  */
216 
217  int draw_delay();
218  void set_draw_delay(int value);
219 
220  bool animate_map();
221  void set_animate_map(bool value);
222 
223  bool animate_water();
224  void set_animate_water(bool value);
225 
228 
229  bool minimap_terrain_coding();
231 
232  bool minimap_draw_units();
234 
235  bool minimap_draw_villages();
237 
238  bool minimap_draw_terrain();
240 
241  bool show_fps();
242  void set_show_fps(bool value);
243 
244  bool ellipses();
245  void set_ellipses(bool ison);
246 
247  bool grid();
248  void set_grid(bool ison);
249 
251 
254 
255  bool disable_auto_moves();
256  void set_disable_auto_moves(bool value);
257 
260 
261  std::string addon_manager_saved_order_name();
262  void set_addon_manager_saved_order_name(const std::string& value);
263 
266 
267  std::string selected_achievement_group();
268  void set_selected_achievement_group(const std::string& content_for);
269 
270  /**
271  * @param content_for The achievement group the achievement is part of.
272  * @param id The ID of the achievement within the achievement group.
273  * @return True if the achievement exists and is completed, false otherwise.
274  */
275  bool achievement(const std::string& content_for, const std::string& id);
276  /**
277  * Marks the specified achievement as completed.
278  *
279  * @param content_for The achievement group the achievement is part of.
280  * @param id The ID of the achievement within the achievement group.
281  */
282  void set_achievement(const std::string& content_for, const std::string& id);
283 
284  /**
285  * Increments the achievement's current progress by @a amount if it hasn't already been completed.
286  * If you only want to check the achievement's current progress, then omit the last three arguments.
287  * @a amount defaults to 0, which will result in the current progress value being returned without being changed (x + 0 == x).
288  *
289  * Note that this uses the same [in_progress] as is used for set_sub_achievement().
290  *
291  * @param content_for The id of the achievement group this achievement is in.
292  * @param id The id for the specific achievement in the achievement group.
293  * @param limit The maximum value that a specific call to this function can increase the achievement progress value.
294  * @param max_progress The value when the achievement is considered completed.
295  * @param amount The amount to progress the achievement.
296  * @return The achievement's current progress, or -1 if it has already been completed.
297  */
298  int progress_achievement(const std::string& content_for, const std::string& id, int limit = 999999, int max_progress = 999999, int amount = 0);
299 
300  /**
301  * @param content_for The achievement group the achievement is part of.
302  * @param id The ID of the achievement within the achievement group.
303  * @param sub_id The ID of the sub-achievement within the achievement.
304  * @return True if the sub-achievement exists and is completed, false otherwise.
305  */
306  bool sub_achievement(const std::string& content_for, const std::string& id, const std::string& sub_id);
307 
308  /**
309  * Marks the specified sub-achievement as completed.
310  *
311  * Note that this uses the same [in_progress] as is used for progress_achievement().
312  *
313  * @param content_for The achievement group the achievement is part of.
314  * @param id The ID of the achievement within the achievement group.
315  * @param sub_id The ID of the sub-achievement within the achievement.
316  */
317  void set_sub_achievement(const std::string& content_for, const std::string& id, const std::string& sub_id);
318 
319  /**
320  * @param addon_id The chosen addon id from the editor to store in the preferences.
321  */
322  void set_editor_chosen_addon(const std::string& addon_id);
323 
324  /**
325  * @return The most recently selected add-on id from the editor. May be an empty string.
326  */
327  std::string editor_chosen_addon();
328 
329  void set_mp_alert_option(const std::string& id, const std::string& type, bool value);
330  bool mp_alert_option(const std::string& id, const std::string& type, bool def = false);
331  bool has_mp_alert_option(const std::string& id, const std::string& type);
332 
333  void set_last_cache_cleared_version(const std::string& version);
334  std::string last_cache_cleared_version();
335 
336  bool get_show_deprecation(bool def);
337 
338  bool get_scroll_when_mouse_outside(bool def);
339 
340  void set_dir_bookmarks(const config& cfg);
342 
343 } // end namespace preferences
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
Modify, read and display user preferences.
void set_achievement(const std::string &content_for, const std::string &id)
Marks the specified achievement as completed.
Definition: general.cpp:1026
bool has_mp_alert_option(const std::string &id, const std::string &type)
Definition: general.cpp:1215
void set_scroll_speed(const int new_speed)
Definition: general.cpp:794
void set_show_disengaged_orb(bool show_orb)
Definition: general.cpp:309
bool stop_music_in_background()
Definition: general.cpp:779
const int max_window_height
Definition: general.cpp:73
int idle_anim_rate()
Definition: general.cpp:527
const int def_window_width
Definition: general.cpp:69
std::size_t sound_buffer_size()
Definition: general.cpp:577
void set_resolution(const point &res)
Definition: general.cpp:446
void disable_preferences_save()
Definition: general.cpp:231
void set_turbo(bool ison)
Definition: general.cpp:476
bool get_show_deprecation(bool def)
Definition: general.cpp:1229
void set_allied_color(const std::string &color_id)
Definition: general.cpp:330
void set_addon_manager_saved_order_direction(sort_order::type value)
Definition: general.cpp:998
bool have_setting(const std::string &key)
Definition: general.cpp:209
void set_music_volume(int vol)
Definition: general.cpp:612
void set_show_partial_orb(bool show_orb)
Definition: general.cpp:302
void set_idle_anim(const bool ison)
Definition: general.cpp:522
bool minimap_movement_coding()
Definition: general.cpp:829
void set_maximized(bool ison)
Definition: general.cpp:452
void clear(const std::string &key)
Definition: general.cpp:190
void set_core_id(const std::string &core_id)
Definition: general.cpp:340
bool show_unmoved_orb()
Definition: general.cpp:292
bool set_turn_bell(bool ison)
Definition: general.cpp:682
int UI_volume()
Definition: general.cpp:652
bool vsync()
Definition: general.cpp:441
void set_mp_alert_option(const std::string &id, const std::string &type, bool value)
Definition: general.cpp:1207
void set_show_enemy_orb(bool show_orb)
Definition: general.cpp:281
void set_sound_volume(int vol)
Definition: general.cpp:627
sort_order::type addon_manager_saved_order_direction()
Definition: general.cpp:993
void set_dir_bookmarks(const config &cfg)
Definition: general.cpp:1239
bool maximized()
Definition: general.cpp:431
void set_gui_theme(const std::string &s)
Definition: general.cpp:552
unsigned int tile_size()
Definition: general.cpp:667
void save_sound_buffer_size(const std::size_t size)
Definition: general.cpp:590
const int min_pixel_scale
Definition: general.cpp:78
bool set_sound(bool ison)
Definition: general.cpp:735
bool use_twelve_hour_clock_format()
Definition: general.cpp:958
bool auto_pixel_scale()
Definition: general.cpp:421
bool show_partial_orb()
Definition: general.cpp:299
bool minimap_draw_villages()
Definition: general.cpp:859
void toggle_minimap_draw_villages()
Definition: general.cpp:864
int font_scaled(int size)
Definition: general.cpp:502
std::string moved_color()
Definition: general.cpp:354
void set_bell_volume(int vol)
Definition: general.cpp:642
void set_damage_prediction_allow_monte_carlo_simulation(bool value)
Definition: general.cpp:978
void set_turbo_speed(const double speed)
Definition: general.cpp:486
void set_grid(bool ison)
Definition: general.cpp:572
bool music_on()
Definition: general.cpp:753
void set_draw_delay(int value)
Definition: general.cpp:904
void set(const std::string &key, bool value)
Definition: general.cpp:165
bool minimap_terrain_coding()
Definition: general.cpp:839
std::string last_cache_cleared_version()
Definition: general.cpp:1224
const int max_window_width
Definition: general.cpp:72
bool damage_prediction_allow_monte_carlo_simulation()
Definition: general.cpp:973
void load_base_prefs()
Definition: general.cpp:240
bool scroll_to_action()
Definition: general.cpp:384
void set_unmoved_color(const std::string &color_id)
Definition: general.cpp:370
void set_fullscreen(bool ison)
Definition: general.cpp:457
void set_show_fps(bool value)
Definition: general.cpp:894
bool turbo()
Definition: general.cpp:467
bool sound_on()
Definition: general.cpp:730
int bell_volume()
Definition: general.cpp:637
int mouse_scroll_threshold()
Gets the threshold for when to scroll.
Definition: general.cpp:814
void set_addon_manager_saved_order_name(const std::string &value)
Definition: general.cpp:988
void write_preferences()
Definition: general.cpp:141
std::string addon_manager_saved_order_name()
Definition: general.cpp:983
bool idle_anim()
Definition: general.cpp:517
double turbo_speed()
Definition: general.cpp:481
void set_stop_music_in_background(bool ison)
Definition: general.cpp:784
bool minimap_draw_terrain()
Definition: general.cpp:869
optional_const_config get_alias()
Definition: general.cpp:932
std::string editor_chosen_addon()
Definition: general.cpp:1202
std::string selected_achievement_group()
Definition: general.cpp:1003
void set_animate_water(bool value)
Definition: general.cpp:884
const int max_font_scaling
Definition: general.cpp:76
void clear_hotkeys()
Definition: general.cpp:919
void set_vsync(bool ison)
Definition: general.cpp:462
const int min_font_scaling
Definition: general.cpp:75
std::string partial_color()
Definition: general.cpp:374
point resolution()
Definition: general.cpp:394
const int def_window_height
Definition: general.cpp:70
config::attribute_value get_as_attribute(const std::string &key)
Definition: general.cpp:226
void toggle_minimap_draw_units()
Definition: general.cpp:854
bool fullscreen()
Definition: general.cpp:436
void set_font_scaling(int scale)
Definition: general.cpp:497
bool mouse_scroll_enabled()
Definition: general.cpp:804
bool set_music(bool ison)
Definition: general.cpp:758
void enable_mouse_scroll(bool value)
Definition: general.cpp:809
void set_pixel_scale(const int scale)
Definition: general.cpp:416
bool show_status_on_ally_orb()
Definition: general.cpp:271
void set_show_ally_orb(bool show_orb)
Definition: general.cpp:267
std::string enemy_color()
Definition: general.cpp:344
void add_alias(const std::string &alias, const std::string &command)
Definition: general.cpp:925
void set_disable_auto_moves(bool value)
Definition: general.cpp:968
config * get_prefs()
Definition: general.cpp:235
bool UI_sound_on()
Definition: general.cpp:701
void load_hotkeys()
Definition: general.cpp:909
bool show_ally_orb()
Definition: general.cpp:264
std::string allied_color()
Definition: general.cpp:324
void set_language(const std::string &s)
Definition: general.cpp:542
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.
Definition: general.cpp:1142
bool disable_auto_moves()
Definition: general.cpp:963
int music_volume()
Definition: general.cpp:607
int progress_achievement(const std::string &content_for, const std::string &id, int limit, int max_progress, int amount)
Increments the achievement's current progress by amount if it hasn't already been completed.
Definition: general.cpp:1055
bool show_enemy_orb()
Definition: general.cpp:278
void toggle_minimap_terrain_coding()
Definition: general.cpp:844
bool mp_alert_option(const std::string &id, const std::string &type, bool def)
Definition: general.cpp:1211
void set_UI_volume(int vol)
Definition: general.cpp:657
optional_const_config get_child(const std::string &key)
Definition: general.cpp:200
void save_sample_rate(const unsigned int rate)
Definition: general.cpp:942
bool animate_water()
Definition: general.cpp:824
unsigned int sample_rate()
Definition: general.cpp:937
std::string unmoved_color()
Definition: general.cpp:364
int pixel_scale()
Definition: general.cpp:410
void set_auto_pixel_scale(bool choice)
Definition: general.cpp:426
int keepalive_timeout()
Definition: general.cpp:507
const int max_pixel_scale
Definition: general.cpp:79
const int min_window_height
Definition: general.cpp:67
void set_child(const std::string &key, const config &val)
Definition: general.cpp:195
void save_hotkeys()
Definition: general.cpp:914
bool ellipses()
Definition: general.cpp:557
bool message_bell()
Definition: general.cpp:725
std::string gui_theme()
Definition: general.cpp:547
int draw_delay()
Definition: general.cpp:899
bool set_UI_sound(bool ison)
Definition: general.cpp:706
void set_last_cache_cleared_version(const std::string &version)
Definition: general.cpp:1220
void set_tile_size(const unsigned int size)
Definition: general.cpp:672
void set_ellipses(bool ison)
Definition: general.cpp:562
void set_editor_chosen_addon(const std::string &addon_id)
Definition: general.cpp:1197
bool confirm_load_save_from_different_version()
Definition: general.cpp:953
void set_selected_achievement_group(const std::string &content_for)
Definition: general.cpp:1008
void set_enemy_color(const std::string &color_id)
Definition: general.cpp:350
bool show_moved_orb()
Definition: general.cpp:285
void set_moved_color(const std::string &color_id)
Definition: general.cpp:360
bool minimap_draw_units()
Definition: general.cpp:849
std::string core_id()
Definition: general.cpp:334
const int min_window_width
Definition: general.cpp:66
void set_animate_map(bool value)
Definition: general.cpp:879
bool middle_click_scrolls()
Definition: general.cpp:799
void toggle_minimap_draw_terrain()
Definition: general.cpp:874
std::string get(const std::string &key)
Definition: general.cpp:213
int sound_volume()
Definition: general.cpp:622
void set_show_status_on_ally_orb(bool show_orb)
Definition: general.cpp:274
void set_idle_anim_rate(int rate)
Definition: general.cpp:532
void set_show_moved_orb(bool show_orb)
Definition: general.cpp:288
void erase(const std::string &key)
Definition: general.cpp:205
std::string language()
Definition: general.cpp:537
bool grid()
Definition: general.cpp:567
void set_show_unmoved_orb(bool show_orb)
Definition: general.cpp:295
bool achievement(const std::string &content_for, const std::string &id)
Definition: general.cpp:1013
bool animate_map()
Definition: general.cpp:819
optional_const_config dir_bookmarks()
Definition: general.cpp:1243
bool show_disengaged_orb()
Definition: general.cpp:306
int font_scaling()
Definition: general.cpp:491
bool show_fps()
Definition: general.cpp:889
void toggle_minimap_movement_coding()
Definition: general.cpp:834
void set_scroll_to_action(bool ison)
Definition: general.cpp:389
bool get_scroll_when_mouse_outside(bool def)
Definition: general.cpp:1234
void set_use_twelve_hour_clock_format(bool value)
int scroll_speed()
Definition: general.cpp:789
void set_partial_color(const std::string &color_id)
Definition: general.cpp:380
bool turn_bell()
Definition: general.cpp:677
bool sub_achievement(const std::string &content_for, const std::string &id, const std::string &sub_id)
Definition: general.cpp:1116
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, const ScalerCfg &cfg=ScalerCfg(), int yFirst=0, int yLast=std::numeric_limits< int >::max())
Definition: xbrz.cpp:1189
Holds a 2D point.
Definition: point.hpp:25
static map_location::DIRECTION s