diff --git a/Source/RMG-Input/UserInterface/MainDialog.cpp b/Source/RMG-Input/UserInterface/MainDialog.cpp index e93c636d..5fc80418 100644 --- a/Source/RMG-Input/UserInterface/MainDialog.cpp +++ b/Source/RMG-Input/UserInterface/MainDialog.cpp @@ -128,14 +128,14 @@ void MainDialog::openInputDevice(InputDevice device) { Widget::ControllerWidget* controllerWidget; controllerWidget = this->controllerWidgets.at(this->tabWidget->currentIndex()); + InputProfileDBEntry inputProfile = {}; // we don't need to open a non-joystick device if (device.type != InputDeviceType::Automatic && device.type != InputDeviceType::Joystick) { this->currentDevice = { }; - controllerWidget->SetCurrentJoystickID(this->currentDevice.id); - controllerWidget->SetCurrentJoystick(nullptr, nullptr); + controllerWidget->SetCurrentInputDevice(this->currentDevice.id, nullptr, nullptr, inputProfile); return; } @@ -146,12 +146,12 @@ void MainDialog::openInputDevice(InputDevice device) if (currentIndex < this->inputDeviceList.size()) { // use device when there's one device.id = this->inputDeviceList.at(currentIndex).id; + inputProfile = this->inputProfileDB.FindEntry(this->inputDeviceList.at(currentIndex)); } else { // no device found, fallback to keyboard this->currentDevice = { InputDeviceType::Keyboard, "Keyboard" }; - controllerWidget->SetCurrentJoystickID(this->currentDevice.id); - controllerWidget->SetCurrentJoystick(nullptr, nullptr); + controllerWidget->SetCurrentInputDevice(this->currentDevice.id, nullptr, nullptr, inputProfile); return; } } @@ -170,9 +170,7 @@ void MainDialog::openInputDevice(InputDevice device) } this->currentDevice = device; - controllerWidget->SetCurrentJoystickID(device.id); - controllerWidget->SetIsCurrentJoystickGamepad(currentGamepad != nullptr); - controllerWidget->SetCurrentJoystick(this->currentJoystick, this->currentGamepad); + controllerWidget->SetCurrentInputDevice(device.id, this->currentJoystick, this->currentGamepad, inputProfile); } void MainDialog::closeInputDevice() diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp index 1ccb8fc1..98fc200b 100644 --- a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp +++ b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp @@ -2025,23 +2025,25 @@ void ControllerWidget::RevertSettings() } } -void ControllerWidget::SetCurrentJoystickID(SDL_JoystickID joystickId) +void ControllerWidget::SetCurrentInputDevice(SDL_JoystickID joystickId, SDL_Joystick* joystick, + SDL_Gamepad* gamepad, const InputProfileDBEntry& inputProfile) { this->currentJoystickId = joystickId; -} - -void ControllerWidget::SetIsCurrentJoystickGamepad(bool isGamepad) -{ - this->isCurrentJoystickGamepad = isGamepad; -} - -void ControllerWidget::SetCurrentJoystick(SDL_Joystick* joystick, SDL_Gamepad* gamepad) -{ this->currentJoystick = joystick; this->currentGamepad = gamepad; + this->isCurrentJoystickGamepad = (gamepad != nullptr); // we can enable the auto-configure button when we have a gamepad this->autoConfigButton->setEnabled(gamepad != nullptr); + + // update input profile when needed + if (inputProfile.valid) + { + int currentIndex = this->inputDeviceComboBox->currentIndex(); + inputDeviceData deviceData = this->inputDeviceComboBox->itemData(currentIndex).value(); + deviceData.inputProfile = inputProfile; + this->inputDeviceComboBox->setItemData(currentIndex, QVariant::fromValue(deviceData)); + } } void ControllerWidget::AddUserProfile(QString name, QString section) diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp index 9d91e645..f61972dc 100644 --- a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp +++ b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp @@ -159,9 +159,8 @@ public: void RevertSettings(); - void SetCurrentJoystickID(SDL_JoystickID joystickId); - void SetIsCurrentJoystickGamepad(bool isGamepad); - void SetCurrentJoystick(SDL_Joystick* joystick, SDL_Gamepad* gamepad); + void SetCurrentInputDevice(SDL_JoystickID joystickId, SDL_Joystick* joystick, + SDL_Gamepad* gamepad, const InputProfileDBEntry& inputProfile); void AddUserProfile(QString name, QString section); void RemoveUserProfile(QString name, QString section);