From de2f3a1703447f957bb6493f95b50cc53750fa13 Mon Sep 17 00:00:00 2001 From: Rosalie Wanders Date: Mon, 14 Nov 2022 14:20:17 +0100 Subject: [PATCH] RMG-Input: don't save settings in OptionsDialog but store them for later --- .../RMG-Input/UserInterface/OptionsDialog.cpp | 23 +++++++++++++++---- .../RMG-Input/UserInterface/OptionsDialog.hpp | 8 ++++++- .../UserInterface/Widget/ControllerWidget.cpp | 13 ++++++++++- .../UserInterface/Widget/ControllerWidget.hpp | 3 +++ 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/Source/RMG-Input/UserInterface/OptionsDialog.cpp b/Source/RMG-Input/UserInterface/OptionsDialog.cpp index d31ed923..717b5f59 100644 --- a/Source/RMG-Input/UserInterface/OptionsDialog.cpp +++ b/Source/RMG-Input/UserInterface/OptionsDialog.cpp @@ -18,7 +18,6 @@ OptionsDialog::OptionsDialog(QWidget* parent, QString mainSettingsSection, QStri this->setupUi(this); std::string section = settingsSection.toStdString(); - this->settingsSection = settingsSection; // fallback to main settings section, // if the current settings section doesn't exist @@ -31,6 +30,21 @@ OptionsDialog::OptionsDialog(QWidget* parent, QString mainSettingsSection, QStri this->controllerPakComboBox->setCurrentIndex(CoreSettingsGetIntValue(SettingsID::Input_Pak, section)); } +bool OptionsDialog::HasSaved() +{ + return this->hasSaved; +} + +bool OptionsDialog::GetRemoveDuplicateMappings() +{ + return this->removeDuplicateMappings; +} + +int OptionsDialog::GetControllerPak() +{ + return this->controllerPak; +} + void OptionsDialog::on_buttonBox_clicked(QAbstractButton *button) { @@ -39,10 +53,9 @@ void OptionsDialog::on_buttonBox_clicked(QAbstractButton *button) if (pushButton == okButton) { - std::string section = this->settingsSection.toStdString(); - - CoreSettingsSetValue(SettingsID::Input_RemoveDuplicateMappings, section, this->removeDuplicateMappingsCheckbox->isChecked()); - CoreSettingsSetValue(SettingsID::Input_Pak, section, this->controllerPakComboBox->currentIndex()); + this->hasSaved = true; + this->removeDuplicateMappings = this->removeDuplicateMappingsCheckbox->isChecked(); + this->controllerPak = this->controllerPakComboBox->currentIndex(); } this->accept(); diff --git a/Source/RMG-Input/UserInterface/OptionsDialog.hpp b/Source/RMG-Input/UserInterface/OptionsDialog.hpp index b723468f..4c6f4453 100644 --- a/Source/RMG-Input/UserInterface/OptionsDialog.hpp +++ b/Source/RMG-Input/UserInterface/OptionsDialog.hpp @@ -23,8 +23,14 @@ Q_OBJECT public: OptionsDialog(QWidget *parent, QString mainSettingsSection, QString settingsSection); + bool HasSaved(); + bool GetRemoveDuplicateMappings(); + int GetControllerPak(); + private: - QString settingsSection; + bool hasSaved = false; + bool removeDuplicateMappings = false; + int controllerPak = 0; private slots: void on_buttonBox_clicked(QAbstractButton *); diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp index 9bf90045..f88f22b0 100644 --- a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp +++ b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp @@ -215,7 +215,7 @@ void ControllerWidget::removeDuplicates(CustomButton* button) { std::string section = this->getCurrentSettingsSection().toStdString(); - if (!CoreSettingsGetBoolValue(SettingsID::Input_RemoveDuplicateMappings, section)) + if (!this->settingRemoveDuplicateMappings) { return; } @@ -493,6 +493,13 @@ void ControllerWidget::on_optionsButton_clicked() { OptionsDialog dialog(this, this->settingsSection, this->getCurrentSettingsSection()); dialog.exec(); + + // when saved, store settings for later + if (dialog.HasSaved()) + { + this->settingRemoveDuplicateMappings = dialog.GetRemoveDuplicateMappings(); + this->settingControllerPak = dialog.GetControllerPak(); + } } void ControllerWidget::on_CustomButton_released(CustomButton* button) @@ -904,6 +911,8 @@ void ControllerWidget::LoadSettings(QString sectionQString) this->controllerPluggedCheckBox->setChecked(CoreSettingsGetBoolValue(SettingsID::Input_PluggedIn, section)); this->analogStickRangeSlider->setValue(CoreSettingsGetIntValue(SettingsID::Input_Range, section)); this->deadZoneSlider->setValue(CoreSettingsGetIntValue(SettingsID::Input_Deadzone, section)); + this->settingRemoveDuplicateMappings = CoreSettingsGetBoolValue(SettingsID::Input_RemoveDuplicateMappings, section); + this->settingControllerPak = CoreSettingsGetIntValue(SettingsID::Input_Pak, section); for (auto& buttonSetting : this->buttonSettingMappings) { @@ -975,6 +984,8 @@ void ControllerWidget::SaveSettings() CoreSettingsSetValue(SettingsID::Input_DeviceNum, section, deviceNum); CoreSettingsSetValue(SettingsID::Input_Range, section, this->analogStickRangeSlider->value()); CoreSettingsSetValue(SettingsID::Input_Deadzone, section, this->deadZoneSlider->value()); + CoreSettingsSetValue(SettingsID::Input_Pak, section, this->settingControllerPak); + CoreSettingsSetValue(SettingsID::Input_RemoveDuplicateMappings, section, this->settingRemoveDuplicateMappings); for (auto& buttonSetting : this->buttonSettingMappings) { diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp index fc1745a4..5359b246 100644 --- a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp +++ b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp @@ -36,6 +36,9 @@ private: QString settingsSection; QString gameSettingsSection; + bool settingRemoveDuplicateMappings = false; + int settingControllerPak = 0; + QList inputDeviceNameList; CustomButton* currentButton = nullptr;