Merge pull request #506 from ggrtk/analog-controller

Update input profiles and input profile handling
This commit is contained in:
Connor McLaughlin 2020-05-28 13:06:40 +10:00 committed by GitHub
commit 13c3426148
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 34 deletions

View file

@ -1,22 +1,24 @@
[Controller1]
Type=AnalogController
ButtonUp=Controller0/Button11
ButtonDown=Controller0/Button12
ButtonLeft=Controller0/Button13
ButtonRight=Controller0/Button14
ButtonSelect=Controller0/Button4
ButtonStart=Controller0/Button6
ButtonTriangle=Controller0/Button3
ButtonCross=Controller0/Button0
ButtonCircle=Controller0/Button1
ButtonSquare=Controller0/Button2
ButtonL1=Controller0/Button9
ButtonL2=Controller0/+Axis4
ButtonR1=Controller0/Button10
ButtonR2=Controller0/+Axis5
ButtonL3=Controller0/Button7
ButtonR3=Controller0/Button8
AxisLeftX=Controller0/Axis0
AxisLeftY=Controller0/Axis1
AxisRightX=Controller0/Axis2
AxisRightY=Controller0/Axis3
Type = AnalogController
ButtonUp = Controller0/Button11
ButtonDown = Controller0/Button12
ButtonLeft = Controller0/Button13
ButtonRight = Controller0/Button14
ButtonSelect = Controller0/Button4
ButtonStart = Controller0/Button6
ButtonTriangle = Controller0/Button3
ButtonCross = Controller0/Button0
ButtonCircle = Controller0/Button1
ButtonSquare = Controller0/Button2
ButtonL1 = Controller0/Button9
ButtonL2 = Controller0/+Axis4
ButtonR1 = Controller0/Button10
ButtonR2 = Controller0/+Axis5
ButtonL3 = Controller0/Button7
ButtonR3 = Controller0/Button8
ButtonAnalog = Controller0/Button5
AxisLeftX = Controller0/Axis0
AxisLeftY = Controller0/Axis1
AxisRightX = Controller0/Axis2
AxisRightY = Controller0/Axis3
Rumble = Controller0

View file

@ -0,0 +1,16 @@
[Controller1]
Type = DigitalController
ButtonUp = Controller0/-Axis1
ButtonDown = Controller0/+Axis1
ButtonLeft = Controller0/-Axis0
ButtonRight = Controller0/+Axis0
ButtonSelect = Controller0/Button4
ButtonStart = Controller0/Button6
ButtonTriangle = Controller0/Button3
ButtonCross = Controller0/Button0
ButtonCircle = Controller0/Button1
ButtonSquare = Controller0/Button2
ButtonL1 = Controller0/Button9
ButtonL2 = Controller0/+Axis4
ButtonR1 = Controller0/Button10
ButtonR2 = Controller0/+Axis5

View file

@ -67,7 +67,7 @@ std::optional<s32> AnalogController::GetButtonCodeByName(std::string_view button
void AnalogController::SetAxisState(s32 axis_code, float value)
{
if (axis_code < 0 || axis_code >= static_cast<s32>(Button::Count))
if (axis_code < 0 || axis_code >= static_cast<s32>(Axis::Count))
return;
// -1..1 -> 0..255

View file

@ -1068,15 +1068,12 @@ void CommonHostInterface::ApplyInputProfile(const char* profile_path, SettingsIn
bool CommonHostInterface::SaveInputProfile(const char* profile_path, SettingsInterface& si)
{
if (FileSystem::FileExists(profile_path))
{
if (!FileSystem::DeleteFile(profile_path))
{
Log_ErrorPrintf("Failed to delete existing input profile '%s' when saving", profile_path);
return false;
}
}
Log_WarningPrintf("Existing input profile at '%s' will be overwritten", profile_path);
else
Log_WarningPrintf("Input profile at '%s' does not exist, new input profile will be created", profile_path);
INISettingsInterface profile(profile_path);
profile.Clear();
for (u32 controller_index = 1; controller_index <= NUM_CONTROLLER_AND_CARD_PORTS; controller_index++)
{
@ -1109,7 +1106,13 @@ bool CommonHostInterface::SaveInputProfile(const char* profile_path, SettingsInt
profile.SetStringValue(section_name, "Rumble", rumble_value.c_str());
}
profile.Save();
if(!profile.Save())
{
Log_ErrorPrintf("Failed to save input profile to '%s'", profile_path);
return false;
}
Log_SuccessPrintf("Input profile saved to '%s'", profile_path);
return true;
}

View file

@ -16,13 +16,17 @@ INISettingsInterface::~INISettingsInterface()
Save();
}
void INISettingsInterface::Save()
bool INISettingsInterface::Save()
{
SI_Error err = m_ini.SaveFile(m_filename.c_str(), false);
if (err != SI_OK)
{
Log_WarningPrintf("Failed to save settings to '%s'.", m_filename.c_str());
else
m_dirty = false;
return false;
}
m_dirty = false;
return true;
}
void INISettingsInterface::Clear()

View file

@ -9,7 +9,7 @@ public:
INISettingsInterface(std::string filename);
~INISettingsInterface();
void Save();
bool Save();
void Clear() override;