From 9c392321bba60428191aab57d8f95a71ba5f83a0 Mon Sep 17 00:00:00 2001 From: pentarctagon Date: Mon, 27 May 2024 23:38:33 -0500 Subject: [PATCH] Refactor the preferences into a proper singleton. The current preferences handling is a mess: * it's essentially a global config object that anything can modify in any way the caller wants, which is managed across multiple source files which have their own oddities and interdependencies. * the general preferences has its own bit of SDL event handling and while I get the idea behind `events::sdl_handler` there's no reason to have SDL events handled in the preferences instead of just calling the relevant preferences setter for each event when it happens. * the general preferences is where most of the preferences are handled and has its `base_manager` struct, which is part of the `manager` struct in the game preferences, which is then implicitly initialized as part of game_launcher's constructor. * the editor preferences are the only preferences in a sub-namespace `preferences::editor` while all other preferences are just in the `preferences` namespace. * the display, editor, and lobby preferences are all dependent on including the game preferences, the credentials are dependent on including the general preferences (but not the game preferences), the game preferences are dependent on including the general preferences, and the advanced preferences are entirely their own thing which is dependent on none of the other preference functionality and manages its own singleton. * nothing checks whether the preferences file has actually been loaded before allowing values to be read from or written to the preferences config - if you attempt to get a value too early in wesnoth's initialization it will silently just give you whatever the default value for that preference happens to be. With this there is instead a single access point (with exceptions handled via friend functions/classes), all predefined preferences are accessed via their own setter/getter, and all mainline preferences are defined in a single file (preference_list.hpp) so it's easily findable what preferences exist and where they're used. Having the list of all mainline preferences listed out also allows the lua preferences API to provide that full list rather than just the list of the preferences that have been set so far. Also it now checks for whether the location of the preferences file is known before attempting to load the preferences file and asserts if someone attempts to use the preferences too early. --- .gitignore | 1 + projectfiles/CodeBlocks-SCons/wesnoth.cbp | 17 +- projectfiles/CodeBlocks/tests.cbp | 17 +- projectfiles/CodeBlocks/wesnoth.cbp | 17 +- .../project.pbxproj | 74 +- source_lists/libwesnoth | 3 +- source_lists/wesnoth | 6 +- src/achievements.cpp | 6 +- src/actions/advancement.cpp | 6 +- src/actions/attack.cpp | 4 +- src/actions/create.cpp | 4 +- src/actions/move.cpp | 4 +- src/actions/unit_creator.cpp | 6 +- src/addon/client.cpp | 7 +- src/addon/manager_ui.cpp | 8 +- src/ai/actions.cpp | 8 +- src/attack_prediction.cpp | 4 +- src/chat_command_handler.cpp | 10 +- src/chat_events.cpp | 8 +- src/controller_base.cpp | 12 +- src/countdown_clock.cpp | 4 +- src/cursor.cpp | 5 +- src/deprecation.cpp | 4 +- src/desktop/paths.cpp | 6 +- src/display.cpp | 38 +- src/display.hpp | 4 +- src/display_chat_manager.cpp | 19 +- src/draw_manager.cpp | 4 +- src/editor/controller/editor_controller.cpp | 28 +- src/editor/map/context_manager.cpp | 26 +- src/editor/map/context_manager.hpp | 4 +- src/editor/map/map_context.cpp | 4 +- src/events.cpp | 8 + src/filesystem.cpp | 5 + src/filesystem.hpp | 2 + src/floating_textbox.cpp | 4 +- src/font/text.cpp | 4 +- src/format_time_summary.cpp | 6 +- src/game_board.cpp | 6 +- src/game_classification.cpp | 4 +- src/game_config_manager.cpp | 26 +- src/game_display.cpp | 4 +- src/game_initialization/configure_engine.cpp | 41 +- src/game_initialization/connect_engine.cpp | 23 +- src/game_initialization/create_engine.cpp | 8 +- src/game_initialization/lobby_data.cpp | 9 +- src/game_initialization/multiplayer.cpp | 19 +- src/game_initialization/playcampaign.cpp | 14 +- src/game_launcher.cpp | 57 +- src/game_launcher.hpp | 2 - src/game_state.cpp | 4 +- src/gui/auxiliary/tips.cpp | 4 +- src/gui/dialogs/achievements_dialog.cpp | 6 +- src/gui/dialogs/addon/addon_auth.cpp | 6 +- src/gui/dialogs/addon/manager.cpp | 22 +- src/gui/dialogs/campaign_difficulty.cpp | 4 +- src/gui/dialogs/campaign_selection.cpp | 8 +- src/gui/dialogs/chat_log.cpp | 4 +- src/gui/dialogs/editor/choose_addon.cpp | 10 +- src/gui/dialogs/game_delete.cpp | 10 +- src/gui/dialogs/game_load.cpp | 4 +- src/gui/dialogs/language_selection.cpp | 4 +- src/gui/dialogs/migrate_version_selection.cpp | 14 +- .../dialogs/multiplayer/faction_select.cpp | 4 +- src/gui/dialogs/multiplayer/lobby.cpp | 27 +- .../dialogs/multiplayer/mp_alerts_options.cpp | 20 +- .../dialogs/multiplayer/mp_change_control.cpp | 4 +- src/gui/dialogs/multiplayer/mp_connect.cpp | 14 +- .../dialogs/multiplayer/mp_create_game.cpp | 103 +- .../multiplayer/mp_host_game_prompt.cpp | 10 +- src/gui/dialogs/multiplayer/mp_join_game.cpp | 14 +- src/gui/dialogs/multiplayer/mp_login.cpp | 14 +- .../multiplayer/mp_method_selection.cpp | 6 +- .../dialogs/multiplayer/mp_options_helper.cpp | 4 +- src/gui/dialogs/multiplayer/player_info.cpp | 8 +- .../multiplayer/player_list_helper.cpp | 6 +- src/gui/dialogs/preferences_dialog.cpp | 250 +- src/gui/dialogs/preferences_dialog.hpp | 27 +- src/gui/dialogs/select_orb_colors.cpp | 52 +- src/gui/dialogs/title_screen.cpp | 10 +- src/gui/gui.cpp | 4 +- src/gui/widgets/chatbox.cpp | 34 +- src/gui/widgets/combobox.cpp | 1 - src/gui/widgets/listbox.hpp | 2 +- src/gui/widgets/text_box.cpp | 4 +- src/gui/widgets/unit_preview_pane.cpp | 4 +- src/help/help.cpp | 10 +- src/help/help_impl.cpp | 10 +- src/help/help_text_area.cpp | 4 +- src/help/help_topic_generators.cpp | 6 +- src/hotkey/command_executor.cpp | 30 +- src/hotkey/hotkey_handler.cpp | 20 +- src/language.cpp | 4 +- src/menu_events.cpp | 54 +- src/minimap.cpp | 18 +- src/mouse_handler_base.cpp | 8 +- src/mp_ui_alerts.cpp | 107 +- src/play_controller.cpp | 23 +- src/playmp_controller.cpp | 9 +- src/playsingle_controller.cpp | 16 +- src/preferences/advanced.cpp | 93 - src/preferences/advanced.hpp | 73 - src/preferences/credentials.cpp | 516 --- src/preferences/credentials.hpp | 31 - src/preferences/display.cpp | 131 - src/preferences/display.hpp | 29 - src/preferences/editor.cpp | 157 - src/preferences/editor.hpp | 55 - src/preferences/game.cpp | 1019 ------ src/preferences/game.hpp | 266 -- src/preferences/general.cpp | 1248 -------- src/preferences/general.hpp | 343 -- src/preferences/lobby.cpp | 76 - src/preferences/lobby.hpp | 37 - src/preferences/preferences.cpp | 2818 +++++++++++++++++ src/preferences/preferences.hpp | 873 +++++ src/preferences/preferences_list.hpp | 453 +++ src/replay.cpp | 10 +- src/reports.cpp | 6 +- src/save_index.cpp | 6 +- src/savegame.cpp | 6 +- src/scripting/game_lua_kernel.cpp | 16 +- src/scripting/lua_audio.cpp | 10 +- src/scripting/lua_preferences.cpp | 22 +- src/sound.cpp | 38 +- src/synced_commands.cpp | 4 +- src/terrain/builder.cpp | 4 +- src/terrain/type_data.cpp | 2 +- src/terrain/type_data.hpp | 2 +- src/tests/gui/test_gui2.cpp | 8 +- src/units/animation_component.cpp | 11 +- src/units/drawer.cpp | 6 +- src/units/orb_status.cpp | 24 +- src/units/orb_status.hpp | 4 +- src/units/udisplay.cpp | 10 +- src/units/unit.cpp | 4 +- src/video.cpp | 50 +- src/video.hpp | 2 +- src/wesnothd_connection.cpp | 6 +- src/whiteboard/manager.cpp | 6 +- 140 files changed, 5079 insertions(+), 5047 deletions(-) delete mode 100644 src/preferences/advanced.cpp delete mode 100644 src/preferences/advanced.hpp delete mode 100644 src/preferences/credentials.cpp delete mode 100644 src/preferences/credentials.hpp delete mode 100644 src/preferences/display.cpp delete mode 100644 src/preferences/display.hpp delete mode 100644 src/preferences/editor.cpp delete mode 100644 src/preferences/editor.hpp delete mode 100644 src/preferences/game.cpp delete mode 100644 src/preferences/game.hpp delete mode 100644 src/preferences/general.cpp delete mode 100644 src/preferences/general.hpp delete mode 100644 src/preferences/lobby.cpp delete mode 100644 src/preferences/lobby.hpp create mode 100644 src/preferences/preferences.cpp create mode 100644 src/preferences/preferences.hpp create mode 100644 src/preferences/preferences_list.hpp diff --git a/.gitignore b/.gitignore index 5afc83be2a6be..36e9aac6d9c8a 100644 --- a/.gitignore +++ b/.gitignore @@ -221,6 +221,7 @@ config.h callgrind.out.* data/dist clean.sh +widgets_tested.log # clangd cache .cache/clangd diff --git a/projectfiles/CodeBlocks-SCons/wesnoth.cbp b/projectfiles/CodeBlocks-SCons/wesnoth.cbp index 968affabae1e3..5921e39e2ff5e 100644 --- a/projectfiles/CodeBlocks-SCons/wesnoth.cbp +++ b/projectfiles/CodeBlocks-SCons/wesnoth.cbp @@ -889,20 +889,9 @@ - - - - - - - - - - - - - - + + + diff --git a/projectfiles/CodeBlocks/tests.cbp b/projectfiles/CodeBlocks/tests.cbp index 2ffcf4db90aef..8df995c9067ff 100644 --- a/projectfiles/CodeBlocks/tests.cbp +++ b/projectfiles/CodeBlocks/tests.cbp @@ -971,20 +971,9 @@ - - - - - - - - - - - - - - + + + diff --git a/projectfiles/CodeBlocks/wesnoth.cbp b/projectfiles/CodeBlocks/wesnoth.cbp index ac57d5da65529..a4a4772c9aabe 100644 --- a/projectfiles/CodeBlocks/wesnoth.cbp +++ b/projectfiles/CodeBlocks/wesnoth.cbp @@ -1003,20 +1003,9 @@ - - - - - - - - - - - - - - + + + diff --git a/projectfiles/Xcode/The Battle for Wesnoth.xcodeproj/project.pbxproj b/projectfiles/Xcode/The Battle for Wesnoth.xcodeproj/project.pbxproj index 4c1fc5ac6dbdc..1ac3f21da2195 100644 --- a/projectfiles/Xcode/The Battle for Wesnoth.xcodeproj/project.pbxproj +++ b/projectfiles/Xcode/The Battle for Wesnoth.xcodeproj/project.pbxproj @@ -84,12 +84,6 @@ 4649B87E20288DC000827CFB /* random_deterministic.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC0680231EA920A300EEE03B /* random_deterministic.cpp */; }; 4649B87F20288DC300827CFB /* random_synced.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC0680251EA920A300EEE03B /* random_synced.cpp */; }; 4649B88020288DC600827CFB /* random.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC0680271EA920A300EEE03B /* random.cpp */; }; - 4649B88120288DF200827CFB /* credentials.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 903F959B1ED5489500F1BDD3 /* credentials.cpp */; }; - 4649B88220288DF500827CFB /* display.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC54017B1EBE0C4500AE66EE /* display.cpp */; }; - 4649B88320288DF800827CFB /* editor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC54017D1EBE0C4500AE66EE /* editor.cpp */; }; - 4649B88420288DFB00827CFB /* game.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC54017F1EBE0C4500AE66EE /* game.cpp */; }; - 4649B88520288DFE00827CFB /* general.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC5401811EBE0C4500AE66EE /* general.cpp */; }; - 4649B88620288E0000827CFB /* lobby.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC5401831EBE0C4500AE66EE /* lobby.cpp */; }; 4649B88720288E3E00827CFB /* parser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ECE09A531EBA529D0020C97B /* parser.cpp */; }; 4649B88B20288EEF00827CFB /* surface.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC669C251DFC95AF00172EED /* surface.cpp */; }; 4649B88D20288EF900827CFB /* point.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ECB6A6321FB8AAC400877C20 /* point.cpp */; }; @@ -256,8 +250,6 @@ 46D60158255AFA7E00E072F0 /* commandline_argv.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46D60156255AFA7E00E072F0 /* commandline_argv.cpp */; }; 46D60159255AFA7E00E072F0 /* commandline_argv.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46D60156255AFA7E00E072F0 /* commandline_argv.cpp */; }; 46D60162255AFDE100E072F0 /* commandline_argv.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46D60156255AFA7E00E072F0 /* commandline_argv.cpp */; }; - 46D6CA012586A176001F0464 /* advanced.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46D6C9FF2586A175001F0464 /* advanced.cpp */; }; - 46D6CA022586A176001F0464 /* advanced.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46D6C9FF2586A175001F0464 /* advanced.cpp */; }; 46E2D98F25022BF5003D99F3 /* lua_widget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46E2D98B25022BF5003D99F3 /* lua_widget.cpp */; }; 46E2D99025022BF5003D99F3 /* lua_widget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46E2D98B25022BF5003D99F3 /* lua_widget.cpp */; }; 46E2D99125022BF6003D99F3 /* lua_widget_attributes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46E2D98D25022BF5003D99F3 /* lua_widget_attributes.cpp */; }; @@ -627,6 +619,7 @@ 4E4A4DBC9F44444A5867EC2B /* migrate_version_selection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F7B1444E9B79504502208B82 /* migrate_version_selection.cpp */; }; 508C40A885166B2E3F4245F4 /* general.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84234C54BB84519421FD4136 /* general.cpp */; }; 529242A8856DE8D00988B9BD /* test_schema_self_validator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26A04033A9545CFE8A226FBD /* test_schema_self_validator.cpp */; }; + 61AB44F89B2EC1B6F92F0193 /* preferences_list.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 95EA4B82BB8CCCBEDD7A00E3 /* preferences_list.hpp */; }; 620A386E15E9364E00A4F513 /* attack.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 620A386215E9364E00A4F513 /* attack.cpp */; }; 620A386F15E9364E00A4F513 /* create.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 620A386415E9364E00A4F513 /* create.cpp */; }; 620A387015E9364F00A4F513 /* heal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 620A386615E9364E00A4F513 /* heal.cpp */; }; @@ -673,13 +666,13 @@ 7A7146D7893AA09891352019 /* test_schema_validator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CF14AB694764953E2CB3AF7 /* test_schema_validator.cpp */; }; 7BFC4DF5BFF8CF75855BA662 /* prompt.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 67044415B63F5888193BD7A6 /* prompt.cpp */; }; 7FDF4E8D9C94E7DA8F41F7BB /* tod_new_schedule.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 5D46466DBCD81B13621C7342 /* tod_new_schedule.hpp */; }; + 8150449A8C3B2EC4FD38A44B /* preferences_list.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 95EA4B82BB8CCCBEDD7A00E3 /* preferences_list.hpp */; }; 867141839BDB89BFE876E310 /* carryover_show_gold.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 09A440B1A671C45BE2924FB4 /* carryover_show_gold.cpp */; }; 87744447951D17AA38BE5F48 /* mp_report.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 58C649488B3014E6F7254B62 /* mp_report.cpp */; }; 8C704B6F99C824A4073EEBEE /* prompt.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 67044415B63F5888193BD7A6 /* prompt.cpp */; }; 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; 8E1D442FB4DA43385F58F77F /* combobox.hpp in Headers */ = {isa = PBXBuildFile; fileRef = B3534BCB9BB2673B5E513D67 /* combobox.hpp */; }; 900000000000000000000009 /* match_history.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4685A5F925B4501E006FD3A1 /* match_history.cpp */; }; - 903F959C1ED5489500F1BDD3 /* credentials.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 903F959B1ED5489500F1BDD3 /* credentials.cpp */; }; 903F959F1ED5496700F1BDD3 /* hash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B52EE8AD121359A600CFBDAB /* hash.cpp */; }; 90606A2B1D5599BA00719B40 /* libpcre.1.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 90606A2A1D5599BA00719B40 /* libpcre.1.dylib */; }; 9107AE181DB32899001927B0 /* lapi.c in Sources */ = {isa = PBXBuildFile; fileRef = EC89A1061879D17D00A3B0B1 /* lapi.c */; }; @@ -1128,7 +1121,9 @@ 97714C7A9FF444E29DCEF0BA /* carryover_show_gold.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 09A440B1A671C45BE2924FB4 /* carryover_show_gold.cpp */; }; 9B4B41D29C90B05F03DE21B0 /* edit_pbl_translation.hpp in Headers */ = {isa = PBXBuildFile; fileRef = C679447D91FD3623CC852FF8 /* edit_pbl_translation.hpp */; }; 9C2743DE8100448B66F7E0AF /* combobox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 875E45698F8A8D5B750E7317 /* combobox.cpp */; }; + 9FE64884AE8121CDBABF7D8A /* preferences.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C1D64406873FEB11E9758A05 /* preferences.cpp */; }; AC4242F78B39C571E34AF48F /* edit_unit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A05D48F0A2C022FC128C8B3E /* edit_unit.cpp */; }; + B45C431C9B7250C3321F8BC2 /* preferences.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 2CFD4922B64EA6C9F71F71A2 /* preferences.hpp */; }; B508D193100146E300B12852 /* engine_fai.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B508D191100146E300B12852 /* engine_fai.cpp */; }; B513B2290ED36BFB0006E551 /* libcairo.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B513B2270ED36BFB0006E551 /* libcairo.2.dylib */; }; B52EE8841213585300CFBDAB /* tod_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B52EE8821213585300CFBDAB /* tod_manager.cpp */; }; @@ -1284,6 +1279,8 @@ D09A4D40A36568E32D8723F7 /* combobox.hpp in Headers */ = {isa = PBXBuildFile; fileRef = B3534BCB9BB2673B5E513D67 /* combobox.hpp */; }; D1254FCA82471825B83AA786 /* multiline_text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0B0F48CE9CF65D9813BE6CDC /* multiline_text.cpp */; }; D2E9440BBCDCE2A75C93F85D /* migrate_version_selection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F7B1444E9B79504502208B82 /* migrate_version_selection.cpp */; }; + D9E94D2083155213BFA6EDD6 /* preferences.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 2CFD4922B64EA6C9F71F71A2 /* preferences.hpp */; }; + DDE34117BDAA30C965F6E4DB /* preferences.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C1D64406873FEB11E9758A05 /* preferences.cpp */; }; DF974010BB46B844E83F7DDA /* tod_new_schedule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C61F473D9AC43768A445E218 /* tod_new_schedule.cpp */; }; E1DA41878F0C255769B8239D /* scroll_text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 755D4555A1DEA29125E7F338 /* scroll_text.cpp */; }; E2F24C0CBC863C3DC8A041EF /* edit_pbl.hpp in Headers */ = {isa = PBXBuildFile; fileRef = B2CC45FEA71445AE817CAA6B /* edit_pbl.hpp */; }; @@ -1342,11 +1339,6 @@ EC4E3B1D19B2D7AD0049CBD7 /* map_generator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC4E3B1A19B2D7AD0049CBD7 /* map_generator.cpp */; }; EC4E3B2219B2D8880049CBD7 /* simulated_actions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC4E3B2119B2D8880049CBD7 /* simulated_actions.cpp */; }; EC51DB7818F8BFA4004621D9 /* playturn_network_adapter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC51DB7618F8BFA4004621D9 /* playturn_network_adapter.cpp */; }; - EC5401851EBE0C4500AE66EE /* display.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC54017B1EBE0C4500AE66EE /* display.cpp */; }; - EC5401861EBE0C4500AE66EE /* editor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC54017D1EBE0C4500AE66EE /* editor.cpp */; }; - EC5401871EBE0C4500AE66EE /* game.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC54017F1EBE0C4500AE66EE /* game.cpp */; }; - EC5401881EBE0C4500AE66EE /* general.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC5401811EBE0C4500AE66EE /* general.cpp */; }; - EC5401891EBE0C4500AE66EE /* lobby.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC5401831EBE0C4500AE66EE /* lobby.cpp */; }; EC5430231A4E6024006D206C /* lua_team.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC5430211A4E6024006D206C /* lua_team.cpp */; }; EC5430241A4E6024006D206C /* lua_unit_type.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC5430221A4E6024006D206C /* lua_unit_type.cpp */; }; EC5590771A0B11C600675179 /* lua_map_generator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC5590761A0B11C600675179 /* lua_map_generator.cpp */; }; @@ -1583,6 +1575,7 @@ 20E644DC98F26C756364EC2C /* choose_addon.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = choose_addon.cpp; sourceTree = ""; }; 26A04033A9545CFE8A226FBD /* test_schema_self_validator.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = test_schema_self_validator.cpp; path = test_schema_self_validator.cpp; sourceTree = ""; }; 27764FB68F02032F1C0B6748 /* statistics_record.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = statistics_record.cpp; sourceTree = ""; }; + 2CFD4922B64EA6C9F71F71A2 /* preferences.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = preferences.hpp; path = preferences/preferences.hpp; sourceTree = ""; }; 46081FED2B2F0F6A006ACAD7 /* libpcre2-8.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libpcre2-8.0.dylib"; path = "lib/libpcre2-8.0.dylib"; sourceTree = ""; }; 46081FF02B2F103E006ACAD7 /* libwebpdemux.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libwebpdemux.2.dylib; path = lib/libwebpdemux.2.dylib; sourceTree = ""; }; 46081FF32B2F11F3006ACAD7 /* libsharpyuv.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsharpyuv.0.dylib; path = lib/libsharpyuv.0.dylib; sourceTree = ""; }; @@ -1729,8 +1722,6 @@ 46D6014D255AFA6000E072F0 /* options.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = options.cpp; sourceTree = ""; }; 46D60156255AFA7E00E072F0 /* commandline_argv.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = commandline_argv.cpp; sourceTree = ""; }; 46D60157255AFA7E00E072F0 /* commandline_argv.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = commandline_argv.hpp; sourceTree = ""; }; - 46D6C9FF2586A175001F0464 /* advanced.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = advanced.cpp; path = preferences/advanced.cpp; sourceTree = ""; }; - 46D6CA002586A176001F0464 /* advanced.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = advanced.hpp; path = preferences/advanced.hpp; sourceTree = ""; }; 46DF5BCB1F46173700BE6D24 /* irdya_datetime.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = irdya_datetime.hpp; sourceTree = ""; }; 46DF5BCC1F46173700BE6D24 /* irdya_datetime.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = irdya_datetime.cpp; sourceTree = ""; }; 46E2D98925022BF4003D99F3 /* lua_widget_methods.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_widget_methods.hpp; sourceTree = ""; }; @@ -2213,8 +2204,6 @@ 875E45698F8A8D5B750E7317 /* combobox.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = combobox.cpp; path = combobox.cpp; sourceTree = ""; }; 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 8D1107320486CEB800E47090 /* The Battle for Wesnoth.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "The Battle for Wesnoth.app"; sourceTree = BUILT_PRODUCTS_DIR; }; - 903F959B1ED5489500F1BDD3 /* credentials.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = credentials.cpp; path = preferences/credentials.cpp; sourceTree = ""; }; - 903F959D1ED5489D00F1BDD3 /* credentials.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = credentials.hpp; path = preferences/credentials.hpp; sourceTree = ""; }; 90606A2A1D5599BA00719B40 /* libpcre.1.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libpcre.1.dylib; path = lib/libpcre.1.dylib; sourceTree = ""; }; 9107AE141DB32862001927B0 /* liblua.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = liblua.a; sourceTree = BUILT_PRODUCTS_DIR; }; 9107AE551DB5BD3B001927B0 /* lprefix.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = lprefix.h; sourceTree = ""; }; @@ -2404,6 +2393,7 @@ 91FBBAD71CB6BC3F00470BFE /* filesystem_sdl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = filesystem_sdl.cpp; sourceTree = ""; }; 91FBBAD91CB6D1B700470BFE /* markov_generator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = markov_generator.cpp; sourceTree = ""; }; 91FBBADA1CB6D1B700470BFE /* markov_generator.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = markov_generator.hpp; sourceTree = ""; }; + 95EA4B82BB8CCCBEDD7A00E3 /* preferences_list.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = preferences_list.hpp; path = preferences_list.hpp; sourceTree = ""; }; 95EB8A50287A02B800B09F95 /* draw_manager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = draw_manager.cpp; sourceTree = ""; }; 95EB8A51287A02B800B09F95 /* draw_manager.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = draw_manager.hpp; sourceTree = ""; }; 95EB8A53287A02EC00B09F95 /* top_level_drawable.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = top_level_drawable.hpp; path = gui/core/top_level_drawable.hpp; sourceTree = ""; }; @@ -2733,6 +2723,7 @@ B5CE46F712A0417D00D665EE /* side_filter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = side_filter.cpp; sourceTree = ""; }; B5CE46F812A0417D00D665EE /* side_filter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = side_filter.hpp; sourceTree = ""; }; BF3B41AF9FEBC9C3A11736A2 /* tab_container.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = tab_container.hpp; path = tab_container.hpp; sourceTree = ""; }; + C1D64406873FEB11E9758A05 /* preferences.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = preferences.cpp; path = preferences/preferences.cpp; sourceTree = ""; }; C61F473D9AC43768A445E218 /* tod_new_schedule.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = tod_new_schedule.cpp; sourceTree = ""; }; C679447D91FD3623CC852FF8 /* edit_pbl_translation.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = edit_pbl_translation.hpp; sourceTree = ""; }; D4594633BF3F8A06D6AE752F /* prompt.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = prompt.hpp; sourceTree = ""; }; @@ -2813,16 +2804,6 @@ EC5012731E06185600C4DFC6 /* math.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = math.hpp; sourceTree = ""; }; EC51DB7618F8BFA4004621D9 /* playturn_network_adapter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = playturn_network_adapter.cpp; sourceTree = ""; }; EC51DB7718F8BFA4004621D9 /* playturn_network_adapter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = playturn_network_adapter.hpp; sourceTree = ""; }; - EC54017B1EBE0C4500AE66EE /* display.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = display.cpp; path = preferences/display.cpp; sourceTree = ""; }; - EC54017C1EBE0C4500AE66EE /* display.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = display.hpp; path = preferences/display.hpp; sourceTree = ""; }; - EC54017D1EBE0C4500AE66EE /* editor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = editor.cpp; path = preferences/editor.cpp; sourceTree = ""; }; - EC54017E1EBE0C4500AE66EE /* editor.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = editor.hpp; path = preferences/editor.hpp; sourceTree = ""; }; - EC54017F1EBE0C4500AE66EE /* game.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = game.cpp; path = preferences/game.cpp; sourceTree = ""; }; - EC5401801EBE0C4500AE66EE /* game.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = game.hpp; path = preferences/game.hpp; sourceTree = ""; }; - EC5401811EBE0C4500AE66EE /* general.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = general.cpp; path = preferences/general.cpp; sourceTree = ""; }; - EC5401821EBE0C4500AE66EE /* general.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = general.hpp; path = preferences/general.hpp; sourceTree = ""; }; - EC5401831EBE0C4500AE66EE /* lobby.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = lobby.cpp; path = preferences/lobby.cpp; sourceTree = ""; }; - EC5401841EBE0C4500AE66EE /* lobby.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = lobby.hpp; path = preferences/lobby.hpp; sourceTree = ""; }; EC5430211A4E6024006D206C /* lua_team.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_team.cpp; sourceTree = ""; }; EC5430221A4E6024006D206C /* lua_unit_type.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_unit_type.cpp; sourceTree = ""; }; EC5590761A0B11C600675179 /* lua_map_generator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_map_generator.cpp; sourceTree = ""; }; @@ -5097,20 +5078,9 @@ EC54017A1EBE0C2B00AE66EE /* preferences */ = { isa = PBXGroup; children = ( - 46D6C9FF2586A175001F0464 /* advanced.cpp */, - 46D6CA002586A176001F0464 /* advanced.hpp */, - 903F959B1ED5489500F1BDD3 /* credentials.cpp */, - 903F959D1ED5489D00F1BDD3 /* credentials.hpp */, - EC54017B1EBE0C4500AE66EE /* display.cpp */, - EC54017C1EBE0C4500AE66EE /* display.hpp */, - EC54017D1EBE0C4500AE66EE /* editor.cpp */, - EC54017E1EBE0C4500AE66EE /* editor.hpp */, - EC54017F1EBE0C4500AE66EE /* game.cpp */, - EC5401801EBE0C4500AE66EE /* game.hpp */, - EC5401811EBE0C4500AE66EE /* general.cpp */, - EC5401821EBE0C4500AE66EE /* general.hpp */, - EC5401831EBE0C4500AE66EE /* lobby.cpp */, - EC5401841EBE0C4500AE66EE /* lobby.hpp */, + C1D64406873FEB11E9758A05 /* preferences.cpp */, + 2CFD4922B64EA6C9F71F71A2 /* preferences.hpp */, + 95EA4B82BB8CCCBEDD7A00E3 /* preferences_list.hpp */, ); name = preferences; sourceTree = ""; @@ -5155,6 +5125,8 @@ 8E1D442FB4DA43385F58F77F /* combobox.hpp in Headers */, B7B34687A61290490C1616D3 /* tab_container.hpp in Headers */, 365D4F89BD511BC074E639D7 /* migrate_version_selection.hpp in Headers */, + D9E94D2083155213BFA6EDD6 /* preferences.hpp in Headers */, + 8150449A8C3B2EC4FD38A44B /* preferences_list.hpp in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -5171,6 +5143,8 @@ D09A4D40A36568E32D8723F7 /* combobox.hpp in Headers */, 3CC6488695A7293C9CFC2CB6 /* tab_container.hpp in Headers */, 7A0347D48BDB52B1430D9E79 /* migrate_version_selection.hpp in Headers */, + B45C431C9B7250C3321F8BC2 /* preferences.hpp in Headers */, + 61AB44F89B2EC1B6F92F0193 /* preferences_list.hpp in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -5401,7 +5375,6 @@ 46F92E052174F6A400602C1C /* preferences_dialog.cpp in Sources */, 46F92E992174F6A400602C1C /* slider.cpp in Sources */, B59F96D5103478C900A57C1A /* aspect.cpp in Sources */, - 46D6CA012586A176001F0464 /* advanced.cpp in Sources */, B55BE03211234AAB00154E6C /* astarsearch.cpp in Sources */, B5599B910EC62181008DD061 /* attack_prediction.cpp in Sources */, B54AC6DF0FEA9EB5006F6FBD /* attack.cpp in Sources */, @@ -5607,7 +5580,6 @@ 46F92DE52174F6A400602C1C /* terrain_layers.cpp in Sources */, B5599B2F0EC62181008DD061 /* log.cpp in Sources */, 46F92DB32174F6A300602C1C /* game_load.cpp in Sources */, - EC5401871EBE0C4500AE66EE /* game.cpp in Sources */, ECB6A6331FB8AAC500877C20 /* point.cpp in Sources */, EC218EA01A106648007C910C /* lua_common.cpp in Sources */, ECD5D7BF1A22DC8600114175 /* lua_cpp_function.cpp in Sources */, @@ -5616,7 +5588,6 @@ ECA1E0F21A1271AC00426E00 /* lua_gui2.cpp in Sources */, 46F92D872174F6A300602C1C /* horizontal_list.cpp in Sources */, 91AF564F284D8A8B007A7652 /* walker_container.cpp in Sources */, - EC5401851EBE0C4500AE66EE /* display.cpp in Sources */, 46F92C1E2174F5D700602C1C /* help.cpp in Sources */, F4D5483E15198D060058C8A7 /* lua_jailbreak_exception.cpp in Sources */, EC218EA11A106648007C910C /* lua_kernel_base.cpp in Sources */, @@ -5661,7 +5632,6 @@ F480CD1F14034E6D007175D6 /* mapbuilder.cpp in Sources */, ECA1E1011A12755B00426E00 /* mapgen_lua_kernel.cpp in Sources */, B5599B260EC62181008DD061 /* menu_events.cpp in Sources */, - 903F959C1ED5489500F1BDD3 /* credentials.cpp in Sources */, EC44E382181DDAF90037A62F /* menu_item.cpp in Sources */, 46F92DC52174F6A300602C1C /* modeless_dialog.cpp in Sources */, 46F92D9B2174F6A300602C1C /* depcheck_confirm_change.cpp in Sources */, @@ -5768,7 +5738,6 @@ 46F92E312174F6A400602C1C /* custom_tod.cpp in Sources */, 46F92DA92174F6A300602C1C /* screenshot_notification.cpp in Sources */, B5599AFF0EC62181008DD061 /* soundsource.cpp in Sources */, - EC5401861EBE0C4500AE66EE /* editor.cpp in Sources */, B54AC6E80FEA9EB5006F6FBD /* stage_rca.cpp in Sources */, 46F92D8D2174F6A300602C1C /* placer.cpp in Sources */, 46F92DD52174F6A300602C1C /* edit_text.cpp in Sources */, @@ -5883,7 +5852,6 @@ 91ECD5D21BA11A5200B25CF1 /* unit_creator.cpp in Sources */, 911F2DAD1BA086A400E3102E /* window.cpp in Sources */, 919B37F81BAF789E00E0094C /* synced_user_choice.cpp in Sources */, - EC5401891EBE0C4500AE66EE /* lobby.cpp in Sources */, 46F92E4D2174F6A400602C1C /* walker_widget.cpp in Sources */, 91FAC70A1C7FBC3400DAB2C3 /* lua_formula_bridge.cpp in Sources */, 91FBBAD81CB6BC3F00470BFE /* filesystem_sdl.cpp in Sources */, @@ -5900,7 +5868,6 @@ 918C8A201D05F9AA009744A0 /* wesnothd_connection.cpp in Sources */, 46F92F172174FEC000602C1C /* font_config.cpp in Sources */, 914F2F861D35253900A42440 /* location_palette.cpp in Sources */, - EC5401881EBE0C4500AE66EE /* general.cpp in Sources */, 913D26771D3C9697002FF3AB /* name_generator_factory.cpp in Sources */, 9193FC7E1D5BB64F004F6C07 /* advancement.cpp in Sources */, 9193FC821D5C2CF8004F6C07 /* lua_unit.cpp in Sources */, @@ -5928,6 +5895,7 @@ 1C3D48879EAC414AE3DB122E /* combobox.cpp in Sources */, 1BC74FED857215A162E9E0F2 /* tab_container.cpp in Sources */, D2E9440BBCDCE2A75C93F85D /* migrate_version_selection.cpp in Sources */, + 9FE64884AE8121CDBABF7D8A /* preferences.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -6143,7 +6111,6 @@ 91E3568B1CACC77E00774252 /* synced_context.cpp in Sources */, 46F92E3E2174F6A400602C1C /* new_map.cpp in Sources */, 46F92D922174F6A300602C1C /* gui_definition.cpp in Sources */, - 4649B88320288DF800827CFB /* editor.cpp in Sources */, 91E3568C1CACC77E00774252 /* synced_user_choice.cpp in Sources */, 91E3568D1CACC77E00774252 /* syncmp_handler.cpp in Sources */, 91E3568E1CACC77E00774252 /* team.cpp in Sources */, @@ -6172,7 +6139,6 @@ 91E3569B1CACC7CE00774252 /* undo_dismiss_action.cpp in Sources */, 46F92E122174F6A400602C1C /* mp_staging.cpp in Sources */, 46F92DF22174F6A400602C1C /* manager.cpp in Sources */, - 4649B88520288DFE00827CFB /* general.cpp in Sources */, 46F92DE02174F6A300602C1C /* select_orb_colors.cpp in Sources */, 46F92E742174F6A400602C1C /* addon_list.cpp in Sources */, 91E3569C1CACC7CE00774252 /* undo_move_action.cpp in Sources */, @@ -6300,7 +6266,6 @@ 91E356E51CACC93000774252 /* palette_manager.cpp in Sources */, 46F92DCE2174F6A300602C1C /* log_settings.cpp in Sources */, 46F92DDE2174F6A300602C1C /* edit_label.cpp in Sources */, - 4649B88120288DF200827CFB /* credentials.cpp in Sources */, 91E356E61CACC93000774252 /* terrain_palettes.cpp in Sources */, 91E356E71CACC93000774252 /* tristate_button.cpp in Sources */, 91E356E81CACC93000774252 /* unit_palette.cpp in Sources */, @@ -6392,7 +6357,6 @@ 91A214FB1CAD66CC00927AEA /* picture.cpp in Sources */, 91AF5654284D90ED007A7652 /* walker_container.cpp in Sources */, 91A214FC1CAD66CC00927AEA /* image_modifications.cpp in Sources */, - 4649B88420288DFB00827CFB /* game.cpp in Sources */, 46F92E322174F6A400602C1C /* custom_tod.cpp in Sources */, 91A214FE1CAD66CC00927AEA /* key.cpp in Sources */, 91A214FF1CAD66CC00927AEA /* language.cpp in Sources */, @@ -6455,7 +6419,6 @@ 91A2156B1CAD6DA400927AEA /* lua_race.cpp in Sources */, 46F92E962174F6A400602C1C /* spacer.cpp in Sources */, 91A2156C1CAD6DA500927AEA /* lua_rng.cpp in Sources */, - 4649B88620288E0000827CFB /* lobby.cpp in Sources */, 91A2156D1CAD6DA500927AEA /* lua_team.cpp in Sources */, 91A2156F1CAD6DA500927AEA /* lua_unit_type.cpp in Sources */, 91D816832894DB0B00631AFB /* simple_wml.cpp in Sources */, @@ -6491,7 +6454,6 @@ 91A215851CAD884A00927AEA /* abilities.cpp in Sources */, 46685C9E219D518B0009CFFE /* schema_validator.cpp in Sources */, 46F92E9A2174F6A400602C1C /* slider.cpp in Sources */, - 4649B88220288DF500827CFB /* display.cpp in Sources */, 91A215861CAD884A00927AEA /* animation.cpp in Sources */, 91A215871CAD884B00927AEA /* animation_component.cpp in Sources */, 46685C96219D518B0009CFFE /* tag.cpp in Sources */, @@ -6557,7 +6519,6 @@ 46F92E1A2174F6A400602C1C /* mp_connect.cpp in Sources */, 4649B88020288DC600827CFB /* random.cpp in Sources */, 4649B88E20288F1E00827CFB /* lua_audio.cpp in Sources */, - 46D6CA022586A176001F0464 /* advanced.cpp in Sources */, 916718FB1CADAA1200B055A9 /* fake_display.cpp in Sources */, 916718FD1CADAA1200B055A9 /* game_config_manager_tests.cpp in Sources */, 916718FF1CADAA1D00B055A9 /* fire_event.cpp in Sources */, @@ -6614,6 +6575,7 @@ 9C2743DE8100448B66F7E0AF /* combobox.cpp in Sources */, 19B14238AD52EC06ED2094F1 /* tab_container.cpp in Sources */, 4E4A4DBC9F44444A5867EC2B /* migrate_version_selection.cpp in Sources */, + DDE34117BDAA30C965F6E4DB /* preferences.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/source_lists/libwesnoth b/source_lists/libwesnoth index 9b3d05e7c97b0..0ea37b74ae5b5 100644 --- a/source_lists/libwesnoth +++ b/source_lists/libwesnoth @@ -30,8 +30,7 @@ hotkey/hotkey_item.cpp hotkey/hotkey_manager.cpp picture.cpp image_modifications.cpp -preferences/credentials.cpp -preferences/general.cpp +preferences/preferences.cpp key.cpp language.cpp map/label.cpp diff --git a/source_lists/wesnoth b/source_lists/wesnoth index dac895191230c..d80a31adc7c37 100644 --- a/source_lists/wesnoth +++ b/source_lists/wesnoth @@ -312,11 +312,7 @@ play_controller.cpp playmp_controller.cpp playsingle_controller.cpp playturn_network_adapter.cpp -preferences/advanced.cpp -preferences/display.cpp -preferences/editor.cpp -preferences/game.cpp -preferences/lobby.cpp +preferences/preferences.cpp random_deterministic.cpp random_synced.cpp recall_list_manager.cpp diff --git a/src/achievements.cpp b/src/achievements.cpp index 61ef0c6b02c34..cae2a376f3a9b 100644 --- a/src/achievements.cpp +++ b/src/achievements.cpp @@ -17,7 +17,7 @@ #include "filesystem.hpp" #include "log.hpp" -#include "preferences/general.hpp" +#include "preferences/preferences.hpp" #include "serialization/parser.hpp" #include "serialization/preprocessor.hpp" @@ -65,7 +65,7 @@ achievement::achievement(const config& cfg, const std::string& content_for, bool if(sub_id.empty()) { ERR_CONFIG << "Achievement " << id_ << " has a sub-achievement missing the id attribute:\n" << sub_ach.debug(); } else { - sub_achievements_.emplace_back(sub_ach, achieved_ || preferences::sub_achievement(content_for, id_, sub_id)); + sub_achievements_.emplace_back(sub_ach, achieved_ || prefs::get().sub_achievement(content_for, id_, sub_id)); max_progress_++; } } @@ -85,7 +85,7 @@ achievement_group::achievement_group(const config& cfg) ERR_CONFIG << content_for_ + " achievement id " << id << " contains a comma, skipping."; continue; } else { - achievements_.emplace_back(ach, content_for_, preferences::achievement(content_for_, id), preferences::progress_achievement(content_for_, id)); + achievements_.emplace_back(ach, content_for_, prefs::get().achievement(content_for_, id), prefs::get().progress_achievement(content_for_, id)); } } } diff --git a/src/actions/advancement.cpp b/src/actions/advancement.cpp index a2891c4395414..a75d92aebaa71 100644 --- a/src/actions/advancement.cpp +++ b/src/actions/advancement.cpp @@ -24,7 +24,7 @@ #include "ai/manager.hpp" // for manager, holder #include "ai/lua/aspect_advancements.hpp" #include "game_events/pump.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "game_data.hpp" //resources::gamedata->phase() #include "gettext.hpp" #include "gui/dialogs/unit_advance.hpp" @@ -67,7 +67,7 @@ namespace std::vector previews; for (const std::string& advance : u.advances_to()) { - preferences::encountered_units().insert(advance); + prefs::get().encountered_units().insert(advance); previews.push_back(get_advanced_unit(u, advance)); } @@ -386,7 +386,7 @@ void advance_unit(map_location loc, const advancement_option &advance_to, bool f if ( !use_amla ) { resources::controller->statistics().advance_unit(*new_unit); - preferences::encountered_units().insert(new_unit->type_id()); + prefs::get().encountered_units().insert(new_unit->type_id()); LOG_CF << "Added '" << new_unit->type_id() << "' to the encountered units."; } u->anim_comp().clear_haloes(); diff --git a/src/actions/attack.cpp b/src/actions/attack.cpp index 01294afe0ee67..b7d23559e5b29 100644 --- a/src/actions/attack.cpp +++ b/src/actions/attack.cpp @@ -32,7 +32,7 @@ #include "map/map.hpp" #include "mouse_handler_base.hpp" #include "play_controller.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "random.hpp" #include "replay.hpp" #include "resources.hpp" @@ -1311,7 +1311,7 @@ void attack::unit_killed(unit_info& attacker, game_events::entity_location reanim_loc(defender.loc_, newunit->underlying_id()); resources::game_events->pump().fire("unit_placed", reanim_loc); - preferences::encountered_units().insert(newunit->type_id()); + prefs::get().encountered_units().insert(newunit->type_id()); if(update_display_) { display::get_singleton()->invalidate(death_loc); diff --git a/src/actions/create.cpp b/src/actions/create.cpp index a9e3d7298d608..0f45b66135e5d 100644 --- a/src/actions/create.cpp +++ b/src/actions/create.cpp @@ -29,7 +29,7 @@ #include "filter_context.hpp" #include "game_events/pump.hpp" #include "game_state.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "gettext.hpp" #include "log.hpp" #include "map/map.hpp" @@ -671,7 +671,7 @@ place_recruit_result place_recruit(unit_ptr u, const map_location &recruit_locat return std::tuple(true, 0, false); new_unit_itor->set_hidden(true); } - preferences::encountered_units().insert(new_unit_itor->type_id()); + prefs::get().encountered_units().insert(new_unit_itor->type_id()); current_team.spend_gold(cost); if ( show ) { diff --git a/src/actions/move.cpp b/src/actions/move.cpp index d59eda8b52b61..109743a0b8839 100644 --- a/src/actions/move.cpp +++ b/src/actions/move.cpp @@ -24,7 +24,7 @@ #include "actions/vision.hpp" #include "game_events/pump.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "gettext.hpp" #include "hotkey/hotkey_item.hpp" #include "hotkey/hotkey_command.hpp" @@ -1363,7 +1363,7 @@ std::size_t move_unit_and_record(const std::vector &steps, resources::gameboard->units().find(steps.front())->side() - 1]; continued_move |= !current_team.fog_or_shroud(); } - const bool skip_ally_sighted = !preferences::interrupt_when_ally_sighted(); + const bool skip_ally_sighted = !prefs::get().interrupt_when_ally_sighted(); // Evaluate this move. unit_mover mover(steps, move_spectator, continued_move, skip_ally_sighted); diff --git a/src/actions/unit_creator.cpp b/src/actions/unit_creator.cpp index 018c6f7791650..434149fd6c557 100644 --- a/src/actions/unit_creator.cpp +++ b/src/actions/unit_creator.cpp @@ -26,7 +26,7 @@ #include "display.hpp" #include "game_board.hpp" #include "game_events/pump.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "game_data.hpp" // for resources::gamedata conversion variable_set #include "game_version.hpp" #include "log.hpp" @@ -193,7 +193,7 @@ void unit_creator::add_unit(const config &cfg, const vconfig* vcfg) //add to recall list team_.recall_list().add(new_unit); DBG_NG << "inserting unit with id=["<side(); - preferences::encountered_units().insert(new_unit->type_id()); + prefs::get().encountered_units().insert(new_unit->type_id()); } } else { //get unit from recall list @@ -217,7 +217,7 @@ void unit_creator::post_create(const map_location &loc, const unit &new_unit, bo { if (discover_) { - preferences::encountered_units().insert(new_unit.type_id()); + prefs::get().encountered_units().insert(new_unit.type_id()); } bool show = show_ && (display::get_singleton() !=nullptr) && !display::get_singleton()->fogged(loc); diff --git a/src/addon/client.cpp b/src/addon/client.cpp index fb77d248615b4..edbd33e5c3aad 100644 --- a/src/addon/client.cpp +++ b/src/addon/client.cpp @@ -29,8 +29,7 @@ #include "gui/dialogs/message.hpp" #include "gui/widgets/retval.hpp" #include "log.hpp" -#include "preferences/credentials.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "serialization/string_utils.hpp" #include "serialization/utf8_exception.hpp" #include "utils/parse_network_address.hpp" @@ -286,14 +285,14 @@ bool addons_client::delete_remote_addon(const std::string& id, std::string& resp // if the passphrase isn't provided from the _server.pbl, try to pre-populate it from the preferences before prompting for it if(cfg["passphrase"].empty()) { - cfg["passphrase"] = preferences::password(preferences::campaign_server(), cfg["author"]); + cfg["passphrase"] = prefs::get().password(prefs::get().campaign_server(), cfg["author"]); if(!gui2::dialogs::addon_auth::execute(cfg)) { config dummy; config& error = dummy.add_child("error"); error["message"] = "Password not provided."; return !update_last_error(dummy); } else { - preferences::set_password(preferences::campaign_server(), cfg["author"], cfg["passphrase"]); + prefs::get().set_password(prefs::get().campaign_server(), cfg["author"], cfg["passphrase"]); } } diff --git a/src/addon/manager_ui.cpp b/src/addon/manager_ui.cpp index 6338e32c0b8c6..455f90a6ea59e 100644 --- a/src/addon/manager_ui.cpp +++ b/src/addon/manager_ui.cpp @@ -22,7 +22,7 @@ #include "config_cache.hpp" #include "filesystem.hpp" #include "formula/string_utils.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "gettext.hpp" #include "gui/dialogs/addon/manager.hpp" #include "gui/dialogs/addon/uninstall_list.hpp" @@ -66,7 +66,7 @@ bool addons_manager_ui(const std::string& remote_address) { bool need_wml_cache_refresh = false; - preferences::set_campaign_server(remote_address); + prefs::get().set_campaign_server(remote_address); try { addons_client client(remote_address); @@ -231,7 +231,7 @@ bool manage_addons() // NOTE: the following two values are also known by WML, so don't change them. static const int addon_uninstall = 2; - std::string host_name = preferences::campaign_server(); + std::string host_name = prefs::get().campaign_server(); const bool have_addons = !installed_addons().empty(); gui2::dialogs::addon_connect addon_dlg(host_name, have_addons); @@ -254,7 +254,7 @@ bool manage_addons() bool ad_hoc_addon_fetch_session(const std::vector& addon_ids) { - std::string remote_address = preferences::campaign_server(); + std::string remote_address = prefs::get().campaign_server(); // These exception handlers copied from addon_manager_ui fcn above. try { diff --git a/src/ai/actions.cpp b/src/ai/actions.cpp index 8a8f19f27df06..907f69d0d98c8 100644 --- a/src/ai/actions.cpp +++ b/src/ai/actions.cpp @@ -41,7 +41,7 @@ #include "actions/attack.hpp" #include "actions/create.hpp" #include "attack_prediction.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "log.hpp" #include "map/map.hpp" #include "mouse_handler_base.hpp" @@ -476,7 +476,7 @@ void move_result::do_execute() /*std::vector steps*/ route_->steps, /*::actions::undo_list* undo_stack*/ nullptr, /*bool continue_move*/ true, - /*bool show_move*/ !preferences::skip_ai_moves(), + /*bool show_move*/ !prefs::get().skip_ai_moves(), /*bool* interrupted*/ nullptr, /*::actions::move_unit_spectator* move_spectator*/ &move_spectator); @@ -658,7 +658,7 @@ void recall_result::do_execute() synced_context::run_in_synced_context_if_not_already("recall", replay_helper::get_recall(unit_id_, recall_location_, recall_from_), false, - !preferences::skip_ai_moves(), + !prefs::get().skip_ai_moves(), synced_context::ignore_error_function); set_gamestate_changed(); @@ -804,7 +804,7 @@ void recruit_result::do_execute() } resources::undo_stack->clear(); - synced_context::run_in_synced_context_if_not_already("recruit", replay_helper::get_recruit(u->id(), recruit_location_, recruit_from_), false, !preferences::skip_ai_moves()); + synced_context::run_in_synced_context_if_not_already("recruit", replay_helper::get_recruit(u->id(), recruit_location_, recruit_from_), false, !prefs::get().skip_ai_moves()); set_gamestate_changed(); try { diff --git a/src/attack_prediction.cpp b/src/attack_prediction.cpp index 6bee693e833f8..cfc12c629bb71 100644 --- a/src/attack_prediction.cpp +++ b/src/attack_prediction.cpp @@ -32,7 +32,7 @@ #include "actions/attack.hpp" #include "game_config.hpp" -#include "preferences/general.hpp" +#include "preferences/preferences.hpp" #include "random.hpp" #include @@ -2333,7 +2333,7 @@ void combatant::fight(combatant& opponent, bool levelup_considered) bool use_monte_carlo_simulation = fight_complexity(split.size(), opp_split.size(), u_, opponent.u_) > MONTE_CARLO_SIMULATION_THRESHOLD - && preferences::damage_prediction_allow_monte_carlo_simulation(); + && prefs::get().damage_prediction_allow_monte_carlo_simulation(); if(use_monte_carlo_simulation) { // A very complex fight. Use Monte Carlo simulation instead of exact diff --git a/src/chat_command_handler.cpp b/src/chat_command_handler.cpp index 6e82cfff38320..d233725ac14bf 100644 --- a/src/chat_command_handler.cpp +++ b/src/chat_command_handler.cpp @@ -20,7 +20,7 @@ #include "gui/dialogs/multiplayer/mp_report.hpp" #include "gui/dialogs/preferences_dialog.hpp" #include "map_command_handler.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" namespace events { @@ -77,7 +77,7 @@ void chat_command_handler::do_ignore() utils::string_map symbols; symbols["nick"] = get_arg(1); - if (preferences::add_acquaintance(get_arg(1), "ignore", get_data(2)).first) { + if (prefs::get().add_acquaintance(get_arg(1), "ignore", get_data(2)).first) { print(_("ignores list"), VGETTEXT("Added to ignore list: $nick", symbols)); chat_handler_.user_relation_changed(get_arg(1)); } @@ -96,7 +96,7 @@ void chat_command_handler::do_friend() utils::string_map symbols; symbols["nick"] = get_arg(1); - if (preferences::add_acquaintance(get_arg(1), "friend", get_data(2)).first) { + if (prefs::get().add_acquaintance(get_arg(1), "friend", get_data(2)).first) { print(_("friends list"), VGETTEXT("Added to friends list: $nick", symbols)); chat_handler_.user_relation_changed(get_arg(1)); } @@ -109,7 +109,7 @@ void chat_command_handler::do_friend() void chat_command_handler::do_remove() { for (int i = 1;!get_arg(i).empty();i++) { - preferences::remove_acquaintance(get_arg(i)); + prefs::get().remove_acquaintance(get_arg(i)); chat_handler_.user_relation_changed(get_arg(i)); utils::string_map symbols; symbols["nick"] = get_arg(i); @@ -119,7 +119,7 @@ void chat_command_handler::do_remove() void chat_command_handler::do_display() { - gui2::dialogs::preferences_dialog::display(preferences::VIEW_FRIENDS); + gui2::dialogs::preferences_dialog::display(pref_constants::VIEW_FRIENDS); } void chat_command_handler::do_version() { diff --git a/src/chat_events.cpp b/src/chat_events.cpp index 7f9cff280a1c0..7e988acf9f0ca 100644 --- a/src/chat_events.cpp +++ b/src/chat_events.cpp @@ -18,7 +18,7 @@ #include "gettext.hpp" #include "log.hpp" #include "chat_command_handler.hpp" -#include "preferences/credentials.hpp" +#include "preferences/preferences.hpp" static lg::log_domain log_engine("engine"); #define ERR_NG LOG_STREAM(err, log_engine) @@ -133,7 +133,7 @@ void chat_handler::send_whisper(const std::string& receiver, const std::string& config cwhisper, data; cwhisper["receiver"] = receiver; cwhisper["message"] = message; - cwhisper["sender"] = preferences::login(); + cwhisper["sender"] = prefs::get().login(); data.add_child("whisper", std::move(cwhisper)); send_to_server(data); } @@ -158,14 +158,14 @@ void chat_handler::send_chat_room_message(const std::string& room, config cmsg, data; cmsg["room"] = room; cmsg["message"] = message; - cmsg["sender"] = preferences::login(); + cmsg["sender"] = prefs::get().login(); data.add_child("message", std::move(cmsg)); send_to_server(data); } void chat_handler::add_chat_room_message_sent(const std::string &room, const std::string &message) { - add_chat_room_message_received(room, preferences::login(), message); + add_chat_room_message_received(room, prefs::get().login(), message); } void chat_handler::add_chat_room_message_received(const std::string &room, diff --git a/src/controller_base.cpp b/src/controller_base.cpp index 19b86bf11d502..70f2baff5f87a 100644 --- a/src/controller_base.cpp +++ b/src/controller_base.cpp @@ -22,7 +22,7 @@ #include "hotkey/command_executor.hpp" #include "log.hpp" #include "mouse_handler_base.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "scripting/plugins/context.hpp" #include "show_dialog.hpp" //gui::in_dialog #include "gui/core/event/handler.hpp" // gui2::is_in_dialog @@ -299,13 +299,13 @@ bool controller_base::handle_scroll(int mousex, int mousey, int mouse_flags) { const bool mouse_in_window = video::window_has_mouse_focus() - || preferences::get_scroll_when_mouse_outside(true); + || prefs::get().get_scroll_when_mouse_outside(true); - int scroll_speed = preferences::scroll_speed(); + int scroll_speed = prefs::get().scroll_speed(); double dx = 0.0, dy = 0.0; - int scroll_threshold = preferences::mouse_scroll_enabled() - ? preferences::mouse_scroll_threshold() + int scroll_threshold = prefs::get().mouse_scroll_enabled() + ? prefs::get().mouse_scroll_threshold() : 0; for(const theme::menu& m : get_display().get_theme().menus()) { @@ -355,7 +355,7 @@ bool controller_base::handle_scroll(int mousex, int mousey, int mouse_flags) events::mouse_handler_base& mh_base = get_mouse_handler_base(); // Scroll with middle-mouse if enabled - if((mouse_flags & SDL_BUTTON_MMASK) != 0 && preferences::middle_click_scrolls()) { + if((mouse_flags & SDL_BUTTON_MMASK) != 0 && prefs::get().middle_click_scrolls()) { const SDL_Point original_loc = mh_base.get_scroll_start(); if(mh_base.scroll_started()) { diff --git a/src/countdown_clock.cpp b/src/countdown_clock.cpp index 83d048e215b1e..06268d6080a66 100644 --- a/src/countdown_clock.cpp +++ b/src/countdown_clock.cpp @@ -15,7 +15,7 @@ #include "countdown_clock.hpp" #include "team.hpp" -#include "preferences/general.hpp" +#include "preferences/preferences.hpp" #include "sound.hpp" namespace { @@ -73,7 +73,7 @@ void countdown_clock::maybe_play_sound() { if(!playing_sound_ && team_.countdown_time() < WARNTIME ) { - if(preferences::turn_bell() || preferences::sound_on() || preferences::UI_sound_on()) + if(prefs::get().turn_bell() || prefs::get().sound_on() || prefs::get().ui_sound_on()) { const int loop_ticks = team_.countdown_time(); const int fadein_ticks = (loop_ticks > WARNTIME / 2) ? loop_ticks - WARNTIME / 2 : 0; diff --git a/src/cursor.cpp b/src/cursor.cpp index 3dab2a29a3489..d1b8c1d799c41 100644 --- a/src/cursor.cpp +++ b/src/cursor.cpp @@ -21,8 +21,7 @@ #include "cursor.hpp" #include "picture.hpp" -#include "preferences/game.hpp" -#include "preferences/display.hpp" +#include "preferences/preferences.hpp" #include "sdl/utils.hpp" #include @@ -84,7 +83,7 @@ bool have_focus = true; bool use_color_cursors() { - return game_config::editor == false && preferences::use_color_cursors(); + return game_config::editor == false && prefs::get().use_color_cursors(); } SDL_Cursor* create_cursor(surface surf) diff --git a/src/deprecation.cpp b/src/deprecation.cpp index 689254749d658..826081e7e522e 100644 --- a/src/deprecation.cpp +++ b/src/deprecation.cpp @@ -16,7 +16,7 @@ #include "formula/string_utils.hpp" #include "log.hpp" -#include "preferences/general.hpp" +#include "preferences/preferences.hpp" #include "game_version.hpp" // Set the default severity with the second parameter. @@ -79,7 +79,7 @@ std::string deprecated_message( const lg::logger& out_log = *log_ptr; FORCE_LOG_TO(out_log, log_deprecate) << message; // whether to show the error in the ingame chat area - if(preferences::get_show_deprecation(game_config::wesnoth_version.is_dev_version())) { + if(prefs::get().get_show_deprecation(game_config::wesnoth_version.is_dev_version())) { lg::log_to_chat() << message << '\n'; } } diff --git a/src/desktop/paths.cpp b/src/desktop/paths.cpp index d27fb5eba18fe..9894f8cdc9e73 100644 --- a/src/desktop/paths.cpp +++ b/src/desktop/paths.cpp @@ -20,7 +20,7 @@ #include "filesystem.hpp" #include "gettext.hpp" #include "log.hpp" -#include "preferences/general.hpp" +#include "preferences/preferences.hpp" #include "serialization/unicode.hpp" #include "utils/general.hpp" @@ -150,13 +150,13 @@ inline std::string pretty_path(const std::string& path) inline config get_bookmarks_config() { - auto cfg = preferences::dir_bookmarks(); + auto cfg = prefs::get().dir_bookmarks(); return cfg ? *cfg : config{}; } inline void commit_bookmarks_config(config& cfg) { - preferences::set_dir_bookmarks(cfg); + prefs::get().set_dir_bookmarks(cfg); } } // unnamed namespace diff --git a/src/display.cpp b/src/display.cpp index fb79808a8a64a..e516bc71a7d8b 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -28,7 +28,7 @@ #include "filesystem.hpp" #include "font/sdl_ttf_compat.hpp" #include "font/text.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "halo.hpp" #include "hotkey/command_executor.hpp" #include "log.hpp" @@ -155,7 +155,7 @@ display::display(const display_context* dc, , xpos_(0) , ypos_(0) , view_locked_(false) - , theme_(theme::get_theme_config(theme_id.empty() ? preferences::theme() : theme_id), video::game_canvas()) + , theme_(theme::get_theme_config(theme_id.empty() ? prefs::get().theme() : theme_id), video::game_canvas()) , zoom_index_(0) , fake_unit_man_(new fake_unit_manager(*this)) , builder_(new terrain_builder(level, (dc_ ? &dc_->map() : nullptr), theme_.border().tile_image, theme_.border().show_border)) @@ -215,13 +215,13 @@ display::display(const display_context* dc, fill_images_list(game_config::fog_prefix, fog_images_); fill_images_list(game_config::shroud_prefix, shroud_images_); - unsigned int tile_size = preferences::tile_size(); + unsigned int tile_size = prefs::get().tile_size(); if(tile_size < MinZoom || tile_size > MaxZoom) tile_size = DefaultZoom; zoom_index_ = get_zoom_levels_index(tile_size); zoom_ = zoom_levels[zoom_index_]; - if(zoom_ != preferences::tile_size()) // correct saved tile_size if necessary - preferences::set_tile_size(zoom_); + if(zoom_ != prefs::get().tile_size()) // correct saved tile_size if necessary + prefs::get().set_tile_size(zoom_); init_flags(); @@ -1539,7 +1539,7 @@ void display::set_diagnostic(const std::string& msg) void display::update_fps_count() { - static int time_between_draws = preferences::draw_delay(); + static int time_between_draws = prefs::get().draw_delay(); if(time_between_draws < 0) { time_between_draws = 1000 / video::current_refresh_rate(); } @@ -1687,7 +1687,7 @@ void display::draw_minimap() void display::draw_minimap_units() { - if (!preferences::minimap_draw_units() || is_blindfolded()) return; + if (!prefs::get().minimap_draw_units() || is_blindfolded()) return; double xscaling = 1.0 * minimap_location_.w / get_map().w(); double yscaling = 1.0 * minimap_location_.h / get_map().h(); @@ -1703,7 +1703,7 @@ void display::draw_minimap_units() int side = u.side(); color_t col = team::get_minimap_color(side); - if(!preferences::minimap_movement_coding()) { + if(!prefs::get().minimap_movement_coding()) { auto status = orb_status::allied; if(dc_->teams()[currentTeam_].is_enemy(side)) { status = orb_status::enemy; @@ -1902,7 +1902,7 @@ bool display::set_zoom(unsigned int amount, const bool validate_value_and_set_in last_zoom_ = zoom_; } - preferences::set_tile_size(zoom_); + prefs::get().set_tile_size(zoom_); labels().recalculate_labels(); redraw_background_ = true; @@ -1942,7 +1942,7 @@ bool display::tile_nearly_on_screen(const map_location& loc) const void display::scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_type, bool force) { - if(!force && (view_locked_ || !preferences::scroll_to_action())) return; + if(!force && (view_locked_ || !prefs::get().scroll_to_action())) return; if(video::headless()) { return; } @@ -1956,7 +1956,7 @@ void display::scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_ty int xmove = xpos - xpos_; int ymove = ypos - ypos_; - if(scroll_type == WARP || scroll_type == ONSCREEN_WARP || turbo_speed() > 2.0 || preferences::scroll_speed() > 99) { + if(scroll_type == WARP || scroll_type == ONSCREEN_WARP || turbo_speed() > 2.0 || prefs::get().scroll_speed() > 99) { scroll(xmove,ymove,true); redraw_minimap(); events::draw(); @@ -1988,7 +1988,7 @@ void display::scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_ty const double accel_time = 0.3 / turbo_speed(); // seconds until full speed is reached const double decel_time = 0.4 / turbo_speed(); // seconds from full speed to stop - double velocity_max = preferences::scroll_speed() * 60.0; + double velocity_max = prefs::get().scroll_speed() * 60.0; velocity_max *= turbo_speed(); double accel = velocity_max / accel_time; double decel = velocity_max / decel_time; @@ -2187,14 +2187,14 @@ void display::bounds_check_position(int& xpos, int& ypos) const double display::turbo_speed() const { - bool res = preferences::turbo(); + bool res = prefs::get().turbo(); if(keys_[SDLK_LSHIFT] || keys_[SDLK_RSHIFT]) { res = !res; } res |= video::headless(); if(res) - return preferences::turbo_speed(); + return prefs::get().turbo_speed(); else return 1.0; } @@ -2418,7 +2418,7 @@ void display::draw() drawing_buffer_commit(); } - if(preferences::show_fps() || debug_flag_set(DEBUG_BENCHMARK)) { + if(prefs::get().show_fps() || debug_flag_set(DEBUG_BENCHMARK)) { update_fps_label(); update_fps_count(); } else if(fps_handle_ != 0) { @@ -2433,8 +2433,8 @@ void display::update() update_render_textures(); // Trigger cache rebuild if animated water preference has changed. - if(animate_water_ != preferences::animate_water()) { - animate_water_ = preferences::animate_water(); + if(animate_water_ != prefs::get().animate_water()) { + animate_water_ = prefs::get().animate_water(); builder_->rebuild_cache_all(); } @@ -2703,7 +2703,7 @@ void display::draw_hex(const map_location& loc) }); // Draw the grid, if that's been enabled - if(preferences::grid()) { + if(prefs::get().grid()) { static const image::locator grid_top{game_config::images::grid_top}; static const image::locator grid_bottom{game_config::images::grid_bottom}; @@ -3225,7 +3225,7 @@ void display::invalidate_animations() { // There are timing issues with this, but i'm not touching it. new_animation_frame(); - animate_map_ = preferences::animate_map(); + animate_map_ = prefs::get().animate_map(); if(animate_map_) { for(const map_location& loc : get_visible_hexes()) { if(shrouded(loc)) diff --git a/src/display.hpp b/src/display.hpp index 5bcdf73127756..000a11deec688 100644 --- a/src/display.hpp +++ b/src/display.hpp @@ -793,10 +793,10 @@ class display : public gui2::top_level_drawable map_location mouseoverHex_; CKey keys_; - /** Local cache for preferences::animate_map, since it is constantly queried. */ + /** Local cache for prefs::get().animate_map, since it is constantly queried. */ bool animate_map_; - /** Local version of preferences::animate_water, used to detect when it's changed. */ + /** Local version of prefs::get().animate_water, used to detect when it's changed. */ bool animate_water_; private: diff --git a/src/display_chat_manager.cpp b/src/display_chat_manager.cpp index 22c599b4c010c..43f308ca0d854 100644 --- a/src/display_chat_manager.cpp +++ b/src/display_chat_manager.cpp @@ -18,13 +18,12 @@ #include "display.hpp" #include "floating_label.hpp" #include "game_board.hpp" // <-- only needed for is_observer() -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "log.hpp" #include "font/sdl_ttf_compat.hpp" #include "mp_ui_alerts.hpp" #include "serialization/string_utils.hpp" #include "color.hpp" -#include "preferences/credentials.hpp" #include "serialization/utf8_exception.hpp" #include "video.hpp" // only for faked @@ -63,10 +62,10 @@ void display_chat_manager::add_chat_message(const std::time_t& time, const std:: } } - if (!preferences::parse_should_show_lobby_join(sender, message)) return; - if (preferences::is_ignored(sender)) return; + if (!prefs::get().parse_should_show_lobby_join(sender, message)) return; + if (prefs::get().is_ignored(sender)) return; - //preferences::parse_admin_authentication(sender, message); TODO: replace + //prefs::get().parse_admin_authentication(sender, message); TODO: replace bool is_observer = false; { //TODO: Clean this block up somehow @@ -80,9 +79,9 @@ void display_chat_manager::add_chat_message(const std::time_t& time, const std:: if (bell) { if ((type == events::chat_handler::MESSAGE_PRIVATE && (!is_observer || whisper)) - || utils::word_match(message, preferences::login())) { + || utils::word_match(message, prefs::get().login())) { mp::ui_alerts::private_message(false, sender, message); - } else if (preferences::is_friend(sender)) { + } else if (prefs::get().is_friend(sender)) { mp::ui_alerts::friend_message(false, sender, message); } else if (sender == "server") { mp::ui_alerts::server_message(false, sender, message); @@ -149,7 +148,7 @@ void display_chat_manager::add_chat_message(const std::time_t& time, const std:: // Prepend message with timestamp. std::stringstream message_complete; - message_complete << preferences::get_chat_timestamp(time) << str.str(); + message_complete << prefs::get().get_chat_timestamp(time) << str.str(); const SDL_Rect rect = my_disp_.map_outside_area(); @@ -192,8 +191,8 @@ void display_chat_manager::prune_chat_messages(bool remove_all) { //NOTE: prune_chat_messages(false) seems to be only called when a new message is added, which in // particular means the aging feature won't work unless new messages are addded regularly - const unsigned message_aging = preferences::chat_message_aging(); - const unsigned max_chat_messages = preferences::chat_lines(); + const unsigned message_aging = prefs::get().chat_message_aging(); + const unsigned max_chat_messages = prefs::get().chat_lines(); const bool enable_aging = message_aging != 0; const unsigned remove_before = enable_aging ? safe_subtract(SDL_GetTicks(), message_aging * 60 * 1000) : 0; diff --git a/src/draw_manager.cpp b/src/draw_manager.cpp index 8a4bdb09abd2b..5dbd7a510e85c 100644 --- a/src/draw_manager.cpp +++ b/src/draw_manager.cpp @@ -18,7 +18,7 @@ #include "exceptions.hpp" #include "log.hpp" #include "gui/core/top_level_drawable.hpp" -#include "preferences/general.hpp" +#include "preferences/preferences.hpp" #include "sdl/rect.hpp" #include "utils/general.hpp" #include "video.hpp" @@ -186,7 +186,7 @@ int get_frame_length() // allow 1ms for general processing int vsync_delay = (1000 / rr) - 1; // if there's a preferred limit, limit to that - return std::clamp(vsync_delay, preferences::draw_delay(), 1000); + return std::clamp(vsync_delay, prefs::get().draw_delay(), 1000); } static void wait_for_vsync() diff --git a/src/editor/controller/editor_controller.cpp b/src/editor/controller/editor_controller.cpp index 7211c9c998dda..43c925ef27338 100644 --- a/src/editor/controller/editor_controller.cpp +++ b/src/editor/controller/editor_controller.cpp @@ -27,7 +27,7 @@ #include "editor/action/mouse/mouse_action.hpp" -#include "preferences/editor.hpp" +#include "preferences/preferences.hpp" #include "gui/dialogs/edit_text.hpp" #include "gui/dialogs/editor/edit_unit.hpp" @@ -102,9 +102,9 @@ void editor_controller::init_gui() gui_->change_display_context(&get_current_map_context()); gui_->add_redraw_observer(std::bind(&editor_controller::display_redraw_callback, this, std::placeholders::_1)); floating_label_manager_.reset(new font::floating_label_context()); - gui().set_debug_flag(display::DEBUG_COORDINATES, preferences::editor::draw_hex_coordinates()); - gui().set_debug_flag(display::DEBUG_TERRAIN_CODES, preferences::editor::draw_terrain_codes()); - gui().set_debug_flag(display::DEBUG_NUM_BITMAPS, preferences::editor::draw_num_of_bitmaps()); + gui().set_debug_flag(display::DEBUG_COORDINATES, prefs::get().draw_hex_coordinates()); + gui().set_debug_flag(display::DEBUG_TERRAIN_CODES, prefs::get().draw_terrain_codes()); + gui().set_debug_flag(display::DEBUG_NUM_BITMAPS, prefs::get().draw_num_of_bitmaps()); // halo_manager_.reset(new halo::manager(*gui_)); // resources::halo = halo_manager_.get(); // ^ These lines no longer necessary, the gui owns its halo manager. @@ -567,7 +567,7 @@ hotkey::ACTION_STATE editor_controller::get_action_state(const hotkey::ui_comman return toolkit_->is_active_brush("brush-sw-ne") ? ACTION_ON : ACTION_OFF; case HOTKEY_TOGGLE_GRID: - return preferences::grid() ? ACTION_ON : ACTION_OFF; + return prefs::get().grid() ? ACTION_ON : ACTION_OFF; case HOTKEY_EDITOR_SELECT_ALL: return get_current_map_context().map().everything_selected() ? ACTION_SELECTED : ACTION_DESELECTED; @@ -592,15 +592,15 @@ hotkey::ACTION_STATE editor_controller::get_action_state(const hotkey::ui_comman return gui_->debug_flag_set(display::DEBUG_NUM_BITMAPS) ? ACTION_ON : ACTION_OFF; case HOTKEY_MINIMAP_DRAW_VILLAGES: - return (preferences::minimap_draw_villages()) ? ACTION_ON : ACTION_OFF; + return (prefs::get().minimap_draw_villages()) ? ACTION_ON : ACTION_OFF; case HOTKEY_MINIMAP_CODING_UNIT: - return (preferences::minimap_movement_coding()) ? ACTION_ON : ACTION_OFF; + return (prefs::get().minimap_movement_coding()) ? ACTION_ON : ACTION_OFF; case HOTKEY_MINIMAP_CODING_TERRAIN: - return (preferences::minimap_terrain_coding()) ? ACTION_ON : ACTION_OFF; + return (prefs::get().minimap_terrain_coding()) ? ACTION_ON : ACTION_OFF; case HOTKEY_MINIMAP_DRAW_UNITS: - return (preferences::minimap_draw_units()) ? ACTION_ON : ACTION_OFF; + return (prefs::get().minimap_draw_units()) ? ACTION_ON : ACTION_OFF; case HOTKEY_MINIMAP_DRAW_TERRAIN: - return (preferences::minimap_draw_terrain()) ? ACTION_ON : ACTION_OFF; + return (prefs::get().minimap_draw_terrain()) ? ACTION_ON : ACTION_OFF; case HOTKEY_ZOOM_DEFAULT: return (gui_->get_zoom_factor() == 1.0) ? ACTION_ON : ACTION_OFF; @@ -1081,17 +1081,17 @@ bool editor_controller::do_execute_command(const hotkey::ui_command& cmd, bool p case HOTKEY_EDITOR_DRAW_COORDINATES: gui().toggle_debug_flag(display::DEBUG_COORDINATES); - preferences::editor::set_draw_hex_coordinates(gui().debug_flag_set(display::DEBUG_COORDINATES)); + prefs::get().set_draw_hex_coordinates(gui().debug_flag_set(display::DEBUG_COORDINATES)); gui().invalidate_all(); return true; case HOTKEY_EDITOR_DRAW_TERRAIN_CODES: gui().toggle_debug_flag(display::DEBUG_TERRAIN_CODES); - preferences::editor::set_draw_terrain_codes(gui().debug_flag_set(display::DEBUG_TERRAIN_CODES)); + prefs::get().set_draw_terrain_codes(gui().debug_flag_set(display::DEBUG_TERRAIN_CODES)); gui().invalidate_all(); return true; case HOTKEY_EDITOR_DRAW_NUM_OF_BITMAPS: gui().toggle_debug_flag(display::DEBUG_NUM_BITMAPS); - preferences::editor::set_draw_num_of_bitmaps(gui().debug_flag_set(display::DEBUG_NUM_BITMAPS)); + prefs::get().set_draw_num_of_bitmaps(gui().debug_flag_set(display::DEBUG_NUM_BITMAPS)); gui().invalidate_all(); return true; case HOTKEY_EDITOR_REMOVE_LOCATION: { @@ -1228,7 +1228,7 @@ void editor_controller::preferences() void editor_controller::toggle_grid() { - preferences::set_grid(!preferences::grid()); + prefs::get().set_grid(!prefs::get().grid()); gui_->invalidate_all(); } diff --git a/src/editor/map/context_manager.cpp b/src/editor/map/context_manager.cpp index 7a26953213229..c7ee76686010c 100644 --- a/src/editor/map/context_manager.cpp +++ b/src/editor/map/context_manager.cpp @@ -31,7 +31,7 @@ #include "editor/action/action.hpp" #include "editor/controller/editor_controller.hpp" -#include "preferences/editor.hpp" +#include "preferences/preferences.hpp" #include "gui/dialogs/edit_text.hpp" #include "gui/dialogs/prompt.hpp" @@ -74,12 +74,12 @@ context_manager::context_manager(editor_display& gui, const game_config_view& ga : locs_(nullptr) , gui_(gui) , game_config_(game_config) - , default_dir_(preferences::editor::default_dir()) + , default_dir_(prefs::get().default_dir()) , current_addon_(addon_id) , map_generators_() , last_map_generator_(nullptr) , current_context_index_(0) - , auto_update_transitions_(preferences::editor::auto_update_transitions()) + , auto_update_transitions_(prefs::get().auto_update_transitions()) , map_contexts_() , clipboard_() { @@ -158,11 +158,11 @@ void context_manager::reload_map() bool context_manager::is_active_transitions_hotkey(const std::string& item) { switch (auto_update_transitions_) { - case preferences::editor::TRANSITION_UPDATE_ON: + case pref_constants::TRANSITION_UPDATE_ON: return (item == "editor-auto-update-transitions"); - case preferences::editor::TRANSITION_UPDATE_PARTIAL: + case pref_constants::TRANSITION_UPDATE_PARTIAL: return (item == "editor-partial-update-transitions"); - case preferences::editor::TRANSITION_UPDATE_OFF: + case pref_constants::TRANSITION_UPDATE_OFF: return (item == "editor-no-update-transitions"); } @@ -171,10 +171,10 @@ bool context_manager::is_active_transitions_hotkey(const std::string& item) bool context_manager::toggle_update_transitions() { - auto_update_transitions_ = (auto_update_transitions_ + 1) % preferences::editor::TRANSITION_UPDATE_COUNT; - preferences::editor::set_auto_update_transitions(auto_update_transitions_); + auto_update_transitions_ = (auto_update_transitions_ + 1) % pref_constants::TRANSITION_UPDATE_COUNT; + prefs::get().set_auto_update_transitions(auto_update_transitions_); - if(auto_update_transitions_ != preferences::editor::TRANSITION_UPDATE_ON) { + if(auto_update_transitions_ != pref_constants::TRANSITION_UPDATE_ON) { return true; } @@ -222,7 +222,7 @@ void context_manager::load_map_dialog(bool force_same_context /* = false */) void context_manager::load_mru_item(unsigned index, bool force_same_context /* = false */) { - const std::vector& mru = preferences::editor::recent_files(); + const std::vector& mru = prefs::get().recent_files(); if(mru.empty() || index >= mru.size()) { return; } @@ -372,7 +372,7 @@ void context_manager::expand_open_maps_menu(std::vector& items, int i) void context_manager::expand_load_mru_menu(std::vector& items, int i) { - std::vector mru = preferences::editor::recent_files(); + std::vector mru = prefs::get().recent_files(); auto pos = items.erase(items.begin() + i); @@ -573,8 +573,8 @@ void context_manager::refresh_after_action(bool drag_part) const std::set& changed_locs = get_map_context().changed_locations(); if(get_map_context().needs_terrain_rebuild()) { - if((auto_update_transitions_ == preferences::editor::TRANSITION_UPDATE_ON) - || ((auto_update_transitions_ == preferences::editor::TRANSITION_UPDATE_PARTIAL) + if((auto_update_transitions_ == pref_constants::TRANSITION_UPDATE_ON) + || ((auto_update_transitions_ == pref_constants::TRANSITION_UPDATE_PARTIAL) && (!drag_part || get_map_context().everything_changed()))) { gui_.rebuild_all(); diff --git a/src/editor/map/context_manager.hpp b/src/editor/map/context_manager.hpp index e6d0753075cbc..24a7f53aedae4 100644 --- a/src/editor/map/context_manager.hpp +++ b/src/editor/map/context_manager.hpp @@ -18,7 +18,7 @@ #include "editor/map/map_context.hpp" #include "editor/map/map_fragment.hpp" #include "filter_context.hpp" -#include "preferences/editor.hpp" +#include "preferences/preferences.hpp" class map_generator; class game_config_view; @@ -41,7 +41,7 @@ class context_manager : public filter_context void set_update_transitions_mode(int mode) { auto_update_transitions_ = mode; - preferences::editor::set_auto_update_transitions(mode); + prefs::get().set_auto_update_transitions(mode); } bool toggle_update_transitions(); diff --git a/src/editor/map/map_context.cpp b/src/editor/map/map_context.cpp index 2650a30e6b2b8..3cb7a10b958d4 100644 --- a/src/editor/map/map_context.cpp +++ b/src/editor/map/map_context.cpp @@ -24,7 +24,7 @@ #include "gettext.hpp" #include "gui/dialogs/message.hpp" #include "map/label.hpp" -#include "preferences/editor.hpp" +#include "preferences/preferences.hpp" #include "serialization/binary_or_text.hpp" #include "serialization/parser.hpp" #include "serialization/preprocessor.hpp" @@ -992,7 +992,7 @@ void map_context::clear_modified() void map_context::add_to_recent_files() { - preferences::editor::add_recent_files_entry(get_filename()); + prefs::get().add_recent_files_entry(get_filename()); } bool map_context::can_undo() const diff --git a/src/events.cpp b/src/events.cpp index d40f482059291..398fc69a62ce8 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -19,6 +19,7 @@ #include "desktop/clipboard.hpp" #include "log.hpp" #include "draw_manager.hpp" +#include "preferences/preferences.hpp" #include "quit_confirmation.hpp" #include "sdl/userevent.hpp" #include "utils/ranges.hpp" @@ -619,6 +620,7 @@ void pump() << event.window.data1 << 'x' << event.window.data2; info.resize_dimensions.first = event.window.data1; info.resize_dimensions.second = event.window.data2; + prefs::get().set_resolution(video::window_size()); break; // Once everything has had a chance to respond to the resize, @@ -629,7 +631,13 @@ void pump() break; case SDL_WINDOWEVENT_MAXIMIZED: + LOG_DP << "events/MAXIMIZED"; + prefs::get().set_maximized(true); + break; case SDL_WINDOWEVENT_RESTORED: + LOG_DP << "events/RESTORED"; + prefs::get().set_maximized(prefs::get().fullscreen()); + break; case SDL_WINDOWEVENT_SHOWN: case SDL_WINDOWEVENT_MOVED: // Not used. diff --git a/src/filesystem.cpp b/src/filesystem.cpp index aad49d2789ddd..4db3a26eb976d 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -566,6 +566,11 @@ std::string get_next_filename(const std::string& name, const std::string& extens static bfs::path user_data_dir, user_config_dir, cache_dir; +bool is_userdata_initialized() +{ + return !user_data_dir.string().empty(); +} + const std::string get_version_path_suffix(const version_info& version) { std::ostringstream s; diff --git a/src/filesystem.hpp b/src/filesystem.hpp index 3ba35f9c8e225..dddfbd3f32d2e 100644 --- a/src/filesystem.hpp +++ b/src/filesystem.hpp @@ -147,6 +147,8 @@ const std::string& get_version_path_suffix(); * maximum 1000 files then start always giving 999 */ std::string get_next_filename(const std::string& name, const std::string& extension); + +bool is_userdata_initialized(); void set_user_config_dir(const std::string& path); void set_user_data_dir(std::string path); void set_cache_dir(const std::string& path); diff --git a/src/floating_textbox.cpp b/src/floating_textbox.cpp index a5a20b986d3d7..050259f966840 100644 --- a/src/floating_textbox.cpp +++ b/src/floating_textbox.cpp @@ -20,7 +20,7 @@ #include "floating_label.hpp" #include "font/standard_colors.hpp" #include "game_display.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "log.hpp" #include @@ -45,7 +45,7 @@ namespace gui{ } if(check_ != nullptr) { if(mode_ == TEXTBOX_MESSAGE) { - preferences::set_message_private(check_->checked()); + prefs::get().set_message_private(check_->checked()); } } box_.reset(nullptr); diff --git a/src/font/text.cpp b/src/font/text.cpp index 6037064a78d63..14f9eef1d2a44 100644 --- a/src/font/text.cpp +++ b/src/font/text.cpp @@ -29,7 +29,7 @@ #include "gui/core/log.hpp" #include "sdl/point.hpp" #include "serialization/unicode.hpp" -#include "preferences/general.hpp" +#include "preferences/preferences.hpp" #include "video.hpp" @@ -411,7 +411,7 @@ pango_text& pango_text::set_family_class(font::family_class fclass) pango_text& pango_text::set_font_size(unsigned font_size) { - font_size = preferences::font_scaled(font_size) * pixel_scale_; + font_size = prefs::get().font_scaled(font_size) * pixel_scale_; if(font_size != font_size_) { font_size_ = font_size; diff --git a/src/format_time_summary.cpp b/src/format_time_summary.cpp index 30b52d0fed74c..f83bc98c68274 100644 --- a/src/format_time_summary.cpp +++ b/src/format_time_summary.cpp @@ -17,7 +17,7 @@ #include "assert.h" #include "gettext.hpp" -#include "preferences/general.hpp" +#include "preferences/preferences.hpp" namespace utils { @@ -43,7 +43,7 @@ std::string format_time_summary(std::time_t t) { const int days_apart = current_time.tm_yday - save_time.tm_yday; if(days_apart == 0) { // save is from today - if(preferences::use_twelve_hour_clock_format() == false) { + if(prefs::get().use_twelve_hour_clock_format() == false) { // TRANSLATORS: 24-hour time, eg '13:59' format_string = _("%H:%M"); } @@ -53,7 +53,7 @@ std::string format_time_summary(std::time_t t) { } } else if(days_apart > 0 && days_apart <= current_time.tm_wday) { // save is from this week - if(preferences::use_twelve_hour_clock_format() == false) { + if(prefs::get().use_twelve_hour_clock_format() == false) { // TRANSLATORS: Day of week + 24-hour time, eg 'Sunday, 13:59' format_string = _("%A, %H:%M"); } diff --git a/src/game_board.cpp b/src/game_board.cpp index 84d966263981e..60d51e043a25c 100644 --- a/src/game_board.cpp +++ b/src/game_board.cpp @@ -17,7 +17,7 @@ #include "config.hpp" #include "log.hpp" #include "map/map.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "recall_list_manager.hpp" #include "units/unit.hpp" #include "units/animation_component.hpp" @@ -361,7 +361,7 @@ bool game_board::change_terrain(const map_location &loc, const t_translation::te return false; } - preferences::encountered_terrains().insert(new_t); + prefs::get().encountered_terrains().insert(new_t); if(map_->tdata()->is_village(old_t) && !map_->tdata()->is_village(new_t)) { int owner = village_owner(loc); @@ -372,7 +372,7 @@ bool game_board::change_terrain(const map_location &loc, const t_translation::te map_->set_terrain(loc, new_t); for(const t_translation::terrain_code& ut : map_->underlying_union_terrain(loc)) { - preferences::encountered_terrains().insert(ut); + prefs::get().encountered_terrains().insert(ut); } return true; diff --git a/src/game_classification.cpp b/src/game_classification.cpp index 45adaf3b8ead0..75cced08a4ef4 100644 --- a/src/game_classification.cpp +++ b/src/game_classification.cpp @@ -17,7 +17,7 @@ #include "config.hpp" #include "log.hpp" -#include "preferences/general.hpp" +#include "preferences/preferences.hpp" #include "serialization/string_utils.hpp" #include "game_version.hpp" #include "game_config_manager.hpp" @@ -78,7 +78,7 @@ config game_classification::to_config() const cfg["difficulty"] = difficulty; cfg["random_mode"] = random_mode; cfg["oos_debug"] = oos_debug; - cfg["core"] = preferences::core_id(); + cfg["core"] = prefs::get().core_id(); return cfg; } diff --git a/src/game_config_manager.cpp b/src/game_config_manager.cpp index b9c6870e3f6f1..bad0f06f52af3 100644 --- a/src/game_config_manager.cpp +++ b/src/game_config_manager.cpp @@ -31,8 +31,7 @@ #include "language.hpp" #include "log.hpp" #include "picture.hpp" -#include "preferences/advanced.hpp" -#include "preferences/general.hpp" +#include "preferences/preferences.hpp" #include "scripting/game_lua_kernel.hpp" #include "serialization/schema_validator.hpp" #include "sound.hpp" @@ -76,15 +75,15 @@ game_config_manager::game_config_manager(const commandline_options& cmdline_opts } // Clean the cache of any old Wesnoth version's cache data - if(const std::string last_cleaned = preferences::last_cache_cleared_version(); !last_cleaned.empty()) { + if(const std::string last_cleaned = prefs::get().last_cache_cleared_version(); !last_cleaned.empty()) { if(version_info{last_cleaned} < game_config::wesnoth_version) { if(cache_.clean_cache()) { - preferences::set_last_cache_cleared_version(game_config::wesnoth_version.str()); + prefs::get().set_last_cache_cleared_version(game_config::wesnoth_version.str()); } } } else { // If the preference wasn't set, set it, else the cleaning will never happen :P - preferences::set_last_cache_cleared_version(game_config::wesnoth_version.str()); + prefs::get().set_last_cache_cleared_version(game_config::wesnoth_version.str()); } } @@ -122,11 +121,10 @@ bool game_config_manager::init_game_config(FORCE_RELOAD_CONFIG force_reload) // Load the standard hotkeys, then apply any player customizations. hotkey::load_default_hotkeys(game_config()); - preferences::load_hotkeys(); + prefs::get().load_hotkeys(); }); - // TODO: consider making this part of preferences::manager in some fashion - preferences::init_advanced_manager(game_config()); + prefs::get().load_advanced_prefs(game_config()); ::init_textdomains(game_config()); about::set_about(game_config()); @@ -276,7 +274,7 @@ void game_config_manager::load_game_config(bool reload_everything, const game_cl if(id == "default" && !current_core_valid) { wml_tree_root = path; } - if(id == preferences::core_id()) { + if(id == prefs::get().core_id()) { current_core_valid = true; wml_tree_root = path; } @@ -288,11 +286,11 @@ void game_config_manager::load_game_config(bool reload_everything, const game_cl events::call_in_main_thread([&]() { gui2::dialogs::wml_error::display( _("Error loading core data."), - _("Core ID: ") + preferences::core_id() + _("Core ID: ") + prefs::get().core_id() + '\n' + _("Error loading the core with named id.") + '\n' + _("Falling back to the default core.")); }); - preferences::set_core_id("default"); + prefs::get().set_core_id("default"); } // check if we have a valid default core which should always be the case. @@ -366,13 +364,13 @@ void game_config_manager::load_game_config(bool reload_everything, const game_cl e.message); }); load_game_config(reload_everything, classification, scenario_id); - } else if(preferences::core_id() != "default") { + } else if(prefs::get().core_id() != "default") { events::call_in_main_thread([&]() { gui2::dialogs::wml_error::display( _("Error loading custom game configuration files. The game will fallback to the default core files."), e.message); }); - preferences::set_core_id("default"); + prefs::get().set_core_id("default"); game_config::no_addons = false; load_game_config(reload_everything, classification, scenario_id); } else { @@ -537,7 +535,7 @@ void game_config_manager::load_addons_cfg() // Skip add-ons not matching our current core. Cores themselves should be selectable // at all times, so they aren't considered here. - if(!metadata.empty() && metadata["type"] != "core" && using_core != preferences::core_id()) { + if(!metadata.empty() && metadata["type"] != "core" && using_core != prefs::get().core_id()) { continue; } diff --git a/src/game_display.cpp b/src/game_display.cpp index fa4ad46ea2f2a..1b22e871cb91a 100644 --- a/src/game_display.cpp +++ b/src/game_display.cpp @@ -26,7 +26,7 @@ #include "fake_unit_manager.hpp" #include "floating_label.hpp" #include "game_board.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "log.hpp" #include "map/map.hpp" #include "font/standard_colors.hpp" @@ -587,7 +587,7 @@ void game_display::set_route(const pathfind::marked_route *route) void game_display::float_label(const map_location& loc, const std::string& text, const color_t& color) { - if(preferences::show_floating_labels() == false || fogged(loc)) { + if(prefs::get().show_floating_labels() == false || fogged(loc)) { return; } diff --git a/src/game_initialization/configure_engine.cpp b/src/game_initialization/configure_engine.cpp index 81cdb6350ed67..5c12c6b392f31 100644 --- a/src/game_initialization/configure_engine.cpp +++ b/src/game_initialization/configure_engine.cpp @@ -16,8 +16,7 @@ #include "formula/string_utils.hpp" #include "mp_game_settings.hpp" -#include "preferences/credentials.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "map_settings.hpp" #include "tod_manager.hpp" @@ -58,109 +57,109 @@ bool configure_engine::force_lock_settings() const std::string configure_engine::game_name_default() { utils::string_map i18n_symbols; - i18n_symbols["login"] = preferences::login(); + i18n_symbols["login"] = prefs::get().login(); return VGETTEXT("$login|’s game", i18n_symbols); } int configure_engine::num_turns_default() const { - return use_map_settings() ? settings::get_turns(initial_cfg()["turns"]) : preferences::turns(); + return use_map_settings() ? settings::get_turns(initial_cfg()["turns"]) : prefs::get().turns(); } int configure_engine::village_gold_default() const { return use_map_settings() ? settings::get_village_gold(initial_cfg()["mp_village_gold"], &state_.classification()) - : preferences::village_gold(); + : prefs::get().village_gold(); } int configure_engine::village_support_default() const { return use_map_settings() ? settings::get_village_support(initial_cfg()["mp_village_support"]) - : preferences::village_support(); + : prefs::get().village_support(); } int configure_engine::xp_modifier_default() const { return use_map_settings() ? settings::get_xp_modifier(initial_cfg()["experience_modifier"]) - : preferences::xp_modifier(); + : prefs::get().xp_modifier(); } int configure_engine::mp_countdown_init_time_default() const { - return preferences::countdown_init_time(); + return prefs::get().countdown_init_time(); } int configure_engine::mp_countdown_reservoir_time_default() const { - return preferences::countdown_reservoir_time(); + return prefs::get().countdown_reservoir_time(); } int configure_engine::mp_countdown_turn_bonus_default() const { - return preferences::countdown_turn_bonus(); + return prefs::get().countdown_turn_bonus(); } int configure_engine::mp_countdown_action_bonus_default() const { - return preferences::countdown_action_bonus(); + return prefs::get().countdown_action_bonus(); } bool configure_engine::mp_countdown_default() const { - return preferences::countdown(); + return prefs::get().countdown(); } bool configure_engine::use_map_settings_default() const { - return force_lock_settings() || preferences::use_map_settings(); + return force_lock_settings() || prefs::get().use_map_settings(); } bool configure_engine::random_start_time_default() const { return use_map_settings() ? initial_cfg()["random_start_time"].to_bool(false) - : preferences::random_start_time(); + : prefs::get().random_start_time(); } bool configure_engine::fog_game_default() const { return use_map_settings() ? initial_cfg()["mp_fog"].to_bool(state_.classification().is_normal_mp_game()) - : preferences::fog(); + : prefs::get().fog(); } bool configure_engine::shroud_game_default() const { - return use_map_settings() ? initial_cfg()["mp_shroud"].to_bool(false) : preferences::shroud(); + return use_map_settings() ? initial_cfg()["mp_shroud"].to_bool(false) : prefs::get().shroud(); } bool configure_engine::allow_observers_default() const { - return preferences::allow_observers(); + return prefs::get().allow_observers(); } bool configure_engine::shuffle_sides_default() const { - return preferences::shuffle_sides(); + return prefs::get().shuffle_sides(); } random_faction_mode::type configure_engine::random_faction_mode_default() const { - return random_faction_mode::get_enum(preferences::random_faction_mode()).value_or(random_faction_mode::type::independent); + return random_faction_mode::get_enum(prefs::get().random_faction_mode()).value_or(random_faction_mode::type::independent); } void configure_engine::set_options(const config& cfg) { parameters_.options = cfg; - preferences::set_options(cfg); + prefs::get().set_options(cfg); } const config& configure_engine::options_default() const { - return preferences::options(); + return prefs::get().options(); } void configure_engine::write_parameters() diff --git a/src/game_initialization/connect_engine.cpp b/src/game_initialization/connect_engine.cpp index 6c45208e909ce..598e3e233c954 100644 --- a/src/game_initialization/connect_engine.cpp +++ b/src/game_initialization/connect_engine.cpp @@ -20,8 +20,7 @@ #include "game_initialization/mp_game_utils.hpp" #include "game_initialization/multiplayer.hpp" #include "game_initialization/playcampaign.hpp" -#include "preferences/credentials.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "gettext.hpp" #include "log.hpp" #include "map/map.hpp" @@ -204,10 +203,10 @@ connect_engine::connect_engine(saved_game& state, const bool first_scenario, mp_ if(first_scenario_) { // Add host to the connected users list. - import_user(preferences::login(), false); + import_user(prefs::get().login(), false); } else { // Add host but don't assign a side to him. - import_user(preferences::login(), true); + import_user(prefs::get().login(), true); // Load reserved players information into the sides. load_previous_sides_users(); @@ -741,7 +740,7 @@ void connect_engine::send_level_data() const "create_game", config { "name", params_.name, "password", params_.password, - "ignored", preferences::get_ignored_delim(), + "ignored", prefs::get().get_ignored_delim(), "auto_hosted", false, }, }); @@ -968,13 +967,13 @@ config side_engine::new_config() const // The hosts receives the serversided controller tweaks after the start event, but // for mp sync it's very important that the controller types are correct // during the start/prestart event (otherwise random unit creation during prestart fails). - res["is_local"] = player_id_ == preferences::login() || controller_ == CNTR_COMPUTER || controller_ == CNTR_LOCAL; + res["is_local"] = player_id_ == prefs::get().login() || controller_ == CNTR_COMPUTER || controller_ == CNTR_LOCAL; // This function (new_config) is only meant to be called by the host's machine, which is why this check // works. It essentially certifies that whatever side has the player_id that matches the host's login // will be flagged. The reason we cannot check mp_game_metadata::is_host is because that flag is *always* // true on the host's machine, meaning this flag would be set to true for every side. - res["is_host"] = player_id_ == preferences::login(); + res["is_host"] = player_id_ == prefs::get().login(); std::string desc = user_description(); if(!desc.empty()) { @@ -1011,17 +1010,17 @@ config side_engine::new_config() const // The "player_id" is the id of the client who controls that side. It's always the host for Local and AI players and // always empty for free/reserved sides or null controlled sides. You can use !res["player_id"].empty() to check // whether a side is already taken. - assert(!preferences::login().empty()); + assert(!prefs::get().login().empty()); if(controller_ == CNTR_LOCAL) { - res["player_id"] = preferences::login(); - res["current_player"] = preferences::login(); + res["player_id"] = prefs::get().login(); + res["current_player"] = prefs::get().login(); } else if(controller_ == CNTR_RESERVED) { res.remove_attribute("player_id"); res["current_player"] = reserved_for_; } else if(controller_ == CNTR_COMPUTER) { // TODO: what is the content of player_id_ here ? res["current_player"] = desc; - res["player_id"] = preferences::login(); + res["player_id"] = prefs::get().login(); } else if(!player_id_.empty()) { res["player_id"] = player_id_; res["current_player"] = player_id_; @@ -1146,7 +1145,7 @@ bool side_engine::ready_for_start() const } if(controller_ == CNTR_NETWORK) { - if(player_id_ == preferences::login() || !waiting_to_choose_faction_ || !allow_changes_) { + if(player_id_ == prefs::get().login() || !waiting_to_choose_faction_ || !allow_changes_) { // The host is ready. A network player, who got a chance // to choose faction if allowed, is also ready. return true; diff --git a/src/game_initialization/create_engine.cpp b/src/game_initialization/create_engine.cpp index 3ba2bd8687b37..108ed6d519f56 100644 --- a/src/game_initialization/create_engine.cpp +++ b/src/game_initialization/create_engine.cpp @@ -17,7 +17,7 @@ #include "filesystem.hpp" #include "game_config_manager.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "game_initialization/component_availability.hpp" #include "generators/map_create.hpp" #include "gui/dialogs/campaign_difficulty.hpp" @@ -219,10 +219,10 @@ void campaign::set_metadata() void campaign::mark_if_completed() { - data_["completed"] = preferences::is_campaign_completed(data_["id"]); + data_["completed"] = prefs::get().is_campaign_completed(data_["id"]); for(auto& cfg : data_.child_range("difficulty")) { - cfg["completed_at"] = preferences::is_campaign_completed(data_["id"], cfg["define"]); + cfg["completed_at"] = prefs::get().is_campaign_completed(data_["id"], cfg["define"]); } } @@ -279,7 +279,7 @@ create_engine::create_engine(saved_game& state) state_.mp_settings().saved_game = saved_game_mode::type::no; - for(const std::string& str : preferences::modifications(state_.classification().is_multiplayer())) { + for(const std::string& str : prefs::get().modifications(state_.classification().is_multiplayer())) { if(game_config_.find_child("modification", "id", str)) { state_.classification().active_mods.push_back(str); } diff --git a/src/game_initialization/lobby_data.cpp b/src/game_initialization/lobby_data.cpp index f9b488c0f51e9..79c0d740b1d49 100644 --- a/src/game_initialization/lobby_data.cpp +++ b/src/game_initialization/lobby_data.cpp @@ -30,8 +30,7 @@ #include "map/exception.hpp" #include "map/map.hpp" #include "mp_game_settings.hpp" -#include "preferences/credentials.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "wml_exception.hpp" @@ -72,11 +71,11 @@ user_info::user_state user_info::get_state(int selected_game_id) const user_info::user_relation user_info::get_relation() const { - if(name == preferences::login()) { + if(name == prefs::get().login()) { return user_relation::ME; - } else if(preferences::is_ignored(name)) { + } else if(prefs::get().is_ignored(name)) { return user_relation::IGNORED; - } else if(preferences::is_friend(name)) { + } else if(prefs::get().is_friend(name)) { return user_relation::FRIEND; } else { return user_relation::NEUTRAL; diff --git a/src/game_initialization/multiplayer.cpp b/src/game_initialization/multiplayer.cpp index 1253f41ca1851..c2ef29841c388 100644 --- a/src/game_initialization/multiplayer.cpp +++ b/src/game_initialization/multiplayer.cpp @@ -33,8 +33,7 @@ #include "log.hpp" #include "map_settings.hpp" #include "multiplayer_error_codes.hpp" -#include "preferences/credentials.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "replay.hpp" #include "resources.hpp" #include "saved_game.hpp" @@ -314,7 +313,7 @@ std::unique_ptr mp_manager::open_connection(std::string hos // Enter login loop while(true) { - std::string login = preferences::login(); + std::string login = prefs::get().login(); config response; config& sp = response.add_child("login"); @@ -353,7 +352,7 @@ std::unique_ptr mp_manager::open_connection(std::string hos if(!error) break; do { - std::string password = preferences::password(host, login); + std::string password = prefs::get().password(host, login); const bool fall_through = (*error)["force_confirmation"].to_bool() ? (gui2::show_message(_("Confirm"), (*error)["message"], gui2::dialogs::message::ok_cancel_buttons) == gui2::retval::CANCEL) @@ -468,7 +467,7 @@ std::unique_ptr mp_manager::open_connection(std::string hos } // If we have got a new username we have to start all over again - } while(login == preferences::login()); + } while(login == prefs::get().login()); // Somewhat hacky... // If we broke out of the do-while loop above error is still going to be nullopt @@ -585,7 +584,7 @@ void mp_manager::enter_staging_mode() // If we have a connection, set the appropriate info. No connection means we're in local game mode. if(connection) { metadata = std::make_unique(*connection); - metadata->connected_players.insert(preferences::login()); + metadata->connected_players.insert(prefs::get().login()); metadata->is_host = true; } @@ -620,9 +619,9 @@ void mp_manager::enter_wait_mode(int game_id, bool observe) metadata.current_turn = gi->current_turn; } - if(preferences::skip_mp_replay() || preferences::blindfold_replay()) { + if(prefs::get().skip_mp_replay() || prefs::get().blindfold_replay()) { metadata.skip_replay = true; - metadata.skip_replay_blindfolded = preferences::blindfold_replay(); + metadata.skip_replay_blindfolded = prefs::get().blindfold_replay(); } bool dlg_ok = false; @@ -681,7 +680,7 @@ void start_local_game() { DBG_MP << "starting local game"; - preferences::set_message_private(false); + prefs::get().set_message_private(false); mp_manager(std::nullopt).enter_create_mode(); } @@ -695,7 +694,7 @@ void start_local_game_commandline(const commandline_options& cmdline_opts) // The setup is done equivalently to lobby MP games using as much of existing // code as possible. This means that some things are set up that are not // needed in commandline mode, but they are required by the functions called. - preferences::set_message_private(false); + prefs::get().set_message_private(false); DBG_MP << "entering create mode"; diff --git a/src/game_initialization/playcampaign.cpp b/src/game_initialization/playcampaign.cpp index e6264add8d0ed..89c7a360cbffa 100644 --- a/src/game_initialization/playcampaign.cpp +++ b/src/game_initialization/playcampaign.cpp @@ -34,7 +34,7 @@ #include "log.hpp" #include "map/exception.hpp" #include "playmp_controller.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "saved_game.hpp" #include "savegame.hpp" #include "sound.hpp" @@ -182,12 +182,12 @@ level_result::type campaign_controller::play_game() return res; } - if(preferences::delete_saves()) { + if(prefs::get().delete_saves()) { savegame::clean_saves(state_.classification().label); } - if(preferences::save_replays() && end_level.replay_save) { - savegame::replay_savegame save(state_, preferences::save_compression_format()); + if(prefs::get().save_replays() && end_level.replay_save) { + savegame::replay_savegame save(state_, prefs::get().save_compression_format()); save.save_game_automatic(true); } @@ -197,7 +197,7 @@ level_result::type campaign_controller::play_game() if(state_.get_scenario_id().empty()) { // Don't show The End for multiplayer scenarios. if(res == level_result::type::victory && !state_.classification().is_normal_mp_game()) { - preferences::add_completed_campaign( + prefs::get().add_completed_campaign( state_.classification().campaign, state_.classification().difficulty); if(state_.classification().end_credits) { @@ -266,7 +266,7 @@ level_result::type campaign_controller::play_game() // For multiplayer, we want the save to contain the starting position. // For campaigns however, this is the start-of-scenario save and the // starting position needs to be empty, to force a reload of the scenario config. - savegame::scenariostart_savegame save(state_, preferences::save_compression_format()); + savegame::scenariostart_savegame save(state_, prefs::get().save_compression_format()); save.save_game_automatic(); } } @@ -284,7 +284,7 @@ level_result::type campaign_controller::play_game() } if(state_.classification().is_scenario()) { - if(preferences::delete_saves()) { + if(prefs::get().delete_saves()) { savegame::clean_saves(state_.classification().label); } } diff --git a/src/game_launcher.cpp b/src/game_launcher.cpp index 09f721fbc8e98..79095cdfd3542 100644 --- a/src/game_launcher.cpp +++ b/src/game_launcher.cpp @@ -40,9 +40,7 @@ #include "language.hpp" // for language_def, etc #include "log.hpp" // for LOG_STREAM, logger, general, etc #include "map/exception.hpp" -#include "preferences/credentials.hpp" -#include "preferences/display.hpp" -#include "preferences/general.hpp" // for disable_preferences_save, etc +#include "preferences/preferences.hpp" #include "save_index.hpp" #include "scripting/application_lua_kernel.hpp" #include "sdl/surface.hpp" // for surface @@ -93,7 +91,6 @@ namespace bp = boost::process; game_launcher::game_launcher(const commandline_options& cmdline_opts) : cmdline_opts_(cmdline_opts) , font_manager_() - , prefs_manager_() , image_manager_() , main_event_context_() , hotkey_manager_() @@ -131,7 +128,7 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts) } if(cmdline_opts_.core_id) { - preferences::set_core_id(*cmdline_opts_.core_id); + prefs::get().set_core_id(*cmdline_opts_.core_id); } if(cmdline_opts_.campaign) { jump_to_campaign_.jump = true; @@ -174,7 +171,7 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts) } } if(cmdline_opts_.fps) - preferences::set_show_fps(true); + prefs::get().set_show_fps(true); if(cmdline_opts_.fullscreen) start_in_fullscreen_ = true; if(cmdline_opts_.load) @@ -187,11 +184,11 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts) if(1000 % fps != 0) { ++fps; } - preferences::set_draw_delay(fps); + prefs::get().set_draw_delay(fps); } if(cmdline_opts_.nogui || cmdline_opts_.headless_unit_test) { no_sound = true; - preferences::disable_preferences_save(); + prefs::get().disable_preferences_save(); } if(cmdline_opts_.new_widgets) gui2::new_widgets = true; @@ -205,8 +202,8 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts) const int xres = std::get<0>(*cmdline_opts_.resolution); const int yres = std::get<1>(*cmdline_opts_.resolution); if(xres > 0 && yres > 0) { - preferences::set_resolution(point(xres, yres)); - preferences::set_maximized(false); + prefs::get().set_resolution(point(xres, yres)); + prefs::get().set_maximized(false); } } if(cmdline_opts_.screenshot) { @@ -214,7 +211,7 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts) screenshot_map_ = *cmdline_opts_.screenshot_map_file; screenshot_filename_ = *cmdline_opts_.screenshot_output_file; no_sound = true; - preferences::disable_preferences_save(); + prefs::get().disable_preferences_save(); } if (cmdline_opts_.server){ jump_to_multiplayer_ = true; @@ -224,17 +221,17 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts) } else { // Pick the first server in config if(game_config::server_list.size() > 0) { - multiplayer_server_ = preferences::network_host(); + multiplayer_server_ = prefs::get().network_host(); } else { multiplayer_server_ = ""; } } if(cmdline_opts_.username) { - preferences::disable_preferences_save(); - preferences::set_login(*cmdline_opts_.username); + prefs::get().disable_preferences_save(); + prefs::get().set_login(*cmdline_opts_.username); if(cmdline_opts_.password) { - preferences::disable_preferences_save(); - preferences::set_password(*cmdline_opts.server, *cmdline_opts.username, *cmdline_opts_.password); + prefs::get().disable_preferences_save(); + prefs::get().set_password(*cmdline_opts.server, *cmdline_opts.username, *cmdline_opts_.password); } } } @@ -263,15 +260,15 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts) } // disable sound in nosound mode, or when sound engine failed to initialize - if(no_sound || ((preferences::sound_on() || preferences::music_on() || - preferences::turn_bell() || preferences::UI_sound_on()) && + if(no_sound || ((prefs::get().sound_on() || prefs::get().music_on() || + prefs::get().turn_bell() || prefs::get().ui_sound_on()) && !sound::init_sound())) { - preferences::set_sound(false); - preferences::set_music(false); - preferences::set_turn_bell(false); - preferences::set_UI_sound(false); + prefs::get().set_sound(false); + prefs::get().set_music(false); + prefs::get().set_turn_bell(false); + prefs::get().set_ui_sound(false); } else if(no_music) { // else disable the music in nomusic mode - preferences::set_music(false); + prefs::get().set_music(false); } } @@ -821,8 +818,8 @@ bool game_launcher::goto_editor() void game_launcher::start_wesnothd() { std::string wesnothd_program = ""; - if(!preferences::get_mp_server_program_name().empty()) { - wesnothd_program = preferences::get_mp_server_program_name(); + if(!prefs::get().get_mp_server_program_name().empty()) { + wesnothd_program = prefs::get().get_mp_server_program_name(); } else { wesnothd_program = filesystem::get_wesnothd_name(); } @@ -848,7 +845,7 @@ void game_launcher::start_wesnothd() } catch(const bp::process_error& e) { - preferences::set_mp_server_program_name(""); + prefs::get().set_mp_server_program_name(""); // Couldn't start server so throw error WRN_GENERAL << "Failed to start server " << wesnothd_program << ":\n" << e.what(); @@ -863,7 +860,7 @@ bool game_launcher::play_multiplayer(mp_mode mode) try { start_wesnothd(); } catch(const game::mp_server_error&) { - preferences::show_wesnothd_server_search(); + prefs::get().show_wesnothd_server_search(); try { start_wesnothd(); @@ -880,10 +877,10 @@ bool game_launcher::play_multiplayer(mp_mode mode) } // The prompt saves its input to preferences. - multiplayer_server_ = preferences::network_host(); + multiplayer_server_ = prefs::get().network_host(); - if(multiplayer_server_ != preferences::builtin_servers_list().front().address) { - preferences::set_network_host(multiplayer_server_); + if(multiplayer_server_ != prefs::get().builtin_servers_list().front().address) { + prefs::get().set_network_host(multiplayer_server_); } } diff --git a/src/game_launcher.hpp b/src/game_launcher.hpp index 663a0ef4d9782..331cc845eee20 100644 --- a/src/game_launcher.hpp +++ b/src/game_launcher.hpp @@ -21,7 +21,6 @@ #include "game_end_exceptions.hpp" // for LEVEL_RESULT, etc #include "hotkey/hotkey_manager.hpp" // for manager #include "picture.hpp" // for manager -#include "preferences/game.hpp" // for manager #include "saved_game.hpp" // for saved_game #include "savegame.hpp" // for clean_saves, etc #include "sound.hpp" // for music_thinker @@ -132,7 +131,6 @@ class game_launcher bool start_in_fullscreen_ = false; font::manager font_manager_; - const preferences::manager prefs_manager_; const image::manager image_manager_; const events::event_context main_event_context_; const hotkey::manager hotkey_manager_; diff --git a/src/game_state.cpp b/src/game_state.cpp index 42550586a715d..b085f88b0da79 100644 --- a/src/game_state.cpp +++ b/src/game_state.cpp @@ -24,7 +24,7 @@ #include "pathfind/pathfind.hpp" #include "pathfind/teleport.hpp" #include "play_controller.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "random_deterministic.hpp" #include "reports.hpp" #include "scripting/game_lua_kernel.hpp" @@ -202,7 +202,7 @@ void game_state::init(const config& level, play_controller & pc) for(std::size_t i = 0; i < board_.teams().size(); i++) { // Labels from players in your ignore list default to hidden - if(preferences::is_ignored(board_.teams()[i].current_player())) { + if(prefs::get().is_ignored(board_.teams()[i].current_player())) { std::string label_cat = "side:" + std::to_string(i + 1); board_.hidden_label_categories().push_back(label_cat); } diff --git a/src/gui/auxiliary/tips.cpp b/src/gui/auxiliary/tips.cpp index 6499d1af8ce1e..b815dfb588868 100644 --- a/src/gui/auxiliary/tips.cpp +++ b/src/gui/auxiliary/tips.cpp @@ -18,7 +18,7 @@ #include "gui/auxiliary/tips.hpp" #include "config.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "random.hpp" #include "serialization/string_utils.hpp" @@ -47,7 +47,7 @@ std::vector load(const config& cfg) std::vector shuffle(const std::vector& tips) { std::vector result = tips; - const std::set& units = preferences::encountered_units(); + const std::set& units = prefs::get().encountered_units(); // Remove entries whose filters do not match from the tips list. const auto iter = std::remove_if(result.begin(), result.end(), [&units](const game_tip& tip) { diff --git a/src/gui/dialogs/achievements_dialog.cpp b/src/gui/dialogs/achievements_dialog.cpp index 9bf0b1e2c6c93..812b3edfbc64f 100644 --- a/src/gui/dialogs/achievements_dialog.cpp +++ b/src/gui/dialogs/achievements_dialog.cpp @@ -25,7 +25,7 @@ #include "gui/widgets/progress_bar.hpp" #include "gui/widgets/window.hpp" #include "log.hpp" -#include "preferences/general.hpp" +#include "preferences/preferences.hpp" static lg::log_domain log_config("config"); #define ERR_CONFIG LOG_STREAM(err, log_config) @@ -40,7 +40,7 @@ REGISTER_DIALOG(achievements_dialog) achievements_dialog::achievements_dialog() : modal_dialog(window_id()) , achieve_() - , last_selected_(preferences::selected_achievement_group()) + , last_selected_(prefs::get().selected_achievement_group()) , achievements_box_(nullptr) , content_names_(nullptr) { @@ -76,7 +76,7 @@ void achievements_dialog::pre_show(window& win) void achievements_dialog::post_show(window&) { - preferences::set_selected_achievement_group(last_selected_); + prefs::get().set_selected_achievement_group(last_selected_); } void achievements_dialog::set_achievements_row() diff --git a/src/gui/dialogs/addon/addon_auth.cpp b/src/gui/dialogs/addon/addon_auth.cpp index 5d50564fc76ea..bab1e31646449 100644 --- a/src/gui/dialogs/addon/addon_auth.cpp +++ b/src/gui/dialogs/addon/addon_auth.cpp @@ -22,7 +22,7 @@ #include "gui/widgets/menu_button.hpp" #include "gui/widgets/password_box.hpp" #include "gui/widgets/window.hpp" -#include "preferences/credentials.hpp" +#include "preferences/preferences.hpp" #include "serialization/string_utils.hpp" namespace gui2::dialogs @@ -35,8 +35,8 @@ addon_auth::addon_auth(config& cfg) , cfg_(cfg) { register_bool("remember_password", false, - &preferences::remember_password, - &preferences::set_remember_password); + []() {return prefs::get().remember_password();}, + [](bool v) {prefs::get().set_remember_password(v);}); } void addon_auth::pre_show(window& win) diff --git a/src/gui/dialogs/addon/manager.cpp b/src/gui/dialogs/addon/manager.cpp index 47ea69d56a54b..11a05a2d00f1f 100644 --- a/src/gui/dialogs/addon/manager.cpp +++ b/src/gui/dialogs/addon/manager.cpp @@ -37,13 +37,11 @@ #include "gui/widgets/drawing.hpp" #include "gui/widgets/text_box.hpp" #include "gui/widgets/window.hpp" -#include "preferences/credentials.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "serialization/string_utils.hpp" #include "formula/string_utils.hpp" #include "picture.hpp" #include "language.hpp" -#include "preferences/general.hpp" #include "utils/general.hpp" #include "config.hpp" @@ -447,8 +445,8 @@ void addon_manager::pre_show(window& window) order_dropdown.set_values(order_dropdown_entries); { - const std::string saved_order_name = preferences::addon_manager_saved_order_name(); - const sort_order::type saved_order_direction = preferences::addon_manager_saved_order_direction(); + const std::string saved_order_name = prefs::get().addon_manager_saved_order_name(); + const sort_order::type saved_order_direction = prefs::get().addon_manager_saved_order_direction(); if(!saved_order_name.empty()) { auto order_it = std::find_if(all_orders_.begin(), all_orders_.end(), @@ -794,8 +792,8 @@ void addon_manager::order_addons() } find_widget(get_window(), "addons", false).set_addon_order(func); - preferences::set_addon_manager_saved_order_name(order_struct.as_preference); - preferences::set_addon_manager_saved_order_direction(order); + prefs::get().set_addon_manager_saved_order_name(order_struct.as_preference); + prefs::get().set_addon_manager_saved_order_direction(order); } void addon_manager::on_order_changed(unsigned int sort_column, sort_order::type order) @@ -808,8 +806,8 @@ void addon_manager::on_order_changed(unsigned int sort_column, sort_order::type ++index; } order_menu.set_value(index); - preferences::set_addon_manager_saved_order_name(order_it->as_preference); - preferences::set_addon_manager_saved_order_direction(order); + prefs::get().set_addon_manager_saved_order_name(order_it->as_preference); + prefs::get().set_addon_manager_saved_order_direction(order); } template @@ -933,11 +931,11 @@ void addon_manager::publish_addon(const addon_info& addon) // if the passphrase isn't provided from the _server.pbl, try to pre-populate it from the preferences before prompting for it if(cfg["passphrase"].empty()) { - cfg["passphrase"] = preferences::password(preferences::campaign_server(), cfg["author"]); + cfg["passphrase"] = prefs::get().password(prefs::get().campaign_server(), cfg["author"]); if(!gui2::dialogs::addon_auth::execute(cfg)) { return; } else { - preferences::set_password(preferences::campaign_server(), cfg["author"], cfg["passphrase"]); + prefs::get().set_password(prefs::get().campaign_server(), cfg["author"], cfg["passphrase"]); } } else if(cfg["forum_auth"].to_bool()) { // if the uploader's forum password is present in the _server.pbl @@ -1040,7 +1038,7 @@ static std::string format_addon_time(std::time_t time) if(time) { std::ostringstream ss; - const std::string format = preferences::use_twelve_hour_clock_format() + const std::string format = prefs::get().use_twelve_hour_clock_format() // TRANSLATORS: Month + day of month + year + 12-hour time, eg 'November 02 2021, 1:59 PM'. Format for your locale. // Format reference: https://www.boost.org/doc/libs/1_85_0/doc/html/date_time/date_time_io.html#date_time.format_flags ? _("%B %d %Y, %I:%M %p") diff --git a/src/gui/dialogs/campaign_difficulty.cpp b/src/gui/dialogs/campaign_difficulty.cpp index 308e125edd3a9..0c5c805058ee1 100644 --- a/src/gui/dialogs/campaign_difficulty.cpp +++ b/src/gui/dialogs/campaign_difficulty.cpp @@ -25,7 +25,7 @@ #include "gui/widgets/listbox.hpp" #include "gui/widgets/window.hpp" #include "log.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" static lg::log_domain log_wml("wml"); #define WRN_WML LOG_STREAM(warn, log_wml) @@ -100,7 +100,7 @@ void campaign_difficulty::pre_show(window& window) } styled_widget& widget = find_widget(&grid, "victory", false); - if(preferences::is_campaign_completed(campaign_id_, d["define"])) { + if(prefs::get().is_campaign_completed(campaign_id_, d["define"])) { // Use different laurels according to the difficulty level, following the // pre-existing convention established in campaign_selection class. // Assumes ascending order of difficulty and gold laurel is set first diff --git a/src/gui/dialogs/campaign_selection.cpp b/src/gui/dialogs/campaign_selection.cpp index 1294db1c3672f..627a064e5ec2a 100644 --- a/src/gui/dialogs/campaign_selection.cpp +++ b/src/gui/dialogs/campaign_selection.cpp @@ -30,7 +30,7 @@ #include "gui/widgets/tree_view.hpp" #include "gui/widgets/tree_view_node.hpp" #include "gui/widgets/window.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include #include "utils/irdya_datetime.hpp" @@ -90,7 +90,7 @@ void campaign_selection::campaign_selected() entry["label"] = cfg["label"].str() + " (" + cfg["description"].str() + ")"; entry["image"] = cfg["image"].str("misc/blank-hex.png"); - if(preferences::is_campaign_completed(tree.selected_item()->id(), cfg["define"])) { + if(prefs::get().is_campaign_completed(tree.selected_item()->id(), cfg["define"])) { std::string laurel; if(n + 1 >= max_n) { @@ -228,7 +228,7 @@ void campaign_selection::sort_campaigns(campaign_selection::CAMPAIGN_ORDER order bool exists_in_filtered_result = false; for(unsigned i = 0; i < levels.size(); ++i) { - bool completed = preferences::is_campaign_completed(levels[i]->data()["id"]); + bool completed = prefs::get().is_campaign_completed(levels[i]->data()["id"]); config::const_child_itors difficulties = levels[i]->data().child_range("difficulty"); auto did_complete_at = [](const config& c) { return c["completed_at"].to_bool(); }; @@ -494,7 +494,7 @@ void campaign_selection::post_show(window& window) rng_mode_ = RNG_MODE(std::clamp(find_widget(&window, "rng_menu", false).get_value(), RNG_DEFAULT, RNG_BIASED)); - preferences::set_modifications(engine_.active_mods(), false); + prefs::get().set_modifications(engine_.active_mods(), false); } void campaign_selection::mod_toggled() diff --git a/src/gui/dialogs/chat_log.cpp b/src/gui/dialogs/chat_log.cpp index 1974a0471604e..cb44dc7ec37f6 100644 --- a/src/gui/dialogs/chat_log.cpp +++ b/src/gui/dialogs/chat_log.cpp @@ -27,7 +27,7 @@ #include "font/pango/escape.hpp" #include "desktop/clipboard.hpp" #include "serialization/unicode.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "log.hpp" #include "replay.hpp" #include "gettext.hpp" @@ -109,7 +109,7 @@ class chat_log::model chat_log_history.begin() + last)) { const std::string& timestamp - = preferences::get_chat_timestamp(t.time()); + = prefs::get().get_chat_timestamp(t.time()); if(!lcfilter.empty()) { const std::string& lcsample = utf8::lowercase(timestamp) diff --git a/src/gui/dialogs/editor/choose_addon.cpp b/src/gui/dialogs/editor/choose_addon.cpp index b95cb28c76622..e019315290f67 100644 --- a/src/gui/dialogs/editor/choose_addon.cpp +++ b/src/gui/dialogs/editor/choose_addon.cpp @@ -20,7 +20,7 @@ #include "gui/widgets/label.hpp" #include "gui/widgets/listbox.hpp" #include "gui/widgets/toggle_button.hpp" -#include "preferences/general.hpp" +#include "preferences/preferences.hpp" namespace gui2::dialogs { @@ -48,14 +48,14 @@ void editor_choose_addon::post_show(window& win) if(selected_row == 0) { addon_id_ = "///newaddon///"; - preferences::set_editor_chosen_addon(""); + prefs::get().set_editor_chosen_addon(""); } else if(selected_row == 1 && find_widget(get_window(), "show_all", false).get_value_bool()) { addon_id_ = "mainline"; - preferences::set_editor_chosen_addon(""); + prefs::get().set_editor_chosen_addon(""); } else { grid* row = existing_addons.get_row_grid(selected_row); addon_id_ = dynamic_cast(row->find("existing_addon_id", false))->get_label(); - preferences::set_editor_chosen_addon(addon_id_); + prefs::get().set_editor_chosen_addon(addon_id_); } } @@ -94,7 +94,7 @@ void editor_choose_addon::populate_list(bool show_all) {"existing_addon_id", widget_item{{"label", dir}}}, }; existing_addons.add_row(entry); - if(dir == preferences::editor_chosen_addon()) { + if(dir == prefs::get().editor_chosen_addon()) { selected_row = existing_addons.get_item_count()-1; } } diff --git a/src/gui/dialogs/game_delete.cpp b/src/gui/dialogs/game_delete.cpp index c920d75b4855c..b231587557fe3 100644 --- a/src/gui/dialogs/game_delete.cpp +++ b/src/gui/dialogs/game_delete.cpp @@ -15,7 +15,7 @@ #include "gui/dialogs/game_delete.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" namespace gui2::dialogs { @@ -23,23 +23,23 @@ namespace gui2::dialogs REGISTER_DIALOG(game_delete) /** - * Helper to invert @ref preferences::ask_delete_saves. + * Helper to invert @ref prefs::get().ask_delete_saves. * * The value stored and the way shown is inverted. */ static bool get_dont_ask_again() { - return !preferences::ask_delete_saves(); + return !prefs::get().ask_delete_saves(); } /** - * Helper to invert @ref preferences::set_ask_delete_saves. + * Helper to invert @ref prefs::get().set_ask_delete_saves. * * The value stored and the way shown is inverted. */ static void set_dont_ask_again(const bool ask_again) { - preferences::set_ask_delete_saves(!ask_again); + prefs::get().set_ask_delete_saves(!ask_again); } game_delete::game_delete() diff --git a/src/gui/dialogs/game_load.cpp b/src/gui/dialogs/game_load.cpp index 2773fe69063cb..2d41453b7422e 100644 --- a/src/gui/dialogs/game_load.cpp +++ b/src/gui/dialogs/game_load.cpp @@ -35,7 +35,7 @@ #include "gui/widgets/window.hpp" #include "language.hpp" #include "picture.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "serialization/string_utils.hpp" #include "utils/general.hpp" #include @@ -487,7 +487,7 @@ void game_load::delete_button_callback() if(index < games_.size()) { // See if we should ask the user for deletion confirmation - if(preferences::ask_delete_saves()) { + if(prefs::get().ask_delete_saves()) { if(!gui2::dialogs::game_delete::execute()) { return; } diff --git a/src/gui/dialogs/language_selection.cpp b/src/gui/dialogs/language_selection.cpp index 575ec26943ef9..3630d948dace0 100644 --- a/src/gui/dialogs/language_selection.cpp +++ b/src/gui/dialogs/language_selection.cpp @@ -24,7 +24,7 @@ #include "game_config.hpp" #include "gettext.hpp" #include "language.hpp" -#include "preferences/general.hpp" +#include "preferences/preferences.hpp" namespace gui2::dialogs { @@ -128,7 +128,7 @@ void language_selection::post_show(window& window) assert(res != -1); ::set_language(langs_[res]); - preferences::set_language(langs_[res].localename); + prefs::get().set_language(langs_[res].localename); } } diff --git a/src/gui/dialogs/migrate_version_selection.cpp b/src/gui/dialogs/migrate_version_selection.cpp index faae676bf34ea..418794c7539b7 100644 --- a/src/gui/dialogs/migrate_version_selection.cpp +++ b/src/gui/dialogs/migrate_version_selection.cpp @@ -23,8 +23,7 @@ #include "gui/auxiliary/find_widget.hpp" #include "gui/widgets/listbox.hpp" #include "gui/widgets/window.hpp" -#include "preferences/credentials.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "serialization/parser.hpp" #include @@ -136,9 +135,10 @@ void migrate_version_selection::post_show(window& window) // reload preferences and credentials // otherwise the copied files won't be used and also will get overwritten/deleted when Wesnoth closes - preferences::load_base_prefs(); - preferences::load_game_prefs(); - preferences::load_credentials(); + + migrate_version_selection_friend::clear_preferences(); + migrate_version_selection_friend::load_preferences(); + migrate_version_selection_friend::load_credentials(); } } @@ -187,13 +187,13 @@ void migrate_version_selection::migrate_preferences(const std::string& migrate_p bool current_prefs_are_older = filesystem::file_modified_time(filesystem::get_prefs_file()) < filesystem::file_modified_time(migrate_prefs_file); for(const config::attribute& val : old_cfg.attribute_range()) { if(current_prefs_are_older || !current_cfg.has_attribute(val.first)) { - preferences::set(val.first, val.second); + migrate_version_selection_friend::set(val.first, val.second); } } // don't touch child tags - preferences::write_preferences(); + prefs::get().write_preferences(); } } } diff --git a/src/gui/dialogs/multiplayer/faction_select.cpp b/src/gui/dialogs/multiplayer/faction_select.cpp index e3360a2dbccce..acf434def5fa2 100644 --- a/src/gui/dialogs/multiplayer/faction_select.cpp +++ b/src/gui/dialogs/multiplayer/faction_select.cpp @@ -27,7 +27,7 @@ #include "gui/widgets/toggle_button.hpp" #include "gui/widgets/window.hpp" #include "help/help.hpp" -#include "preferences/game.hpp" // for encountered_units +#include "preferences/preferences.hpp" // for encountered_units #include "units/types.hpp" #include @@ -191,7 +191,7 @@ void faction_select::profile_button_callback() const std::string& leader_type = find_widget(get_window(), "leader_menu", false).get_value_string(); const unit_type* ut = unit_types.find(leader_type); if(ut != nullptr) { - preferences::encountered_units().insert(ut->id()); + prefs::get().encountered_units().insert(ut->id()); help::show_unit_description(*ut); } } diff --git a/src/gui/dialogs/multiplayer/lobby.cpp b/src/gui/dialogs/multiplayer/lobby.cpp index 8e3dede4480ac..128f6f0317ba2 100644 --- a/src/gui/dialogs/multiplayer/lobby.cpp +++ b/src/gui/dialogs/multiplayer/lobby.cpp @@ -44,10 +44,9 @@ #include "font/text_formatting.hpp" #include "formatter.hpp" #include "formula/string_utils.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "gettext.hpp" #include "help/help.hpp" -#include "preferences/lobby.hpp" #include "wesnothd_connection.hpp" #include @@ -75,23 +74,23 @@ mp_lobby::mp_lobby(mp::lobby_info& info, wesnothd_connection& connection, int& j , chatbox_(nullptr) , filter_friends_(register_bool("filter_with_friends", true, - preferences::fi_friends_in_game, - preferences::set_fi_friends_in_game, + []() {return prefs::get().fi_friends_in_game();}, + [](bool v) {prefs::get().set_fi_friends_in_game(v);}, std::bind(&mp_lobby::update_gamelist_filter, this))) , filter_ignored_(register_bool("filter_with_ignored", true, - preferences::fi_blocked_in_game, - preferences::set_fi_blocked_in_game, + []() {return prefs::get().fi_blocked_in_game();}, + [](bool v) {prefs::get().set_fi_blocked_in_game(v);}, std::bind(&mp_lobby::update_gamelist_filter, this))) , filter_slots_(register_bool("filter_vacant_slots", true, - preferences::fi_vacant_slots, - preferences::set_fi_vacant_slots, + []() {return prefs::get().fi_vacant_slots();}, + [](bool v) {prefs::get().set_fi_vacant_slots(v);}, std::bind(&mp_lobby::update_gamelist_filter, this))) , filter_invert_(register_bool("filter_invert", true, - preferences::fi_invert, - preferences::set_fi_invert, + []() {return prefs::get().fi_invert();}, + [](bool v) {prefs::get().set_fi_invert(v);}, std::bind(&mp_lobby::update_gamelist_filter, this))) , filter_auto_hosted_(false) , filter_text_(nullptr) @@ -606,11 +605,11 @@ void mp_lobby::pre_show(window& window) menu_button& replay_options = find_widget(&window, "replay_options", false); - if(preferences::skip_mp_replay()) { + if(prefs::get().skip_mp_replay()) { replay_options.set_selected(1); } - if(preferences::blindfold_replay()) { + if(prefs::get().blindfold_replay()) { replay_options.set_selected(2); } @@ -1007,8 +1006,8 @@ void mp_lobby::skip_replay_changed_callback() { // TODO: this prefence should probably be controlled with an enum const int value = find_widget(get_window(), "replay_options", false).get_value(); - preferences::set_skip_mp_replay(value == 1); - preferences::set_blindfold_replay(value == 2); + prefs::get().set_skip_mp_replay(value == 1); + prefs::get().set_blindfold_replay(value == 2); } } // namespace dialogs diff --git a/src/gui/dialogs/multiplayer/mp_alerts_options.cpp b/src/gui/dialogs/multiplayer/mp_alerts_options.cpp index cfe894b2ff88d..fa433a955ad36 100644 --- a/src/gui/dialogs/multiplayer/mp_alerts_options.cpp +++ b/src/gui/dialogs/multiplayer/mp_alerts_options.cpp @@ -25,7 +25,7 @@ #include "gui/widgets/window.hpp" #include "mp_ui_alerts.hpp" -#include "preferences/general.hpp" +#include "preferences/preferences.hpp" #include @@ -36,15 +36,15 @@ namespace gui2::dialogs static toggle_button* setup_pref_toggle_button(const std::string& id, const std::string& type, bool def, window& window) { - toggle_button* b = find_widget(&window, id+"_"+type, false, true); - b->set_value(preferences::mp_alert_option(id, type, def)); - //ensure we have yes / no for the toggle button, so that the preference matches the toggle button for sure. - if (preferences::has_mp_alert_option(id, type)) { - preferences::set_mp_alert_option(id, type, def); + if (!prefs::get().has_mp_alert_option(id, type)) { + prefs::get().set_mp_alert_option(id, type, def); } - connect_signal_mouse_left_click(*b, std::bind([b, id, type]() { preferences::set_mp_alert_option(id, type, b->get_value_bool()); })); + toggle_button* b = find_widget(&window, id+"_"+type, false, true); + b->set_value(prefs::get().mp_alert_option(id, type, def)); + + connect_signal_mouse_left_click(*b, std::bind([b, id, type]() { prefs::get().set_mp_alert_option(id, type, b->get_value_bool()); })); return b; } @@ -61,7 +61,7 @@ static void setup_item(const std::string& item, window& window) if (!desktop::notifications::available()) { notif->set_value(false); notif->set_active(false); - preferences::set_mp_alert_option(item, "notif", false); + prefs::get().set_mp_alert_option(item, "notif", false); } else { notif->set_active(true); } @@ -72,8 +72,8 @@ static void setup_item(const std::string& item, window& window) static void set_pref_and_button(const std::string& id, const std::string& type, bool value, window& window) { - preferences::set_mp_alert_option(id, type, value); - toggle_button* button = find_widget(&window, id, false, true); + prefs::get().set_mp_alert_option(id, type, value); + toggle_button* button = find_widget(&window, id+"_"+type, false, true); button->set_value(value); } diff --git a/src/gui/dialogs/multiplayer/mp_change_control.cpp b/src/gui/dialogs/multiplayer/mp_change_control.cpp index de456d5c9d93a..a5b643f1cabd8 100644 --- a/src/gui/dialogs/multiplayer/mp_change_control.cpp +++ b/src/gui/dialogs/multiplayer/mp_change_control.cpp @@ -22,7 +22,7 @@ #include "formula/string_utils.hpp" #include "game_board.hpp" #include "game_display.hpp" -#include "preferences/credentials.hpp" +#include "preferences/preferences.hpp" #include "gui/auxiliary/find_widget.hpp" #include "gui/widgets/label.hpp" #include "gui/widgets/listbox.hpp" @@ -107,7 +107,7 @@ void mp_change_control::pre_show(window& window) temp_nicks.insert(observers.begin(), observers.end()); // In case we are an observer, it isn't in the observers set and has to be added manually. - temp_nicks.insert(preferences::login()); + temp_nicks.insert(prefs::get().login()); // // Initialize nick list diff --git a/src/gui/dialogs/multiplayer/mp_connect.cpp b/src/gui/dialogs/multiplayer/mp_connect.cpp index 79b354bea8db2..d1431485688e0 100644 --- a/src/gui/dialogs/multiplayer/mp_connect.cpp +++ b/src/gui/dialogs/multiplayer/mp_connect.cpp @@ -18,7 +18,7 @@ #include "gui/dialogs/multiplayer/mp_connect.hpp" #include "gettext.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "gui/auxiliary/field.hpp" #include "gui/dialogs/edit_text.hpp" #include "gui/dialogs/modal_dialog.hpp" @@ -65,11 +65,11 @@ mp_connect::mp_connect() : modal_dialog(window_id()) , host_name_(register_text("host_name", true, - preferences::network_host, - preferences::set_network_host, + []() {return prefs::get().network_host();}, + [](std::string v) {prefs::get().set_network_host(v);}, true)) - , builtin_servers_(preferences::builtin_servers_list()) - , user_servers_(preferences::user_servers_list()) + , builtin_servers_(prefs::get().builtin_servers_list()) + , user_servers_(prefs::get().user_servers_list()) { } @@ -191,7 +191,7 @@ void mp_connect::on_server_add() info.address = address; user_servers_.insert(user_servers_.begin() + mem_pos, info); - preferences::set_user_servers_list(user_servers_); + prefs::get().set_user_servers_list(user_servers_); insert_into_server_listbox(server_list, info, ui_pos); select_first_match(); @@ -211,7 +211,7 @@ void mp_connect::on_server_delete() } user_servers_.erase(user_servers_.begin() + selection.relative_index()); - preferences::set_user_servers_list(user_servers_); + prefs::get().set_user_servers_list(user_servers_); server_list.remove_row(selection.row()); on_server_select(); diff --git a/src/gui/dialogs/multiplayer/mp_create_game.cpp b/src/gui/dialogs/multiplayer/mp_create_game.cpp index d5c581b500041..60a32fb6e981c 100644 --- a/src/gui/dialogs/multiplayer/mp_create_game.cpp +++ b/src/gui/dialogs/multiplayer/mp_create_game.cpp @@ -38,7 +38,7 @@ #include "gui/widgets/toggle_panel.hpp" #include "log.hpp" #include "map_settings.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" #include "save_index.hpp" #include "savegame.hpp" @@ -56,9 +56,6 @@ namespace gui2::dialogs // Special retval value for loading a game static const int LOAD_GAME = 100; -// Shorthand -namespace prefs = preferences; - REGISTER_DIALOG(mp_create_game) mp_create_game::mp_create_game(saved_game& state, bool local_mode) @@ -68,25 +65,55 @@ mp_create_game::mp_create_game(saved_game& state, bool local_mode) , options_manager_() , selected_game_index_(-1) , selected_rfm_index_(-1) - , use_map_settings_(register_bool( "use_map_settings", true, prefs::use_map_settings, prefs::set_use_map_settings, + , use_map_settings_(register_bool( "use_map_settings", true, + []() {return prefs::get().use_map_settings();}, + [](bool v) {prefs::get().set_use_map_settings(v);}, std::bind(&mp_create_game::update_map_settings, this))) - , fog_(register_bool("fog", true, prefs::fog, prefs::set_fog)) - , shroud_(register_bool("shroud", true, prefs::shroud, prefs::set_shroud)) - , start_time_(register_bool("random_start_time", true, prefs::random_start_time, prefs::set_random_start_time)) - , time_limit_(register_bool("time_limit", true, prefs::countdown, prefs::set_countdown, + , fog_(register_bool("fog", true, + []() {return prefs::get().fog();}, + [](bool v) {prefs::get().set_fog(v);})) + , shroud_(register_bool("shroud", true, + []() {return prefs::get().shroud();}, + [](bool v) {prefs::get().set_shroud(v);})) + , start_time_(register_bool("random_start_time", true, + []() {return prefs::get().random_start_time();}, + [](bool v) {prefs::get().set_random_start_time(v);})) + , time_limit_(register_bool("time_limit", true, + []() {return prefs::get().countdown();}, + [](bool v) {prefs::get().set_countdown(v);}, std::bind(&mp_create_game::update_map_settings, this))) - , shuffle_sides_(register_bool("shuffle_sides", true, prefs::shuffle_sides, prefs::set_shuffle_sides)) - , observers_(register_bool("observers", true, prefs::allow_observers, prefs::set_allow_observers)) + , shuffle_sides_(register_bool("shuffle_sides", true, + []() {return prefs::get().shuffle_sides();}, + [](bool v) {prefs::get().set_shuffle_sides(v);})) + , observers_(register_bool("observers", true, + []() {return prefs::get().allow_observers();}, + [](bool v) {prefs::get().set_allow_observers(v);})) , strict_sync_(register_bool("strict_sync", true)) , private_replay_(register_bool("private_replay", true)) - , turns_(register_integer("turn_count", true, prefs::turns, prefs::set_turns)) - , gold_(register_integer("village_gold", true, prefs::village_gold, prefs::set_village_gold)) - , support_(register_integer("village_support", true, prefs::village_support, prefs::set_village_support)) - , experience_(register_integer("experience_modifier", true, prefs::xp_modifier, prefs::set_xp_modifier)) - , init_turn_limit_(register_integer("init_turn_limit", true, prefs::countdown_init_time, prefs::set_countdown_init_time)) - , turn_bonus_(register_integer("turn_bonus", true, prefs::countdown_turn_bonus, prefs::set_countdown_turn_bonus)) - , reservoir_(register_integer("reservoir", true, prefs::countdown_reservoir_time, prefs::set_countdown_reservoir_time)) - , action_bonus_(register_integer("action_bonus", true, prefs::countdown_action_bonus, prefs::set_countdown_action_bonus)) + , turns_(register_integer("turn_count", true, + []() {return prefs::get().turns();}, + [](int v) {prefs::get().set_turns(v);})) + , gold_(register_integer("village_gold", true, + []() {return prefs::get().village_gold();}, + [](int v) {prefs::get().set_village_gold(v);})) + , support_(register_integer("village_support", true, + []() {return prefs::get().village_support();}, + [](int v) {prefs::get().set_village_support(v);})) + , experience_(register_integer("experience_modifier", true, + []() {return prefs::get().xp_modifier();}, + [](int v) {prefs::get().set_xp_modifier(v);})) + , init_turn_limit_(register_integer("init_turn_limit", true, + []() {return prefs::get().countdown_init_time();}, + [](int v) {prefs::get().set_countdown_init_time(v);})) + , turn_bonus_(register_integer("turn_bonus", true, + []() {return prefs::get().countdown_turn_bonus();}, + [](int v) {prefs::get().set_countdown_turn_bonus(v);})) + , reservoir_(register_integer("reservoir", true, + []() {return prefs::get().countdown_reservoir_time();}, + [](int v) {prefs::get().set_countdown_reservoir_time(v);})) + , action_bonus_(register_integer("action_bonus", true, + []() {return prefs::get().countdown_action_bonus();}, + [](int v) {prefs::get().set_countdown_action_bonus(v);})) , mod_list_() , eras_menu_button_() , local_mode_(local_mode) @@ -172,7 +199,7 @@ void mp_create_game::pre_show(window& win) // Helper to make sure the initially selected level type is valid auto get_initial_type_index = [this]()->int { const auto index = std::find_if(level_types_.begin(), level_types_.end(), [](level_type_info& info) { - return info.first == *level_type::get_enum(preferences::level_type()); + return info.first == *level_type::get_enum(prefs::get().level_type()); }); if(index != level_types_.end()) { @@ -192,7 +219,7 @@ void mp_create_game::pre_show(window& win) // mod_list_ = &find_widget(&win, "mod_list", false); - const auto& activemods = preferences::modifications(); + const auto& activemods = prefs::get().modifications(); for(const auto& mod : create_engine_.get_extras_by_type(ng::create_engine::MOD)) { widget_data data; widget_item item; @@ -239,7 +266,7 @@ void mp_create_game::pre_show(window& win) connect_signal_notify_modified(*eras_menu_button_, std::bind(&mp_create_game::on_era_select, this)); - const int era_selection = create_engine_.find_extra_by_id(ng::create_engine::ERA, preferences::era()); + const int era_selection = create_engine_.find_extra_by_id(ng::create_engine::ERA, prefs::get().era()); if(era_selection >= 0) { eras_menu_button_->set_selected(era_selection); } @@ -249,7 +276,7 @@ void mp_create_game::pre_show(window& win) // // Set up random faction mode menu_button // - const int initial_index = static_cast(random_faction_mode::get_enum(prefs::random_faction_mode()).value_or(random_faction_mode::type::independent)); + const int initial_index = static_cast(random_faction_mode::get_enum(prefs::get().random_faction_mode()).value_or(random_faction_mode::type::independent)); menu_button& rfm_menu_button = find_widget(&win, "random_faction_mode", false); rfm_menu_button.set_selected(initial_index); @@ -317,7 +344,7 @@ void mp_create_game::pre_show(window& win) win.add_to_keyboard_chain(&list); // This handles the initial game selection as well - display_games_of_type(level_types_[get_initial_type_index()].first, preferences::level()); + display_games_of_type(level_types_[get_initial_type_index()].first, prefs::get().level()); // Initial tab selection must be done after game selection so the field widgets are set to their correct active state. on_tab_select(); @@ -804,15 +831,15 @@ void mp_create_game::set_active_mods(const std::vector& val) void mp_create_game::reset_timer_settings() { // This allows the defaults to be returned by the pref getters below - preferences::erase("mp_countdown_init_time"); - preferences::erase("mp_countdown_reservoir_time"); - preferences::erase("mp_countdown_turn_bonus"); - preferences::erase("mp_countdown_action_bonus"); - - init_turn_limit_->set_widget_value(preferences::countdown_init_time()); - turn_bonus_->set_widget_value(preferences::countdown_turn_bonus()); - reservoir_->set_widget_value(preferences::countdown_reservoir_time()); - action_bonus_->set_widget_value(preferences::countdown_action_bonus()); + prefs::get().clear_countdown_init_time(); + prefs::get().clear_countdown_reservoir_time(); + prefs::get().clear_countdown_turn_bonus(); + prefs::get().clear_countdown_action_bonus(); + + init_turn_limit_->set_widget_value(prefs::get().countdown_init_time()); + turn_bonus_->set_widget_value(prefs::get().countdown_turn_bonus()); + reservoir_->set_widget_value(prefs::get().countdown_reservoir_time()); + action_bonus_->set_widget_value(prefs::get().countdown_action_bonus()); } bool mp_create_game::dialog_exit_hook(window& /*window*/) @@ -855,10 +882,10 @@ void mp_create_game::post_show(window& window) } if(get_retval() == retval::OK) { - prefs::set_modifications(create_engine_.active_mods()); - prefs::set_level_type(static_cast(create_engine_.current_level_type())); - prefs::set_level(create_engine_.current_level().id()); - prefs::set_era(create_engine_.current_era().id); + prefs::get().set_modifications(create_engine_.active_mods()); + prefs::get().set_level_type(static_cast(create_engine_.current_level_type())); + prefs::get().set_level(create_engine_.current_level().id()); + prefs::get().set_era(create_engine_.current_era().id); create_engine_.prepare_for_era_and_mods(); @@ -939,7 +966,7 @@ void mp_create_game::post_show(window& window) config_engine_->set_random_faction_mode(type); // Since we don't have a field handling this option, we need to save the value manually - prefs::set_random_faction_mode(random_faction_mode::get_string(type)); + prefs::get().set_random_faction_mode(random_faction_mode::get_string(type)); // Save custom option settings config_engine_->set_options(options_manager_->get_options_config()); diff --git a/src/gui/dialogs/multiplayer/mp_host_game_prompt.cpp b/src/gui/dialogs/multiplayer/mp_host_game_prompt.cpp index 6caa5a80c9bd4..2b90bd5c56ee5 100644 --- a/src/gui/dialogs/multiplayer/mp_host_game_prompt.cpp +++ b/src/gui/dialogs/multiplayer/mp_host_game_prompt.cpp @@ -16,7 +16,7 @@ #include "gui/dialogs/multiplayer/mp_host_game_prompt.hpp" -#include "preferences/game.hpp" +#include "preferences/preferences.hpp" namespace gui2::dialogs { @@ -24,19 +24,19 @@ namespace gui2::dialogs REGISTER_DIALOG(mp_host_game_prompt) /** - * Helper for @ref preferences::ask_delete_saves. + * Helper for @ref prefs::get().ask_delete_saves. */ static bool get_do_not_show_again() { - return preferences::mp_server_warning_disabled() != 1; + return prefs::get().mp_server_warning_disabled() != 1; } /** - * Helper for @ref preferences::set_ask_delete_saves. + * Helper for @ref prefs::get().set_ask_delete_saves. */ static void set_do_not_show_again(const bool do_not_show_again) { - preferences::set_mp_server_warning_disabled(do_not_show_again ? 2 : 1); + prefs::get().set_mp_server_warning_disabled(do_not_show_again ? 2 : 1); } mp_host_game_prompt::mp_host_game_prompt() diff --git a/src/gui/dialogs/multiplayer/mp_join_game.cpp b/src/gui/dialogs/multiplayer/mp_join_game.cpp index 061b547bfbcad..b9a6e81b7dc6c 100644 --- a/src/gui/dialogs/multiplayer/mp_join_game.cpp +++ b/src/gui/dialogs/multiplayer/mp_join_game.cpp @@ -39,7 +39,7 @@ #include "gui/widgets/tree_view_node.hpp" #include "log.hpp" #include "mp_ui_alerts.hpp" -#include "preferences/credentials.hpp" +#include "preferences/preferences.hpp" #include "saved_game.hpp" #include "side_controller.hpp" #include "units/types.hpp" @@ -164,7 +164,7 @@ bool mp_join_game::fetch_game_config() for(const config& side : get_scenario().child_range("side")) { // TODO: it can happen that the scenario specifies that the controller // of a side should also gain control of another side. - if(side["controller"] == side_controller::reserved && side["current_player"] == preferences::login()) { + if(side["controller"] == side_controller::reserved && side["current_player"] == prefs::get().login()) { side_choice = &side; side_num_choice = side_num_counter; break; @@ -176,14 +176,14 @@ bool mp_join_game::fetch_game_config() side_num_choice = side_num_counter; } - if(side["current_player"] == preferences::login()) { + if(side["current_player"] == prefs::get().login()) { side_choice = &side; side_num_choice = side_num_counter; break; // Found the preferred one } } - if(side["player_id"] == preferences::login()) { + if(side["player_id"] == prefs::get().login()) { // We already own a side in this game return true; } @@ -326,7 +326,7 @@ bool mp_join_game::show_flg_select(int side_num, bool first_time) config faction; config& change = faction.add_child("change_faction"); change["change_faction"] = true; - change["name"] = preferences::login(); + change["name"] = prefs::get().login(); change["faction"] = flg.current_faction()["id"]; change["leader"] = flg.current_leader(); change["gender"] = flg.current_gender(); @@ -448,7 +448,7 @@ void mp_join_game::generate_side_list() auto* select_leader_button = find_widget