From 4fcc8abf5553bb8aef86eedecad63bb21d130a07 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 27 Jun 2022 22:37:22 +1000 Subject: [PATCH] Qt: Add pressure modifier button for pads --- .../ControllerBindingWidget_DualShock2.ui | 1196 +++++++++-------- .../Settings/ControllerBindingWidgets.cpp | 6 +- pcsx2/PAD/Host/Global.h | 1 + pcsx2/PAD/Host/KeyStatus.cpp | 7 +- pcsx2/PAD/Host/KeyStatus.h | 3 + pcsx2/PAD/Host/PAD.cpp | 5 + pcsx2/PAD/Host/PAD.h | 1 + 7 files changed, 646 insertions(+), 573 deletions(-) diff --git a/pcsx2-qt/Settings/ControllerBindingWidget_DualShock2.ui b/pcsx2-qt/Settings/ControllerBindingWidget_DualShock2.ui index 607f7516d9..030e17d480 100644 --- a/pcsx2-qt/Settings/ControllerBindingWidget_DualShock2.ui +++ b/pcsx2-qt/Settings/ControllerBindingWidget_DualShock2.ui @@ -25,7 +25,7 @@ Form - + 0 @@ -38,7 +38,7 @@ 0 - + @@ -378,6 +378,65 @@ + + + + Large Motor + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 0 + + + + + 16777215 + 16777215 + + + + PushButton + + + + + + + + 80 + 0 + + + + x + + + 3.000000000000000 + + + 0.100000000000000 + + + + + + @@ -393,551 +452,271 @@ - - - - - - - - L1 - - - - 6 + + + + + + L2 + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 16777215 + - - 6 + + PushButton - - 6 - - - 6 - - - - - - 100 - 16777215 - - - - PushButton - - - - - - - - - - L2 - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 100 - 16777215 - - - - PushButton - - - - - - - - - - R1 - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 100 - 16777215 - - - - PushButton - - - - - - - - - - R2 - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 100 - 16777215 - - - - PushButton - - - - - - - - - - Start - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 100 - 16777215 - - - - PushButton - - - - - - - - - - Select - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 100 - 16777215 - - - - PushButton - - - - - - - - - - Analog - - - - - - - 100 - 16777215 - - - - PushButton - - - - - - - - - - Analog Sensitivity - - - - - - 200 - - - Qt::Horizontal - - - - - - - 100% - - - - - - - - - - Analog Deadzone - - - - - - 100 - - - Qt::Horizontal - - - - - - - 0% - - - - - - - + + + + - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 400 - 266 - - - - - - - :/images/dualshock-2.png - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + + Select + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 16777215 + + + + PushButton + + + + + - - - - - - Large Motor - - - - 6 + + + + Start + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 16777215 + - - 6 + + PushButton - - 6 + + + + + + + + + R2 + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 16777215 + - - 6 + + PushButton - - - - x - - - 3.000000000000000 - - - 0.100000000000000 - - - - - - - - 100 - 0 - - - - - 100 - 16777215 - - - - PushButton - - - - - - - - - - Small Motor - - - - 6 + + + + + + + + + L1 + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 16777215 + - - 6 + + PushButton - - 6 + + + + + + + + + Pressure Modifier + + + + + + + 80 + 0 + - - 6 + + x - - - - - 100 - 0 - - - - - 100 - 16777215 - - - - PushButton - - - - - - - x - - - 3.000000000000000 - - - 0.100000000000000 - - - - - - - - - - R3 - - - - 6 + + 1.000000000000000 - - 6 + + 0.010000000000000 - - 6 + + 0.500000000000000 - - 6 + + + + + + + 0 + 0 + - - - - - 100 - 0 - - - - - 100 - 16777215 - - - - PushButton - - - - - - - - - - L3 - - - - 6 + + + 100 + 0 + - - 6 + + + 16777215 + 16777215 + - - 6 + + PushButton - - 6 + + + + + + + + + R1 + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 16777215 + - - - - - 100 - 0 - - - - - 100 - 16777215 - - - - PushButton - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - + + PushButton + + + + + - + @@ -1114,46 +893,6 @@ Right Analog - - - - Down - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 100 - 0 - - - - - 100 - 16777215 - - - - PushButton - - - - - - @@ -1194,12 +933,12 @@ - - + + - Up + Down - + 6 @@ -1213,7 +952,7 @@ 6 - + 100 @@ -1274,6 +1013,99 @@ + + + + Up + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + + + + Small Motor + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 0 + + + + + 16777215 + 16777215 + + + + PushButton + + + + + + + x + + + 3.000000000000000 + + + 0.100000000000000 + + + @@ -1292,6 +1124,232 @@ + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 400 + 266 + + + + + + + :/images/dualshock-2.png + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + L3 + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 150 + 0 + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + R3 + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 150 + 0 + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + Analog Sensitivity + + + + + + 200 + + + Qt::Horizontal + + + + + + + 100% + + + + + + + + + + Analog Deadzone + + + + + + 100 + + + Qt::Horizontal + + + + + + + 0% + + + + + + + + + + Analog + + + + + + + 150 + 16777215 + + + + PushButton + + + + + + + + diff --git a/pcsx2-qt/Settings/ControllerBindingWidgets.cpp b/pcsx2-qt/Settings/ControllerBindingWidgets.cpp index 15a88c04b0..2df94d01db 100644 --- a/pcsx2-qt/Settings/ControllerBindingWidgets.cpp +++ b/pcsx2-qt/Settings/ControllerBindingWidgets.cpp @@ -270,9 +270,11 @@ void ControllerBindingWidget_Base::initBindingWidgets() } if (QDoubleSpinBox* widget = findChild(QStringLiteral("SmallMotorScale")); widget) - ControllerSettingWidgetBinder::BindWidgetToInputProfileFloat(sif, widget, config_section, "SmallMotorScale", 1.0f); + ControllerSettingWidgetBinder::BindWidgetToInputProfileFloat(sif, widget, config_section, "SmallMotorScale", PAD::DEFAULT_MOTOR_SCALE); if (QDoubleSpinBox* widget = findChild(QStringLiteral("LargeMotorScale")); widget) - ControllerSettingWidgetBinder::BindWidgetToInputProfileFloat(sif, widget, config_section, "LargeMotorScale", 1.0f); + ControllerSettingWidgetBinder::BindWidgetToInputProfileFloat(sif, widget, config_section, "LargeMotorScale", PAD::DEFAULT_MOTOR_SCALE); + if (QDoubleSpinBox* widget = findChild(QStringLiteral("PressureModifier")); widget) + ControllerSettingWidgetBinder::BindWidgetToInputProfileFloat(sif, widget, config_section, "PressureModifier", PAD::DEFAULT_PRESSURE_MODIFIER); } ControllerBindingWidget_DualShock2::ControllerBindingWidget_DualShock2(ControllerBindingWidget* parent) diff --git a/pcsx2/PAD/Host/Global.h b/pcsx2/PAD/Host/Global.h index 6b4518c12b..63ebcf0813 100644 --- a/pcsx2/PAD/Host/Global.h +++ b/pcsx2/PAD/Host/Global.h @@ -38,6 +38,7 @@ enum gamePadValues PAD_L3, // Left joystick button (L3) PAD_R3, // Right joystick button (R3) PAD_ANALOG, // Analog mode toggle + PAD_PRESSURE, // Pressure modifier PAD_L_UP, // Left joystick (Up) ↑ PAD_L_RIGHT, // Left joystick (Right) → PAD_L_DOWN, // Left joystick (Down) ↓ diff --git a/pcsx2/PAD/Host/KeyStatus.cpp b/pcsx2/PAD/Host/KeyStatus.cpp index ec8536be2b..b544f0c38b 100644 --- a/pcsx2/PAD/Host/KeyStatus.cpp +++ b/pcsx2/PAD/Host/KeyStatus.cpp @@ -30,6 +30,7 @@ KeyStatus::KeyStatus() { m_axis_scale[pad][0] = 0.0f; m_axis_scale[pad][1] = 1.0f; + m_pressure_modifier[pad] = 0.5f; } } @@ -95,7 +96,8 @@ void KeyStatus::Set(u32 pad, u32 index, float value) } else { - m_button_pressure[pad][index] = static_cast(std::clamp(value * 255.0f, 0.0f, 255.0f)); + const float pmod = ((m_button[pad] & (1u << PAD_PRESSURE)) == 0) ? m_pressure_modifier[pad] : 1.0f; + m_button_pressure[pad][index] = static_cast(std::clamp(value * pmod * 255.0f, 0.0f, 255.0f)); // Since we reordered the buttons for better UI, we need to remap them here. static constexpr std::array bitmask_mapping = {{ @@ -115,7 +117,8 @@ void KeyStatus::Set(u32 pad, u32 index, float value) 1, // PAD_R2 9, // PAD_L3 10, // PAD_R3 - 16, // Analog + 16, // PAD_ANALOG + 17, // PAD_PRESSURE // remainder are analogs and not used here }}; diff --git a/pcsx2/PAD/Host/KeyStatus.h b/pcsx2/PAD/Host/KeyStatus.h index ca25a82c82..3be985dffe 100644 --- a/pcsx2/PAD/Host/KeyStatus.h +++ b/pcsx2/PAD/Host/KeyStatus.h @@ -38,6 +38,7 @@ namespace PAD PADAnalog m_analog[NUM_CONTROLLER_PORTS]; float m_axis_scale[NUM_CONTROLLER_PORTS][2]; float m_vibration_scale[NUM_CONTROLLER_PORTS][2]; + float m_pressure_modifier[NUM_CONTROLLER_PORTS]; public: KeyStatus(); @@ -55,6 +56,8 @@ namespace PAD } __fi float GetVibrationScale(u32 pad, u32 motor) const { return m_vibration_scale[pad][motor]; } __fi void SetVibrationScale(u32 pad, u32 motor, float scale) { m_vibration_scale[pad][motor] = scale; } + __fi float GetPressureModifier(u32 pad) const { return m_pressure_modifier[pad]; } + __fi void SetPressureModifier(u32 pad, float mod) { m_pressure_modifier[pad] = mod; } u32 GetButtons(u32 pad); u8 GetPressure(u32 pad, u32 index); diff --git a/pcsx2/PAD/Host/PAD.cpp b/pcsx2/PAD/Host/PAD.cpp index 747bb254a8..bd07d4b0c7 100644 --- a/pcsx2/PAD/Host/PAD.cpp +++ b/pcsx2/PAD/Host/PAD.cpp @@ -222,6 +222,9 @@ void PAD::LoadConfig(const SettingsInterface& si) g_key_status.SetVibrationScale(i, 1, small_motor_scale); } + const float pressure_modifier = si.GetFloatValue(section.c_str(), "PressureModifier", 1.0f); + g_key_status.SetPressureModifier(i, pressure_modifier); + LoadMacroButtonConfig(si, i, type, section); } } @@ -259,6 +262,7 @@ void PAD::SetDefaultConfig(SettingsInterface& si) si.SetFloatValue(section.c_str(), "AxisScale", DEFAULT_STICK_SCALE); si.SetFloatValue(section.c_str(), "LargeMotorScale", DEFAULT_MOTOR_SCALE); si.SetFloatValue(section.c_str(), "SmallMotorScale", DEFAULT_MOTOR_SCALE); + si.SetFloatValue(section.c_str(), "PressureModifier", DEFAULT_PRESSURE_MODIFIER); } // PCSX2 Controller Settings - Controller 1 / Controller 2 / ... @@ -333,6 +337,7 @@ static const PAD::ControllerBindingInfo s_dualshock2_binds[] = { {"L3", "L3 (Left Stick Button)", PAD::ControllerBindingType::Button, GenericInputBinding::L3}, {"R3", "R3 (Right Stick Button)", PAD::ControllerBindingType::Button, GenericInputBinding::R3}, {"Analog", "Analog Toggle", PAD::ControllerBindingType::Button, GenericInputBinding::System}, + {"Pressure", "Apply Pressure", PAD::ControllerBindingType::Button, GenericInputBinding::Unknown}, {"LUp", "Left Stick Up", PAD::ControllerBindingType::HalfAxis, GenericInputBinding::LeftStickUp}, {"LRight", "Left Stick Right", PAD::ControllerBindingType::HalfAxis, GenericInputBinding::LeftStickRight}, {"LDown", "Left Stick Down", PAD::ControllerBindingType::HalfAxis, GenericInputBinding::LeftStickDown}, diff --git a/pcsx2/PAD/Host/PAD.h b/pcsx2/PAD/Host/PAD.h index 29256ee5c1..88b22e0d09 100644 --- a/pcsx2/PAD/Host/PAD.h +++ b/pcsx2/PAD/Host/PAD.h @@ -91,6 +91,7 @@ namespace PAD static constexpr float DEFAULT_STICK_DEADZONE = 0.0f; static constexpr float DEFAULT_STICK_SCALE = 1.33f; static constexpr float DEFAULT_MOTOR_SCALE = 1.0f; + static constexpr float DEFAULT_PRESSURE_MODIFIER = 0.5f; /// Returns the default type for the specified port. const char* GetDefaultPadType(u32 pad);