From bf93b9465877b198ce1a0770fbb035079cce5c63 Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Fri, 28 Dec 2018 21:13:57 -0500 Subject: [PATCH] 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