From 93c75a5b0be71a97624faba6fe9594f52afa830d Mon Sep 17 00:00:00 2001 From: Rosalie Wanders Date: Thu, 17 Nov 2022 01:18:36 +0100 Subject: [PATCH] RMG-Input: add transfer pak support --- .../RMG-Input/UserInterface/OptionsDialog.cpp | 55 ++++-- .../RMG-Input/UserInterface/OptionsDialog.hpp | 23 ++- .../RMG-Input/UserInterface/OptionsDialog.ui | 183 ++++++++++++++---- .../UserInterface/Widget/ControllerWidget.cpp | 19 +- .../UserInterface/Widget/ControllerWidget.hpp | 4 +- Source/RMG-Input/common.hpp | 1 + Source/RMG-Input/main.cpp | 60 +++++- 7 files changed, 262 insertions(+), 83 deletions(-) diff --git a/Source/RMG-Input/UserInterface/OptionsDialog.cpp b/Source/RMG-Input/UserInterface/OptionsDialog.cpp index 717b5f59..56d50294 100644 --- a/Source/RMG-Input/UserInterface/OptionsDialog.cpp +++ b/Source/RMG-Input/UserInterface/OptionsDialog.cpp @@ -9,25 +9,19 @@ */ #include "OptionsDialog.hpp" +#include #include using namespace UserInterface; -OptionsDialog::OptionsDialog(QWidget* parent, QString mainSettingsSection, QString settingsSection) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint) +OptionsDialog::OptionsDialog(QWidget* parent, OptionsDialogSettings settings) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint) { this->setupUi(this); - std::string section = settingsSection.toStdString(); - - // fallback to main settings section, - // if the current settings section doesn't exist - if (!CoreSettingsSectionExists(settingsSection.toStdString())) - { - section = mainSettingsSection.toStdString(); - } - - this->removeDuplicateMappingsCheckbox->setChecked(CoreSettingsGetBoolValue(SettingsID::Input_RemoveDuplicateMappings, section)); - this->controllerPakComboBox->setCurrentIndex(CoreSettingsGetIntValue(SettingsID::Input_Pak, section)); + this->controllerPakComboBox->setCurrentIndex(settings.ControllerPak); + this->gameboyRomLineEdit->setText(QString::fromStdString(settings.GameboyRom)); + this->gameboySaveLineEdit->setText(QString::fromStdString(settings.GameboySave)); + this->removeDuplicateMappingsCheckbox->setChecked(settings.RemoveDuplicateMappings); } bool OptionsDialog::HasSaved() @@ -35,14 +29,9 @@ bool OptionsDialog::HasSaved() return this->hasSaved; } -bool OptionsDialog::GetRemoveDuplicateMappings() +OptionsDialogSettings OptionsDialog::GetSettings() { - return this->removeDuplicateMappings; -} - -int OptionsDialog::GetControllerPak() -{ - return this->controllerPak; + return this->settings; } void OptionsDialog::on_buttonBox_clicked(QAbstractButton *button) @@ -54,9 +43,33 @@ void OptionsDialog::on_buttonBox_clicked(QAbstractButton *button) if (pushButton == okButton) { this->hasSaved = true; - this->removeDuplicateMappings = this->removeDuplicateMappingsCheckbox->isChecked(); - this->controllerPak = this->controllerPakComboBox->currentIndex(); + this->settings.ControllerPak = this->controllerPakComboBox->currentIndex(); + this->settings.GameboyRom = this->gameboyRomLineEdit->text().toStdString(); + this->settings.GameboySave = this->gameboySaveLineEdit->text().toStdString(); + this->settings.RemoveDuplicateMappings = this->removeDuplicateMappingsCheckbox->isChecked(); } this->accept(); } + +void OptionsDialog::on_changeGameboyRomButton_clicked() +{ + QString gameBoyRom; + gameBoyRom = QFileDialog::getOpenFileName(this, "", "", "Gameboy ROM (*.gb *.gbc)"); + + if (!gameBoyRom.isEmpty()) + { + this->gameboyRomLineEdit->setText(gameBoyRom); + } +} + +void OptionsDialog::on_changeGameboySaveButton_clicked() +{ + QString gameBoySave; + gameBoySave = QFileDialog::getOpenFileName(this, "", "", "Gameboy SAVE (*.sav *.ram)"); + + if (!gameBoySave.isEmpty()) + { + this->gameboySaveLineEdit->setText(gameBoySave); + } +} diff --git a/Source/RMG-Input/UserInterface/OptionsDialog.hpp b/Source/RMG-Input/UserInterface/OptionsDialog.hpp index 4c6f4453..99b747a8 100644 --- a/Source/RMG-Input/UserInterface/OptionsDialog.hpp +++ b/Source/RMG-Input/UserInterface/OptionsDialog.hpp @@ -11,9 +11,21 @@ #define OPTIONSDIALOG_HPP #include +#include #include "ui_OptionsDialog.h" +struct OptionsDialogSettings +{ + // controller settings + int ControllerPak = 0; + std::string GameboyRom; + std::string GameboySave; + + // UI settings + bool RemoveDuplicateMappings = false; +}; + namespace UserInterface { class OptionsDialog : public QDialog, private Ui::OptionsDialog @@ -21,19 +33,20 @@ class OptionsDialog : public QDialog, private Ui::OptionsDialog Q_OBJECT public: - OptionsDialog(QWidget *parent, QString mainSettingsSection, QString settingsSection); + OptionsDialog(QWidget *parent, OptionsDialogSettings settings); bool HasSaved(); - bool GetRemoveDuplicateMappings(); - int GetControllerPak(); + OptionsDialogSettings GetSettings(); private: bool hasSaved = false; - bool removeDuplicateMappings = false; - int controllerPak = 0; + OptionsDialogSettings settings; private slots: void on_buttonBox_clicked(QAbstractButton *); + + void on_changeGameboyRomButton_clicked(); + void on_changeGameboySaveButton_clicked(); }; } diff --git a/Source/RMG-Input/UserInterface/OptionsDialog.ui b/Source/RMG-Input/UserInterface/OptionsDialog.ui index 04019b7f..5490ede8 100644 --- a/Source/RMG-Input/UserInterface/OptionsDialog.ui +++ b/Source/RMG-Input/UserInterface/OptionsDialog.ui @@ -6,8 +6,8 @@ 0 0 - 321 - 316 + 354 + 405 @@ -21,9 +21,136 @@ - General + Controller + + + + 0 + + + + Controller + + + + + + + + Controller Pak + + + + + + + + Memory + + + + + Rumble + + + + + Transfer + + + + + None + + + + + + + + + + Qt::Vertical + + + + 20 + 212 + + + + + + + + + Transfer Pak + + + + + + Gameboy ROM + + + + + + + + + Change + + + + + + + + + + Gameboy SAVE + + + + + + + + + Change + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + User Interface + + @@ -32,58 +159,32 @@ - - - Controller Pak - - - - - - - - Memory - - - - - Rumble - - - - - None - - - - - - + Qt::Vertical 20 - 122 + 40 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp index 8ca5f58c..012418f8 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 (!this->settingRemoveDuplicateMappings) + if (!this->optionsDialogSettings.RemoveDuplicateMappings) { return; } @@ -493,14 +493,13 @@ void ControllerWidget::on_resetButton_clicked() void ControllerWidget::on_optionsButton_clicked() { - OptionsDialog dialog(this, this->settingsSection, this->getCurrentSettingsSection()); + OptionsDialog dialog(this, this->optionsDialogSettings); dialog.exec(); // when saved, store settings for later if (dialog.HasSaved()) { - this->settingRemoveDuplicateMappings = dialog.GetRemoveDuplicateMappings(); - this->settingControllerPak = dialog.GetControllerPak(); + this->optionsDialogSettings = dialog.GetSettings(); } } @@ -892,8 +891,10 @@ 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); + this->optionsDialogSettings.RemoveDuplicateMappings = CoreSettingsGetBoolValue(SettingsID::Input_RemoveDuplicateMappings, section); + this->optionsDialogSettings.ControllerPak = CoreSettingsGetIntValue(SettingsID::Input_Pak, section); + this->optionsDialogSettings.GameboyRom = CoreSettingsGetStringValue(SettingsID::Input_GameboyRom, section); + this->optionsDialogSettings.GameboySave = CoreSettingsGetStringValue(SettingsID::Input_GameboySave, section); for (auto& buttonSetting : this->buttonSettingMappings) { @@ -952,8 +953,10 @@ 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); + CoreSettingsSetValue(SettingsID::Input_Pak, section, this->optionsDialogSettings.ControllerPak); + CoreSettingsSetValue(SettingsID::Input_GameboyRom, section, this->optionsDialogSettings.GameboyRom); + CoreSettingsSetValue(SettingsID::Input_GameboySave, section, this->optionsDialogSettings.GameboySave); + CoreSettingsSetValue(SettingsID::Input_RemoveDuplicateMappings, section, this->optionsDialogSettings.RemoveDuplicateMappings); for (auto& buttonSetting : this->buttonSettingMappings) { diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp index f5817c5b..58bd69da 100644 --- a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp +++ b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.hpp @@ -14,6 +14,7 @@ #include "ControllerImageWidget.hpp" #include "UserInterface/EventFilter.hpp" +#include "UserInterface/OptionsDialog.hpp" using namespace UserInterface::Widget; @@ -35,8 +36,7 @@ class ControllerWidget : public QWidget, Ui::ControllerWidget private: QString settingsSection; - bool settingRemoveDuplicateMappings = false; - int settingControllerPak = 0; + OptionsDialogSettings optionsDialogSettings; QList inputDeviceNameList; CustomButton* currentButton = nullptr; diff --git a/Source/RMG-Input/common.hpp b/Source/RMG-Input/common.hpp index a809dc24..52354e8a 100644 --- a/Source/RMG-Input/common.hpp +++ b/Source/RMG-Input/common.hpp @@ -54,6 +54,7 @@ enum class N64ControllerPak { MemoryPak = 0, RumblePak, + TransferPak, None, }; diff --git a/Source/RMG-Input/main.cpp b/Source/RMG-Input/main.cpp index 60638242..e1a5b045 100644 --- a/Source/RMG-Input/main.cpp +++ b/Source/RMG-Input/main.cpp @@ -65,6 +65,10 @@ struct InputProfile int DeviceNum = -1; std::chrono::time_point LastDeviceCheckTime = std::chrono::high_resolution_clock::now(); + // Gameboy information + std::string GameboyRom; + std::string GameboySave; + // input device Utilities::InputDevice InputDevice; @@ -164,6 +168,8 @@ static void load_settings(void) profile->ControllerPak = (N64ControllerPak)CoreSettingsGetIntValue(SettingsID::Input_Pak, section); profile->DeviceName = CoreSettingsGetStringValue(SettingsID::Input_DeviceName, section); profile->DeviceNum = CoreSettingsGetIntValue(SettingsID::Input_DeviceNum, section); + profile->GameboyRom = CoreSettingsGetStringValue(SettingsID::Input_GameboyRom, section); + profile->GameboySave = CoreSettingsGetStringValue(SettingsID::Input_GameboySave, section); // load inputmapping settings load_inputmapping_settings(&profile->Button_A, section, SettingsID::Input_A_InputType, SettingsID::Input_A_Data, SettingsID::Input_A_ExtraData); @@ -209,6 +215,9 @@ static void apply_controller_profiles(void) case N64ControllerPak::RumblePak: plugin = PLUGIN_RAW; break; + case N64ControllerPak::TransferPak: + plugin = PLUGIN_TRANSFER_PAK; + break; default: plugin = PLUGIN_NONE; break; @@ -221,6 +230,37 @@ static void apply_controller_profiles(void) } } +static void apply_gameboy_settings(void) +{ + SettingsID gameBoyRomSettings[] = + { + SettingsID::Core_Gameboy_P1_Rom, + SettingsID::Core_Gameboy_P2_Rom, + SettingsID::Core_Gameboy_P3_Rom, + SettingsID::Core_Gameboy_P4_Rom, + }; + + SettingsID gameBoySaveSettings[] = + { + SettingsID::Core_Gameboy_P1_Save, + SettingsID::Core_Gameboy_P2_Save, + SettingsID::Core_Gameboy_P3_Save, + SettingsID::Core_Gameboy_P4_Save, + }; + + for (int i = 0; i < NUM_CONTROLLERS; i++) + { + InputProfile* profile = &l_InputProfiles[i]; + SettingsID gameBoyRomSettingId = gameBoyRomSettings[i]; + SettingsID gameBoySaveSettingId = gameBoySaveSettings[i]; + + CoreSettingsSetValue(gameBoyRomSettingId, profile->GameboyRom); + CoreSettingsSetValue(gameBoySaveSettingId, profile->GameboySave); + } + + CoreSettingsSave(); +} + static void open_controllers(void) { for (int i = 0; i < NUM_CONTROLLERS; i++) @@ -482,6 +522,9 @@ EXPORT m64p_error CALL PluginConfig() // apply profiles apply_controller_profiles(); + // apply gameboy settings + apply_gameboy_settings(); + // open controllers open_controllers(); @@ -620,6 +663,17 @@ EXPORT void CALL InitiateControllers(CONTROL_INFO ControlInfo) l_ControlInfo = ControlInfo; l_HasControlInfo = true; + + std::cout << "InitiateControllers()" << std::endl; + + // load settings + load_settings(); + // apply profiles + apply_controller_profiles(); + // apply gameboy settings + apply_gameboy_settings(); + // open controllers + open_controllers(); } EXPORT void CALL ReadController(int Control, unsigned char *Command) @@ -628,12 +682,6 @@ EXPORT void CALL ReadController(int Control, unsigned char *Command) EXPORT int CALL RomOpen(void) { - // reload settings - load_settings(); - // apply profiles - apply_controller_profiles(); - // open controllers - open_controllers(); return 1; }