From 14482a72af9e70667cb0e8477f4c14feb2c7a762 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Sun, 22 Apr 2018 16:27:10 -0500 Subject: [PATCH] Input: Allow cycling to occur for each individual controller --- .../Core/Core/Config/WiimoteInputSettings.cpp | 3 - .../Core/Core/Config/WiimoteInputSettings.h | 4 - Source/Core/Core/HotkeyManager.cpp | 24 ++++-- Source/Core/Core/HotkeyManager.h | 20 ++++- Source/Core/DolphinQt/HotkeyScheduler.cpp | 46 +++++++++-- Source/Core/InputCommon/InputConfig.cpp | 13 +++- Source/Core/InputCommon/InputProfile.cpp | 77 ++++++++++--------- Source/Core/InputCommon/InputProfile.h | 16 ++-- 8 files changed, 131 insertions(+), 72 deletions(-) diff --git a/Source/Core/Core/Config/WiimoteInputSettings.cpp b/Source/Core/Core/Config/WiimoteInputSettings.cpp index 3dac7e5851..a60ed45e9f 100644 --- a/Source/Core/Core/Config/WiimoteInputSettings.cpp +++ b/Source/Core/Core/Config/WiimoteInputSettings.cpp @@ -27,7 +27,4 @@ namespace Config const ConfigInfo NUNCHUK_INPUT_SHAKE_INTENSITY_HARD{ { System::WiiPad, "Nunchuk_Shake", "Hard" }, 5.0 }; const ConfigInfo NUNCHUK_INPUT_SHAKE_INTENSITY_MEDIUM{ { System::WiiPad, "Nunchuk_Shake", "Medium" }, 3.0 }; const ConfigInfo NUNCHUK_INPUT_SHAKE_INTENSITY_SOFT{ { System::WiiPad, "Nunchuk_Shake", "Soft" }, 2.0 }; - - // Other Settings - const ConfigInfo WIIMOTE_PROFILES{ {System::WiiPad, "InputProfiles", "List"}, "" }; } diff --git a/Source/Core/Core/Config/WiimoteInputSettings.h b/Source/Core/Core/Config/WiimoteInputSettings.h index e6db349c07..44ab85b37d 100644 --- a/Source/Core/Core/Config/WiimoteInputSettings.h +++ b/Source/Core/Core/Config/WiimoteInputSettings.h @@ -30,8 +30,4 @@ namespace Config extern const ConfigInfo NUNCHUK_INPUT_SHAKE_INTENSITY_MEDIUM; extern const ConfigInfo NUNCHUK_INPUT_SHAKE_INTENSITY_SOFT; - // Other settings - - extern const ConfigInfo WIIMOTE_PROFILES; - } // namespace Config diff --git a/Source/Core/Core/HotkeyManager.cpp b/Source/Core/Core/HotkeyManager.cpp index 6e844ce7ea..5905ea0ad1 100644 --- a/Source/Core/Core/HotkeyManager.cpp +++ b/Source/Core/Core/HotkeyManager.cpp @@ -20,7 +20,7 @@ #include "InputCommon/GCPadStatus.h" // clang-format off -constexpr std::array s_hotkey_labels{{ +constexpr std::array s_hotkey_labels{{ _trans("Open"), _trans("Change Disc"), _trans("Eject Disc"), @@ -69,10 +69,22 @@ constexpr std::array s_hotkey_labels{{ _trans("Connect Wii Remote 4"), _trans("Connect Balance Board"), - _trans("Next Wii Remote Profile"), - _trans("Previous Wii Remote Profile"), - _trans("Next Wii Remote Profile For Current Game"), - _trans("Previous Wii Remote Profile For Current Game"), + _trans("Next Profile for Wii Remote 1"), + _trans("Previous Profile for Wii Remote 1"), + _trans("Next Game Profile for Wii Remote 1"), + _trans("Previous Game Profile for Wii Remote 1"), + _trans("Next Profile for Wii Remote 2"), + _trans("Previous Profile for Wii Remote 2"), + _trans("Next Game Profile for Wii Remote 2"), + _trans("Previous Game Profile for Wii Remote 2"), + _trans("Next Profile for Wii Remote 3"), + _trans("Previous Profile for Wii Remote 3"), + _trans("Next Game Profile for Wii Remote 3"), + _trans("Previous Game Profile for Wii Remote 3"), + _trans("Next Profile for Wii Remote 4"), + _trans("Previous Profile for Wii Remote 4"), + _trans("Next Game Profile for Wii Remote 4"), + _trans("Previous Game Profile for Wii Remote 4"), _trans("Toggle Crop"), _trans("Toggle Aspect Ratio"), @@ -260,7 +272,7 @@ constexpr std::array s_groups_info = { {_trans("Program Counter"), HK_SHOW_PC, HK_SET_PC}, {_trans("Breakpoint"), HK_BP_TOGGLE, HK_MBP_ADD}, {_trans("Wii"), HK_TRIGGER_SYNC_BUTTON, HK_BALANCEBOARD_CONNECT}, - {_trans("Controller Profile"), HK_NEXT_WIIMOTE_PROFILE, HK_PREV_GAME_WIIMOTE_PROFILE}, + {_trans("Controller Profile"), HK_NEXT_WIIMOTE_PROFILE_1, HK_PREV_GAME_WIIMOTE_PROFILE_4}, {_trans("Graphics Toggles"), HK_TOGGLE_CROP, HK_TOGGLE_TEXTURES}, {_trans("Internal Resolution"), HK_INCREASE_IR, HK_DECREASE_IR}, {_trans("Freelook"), HK_FREELOOK_DECREASE_SPEED, HK_FREELOOK_RESET}, diff --git a/Source/Core/Core/HotkeyManager.h b/Source/Core/Core/HotkeyManager.h index fb67cfbc4c..7b72478a4d 100644 --- a/Source/Core/Core/HotkeyManager.h +++ b/Source/Core/Core/HotkeyManager.h @@ -67,10 +67,22 @@ enum Hotkey HK_WIIMOTE4_CONNECT, HK_BALANCEBOARD_CONNECT, - HK_NEXT_WIIMOTE_PROFILE, - HK_PREV_WIIMOTE_PROFILE, - HK_NEXT_GAME_WIIMOTE_PROFILE, - HK_PREV_GAME_WIIMOTE_PROFILE, + HK_NEXT_WIIMOTE_PROFILE_1, + HK_PREV_WIIMOTE_PROFILE_1, + HK_NEXT_GAME_WIIMOTE_PROFILE_1, + HK_PREV_GAME_WIIMOTE_PROFILE_1, + HK_NEXT_WIIMOTE_PROFILE_2, + HK_PREV_WIIMOTE_PROFILE_2, + HK_NEXT_GAME_WIIMOTE_PROFILE_2, + HK_PREV_GAME_WIIMOTE_PROFILE_2, + HK_NEXT_WIIMOTE_PROFILE_3, + HK_PREV_WIIMOTE_PROFILE_3, + HK_NEXT_GAME_WIIMOTE_PROFILE_3, + HK_PREV_GAME_WIIMOTE_PROFILE_3, + HK_NEXT_WIIMOTE_PROFILE_4, + HK_PREV_WIIMOTE_PROFILE_4, + HK_NEXT_GAME_WIIMOTE_PROFILE_4, + HK_PREV_GAME_WIIMOTE_PROFILE_4, HK_TOGGLE_CROP, HK_TOGGLE_AR, diff --git a/Source/Core/DolphinQt/HotkeyScheduler.cpp b/Source/Core/DolphinQt/HotkeyScheduler.cpp index 8a8c243abc..8def220bad 100644 --- a/Source/Core/DolphinQt/HotkeyScheduler.cpp +++ b/Source/Core/DolphinQt/HotkeyScheduler.cpp @@ -240,15 +240,45 @@ void HotkeyScheduler::Run() emit ConnectWiiRemote(wiimote_id); } - if (IsHotkey(HK_PREV_WIIMOTE_PROFILE)) - m_profile_cycler.PreviousWiimoteProfile(); - else if (IsHotkey(HK_NEXT_WIIMOTE_PROFILE)) - m_profile_cycler.NextWiimoteProfile(); + if (IsHotkey(HK_PREV_WIIMOTE_PROFILE_1)) + m_profile_cycler.PreviousWiimoteProfile(0); + else if (IsHotkey(HK_NEXT_WIIMOTE_PROFILE_1)) + m_profile_cycler.NextWiimoteProfile(0); - if (IsHotkey(HK_PREV_GAME_WIIMOTE_PROFILE)) - m_profile_cycler.PreviousWiimoteProfileForGame(); - else if (IsHotkey(HK_NEXT_GAME_WIIMOTE_PROFILE)) - m_profile_cycler.NextWiimoteProfileForGame(); + if (IsHotkey(HK_PREV_WIIMOTE_PROFILE_2)) + m_profile_cycler.PreviousWiimoteProfile(1); + else if (IsHotkey(HK_NEXT_WIIMOTE_PROFILE_2)) + m_profile_cycler.NextWiimoteProfile(1); + + if (IsHotkey(HK_PREV_WIIMOTE_PROFILE_3)) + m_profile_cycler.PreviousWiimoteProfile(2); + else if (IsHotkey(HK_NEXT_WIIMOTE_PROFILE_3)) + m_profile_cycler.NextWiimoteProfile(2); + + if (IsHotkey(HK_PREV_WIIMOTE_PROFILE_4)) + m_profile_cycler.PreviousWiimoteProfile(3); + else if (IsHotkey(HK_NEXT_WIIMOTE_PROFILE_4)) + m_profile_cycler.NextWiimoteProfile(3); + + if (IsHotkey(HK_PREV_GAME_WIIMOTE_PROFILE_1)) + m_profile_cycler.PreviousWiimoteProfileForGame(0); + else if (IsHotkey(HK_NEXT_GAME_WIIMOTE_PROFILE_1)) + m_profile_cycler.NextWiimoteProfileForGame(0); + + if (IsHotkey(HK_PREV_GAME_WIIMOTE_PROFILE_2)) + m_profile_cycler.PreviousWiimoteProfileForGame(1); + else if (IsHotkey(HK_NEXT_GAME_WIIMOTE_PROFILE_2)) + m_profile_cycler.NextWiimoteProfileForGame(1); + + if (IsHotkey(HK_PREV_GAME_WIIMOTE_PROFILE_3)) + m_profile_cycler.PreviousWiimoteProfileForGame(2); + else if (IsHotkey(HK_NEXT_GAME_WIIMOTE_PROFILE_3)) + m_profile_cycler.NextWiimoteProfileForGame(2); + + if (IsHotkey(HK_PREV_GAME_WIIMOTE_PROFILE_4)) + m_profile_cycler.PreviousWiimoteProfileForGame(3); + else if (IsHotkey(HK_NEXT_GAME_WIIMOTE_PROFILE_4)) + m_profile_cycler.NextWiimoteProfileForGame(3); const auto show_msg = [](OSDMessage message) { if (g_renderer) 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& controllers) + void ProfileCycler::UpdateToProfile(const std::string& profile_filename, ControllerEmu::EmulatedController* controller) { std::string base; SplitPath(profile_filename, nullptr, &base, nullptr); @@ -49,34 +50,16 @@ 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); + Core::DisplayMessage("Unable to load input profile '" + base + "' for device '" + controller->GetName() + "'", display_message_ms); } } - std::vector ProfileCycler::GetControllersForDevice(InputConfig* device_configuration) - { - const std::size_t size = device_configuration->GetControllerCount(); - - std::vector result(size); - - for (int i = 0; i < static_cast(size); i++) - { - result[i] = device_configuration->GetController(i); - } - - return result; - } - std::vector ProfileCycler::GetProfilesFromSetting(const std::string& setting, InputConfig* device_configuration) { const auto& profiles = SplitString(setting, ','); @@ -86,7 +69,7 @@ namespace InputProfile std::vector 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) { - CycleProfile(CycleDirection::Forward, Wiimote::GetConfig(), m_wiimote_profile_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::PreviousWiimoteProfile() + void ProfileCycler::NextWiimoteProfile(int controller_index) { - CycleProfile(CycleDirection::Backward, Wiimote::GetConfig(), m_wiimote_profile_index); + CycleProfile(CycleDirection::Forward, Wiimote::GetConfig(), m_wiimote_profile_index, + controller_index); } - void ProfileCycler::NextWiimoteProfileForGame() + void ProfileCycler::PreviousWiimoteProfile(int controller_index) + { + CycleProfile(CycleDirection::Backward, Wiimote::GetConfig(), m_wiimote_profile_index, + controller_index); + } + + 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 GetProfilesForDevice(InputConfig* device_configuration); std::vector GetProfilesFromSetting(const std::string& setting, InputConfig* device_configuration); std::string GetProfile(CycleDirection cycle_direction, int& profile_index, const std::vector& profiles); std::vector GetMatchingProfilesFromSetting(const std::string& setting, const std::vector& profiles, InputConfig* device_configuration); - void UpdateToProfile(const std::string& profile_filename, const std::vector& controllers); - std::vector 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; };