2018-09-11 03:29:59 +02:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
2016-07-29 14:45:49 +02:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2017-01-22 20:02:29 +01:00
|
|
|
#include <algorithm>
|
2016-07-29 14:45:49 +02:00
|
|
|
#include <memory>
|
2018-11-27 11:00:56 +01:00
|
|
|
|
2016-09-20 17:21:23 +02:00
|
|
|
#include <QTimer>
|
2018-11-27 11:00:56 +01:00
|
|
|
|
2018-11-02 03:06:48 +01:00
|
|
|
#include "configuration/configure_touchscreen_advanced.h"
|
|
|
|
#include "core/core.h"
|
2018-11-04 16:18:59 +01:00
|
|
|
#include "core/hle/service/am/am.h"
|
|
|
|
#include "core/hle/service/am/applet_ae.h"
|
|
|
|
#include "core/hle/service/am/applet_oe.h"
|
2018-11-03 17:55:39 +01:00
|
|
|
#include "core/hle/service/hid/controllers/npad.h"
|
2018-11-04 16:18:59 +01:00
|
|
|
#include "core/hle/service/sm/sm.h"
|
2018-11-02 03:06:48 +01:00
|
|
|
#include "ui_configure_input.h"
|
|
|
|
#include "ui_configure_input_player.h"
|
2018-01-12 04:33:56 +01:00
|
|
|
#include "yuzu/configuration/configure_input.h"
|
2018-11-02 03:06:48 +01:00
|
|
|
#include "yuzu/configuration/configure_input_player.h"
|
|
|
|
#include "yuzu/configuration/configure_mouse_advanced.h"
|
2017-12-13 19:06:14 +01:00
|
|
|
|
2018-12-05 04:01:01 +01:00
|
|
|
void OnDockedModeChanged(bool last_state, bool new_state) {
|
|
|
|
if (last_state == new_state) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Core::System& system{Core::System::GetInstance()};
|
|
|
|
if (!system.IsPoweredOn()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Service::SM::ServiceManager& sm = system.ServiceManager();
|
|
|
|
|
|
|
|
// Message queue is shared between these services, we just need to signal an operation
|
|
|
|
// change to one and it will handle both automatically
|
|
|
|
auto applet_oe = sm.GetService<Service::AM::AppletOE>("appletOE");
|
|
|
|
auto applet_ae = sm.GetService<Service::AM::AppletAE>("appletAE");
|
|
|
|
bool has_signalled = false;
|
|
|
|
|
|
|
|
if (applet_oe != nullptr) {
|
|
|
|
applet_oe->GetMessageQueue()->OperationModeChanged();
|
|
|
|
has_signalled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (applet_ae != nullptr && !has_signalled) {
|
|
|
|
applet_ae->GetMessageQueue()->OperationModeChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-27 11:14:59 +01:00
|
|
|
namespace {
|
|
|
|
template <typename Dialog, typename... Args>
|
|
|
|
void CallConfigureDialog(ConfigureInput& parent, Args&&... args) {
|
|
|
|
parent.applyConfiguration();
|
|
|
|
Dialog dialog(&parent, std::forward<Args>(args)...);
|
|
|
|
|
|
|
|
const auto res = dialog.exec();
|
|
|
|
if (res == QDialog::Accepted) {
|
|
|
|
dialog.applyConfiguration();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // Anonymous namespace
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
ConfigureInput::ConfigureInput(QWidget* parent)
|
2018-11-22 21:27:07 +01:00
|
|
|
: QDialog(parent), ui(std::make_unique<Ui::ConfigureInput>()) {
|
2016-07-29 14:45:49 +02:00
|
|
|
ui->setupUi(this);
|
|
|
|
|
2018-11-04 16:18:59 +01:00
|
|
|
players_controller = {
|
2018-11-02 03:06:48 +01:00
|
|
|
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 20:02:29 +01:00
|
|
|
|
2018-11-04 16:18:59 +01:00
|
|
|
players_configure = {
|
2018-11-02 03:06:48 +01:00
|
|
|
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 05:26:29 +01:00
|
|
|
|
2018-11-04 16:18:59 +01:00
|
|
|
for (auto* controller_box : players_controller) {
|
2019-05-19 17:23:21 +02:00
|
|
|
controller_box->addItems({tr("None"), tr("Pro Controller"), tr("Dual Joycons"),
|
|
|
|
tr("Single Right Joycon"), tr("Single Left Joycon")});
|
2017-01-22 20:02:29 +01:00
|
|
|
}
|
|
|
|
|
2018-11-02 03:06:48 +01:00
|
|
|
this->loadConfiguration();
|
|
|
|
updateUIEnabled();
|
2016-12-10 00:59:09 +01:00
|
|
|
|
2018-11-02 03:06:48 +01:00
|
|
|
connect(ui->restore_defaults_button, &QPushButton::pressed, this,
|
|
|
|
&ConfigureInput::restoreDefaults);
|
2016-12-10 00:59:09 +01:00
|
|
|
|
2019-05-19 17:23:21 +02:00
|
|
|
for (auto* enabled : players_controller) {
|
2018-11-04 16:18:59 +01:00
|
|
|
connect(enabled, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
|
|
|
&ConfigureInput::updateUIEnabled);
|
2019-05-19 17:23:21 +02:00
|
|
|
}
|
2018-11-02 03:06:48 +01:00
|
|
|
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 05:26:29 +01:00
|
|
|
|
2018-11-04 16:18:59 +01:00
|
|
|
for (std::size_t i = 0; i < players_configure.size(); ++i) {
|
|
|
|
connect(players_configure[i], &QPushButton::pressed, this,
|
2018-11-27 11:14:59 +01:00
|
|
|
[this, i] { CallConfigureDialog<ConfigureInputPlayer>(*this, i, false); });
|
2018-11-02 03:06:48 +01:00
|
|
|
}
|
2016-07-29 14:45:49 +02:00
|
|
|
|
2018-11-02 03:06:48 +01:00
|
|
|
connect(ui->handheld_configure, &QPushButton::pressed, this,
|
2018-11-27 11:14:59 +01:00
|
|
|
[this] { CallConfigureDialog<ConfigureInputPlayer>(*this, 8, false); });
|
2017-01-22 20:02:29 +01:00
|
|
|
|
2018-11-02 03:06:48 +01:00
|
|
|
connect(ui->debug_configure, &QPushButton::pressed, this,
|
2018-11-27 11:14:59 +01:00
|
|
|
[this] { CallConfigureDialog<ConfigureInputPlayer>(*this, 9, true); });
|
2016-07-29 14:45:49 +02:00
|
|
|
|
2018-11-02 03:06:48 +01:00
|
|
|
connect(ui->mouse_advanced, &QPushButton::pressed, this,
|
2018-11-27 11:14:59 +01:00
|
|
|
[this] { CallConfigureDialog<ConfigureMouseAdvanced>(*this); });
|
2016-07-29 14:45:49 +02:00
|
|
|
|
2018-11-02 03:06:48 +01:00
|
|
|
connect(ui->touchscreen_advanced, &QPushButton::pressed, this,
|
2018-11-27 11:14:59 +01:00
|
|
|
[this] { CallConfigureDialog<ConfigureTouchscreenAdvanced>(*this); });
|
2018-08-26 10:23:12 +02:00
|
|
|
}
|
|
|
|
|
2018-12-02 20:06:39 +01:00
|
|
|
ConfigureInput::~ConfigureInput() = default;
|
|
|
|
|
2018-11-02 03:06:48 +01:00
|
|
|
void ConfigureInput::applyConfiguration() {
|
2018-11-04 16:18:59 +01:00
|
|
|
for (std::size_t i = 0; i < players_controller.size(); ++i) {
|
|
|
|
const auto controller_type_index = players_controller[i]->currentIndex();
|
|
|
|
|
|
|
|
Settings::values.players[i].connected = controller_type_index != 0;
|
|
|
|
|
|
|
|
if (controller_type_index > 0) {
|
|
|
|
Settings::values.players[i].type =
|
|
|
|
static_cast<Settings::ControllerType>(controller_type_index - 1);
|
|
|
|
} else {
|
|
|
|
Settings::values.players[i].type = Settings::ControllerType::DualJoycon;
|
|
|
|
}
|
2018-11-02 03:06:48 +01:00
|
|
|
}
|
|
|
|
|
2018-11-04 16:18:59 +01:00
|
|
|
const bool pre_docked_mode = Settings::values.use_docked_mode;
|
2018-11-02 03:06:48 +01:00
|
|
|
Settings::values.use_docked_mode = ui->use_docked_mode->isChecked();
|
2018-11-04 16:18:59 +01:00
|
|
|
OnDockedModeChanged(pre_docked_mode, Settings::values.use_docked_mode);
|
2018-11-03 17:55:39 +01:00
|
|
|
Settings::values
|
|
|
|
.players[Service::HID::Controller_NPad::NPadIdToIndex(Service::HID::NPAD_HANDHELD)]
|
|
|
|
.connected = ui->handheld_connected->isChecked();
|
2018-11-02 03:06:48 +01:00
|
|
|
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 20:02:29 +01:00
|
|
|
}
|
2016-07-29 14:45:49 +02:00
|
|
|
|
2018-11-02 03:06:48 +01:00
|
|
|
void ConfigureInput::updateUIEnabled() {
|
|
|
|
bool hit_disabled = false;
|
2018-11-04 16:18:59 +01:00
|
|
|
for (auto* player : players_controller) {
|
2018-11-03 17:55:39 +01:00
|
|
|
player->setDisabled(hit_disabled);
|
2019-05-19 17:23:21 +02:00
|
|
|
if (hit_disabled) {
|
2018-11-10 23:09:33 +01:00
|
|
|
player->setCurrentIndex(0);
|
2019-05-19 17:23:21 +02:00
|
|
|
}
|
|
|
|
if (!hit_disabled && player->currentIndex() == 0) {
|
2018-11-02 03:06:48 +01:00
|
|
|
hit_disabled = true;
|
2019-05-19 17:23:21 +02:00
|
|
|
}
|
2017-12-06 05:26:29 +01:00
|
|
|
}
|
2016-07-29 14:45:49 +02:00
|
|
|
|
2018-11-04 16:18:59 +01:00
|
|
|
for (std::size_t i = 0; i < players_controller.size(); ++i) {
|
|
|
|
players_configure[i]->setEnabled(players_controller[i]->currentIndex() != 0);
|
|
|
|
}
|
|
|
|
|
2018-11-02 03:06:48 +01: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 14:45:49 +02:00
|
|
|
}
|
|
|
|
|
2018-11-02 03:06:48 +01:00
|
|
|
void ConfigureInput::loadConfiguration() {
|
2018-11-04 16:18:59 +01:00
|
|
|
std::stable_partition(
|
|
|
|
Settings::values.players.begin(),
|
|
|
|
Settings::values.players.begin() +
|
|
|
|
Service::HID::Controller_NPad::NPadIdToIndex(Service::HID::NPAD_HANDHELD),
|
|
|
|
[](const auto& player) { return player.connected; });
|
|
|
|
|
|
|
|
for (std::size_t i = 0; i < players_controller.size(); ++i) {
|
|
|
|
const auto connected = Settings::values.players[i].connected;
|
|
|
|
players_controller[i]->setCurrentIndex(
|
|
|
|
connected ? static_cast<u8>(Settings::values.players[i].type) + 1 : 0);
|
2017-12-06 05:26:29 +01:00
|
|
|
}
|
2016-12-10 00:59:09 +01:00
|
|
|
|
2018-11-02 03:06:48 +01:00
|
|
|
ui->use_docked_mode->setChecked(Settings::values.use_docked_mode);
|
2018-11-03 17:55:39 +01:00
|
|
|
ui->handheld_connected->setChecked(
|
|
|
|
Settings::values
|
|
|
|
.players[Service::HID::Controller_NPad::NPadIdToIndex(Service::HID::NPAD_HANDHELD)]
|
|
|
|
.connected);
|
2018-11-02 03:06:48 +01:00
|
|
|
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 05:26:29 +01:00
|
|
|
}
|
|
|
|
|
2018-11-02 03:06:48 +01:00
|
|
|
void ConfigureInput::restoreDefaults() {
|
2018-11-04 16:18:59 +01:00
|
|
|
players_controller[0]->setCurrentIndex(2);
|
2017-12-06 05:26:29 +01:00
|
|
|
|
2018-11-04 16:18:59 +01:00
|
|
|
for (std::size_t i = 1; i < players_controller.size(); ++i) {
|
|
|
|
players_controller[i]->setCurrentIndex(0);
|
2017-12-06 05:26:29 +01:00
|
|
|
}
|
2018-11-02 03:06:48 +01: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 14:45:49 +02:00
|
|
|
}
|