From c3da236f92578da64c3ec66d363772d6119ae39f Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 10 Aug 2022 13:09:48 +1000 Subject: [PATCH] System: Preparations for per-game controller settings --- src/core/system.cpp | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/src/core/system.cpp b/src/core/system.cpp index 91b02325d..050128842 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -862,8 +862,13 @@ bool System::UpdateGameSettingsLayer() } std::string input_profile_name; + bool use_game_settings_for_controller = false; if (new_interface) - new_interface->GetStringValue("ControllerPorts", "InputProfileName", &input_profile_name); + { + new_interface->GetBoolValue("ControllerPorts", "UseGameSettingsForController", &use_game_settings_for_controller); + if (!use_game_settings_for_controller) + new_interface->GetStringValue("ControllerPorts", "InputProfileName", &input_profile_name); + } if (!s_game_settings_interface && !new_interface && s_input_profile_name == input_profile_name) return false; @@ -872,31 +877,39 @@ bool System::UpdateGameSettingsLayer() s_game_settings_interface = std::move(new_interface); std::unique_ptr input_interface; - if (!input_profile_name.empty()) + if (!use_game_settings_for_controller) { - const std::string filename(GetInputProfilePath(input_profile_name)); - if (FileSystem::FileExists(filename.c_str())) + if (!input_profile_name.empty()) { - Log_InfoPrintf("Loading input profile from '%s'...", filename.c_str()); - input_interface = std::make_unique(std::move(filename)); - if (!input_interface->Load()) + const std::string filename(GetInputProfilePath(input_profile_name)); + if (FileSystem::FileExists(filename.c_str())) { - Log_ErrorPrintf("Failed to parse input profile ini '%s'", input_interface->GetFileName().c_str()); - input_interface.reset(); + Log_InfoPrintf("Loading input profile from '%s'...", filename.c_str()); + input_interface = std::make_unique(std::move(filename)); + if (!input_interface->Load()) + { + Log_ErrorPrintf("Failed to parse input profile ini '%s'", input_interface->GetFileName().c_str()); + input_interface.reset(); + input_profile_name = {}; + } + } + else + { + Log_InfoPrintf("No input profile found (tried '%s')", filename.c_str()); input_profile_name = {}; } } - else - { - Log_InfoPrintf("No input profile found (tried '%s')", filename.c_str()); - input_profile_name = {}; - } + + Host::Internal::SetInputSettingsLayer(input_interface.get()); + } + else + { + // using game settings for bindings too + Host::Internal::SetInputSettingsLayer(s_game_settings_interface.get()); } - Host::Internal::SetInputSettingsLayer(input_interface.get()); s_input_settings_interface = std::move(input_interface); s_input_profile_name = std::move(input_profile_name); - return true; }