diff --git a/Source/Core/Core/Config/WiimoteInputSettings.cpp b/Source/Core/Core/Config/WiimoteInputSettings.cpp index a60ed45e9f..3dac7e5851 100644 --- a/Source/Core/Core/Config/WiimoteInputSettings.cpp +++ b/Source/Core/Core/Config/WiimoteInputSettings.cpp @@ -27,4 +27,7 @@ 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 44ab85b37d..e6db349c07 100644 --- a/Source/Core/Core/Config/WiimoteInputSettings.h +++ b/Source/Core/Core/Config/WiimoteInputSettings.h @@ -30,4 +30,8 @@ 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 113f4db737..6e844ce7ea 100644 --- a/Source/Core/Core/HotkeyManager.cpp +++ b/Source/Core/Core/HotkeyManager.cpp @@ -69,8 +69,10 @@ 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"), + _trans("Previous Wii Remote Profile"), + _trans("Next Wii Remote Profile For Current Game"), + _trans("Previous Wii Remote Profile For Current Game"), _trans("Toggle Crop"), _trans("Toggle Aspect Ratio"), @@ -258,7 +260,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_WIIMOTE_PROFILE}, + {_trans("Controller Profile"), HK_NEXT_WIIMOTE_PROFILE, HK_PREV_GAME_WIIMOTE_PROFILE}, {_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 8b639f59fd..fb67cfbc4c 100644 --- a/Source/Core/Core/HotkeyManager.h +++ b/Source/Core/Core/HotkeyManager.h @@ -69,6 +69,8 @@ enum Hotkey HK_NEXT_WIIMOTE_PROFILE, HK_PREV_WIIMOTE_PROFILE, + HK_NEXT_GAME_WIIMOTE_PROFILE, + HK_PREV_GAME_WIIMOTE_PROFILE, HK_TOGGLE_CROP, HK_TOGGLE_AR, diff --git a/Source/Core/DolphinQt/HotkeyScheduler.cpp b/Source/Core/DolphinQt/HotkeyScheduler.cpp index 6f29aa8431..8a8c243abc 100644 --- a/Source/Core/DolphinQt/HotkeyScheduler.cpp +++ b/Source/Core/DolphinQt/HotkeyScheduler.cpp @@ -245,6 +245,11 @@ void HotkeyScheduler::Run() else if (IsHotkey(HK_NEXT_WIIMOTE_PROFILE)) m_profile_cycler.NextWiimoteProfile(); + if (IsHotkey(HK_PREV_GAME_WIIMOTE_PROFILE)) + m_profile_cycler.PreviousWiimoteProfileForGame(); + else if (IsHotkey(HK_NEXT_GAME_WIIMOTE_PROFILE)) + m_profile_cycler.NextWiimoteProfileForGame(); + const auto show_msg = [](OSDMessage message) { if (g_renderer) g_renderer->ShowOSDMessage(message); diff --git a/Source/Core/InputCommon/InputProfile.cpp b/Source/Core/InputCommon/InputProfile.cpp index 87d8c5bcab..07fa1f7795 100644 --- a/Source/Core/InputCommon/InputProfile.cpp +++ b/Source/Core/InputCommon/InputProfile.cpp @@ -5,6 +5,7 @@ #include "Common/FileSearch.h" #include "Common/FileUtil.h" +#include "Core/Config/WiimoteInputSettings.h" #include "Core/Core.h" #include "Core/HW/Wiimote.h" #include "Core/HotkeyManager.h" @@ -13,6 +14,9 @@ #include "InputCommon/InputConfig.h" #include "InputCommon/InputProfile.h" +#include +#include + namespace InputProfile { @@ -73,6 +77,35 @@ namespace InputProfile return result; } + std::vector ProfileCycler::GetProfilesFromSetting(const std::string& setting, InputConfig* device_configuration) + { + const auto& profiles = SplitString(setting, ','); + + const std::string device_profile_root_location(File::GetUserPath(D_CONFIG_IDX) + "Profiles/" + device_configuration->GetProfileName()); + + 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 result; + } + + std::vector ProfileCycler::GetMatchingProfilesFromSetting(const std::string& setting, const std::vector& profiles, InputConfig* device_configuration) + { + const auto& profiles_from_setting = GetProfilesFromSetting(setting, device_configuration); + if (profiles_from_setting.empty()) + { + return {}; + } + + std::vector result; + std::set_intersection(profiles.begin(), profiles.end(), profiles_from_setting.begin(), + profiles_from_setting.end(), std::back_inserter(result)); + return result; + } + void ProfileCycler::CycleProfile(CycleDirection cycle_direction, InputConfig* device_configuration, int& profile_index) { @@ -88,6 +121,44 @@ namespace InputProfile UpdateToProfile(profile, controllers); } + void ProfileCycler::CycleProfileForGame(CycleDirection cycle_direction, + InputConfig* device_configuration, int& profile_index, + const std::string& setting) + { + const auto& profiles = GetProfilesForDevice(device_configuration); + if (profiles.empty()) + { + Core::DisplayMessage("No input profiles found", display_message_ms); + return; + } + + if (setting.empty()) + { + Core::DisplayMessage("No setting found for game", display_message_ms); + return; + } + + const auto& profiles_for_game = GetMatchingProfilesFromSetting(setting, profiles, + device_configuration); + if (profiles_for_game.empty()) + { + Core::DisplayMessage("No input profiles found for game", display_message_ms); + return; + } + + const std::string profile = GetProfile(cycle_direction, profile_index, profiles_for_game); + + 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::NextWiimoteProfile() { CycleProfile(CycleDirection::Forward, Wiimote::GetConfig(), m_wiimote_profile_index); @@ -97,4 +168,16 @@ namespace InputProfile { CycleProfile(CycleDirection::Backward, Wiimote::GetConfig(), m_wiimote_profile_index); } + + void ProfileCycler::NextWiimoteProfileForGame() + { + CycleProfileForGame(CycleDirection::Forward, Wiimote::GetConfig(), m_wiimote_profile_index, + Config::Get(Config::WIIMOTE_PROFILES)); + } + + void ProfileCycler::PreviousWiimoteProfileForGame() + { + CycleProfileForGame(CycleDirection::Backward, Wiimote::GetConfig(), m_wiimote_profile_index, + Config::Get(Config::WIIMOTE_PROFILES)); + } } diff --git a/Source/Core/InputCommon/InputProfile.h b/Source/Core/InputCommon/InputProfile.h index 09b617c398..ec0344b23f 100644 --- a/Source/Core/InputCommon/InputProfile.h +++ b/Source/Core/InputCommon/InputProfile.h @@ -27,10 +27,15 @@ namespace InputProfile public: void NextWiimoteProfile(); void PreviousWiimoteProfile(); + void NextWiimoteProfileForGame(); + void PreviousWiimoteProfileForGame(); 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); 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);