1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
|
/*
* Copyright (C) 2012-2025 by the Widelands Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*
*/
#ifndef WL_WLAPPLICATION_OPTIONS_H
#define WL_WLAPPLICATION_OPTIONS_H
#include <map>
#include <vector>
#include <SDL_keyboard.h>
#include "io/profile.h"
/* Command line options */
extern bool g_allow_script_console;
extern bool g_write_syncstreams;
/*
* Further explanations for all functions and their return values
* can be found in io/profile.cc
*/
/*
* Check if all options has been read.
*/
void check_config_used();
/*
* Get config values from the config settings cache.
* If the section parameter is omitted the global section will be used.
* Values are available after read_config() is called.
*/
Section& get_config_section();
Section& get_config_section(const std::string&);
Section* get_config_section_ptr(const std::string&);
bool get_config_bool(const std::string& name, bool dflt);
bool get_config_bool(const std::string& section, const std::string& name, bool dflt);
int32_t get_config_int(const std::string& name, int32_t dflt = 0);
int32_t get_config_int(const std::string& section, const std::string& name, int32_t dflt);
uint32_t get_config_natural(const std::string& name, uint32_t dflt);
uint32_t get_config_natural(const std::string& section, const std::string& name, uint32_t dflt);
std::string get_config_string(const std::string& name, const std::string& dflt);
std::string
get_config_string(const std::string& section, const std::string& name, const std::string& dflt);
/*
* Get config values from the config settings cache.
* Throws an exception if the value doesn't exist.
* If the section parameter is omitted the global section will be used.
* Values are available after read_config() is called.
*/
Section& get_config_safe_section();
Section& get_config_safe_section(const std::string&);
/*
* Set config values to the config settings cache.
* If the section parameter is omitted the global section will be used.
* Values will be written to the config file once write_config() is called.
*/
void set_config_bool(const std::string& name, bool value);
void set_config_bool(const std::string& section, const std::string& name, bool value);
void set_config_int(const std::string& name, int32_t value);
void set_config_int(const std::string& section, const std::string& name, int32_t value);
void set_config_string(const std::string& name, const std::string& value);
void set_config_string(const std::string& section,
const std::string& name,
const std::string& value);
static const std::string kFastplaceGroupPrefix = "fastplace_";
// Keyboard shortcuts. The order in which they are defined here
// defines the order in which they appear in the options menu.
enum class KeyboardShortcut : uint16_t {
k_Begin = 0,
kMainMenu_Begin = k_Begin,
kMainMenuSP = kMainMenu_Begin,
kMainMenuNew,
kMainMenuRandomMatch,
kMainMenuCampaign,
kMainMenuTutorial,
kMainMenuLoad,
kMainMenuContinuePlaying,
kMainMenuMP,
kMainMenuLobby,
kMainMenuLogin,
kMainMenuLAN,
kMainMenuE,
kMainMenuEditorNew,
kMainMenuEditorRandom,
kMainMenuEditorLoad,
kMainMenuContinueEditing,
kMainMenuReplay,
kMainMenuLoadReplay,
kMainMenuReplayLast,
kMainMenuOptions,
kMainMenuAddons,
kMainMenuAbout,
kMainMenuQuit,
kMainMenu_End = kMainMenuQuit,
kCommon_Begin = kMainMenu_End + 1,
// These will get different descriptions for the in-game and in-editor help
kCommonLoad = kCommon_Begin,
kCommonSave,
kCommonExit,
kCommonEncyclopedia,
// These can be inserted as one block in the in-game and in-editor help
kCommonGeneral_Begin,
kCommonZoomIn = kCommonGeneral_Begin,
kCommonZoomOut,
kCommonZoomReset,
kCommonContextMenu,
kCommonTextCut,
kCommonTextCopy,
kCommonTextPaste,
kCommonSelectAll,
kCommonDeleteItem,
kCommonTooltipAccessibilityMode,
kCommonFullscreen,
kCommonScreenshot,
kCommonChangeMusic,
kCommonGeneral_End = kCommonChangeMusic,
// These are only shown in the help in debug builds
kCommonDebugConsole,
kCommonCheatMode,
// These will be moved to related items in the in-game and in-editor help
kCommonBuildhelp,
kCommonMinimap,
kCommonQuicknavPrev,
kCommonQuicknavNext,
kCommon_End = kCommonQuicknavNext,
kEditor_Begin = kCommon_End + 1,
kEditorNewMap = kEditor_Begin,
kEditorNewRandomMap,
kEditorLoad, // alias of kCommonLoad
kEditorSave, // alias of kCommonSave
kEditorUploadMap,
kEditorMapOptions,
kEditorExit, // alias of kCommonExit
kEditorHelp, // alias of kCommonEncyclopedia
kEditorShowhideBuildhelp, // alias of kCommonBuildhelp
kEditorShowhideMaximumBuildhelp,
kEditorShowhideHeightHeatMap,
kEditorShowhideGrid,
kEditorShowhideOceans,
kEditorShowhideImmovables,
kEditorShowhideCritters,
kEditorShowhideResources,
kEditorMinimap, // alias of kCommonMinimap
kEditor_Special_MapMove, // special entries for map movement with arrow keys
kEditorQuicknavPrev, // alias of kCommonQuicknavPrev
kEditorQuicknavNext, // alias of kCommonQuicknavNext
kEditorMain_End = kEditorQuicknavNext,
// This will be a separate section in the help
kEditorTools_Begin = kEditorMain_End + 1,
kEditorTools = kEditorTools_Begin,
kEditorChangeHeight,
kEditorRandomHeight,
kEditorTerrain,
kEditorImmovables,
kEditorAnimals,
kEditorResources,
kEditorPortSpaces,
kEditorInfo,
kEditorMapOrigin,
kEditorMapSize,
kEditorPlayers,
kEditorToolHistory,
kEditorUndo,
kEditorRedo,
kEditorTools_End = kEditorRedo,
// These will be grouped to one line in the in-editor help
kEditorToolsize1,
kEditorToolsize2,
kEditorToolsize3,
kEditorToolsize4,
kEditorToolsize5,
kEditorToolsize6,
kEditorToolsize7,
kEditorToolsize8,
kEditorToolsize9,
kEditorToolsize10,
kEditorToolgap0,
kEditorToolgap10,
kEditorToolgap20,
kEditorToolgap30,
kEditorToolgap40,
kEditorToolgap50,
kEditorToolgap60,
kEditorToolgap70,
kEditorToolgap80,
kEditorToolgap90,
kEditor_End = kEditorToolgap90,
kInGame_Begin = kEditor_End + 1,
kInGameSoundOptions = kInGame_Begin,
kInGameSave, // alias of kCommonSave
kInGameLoad, // alias of kCommonLoad
kInGameRestart,
kInGameExit, // alias of kCommonExit
kInGameEncyclopedia, // alias of kCommonEncyclopedia
kInGameMessages,
kInGameObjectives,
kInGameDiplomacy,
kInGameChat,
kInGameStatsGeneral,
kInGameStatsWares,
kInGameStatsBuildings,
kInGameStatsStock,
kInGameStatsSoldiers,
kInGameStatsSeafaring,
kInGameSpeedUp,
kInGameSpeedUpSlow,
kInGameSpeedUpFast,
kInGameSpeedDown,
kInGameSpeedDownSlow,
kInGameSpeedDownFast,
kInGamePause,
kInGameSpeedReset,
kInGameShowhideBuildhelp, // alias of kCommonBuildhelp
kInGameShowhideCensus,
kInGameShowhideStats,
kInGameShowhideSoldiers,
kInGameShowhideBuildings,
kInGameShowhideWorkareas,
kInGameMinimap, // alias of kCommonMinimap
kInGame_Special_MapMove, // special entries for map movement with arrow keys
kInGameScrollToHQ,
kInGameQuicknavPrev, // alias of kCommonQuicknavPrev
kInGameQuicknavNext, // alias of kCommonQuicknavNext
kInGame_Special_Quicknav, // special entries with grouped quicknav set/goto shortcuts
kInGameQuicknavGUI,
kInGamePinnedNote,
kInGameMain_End = kInGamePinnedNote,
// These will be grouped to two lines in the Encyclopedia
kInGameQuicknavSet1,
kInGameQuicknavGoto1,
kInGameQuicknavSet2,
kInGameQuicknavGoto2,
kInGameQuicknavSet3,
kInGameQuicknavGoto3,
kInGameQuicknavSet4,
kInGameQuicknavGoto4,
kInGameQuicknavSet5,
kInGameQuicknavGoto5,
kInGameQuicknavSet6,
kInGameQuicknavGoto6,
kInGameQuicknavSet7,
kInGameQuicknavGoto7,
kInGameQuicknavSet8,
kInGameQuicknavGoto8,
kInGameQuicknavSet9,
kInGameQuicknavGoto9,
// These have their own sections in the Encyclopedia
kInGameMessages_Begin,
kInGameMessagesFilterAll = kInGameMessages_Begin,
kInGameMessagesFilterGeologists,
kInGameMessagesFilterEconomy,
kInGameMessagesFilterSeafaring,
kInGameMessagesFilterWarfare,
kInGameMessagesFilterScenario,
kInGameMessagesFilterDiplomacy,
kInGameMessagesGoto,
kInGameMessages_End = kInGameMessagesGoto,
kInGameSeafaringstats_Begin = kInGameMessages_End + 1,
kInGameSeafaringstatsFilterAll = kInGameSeafaringstats_Begin,
kInGameSeafaringstatsFilterIdle,
kInGameSeafaringstatsFilterShipping,
kInGameSeafaringstatsFilterExpWait,
kInGameSeafaringstatsFilterExpScout,
kInGameSeafaringstatsFilterExpPortspace,
kInGameSeafaringstatsFilterWarship,
kInGameSeafaringstatsFilterRefitting,
kInGameSeafaringstatsGotoShip,
kInGameSeafaringstatsWatchShip,
kInGameSeafaringstatsOpenShipWindow,
kInGameSeafaringstatsOpenShipWindowAndGoto,
kInGameSeafaringstats_End = kInGameSeafaringstatsOpenShipWindowAndGoto,
kInGame_End = kInGameSeafaringstats_End,
kFastplace_Begin = kInGame_End + 1,
kFastplace_End = kFastplace_Begin + 127, // Arbitrary limit of 128 fastplace shortcuts.
k_End = kFastplace_End
};
KeyboardShortcut operator+(const KeyboardShortcut& id, int i);
KeyboardShortcut& operator++(KeyboardShortcut& id);
uint16_t operator-(const KeyboardShortcut& a, const KeyboardShortcut& b);
enum class KeyboardShortcutScope {
kGlobal, // special value that intersects with all other scopes
kMainMenu,
kEditor,
kGame,
};
/**
* Check whether the given shortcut can be used for setting and retrieving the
* actual key combination.
*
* This function should be used when iterating over KeyboardShortcut ranges.
*
* Not "real" shortcuts are aliases and special entries, that are only used for
* help generation to simplify inserting common shortcuts and other related
* help entries at the right place.
*/
bool is_real(KeyboardShortcut id);
bool is_developer_tool(KeyboardShortcut id);
/** Check whether a given shortcut is reserved for a fastplace shortcut slot. */
inline bool is_fastplace(const KeyboardShortcut id) {
return id >= KeyboardShortcut::kFastplace_Begin && id <= KeyboardShortcut::kFastplace_End;
}
void create_replace_shortcut(const std::string& name,
const std::string& descname,
const std::set<KeyboardShortcutScope>& scopes,
SDL_Keysym default_shortcut);
KeyboardShortcut get_highest_used_keyboard_shortcut();
std::vector<std::string> get_all_keyboard_shortcut_names();
/**
* Change a keyboard shortcut.
* @param id ID of the shortcut to change.
* @param code New keysym to use. Ignored when setting a fastplace shortcut to \c "".
* @param conflict If not \c nullptr and a conflict occurs, this will
* be filled in with the conflicting shortcut's ID.
* @return The shortcut was changed successfully. If \c false, #conflict will contain the reason.
*/
bool set_shortcut(KeyboardShortcut id, SDL_Keysym code, KeyboardShortcut* conflict);
/** Look up the keysym assigned to a given shortcut ID. */
SDL_Keysym get_shortcut(KeyboardShortcut);
/** Get the formatted help of the current in game keyboard shortcuts including headers. */
std::string get_ingame_shortcut_help();
struct FastplaceShortcut {
std::string hotkey;
std::string building;
};
/** Get the current fastplace shortcuts for tribe. */
std::vector<FastplaceShortcut> get_active_fastplace_shortcuts(const std::string& tribe);
/** Get the formatted help of the current editor keyboard shortcuts including headers. */
std::string get_editor_shortcut_help();
/** Look up the hardcoded default keysym for a given shortcut ID. */
SDL_Keysym get_default_shortcut(KeyboardShortcut);
/** Replace numpad keysyms with their non-numpad equivalents. */
void normalize_numpad(SDL_Keysym&);
/**
* Filter out all modifiers we are not interested in as well as left/right information.
* @param keymod Modifier bitset to normalize.
* @return #KMOD_NONE or a bitset of #KMOD_CTRL, #KMOD_SHIFT, #KMOD_ALT, and #KMOD_GUI.
*/
uint16_t normalize_keymod(uint16_t keymod);
/** Check if the two modifier bitsets match each other. */
bool matches_keymod(uint16_t, uint16_t);
/** Check if the given keysym should trigger the given shortcut. */
bool matches_shortcut(KeyboardShortcut, SDL_Keysym);
bool matches_shortcut(KeyboardShortcut, SDL_Keycode, int modifiers);
/** Look up the fastplace building assigned to a given shortcut. May return \c "". */
std::string matching_fastplace_shortcut(SDL_Keysym, const std::string& tribename);
/** Read all shortcuts from the config file, or replace all mappings with the default values. */
void init_shortcuts(bool force_defaults = false);
/** The human-readable name of a shortcut identifier. */
std::string to_string(KeyboardShortcut);
/** Get the shortcut ID from an internal shortcut name. Throws an exception for invalid names. */
KeyboardShortcut shortcut_from_string(const std::string&);
bool shortcut_exists(const std::string&);
/**
* Generate a human-readable description of a keyboard shortcut.
* Return value will either be an empty string or have a trailing "+".
*/
std::string keymod_string_for(uint16_t modstate, bool rt_escape = true);
std::string shortcut_string_for(SDL_Keysym, bool rt_escape);
std::string shortcut_string_for(KeyboardShortcut, bool rt_escape);
/** Set or get each tribe's fastplace building for a given fastplace group. */
void set_fastplace_shortcuts(KeyboardShortcut, const std::map<std::string, std::string>&);
const std::map<std::string, std::string>& get_fastplace_shortcuts(KeyboardShortcut);
const std::string& get_fastplace_group_name(KeyboardShortcut);
/** Initialize all fastplace group definitions, but do not overwrite existing mappings. */
void init_fastplace_default_shortcuts(
const std::map<std::string /* key */,
std::map<std::string /* tribe */, std::string /* building */>>&);
/** Clear a shortcut. */
void unset_shortcut(KeyboardShortcut);
inline SDL_Keysym keysym(const SDL_Keycode c, uint16_t mod = 0) {
return SDL_Keysym{SDL_GetScancodeFromKey(c), c, mod, 0};
}
// Default step sizes for changing value of spinbox, slider, etc. on PgUp/PgDown or Ctrl+mousewheel
namespace ChangeBigStep {
constexpr int32_t kSmallRange = 3;
constexpr int32_t kMediumRange = 5;
constexpr int32_t kWideRange = 10;
} // namespace ChangeBigStep
// Return values for changing value of spinbox, slider, etc.
enum class ChangeType : int32_t {
kSetMin = std::numeric_limits<int32_t>::min(), // set value to minimum
// -- keys: Home, Ctrl + decrease keys
kBigMinus = -ChangeBigStep::kWideRange, // decrease by big step -- key: PageDown
kMinus = -1, // decrease -- keys: Left, Down, Minus
kNone = 0, // no change -- all other keys
kPlus = 1, // increase -- keys: Right, Up, Plus
kBigPlus = ChangeBigStep::kWideRange, // increase by big step -- key: PageUp
kSetMax = std::numeric_limits<int32_t>::max() // set value to maximum
// -- keys: End, Ctrl + increase keys
};
// Helper function for spinbox, slider, etc. handle_key(...)
ChangeType get_keyboard_change(SDL_Keysym);
/*
* Sets the directory where to read/write kConfigFile.
*/
void set_config_directory(const std::string& userconfigdir);
const std::string& get_config_file();
/*
* Reads the configuration from kConfigFile.
* Assumes that set_config_directory has been called.
*/
void read_config();
/*
* Writes the configuration to kConfigFile.
* * Assumes that set_config_directory has been called.
*/
void write_config();
#endif // end of include guard: WL_WLAPPLICATION_OPTIONS_H
|