From c1bf1e5369d2e9f83b8401e52f3bf15d6c615566 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 16 Apr 2024 14:53:52 +1000 Subject: [PATCH] Qt: Add binding layout for NegConRumble --- src/core/negcon_rumble.cpp | 56 +- src/core/negcon_rumble.h | 4 +- src/duckstation-qt/CMakeLists.txt | 1 + .../controllerbindingwidget_negconrumble.ui | 738 ++++++++++++++++++ .../controllerbindingwidgets.cpp | 10 + src/duckstation-qt/duckstation-qt.vcxproj | 3 + .../duckstation-qt.vcxproj.filters | 1 + 7 files changed, 783 insertions(+), 30 deletions(-) create mode 100644 src/duckstation-qt/controllerbindingwidget_negconrumble.ui diff --git a/src/core/negcon_rumble.cpp b/src/core/negcon_rumble.cpp index a11a7ce8a..b8dfeb944 100644 --- a/src/core/negcon_rumble.cpp +++ b/src/core/negcon_rumble.cpp @@ -24,10 +24,9 @@ Log_SetChannel(NeGconRumble); - // Mapping of Button to index of corresponding bit in m_button_state static constexpr std::array(NeGconRumble::Button::Count)> s_button_indices = {3, 4, 5, 6, - 7, 11, 12, 13}; + 7, 11, 12, 13}; NeGconRumble::NeGconRumble(u32 index) : Controller(index) { m_status_byte = 0x5A; @@ -120,12 +119,12 @@ bool NeGconRumble::DoState(StateWrapper& sw, bool apply_input_state) if (old_analog_mode != m_analog_mode) { - Host::AddIconOSDMessage(fmt::format("Controller{}AnalogMode", m_index), ICON_FA_GAMEPAD, - fmt::format(m_analog_mode ? - TRANSLATE_FS("AnalogController", "Controller {} switched to analog mode.") : - TRANSLATE_FS("AnalogController", "Controller {} switched to digital mode."), - m_index + 1u), - 5.0f); + Host::AddIconOSDMessage(fmt::format("Controller{}AnalogMode", m_index), ICON_FA_GAMEPAD, + fmt::format(m_analog_mode ? + TRANSLATE_FS("AnalogController", "Controller {} switched to analog mode.") : + TRANSLATE_FS("AnalogController", "Controller {} switched to digital mode."), + m_index + 1u), + 5.0f); } } return true; @@ -168,7 +167,7 @@ void NeGconRumble::SetBindState(u32 index, float value) } // Steering Axis: -1..1 -> 0..255 else if (index == (static_cast(Button::Count) + static_cast(HalfAxis::SteeringLeft)) || - index == (static_cast(Button::Count) + static_cast(HalfAxis::SteeringRight))) + index == (static_cast(Button::Count) + static_cast(HalfAxis::SteeringRight))) { value *= m_steering_sensitivity; if (value < m_steering_deadzone) @@ -247,8 +246,8 @@ void NeGconRumble::SetAnalogMode(bool enabled, bool show_message) fmt::format(enabled ? TRANSLATE_FS("AnalogController", "Controller {} switched to analog mode.") : TRANSLATE_FS("AnalogController", "Controller {} switched to digital mode."), - m_index + 1u), - 5.0f); + m_index + 1u), + 5.0f); } m_analog_mode = enabled; } @@ -347,7 +346,6 @@ u8 NeGconRumble::GetModeID() const u8 NeGconRumble::GetIDByte() const { - auto tteste = GetResponseNumHalfwords(); return Truncate8((GetModeID() << 4) | GetResponseNumHalfwords()); } @@ -482,7 +480,7 @@ bool NeGconRumble::Transfer(const u8 data_in, u8* data_out) case 4: { if (m_configuration_mode || m_analog_mode) - m_tx_buffer[m_command_step] = m_axis_state[static_cast(Axis::Steering)]; + m_tx_buffer[m_command_step] = m_axis_state[static_cast(Axis::Steering)]; if (m_dualshock_enabled) SetMotorStateForConfigIndex(rumble_index, data_in); @@ -502,7 +500,7 @@ bool NeGconRumble::Transfer(const u8 data_in, u8* data_out) case 6: { if (m_configuration_mode || m_analog_mode) - m_tx_buffer[m_command_step] = m_axis_state[static_cast(Axis::II)]; + m_tx_buffer[m_command_step] = m_axis_state[static_cast(Axis::II)]; if (m_dualshock_enabled) SetMotorStateForConfigIndex(rumble_index, data_in); @@ -512,7 +510,7 @@ bool NeGconRumble::Transfer(const u8 data_in, u8* data_out) case 7: { if (m_configuration_mode || m_analog_mode) - m_tx_buffer[m_command_step] = m_axis_state[static_cast(Axis::L)]; + m_tx_buffer[m_command_step] = m_axis_state[static_cast(Axis::L)]; if (m_dualshock_enabled) SetMotorStateForConfigIndex(rumble_index, data_in); @@ -548,7 +546,7 @@ bool NeGconRumble::Transfer(const u8 data_in, u8* data_out) case 4: { if (m_configuration_mode || m_analog_mode) - m_tx_buffer[m_command_step] = m_axis_state[static_cast(Axis::Steering)]; + m_tx_buffer[m_command_step] = m_axis_state[static_cast(Axis::Steering)]; } break; @@ -562,14 +560,14 @@ bool NeGconRumble::Transfer(const u8 data_in, u8* data_out) case 6: { if (m_configuration_mode || m_analog_mode) - m_tx_buffer[m_command_step] = m_axis_state[static_cast(Axis::II)]; + m_tx_buffer[m_command_step] = m_axis_state[static_cast(Axis::II)]; } break; case 7: { if (m_configuration_mode || m_analog_mode) - m_tx_buffer[m_command_step] = m_axis_state[static_cast(Axis::L)]; + m_tx_buffer[m_command_step] = m_axis_state[static_cast(Axis::L)]; } break; @@ -692,7 +690,6 @@ bool NeGconRumble::Transfer(const u8 data_in, u8* data_out) break; DefaultCaseIsUnreachable(); - } *data_out = m_tx_buffer[m_command_step]; @@ -714,7 +711,6 @@ bool NeGconRumble::Transfer(const u8 data_in, u8* data_out) } return ack; - } std::unique_ptr NeGconRumble::Create(u32 index) @@ -729,7 +725,7 @@ static const Controller::ControllerBindingInfo s_binding_info[] = { } #define AXIS(name, display_name, icon_name, halfaxis, genb) \ { \ - name, display_name, icon_name, static_cast(NeGconRumble::Button::Count) + static_cast(halfaxis), \ + name, display_name, icon_name, static_cast(NeGconRumble::Button::Count) + static_cast(halfaxis), \ InputBindingInfo::Type::HalfAxis, genb \ } @@ -756,16 +752,20 @@ static const Controller::ControllerBindingInfo s_binding_info[] = { static const SettingInfo s_settings[] = { {SettingInfo::Type::Float, "SteeringDeadzone", TRANSLATE_NOOP("NeGconRumble", "Steering Axis Deadzone"), - TRANSLATE_NOOP("NeGconRumble", "Sets deadzone size for steering axis."), "0.00f", "0.00f", "0.99f", "0.01f", "%.0f%%", nullptr, - 100.0f}, + TRANSLATE_NOOP("NeGconRumble", "Sets deadzone size for steering axis."), "0.00f", "0.00f", "0.99f", "0.01f", + "%.0f%%", nullptr, 100.0f}, {SettingInfo::Type::Float, "SteeringSensitivity", TRANSLATE_NOOP("NeGconRumble", "Steering Axis Sensitivity"), - TRANSLATE_NOOP("NeGconRumble", "Sets the steering axis scaling factor."), "1.00f", "0.01f", "2.00f", "0.01f", "%.0f%%", - nullptr, 100.0f}, + TRANSLATE_NOOP("NeGconRumble", "Sets the steering axis scaling factor."), "1.00f", "0.01f", "2.00f", "0.01f", + "%.0f%%", nullptr, 100.0f}, }; -const Controller::ControllerInfo NeGconRumble::INFO = { - ControllerType::NeGconRumble, "NeGconRumble", TRANSLATE_NOOP("ControllerType", "NeGconRumble"), ICON_PF_GAMEPAD, - s_binding_info, s_settings, Controller::VibrationCapabilities::LargeSmallMotors}; +const Controller::ControllerInfo NeGconRumble::INFO = {ControllerType::NeGconRumble, + "NeGconRumble", + TRANSLATE_NOOP("ControllerType", "NeGcon with Rumble"), + ICON_PF_GAMEPAD, + s_binding_info, + s_settings, + Controller::VibrationCapabilities::LargeSmallMotors}; void NeGconRumble::LoadSettings(SettingsInterface& si, const char* section) { diff --git a/src/core/negcon_rumble.h b/src/core/negcon_rumble.h index 14e0868a7..632c42bc3 100644 --- a/src/core/negcon_rumble.h +++ b/src/core/negcon_rumble.h @@ -77,7 +77,7 @@ private: { Idle, Ready, - ReadPad, // 0x42 + ReadPad, // 0x42 ConfigModeSetMode, // 0x43 SetAnalogMode, // 0x44 GetAnalogMode, // 0x45 @@ -129,7 +129,7 @@ private: std::array m_rumble_config{}; int m_rumble_config_large_motor_index = -1; int m_rumble_config_small_motor_index = -1; - + bool m_analog_toggle_queued = false; u8 m_status_byte = 0; diff --git a/src/duckstation-qt/CMakeLists.txt b/src/duckstation-qt/CMakeLists.txt index c5e886363..2a4f40e63 100644 --- a/src/duckstation-qt/CMakeLists.txt +++ b/src/duckstation-qt/CMakeLists.txt @@ -48,6 +48,7 @@ set(SRCS controllerbindingwidget_guncon.ui controllerbindingwidget_mouse.ui controllerbindingwidget_negcon.ui + controllerbindingwidget_negconrumble.ui controllerbindingwidgets.cpp controllerbindingwidgets.h controllerbindingwidget.ui diff --git a/src/duckstation-qt/controllerbindingwidget_negconrumble.ui b/src/duckstation-qt/controllerbindingwidget_negconrumble.ui new file mode 100644 index 000000000..aa9fb2be8 --- /dev/null +++ b/src/duckstation-qt/controllerbindingwidget_negconrumble.ui @@ -0,0 +1,738 @@ + + + ControllerBindingWidget_NeGconRumble + + + + 0 + 0 + 1100 + 532 + + + + + 0 + 0 + + + + + 1100 + 500 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + D-Pad + + + + + + Down + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + Left + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + Up + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + Right + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + + + + Start + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + + + + L + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + R + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + Face Buttons + + + + + + I + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + II + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + B + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + A + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 400 + 266 + + + + + + + :/controllers/negcon.svg + + + true + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Steering/Twist + + + + + + Right + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + Left + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + Analog + + + + + + + 150 + 16777215 + + + + PushButton + + + + + + + + + + + + + InputBindingWidget + QPushButton +
inputbindingwidgets.h
+
+
+ + + + +
diff --git a/src/duckstation-qt/controllerbindingwidgets.cpp b/src/duckstation-qt/controllerbindingwidgets.cpp index ad24b153d..9d45f1228 100644 --- a/src/duckstation-qt/controllerbindingwidgets.cpp +++ b/src/duckstation-qt/controllerbindingwidgets.cpp @@ -14,6 +14,7 @@ #include "ui_controllerbindingwidget_guncon.h" #include "ui_controllerbindingwidget_mouse.h" #include "ui_controllerbindingwidget_negcon.h" +#include "ui_controllerbindingwidget_negconrumble.h" #include "core/controller.h" #include "core/host.h" @@ -153,6 +154,15 @@ void ControllerBindingWidget::populateWidgets() } break; + case ControllerType::NeGconRumble: + { + Ui::ControllerBindingWidget_NeGconRumble ui; + ui.setupUi(m_bindings_widget); + bindBindingWidgets(m_bindings_widget); + m_icon = QIcon::fromTheme(QStringLiteral("negcon-line")); + } + break; + case ControllerType::PlayStationMouse: { Ui::ControllerBindingWidget_Mouse ui; diff --git a/src/duckstation-qt/duckstation-qt.vcxproj b/src/duckstation-qt/duckstation-qt.vcxproj index 441692259..fad2ae64d 100644 --- a/src/duckstation-qt/duckstation-qt.vcxproj +++ b/src/duckstation-qt/duckstation-qt.vcxproj @@ -335,6 +335,9 @@ Document + + Document + diff --git a/src/duckstation-qt/duckstation-qt.vcxproj.filters b/src/duckstation-qt/duckstation-qt.vcxproj.filters index a196a2e56..cf4c51343 100644 --- a/src/duckstation-qt/duckstation-qt.vcxproj.filters +++ b/src/duckstation-qt/duckstation-qt.vcxproj.filters @@ -293,6 +293,7 @@ +