diff --git a/Source/RMG-Input/UserInterface/MainDialog.cpp b/Source/RMG-Input/UserInterface/MainDialog.cpp index 0ffae5d2..f2474a7e 100644 --- a/Source/RMG-Input/UserInterface/MainDialog.cpp +++ b/Source/RMG-Input/UserInterface/MainDialog.cpp @@ -18,7 +18,7 @@ using namespace UserInterface; -MainDialog::MainDialog(QWidget* parent, Thread::SDLThread* sdlThread) : QDialog(parent) +MainDialog::MainDialog(QWidget* parent, Thread::SDLThread* sdlThread, bool romConfig) : QDialog(parent) { this->setupUi(this); this->setWindowIcon(QIcon(":Resource/RMG.png")); @@ -41,6 +41,7 @@ MainDialog::MainDialog(QWidget* parent, Thread::SDLThread* sdlThread) : QDialog( for (int i = 0; i < this->tabWidget->count(); i++) { Widget::ControllerWidget* widget = new Widget::ControllerWidget(this, this->eventFilter); + widget->SetOnlyLoadGameProfile(romConfig); widget->SetSettingsSection("Player " + QString::number(i + 1), "Rosalie's Mupen GUI - Input Plugin Profile " + QString::number(i)); widget->LoadSettings(); this->tabWidget->widget(i)->layout()->addWidget(widget); diff --git a/Source/RMG-Input/UserInterface/MainDialog.hpp b/Source/RMG-Input/UserInterface/MainDialog.hpp index b7029cb3..8594fe28 100644 --- a/Source/RMG-Input/UserInterface/MainDialog.hpp +++ b/Source/RMG-Input/UserInterface/MainDialog.hpp @@ -59,7 +59,7 @@ private: void closeInputDevice(); public: - MainDialog(QWidget *parent, Thread::SDLThread*); + MainDialog(QWidget *parent, Thread::SDLThread*, bool); ~MainDialog(void); public slots: diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp index 22c10c68..5788c57a 100644 --- a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp +++ b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp @@ -355,6 +355,67 @@ void ControllerWidget::setPluggedIn(bool value) this->ClearControllerImage(); } +bool ControllerWidget::hasAnyGameSettingChanged(void) +{ + std::string section = this->getCurrentSettingsSection().toStdString(); + // fallback to main section + if (!CoreSettingsSectionExists(section)) + { + section = this->settingsSection.toStdString(); + } + + // retrieve data from settings + bool settingsIsPluggedIn = CoreSettingsGetBoolValue(SettingsID::Input_PluggedIn, section); + int settingsDeadZone = CoreSettingsGetIntValue(SettingsID::Input_Deadzone, section); + int settingsAnalogSensitivity = 100; + // account for profiles before v0.3.9 + if (CoreSettingsKeyExists(section, "Sensitivity")) + { + settingsAnalogSensitivity = CoreSettingsGetIntValue(SettingsID::Input_Sensitivity, section); + } + + // retrieve current data + bool currentIsPluggedIn = this->inputDeviceComboBox->currentText() != "None"; + int currentDeadZone = this->deadZoneSlider->value(); + int currentAnalogSensitivity = this->analogStickSensitivitySlider->value(); + + // compare data + if (settingsIsPluggedIn != currentIsPluggedIn || + settingsDeadZone != currentDeadZone || + settingsAnalogSensitivity != currentAnalogSensitivity) + { + return true; + } + + // compare button mappings with settings + for (auto& buttonSetting : this->buttonSettingMappings) + { + // retrieve data from settings + std::vector settingsTypes = CoreSettingsGetIntListValue(buttonSetting.inputTypeSettingsId, section); + std::vector settingsNames = CoreSettingsGetStringListValue(buttonSetting.nameSettingsId, section); + std::vector settingsData = CoreSettingsGetIntListValue(buttonSetting.dataSettingsId, section); + std::vector settingsExtraData = CoreSettingsGetIntListValue(buttonSetting.extraDataSettingsId, section); + + // retrieve current data + std::vector currentTypes = buttonSetting.button->GetInputType(); + std::vector currentNames = buttonSetting.button->GetInputText(); + std::vector currentData = buttonSetting.button->GetInputData(); + std::vector currentExtraData = buttonSetting.button->GetExtraInputData(); + + // compare data + if (settingsTypes != currentTypes || + settingsNames != currentNames || + settingsData != currentData || + settingsExtraData != currentExtraData) + { + return true; + } + } + + // no differences found + return false; +} + void ControllerWidget::showErrorMessage(QString text, QString details) { QMessageBox msgBox(this); @@ -633,7 +694,7 @@ void ControllerWidget::on_removeProfileButton_clicked() { bool ret; - if (this->profileComboBox->currentIndex() == 0) + if (this->profileComboBox->currentData().toString() == this->settingsSection) { QMessageBox messageBox(this); messageBox.setIcon(QMessageBox::Icon::Warning); @@ -689,6 +750,13 @@ void ControllerWidget::on_removeProfileButton_clicked() this->previousProfileComboBoxIndex = -1; this->profileComboBox->setCurrentIndex(0); } + + // force a re-load when + // we're only loading the game profile + if (this->onlyLoadGameProfile) + { + this->LoadSettings(this->settingsSection); + } } void ControllerWidget::on_resetButton_clicked() @@ -1104,10 +1172,21 @@ bool ControllerWidget::IsPluggedIn() return this->inputDeviceComboBox->currentData().toInt() != (int)InputDeviceType::None; } +void ControllerWidget::SetOnlyLoadGameProfile(bool value) +{ + this->onlyLoadGameProfile = value; + + // update UI element + this->addProfileButton->setDisabled(value); +} + void ControllerWidget::SetSettingsSection(QString profile, QString section) { this->settingsSection = section; - this->profileComboBox->addItem(profile, section); + if (!this->onlyLoadGameProfile) + { + this->profileComboBox->addItem(profile, section); + } } void ControllerWidget::SetInitialized(bool value) @@ -1156,41 +1235,53 @@ void ControllerWidget::LoadSettings() // if a game specific section exists, // select it in the profile combobox // and use it to load the settings - if (CoreSettingsSectionExists(this->gameSection.toStdString())) + if (CoreSettingsSectionExists(this->gameSection.toStdString()) || + this->onlyLoadGameProfile) { // check if the key 'UseGameProfile' exists, // if it doesn't then use the profile, - // else check if it's true and use it - if (!CoreSettingsKeyExists(this->gameSection.toStdString(), "UseGameProfile") || + // else check if it's true and use it, + // or if we're only loading the game profile + if (this->onlyLoadGameProfile || + !CoreSettingsKeyExists(this->gameSection.toStdString(), "UseGameProfile") || CoreSettingsGetBoolValue(SettingsID::Input_UseGameProfile, this->gameSection.toStdString())) { this->profileComboBox->setCurrentText(internalName); - section = this->gameSection; + + // only use game section if it exists + if (CoreSettingsSectionExists(this->gameSection.toStdString())) + { + section = this->gameSection; + } } } } - // clear profiles list - profiles.clear(); - - // try to add all the user's profiles - userProfiles = CoreSettingsGetStringListValue(SettingsID::Input_Profiles); - for (const std::string& profile : userProfiles) + // try to add all the user's profiles when we're not only loading the + // game profile + if (!this->onlyLoadGameProfile) { - QString profileSection = this->getUserProfileSectionName(QString::fromStdString(profile)); + // clear profiles list + profiles.clear(); - // ensure the profile section exists, - // if it does, add it when it doesn't - // exist yet - if (CoreSettingsSectionExists(profileSection.toStdString())) + userProfiles = CoreSettingsGetStringListValue(SettingsID::Input_Profiles); + for (const std::string& profile : userProfiles) { - // add to profiles list - this->profiles.push_back(profileSection); + QString profileSection = this->getUserProfileSectionName(QString::fromStdString(profile)); - int index = this->profileComboBox->findData(profileSection); - if (index == -1) + // ensure the profile section exists, + // if it does, add it when it doesn't + // exist yet + if (CoreSettingsSectionExists(profileSection.toStdString())) { - this->profileComboBox->addItem(QString::fromStdString(profile), profileSection); + // add to profiles list + this->profiles.push_back(profileSection); + + int index = this->profileComboBox->findData(profileSection); + if (index == -1) + { + this->profileComboBox->addItem(QString::fromStdString(profile), profileSection); + } } } } @@ -1230,7 +1321,7 @@ void ControllerWidget::LoadSettings(QString sectionQString, bool loadUserProfile // if it does, see if that profile exists, then load // that instead useProfile = CoreSettingsGetStringValue(SettingsID::Input_UseProfile, section); - if (loadUserProfile && !useProfile.empty()) + if (!this->onlyLoadGameProfile && loadUserProfile && !useProfile.empty()) { QString profileSection = this->getUserProfileSectionName(QString::fromStdString(useProfile)); @@ -1352,6 +1443,14 @@ void ControllerWidget::SaveSettings() return; } + // when we're only loading the game profile, + // we should only save when anything has changed + if (this->onlyLoadGameProfile && + !this->hasAnyGameSettingChanged()) + { + return; + } + this->SaveSettings(this->getCurrentSettingsSection()); // delete all removed profile sections @@ -1448,6 +1547,14 @@ void ControllerWidget::RevertSettings() CoreSettingsRevertSection(section.toStdString()); } + // don't compare profiles, + // when we're only loading + // the game profile + if (this->onlyLoadGameProfile) + { + return; + } + // delete all sections for added & removed profiles, // which aren't in the base profile section list sections.clear(); diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp index 836c79b4..1e491a0a 100644 --- a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp +++ b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp @@ -95,6 +95,8 @@ private: void setPluggedIn(bool value); + bool hasAnyGameSettingChanged(void); + void showErrorMessage(QString text, QString details = ""); SDL_JoystickID currentJoystickId = -1; @@ -102,6 +104,8 @@ private: int previousProfileComboBoxIndex = -1; + bool onlyLoadGameProfile = false; + public: ControllerWidget(QWidget* parent, EventFilter* eventFilter); ~ControllerWidget(); @@ -116,6 +120,8 @@ public: void GetCurrentInputDevice(QString& deviceName, int& deviceNum, bool ignoreDeviceNotFound = false); bool IsPluggedIn(); + void SetOnlyLoadGameProfile(bool value); + void SetSettingsSection(QString profile, QString section); void SetInitialized(bool value); diff --git a/Source/RMG-Input/main.cpp b/Source/RMG-Input/main.cpp index 5da5f20d..2e2b5355 100644 --- a/Source/RMG-Input/main.cpp +++ b/Source/RMG-Input/main.cpp @@ -417,7 +417,7 @@ static void close_controllers(void) for (int i = 0; i < NUM_CONTROLLERS; i++) { InputProfile* profile = &l_InputProfiles[i]; - + profile->InputDevice.CloseDevice(); } } @@ -731,7 +731,7 @@ EXPORT m64p_error CALL PluginGetVersion(m64p_plugin_type *pluginType, int *plugi // Custom Plugin Functions // -EXPORT m64p_error CALL PluginConfig() +EXPORT m64p_error CALL PluginConfig2(int romConfig) { if (l_SDLThread == nullptr) { @@ -743,7 +743,7 @@ EXPORT m64p_error CALL PluginConfig() l_SDLThread->SetAction(SDLThreadAction::SDLPumpEvents); - UserInterface::MainDialog dialog(nullptr, l_SDLThread); + UserInterface::MainDialog dialog(nullptr, l_SDLThread, romConfig); dialog.exec(); l_SDLThread->SetAction(SDLThreadAction::None); @@ -754,7 +754,6 @@ EXPORT m64p_error CALL PluginConfig() QThread::msleep(5); } - // reload settings load_settings(); @@ -770,6 +769,11 @@ EXPORT m64p_error CALL PluginConfig() return M64ERR_SUCCESS; } +EXPORT int CALL PluginConfig2HasRomConfig(void) +{ + return 1; +} + // // Input Plugin Functions //