Input: Allow cycling to occur for each individual controller

This commit is contained in:
iwubcode 2018-04-22 16:27:10 -05:00
parent 485285eadc
commit 14482a72af
8 changed files with 131 additions and 72 deletions

View file

@ -27,7 +27,4 @@ namespace Config
const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_HARD{ { System::WiiPad, "Nunchuk_Shake", "Hard" }, 5.0 };
const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_MEDIUM{ { System::WiiPad, "Nunchuk_Shake", "Medium" }, 3.0 };
const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_SOFT{ { System::WiiPad, "Nunchuk_Shake", "Soft" }, 2.0 };
// Other Settings
const ConfigInfo<std::string> WIIMOTE_PROFILES{ {System::WiiPad, "InputProfiles", "List"}, "" };
}

View file

@ -30,8 +30,4 @@ namespace Config
extern const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_MEDIUM;
extern const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_SOFT;
// Other settings
extern const ConfigInfo<std::string> WIIMOTE_PROFILES;
} // namespace Config

View file

@ -20,7 +20,7 @@
#include "InputCommon/GCPadStatus.h"
// clang-format off
constexpr std::array<const char*, 114> s_hotkey_labels{{
constexpr std::array<const char*, 130> s_hotkey_labels{{
_trans("Open"),
_trans("Change Disc"),
_trans("Eject Disc"),
@ -69,10 +69,22 @@ constexpr std::array<const char*, 114> 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<HotkeyGroupInfo, NUM_HOTKEY_GROUPS> 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},

View file

@ -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,

View file

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

View file

@ -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

View file

@ -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,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<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);
}
return result;
}
std::vector<std::string> ProfileCycler::GetProfilesFromSetting(const std::string& setting, InputConfig* device_configuration)
{
const auto& profiles = SplitString(setting, ',');
@ -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)
{
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);
}
}

View file

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