summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Morph2020-09-01 10:02:18 -0400
committerGravatar Morph2020-09-17 21:57:06 -0400
commit65d9def873bdc9a7b3e78949a432467bda5a8465 (patch)
treed54614dc8dc37cdaa7b4bec57deeeb044339560b
parentMerge pull request #4670 from lioncash/initializer (diff)
downloadyuzu-65d9def873bdc9a7b3e78949a432467bda5a8465.tar.gz
yuzu-65d9def873bdc9a7b3e78949a432467bda5a8465.tar.xz
yuzu-65d9def873bdc9a7b3e78949a432467bda5a8465.zip
configure_input_player: Re-add "Clear" context menu option
The context menu was removed in Mjölnir Part 1 as part of the input rewrite as we were unaware of it's usage statistics. However, as this was the only way to clear the inputs of individual buttons, this PR will re-add it back in.
Diffstat (limited to '')
-rw-r--r--src/yuzu/configuration/configure_input_player.cpp93
-rw-r--r--src/yuzu/configuration/configure_input_player.h4
2 files changed, 66 insertions, 31 deletions
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp
index 9a61a6e15..8c5921eb6 100644
--- a/src/yuzu/configuration/configure_input_player.cpp
+++ b/src/yuzu/configuration/configure_input_player.cpp
@@ -256,6 +256,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
256 ui->buttonSL, ui->buttonSR, ui->buttonHome, ui->buttonScreenshot, 256 ui->buttonSL, ui->buttonSR, ui->buttonHome, ui->buttonScreenshot,
257 }; 257 };
258 258
259 mod_buttons = {
260 ui->buttonLStickMod,
261 ui->buttonRStickMod,
262 };
263
259 analog_map_buttons = {{ 264 analog_map_buttons = {{
260 { 265 {
261 ui->buttonLStickUp, 266 ui->buttonLStickUp,
@@ -311,11 +316,25 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
311 316
312 for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) { 317 for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) {
313 auto* const button = button_map[button_id]; 318 auto* const button = button_map[button_id];
319
314 if (button == nullptr) { 320 if (button == nullptr) {
315 continue; 321 continue;
316 } 322 }
323
317 ConfigureButtonClick(button_map[button_id], &buttons_param[button_id], 324 ConfigureButtonClick(button_map[button_id], &buttons_param[button_id],
318 Config::default_buttons[button_id]); 325 Config::default_buttons[button_id]);
326
327 button->setContextMenuPolicy(Qt::CustomContextMenu);
328
329 connect(button, &QPushButton::customContextMenuRequested,
330 [=, this](const QPoint& menu_location) {
331 QMenu context_menu;
332 context_menu.addAction(tr("Clear"), [&] {
333 buttons_param[button_id].Clear();
334 button_map[button_id]->setText(tr("[not set]"));
335 });
336 context_menu.exec(button_map[button_id]->mapToGlobal(menu_location));
337 });
319 } 338 }
320 339
321 for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { 340 for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
@@ -324,15 +343,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
324 continue; 343 continue;
325 } 344 }
326 345
346 ConfigureButtonClick(motion_map[motion_id], &motions_param[motion_id],
347 Config::default_motions[motion_id]);
348
327 button->setContextMenuPolicy(Qt::CustomContextMenu); 349 button->setContextMenuPolicy(Qt::CustomContextMenu);
328 connect(button, &QPushButton::clicked, [=, this] { 350
329 HandleClick(
330 motion_map[motion_id],
331 [=, this](Common::ParamPackage params) {
332 motions_param[motion_id] = std::move(params);
333 },
334 InputCommon::Polling::DeviceType::Motion);
335 });
336 connect(button, &QPushButton::customContextMenuRequested, 351 connect(button, &QPushButton::customContextMenuRequested,
337 [=, this](const QPoint& menu_location) { 352 [=, this](const QPoint& menu_location) {
338 QMenu context_menu; 353 QMenu context_menu;
@@ -344,10 +359,6 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
344 }); 359 });
345 } 360 }
346 361
347 // Handle clicks for the modifier buttons as well.
348 ConfigureButtonClick(ui->buttonLStickMod, &lstick_mod, Config::default_stick_mod[0]);
349 ConfigureButtonClick(ui->buttonRStickMod, &rstick_mod, Config::default_stick_mod[1]);
350
351 for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { 362 for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) {
352 for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { 363 for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
353 auto* const analog_button = analog_map_buttons[analog_id][sub_button_id]; 364 auto* const analog_button = analog_map_buttons[analog_id][sub_button_id];
@@ -365,8 +376,37 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
365 }, 376 },
366 InputCommon::Polling::DeviceType::AnalogPreferred); 377 InputCommon::Polling::DeviceType::AnalogPreferred);
367 }); 378 });
379
380 analog_button->setContextMenuPolicy(Qt::CustomContextMenu);
381
382 connect(analog_button, &QPushButton::customContextMenuRequested,
383 [=, this](const QPoint& menu_location) {
384 QMenu context_menu;
385 context_menu.addAction(tr("Clear"), [&] {
386 analogs_param[analog_id].Clear();
387 analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]"));
388 });
389 context_menu.exec(analog_map_buttons[analog_id][sub_button_id]->mapToGlobal(
390 menu_location));
391 });
368 } 392 }
369 393
394 // Handle clicks for the modifier buttons as well.
395 ConfigureButtonClick(mod_buttons[analog_id], &stick_mod_param[analog_id],
396 Config::default_stick_mod[analog_id]);
397
398 mod_buttons[analog_id]->setContextMenuPolicy(Qt::CustomContextMenu);
399
400 connect(mod_buttons[analog_id], &QPushButton::customContextMenuRequested,
401 [=, this](const QPoint& menu_location) {
402 QMenu context_menu;
403 context_menu.addAction(tr("Clear"), [&] {
404 stick_mod_param[analog_id].Clear();
405 mod_buttons[analog_id]->setText(tr("[not set]"));
406 });
407 context_menu.exec(mod_buttons[analog_id]->mapToGlobal(menu_location));
408 });
409
370 connect(analog_map_range_spinbox[analog_id], qOverload<int>(&QSpinBox::valueChanged), 410 connect(analog_map_range_spinbox[analog_id], qOverload<int>(&QSpinBox::valueChanged),
371 [=, this] { 411 [=, this] {
372 const auto spinbox_value = analog_map_range_spinbox[analog_id]->value(); 412 const auto spinbox_value = analog_map_range_spinbox[analog_id]->value();
@@ -585,19 +625,16 @@ void ConfigureInputPlayer::RestoreDefaults() {
585 InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])}; 625 InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])};
586 } 626 }
587 627
588 // Reset Modifier Buttons 628 // Reset Analogs and Modifier Buttons
589 lstick_mod =
590 Common::ParamPackage(InputCommon::GenerateKeyboardParam(Config::default_stick_mod[0]));
591 rstick_mod =
592 Common::ParamPackage(InputCommon::GenerateKeyboardParam(Config::default_stick_mod[1]));
593
594 // Reset Analogs
595 for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { 629 for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) {
596 for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { 630 for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
597 Common::ParamPackage params{InputCommon::GenerateKeyboardParam( 631 Common::ParamPackage params{InputCommon::GenerateKeyboardParam(
598 Config::default_analogs[analog_id][sub_button_id])}; 632 Config::default_analogs[analog_id][sub_button_id])};
599 SetAnalogParam(params, analogs_param[analog_id], analog_sub_buttons[sub_button_id]); 633 SetAnalogParam(params, analogs_param[analog_id], analog_sub_buttons[sub_button_id]);
600 } 634 }
635
636 stick_mod_param[analog_id] = Common::ParamPackage(
637 InputCommon::GenerateKeyboardParam(Config::default_stick_mod[analog_id]));
601 } 638 }
602 639
603 for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { 640 for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
@@ -613,30 +650,29 @@ void ConfigureInputPlayer::RestoreDefaults() {
613void ConfigureInputPlayer::ClearAll() { 650void ConfigureInputPlayer::ClearAll() {
614 for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) { 651 for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) {
615 const auto* const button = button_map[button_id]; 652 const auto* const button = button_map[button_id];
616 if (button == nullptr || !button->isEnabled()) { 653 if (button == nullptr) {
617 continue; 654 continue;
618 } 655 }
619 656
620 buttons_param[button_id].Clear(); 657 buttons_param[button_id].Clear();
621 } 658 }
622 659
623 lstick_mod.Clear();
624 rstick_mod.Clear();
625
626 for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { 660 for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) {
627 for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { 661 for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
628 const auto* const analog_button = analog_map_buttons[analog_id][sub_button_id]; 662 const auto* const analog_button = analog_map_buttons[analog_id][sub_button_id];
629 if (analog_button == nullptr || !analog_button->isEnabled()) { 663 if (analog_button == nullptr) {
630 continue; 664 continue;
631 } 665 }
632 666
633 analogs_param[analog_id].Clear(); 667 analogs_param[analog_id].Clear();
634 } 668 }
669
670 stick_mod_param[analog_id].Clear();
635 } 671 }
636 672
637 for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { 673 for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
638 const auto* const button = motion_map[motion_id]; 674 const auto* const motion_button = motion_map[motion_id];
639 if (button == nullptr || !button->isEnabled()) { 675 if (motion_button == nullptr) {
640 continue; 676 continue;
641 } 677 }
642 678
@@ -656,9 +692,6 @@ void ConfigureInputPlayer::UpdateUI() {
656 motion_map[motion_id]->setText(ButtonToText(motions_param[motion_id])); 692 motion_map[motion_id]->setText(ButtonToText(motions_param[motion_id]));
657 } 693 }
658 694
659 ui->buttonLStickMod->setText(ButtonToText(lstick_mod));
660 ui->buttonRStickMod->setText(ButtonToText(rstick_mod));
661
662 for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { 695 for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) {
663 for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { 696 for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
664 auto* const analog_button = analog_map_buttons[analog_id][sub_button_id]; 697 auto* const analog_button = analog_map_buttons[analog_id][sub_button_id];
@@ -671,6 +704,8 @@ void ConfigureInputPlayer::UpdateUI() {
671 AnalogToText(analogs_param[analog_id], analog_sub_buttons[sub_button_id])); 704 AnalogToText(analogs_param[analog_id], analog_sub_buttons[sub_button_id]));
672 } 705 }
673 706
707 mod_buttons[analog_id]->setText(ButtonToText(stick_mod_param[analog_id]));
708
674 const auto deadzone_label = analog_map_deadzone_label[analog_id]; 709 const auto deadzone_label = analog_map_deadzone_label[analog_id];
675 const auto deadzone_slider = analog_map_deadzone_slider[analog_id]; 710 const auto deadzone_slider = analog_map_deadzone_slider[analog_id];
676 const auto modifier_groupbox = analog_map_modifier_groupbox[analog_id]; 711 const auto modifier_groupbox = analog_map_modifier_groupbox[analog_id];
diff --git a/src/yuzu/configuration/configure_input_player.h b/src/yuzu/configuration/configure_input_player.h
index b343f2c1d..ce443dec5 100644
--- a/src/yuzu/configuration/configure_input_player.h
+++ b/src/yuzu/configuration/configure_input_player.h
@@ -131,6 +131,7 @@ private:
131 131
132 std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param; 132 std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param;
133 std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param; 133 std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param;
134 std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> stick_mod_param;
134 std::array<Common::ParamPackage, Settings::NativeMotion::NumMotions> motions_param; 135 std::array<Common::ParamPackage, Settings::NativeMotion::NumMotions> motions_param;
135 136
136 static constexpr int ANALOG_SUB_BUTTONS_NUM = 4; 137 static constexpr int ANALOG_SUB_BUTTONS_NUM = 4;
@@ -140,8 +141,7 @@ private:
140 /// Each motion input is represented by a QPushButton. 141 /// Each motion input is represented by a QPushButton.
141 std::array<QPushButton*, Settings::NativeMotion::NumMotions> motion_map; 142 std::array<QPushButton*, Settings::NativeMotion::NumMotions> motion_map;
142 /// Extra buttons for the modifiers. 143 /// Extra buttons for the modifiers.
143 Common::ParamPackage lstick_mod; 144 std::array<QPushButton*, Settings::NativeAnalog::NumAnalogs> mod_buttons;
144 Common::ParamPackage rstick_mod;
145 145
146 /// A group of four QPushButtons represent one analog input. The buttons each represent up, 146 /// A group of four QPushButtons represent one analog input. The buttons each represent up,
147 /// down, left, right, respectively. 147 /// down, left, right, respectively.