Input: Add cycling between game specific profiles

This commit is contained in:
iwubcode 2018-04-17 00:43:56 -05:00
parent 3969bf6d1c
commit 485285eadc
7 changed files with 107 additions and 3 deletions

View file

@ -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));
}
}