diff --git a/Source/RMG-Input/UserInterface/MainDialog.cpp b/Source/RMG-Input/UserInterface/MainDialog.cpp index 3a171ada..0c816a2f 100644 --- a/Source/RMG-Input/UserInterface/MainDialog.cpp +++ b/Source/RMG-Input/UserInterface/MainDialog.cpp @@ -117,6 +117,7 @@ void MainDialog::openInputDevice(QString deviceName, int deviceNum) this->currentDeviceName = ""; this->currentDeviceNum = deviceNum; controllerWidget->SetCurrentJoystickID(this->currentDeviceNum); + controllerWidget->SetCurrentJoystick(nullptr, nullptr); return; } @@ -133,6 +134,7 @@ void MainDialog::openInputDevice(QString deviceName, int deviceNum) this->currentDeviceName = ""; this->currentDeviceNum = (int)InputDeviceType::Keyboard; controllerWidget->SetCurrentJoystickID(this->currentDeviceNum); + controllerWidget->SetCurrentJoystick(nullptr, nullptr); return; } } @@ -152,6 +154,7 @@ void MainDialog::openInputDevice(QString deviceName, int deviceNum) joystickId = SDL_JoystickGetDeviceInstanceID(deviceNum); controllerWidget->SetCurrentJoystickID(joystickId); controllerWidget->SetIsCurrentJoystickGameController(currentController != nullptr); + controllerWidget->SetCurrentJoystick(this->currentJoystick, this->currentController); } void MainDialog::closeInputDevice() diff --git a/Source/RMG-Input/UserInterface/OptionsDialog.cpp b/Source/RMG-Input/UserInterface/OptionsDialog.cpp index 3e225b56..a17c0ef5 100644 --- a/Source/RMG-Input/UserInterface/OptionsDialog.cpp +++ b/Source/RMG-Input/UserInterface/OptionsDialog.cpp @@ -10,11 +10,15 @@ #include "OptionsDialog.hpp" #include +#include #include +#include + using namespace UserInterface; -OptionsDialog::OptionsDialog(QWidget* parent, OptionsDialogSettings settings) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint) +OptionsDialog::OptionsDialog(QWidget* parent, OptionsDialogSettings settings, + SDL_Joystick* joystick, SDL_GameController* controller) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint) { this->setupUi(this); @@ -31,6 +35,11 @@ OptionsDialog::OptionsDialog(QWidget* parent, OptionsDialogSettings settings) : { this->hideEmulationInfoText(); } + + this->currentJoystick = joystick; + this->currentController = controller; + + this->testRumbleButton->setEnabled(this->currentJoystick != nullptr || this->currentController != nullptr); } OptionsDialogSettings OptionsDialog::GetSettings() @@ -100,3 +109,27 @@ void OptionsDialog::on_changeGameboySaveButton_clicked() this->gameboySaveLineEdit->setText(QDir::toNativeSeparators(gameBoySave)); } } + +void OptionsDialog::on_testRumbleButton_clicked() +{ + if ((this->currentJoystick != nullptr && SDL_JoystickHasRumble(this->currentJoystick) != SDL_TRUE) || + (this->currentController != nullptr && SDL_GameControllerHasRumble(this->currentController) != SDL_TRUE)) + { + QMessageBox msgBox(this); + msgBox.setIcon(QMessageBox::Icon::Critical); + msgBox.setWindowTitle("Error"); + msgBox.setText("Controller doesn't support rumble"); + msgBox.addButton(QMessageBox::Ok); + msgBox.exec(); + return; + } + + if (this->currentJoystick != nullptr) + { + SDL_JoystickRumble(this->currentJoystick, 0xFFFF, 0xFFFF, 1500); + } + else + { + SDL_GameControllerRumble(this->currentController, 0xFFFF, 0xFFFF, 1500); + } +} diff --git a/Source/RMG-Input/UserInterface/OptionsDialog.hpp b/Source/RMG-Input/UserInterface/OptionsDialog.hpp index 5b772957..14e3ed49 100644 --- a/Source/RMG-Input/UserInterface/OptionsDialog.hpp +++ b/Source/RMG-Input/UserInterface/OptionsDialog.hpp @@ -13,6 +13,8 @@ #include #include +#include + #include "ui_OptionsDialog.h" struct OptionsDialogSettings @@ -35,7 +37,8 @@ class OptionsDialog : public QDialog, private Ui::OptionsDialog Q_OBJECT public: - OptionsDialog(QWidget *parent, OptionsDialogSettings settings); + OptionsDialog(QWidget *parent, OptionsDialogSettings settings, + SDL_Joystick* joystick, SDL_GameController* controller); OptionsDialogSettings GetSettings(); @@ -45,12 +48,16 @@ protected: private: OptionsDialogSettings settings; + SDL_Joystick* currentJoystick = nullptr; + SDL_GameController* currentController = nullptr; + void setIconsForEmulationInfoText(void); void hideEmulationInfoText(void); private slots: void on_changeGameboyRomButton_clicked(); void on_changeGameboySaveButton_clicked(); + void on_testRumbleButton_clicked(); }; } diff --git a/Source/RMG-Input/UserInterface/OptionsDialog.ui b/Source/RMG-Input/UserInterface/OptionsDialog.ui index 49b6b047..e6744486 100644 --- a/Source/RMG-Input/UserInterface/OptionsDialog.ui +++ b/Source/RMG-Input/UserInterface/OptionsDialog.ui @@ -72,7 +72,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -82,6 +82,13 @@ + + + + Test Rumble + + + @@ -138,7 +145,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -219,7 +226,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -236,10 +243,10 @@ - Qt::Horizontal + Qt::Orientation::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp index d5cf8562..66f3c8a1 100644 --- a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp +++ b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp @@ -853,7 +853,11 @@ void ControllerWidget::on_resetButton_clicked() void ControllerWidget::on_optionsButton_clicked() { - OptionsDialog dialog(this, this->optionsDialogSettings); + bool isKeyboard = this->inputDeviceComboBox->currentData().toInt() == (int)InputDeviceType::Keyboard; + + OptionsDialog dialog(this, this->optionsDialogSettings, + isKeyboard ? nullptr : this->currentJoystick, + isKeyboard ? nullptr : this->currentController); int ret = dialog.exec(); // when saved, store settings for later @@ -1866,6 +1870,12 @@ void ControllerWidget::SetIsCurrentJoystickGameController(bool isGameController) this->isCurrentJoystickGameController = isGameController; } +void ControllerWidget::SetCurrentJoystick(SDL_Joystick* joystick, SDL_GameController* controller) +{ + this->currentJoystick = joystick; + this->currentController = controller; +} + void ControllerWidget::AddUserProfile(QString name, QString section) { int index = this->profileComboBox->findData(section); diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp index da51f8f0..fbd0193a 100644 --- a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp +++ b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp @@ -104,6 +104,9 @@ private: SDL_JoystickID currentJoystickId = -1; bool isCurrentJoystickGameController = false; + SDL_Joystick* currentJoystick = nullptr; + SDL_GameController* currentController = nullptr; + int previousProfileComboBoxIndex = -1; bool onlyLoadGameProfile = false; @@ -143,6 +146,7 @@ public: void SetCurrentJoystickID(SDL_JoystickID joystickId); void SetIsCurrentJoystickGameController(bool isGameController); + void SetCurrentJoystick(SDL_Joystick* joystick, SDL_GameController* controller); void AddUserProfile(QString name, QString section); void RemoveUserProfile(QString name, QString section);