diff options
| author | iwubcode <iwubcode@users.noreply.github.com> | 2018-04-22 16:27:10 -0500 |
|---|---|---|
| committer | iwubcode <iwubcode@users.noreply.github.com> | 2018-07-07 12:55:49 -0500 |
| commit | 14482a72af9e70667cb0e8477f4c14feb2c7a762 (patch) | |
| tree | e4fd6c9a881ce9ecf347c32e016849c5b64fb0a9 /Source/Core/InputCommon | |
| parent | 485285eadc71a8ca7055b9fc6b5da13c8b0251f4 (diff) | |
Input: Allow cycling to occur for each individual controller
Diffstat (limited to 'Source/Core/InputCommon')
| -rw-r--r-- | Source/Core/InputCommon/InputConfig.cpp | 13 | ||||
| -rw-r--r-- | Source/Core/InputCommon/InputProfile.cpp | 77 | ||||
| -rw-r--r-- | Source/Core/InputCommon/InputProfile.h | 16 |
3 files changed, 59 insertions, 47 deletions
diff --git a/Source/Core/InputCommon/InputConfig.cpp b/Source/Core/InputCommon/InputConfig.cpp index 989c1bdce9..9ca3e1708d 100644 --- a/Source/Core/InputCommon/InputConfig.cpp +++ b/Source/Core/InputCommon/InputConfig.cpp @@ -7,6 +7,7 @@ #include "Common/FileUtil.h" #include "Common/IniFile.h" #include "Common/MsgHandler.h" +#include "Common/StringUtil.h" #include "Core/ConfigManager.h" #include "Core/HW/Wiimote.h" #include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" @@ -51,8 +52,16 @@ bool InputConfig::LoadConfig(bool isGC) { if (control_section->Exists(type + "Profile" + num[i])) { - if (control_section->Get(type + "Profile" + num[i], &profile[i])) + std::string profile_setting; + if (control_section->Get(type + "Profile" + num[i], &profile_setting)) { + // Setting can contain commas, which means there are multiple profiles specified + // this is used for controller cycling + const auto& profile_options = SplitString(profile_setting, ','); + + // Use the first profile by default + profile[i] = profile_options[0]; + if (File::Exists(File::GetUserPath(D_CONFIG_IDX) + path + profile[i] + ".ini")) { useProfile[i] = true; @@ -76,7 +85,7 @@ bool InputConfig::LoadConfig(bool isGC) if (useProfile[n]) { IniFile profile_ini; - profile_ini.Load(File::GetUserPath(D_CONFIG_IDX) + path + profile[n] + ".ini"); + profile_ini.Load(profile[n]); controller->LoadConfig(profile_ini.GetOrCreateSection("Profile")); } else diff --git a/Source/Core/InputCommon/InputProfile.cpp b/Source/Core/InputCommon/InputProfile.cpp index 07fa1f7795..7cefa5122c 100644 --- a/Source/Core/InputCommon/InputProfile.cpp +++ b/Source/Core/InputCommon/InputProfile.cpp @@ -4,8 +4,9 @@ #include "Common/FileSearch.h" #include "Common/FileUtil.h" +#include "Common/StringUtil.h" -#include "Core/Config/WiimoteInputSettings.h" +#include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/HW/Wiimote.h" #include "Core/HotkeyManager.h" @@ -41,7 +42,7 @@ namespace InputProfile return profiles[profile_index]; } - void ProfileCycler::UpdateToProfile(const std::string& profile_filename, const std::vector<ControllerEmu::EmulatedController*>& controllers) + void ProfileCycler::UpdateToProfile(const std::string& profile_filename, ControllerEmu::EmulatedController* controller) { std::string base; SplitPath(profile_filename, nullptr, &base, nullptr); @@ -49,32 +50,14 @@ namespace InputProfile IniFile ini_file; if (ini_file.Load(profile_filename)) { - Core::DisplayMessage("Loading input profile: " + base, display_message_ms); - - for (auto* controller : controllers) - { - controller->LoadConfig(ini_file.GetOrCreateSection("Profile")); - controller->UpdateReferences(g_controller_interface); - } + Core::DisplayMessage("Loading input profile '" + base + "' for device '" + controller->GetName() + "'", display_message_ms); + controller->LoadConfig(ini_file.GetOrCreateSection("Profile")); + controller->UpdateReferences(g_controller_interface); } else { - Core::DisplayMessage("Unable to load input profile: " + base, display_message_ms); - } - } - - std::vector<ControllerEmu::EmulatedController*> ProfileCycler::GetControllersForDevice(InputConfig* device_configuration) - { - const std::size_t size = device_configuration->GetControllerCount(); - - std::vector<ControllerEmu::EmulatedController*> result(size); - - for (int i = 0; i < static_cast<int>(size); i++) - { - result[i] = device_configuration->GetController(i); + Core::DisplayMessage("Unable to load input profile '" + base + "' for device '" + controller->GetName() + "'", display_message_ms); } - - return result; } std::vector<std::string> ProfileCycler::GetProfilesFromSetting(const std::string& setting, InputConfig* device_configuration) @@ -86,7 +69,7 @@ namespace InputProfile std::vector<std::string> result(profiles.size()); std::transform(profiles.begin(), profiles.end(), result.begin(), [&device_profile_root_location](const std::string& profile) { - return device_profile_root_location + "/" + profile; + return device_profile_root_location + "/" + profile + ".ini"; }); return result; @@ -107,7 +90,8 @@ namespace InputProfile } void ProfileCycler::CycleProfile(CycleDirection cycle_direction, - InputConfig* device_configuration, int& profile_index) + InputConfig* device_configuration, int& profile_index, + int controller_index) { const auto& profiles = GetProfilesForDevice(device_configuration); if (profiles.empty()) @@ -117,13 +101,20 @@ namespace InputProfile } const std::string profile = GetProfile(cycle_direction, profile_index, profiles); - const auto& controllers = GetControllersForDevice(device_configuration); - UpdateToProfile(profile, controllers); + auto* controller = device_configuration->GetController(controller_index); + if (controller) + { + UpdateToProfile(profile, controller); + } + else + { + Core::DisplayMessage("No controller found for index: " + std::to_string(controller_index), display_message_ms); + } } void ProfileCycler::CycleProfileForGame(CycleDirection cycle_direction, InputConfig* device_configuration, int& profile_index, - const std::string& setting) + const std::string& setting, int controller_index) { const auto& profiles = GetProfilesForDevice(device_configuration); if (profiles.empty()) @@ -159,25 +150,37 @@ namespace InputProfile } } - void ProfileCycler::NextWiimoteProfile() + std::string ProfileCycler::GetWiimoteInputProfilesForGame(int controller_index) + { + IniFile game_ini = SConfig::GetInstance().LoadGameIni(); + const IniFile::Section* const control_section = game_ini.GetOrCreateSection("Controls"); + + std::string result; + control_section->Get(StringFromFormat("WiimoteProfile%d", controller_index+1), &result); + return result; + } + + void ProfileCycler::NextWiimoteProfile(int controller_index) { - CycleProfile(CycleDirection::Forward, Wiimote::GetConfig(), m_wiimote_profile_index); + CycleProfile(CycleDirection::Forward, Wiimote::GetConfig(), m_wiimote_profile_index, + controller_index); } - void ProfileCycler::PreviousWiimoteProfile() + void ProfileCycler::PreviousWiimoteProfile(int controller_index) { - CycleProfile(CycleDirection::Backward, Wiimote::GetConfig(), m_wiimote_profile_index); + CycleProfile(CycleDirection::Backward, Wiimote::GetConfig(), m_wiimote_profile_index, + controller_index); } - void ProfileCycler::NextWiimoteProfileForGame() + void ProfileCycler::NextWiimoteProfileForGame(int controller_index) { CycleProfileForGame(CycleDirection::Forward, Wiimote::GetConfig(), m_wiimote_profile_index, - Config::Get(Config::WIIMOTE_PROFILES)); + GetWiimoteInputProfilesForGame(controller_index), controller_index); } - void ProfileCycler::PreviousWiimoteProfileForGame() + void ProfileCycler::PreviousWiimoteProfileForGame(int controller_index) { CycleProfileForGame(CycleDirection::Backward, Wiimote::GetConfig(), m_wiimote_profile_index, - Config::Get(Config::WIIMOTE_PROFILES)); + GetWiimoteInputProfilesForGame(controller_index), controller_index); } } diff --git a/Source/Core/InputCommon/InputProfile.h b/Source/Core/InputCommon/InputProfile.h index ec0344b23f..6cf2b05716 100644 --- a/Source/Core/InputCommon/InputProfile.h +++ b/Source/Core/InputCommon/InputProfile.h @@ -25,19 +25,19 @@ namespace InputProfile class ProfileCycler { public: - void NextWiimoteProfile(); - void PreviousWiimoteProfile(); - void NextWiimoteProfileForGame(); - void PreviousWiimoteProfileForGame(); + void NextWiimoteProfile(int controller_index); + void PreviousWiimoteProfile(int controller_index); + void NextWiimoteProfileForGame(int controller_index); + void PreviousWiimoteProfileForGame(int controller_index); private: - void CycleProfile(CycleDirection cycle_direction, InputConfig* device_configuration, int& profile_index); - void CycleProfileForGame(CycleDirection cycle_direction, InputConfig* device_configuration, int& profile_index, const std::string& setting); + void CycleProfile(CycleDirection cycle_direction, InputConfig* device_configuration, int& profile_index, int controller_index); + void CycleProfileForGame(CycleDirection cycle_direction, InputConfig* device_configuration, int& profile_index, const std::string& setting, int controller_index); std::vector<std::string> GetProfilesForDevice(InputConfig* device_configuration); std::vector<std::string> GetProfilesFromSetting(const std::string& setting, InputConfig* device_configuration); std::string GetProfile(CycleDirection cycle_direction, int& profile_index, const std::vector<std::string>& profiles); std::vector<std::string> GetMatchingProfilesFromSetting(const std::string& setting, const std::vector<std::string>& profiles, InputConfig* device_configuration); - void UpdateToProfile(const std::string& profile_filename, const std::vector<ControllerEmu::EmulatedController*>& controllers); - std::vector<ControllerEmu::EmulatedController*> GetControllersForDevice(InputConfig* device_configuration); + void UpdateToProfile(const std::string& profile_filename, ControllerEmu::EmulatedController* controller); + std::string GetWiimoteInputProfilesForGame(int controller_index); int m_wiimote_profile_index = 0; }; |
