2018-09-11 01:29:59 +00:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
2016-07-29 12:45:49 +00:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2017-01-22 19:02:29 +00:00
|
|
|
#include <algorithm>
|
2016-07-29 12:45:49 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
2018-08-26 08:23:12 +00:00
|
|
|
#include <QMenu>
|
2017-12-06 04:26:29 +00:00
|
|
|
#include <QMessageBox>
|
2016-09-20 15:21:23 +00:00
|
|
|
#include <QTimer>
|
2017-01-22 19:02:29 +00:00
|
|
|
#include "common/param_package.h"
|
2018-11-02 02:06:48 +00:00
|
|
|
#include "configuration/configure_touchscreen_advanced.h"
|
|
|
|
#include "core/core.h"
|
2017-01-22 19:02:29 +00:00
|
|
|
#include "input_common/main.h"
|
2018-11-02 02:06:48 +00:00
|
|
|
#include "ui_configure_input.h"
|
|
|
|
#include "ui_configure_input_player.h"
|
|
|
|
#include "ui_configure_mouse_advanced.h"
|
|
|
|
#include "ui_configure_touchscreen_advanced.h"
|
2018-01-12 03:33:56 +00:00
|
|
|
#include "yuzu/configuration/config.h"
|
|
|
|
#include "yuzu/configuration/configure_input.h"
|
2018-11-02 02:06:48 +00:00
|
|
|
#include "yuzu/configuration/configure_input_player.h"
|
|
|
|
#include "yuzu/configuration/configure_mouse_advanced.h"
|
2017-12-13 18:06:14 +00:00
|
|
|
|
2016-09-18 00:38:01 +00:00
|
|
|
ConfigureInput::ConfigureInput(QWidget* parent)
|
2018-11-02 02:06:48 +00:00
|
|
|
: QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()) {
|
2016-07-29 12:45:49 +00:00
|
|
|
ui->setupUi(this);
|
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
players_enabled = {
|
|
|
|
ui->player1_checkbox, ui->player2_checkbox, ui->player3_checkbox, ui->player4_checkbox,
|
|
|
|
ui->player5_checkbox, ui->player6_checkbox, ui->player7_checkbox, ui->player8_checkbox,
|
2016-07-29 12:45:49 +00:00
|
|
|
};
|
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
player_controller = {
|
|
|
|
ui->player1_combobox, ui->player2_combobox, ui->player3_combobox, ui->player4_combobox,
|
|
|
|
ui->player5_combobox, ui->player6_combobox, ui->player7_combobox, ui->player8_combobox,
|
|
|
|
};
|
2017-01-22 19:02:29 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
player_configure = {
|
|
|
|
ui->player1_configure, ui->player2_configure, ui->player3_configure, ui->player4_configure,
|
|
|
|
ui->player5_configure, ui->player6_configure, ui->player7_configure, ui->player8_configure,
|
|
|
|
};
|
2017-12-06 04:26:29 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
for (auto* controller_box : player_controller) {
|
|
|
|
controller_box->addItems(
|
|
|
|
{"Pro Controller", "Dual Joycons", "Single Right Joycon", "Single Left Joycon"});
|
2017-01-22 19:02:29 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
this->loadConfiguration();
|
|
|
|
updateUIEnabled();
|
2016-12-09 23:59:09 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
connect(ui->restore_defaults_button, &QPushButton::pressed, this,
|
|
|
|
&ConfigureInput::restoreDefaults);
|
2016-12-09 23:59:09 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
for (auto* enabled : players_enabled)
|
|
|
|
connect(enabled, &QCheckBox::stateChanged, this, &ConfigureInput::updateUIEnabled);
|
|
|
|
connect(ui->use_docked_mode, &QCheckBox::stateChanged, this, &ConfigureInput::updateUIEnabled);
|
|
|
|
connect(ui->handheld_connected, &QCheckBox::stateChanged, this,
|
|
|
|
&ConfigureInput::updateUIEnabled);
|
|
|
|
connect(ui->mouse_enabled, &QCheckBox::stateChanged, this, &ConfigureInput::updateUIEnabled);
|
|
|
|
connect(ui->keyboard_enabled, &QCheckBox::stateChanged, this, &ConfigureInput::updateUIEnabled);
|
|
|
|
connect(ui->debug_enabled, &QCheckBox::stateChanged, this, &ConfigureInput::updateUIEnabled);
|
|
|
|
connect(ui->touchscreen_enabled, &QCheckBox::stateChanged, this,
|
|
|
|
&ConfigureInput::updateUIEnabled);
|
2017-12-06 04:26:29 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
for (std::size_t i = 0; i < player_configure.size(); ++i) {
|
|
|
|
connect(player_configure[i], &QPushButton::pressed, this,
|
|
|
|
[this, i]() { CallConfigureDialog<ConfigureInputPlayer>(i, false); });
|
|
|
|
}
|
2016-07-29 12:45:49 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
connect(ui->handheld_configure, &QPushButton::pressed, this,
|
|
|
|
[this]() { CallConfigureDialog<ConfigureInputPlayer>(8, false); });
|
2017-01-22 19:02:29 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
connect(ui->debug_configure, &QPushButton::pressed, this,
|
|
|
|
[this]() { CallConfigureDialog<ConfigureInputPlayer>(9, true); });
|
2016-07-29 12:45:49 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
connect(ui->mouse_advanced, &QPushButton::pressed, this,
|
|
|
|
[this]() { CallConfigureDialog<ConfigureMouseAdvanced>(); });
|
2016-07-29 12:45:49 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
connect(ui->touchscreen_advanced, &QPushButton::pressed, this,
|
|
|
|
[this]() { CallConfigureDialog<ConfigureTouchscreenAdvanced>(); });
|
|
|
|
|
|
|
|
ui->use_docked_mode->setEnabled(!Core::System::GetInstance().IsPoweredOn());
|
2016-07-29 12:45:49 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
template <typename Dialog, typename... Args>
|
|
|
|
void ConfigureInput::CallConfigureDialog(Args... args) {
|
|
|
|
this->applyConfiguration();
|
|
|
|
Dialog dialog(this, args...);
|
2017-01-22 19:02:29 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
const auto res = dialog.exec();
|
|
|
|
if (res == QDialog::Accepted) {
|
|
|
|
dialog.applyConfiguration();
|
2017-01-22 19:02:29 +00:00
|
|
|
}
|
2018-08-26 08:23:12 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
void ConfigureInput::applyConfiguration() {
|
|
|
|
for (std::size_t i = 0; i < 8; ++i) {
|
|
|
|
Settings::values.players[i].connected = players_enabled[i]->isChecked();
|
|
|
|
Settings::values.players[i].type =
|
|
|
|
static_cast<Settings::ControllerType>(player_controller[i]->currentIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings::values.use_docked_mode = ui->use_docked_mode->isChecked();
|
|
|
|
Settings::values.players[8].connected = ui->handheld_connected->isChecked();
|
|
|
|
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();
|
|
|
|
Settings::values.touchscreen.enabled = ui->touchscreen_enabled->isChecked();
|
2017-01-22 19:02:29 +00:00
|
|
|
}
|
2016-07-29 12:45:49 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
void ConfigureInput::updateUIEnabled() {
|
|
|
|
for (std::size_t i = 0; i < 8; ++i) {
|
|
|
|
const auto enabled = players_enabled[i]->checkState() == Qt::Checked;
|
2017-01-22 19:02:29 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
player_controller[i]->setEnabled(enabled);
|
|
|
|
player_configure[i]->setEnabled(enabled);
|
2016-12-09 23:59:09 +00:00
|
|
|
}
|
2017-12-06 04:26:29 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
bool hit_disabled = false;
|
|
|
|
for (auto* player : players_enabled) {
|
|
|
|
if (hit_disabled)
|
|
|
|
player->setDisabled(true);
|
|
|
|
else
|
|
|
|
player->setEnabled(true);
|
|
|
|
if (!player->isChecked())
|
|
|
|
hit_disabled = true;
|
2017-12-06 04:26:29 +00:00
|
|
|
}
|
2016-07-29 12:45:49 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
ui->handheld_connected->setEnabled(!ui->use_docked_mode->isChecked());
|
|
|
|
ui->handheld_configure->setEnabled(ui->handheld_connected->isChecked() &&
|
|
|
|
!ui->use_docked_mode->isChecked());
|
|
|
|
ui->mouse_advanced->setEnabled(ui->mouse_enabled->isChecked());
|
|
|
|
ui->debug_configure->setEnabled(ui->debug_enabled->isChecked());
|
|
|
|
ui->touchscreen_advanced->setEnabled(ui->touchscreen_enabled->isChecked());
|
2016-07-29 12:45:49 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
void ConfigureInput::loadConfiguration() {
|
|
|
|
std::stable_partition(Settings::values.players.begin(), Settings::values.players.end(),
|
|
|
|
[](const auto& player) { return player.connected; });
|
2016-12-09 23:59:09 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
for (std::size_t i = 0; i < 8; ++i) {
|
|
|
|
players_enabled[i]->setChecked(Settings::values.players[i].connected);
|
|
|
|
player_controller[i]->setCurrentIndex(static_cast<u8>(Settings::values.players[i].type));
|
2017-12-06 04:26:29 +00:00
|
|
|
}
|
2016-12-09 23:59:09 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
ui->use_docked_mode->setChecked(Settings::values.use_docked_mode);
|
|
|
|
ui->handheld_connected->setChecked(Settings::values.players[8].connected);
|
|
|
|
ui->debug_enabled->setChecked(Settings::values.debug_pad_enabled);
|
|
|
|
ui->mouse_enabled->setChecked(Settings::values.mouse_enabled);
|
|
|
|
ui->keyboard_enabled->setChecked(Settings::values.keyboard_enabled);
|
|
|
|
ui->touchscreen_enabled->setChecked(Settings::values.touchscreen.enabled);
|
|
|
|
|
|
|
|
updateUIEnabled();
|
2017-12-06 04:26:29 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
void ConfigureInput::restoreDefaults() {
|
|
|
|
players_enabled[0]->setCheckState(Qt::Checked);
|
|
|
|
player_controller[0]->setCurrentIndex(1);
|
2017-12-06 04:26:29 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
for (std::size_t i = 1; i < 8; ++i) {
|
|
|
|
players_enabled[i]->setCheckState(Qt::Unchecked);
|
|
|
|
player_controller[i]->setCurrentIndex(0);
|
2017-12-06 04:26:29 +00:00
|
|
|
}
|
2018-11-02 02:06:48 +00:00
|
|
|
|
|
|
|
ui->use_docked_mode->setCheckState(Qt::Unchecked);
|
|
|
|
ui->handheld_connected->setCheckState(Qt::Unchecked);
|
|
|
|
ui->mouse_enabled->setCheckState(Qt::Unchecked);
|
|
|
|
ui->keyboard_enabled->setCheckState(Qt::Unchecked);
|
|
|
|
ui->debug_enabled->setCheckState(Qt::Unchecked);
|
|
|
|
ui->touchscreen_enabled->setCheckState(Qt::Checked);
|
|
|
|
updateUIEnabled();
|
2016-07-29 12:45:49 +00:00
|
|
|
}
|