diff options
Diffstat (limited to '')
| -rw-r--r-- | src/yuzu/configuration/configure_input_advanced.cpp | 169 |
1 files changed, 169 insertions, 0 deletions
diff --git a/src/yuzu/configuration/configure_input_advanced.cpp b/src/yuzu/configuration/configure_input_advanced.cpp new file mode 100644 index 000000000..18db04e7e --- /dev/null +++ b/src/yuzu/configuration/configure_input_advanced.cpp | |||
| @@ -0,0 +1,169 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <QColorDialog> | ||
| 6 | #include "core/core.h" | ||
| 7 | #include "core/settings.h" | ||
| 8 | #include "ui_configure_input_advanced.h" | ||
| 9 | #include "yuzu/configuration/configure_input_advanced.h" | ||
| 10 | |||
| 11 | ConfigureInputAdvanced::ConfigureInputAdvanced(QWidget* parent) | ||
| 12 | : QWidget(parent), ui(new Ui::ConfigureInputAdvanced) { | ||
| 13 | ui->setupUi(this); | ||
| 14 | |||
| 15 | controllers_color_buttons = {{ | ||
| 16 | { | ||
| 17 | ui->player1_left_body_button, | ||
| 18 | ui->player1_left_buttons_button, | ||
| 19 | ui->player1_right_body_button, | ||
| 20 | ui->player1_right_buttons_button, | ||
| 21 | }, | ||
| 22 | { | ||
| 23 | ui->player2_left_body_button, | ||
| 24 | ui->player2_left_buttons_button, | ||
| 25 | ui->player2_right_body_button, | ||
| 26 | ui->player2_right_buttons_button, | ||
| 27 | }, | ||
| 28 | { | ||
| 29 | ui->player3_left_body_button, | ||
| 30 | ui->player3_left_buttons_button, | ||
| 31 | ui->player3_right_body_button, | ||
| 32 | ui->player3_right_buttons_button, | ||
| 33 | }, | ||
| 34 | { | ||
| 35 | ui->player4_left_body_button, | ||
| 36 | ui->player4_left_buttons_button, | ||
| 37 | ui->player4_right_body_button, | ||
| 38 | ui->player4_right_buttons_button, | ||
| 39 | }, | ||
| 40 | { | ||
| 41 | ui->player5_left_body_button, | ||
| 42 | ui->player5_left_buttons_button, | ||
| 43 | ui->player5_right_body_button, | ||
| 44 | ui->player5_right_buttons_button, | ||
| 45 | }, | ||
| 46 | { | ||
| 47 | ui->player6_left_body_button, | ||
| 48 | ui->player6_left_buttons_button, | ||
| 49 | ui->player6_right_body_button, | ||
| 50 | ui->player6_right_buttons_button, | ||
| 51 | }, | ||
| 52 | { | ||
| 53 | ui->player7_left_body_button, | ||
| 54 | ui->player7_left_buttons_button, | ||
| 55 | ui->player7_right_body_button, | ||
| 56 | ui->player7_right_buttons_button, | ||
| 57 | }, | ||
| 58 | { | ||
| 59 | ui->player8_left_body_button, | ||
| 60 | ui->player8_left_buttons_button, | ||
| 61 | ui->player8_right_body_button, | ||
| 62 | ui->player8_right_buttons_button, | ||
| 63 | }, | ||
| 64 | }}; | ||
| 65 | |||
| 66 | for (std::size_t player_idx = 0; player_idx < controllers_color_buttons.size(); ++player_idx) { | ||
| 67 | auto& color_buttons = controllers_color_buttons[player_idx]; | ||
| 68 | for (std::size_t button_idx = 0; button_idx < color_buttons.size(); ++button_idx) { | ||
| 69 | connect(color_buttons[button_idx], &QPushButton::clicked, this, | ||
| 70 | [this, player_idx, button_idx] { | ||
| 71 | OnControllerButtonClick(static_cast<int>(player_idx), | ||
| 72 | static_cast<int>(button_idx)); | ||
| 73 | }); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | connect(ui->mouse_enabled, &QCheckBox::stateChanged, this, | ||
| 78 | &ConfigureInputAdvanced::UpdateUIEnabled); | ||
| 79 | connect(ui->debug_enabled, &QCheckBox::stateChanged, this, | ||
| 80 | &ConfigureInputAdvanced::UpdateUIEnabled); | ||
| 81 | connect(ui->touchscreen_enabled, &QCheckBox::stateChanged, this, | ||
| 82 | &ConfigureInputAdvanced::UpdateUIEnabled); | ||
| 83 | |||
| 84 | connect(ui->debug_configure, &QPushButton::clicked, this, | ||
| 85 | [this] { CallDebugControllerDialog(); }); | ||
| 86 | connect(ui->mouse_advanced, &QPushButton::clicked, this, [this] { CallMouseConfigDialog(); }); | ||
| 87 | connect(ui->touchscreen_advanced, &QPushButton::clicked, this, | ||
| 88 | [this] { CallTouchscreenConfigDialog(); }); | ||
| 89 | |||
| 90 | LoadConfiguration(); | ||
| 91 | } | ||
| 92 | |||
| 93 | ConfigureInputAdvanced::~ConfigureInputAdvanced() = default; | ||
| 94 | |||
| 95 | void ConfigureInputAdvanced::OnControllerButtonClick(int player_idx, int button_idx) { | ||
| 96 | const QColor new_bg_color = QColorDialog::getColor(controllers_colors[player_idx][button_idx]); | ||
| 97 | if (!new_bg_color.isValid()) { | ||
| 98 | return; | ||
| 99 | } | ||
| 100 | controllers_colors[player_idx][button_idx] = new_bg_color; | ||
| 101 | controllers_color_buttons[player_idx][button_idx]->setStyleSheet( | ||
| 102 | QStringLiteral("background-color: %1; min-width: 55px;") | ||
| 103 | .arg(controllers_colors[player_idx][button_idx].name())); | ||
| 104 | } | ||
| 105 | |||
| 106 | void ConfigureInputAdvanced::ApplyConfiguration() { | ||
| 107 | for (std::size_t player_idx = 0; player_idx < controllers_color_buttons.size(); ++player_idx) { | ||
| 108 | auto& player = Settings::values.players[player_idx]; | ||
| 109 | std::array<u32, 4> colors{}; | ||
| 110 | std::transform(controllers_colors[player_idx].begin(), controllers_colors[player_idx].end(), | ||
| 111 | colors.begin(), [](QColor color) { return color.rgb(); }); | ||
| 112 | |||
| 113 | player.body_color_left = colors[0]; | ||
| 114 | player.button_color_left = colors[1]; | ||
| 115 | player.body_color_right = colors[2]; | ||
| 116 | player.button_color_right = colors[3]; | ||
| 117 | } | ||
| 118 | |||
| 119 | Settings::values.debug_pad_enabled = ui->debug_enabled->isChecked(); | ||
| 120 | Settings::values.mouse_enabled = ui->mouse_enabled->isChecked(); | ||
| 121 | Settings::values.keyboard_enabled = ui->keyboard_enabled->isChecked(); | ||
| 122 | Settings::values.touchscreen.enabled = ui->touchscreen_enabled->isChecked(); | ||
| 123 | } | ||
| 124 | |||
| 125 | void ConfigureInputAdvanced::LoadConfiguration() { | ||
| 126 | for (std::size_t player_idx = 0; player_idx < controllers_color_buttons.size(); ++player_idx) { | ||
| 127 | auto& player = Settings::values.players[player_idx]; | ||
| 128 | std::array<u32, 4> colors = { | ||
| 129 | player.body_color_left, | ||
| 130 | player.button_color_left, | ||
| 131 | player.body_color_right, | ||
| 132 | player.button_color_right, | ||
| 133 | }; | ||
| 134 | |||
| 135 | std::transform(colors.begin(), colors.end(), controllers_colors[player_idx].begin(), | ||
| 136 | [](u32 rgb) { return QColor::fromRgb(rgb); }); | ||
| 137 | |||
| 138 | for (std::size_t button_idx = 0; button_idx < colors.size(); ++button_idx) { | ||
| 139 | controllers_color_buttons[player_idx][button_idx]->setStyleSheet( | ||
| 140 | QStringLiteral("background-color: %1; min-width: 55px;") | ||
| 141 | .arg(controllers_colors[player_idx][button_idx].name())); | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | ui->debug_enabled->setChecked(Settings::values.debug_pad_enabled); | ||
| 146 | ui->mouse_enabled->setChecked(Settings::values.mouse_enabled); | ||
| 147 | ui->keyboard_enabled->setChecked(Settings::values.keyboard_enabled); | ||
| 148 | ui->touchscreen_enabled->setChecked(Settings::values.touchscreen.enabled); | ||
| 149 | |||
| 150 | UpdateUIEnabled(); | ||
| 151 | } | ||
| 152 | |||
| 153 | void ConfigureInputAdvanced::changeEvent(QEvent* event) { | ||
| 154 | if (event->type() == QEvent::LanguageChange) { | ||
| 155 | RetranslateUI(); | ||
| 156 | } | ||
| 157 | |||
| 158 | QWidget::changeEvent(event); | ||
| 159 | } | ||
| 160 | |||
| 161 | void ConfigureInputAdvanced::RetranslateUI() { | ||
| 162 | ui->retranslateUi(this); | ||
| 163 | } | ||
| 164 | |||
| 165 | void ConfigureInputAdvanced::UpdateUIEnabled() { | ||
| 166 | ui->mouse_advanced->setEnabled(ui->mouse_enabled->isChecked()); | ||
| 167 | ui->debug_configure->setEnabled(ui->debug_enabled->isChecked()); | ||
| 168 | ui->touchscreen_advanced->setEnabled(ui->touchscreen_enabled->isChecked()); | ||
| 169 | } | ||