Qt: Add pressure modifier button for pads

This commit is contained in:
Connor McLaughlin 2022-06-27 22:37:22 +10:00 committed by lightningterror
parent 131b92e9fe
commit 4fcc8abf55
7 changed files with 646 additions and 573 deletions

File diff suppressed because it is too large Load Diff

View File

@ -270,9 +270,11 @@ void ControllerBindingWidget_Base::initBindingWidgets()
}
if (QDoubleSpinBox* widget = findChild<QDoubleSpinBox*>(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<QDoubleSpinBox*>(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<QDoubleSpinBox*>(QStringLiteral("PressureModifier")); widget)
ControllerSettingWidgetBinder::BindWidgetToInputProfileFloat(sif, widget, config_section, "PressureModifier", PAD::DEFAULT_PRESSURE_MODIFIER);
}
ControllerBindingWidget_DualShock2::ControllerBindingWidget_DualShock2(ControllerBindingWidget* parent)

View File

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

View File

@ -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<u8>(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<u8>(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<u8, MAX_KEYS> 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
}};

View File

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

View File

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

View File

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