diff options
| author | iwubcode <iwubcode@users.noreply.github.com> | 2018-04-17 00:43:56 -0500 |
|---|---|---|
| committer | iwubcode <iwubcode@users.noreply.github.com> | 2018-07-07 12:39:08 -0500 |
| commit | 485285eadc71a8ca7055b9fc6b5da13c8b0251f4 (patch) | |
| tree | fe082f509266b15f6d09873b9cbd8907d693134d /Source/Core/InputCommon/InputProfile.cpp | |
| parent | 3969bf6d1c83acb7e3699bcd3c2715d5b85e2ea0 (diff) | |
Input: Add cycling between game specific profiles
Diffstat (limited to 'Source/Core/InputCommon/InputProfile.cpp')
| -rw-r--r-- | Source/Core/InputCommon/InputProfile.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
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 <algorithm> +#include <iterator> + namespace InputProfile { @@ -73,6 +77,35 @@ namespace InputProfile return result; } + std::vector<std::string> 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<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 result; + } + + std::vector<std::string> ProfileCycler::GetMatchingProfilesFromSetting(const std::string& setting, const std::vector<std::string>& profiles, InputConfig* device_configuration) + { + const auto& profiles_from_setting = GetProfilesFromSetting(setting, device_configuration); + if (profiles_from_setting.empty()) + { + return {}; + } + + std::vector<std::string> 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)); + } } |
