From 7c95032e3a58a1170b24d16b76acba6158e935bc Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Fri, 28 Dec 2018 19:24:56 -0500 Subject: [PATCH 01/19] Add multiple input profile support Only supported in the Qt frontend. --- src/citra/config.cpp | 1 + src/citra_qt/configuration/config.cpp | 143 ++++++---- .../configuration/configure_dialog.cpp | 1 + .../configuration/configure_input.cpp | 97 ++++++- src/citra_qt/configuration/configure_input.h | 8 + src/citra_qt/configuration/configure_input.ui | 244 +++++++++++------- .../configuration/configure_motion_touch.cpp | 1 + src/citra_qt/main.cpp | 5 + src/core/settings.cpp | 48 ++++ src/core/settings.h | 32 ++- 10 files changed, 415 insertions(+), 165 deletions(-) diff --git a/src/citra/config.cpp b/src/citra/config.cpp index 3cd7bec88..563c3b953 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -71,6 +71,7 @@ static const std::array, Settings::NativeAnalog::NumAnalogs> void Config::ReadValues() { // Controls + // TODO: add multiple input profile support for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); Settings::values.buttons[i] = diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index dcbe18122..72c4b9917 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -50,45 +50,69 @@ const std::array, Settings::NativeAnalog::NumAnalogs> Config: void Config::ReadValues() { qt_config->beginGroup("Controls"); - for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { - std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); - Settings::values.buttons[i] = - ReadSetting(Settings::NativeButton::mapping[i], QString::fromStdString(default_param)) + + Settings::values.profile = ReadSetting("profile", 0).toInt(); + + const auto append_profile = [this] { + Settings::InputProfile profile; + profile.name = ReadSetting("name", "default").toString().toStdString(); + for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { + std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); + profile.buttons[i] = ReadSetting(Settings::NativeButton::mapping[i], + QString::fromStdString(default_param)) + .toString() + .toStdString(); + if (profile.buttons.empty()) + profile.buttons[i] = default_param; + } + for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { + std::string default_param = InputCommon::GenerateAnalogParamFromKeys( + default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], + default_analogs[i][3], default_analogs[i][4], 0.5f); + profile.analogs[i] = ReadSetting(Settings::NativeAnalog::mapping[i], + QString::fromStdString(default_param)) + .toString() + .toStdString(); + if (profile.analogs[i].empty()) + profile.analogs[i] = default_param; + } + profile.motion_device = + ReadSetting("motion_device", + "engine:motion_emu,update_period:100,sensitivity:0.01,tilt_clamp:90.0") .toString() .toStdString(); - if (Settings::values.buttons[i].empty()) - Settings::values.buttons[i] = default_param; - } - - for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { - std::string default_param = InputCommon::GenerateAnalogParamFromKeys( - default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], - default_analogs[i][3], default_analogs[i][4], 0.5f); - Settings::values.analogs[i] = - ReadSetting(Settings::NativeAnalog::mapping[i], QString::fromStdString(default_param)) + profile.touch_device = + ReadSetting("touch_device", "engine:emu_window").toString().toStdString(); + profile.udp_input_address = + ReadSetting("udp_input_address", InputCommon::CemuhookUDP::DEFAULT_ADDR) .toString() .toStdString(); - if (Settings::values.analogs[i].empty()) - Settings::values.analogs[i] = default_param; + profile.udp_input_port = static_cast( + ReadSetting("udp_input_port", InputCommon::CemuhookUDP::DEFAULT_PORT).toInt()); + profile.udp_pad_index = static_cast(ReadSetting("udp_pad_index", 0).toUInt()); + Settings::values.profiles.emplace_back(std::move(profile)); + }; + + int size = qt_config->beginReadArray("profiles"); + + for (int i = 0; i < size; ++i) { + qt_config->setArrayIndex(i); + append_profile(); } - Settings::values.motion_device = - ReadSetting("motion_device", - "engine:motion_emu,update_period:100,sensitivity:0.01,tilt_clamp:90.0") - .toString() - .toStdString(); - Settings::values.touch_device = - ReadSetting("touch_device", "engine:emu_window").toString().toStdString(); + qt_config->endArray(); - Settings::values.udp_input_address = - ReadSetting("udp_input_address", InputCommon::CemuhookUDP::DEFAULT_ADDR) - .toString() - .toStdString(); - Settings::values.udp_input_port = static_cast( - ReadSetting("udp_input_port", InputCommon::CemuhookUDP::DEFAULT_PORT).toInt()); - Settings::values.udp_pad_index = static_cast(ReadSetting("udp_pad_index", 0).toUInt()); + if (Settings::values.profile <= size) { + Settings::values.profile = 0; + } - qt_config->endGroup(); + if (size == 0) { + append_profile(); + } + + Settings::LoadProfile(Settings::values.profile); + + qt_config->endArray(); qt_config->beginGroup("Core"); Settings::values.use_cpu_jit = ReadSetting("use_cpu_jit", true).toBool(); @@ -257,7 +281,7 @@ void Config::ReadValues() { UISettings::values.game_dir_deprecated = ReadSetting("gameListRootDir", ".").toString(); UISettings::values.game_dir_deprecated_deepscan = ReadSetting("gameListDeepScan", false).toBool(); - int size = qt_config->beginReadArray("gamedirs"); + size = qt_config->beginReadArray("gamedirs"); for (int i = 0; i < size; ++i) { qt_config->setArrayIndex(i); UISettings::GameDir game_dir; @@ -267,8 +291,8 @@ void Config::ReadValues() { UISettings::values.game_dirs.append(game_dir); } qt_config->endArray(); - // create NAND and SD card directories if empty, these are not removable through the UI, also - // carries over old game list settings if present + // create NAND and SD card directories if empty, these are not removable through the UI, + // also carries over old game list settings if present if (UISettings::values.game_dirs.isEmpty()) { UISettings::GameDir game_dir; game_dir.path = "INSTALLED"; @@ -352,29 +376,36 @@ void Config::ReadValues() { void Config::SaveValues() { qt_config->beginGroup("Controls"); - for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { - std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); - WriteSetting(QString::fromStdString(Settings::NativeButton::mapping[i]), - QString::fromStdString(Settings::values.buttons[i]), - QString::fromStdString(default_param)); + WriteSetting("profile", Settings::values.profile, 0); + qt_config->beginWriteArray("profiles"); + for (int p = 0; p < Settings::values.profiles.size(); ++p) { + qt_config->setArrayIndex(p); + const auto& profile = Settings::values.profiles[p]; + for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { + std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); + WriteSetting(QString::fromStdString(Settings::NativeButton::mapping[i]), + QString::fromStdString(profile.buttons[i]), + QString::fromStdString(default_param)); + } + for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { + std::string default_param = InputCommon::GenerateAnalogParamFromKeys( + default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], + default_analogs[i][3], default_analogs[i][4], 0.5f); + WriteSetting(QString::fromStdString(Settings::NativeAnalog::mapping[i]), + QString::fromStdString(profile.analogs[i]), + QString::fromStdString(default_param)); + } + WriteSetting("motion_device", QString::fromStdString(profile.motion_device), + "engine:motion_emu,update_period:100,sensitivity:0.01,tilt_clamp:90.0"); + WriteSetting("touch_device", QString::fromStdString(profile.touch_device), + "engine:emu_window"); + WriteSetting("udp_input_address", QString::fromStdString(profile.udp_input_address), + InputCommon::CemuhookUDP::DEFAULT_ADDR); + WriteSetting("udp_input_port", profile.udp_input_port, + InputCommon::CemuhookUDP::DEFAULT_PORT); + WriteSetting("udp_pad_index", profile.udp_pad_index, 0); } - for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { - std::string default_param = InputCommon::GenerateAnalogParamFromKeys( - default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], - default_analogs[i][3], default_analogs[i][4], 0.5f); - WriteSetting(QString::fromStdString(Settings::NativeAnalog::mapping[i]), - QString::fromStdString(Settings::values.analogs[i]), - QString::fromStdString(default_param)); - } - WriteSetting("motion_device", QString::fromStdString(Settings::values.motion_device), - "engine:motion_emu,update_period:100,sensitivity:0.01,tilt_clamp:90.0"); - WriteSetting("touch_device", QString::fromStdString(Settings::values.touch_device), - "engine:emu_window"); - WriteSetting("udp_input_address", QString::fromStdString(Settings::values.udp_input_address), - InputCommon::CemuhookUDP::DEFAULT_ADDR); - WriteSetting("udp_input_port", Settings::values.udp_input_port, - InputCommon::CemuhookUDP::DEFAULT_PORT); - WriteSetting("udp_pad_index", Settings::values.udp_pad_index, 0); + qt_config->endArray(); qt_config->endGroup(); qt_config->beginGroup("Core"); diff --git a/src/citra_qt/configuration/configure_dialog.cpp b/src/citra_qt/configuration/configure_dialog.cpp index 3f13401f1..1d55f8934 100644 --- a/src/citra_qt/configuration/configure_dialog.cpp +++ b/src/citra_qt/configuration/configure_dialog.cpp @@ -42,6 +42,7 @@ void ConfigureDialog::applyConfiguration() { ui->generalTab->applyConfiguration(); ui->systemTab->applyConfiguration(); ui->inputTab->applyConfiguration(); + ui->inputTab->applyProfile(); ui->graphicsTab->applyConfiguration(); ui->audioTab->applyConfiguration(); ui->cameraTab->applyConfiguration(); diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index b0cc53395..fdb0ef8d6 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -99,6 +100,12 @@ ConfigureInput::ConfigureInput(QWidget* parent) ui->setupUi(this); setFocusPolicy(Qt::ClickFocus); + for (int i = 0; i < Settings::values.profiles.size(); ++i) { + ui->profile->addItem(QString::fromStdString(Settings::values.profiles[i].name)); + } + + ui->profile->setCurrentIndex(Settings::values.profile); + button_map = { ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, ui->buttonDpadUp, ui->buttonDpadDown, ui->buttonDpadLeft, ui->buttonDpadRight, ui->buttonL, ui->buttonR, @@ -131,7 +138,11 @@ ConfigureInput::ConfigureInput(QWidget* parent) connect(button_map[button_id], &QPushButton::released, [=]() { handleClick( button_map[button_id], - [=](const Common::ParamPackage& params) { buttons_param[button_id] = params; }, + [=](const Common::ParamPackage& params) { + buttons_param[button_id] = params; + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, InputCommon::Polling::DeviceType::Button); }); connect(button_map[button_id], &QPushButton::customContextMenuRequested, @@ -140,11 +151,15 @@ ConfigureInput::ConfigureInput(QWidget* parent) context_menu.addAction(tr("Clear"), [&] { buttons_param[button_id].Clear(); button_map[button_id]->setText(tr("[not set]")); + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); }); context_menu.addAction(tr("Restore Default"), [&] { buttons_param[button_id] = Common::ParamPackage{ InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])}; button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); }); context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); }); @@ -157,12 +172,15 @@ ConfigureInput::ConfigureInput(QWidget* parent) analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy( Qt::CustomContextMenu); connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::released, [=]() { - handleClick(analog_map_buttons[analog_id][sub_button_id], - [=](const Common::ParamPackage& params) { - SetAnalogButton(params, analogs_param[analog_id], - analog_sub_buttons[sub_button_id]); - }, - InputCommon::Polling::DeviceType::Button); + handleClick( + analog_map_buttons[analog_id][sub_button_id], + [=](const Common::ParamPackage& params) { + SetAnalogButton(params, analogs_param[analog_id], + analog_sub_buttons[sub_button_id]); + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Button); }); connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { @@ -170,6 +188,8 @@ ConfigureInput::ConfigureInput(QWidget* parent) context_menu.addAction(tr("Clear"), [&] { analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]); analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]")); + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); }); context_menu.addAction(tr("Restore Default"), [&] { Common::ParamPackage params{InputCommon::GenerateKeyboardParam( @@ -178,6 +198,8 @@ ConfigureInput::ConfigureInput(QWidget* parent) analog_sub_buttons[sub_button_id]); analog_map_buttons[analog_id][sub_button_id]->setText(AnalogToText( analogs_param[analog_id], analog_sub_buttons[sub_button_id])); + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); }); context_menu.exec(analog_map_buttons[analog_id][sub_button_id]->mapToGlobal( menu_location)); @@ -189,7 +211,11 @@ ConfigureInput::ConfigureInput(QWidget* parent) "and then vertically.")); handleClick( analog_map_stick[analog_id], - [=](const Common::ParamPackage& params) { analogs_param[analog_id] = params; }, + [=](const Common::ParamPackage& params) { + analogs_param[analog_id] = params; + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, InputCommon::Polling::DeviceType::Analog); }); } @@ -200,6 +226,17 @@ ConfigureInput::ConfigureInput(QWidget* parent) }); connect(ui->buttonClearAll, &QPushButton::released, [this] { ClearAll(); }); connect(ui->buttonRestoreDefaults, &QPushButton::released, [this]() { restoreDefaults(); }); + connect(ui->buttonNew, &QPushButton::released, [this] { newProfile(); }); + connect(ui->buttonDelete, &QPushButton::released, [this] { deleteProfile(); }); + connect(ui->buttonRename, &QPushButton::released, [this] { renameProfile(); }); + + connect(ui->profile, static_cast(&QComboBox::currentIndexChanged), + [this](int i) { + applyConfiguration(); + Settings::SaveProfile(Settings::values.profile); + Settings::LoadProfile(i); + loadConfiguration(); + }); timeout_timer->setSingleShot(true); connect(timeout_timer.get(), &QTimer::timeout, [this]() { setPollingResult({}, true); }); @@ -230,6 +267,10 @@ void ConfigureInput::applyConfiguration() { [](const Common::ParamPackage& param) { return param.Serialize(); }); } +void ConfigureInput::applyProfile() { + Settings::values.profile = ui->profile->currentIndex(); +} + void ConfigureInput::loadConfiguration() { std::transform(Settings::values.buttons.begin(), Settings::values.buttons.end(), buttons_param.begin(), @@ -346,3 +387,43 @@ void ConfigureInput::keyPressEvent(QKeyEvent* event) { void ConfigureInput::retranslateUi() { ui->retranslateUi(this); } + +void ConfigureInput::newProfile() { + QString name = + QInputDialog::getText(this, tr("New Profile"), tr("Enter the name for the new profile.")); + if (name.isEmpty()) { + return; + } + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + Settings::CreateProfile(name.toStdString()); + ui->profile->addItem(name); + ui->profile->setCurrentIndex(Settings::values.profile); + loadConfiguration(); +} + +void ConfigureInput::deleteProfile() { + if (ui->profile->count() == 1) { + QMessageBox::critical(this, tr("Citra"), tr("You need to have 1 profile at least")); + return; + } + QMessageBox::StandardButton answer = QMessageBox::question( + this, tr("Delete Profile"), tr("Delete profile %1?").arg(ui->profile->currentText())); + if (answer != QMessageBox::Yes) { + return; + } + int index = ui->profile->currentIndex(); + ui->profile->removeItem(index); + ui->profile->setCurrentIndex(0); + Settings::DeleteProfile(index); + loadConfiguration(); +} + +void ConfigureInput::renameProfile() { + QString new_name = QInputDialog::getText(this, tr("Rename Profile"), tr("New name:")); + if (new_name.isEmpty()) { + return; + } + ui->profile->setItemText(ui->profile->currentIndex(), new_name); + Settings::RenameCurrentProfile(new_name.toStdString()); +} diff --git a/src/citra_qt/configuration/configure_input.h b/src/citra_qt/configuration/configure_input.h index aa3cce7a5..7c4b02f7a 100644 --- a/src/citra_qt/configuration/configure_input.h +++ b/src/citra_qt/configuration/configure_input.h @@ -39,6 +39,9 @@ public: /// Load configuration settings. void loadConfiguration(); + // Save the current input profile index + void applyProfile(); + private: std::unique_ptr ui; @@ -91,4 +94,9 @@ private: /// Handle key press events. void keyPressEvent(QKeyEvent* event) override; + + /// input profiles + void newProfile(); + void deleteProfile(); + void renameProfile(); }; diff --git a/src/citra_qt/configuration/configure_input.ui b/src/citra_qt/configuration/configure_input.ui index 8421adf09..498e08b1d 100644 --- a/src/citra_qt/configuration/configure_input.ui +++ b/src/citra_qt/configuration/configure_input.ui @@ -6,8 +6,8 @@ 0 0 - 370 - 534 + 376 + 535 @@ -555,103 +555,155 @@ - + - - - - 0 - 0 - - - - - 0 - 0 - - - - - 0 - 0 - - - - Qt::LeftToRight - - - Motion / Touch... - - + + + + + Profile + + + + + + + + + + New + + + + + + + Delete + + + + + + + Rename + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 0 - 0 - - - - Qt::LeftToRight - - - Clear All - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 0 - 0 - - - - Qt::LeftToRight - - - Restore Defaults - - + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Motion / Touch... + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Clear All + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Restore Defaults + + + + diff --git a/src/citra_qt/configuration/configure_motion_touch.cpp b/src/citra_qt/configuration/configure_motion_touch.cpp index b1d04f0d2..494c5bd21 100644 --- a/src/citra_qt/configuration/configure_motion_touch.cpp +++ b/src/citra_qt/configuration/configure_motion_touch.cpp @@ -270,6 +270,7 @@ void ConfigureMotionTouch::applyConfiguration() { Settings::values.udp_input_address = ui->udp_server->text().toStdString(); Settings::values.udp_input_port = static_cast(ui->udp_port->text().toInt()); Settings::values.udp_pad_index = static_cast(ui->udp_pad_index->currentIndex()); + Settings::SaveProfile(Settings::values.profile); InputCommon::ReloadInputDevices(); accept(); diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 69d8636dc..f7206c93d 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -1326,6 +1326,8 @@ void GMainWindow::OnConfigure() { connect(&configureDialog, &ConfigureDialog::languageChanged, this, &GMainWindow::OnLanguageChanged); auto old_theme = UISettings::values.theme; + const int old_profile = Settings::values.profile; + auto old_profiles = Settings::values.profiles; const bool old_discord_presence = UISettings::values.enable_discord_presence; auto result = configureDialog.exec(); if (result == QDialog::Accepted) { @@ -1338,6 +1340,9 @@ void GMainWindow::OnConfigure() { SyncMenuUISettings(); game_list->RefreshGameDirectory(); config->Save(); + } else { + Settings::values.profiles = old_profiles; + Settings::LoadProfile(old_profile); } } diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 8bdf5689b..ec7af5b5a 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include "audio_core/dsp_interface.h" #include "core/core.h" #include "core/gdbstub/gdbstub.h" @@ -99,4 +100,51 @@ void LogSettings() { LogSetting("Debugging_GdbstubPort", Settings::values.gdbstub_port); } +void LoadProfile(int index) { + const auto& profile = values.profiles[index]; + values.profile = index; + values.analogs = profile.analogs; + values.buttons = profile.buttons; + values.motion_device = profile.motion_device; + values.touch_device = profile.touch_device; + values.udp_input_address = profile.udp_input_address; + values.udp_input_port = profile.udp_input_port; + values.udp_pad_index = profile.udp_pad_index; +} + +void SaveProfile(int index) { + auto& profile = values.profiles[index]; + profile.analogs = values.analogs; + profile.buttons = values.buttons; + profile.motion_device = values.motion_device; + profile.touch_device = values.touch_device; + profile.udp_input_address = values.udp_input_address; + profile.udp_input_port = values.udp_input_port; + profile.udp_pad_index = values.udp_pad_index; +} + +void CreateProfile(std::string name) { + InputProfile profile; + profile.name = std::move(name); + profile.analogs = values.analogs; + profile.buttons = values.buttons; + profile.motion_device = values.motion_device; + profile.touch_device = values.touch_device; + profile.udp_input_address = values.udp_input_address; + profile.udp_input_port = values.udp_input_port; + profile.udp_pad_index = values.udp_pad_index; + values.profiles.push_back(profile); + values.profile = static_cast(values.profiles.size()) - 1; + LoadProfile(values.profile); +} + +void DeleteProfile(int index) { + values.profiles.erase(values.profiles.begin() + index); + LoadProfile(0); +} + +void RenameCurrentProfile(std::string new_name) { + values.profiles[values.profile].name = std::move(new_name); +} + } // namespace Settings diff --git a/src/core/settings.h b/src/core/settings.h index 929db156c..e179b610d 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "common/common_types.h" #include "core/hle/service/cam/cam.h" @@ -92,11 +93,8 @@ static const std::array mapping = {{ }}; } // namespace NativeAnalog -struct Values { - // CheckNew3DS - bool is_new_3ds; - - // Controls +struct InputProfile { + std::string name; std::array buttons; std::array analogs; std::string motion_device; @@ -104,6 +102,23 @@ struct Values { std::string udp_input_address; u16 udp_input_port; u8 udp_pad_index; +}; + +struct Values { + // CheckNew3DS + bool is_new_3ds; + + // Current controls + std::array buttons; + std::array analogs; + std::string motion_device; + std::string touch_device; + std::string udp_input_address; + u16 udp_input_port; + u8 udp_pad_index; + + int profile; ///< The current input profile index + std::vector profiles; ///< The list of input profiles // Core bool use_cpu_jit; @@ -176,4 +191,11 @@ static constexpr int REGION_VALUE_AUTO_SELECT = -1; void Apply(); void LogSettings(); + +// input profiles +void LoadProfile(int index); +void SaveProfile(int index); +void CreateProfile(std::string name); +void DeleteProfile(int index); +void RenameCurrentProfile(std::string new_name); } // namespace Settings From 90965525acb37d0349cc558d3b721e150e53ba3d Mon Sep 17 00:00:00 2001 From: Mat M Date: Fri, 28 Dec 2018 21:00:09 -0500 Subject: [PATCH 02/19] Apply suggestions from code review Co-Authored-By: valentinvanelslande --- src/citra_qt/configuration/config.cpp | 2 +- src/citra_qt/configuration/configure_input.cpp | 12 +++++++----- src/citra_qt/main.cpp | 2 +- src/core/settings.cpp | 2 +- src/core/settings.h | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 72c4b9917..68d7ad065 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -93,7 +93,7 @@ void Config::ReadValues() { Settings::values.profiles.emplace_back(std::move(profile)); }; - int size = qt_config->beginReadArray("profiles"); + const int num_input_profiles = qt_config->beginReadArray("profiles"); for (int i = 0; i < size; ++i) { qt_config->setArrayIndex(i); diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index fdb0ef8d6..efc893e07 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -100,7 +100,9 @@ ConfigureInput::ConfigureInput(QWidget* parent) ui->setupUi(this); setFocusPolicy(Qt::ClickFocus); - for (int i = 0; i < Settings::values.profiles.size(); ++i) { + for (const auto& profile : Settings::values::profiles) { + ui->profile->addItem(QString::fromStdString(profile.name)); + } ui->profile->addItem(QString::fromStdString(Settings::values.profiles[i].name)); } @@ -389,7 +391,7 @@ void ConfigureInput::retranslateUi() { } void ConfigureInput::newProfile() { - QString name = + const QString name = QInputDialog::getText(this, tr("New Profile"), tr("Enter the name for the new profile.")); if (name.isEmpty()) { return; @@ -407,12 +409,12 @@ void ConfigureInput::deleteProfile() { QMessageBox::critical(this, tr("Citra"), tr("You need to have 1 profile at least")); return; } - QMessageBox::StandardButton answer = QMessageBox::question( + const auto answer = QMessageBox::question( this, tr("Delete Profile"), tr("Delete profile %1?").arg(ui->profile->currentText())); if (answer != QMessageBox::Yes) { return; } - int index = ui->profile->currentIndex(); + const int index = ui->profile->currentIndex(); ui->profile->removeItem(index); ui->profile->setCurrentIndex(0); Settings::DeleteProfile(index); @@ -420,7 +422,7 @@ void ConfigureInput::deleteProfile() { } void ConfigureInput::renameProfile() { - QString new_name = QInputDialog::getText(this, tr("Rename Profile"), tr("New name:")); + const QString new_name = QInputDialog::getText(this, tr("Rename Profile"), tr("New name:")); if (new_name.isEmpty()) { return; } diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index f7206c93d..28d26e6ed 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -1327,7 +1327,7 @@ void GMainWindow::OnConfigure() { &GMainWindow::OnLanguageChanged); auto old_theme = UISettings::values.theme; const int old_profile = Settings::values.profile; - auto old_profiles = Settings::values.profiles; + const auto old_profiles = Settings::values.profiles; const bool old_discord_presence = UISettings::values.enable_discord_presence; auto result = configureDialog.exec(); if (result == QDialog::Accepted) { diff --git a/src/core/settings.cpp b/src/core/settings.cpp index ec7af5b5a..da6a97d81 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -133,7 +133,7 @@ void CreateProfile(std::string name) { profile.udp_input_address = values.udp_input_address; profile.udp_input_port = values.udp_input_port; profile.udp_pad_index = values.udp_pad_index; - values.profiles.push_back(profile); + values.profiles.push_back(std::move(profile)); values.profile = static_cast(values.profiles.size()) - 1; LoadProfile(values.profile); } diff --git a/src/core/settings.h b/src/core/settings.h index e179b610d..50e02f0df 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -117,8 +117,8 @@ struct Values { u16 udp_input_port; u8 udp_pad_index; - int profile; ///< The current input profile index - std::vector profiles; ///< The list of input profiles + int current_input_profile; ///< The current input profile index + std::vector input_profiles; ///< The list of input profiles // Core bool use_cpu_jit; From bf93b9465877b198ce1a0770fbb035079cce5c63 Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Fri, 28 Dec 2018 21:13:57 -0500 Subject: [PATCH 03/19] fixes --- src/citra_qt/configuration/config.cpp | 21 +- .../configuration/configure_input.cpp | 255 +++++++++--------- .../configuration/configure_motion_touch.cpp | 2 +- src/citra_qt/main.cpp | 8 +- src/core/settings.cpp | 8 +- src/core/settings.h | 2 +- 6 files changed, 148 insertions(+), 148 deletions(-) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 68d7ad065..5b5708fdf 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -51,7 +51,7 @@ const std::array, Settings::NativeAnalog::NumAnalogs> Config: void Config::ReadValues() { qt_config->beginGroup("Controls"); - Settings::values.profile = ReadSetting("profile", 0).toInt(); + Settings::values.current_input_profile = ReadSetting("profile", 0).toInt(); const auto append_profile = [this] { Settings::InputProfile profile; @@ -95,22 +95,23 @@ void Config::ReadValues() { const int num_input_profiles = qt_config->beginReadArray("profiles"); - for (int i = 0; i < size; ++i) { + for (int i = 0; i < num_input_profiles; ++i) { qt_config->setArrayIndex(i); append_profile(); } qt_config->endArray(); - if (Settings::values.profile <= size) { - Settings::values.profile = 0; + if (Settings::values.current_input_profile <= num_input_profiles) { + Settings::values.current_input_profile = 0; } - if (size == 0) { + // create a input profile if no input profiles exist, with the default or old settings + if (num_input_profiles == 0) { append_profile(); } - Settings::LoadProfile(Settings::values.profile); + Settings::LoadProfile(Settings::values.current_input_profile); qt_config->endArray(); @@ -281,7 +282,7 @@ void Config::ReadValues() { UISettings::values.game_dir_deprecated = ReadSetting("gameListRootDir", ".").toString(); UISettings::values.game_dir_deprecated_deepscan = ReadSetting("gameListDeepScan", false).toBool(); - size = qt_config->beginReadArray("gamedirs"); + int size = qt_config->beginReadArray("gamedirs"); for (int i = 0; i < size; ++i) { qt_config->setArrayIndex(i); UISettings::GameDir game_dir; @@ -376,10 +377,10 @@ void Config::ReadValues() { void Config::SaveValues() { qt_config->beginGroup("Controls"); - WriteSetting("profile", Settings::values.profile, 0); + WriteSetting("profile", Settings::values.current_input_profile, 0); qt_config->beginWriteArray("profiles"); - for (int p = 0; p < Settings::values.profiles.size(); ++p) { - qt_config->setArrayIndex(p); + for (std::size_t p = 0; p < Settings::values.inprofiles.size(); ++p) { + qt_config->setArrayIndex(static_cast(p)); const auto& profile = Settings::values.profiles[p]; for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index efc893e07..27a400311 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -103,161 +103,160 @@ ConfigureInput::ConfigureInput(QWidget* parent) for (const auto& profile : Settings::values::profiles) { ui->profile->addItem(QString::fromStdString(profile.name)); } - ui->profile->addItem(QString::fromStdString(Settings::values.profiles[i].name)); - } + ui->profile->addItem(QString::fromStdString(Settings::values.profiles[i].name)); +} - ui->profile->setCurrentIndex(Settings::values.profile); +ui->profile->setCurrentIndex(Settings::values.current_input_profile); - button_map = { - ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, ui->buttonDpadUp, - ui->buttonDpadDown, ui->buttonDpadLeft, ui->buttonDpadRight, ui->buttonL, ui->buttonR, - ui->buttonStart, ui->buttonSelect, ui->buttonZL, ui->buttonZR, ui->buttonHome, - }; +button_map = { + ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, ui->buttonDpadUp, + ui->buttonDpadDown, ui->buttonDpadLeft, ui->buttonDpadRight, ui->buttonL, ui->buttonR, + ui->buttonStart, ui->buttonSelect, ui->buttonZL, ui->buttonZR, ui->buttonHome, +}; - analog_map_buttons = {{ - { - ui->buttonCircleUp, - ui->buttonCircleDown, - ui->buttonCircleLeft, - ui->buttonCircleRight, - ui->buttonCircleMod, - }, - { - ui->buttonCStickUp, - ui->buttonCStickDown, - ui->buttonCStickLeft, - ui->buttonCStickRight, - nullptr, - }, - }}; +analog_map_buttons = {{ + { + ui->buttonCircleUp, + ui->buttonCircleDown, + ui->buttonCircleLeft, + ui->buttonCircleRight, + ui->buttonCircleMod, + }, + { + ui->buttonCStickUp, + ui->buttonCStickDown, + ui->buttonCStickLeft, + ui->buttonCStickRight, + nullptr, + }, +}}; - analog_map_stick = {ui->buttonCircleAnalog, ui->buttonCStickAnalog}; +analog_map_stick = {ui->buttonCircleAnalog, ui->buttonCStickAnalog}; - for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) { - if (!button_map[button_id]) +for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) { + if (!button_map[button_id]) + continue; + button_map[button_id]->setContextMenuPolicy(Qt::CustomContextMenu); + connect(button_map[button_id], &QPushButton::released, [=]() { + handleClick( + button_map[button_id], + [=](const Common::ParamPackage& params) { + buttons_param[button_id] = params; + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Button); + }); + connect(button_map[button_id], &QPushButton::customContextMenuRequested, + [=](const QPoint& menu_location) { + QMenu context_menu; + context_menu.addAction(tr("Clear"), [&] { + buttons_param[button_id].Clear(); + button_map[button_id]->setText(tr("[not set]")); + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }); + context_menu.addAction(tr("Restore Default"), [&] { + buttons_param[button_id] = Common::ParamPackage{ + InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])}; + button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }); + context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); + }); +} + +for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { + for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { + if (!analog_map_buttons[analog_id][sub_button_id]) continue; - button_map[button_id]->setContextMenuPolicy(Qt::CustomContextMenu); - connect(button_map[button_id], &QPushButton::released, [=]() { + analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy(Qt::CustomContextMenu); + connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::released, [=]() { handleClick( - button_map[button_id], + analog_map_buttons[analog_id][sub_button_id], [=](const Common::ParamPackage& params) { - buttons_param[button_id] = params; + SetAnalogButton(params, analogs_param[analog_id], + analog_sub_buttons[sub_button_id]); applyConfiguration(); Settings::SaveProfile(ui->profile->currentIndex()); }, InputCommon::Polling::DeviceType::Button); }); - connect(button_map[button_id], &QPushButton::customContextMenuRequested, - [=](const QPoint& menu_location) { + connect(analog_map_buttons[analog_id][sub_button_id], + &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { QMenu context_menu; context_menu.addAction(tr("Clear"), [&] { - buttons_param[button_id].Clear(); - button_map[button_id]->setText(tr("[not set]")); + analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]); + analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]")); applyConfiguration(); Settings::SaveProfile(ui->profile->currentIndex()); }); context_menu.addAction(tr("Restore Default"), [&] { - buttons_param[button_id] = Common::ParamPackage{ - InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])}; - button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }); - context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); - }); - } - - for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { - for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { - if (!analog_map_buttons[analog_id][sub_button_id]) - continue; - analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy( - Qt::CustomContextMenu); - connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::released, [=]() { - handleClick( - analog_map_buttons[analog_id][sub_button_id], - [=](const Common::ParamPackage& params) { + Common::ParamPackage params{InputCommon::GenerateKeyboardParam( + Config::default_analogs[analog_id][sub_button_id])}; SetAnalogButton(params, analogs_param[analog_id], analog_sub_buttons[sub_button_id]); + analog_map_buttons[analog_id][sub_button_id]->setText(AnalogToText( + analogs_param[analog_id], analog_sub_buttons[sub_button_id])); applyConfiguration(); Settings::SaveProfile(ui->profile->currentIndex()); - }, - InputCommon::Polling::DeviceType::Button); - }); - connect(analog_map_buttons[analog_id][sub_button_id], - &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { - QMenu context_menu; - context_menu.addAction(tr("Clear"), [&] { - analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]); - analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]")); - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }); - context_menu.addAction(tr("Restore Default"), [&] { - Common::ParamPackage params{InputCommon::GenerateKeyboardParam( - Config::default_analogs[analog_id][sub_button_id])}; - SetAnalogButton(params, analogs_param[analog_id], - analog_sub_buttons[sub_button_id]); - analog_map_buttons[analog_id][sub_button_id]->setText(AnalogToText( - analogs_param[analog_id], analog_sub_buttons[sub_button_id])); - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }); - context_menu.exec(analog_map_buttons[analog_id][sub_button_id]->mapToGlobal( - menu_location)); }); - } - connect(analog_map_stick[analog_id], &QPushButton::released, [=]() { - QMessageBox::information(this, tr("Information"), - tr("After pressing OK, first move your joystick horizontally, " - "and then vertically.")); - handleClick( - analog_map_stick[analog_id], - [=](const Common::ParamPackage& params) { - analogs_param[analog_id] = params; - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }, - InputCommon::Polling::DeviceType::Analog); - }); + context_menu.exec( + analog_map_buttons[analog_id][sub_button_id]->mapToGlobal(menu_location)); + }); } - - connect(ui->buttonMotionTouch, &QPushButton::released, [this] { - QDialog* motion_touch_dialog = new ConfigureMotionTouch(this); - return motion_touch_dialog->exec(); - }); - connect(ui->buttonClearAll, &QPushButton::released, [this] { ClearAll(); }); - connect(ui->buttonRestoreDefaults, &QPushButton::released, [this]() { restoreDefaults(); }); - connect(ui->buttonNew, &QPushButton::released, [this] { newProfile(); }); - connect(ui->buttonDelete, &QPushButton::released, [this] { deleteProfile(); }); - connect(ui->buttonRename, &QPushButton::released, [this] { renameProfile(); }); - - connect(ui->profile, static_cast(&QComboBox::currentIndexChanged), - [this](int i) { + connect(analog_map_stick[analog_id], &QPushButton::released, [=]() { + QMessageBox::information(this, tr("Information"), + tr("After pressing OK, first move your joystick horizontally, " + "and then vertically.")); + handleClick( + analog_map_stick[analog_id], + [=](const Common::ParamPackage& params) { + analogs_param[analog_id] = params; applyConfiguration(); - Settings::SaveProfile(Settings::values.profile); - Settings::LoadProfile(i); - loadConfiguration(); - }); - - timeout_timer->setSingleShot(true); - connect(timeout_timer.get(), &QTimer::timeout, [this]() { setPollingResult({}, true); }); - - connect(poll_timer.get(), &QTimer::timeout, [this]() { - Common::ParamPackage params; - for (auto& poller : device_pollers) { - params = poller->GetNextInput(); - if (params.Has("engine")) { - setPollingResult(params, false); - return; - } - } + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Analog); }); +} - this->loadConfiguration(); +connect(ui->buttonMotionTouch, &QPushButton::released, [this] { + QDialog* motion_touch_dialog = new ConfigureMotionTouch(this); + return motion_touch_dialog->exec(); +}); +connect(ui->buttonClearAll, &QPushButton::released, [this] { ClearAll(); }); +connect(ui->buttonRestoreDefaults, &QPushButton::released, [this]() { restoreDefaults(); }); +connect(ui->buttonNew, &QPushButton::released, [this] { newProfile(); }); +connect(ui->buttonDelete, &QPushButton::released, [this] { deleteProfile(); }); +connect(ui->buttonRename, &QPushButton::released, [this] { renameProfile(); }); - // TODO(wwylele): enable this when we actually emulate it - ui->buttonHome->setEnabled(false); +connect(ui->profile, static_cast(&QComboBox::currentIndexChanged), + [this](int i) { + applyConfiguration(); + Settings::SaveProfile(Settings::values.current_input_profile); + Settings::LoadProfile(i); + loadConfiguration(); + }); + +timeout_timer->setSingleShot(true); +connect(timeout_timer.get(), &QTimer::timeout, [this]() { setPollingResult({}, true); }); + +connect(poll_timer.get(), &QTimer::timeout, [this]() { + Common::ParamPackage params; + for (auto& poller : device_pollers) { + params = poller->GetNextInput(); + if (params.Has("engine")) { + setPollingResult(params, false); + return; + } + } +}); + +this->loadConfiguration(); + +// TODO(wwylele): enable this when we actually emulate it +ui->buttonHome->setEnabled(false); } ConfigureInput::~ConfigureInput() = default; @@ -270,7 +269,7 @@ void ConfigureInput::applyConfiguration() { } void ConfigureInput::applyProfile() { - Settings::values.profile = ui->profile->currentIndex(); + Settings::values.current_input_profile = ui->profile->currentIndex(); } void ConfigureInput::loadConfiguration() { @@ -400,7 +399,7 @@ void ConfigureInput::newProfile() { Settings::SaveProfile(ui->profile->currentIndex()); Settings::CreateProfile(name.toStdString()); ui->profile->addItem(name); - ui->profile->setCurrentIndex(Settings::values.profile); + ui->profile->setCurrentIndex(Settings::values.current_input_profile); loadConfiguration(); } diff --git a/src/citra_qt/configuration/configure_motion_touch.cpp b/src/citra_qt/configuration/configure_motion_touch.cpp index 494c5bd21..289570beb 100644 --- a/src/citra_qt/configuration/configure_motion_touch.cpp +++ b/src/citra_qt/configuration/configure_motion_touch.cpp @@ -270,7 +270,7 @@ void ConfigureMotionTouch::applyConfiguration() { Settings::values.udp_input_address = ui->udp_server->text().toStdString(); Settings::values.udp_input_port = static_cast(ui->udp_port->text().toInt()); Settings::values.udp_pad_index = static_cast(ui->udp_pad_index->currentIndex()); - Settings::SaveProfile(Settings::values.profile); + Settings::SaveProfile(Settings::values.current_input_profile); InputCommon::ReloadInputDevices(); accept(); diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 28d26e6ed..0af691e70 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -1326,8 +1326,8 @@ void GMainWindow::OnConfigure() { connect(&configureDialog, &ConfigureDialog::languageChanged, this, &GMainWindow::OnLanguageChanged); auto old_theme = UISettings::values.theme; - const int old_profile = Settings::values.profile; - const auto old_profiles = Settings::values.profiles; + const int old_input_profile = Settings::values.current_input_profile; + const auto old_input_profiles = Settings::values.input_profiles; const bool old_discord_presence = UISettings::values.enable_discord_presence; auto result = configureDialog.exec(); if (result == QDialog::Accepted) { @@ -1341,8 +1341,8 @@ void GMainWindow::OnConfigure() { game_list->RefreshGameDirectory(); config->Save(); } else { - Settings::values.profiles = old_profiles; - Settings::LoadProfile(old_profile); + Settings::values.input_profiles = old_input_profiles; + Settings::LoadProfile(old_input_profile); } } diff --git a/src/core/settings.cpp b/src/core/settings.cpp index da6a97d81..1d818dcab 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -102,7 +102,7 @@ void LogSettings() { void LoadProfile(int index) { const auto& profile = values.profiles[index]; - values.profile = index; + values.current_input_profile = index; values.analogs = profile.analogs; values.buttons = profile.buttons; values.motion_device = profile.motion_device; @@ -134,8 +134,8 @@ void CreateProfile(std::string name) { profile.udp_input_port = values.udp_input_port; profile.udp_pad_index = values.udp_pad_index; values.profiles.push_back(std::move(profile)); - values.profile = static_cast(values.profiles.size()) - 1; - LoadProfile(values.profile); + values.current_input_profile = static_cast(values.profiles.size()) - 1; + LoadProfile(values.current_input_profile); } void DeleteProfile(int index) { @@ -144,7 +144,7 @@ void DeleteProfile(int index) { } void RenameCurrentProfile(std::string new_name) { - values.profiles[values.profile].name = std::move(new_name); + values.profiles[values.current_input_profile].name = std::move(new_name); } } // namespace Settings diff --git a/src/core/settings.h b/src/core/settings.h index 50e02f0df..2bf6b5e6e 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -117,7 +117,7 @@ struct Values { u16 udp_input_port; u8 udp_pad_index; - int current_input_profile; ///< The current input profile index + int current_input_profile; ///< The current input profile index std::vector input_profiles; ///< The list of input profiles // Core From 6d0c50dfecc741a65e0e0186347d27488b06e70a Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Fri, 28 Dec 2018 21:14:44 -0500 Subject: [PATCH 04/19] more fixes --- src/citra_qt/configuration/config.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 5b5708fdf..403e2eb3e 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -379,9 +379,9 @@ void Config::SaveValues() { qt_config->beginGroup("Controls"); WriteSetting("profile", Settings::values.current_input_profile, 0); qt_config->beginWriteArray("profiles"); - for (std::size_t p = 0; p < Settings::values.inprofiles.size(); ++p) { + for (std::size_t p = 0; p < Settings::values.input_profiles.size(); ++p) { qt_config->setArrayIndex(static_cast(p)); - const auto& profile = Settings::values.profiles[p]; + const auto& profile = Settings::values.input_profiles[p]; for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); WriteSetting(QString::fromStdString(Settings::NativeButton::mapping[i]), From e420fb666f49b04ae82e63b57e900e91db20a267 Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Fri, 28 Dec 2018 21:15:18 -0500 Subject: [PATCH 05/19] another fix --- src/citra_qt/configuration/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 403e2eb3e..05698e592 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -90,7 +90,7 @@ void Config::ReadValues() { profile.udp_input_port = static_cast( ReadSetting("udp_input_port", InputCommon::CemuhookUDP::DEFAULT_PORT).toInt()); profile.udp_pad_index = static_cast(ReadSetting("udp_pad_index", 0).toUInt()); - Settings::values.profiles.emplace_back(std::move(profile)); + Settings::values.input_profiles.emplace_back(std::move(profile)); }; const int num_input_profiles = qt_config->beginReadArray("profiles"); From 16ebb38b4aef537d52b4afc133c070c0e5da1e0e Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Fri, 28 Dec 2018 21:23:43 -0500 Subject: [PATCH 06/19] more fixes --- src/core/settings.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 1d818dcab..72f333685 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -101,7 +101,7 @@ void LogSettings() { } void LoadProfile(int index) { - const auto& profile = values.profiles[index]; + const auto& profile = values.input_profiles[index]; values.current_input_profile = index; values.analogs = profile.analogs; values.buttons = profile.buttons; @@ -113,7 +113,7 @@ void LoadProfile(int index) { } void SaveProfile(int index) { - auto& profile = values.profiles[index]; + auto& profile = values.input_profiles[index]; profile.analogs = values.analogs; profile.buttons = values.buttons; profile.motion_device = values.motion_device; @@ -133,18 +133,18 @@ void CreateProfile(std::string name) { profile.udp_input_address = values.udp_input_address; profile.udp_input_port = values.udp_input_port; profile.udp_pad_index = values.udp_pad_index; - values.profiles.push_back(std::move(profile)); - values.current_input_profile = static_cast(values.profiles.size()) - 1; + values.input_profiles.push_back(std::move(profile)); + values.current_input_profile = static_cast(values.input_profiles.size()) - 1; LoadProfile(values.current_input_profile); } void DeleteProfile(int index) { - values.profiles.erase(values.profiles.begin() + index); + values.input_profiles(values.input_profiles.begin() + index); LoadProfile(0); } void RenameCurrentProfile(std::string new_name) { - values.profiles[values.current_input_profile].name = std::move(new_name); + values.input_profiles[values.current_input_profile].name = std::move(new_name); } } // namespace Settings From 39140bbff8838086941b8b5ddd40e0341244d90a Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Fri, 28 Dec 2018 21:24:01 -0500 Subject: [PATCH 07/19] another fix --- src/core/settings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 72f333685..667fe1b52 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -139,7 +139,7 @@ void CreateProfile(std::string name) { } void DeleteProfile(int index) { - values.input_profiles(values.input_profiles.begin() + index); + values.input_profiles.erase(values.input_profiles.begin() + index); LoadProfile(0); } From 860860397b47efa7019bece3b90c980ccf3c7102 Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Fri, 28 Dec 2018 21:26:50 -0500 Subject: [PATCH 08/19] more fixes --- .../configuration/configure_input.cpp | 251 +++++++++--------- 1 file changed, 125 insertions(+), 126 deletions(-) diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index 27a400311..5f05eff41 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -100,163 +100,162 @@ ConfigureInput::ConfigureInput(QWidget* parent) ui->setupUi(this); setFocusPolicy(Qt::ClickFocus); - for (const auto& profile : Settings::values::profiles) { + for (const auto& profile : Settings::values.input_profiles) { ui->profile->addItem(QString::fromStdString(profile.name)); } - ui->profile->addItem(QString::fromStdString(Settings::values.profiles[i].name)); -} -ui->profile->setCurrentIndex(Settings::values.current_input_profile); + ui->profile->setCurrentIndex(Settings::values.current_input_profile); -button_map = { - ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, ui->buttonDpadUp, - ui->buttonDpadDown, ui->buttonDpadLeft, ui->buttonDpadRight, ui->buttonL, ui->buttonR, - ui->buttonStart, ui->buttonSelect, ui->buttonZL, ui->buttonZR, ui->buttonHome, -}; + button_map = { + ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, ui->buttonDpadUp, + ui->buttonDpadDown, ui->buttonDpadLeft, ui->buttonDpadRight, ui->buttonL, ui->buttonR, + ui->buttonStart, ui->buttonSelect, ui->buttonZL, ui->buttonZR, ui->buttonHome, + }; -analog_map_buttons = {{ - { - ui->buttonCircleUp, - ui->buttonCircleDown, - ui->buttonCircleLeft, - ui->buttonCircleRight, - ui->buttonCircleMod, - }, - { - ui->buttonCStickUp, - ui->buttonCStickDown, - ui->buttonCStickLeft, - ui->buttonCStickRight, - nullptr, - }, -}}; + analog_map_buttons = {{ + { + ui->buttonCircleUp, + ui->buttonCircleDown, + ui->buttonCircleLeft, + ui->buttonCircleRight, + ui->buttonCircleMod, + }, + { + ui->buttonCStickUp, + ui->buttonCStickDown, + ui->buttonCStickLeft, + ui->buttonCStickRight, + nullptr, + }, + }}; -analog_map_stick = {ui->buttonCircleAnalog, ui->buttonCStickAnalog}; + analog_map_stick = {ui->buttonCircleAnalog, ui->buttonCStickAnalog}; -for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) { - if (!button_map[button_id]) - continue; - button_map[button_id]->setContextMenuPolicy(Qt::CustomContextMenu); - connect(button_map[button_id], &QPushButton::released, [=]() { - handleClick( - button_map[button_id], - [=](const Common::ParamPackage& params) { - buttons_param[button_id] = params; - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }, - InputCommon::Polling::DeviceType::Button); - }); - connect(button_map[button_id], &QPushButton::customContextMenuRequested, - [=](const QPoint& menu_location) { - QMenu context_menu; - context_menu.addAction(tr("Clear"), [&] { - buttons_param[button_id].Clear(); - button_map[button_id]->setText(tr("[not set]")); - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }); - context_menu.addAction(tr("Restore Default"), [&] { - buttons_param[button_id] = Common::ParamPackage{ - InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])}; - button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }); - context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); - }); -} - -for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { - for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { - if (!analog_map_buttons[analog_id][sub_button_id]) + for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) { + if (!button_map[button_id]) continue; - analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy(Qt::CustomContextMenu); - connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::released, [=]() { + button_map[button_id]->setContextMenuPolicy(Qt::CustomContextMenu); + connect(button_map[button_id], &QPushButton::released, [=]() { handleClick( - analog_map_buttons[analog_id][sub_button_id], + button_map[button_id], [=](const Common::ParamPackage& params) { - SetAnalogButton(params, analogs_param[analog_id], - analog_sub_buttons[sub_button_id]); + buttons_param[button_id] = params; applyConfiguration(); Settings::SaveProfile(ui->profile->currentIndex()); }, InputCommon::Polling::DeviceType::Button); }); - connect(analog_map_buttons[analog_id][sub_button_id], - &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { + connect(button_map[button_id], &QPushButton::customContextMenuRequested, + [=](const QPoint& menu_location) { QMenu context_menu; context_menu.addAction(tr("Clear"), [&] { - analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]); - analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]")); + buttons_param[button_id].Clear(); + button_map[button_id]->setText(tr("[not set]")); applyConfiguration(); Settings::SaveProfile(ui->profile->currentIndex()); }); context_menu.addAction(tr("Restore Default"), [&] { - Common::ParamPackage params{InputCommon::GenerateKeyboardParam( - Config::default_analogs[analog_id][sub_button_id])}; - SetAnalogButton(params, analogs_param[analog_id], - analog_sub_buttons[sub_button_id]); - analog_map_buttons[analog_id][sub_button_id]->setText(AnalogToText( - analogs_param[analog_id], analog_sub_buttons[sub_button_id])); + buttons_param[button_id] = Common::ParamPackage{ + InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])}; + button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); applyConfiguration(); Settings::SaveProfile(ui->profile->currentIndex()); }); - context_menu.exec( - analog_map_buttons[analog_id][sub_button_id]->mapToGlobal(menu_location)); + context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); }); } - connect(analog_map_stick[analog_id], &QPushButton::released, [=]() { - QMessageBox::information(this, tr("Information"), - tr("After pressing OK, first move your joystick horizontally, " - "and then vertically.")); - handleClick( - analog_map_stick[analog_id], - [=](const Common::ParamPackage& params) { - analogs_param[analog_id] = params; - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }, - InputCommon::Polling::DeviceType::Analog); - }); -} -connect(ui->buttonMotionTouch, &QPushButton::released, [this] { - QDialog* motion_touch_dialog = new ConfigureMotionTouch(this); - return motion_touch_dialog->exec(); -}); -connect(ui->buttonClearAll, &QPushButton::released, [this] { ClearAll(); }); -connect(ui->buttonRestoreDefaults, &QPushButton::released, [this]() { restoreDefaults(); }); -connect(ui->buttonNew, &QPushButton::released, [this] { newProfile(); }); -connect(ui->buttonDelete, &QPushButton::released, [this] { deleteProfile(); }); -connect(ui->buttonRename, &QPushButton::released, [this] { renameProfile(); }); - -connect(ui->profile, static_cast(&QComboBox::currentIndexChanged), - [this](int i) { - applyConfiguration(); - Settings::SaveProfile(Settings::values.current_input_profile); - Settings::LoadProfile(i); - loadConfiguration(); - }); - -timeout_timer->setSingleShot(true); -connect(timeout_timer.get(), &QTimer::timeout, [this]() { setPollingResult({}, true); }); - -connect(poll_timer.get(), &QTimer::timeout, [this]() { - Common::ParamPackage params; - for (auto& poller : device_pollers) { - params = poller->GetNextInput(); - if (params.Has("engine")) { - setPollingResult(params, false); - return; + for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { + for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { + if (!analog_map_buttons[analog_id][sub_button_id]) + continue; + analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy( + Qt::CustomContextMenu); + connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::released, [=]() { + handleClick( + analog_map_buttons[analog_id][sub_button_id], + [=](const Common::ParamPackage& params) { + SetAnalogButton(params, analogs_param[analog_id], + analog_sub_buttons[sub_button_id]); + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Button); + }); + connect(analog_map_buttons[analog_id][sub_button_id], + &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { + QMenu context_menu; + context_menu.addAction(tr("Clear"), [&] { + analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]); + analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]")); + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }); + context_menu.addAction(tr("Restore Default"), [&] { + Common::ParamPackage params{InputCommon::GenerateKeyboardParam( + Config::default_analogs[analog_id][sub_button_id])}; + SetAnalogButton(params, analogs_param[analog_id], + analog_sub_buttons[sub_button_id]); + analog_map_buttons[analog_id][sub_button_id]->setText(AnalogToText( + analogs_param[analog_id], analog_sub_buttons[sub_button_id])); + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }); + context_menu.exec(analog_map_buttons[analog_id][sub_button_id]->mapToGlobal( + menu_location)); + }); } + connect(analog_map_stick[analog_id], &QPushButton::released, [=]() { + QMessageBox::information(this, tr("Information"), + tr("After pressing OK, first move your joystick horizontally, " + "and then vertically.")); + handleClick( + analog_map_stick[analog_id], + [=](const Common::ParamPackage& params) { + analogs_param[analog_id] = params; + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Analog); + }); } -}); -this->loadConfiguration(); + connect(ui->buttonMotionTouch, &QPushButton::released, [this] { + QDialog* motion_touch_dialog = new ConfigureMotionTouch(this); + return motion_touch_dialog->exec(); + }); + connect(ui->buttonClearAll, &QPushButton::released, [this] { ClearAll(); }); + connect(ui->buttonRestoreDefaults, &QPushButton::released, [this]() { restoreDefaults(); }); + connect(ui->buttonNew, &QPushButton::released, [this] { newProfile(); }); + connect(ui->buttonDelete, &QPushButton::released, [this] { deleteProfile(); }); + connect(ui->buttonRename, &QPushButton::released, [this] { renameProfile(); }); -// TODO(wwylele): enable this when we actually emulate it -ui->buttonHome->setEnabled(false); + connect(ui->profile, static_cast(&QComboBox::currentIndexChanged), + [this](int i) { + applyConfiguration(); + Settings::SaveProfile(Settings::values.current_input_profile); + Settings::LoadProfile(i); + loadConfiguration(); + }); + + timeout_timer->setSingleShot(true); + connect(timeout_timer.get(), &QTimer::timeout, [this]() { setPollingResult({}, true); }); + + connect(poll_timer.get(), &QTimer::timeout, [this]() { + Common::ParamPackage params; + for (auto& poller : device_pollers) { + params = poller->GetNextInput(); + if (params.Has("engine")) { + setPollingResult(params, false); + return; + } + } + }); + + this->loadConfiguration(); + + // TODO(wwylele): enable this when we actually emulate it + ui->buttonHome->setEnabled(false); } ConfigureInput::~ConfigureInput() = default; From 8e614c3eb038bbb288cd95ab993f66fefda9257d Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Fri, 28 Dec 2018 23:31:55 -0500 Subject: [PATCH 09/19] clang-format; address one comment --- src/citra/config.cpp | 23 ++++++------ src/citra_qt/configuration/config.cpp | 10 +++--- .../configuration/configure_input.cpp | 22 ++++++------ .../configuration/configure_motion_touch.cpp | 25 +++++++------ src/citra_qt/main.cpp | 2 +- src/core/hle/service/hid/hid.cpp | 14 +++++--- src/core/hle/service/ir/extra_hid.cpp | 6 ++-- src/core/hle/service/ir/ir_rst.cpp | 6 ++-- src/core/settings.cpp | 35 ++++--------------- src/core/settings.h | 13 ++----- src/input_common/udp/udp.cpp | 10 +++--- 11 files changed, 75 insertions(+), 91 deletions(-) diff --git a/src/citra/config.cpp b/src/citra/config.cpp index 563c3b953..7b5d437ac 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -74,31 +74,32 @@ void Config::ReadValues() { // TODO: add multiple input profile support for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); - Settings::values.buttons[i] = + Settings::values.current_input_profile.buttons[i] = sdl2_config->GetString("Controls", Settings::NativeButton::mapping[i], default_param); - if (Settings::values.buttons[i].empty()) - Settings::values.buttons[i] = default_param; + if (Settings::values.current_input_profile.buttons[i].empty()) + Settings::values.current_input_profile.buttons[i] = default_param; } for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { std::string default_param = InputCommon::GenerateAnalogParamFromKeys( default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], default_analogs[i][3], default_analogs[i][4], 0.5f); - Settings::values.analogs[i] = + Settings::values.current_input_profile.analogs[i] = sdl2_config->GetString("Controls", Settings::NativeAnalog::mapping[i], default_param); - if (Settings::values.analogs[i].empty()) - Settings::values.analogs[i] = default_param; + if (Settings::values.current_input_profile.analogs[i].empty()) + Settings::values.current_input_profile.analogs[i] = default_param; } - Settings::values.motion_device = sdl2_config->GetString( + Settings::values.current_input_profile.motion_device = sdl2_config->GetString( "Controls", "motion_device", "engine:motion_emu,update_period:100,sensitivity:0.01,tilt_clamp:90.0"); - Settings::values.touch_device = + Settings::values.current_input_profile.touch_device = sdl2_config->GetString("Controls", "touch_device", "engine:emu_window"); - Settings::values.udp_input_address = sdl2_config->GetString( + Settings::values.current_input_profile.udp_input_address = sdl2_config->GetString( "Controls", "udp_input_address", InputCommon::CemuhookUDP::DEFAULT_ADDR); - Settings::values.udp_input_port = static_cast(sdl2_config->GetInteger( - "Controls", "udp_input_port", InputCommon::CemuhookUDP::DEFAULT_PORT)); + Settings::values.current_input_profile.udp_input_port = + static_cast(sdl2_config->GetInteger("Controls", "udp_input_port", + InputCommon::CemuhookUDP::DEFAULT_PORT)); // Core Settings::values.use_cpu_jit = sdl2_config->GetBoolean("Core", "use_cpu_jit", true); diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 05698e592..91f6fbd8f 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -51,7 +51,7 @@ const std::array, Settings::NativeAnalog::NumAnalogs> Config: void Config::ReadValues() { qt_config->beginGroup("Controls"); - Settings::values.current_input_profile = ReadSetting("profile", 0).toInt(); + Settings::values.current_input_profile_index = ReadSetting("profile", 0).toInt(); const auto append_profile = [this] { Settings::InputProfile profile; @@ -102,8 +102,8 @@ void Config::ReadValues() { qt_config->endArray(); - if (Settings::values.current_input_profile <= num_input_profiles) { - Settings::values.current_input_profile = 0; + if (Settings::values.current_input_profile_index <= num_input_profiles) { + Settings::values.current_input_profile_index = 0; } // create a input profile if no input profiles exist, with the default or old settings @@ -111,7 +111,7 @@ void Config::ReadValues() { append_profile(); } - Settings::LoadProfile(Settings::values.current_input_profile); + Settings::LoadProfile(Settings::values.current_input_profile_index); qt_config->endArray(); @@ -377,7 +377,7 @@ void Config::ReadValues() { void Config::SaveValues() { qt_config->beginGroup("Controls"); - WriteSetting("profile", Settings::values.current_input_profile, 0); + WriteSetting("profile", Settings::values.current_input_profile_index, 0); qt_config->beginWriteArray("profiles"); for (std::size_t p = 0; p < Settings::values.input_profiles.size(); ++p) { qt_config->setArrayIndex(static_cast(p)); diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index 5f05eff41..80db5c29f 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -104,7 +104,7 @@ ConfigureInput::ConfigureInput(QWidget* parent) ui->profile->addItem(QString::fromStdString(profile.name)); } - ui->profile->setCurrentIndex(Settings::values.current_input_profile); + ui->profile->setCurrentIndex(Settings::values.current_input_profile_index); button_map = { ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, ui->buttonDpadUp, @@ -233,7 +233,7 @@ ConfigureInput::ConfigureInput(QWidget* parent) connect(ui->profile, static_cast(&QComboBox::currentIndexChanged), [this](int i) { applyConfiguration(); - Settings::SaveProfile(Settings::values.current_input_profile); + Settings::SaveProfile(Settings::values.current_input_profile_index); Settings::LoadProfile(i); loadConfiguration(); }); @@ -261,22 +261,24 @@ ConfigureInput::ConfigureInput(QWidget* parent) ConfigureInput::~ConfigureInput() = default; void ConfigureInput::applyConfiguration() { - std::transform(buttons_param.begin(), buttons_param.end(), Settings::values.buttons.begin(), + std::transform(buttons_param.begin(), buttons_param.end(), + Settings::values.current_input_profile.buttons.begin(), [](const Common::ParamPackage& param) { return param.Serialize(); }); - std::transform(analogs_param.begin(), analogs_param.end(), Settings::values.analogs.begin(), + std::transform(analogs_param.begin(), analogs_param.end(), + Settings::values.current_input_profile.analogs.begin(), [](const Common::ParamPackage& param) { return param.Serialize(); }); } void ConfigureInput::applyProfile() { - Settings::values.current_input_profile = ui->profile->currentIndex(); + Settings::values.current_input_profile_index = ui->profile->currentIndex(); } void ConfigureInput::loadConfiguration() { - std::transform(Settings::values.buttons.begin(), Settings::values.buttons.end(), - buttons_param.begin(), + std::transform(Settings::values.current_input_profile.buttons.begin(), + Settings::values.current_input_profile.buttons.end(), buttons_param.begin(), [](const std::string& str) { return Common::ParamPackage(str); }); - std::transform(Settings::values.analogs.begin(), Settings::values.analogs.end(), - analogs_param.begin(), + std::transform(Settings::values.current_input_profile.analogs.begin(), + Settings::values.current_input_profile.analogs.end(), analogs_param.begin(), [](const std::string& str) { return Common::ParamPackage(str); }); updateButtonLabels(); } @@ -398,7 +400,7 @@ void ConfigureInput::newProfile() { Settings::SaveProfile(ui->profile->currentIndex()); Settings::CreateProfile(name.toStdString()); ui->profile->addItem(name); - ui->profile->setCurrentIndex(Settings::values.current_input_profile); + ui->profile->setCurrentIndex(Settings::values.current_input_profile_index); loadConfiguration(); } diff --git a/src/citra_qt/configuration/configure_motion_touch.cpp b/src/citra_qt/configuration/configure_motion_touch.cpp index 289570beb..80bf6a148 100644 --- a/src/citra_qt/configuration/configure_motion_touch.cpp +++ b/src/citra_qt/configuration/configure_motion_touch.cpp @@ -102,8 +102,8 @@ ConfigureMotionTouch::ConfigureMotionTouch(QWidget* parent) ConfigureMotionTouch::~ConfigureMotionTouch() = default; void ConfigureMotionTouch::setConfiguration() { - Common::ParamPackage motion_param(Settings::values.motion_device); - Common::ParamPackage touch_param(Settings::values.touch_device); + Common::ParamPackage motion_param(Settings::values.current_input_profile.motion_device); + Common::ParamPackage touch_param(Settings::values.current_input_profile.touch_device); std::string motion_engine = motion_param.Get("engine", "motion_emu"); std::string touch_engine = touch_param.Get("engine", "emu_window"); @@ -118,9 +118,10 @@ void ConfigureMotionTouch::setConfiguration() { max_x = touch_param.Get("max_x", 1800); max_y = touch_param.Get("max_y", 850); - ui->udp_server->setText(QString::fromStdString(Settings::values.udp_input_address)); - ui->udp_port->setText(QString::number(Settings::values.udp_input_port)); - ui->udp_pad_index->setCurrentIndex(Settings::values.udp_pad_index); + ui->udp_server->setText( + QString::fromStdString(Settings::values.current_input_profile.udp_input_address)); + ui->udp_port->setText(QString::number(Settings::values.current_input_profile.udp_input_port)); + ui->udp_pad_index->setCurrentIndex(Settings::values.current_input_profile.udp_pad_index); } void ConfigureMotionTouch::updateUiDisplay() { @@ -265,12 +266,14 @@ void ConfigureMotionTouch::applyConfiguration() { touch_param.Set("max_y", max_y); } - Settings::values.motion_device = motion_param.Serialize(); - Settings::values.touch_device = touch_param.Serialize(); - Settings::values.udp_input_address = ui->udp_server->text().toStdString(); - Settings::values.udp_input_port = static_cast(ui->udp_port->text().toInt()); - Settings::values.udp_pad_index = static_cast(ui->udp_pad_index->currentIndex()); - Settings::SaveProfile(Settings::values.current_input_profile); + Settings::values.current_input_profile.motion_device = motion_param.Serialize(); + Settings::values.current_input_profile.touch_device = touch_param.Serialize(); + Settings::values.current_input_profile.udp_input_address = ui->udp_server->text().toStdString(); + Settings::values.current_input_profile.udp_input_port = + static_cast(ui->udp_port->text().toInt()); + Settings::values.current_input_profile.udp_pad_index = + static_cast(ui->udp_pad_index->currentIndex()); + Settings::SaveProfile(Settings::values.current_input_profile_index); InputCommon::ReloadInputDevices(); accept(); diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 0af691e70..245b1b404 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -1326,7 +1326,7 @@ void GMainWindow::OnConfigure() { connect(&configureDialog, &ConfigureDialog::languageChanged, this, &GMainWindow::OnLanguageChanged); auto old_theme = UISettings::values.theme; - const int old_input_profile = Settings::values.current_input_profile; + const int old_input_profile = Settings::values.current_input_profile_index; const auto old_input_profiles = Settings::values.input_profiles; const bool old_discord_presence = UISettings::values.enable_discord_presence; auto result = configureDialog.exec(); diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 417f3b4d2..132594091 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -59,13 +59,17 @@ DirectionState GetStickDirectionState(s16 circle_pad_x, s16 circle_pad_y) { } void Module::LoadInputDevices() { - std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, - Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END, + std::transform(Settings::values.current_input_profile.buttons.begin() + + Settings::NativeButton::BUTTON_HID_BEGIN, + Settings::values.current_input_profile.buttons.begin() + + Settings::NativeButton::BUTTON_HID_END, buttons.begin(), Input::CreateDevice); circle_pad = Input::CreateDevice( - Settings::values.analogs[Settings::NativeAnalog::CirclePad]); - motion_device = Input::CreateDevice(Settings::values.motion_device); - touch_device = Input::CreateDevice(Settings::values.touch_device); + Settings::values.current_input_profile.analogs[Settings::NativeAnalog::CirclePad]); + motion_device = Input::CreateDevice( + Settings::values.current_input_profile.motion_device); + touch_device = Input::CreateDevice( + Settings::values.current_input_profile.touch_device); } void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) { diff --git a/src/core/hle/service/ir/extra_hid.cpp b/src/core/hle/service/ir/extra_hid.cpp index 8568f15a1..e5332cc76 100644 --- a/src/core/hle/service/ir/extra_hid.cpp +++ b/src/core/hle/service/ir/extra_hid.cpp @@ -263,11 +263,11 @@ void ExtraHID::RequestInputDevicesReload() { void ExtraHID::LoadInputDevices() { zl = Input::CreateDevice( - Settings::values.buttons[Settings::NativeButton::ZL]); + Settings::values.current_input_profile.buttons[Settings::NativeButton::ZL]); zr = Input::CreateDevice( - Settings::values.buttons[Settings::NativeButton::ZR]); + Settings::values.current_input_profile.buttons[Settings::NativeButton::ZR]); c_stick = Input::CreateDevice( - Settings::values.analogs[Settings::NativeAnalog::CStick]); + Settings::values.current_input_profile.analogs[Settings::NativeAnalog::CStick]); } } // namespace Service::IR diff --git a/src/core/hle/service/ir/ir_rst.cpp b/src/core/hle/service/ir/ir_rst.cpp index 7b7849afd..71d16a1ce 100644 --- a/src/core/hle/service/ir/ir_rst.cpp +++ b/src/core/hle/service/ir/ir_rst.cpp @@ -35,11 +35,11 @@ static_assert(sizeof(SharedMem) == 0x98, "SharedMem has wrong size!"); void IR_RST::LoadInputDevices() { zl_button = Input::CreateDevice( - Settings::values.buttons[Settings::NativeButton::ZL]); + Settings::values.current_input_profile.buttons[Settings::NativeButton::ZL]); zr_button = Input::CreateDevice( - Settings::values.buttons[Settings::NativeButton::ZR]); + Settings::values.current_input_profile.buttons[Settings::NativeButton::ZR]); c_stick = Input::CreateDevice( - Settings::values.analogs[Settings::NativeAnalog::CStick]); + Settings::values.current_input_profile.analogs[Settings::NativeAnalog::CStick]); } void IR_RST::UnloadInputDevices() { diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 667fe1b52..8ac3b17c8 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -101,41 +101,20 @@ void LogSettings() { } void LoadProfile(int index) { - const auto& profile = values.input_profiles[index]; - values.current_input_profile = index; - values.analogs = profile.analogs; - values.buttons = profile.buttons; - values.motion_device = profile.motion_device; - values.touch_device = profile.touch_device; - values.udp_input_address = profile.udp_input_address; - values.udp_input_port = profile.udp_input_port; - values.udp_pad_index = profile.udp_pad_index; + values.current_input_profile = values.input_profiles[index]; + values.current_input_profile_index = index; } void SaveProfile(int index) { - auto& profile = values.input_profiles[index]; - profile.analogs = values.analogs; - profile.buttons = values.buttons; - profile.motion_device = values.motion_device; - profile.touch_device = values.touch_device; - profile.udp_input_address = values.udp_input_address; - profile.udp_input_port = values.udp_input_port; - profile.udp_pad_index = values.udp_pad_index; + values.input_profiles[index] = values.current_input_profile; } void CreateProfile(std::string name) { - InputProfile profile; + InputProfile profile = values.current_input_profile; profile.name = std::move(name); - profile.analogs = values.analogs; - profile.buttons = values.buttons; - profile.motion_device = values.motion_device; - profile.touch_device = values.touch_device; - profile.udp_input_address = values.udp_input_address; - profile.udp_input_port = values.udp_input_port; - profile.udp_pad_index = values.udp_pad_index; values.input_profiles.push_back(std::move(profile)); - values.current_input_profile = static_cast(values.input_profiles.size()) - 1; - LoadProfile(values.current_input_profile); + values.current_input_profile_index = static_cast(values.input_profiles.size()) - 1; + LoadProfile(values.current_input_profile_index); } void DeleteProfile(int index) { @@ -144,7 +123,7 @@ void DeleteProfile(int index) { } void RenameCurrentProfile(std::string new_name) { - values.input_profiles[values.current_input_profile].name = std::move(new_name); + values.input_profiles[values.current_input_profile_index].name = std::move(new_name); } } // namespace Settings diff --git a/src/core/settings.h b/src/core/settings.h index 2bf6b5e6e..ccb00928f 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -108,16 +108,9 @@ struct Values { // CheckNew3DS bool is_new_3ds; - // Current controls - std::array buttons; - std::array analogs; - std::string motion_device; - std::string touch_device; - std::string udp_input_address; - u16 udp_input_port; - u8 udp_pad_index; - - int current_input_profile; ///< The current input profile index + // Controls + InputProfile current_input_profile; ///< The current input profile + int current_input_profile_index; ///< The current input profile index std::vector input_profiles; ///< The list of input profiles // Core diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp index d94278def..239cf25ed 100644 --- a/src/input_common/udp/udp.cpp +++ b/src/input_common/udp/udp.cpp @@ -71,8 +71,9 @@ private: State::State() { auto status = std::make_shared(); client = - std::make_unique(status, Settings::values.udp_input_address, - Settings::values.udp_input_port, Settings::values.udp_pad_index); + std::make_unique(status, Settings::values.current_input_profile.udp_input_address, + Settings::values.current_input_profile.udp_input_port, + Settings::values.current_input_profile.udp_pad_index); Input::RegisterFactory("cemuhookudp", std::make_shared(status)); @@ -86,8 +87,9 @@ State::~State() { } void State::ReloadUDPClient() { - client->ReloadSocket(Settings::values.udp_input_address, Settings::values.udp_input_port, - Settings::values.udp_pad_index); + client->ReloadSocket(Settings::values.current_input_profile.udp_input_address, + Settings::values.current_input_profile.udp_input_port, + Settings::values.current_input_profile.udp_pad_index); } std::unique_ptr Init() { From ec7a3fb72ce9434e6066cad8f34a6dc523b23490 Mon Sep 17 00:00:00 2001 From: Mat M Date: Fri, 28 Dec 2018 23:33:40 -0500 Subject: [PATCH 10/19] Update src/core/settings.h Co-Authored-By: valentinvanelslande --- src/core/settings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/settings.h b/src/core/settings.h index ccb00928f..43c7b7d1f 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -185,7 +185,7 @@ static constexpr int REGION_VALUE_AUTO_SELECT = -1; void Apply(); void LogSettings(); -// input profiles +// Input profiles void LoadProfile(int index); void SaveProfile(int index); void CreateProfile(std::string name); From 5a4c7c32d81cfbd5109e428035d6bc6ad9ba78ca Mon Sep 17 00:00:00 2001 From: Pengfei Zhu Date: Sat, 29 Dec 2018 08:14:37 -0500 Subject: [PATCH 11/19] Update src/citra_qt/configuration/config.cpp Co-Authored-By: valentinvanelslande --- src/citra_qt/configuration/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 91f6fbd8f..c28f0d828 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -62,7 +62,7 @@ void Config::ReadValues() { QString::fromStdString(default_param)) .toString() .toStdString(); - if (profile.buttons.empty()) + if (profile.buttons[i].empty()) profile.buttons[i] = default_param; } for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { From 5a14af5f38febb976fb2af0639879695a1f53aa1 Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Sat, 29 Dec 2018 08:27:06 -0500 Subject: [PATCH 12/19] address some comments --- src/citra_qt/configuration/config.cpp | 2 +- .../configuration/configure_dialog.cpp | 2 +- .../configuration/configure_input.cpp | 23 ++++++++++--------- src/citra_qt/configuration/configure_input.h | 8 +++---- src/core/settings.cpp | 22 ++++++++++-------- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index c28f0d828..68e58e63b 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -113,7 +113,7 @@ void Config::ReadValues() { Settings::LoadProfile(Settings::values.current_input_profile_index); - qt_config->endArray(); + qt_config->endGroup(); qt_config->beginGroup("Core"); Settings::values.use_cpu_jit = ReadSetting("use_cpu_jit", true).toBool(); diff --git a/src/citra_qt/configuration/configure_dialog.cpp b/src/citra_qt/configuration/configure_dialog.cpp index 1d55f8934..3527b8589 100644 --- a/src/citra_qt/configuration/configure_dialog.cpp +++ b/src/citra_qt/configuration/configure_dialog.cpp @@ -42,7 +42,7 @@ void ConfigureDialog::applyConfiguration() { ui->generalTab->applyConfiguration(); ui->systemTab->applyConfiguration(); ui->inputTab->applyConfiguration(); - ui->inputTab->applyProfile(); + ui->inputTab->ApplyProfile(); ui->graphicsTab->applyConfiguration(); ui->audioTab->applyConfiguration(); ui->cameraTab->applyConfiguration(); diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index 80db5c29f..437265763 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -224,11 +224,14 @@ ConfigureInput::ConfigureInput(QWidget* parent) QDialog* motion_touch_dialog = new ConfigureMotionTouch(this); return motion_touch_dialog->exec(); }); + + ui->buttonDelete->setEnabled(ui->profile->count() > 1); + connect(ui->buttonClearAll, &QPushButton::released, [this] { ClearAll(); }); connect(ui->buttonRestoreDefaults, &QPushButton::released, [this]() { restoreDefaults(); }); - connect(ui->buttonNew, &QPushButton::released, [this] { newProfile(); }); - connect(ui->buttonDelete, &QPushButton::released, [this] { deleteProfile(); }); - connect(ui->buttonRename, &QPushButton::released, [this] { renameProfile(); }); + connect(ui->buttonNew, &QPushButton::released, [this] { NewProfile(); }); + connect(ui->buttonDelete, &QPushButton::released, [this] { DeleteProfile(); }); + connect(ui->buttonRename, &QPushButton::released, [this] { RenameProfile(); }); connect(ui->profile, static_cast(&QComboBox::currentIndexChanged), [this](int i) { @@ -269,7 +272,7 @@ void ConfigureInput::applyConfiguration() { [](const Common::ParamPackage& param) { return param.Serialize(); }); } -void ConfigureInput::applyProfile() { +void ConfigureInput::ApplyProfile() { Settings::values.current_input_profile_index = ui->profile->currentIndex(); } @@ -390,7 +393,7 @@ void ConfigureInput::retranslateUi() { ui->retranslateUi(this); } -void ConfigureInput::newProfile() { +void ConfigureInput::NewProfile() { const QString name = QInputDialog::getText(this, tr("New Profile"), tr("Enter the name for the new profile.")); if (name.isEmpty()) { @@ -402,13 +405,10 @@ void ConfigureInput::newProfile() { ui->profile->addItem(name); ui->profile->setCurrentIndex(Settings::values.current_input_profile_index); loadConfiguration(); + ui->buttonDelete->setEnabled(ui->profile->count() > 1); } -void ConfigureInput::deleteProfile() { - if (ui->profile->count() == 1) { - QMessageBox::critical(this, tr("Citra"), tr("You need to have 1 profile at least")); - return; - } +void ConfigureInput::DeleteProfile() { const auto answer = QMessageBox::question( this, tr("Delete Profile"), tr("Delete profile %1?").arg(ui->profile->currentText())); if (answer != QMessageBox::Yes) { @@ -419,9 +419,10 @@ void ConfigureInput::deleteProfile() { ui->profile->setCurrentIndex(0); Settings::DeleteProfile(index); loadConfiguration(); + ui->buttonDelete->setEnabled(ui->profile->count() > 1); } -void ConfigureInput::renameProfile() { +void ConfigureInput::RenameProfile() { const QString new_name = QInputDialog::getText(this, tr("Rename Profile"), tr("New name:")); if (new_name.isEmpty()) { return; diff --git a/src/citra_qt/configuration/configure_input.h b/src/citra_qt/configuration/configure_input.h index 7c4b02f7a..1e55fd272 100644 --- a/src/citra_qt/configuration/configure_input.h +++ b/src/citra_qt/configuration/configure_input.h @@ -40,7 +40,7 @@ public: void loadConfiguration(); // Save the current input profile index - void applyProfile(); + void ApplyProfile(); private: std::unique_ptr ui; @@ -96,7 +96,7 @@ private: void keyPressEvent(QKeyEvent* event) override; /// input profiles - void newProfile(); - void deleteProfile(); - void renameProfile(); + void NewProfile(); + void DeleteProfile(); + void RenameProfile(); }; diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 8ac3b17c8..a286d149b 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -101,29 +101,31 @@ void LogSettings() { } void LoadProfile(int index) { - values.current_input_profile = values.input_profiles[index]; - values.current_input_profile_index = index; + Settings::values.current_input_profile = Settings::values.input_profiles[index]; + Settings::values.current_input_profile_index = index; } void SaveProfile(int index) { - values.input_profiles[index] = values.current_input_profile; + Settings::values.input_profiles[index] = Settings::values.current_input_profile; } void CreateProfile(std::string name) { - InputProfile profile = values.current_input_profile; + Settings::InputProfile profile = values.current_input_profile; profile.name = std::move(name); - values.input_profiles.push_back(std::move(profile)); - values.current_input_profile_index = static_cast(values.input_profiles.size()) - 1; - LoadProfile(values.current_input_profile_index); + Settings::values.input_profiles.push_back(std::move(profile)); + Settings::values.current_input_profile_index = + static_cast(Settings::values.input_profiles.size()) - 1; + Settings::LoadProfile(Settings::values.current_input_profile_index); } void DeleteProfile(int index) { - values.input_profiles.erase(values.input_profiles.begin() + index); - LoadProfile(0); + Settings::values.input_profiles.erase(Settings::values.input_profiles.begin() + index); + Settings::LoadProfile(0); } void RenameCurrentProfile(std::string new_name) { - values.input_profiles[values.current_input_profile_index].name = std::move(new_name); + Settings::values.input_profiles[Settings::values.current_input_profile_index].name = + std::move(new_name); } } // namespace Settings From 60d1822206632d4f6120296a7ce84ed000e24e43 Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Sat, 29 Dec 2018 08:39:30 -0500 Subject: [PATCH 13/19] if to clamp --- src/citra_qt/configuration/config.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 68e58e63b..21a0bd1d8 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include #include "citra_qt/configuration/config.h" @@ -102,15 +103,15 @@ void Config::ReadValues() { qt_config->endArray(); - if (Settings::values.current_input_profile_index <= num_input_profiles) { - Settings::values.current_input_profile_index = 0; - } - // create a input profile if no input profiles exist, with the default or old settings if (num_input_profiles == 0) { append_profile(); } + // ensure that the current input profile index is valid. + Settings::values.current_input_profile_index = + std::clamp(Settings::values.current_input_profile_index, 0, num_input_profiles - 1); + Settings::LoadProfile(Settings::values.current_input_profile_index); qt_config->endGroup(); From e7b1a1d5c82278e2a50ed2a9e5876c4a403b18bf Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Sat, 29 Dec 2018 09:04:43 -0500 Subject: [PATCH 14/19] fix clang-format --- .../configuration/configure_input.cpp | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index 437265763..a3cf53a75 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -136,14 +136,13 @@ ConfigureInput::ConfigureInput(QWidget* parent) continue; button_map[button_id]->setContextMenuPolicy(Qt::CustomContextMenu); connect(button_map[button_id], &QPushButton::released, [=]() { - handleClick( - button_map[button_id], - [=](const Common::ParamPackage& params) { - buttons_param[button_id] = params; - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }, - InputCommon::Polling::DeviceType::Button); + handleClick(button_map[button_id], + [=](const Common::ParamPackage& params) { + buttons_param[button_id] = params; + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Button); }); connect(button_map[button_id], &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { @@ -172,15 +171,14 @@ ConfigureInput::ConfigureInput(QWidget* parent) analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy( Qt::CustomContextMenu); connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::released, [=]() { - handleClick( - analog_map_buttons[analog_id][sub_button_id], - [=](const Common::ParamPackage& params) { - SetAnalogButton(params, analogs_param[analog_id], - analog_sub_buttons[sub_button_id]); - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }, - InputCommon::Polling::DeviceType::Button); + handleClick(analog_map_buttons[analog_id][sub_button_id], + [=](const Common::ParamPackage& params) { + SetAnalogButton(params, analogs_param[analog_id], + analog_sub_buttons[sub_button_id]); + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Button); }); connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { @@ -209,14 +207,13 @@ ConfigureInput::ConfigureInput(QWidget* parent) QMessageBox::information(this, tr("Information"), tr("After pressing OK, first move your joystick horizontally, " "and then vertically.")); - handleClick( - analog_map_stick[analog_id], - [=](const Common::ParamPackage& params) { - analogs_param[analog_id] = params; - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }, - InputCommon::Polling::DeviceType::Analog); + handleClick(analog_map_stick[analog_id], + [=](const Common::ParamPackage& params) { + analogs_param[analog_id] = params; + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Analog); }); } From 3d00beb9d58508b03ac8d22c9da4b8bcba89f692 Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Sat, 29 Dec 2018 09:19:45 -0500 Subject: [PATCH 15/19] add a comment, rename old index --- .../configuration/configure_input.cpp | 49 ++++++++++--------- src/citra_qt/main.cpp | 4 +- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index a3cf53a75..437bc13b7 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -97,6 +97,8 @@ ConfigureInput::ConfigureInput(QWidget* parent) : QWidget(parent), ui(std::make_unique()), timeout_timer(std::make_unique()), poll_timer(std::make_unique()) { + // If the user closes the dialog, the changes are reverted in `GMainWindow::OnConfigure()` + ui->setupUi(this); setFocusPolicy(Qt::ClickFocus); @@ -136,13 +138,14 @@ ConfigureInput::ConfigureInput(QWidget* parent) continue; button_map[button_id]->setContextMenuPolicy(Qt::CustomContextMenu); connect(button_map[button_id], &QPushButton::released, [=]() { - handleClick(button_map[button_id], - [=](const Common::ParamPackage& params) { - buttons_param[button_id] = params; - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }, - InputCommon::Polling::DeviceType::Button); + handleClick( + button_map[button_id], + [=](const Common::ParamPackage& params) { + buttons_param[button_id] = params; + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Button); }); connect(button_map[button_id], &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { @@ -171,14 +174,15 @@ ConfigureInput::ConfigureInput(QWidget* parent) analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy( Qt::CustomContextMenu); connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::released, [=]() { - handleClick(analog_map_buttons[analog_id][sub_button_id], - [=](const Common::ParamPackage& params) { - SetAnalogButton(params, analogs_param[analog_id], - analog_sub_buttons[sub_button_id]); - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }, - InputCommon::Polling::DeviceType::Button); + handleClick( + analog_map_buttons[analog_id][sub_button_id], + [=](const Common::ParamPackage& params) { + SetAnalogButton(params, analogs_param[analog_id], + analog_sub_buttons[sub_button_id]); + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Button); }); connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { @@ -207,13 +211,14 @@ ConfigureInput::ConfigureInput(QWidget* parent) QMessageBox::information(this, tr("Information"), tr("After pressing OK, first move your joystick horizontally, " "and then vertically.")); - handleClick(analog_map_stick[analog_id], - [=](const Common::ParamPackage& params) { - analogs_param[analog_id] = params; - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }, - InputCommon::Polling::DeviceType::Analog); + handleClick( + analog_map_stick[analog_id], + [=](const Common::ParamPackage& params) { + analogs_param[analog_id] = params; + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Analog); }); } diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 245b1b404..a62e23260 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -1326,7 +1326,7 @@ void GMainWindow::OnConfigure() { connect(&configureDialog, &ConfigureDialog::languageChanged, this, &GMainWindow::OnLanguageChanged); auto old_theme = UISettings::values.theme; - const int old_input_profile = Settings::values.current_input_profile_index; + const int old_input_profile_index = Settings::values.current_input_profile_index; const auto old_input_profiles = Settings::values.input_profiles; const bool old_discord_presence = UISettings::values.enable_discord_presence; auto result = configureDialog.exec(); @@ -1342,7 +1342,7 @@ void GMainWindow::OnConfigure() { config->Save(); } else { Settings::values.input_profiles = old_input_profiles; - Settings::LoadProfile(old_input_profile); + Settings::LoadProfile(old_input_profile_index); } } From 57f224fc50198167f8f01118ee22cb72b038e981 Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Sat, 29 Dec 2018 09:31:03 -0500 Subject: [PATCH 16/19] fix clang-format --- .../configuration/configure_input.cpp | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index 437bc13b7..7bfc58aa8 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -138,14 +138,13 @@ ConfigureInput::ConfigureInput(QWidget* parent) continue; button_map[button_id]->setContextMenuPolicy(Qt::CustomContextMenu); connect(button_map[button_id], &QPushButton::released, [=]() { - handleClick( - button_map[button_id], - [=](const Common::ParamPackage& params) { - buttons_param[button_id] = params; - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }, - InputCommon::Polling::DeviceType::Button); + handleClick(button_map[button_id], + [=](const Common::ParamPackage& params) { + buttons_param[button_id] = params; + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Button); }); connect(button_map[button_id], &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { @@ -174,15 +173,14 @@ ConfigureInput::ConfigureInput(QWidget* parent) analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy( Qt::CustomContextMenu); connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::released, [=]() { - handleClick( - analog_map_buttons[analog_id][sub_button_id], - [=](const Common::ParamPackage& params) { - SetAnalogButton(params, analogs_param[analog_id], - analog_sub_buttons[sub_button_id]); - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }, - InputCommon::Polling::DeviceType::Button); + handleClick(analog_map_buttons[analog_id][sub_button_id], + [=](const Common::ParamPackage& params) { + SetAnalogButton(params, analogs_param[analog_id], + analog_sub_buttons[sub_button_id]); + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Button); }); connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { @@ -211,14 +209,13 @@ ConfigureInput::ConfigureInput(QWidget* parent) QMessageBox::information(this, tr("Information"), tr("After pressing OK, first move your joystick horizontally, " "and then vertically.")); - handleClick( - analog_map_stick[analog_id], - [=](const Common::ParamPackage& params) { - analogs_param[analog_id] = params; - applyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }, - InputCommon::Polling::DeviceType::Analog); + handleClick(analog_map_stick[analog_id], + [=](const Common::ParamPackage& params) { + analogs_param[analog_id] = params; + applyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Analog); }); } From dce82fa005457d4cb9314922ac6e1247fa67d117 Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Sat, 29 Dec 2018 13:15:31 -0500 Subject: [PATCH 17/19] move comment --- src/citra_qt/configuration/configure_input.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index 7bfc58aa8..09a6a8330 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -96,9 +96,6 @@ static QString AnalogToText(const Common::ParamPackage& param, const std::string ConfigureInput::ConfigureInput(QWidget* parent) : QWidget(parent), ui(std::make_unique()), timeout_timer(std::make_unique()), poll_timer(std::make_unique()) { - - // If the user closes the dialog, the changes are reverted in `GMainWindow::OnConfigure()` - ui->setupUi(this); setFocusPolicy(Qt::ClickFocus); @@ -141,6 +138,8 @@ ConfigureInput::ConfigureInput(QWidget* parent) handleClick(button_map[button_id], [=](const Common::ParamPackage& params) { buttons_param[button_id] = params; + // If the user closes the dialog, the changes are reverted in + // `GMainWindow::OnConfigure()` applyConfiguration(); Settings::SaveProfile(ui->profile->currentIndex()); }, From 64b992487ebb1674db83acd0f4ac29aaa3458ce2 Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Sat, 29 Dec 2018 16:23:33 -0500 Subject: [PATCH 18/19] fix regression --- src/citra_qt/configuration/config.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 21a0bd1d8..4d6e736e9 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -94,7 +94,7 @@ void Config::ReadValues() { Settings::values.input_profiles.emplace_back(std::move(profile)); }; - const int num_input_profiles = qt_config->beginReadArray("profiles"); + int num_input_profiles = qt_config->beginReadArray("profiles"); for (int i = 0; i < num_input_profiles; ++i) { qt_config->setArrayIndex(i); @@ -106,6 +106,7 @@ void Config::ReadValues() { // create a input profile if no input profiles exist, with the default or old settings if (num_input_profiles == 0) { append_profile(); + num_input_profiles = 1; } // ensure that the current input profile index is valid. From df02ea48d28eecd012627310d17f13d676e51105 Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Sat, 29 Dec 2018 19:28:56 -0500 Subject: [PATCH 19/19] minor ui changes --- src/citra_qt/configuration/configure_input.ui | 244 +++++++++--------- 1 file changed, 122 insertions(+), 122 deletions(-) diff --git a/src/citra_qt/configuration/configure_input.ui b/src/citra_qt/configuration/configure_input.ui index 498e08b1d..dcb915323 100644 --- a/src/citra_qt/configuration/configure_input.ui +++ b/src/citra_qt/configuration/configure_input.ui @@ -6,7 +6,7 @@ 0 0 - 376 + 374 535 @@ -14,6 +14,54 @@ ConfigureInput + + + + + + Profile + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + New + + + + + + + Delete + + + + + + + Rename + + + + + @@ -28,35 +76,17 @@ false - - + + - + - A: + Y: - - - - - - - - - - - - - - B: - - - - - + @@ -82,17 +112,35 @@ - - + + - + - Y: + B: - + + + + + + + + + + + + + + A: + + + + + @@ -289,50 +337,7 @@ false - - - - Set Analog Stick - - - - - - - - - Left: - - - - - - - - - - - - - - - - - - Right: - - - - - - - - - - - - - + @@ -350,7 +355,7 @@ - + @@ -368,6 +373,49 @@ + + + + + + Right: + + + + + + + + + + + + + + + + Set Analog Stick + + + + + + + + + Left: + + + + + + + + + + + + @@ -556,54 +604,6 @@ - - - - - - Profile - - - - - - - - - - New - - - - - - - Delete - - - - - - - Rename - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - -