From 88a475970240e1dbade1720b02f9e5338647b1b8 Mon Sep 17 00:00:00 2001 From: SachinVin <26602104+SachinVin@users.noreply.github.com> Date: Sat, 11 Jun 2022 11:53:27 +0530 Subject: [PATCH] citra_qt: configure_input.cpp: update the modifier settings for both the sticks (#6033) The Controller config UI exposes the Circle mod, only for the Circle pad's modifier, So after changing the binding, it leaves the default binding for the c-stick untouched, and the user is nagged about the (default) D key being bound to something, when trying to bind it to any other button. With this PR we update the modifier for both the Circle Pad and C-stick. --- .../configuration/configure_input.cpp | 60 ++++++++++++++++++- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index 1897c6d43..0422c11d2 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -27,6 +27,14 @@ const std::array "modifier", }}; +enum class AnalogSubButtons { + up, + down, + left, + right, + modifier, +}; + static QString GetKeyName(int key_code) { switch (key_code) { case Qt::Key_Shift: @@ -163,7 +171,7 @@ ConfigureInput::ConfigureInput(QWidget* parent) ui->buttonCircleDown, ui->buttonCircleLeft, ui->buttonCircleRight, - ui->buttonCircleMod, + nullptr, }, { ui->buttonCStickUp, @@ -289,6 +297,50 @@ ConfigureInput::ConfigureInput(QWidget* parent) }); } + // The Circle Mod button is common for both the sticks, so update the modifier settings + // for both the sticks. + connect(ui->buttonCircleMod, &QPushButton::clicked, [=]() { + HandleClick( + ui->buttonCircleMod, + [=](const Common::ParamPackage& params) { + for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; + analog_id++) { + SetAnalogButton(params, analogs_param[analog_id], "modifier"); + } + ApplyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Button); + }); + connect(ui->buttonCircleMod, &QPushButton::customContextMenuRequested, + [&](const QPoint& menu_location) { + QMenu context_menu; + context_menu.addAction(tr("Clear"), [&] { + for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; + analog_id++) { + analogs_param[analog_id].Erase("modifier"); + } + ui->buttonCircleMod->setText(tr("[not set]")); + ApplyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }); + + context_menu.addAction(tr("Restore Default"), [&] { + for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; + analog_id++) { + Common::ParamPackage params{InputCommon::GenerateKeyboardParam( + Config::default_analogs[analog_id] + [static_cast(AnalogSubButtons::modifier)])}; + SetAnalogButton(params, analogs_param[analog_id], "modifier"); + ui->buttonCircleMod->setText( + AnalogToText(analogs_param[analog_id], "modifier")); + } + ApplyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }); + context_menu.exec(ui->buttonCircleMod->mapToGlobal(menu_location)); + }); + connect(ui->buttonMotionTouch, &QPushButton::clicked, [this] { QDialog* motion_touch_dialog = new ConfigureMotionTouch(this); return motion_touch_dialog->exec(); @@ -363,14 +415,14 @@ QList ConfigureInput::GetUsedKeyboardKeys() { continue; } - auto button_param = buttons_param[button]; + const auto& button_param = buttons_param[button]; if (button_param.Get("engine", "") == "keyboard") { list << QKeySequence(button_param.Get("code", 0)); } } for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { - auto analog_param = analogs_param[analog_id]; + const auto& analog_param = analogs_param[analog_id]; if (analog_param.Get("engine", "") == "analog_from_button") { for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { const Common::ParamPackage sub_button{ @@ -467,6 +519,8 @@ void ConfigureInput::UpdateButtonLabels() { } } + ui->buttonCircleMod->setText(AnalogToText(analogs_param[0], "modifier")); + EmitInputKeysChanged(); }