2020-07-22 16:39:53 +02:00
|
|
|
// Copyright 2020 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <QColorDialog>
|
2021-04-15 01:07:40 +02:00
|
|
|
#include "common/settings.h"
|
2020-07-22 16:39:53 +02:00
|
|
|
#include "core/core.h"
|
|
|
|
#include "ui_configure_input_advanced.h"
|
|
|
|
#include "yuzu/configuration/configure_input_advanced.h"
|
|
|
|
|
|
|
|
ConfigureInputAdvanced::ConfigureInputAdvanced(QWidget* parent)
|
2020-08-15 21:26:29 +02:00
|
|
|
: QWidget(parent), ui(std::make_unique<Ui::ConfigureInputAdvanced>()) {
|
2020-07-22 16:39:53 +02:00
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
controllers_color_buttons = {{
|
|
|
|
{
|
|
|
|
ui->player1_left_body_button,
|
|
|
|
ui->player1_left_buttons_button,
|
|
|
|
ui->player1_right_body_button,
|
|
|
|
ui->player1_right_buttons_button,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ui->player2_left_body_button,
|
|
|
|
ui->player2_left_buttons_button,
|
|
|
|
ui->player2_right_body_button,
|
|
|
|
ui->player2_right_buttons_button,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ui->player3_left_body_button,
|
|
|
|
ui->player3_left_buttons_button,
|
|
|
|
ui->player3_right_body_button,
|
|
|
|
ui->player3_right_buttons_button,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ui->player4_left_body_button,
|
|
|
|
ui->player4_left_buttons_button,
|
|
|
|
ui->player4_right_body_button,
|
|
|
|
ui->player4_right_buttons_button,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ui->player5_left_body_button,
|
|
|
|
ui->player5_left_buttons_button,
|
|
|
|
ui->player5_right_body_button,
|
|
|
|
ui->player5_right_buttons_button,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ui->player6_left_body_button,
|
|
|
|
ui->player6_left_buttons_button,
|
|
|
|
ui->player6_right_body_button,
|
|
|
|
ui->player6_right_buttons_button,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ui->player7_left_body_button,
|
|
|
|
ui->player7_left_buttons_button,
|
|
|
|
ui->player7_right_body_button,
|
|
|
|
ui->player7_right_buttons_button,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ui->player8_left_body_button,
|
|
|
|
ui->player8_left_buttons_button,
|
|
|
|
ui->player8_right_body_button,
|
|
|
|
ui->player8_right_buttons_button,
|
|
|
|
},
|
|
|
|
}};
|
|
|
|
|
|
|
|
for (std::size_t player_idx = 0; player_idx < controllers_color_buttons.size(); ++player_idx) {
|
|
|
|
auto& color_buttons = controllers_color_buttons[player_idx];
|
|
|
|
for (std::size_t button_idx = 0; button_idx < color_buttons.size(); ++button_idx) {
|
|
|
|
connect(color_buttons[button_idx], &QPushButton::clicked, this,
|
|
|
|
[this, player_idx, button_idx] {
|
2020-10-27 18:33:25 +01:00
|
|
|
OnControllerButtonClick(player_idx, button_idx);
|
2020-07-22 16:39:53 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(ui->mouse_enabled, &QCheckBox::stateChanged, this,
|
|
|
|
&ConfigureInputAdvanced::UpdateUIEnabled);
|
|
|
|
connect(ui->debug_enabled, &QCheckBox::stateChanged, this,
|
|
|
|
&ConfigureInputAdvanced::UpdateUIEnabled);
|
|
|
|
connect(ui->touchscreen_enabled, &QCheckBox::stateChanged, this,
|
|
|
|
&ConfigureInputAdvanced::UpdateUIEnabled);
|
|
|
|
|
|
|
|
connect(ui->debug_configure, &QPushButton::clicked, this,
|
|
|
|
[this] { CallDebugControllerDialog(); });
|
|
|
|
connect(ui->mouse_advanced, &QPushButton::clicked, this, [this] { CallMouseConfigDialog(); });
|
|
|
|
connect(ui->touchscreen_advanced, &QPushButton::clicked, this,
|
|
|
|
[this] { CallTouchscreenConfigDialog(); });
|
2020-08-29 20:56:51 +02:00
|
|
|
connect(ui->buttonMotionTouch, &QPushButton::clicked, this,
|
2020-08-30 00:07:38 +02:00
|
|
|
&ConfigureInputAdvanced::CallMotionTouchConfigDialog);
|
2020-07-22 16:39:53 +02:00
|
|
|
|
2021-09-18 13:41:51 +02:00
|
|
|
#ifndef _WIN32
|
|
|
|
ui->enable_raw_input->setVisible(false);
|
|
|
|
#endif
|
|
|
|
|
2020-07-22 16:39:53 +02:00
|
|
|
LoadConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigureInputAdvanced::~ConfigureInputAdvanced() = default;
|
|
|
|
|
2020-10-27 18:33:25 +01:00
|
|
|
void ConfigureInputAdvanced::OnControllerButtonClick(std::size_t player_idx,
|
|
|
|
std::size_t button_idx) {
|
2020-07-22 16:39:53 +02:00
|
|
|
const QColor new_bg_color = QColorDialog::getColor(controllers_colors[player_idx][button_idx]);
|
|
|
|
if (!new_bg_color.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
controllers_colors[player_idx][button_idx] = new_bg_color;
|
|
|
|
controllers_color_buttons[player_idx][button_idx]->setStyleSheet(
|
2020-09-13 15:25:22 +02:00
|
|
|
QStringLiteral("background-color: %1; min-width: 60px;")
|
2020-07-22 16:39:53 +02:00
|
|
|
.arg(controllers_colors[player_idx][button_idx].name()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureInputAdvanced::ApplyConfiguration() {
|
|
|
|
for (std::size_t player_idx = 0; player_idx < controllers_color_buttons.size(); ++player_idx) {
|
2020-09-28 16:00:15 +02:00
|
|
|
auto& player = Settings::values.players.GetValue()[player_idx];
|
2020-07-22 16:39:53 +02:00
|
|
|
std::array<u32, 4> colors{};
|
|
|
|
std::transform(controllers_colors[player_idx].begin(), controllers_colors[player_idx].end(),
|
|
|
|
colors.begin(), [](QColor color) { return color.rgb(); });
|
|
|
|
|
|
|
|
player.body_color_left = colors[0];
|
|
|
|
player.button_color_left = colors[1];
|
|
|
|
player.body_color_right = colors[2];
|
|
|
|
player.button_color_right = colors[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings::values.debug_pad_enabled = ui->debug_enabled->isChecked();
|
|
|
|
Settings::values.mouse_enabled = ui->mouse_enabled->isChecked();
|
|
|
|
Settings::values.keyboard_enabled = ui->keyboard_enabled->isChecked();
|
2020-11-27 03:56:06 +01:00
|
|
|
Settings::values.emulate_analog_keyboard = ui->emulate_analog_keyboard->isChecked();
|
2021-02-03 19:34:25 +01:00
|
|
|
Settings::values.mouse_panning = ui->mouse_panning->isChecked();
|
|
|
|
Settings::values.mouse_panning_sensitivity =
|
|
|
|
static_cast<float>(ui->mouse_panning_sensitivity->value());
|
2020-07-22 16:39:53 +02:00
|
|
|
Settings::values.touchscreen.enabled = ui->touchscreen_enabled->isChecked();
|
2021-09-02 01:48:01 +02:00
|
|
|
Settings::values.enable_raw_input = ui->enable_raw_input->isChecked();
|
2020-07-22 16:39:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureInputAdvanced::LoadConfiguration() {
|
|
|
|
for (std::size_t player_idx = 0; player_idx < controllers_color_buttons.size(); ++player_idx) {
|
2020-09-28 16:00:15 +02:00
|
|
|
auto& player = Settings::values.players.GetValue()[player_idx];
|
2020-07-22 16:39:53 +02:00
|
|
|
std::array<u32, 4> colors = {
|
|
|
|
player.body_color_left,
|
|
|
|
player.button_color_left,
|
|
|
|
player.body_color_right,
|
|
|
|
player.button_color_right,
|
|
|
|
};
|
|
|
|
|
|
|
|
std::transform(colors.begin(), colors.end(), controllers_colors[player_idx].begin(),
|
|
|
|
[](u32 rgb) { return QColor::fromRgb(rgb); });
|
|
|
|
|
|
|
|
for (std::size_t button_idx = 0; button_idx < colors.size(); ++button_idx) {
|
|
|
|
controllers_color_buttons[player_idx][button_idx]->setStyleSheet(
|
2020-09-13 15:25:22 +02:00
|
|
|
QStringLiteral("background-color: %1; min-width: 60px;")
|
2020-07-22 16:39:53 +02:00
|
|
|
.arg(controllers_colors[player_idx][button_idx].name()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-28 21:58:16 +02:00
|
|
|
ui->debug_enabled->setChecked(Settings::values.debug_pad_enabled.GetValue());
|
|
|
|
ui->mouse_enabled->setChecked(Settings::values.mouse_enabled.GetValue());
|
|
|
|
ui->keyboard_enabled->setChecked(Settings::values.keyboard_enabled.GetValue());
|
|
|
|
ui->emulate_analog_keyboard->setChecked(Settings::values.emulate_analog_keyboard.GetValue());
|
|
|
|
ui->mouse_panning->setChecked(Settings::values.mouse_panning.GetValue());
|
|
|
|
ui->mouse_panning_sensitivity->setValue(Settings::values.mouse_panning_sensitivity.GetValue());
|
2020-07-22 16:39:53 +02:00
|
|
|
ui->touchscreen_enabled->setChecked(Settings::values.touchscreen.enabled);
|
2021-09-02 01:48:01 +02:00
|
|
|
ui->enable_raw_input->setChecked(Settings::values.enable_raw_input.GetValue());
|
2020-07-22 16:39:53 +02:00
|
|
|
|
|
|
|
UpdateUIEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureInputAdvanced::changeEvent(QEvent* event) {
|
|
|
|
if (event->type() == QEvent::LanguageChange) {
|
|
|
|
RetranslateUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget::changeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureInputAdvanced::RetranslateUI() {
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureInputAdvanced::UpdateUIEnabled() {
|
|
|
|
ui->mouse_advanced->setEnabled(ui->mouse_enabled->isChecked());
|
|
|
|
ui->debug_configure->setEnabled(ui->debug_enabled->isChecked());
|
|
|
|
ui->touchscreen_advanced->setEnabled(ui->touchscreen_enabled->isChecked());
|
|
|
|
}
|