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>
|
2018-11-27 10:00:56 +00:00
|
|
|
|
2019-06-05 22:39:46 +00:00
|
|
|
#include <QSignalBlocker>
|
2016-09-20 15:21:23 +00:00
|
|
|
#include <QTimer>
|
2018-11-27 10:00:56 +00:00
|
|
|
|
2018-11-02 02:06:48 +00:00
|
|
|
#include "core/core.h"
|
2018-11-04 15:18:59 +00:00
|
|
|
#include "core/hle/service/am/am.h"
|
|
|
|
#include "core/hle/service/am/applet_ae.h"
|
|
|
|
#include "core/hle/service/am/applet_oe.h"
|
|
|
|
#include "core/hle/service/sm/sm.h"
|
2018-11-02 02:06:48 +00:00
|
|
|
#include "ui_configure_input.h"
|
2020-07-22 14:39:53 +00:00
|
|
|
#include "ui_configure_input_advanced.h"
|
2018-11-02 02:06:48 +00:00
|
|
|
#include "ui_configure_input_player.h"
|
2020-07-22 14:39:53 +00:00
|
|
|
#include "yuzu/configuration/configure_debug_controller.h"
|
2018-01-12 03:33:56 +00:00
|
|
|
#include "yuzu/configuration/configure_input.h"
|
2020-07-22 14:39:53 +00:00
|
|
|
#include "yuzu/configuration/configure_input_advanced.h"
|
2018-11-02 02:06:48 +00:00
|
|
|
#include "yuzu/configuration/configure_input_player.h"
|
2020-07-14 17:01:36 +00:00
|
|
|
#include "yuzu/configuration/configure_motion_touch.h"
|
2018-11-02 02:06:48 +00:00
|
|
|
#include "yuzu/configuration/configure_mouse_advanced.h"
|
2020-07-22 14:39:53 +00:00
|
|
|
#include "yuzu/configuration/configure_touchscreen_advanced.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
template <typename Dialog, typename... Args>
|
|
|
|
void CallConfigureDialog(ConfigureInput& parent, Args&&... args) {
|
|
|
|
Dialog dialog(&parent, std::forward<Args>(args)...);
|
|
|
|
|
|
|
|
const auto res = dialog.exec();
|
|
|
|
if (res == QDialog::Accepted) {
|
|
|
|
dialog.ApplyConfiguration();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // Anonymous namespace
|
2017-12-13 18:06:14 +00:00
|
|
|
|
2018-12-05 03:01:01 +00: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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-18 00:38:01 +00:00
|
|
|
ConfigureInput::ConfigureInput(QWidget* parent)
|
2020-07-22 14:39:53 +00:00
|
|
|
: QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()) {
|
2016-07-29 12:45:49 +00:00
|
|
|
ui->setupUi(this);
|
2020-08-27 19:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ConfigureInput::~ConfigureInput() = default;
|
2016-07-29 12:45:49 +00:00
|
|
|
|
2020-08-21 11:39:24 +00:00
|
|
|
void ConfigureInput::Initialize(InputCommon::InputSubsystem* input_subsystem, std::size_t max_players) {
|
2020-07-22 14:39:53 +00:00
|
|
|
player_controllers = {
|
2020-08-27 19:16:47 +00:00
|
|
|
new ConfigureInputPlayer(this, 0, ui->consoleInputSettings, input_subsystem),
|
|
|
|
new ConfigureInputPlayer(this, 1, ui->consoleInputSettings, input_subsystem),
|
|
|
|
new ConfigureInputPlayer(this, 2, ui->consoleInputSettings, input_subsystem),
|
|
|
|
new ConfigureInputPlayer(this, 3, ui->consoleInputSettings, input_subsystem),
|
|
|
|
new ConfigureInputPlayer(this, 4, ui->consoleInputSettings, input_subsystem),
|
|
|
|
new ConfigureInputPlayer(this, 5, ui->consoleInputSettings, input_subsystem),
|
|
|
|
new ConfigureInputPlayer(this, 6, ui->consoleInputSettings, input_subsystem),
|
|
|
|
new ConfigureInputPlayer(this, 7, ui->consoleInputSettings, input_subsystem),
|
2018-11-02 02:06:48 +00:00
|
|
|
};
|
2017-01-22 19:02:29 +00:00
|
|
|
|
2020-07-22 14:39:53 +00:00
|
|
|
player_tabs = {
|
|
|
|
ui->tabPlayer1, ui->tabPlayer2, ui->tabPlayer3, ui->tabPlayer4,
|
|
|
|
ui->tabPlayer5, ui->tabPlayer6, ui->tabPlayer7, ui->tabPlayer8,
|
2018-11-02 02:06:48 +00:00
|
|
|
};
|
2017-12-06 04:26:29 +00:00
|
|
|
|
2020-07-22 14:39:53 +00:00
|
|
|
player_connected = {
|
|
|
|
ui->checkboxPlayer1Connected, ui->checkboxPlayer2Connected, ui->checkboxPlayer3Connected,
|
|
|
|
ui->checkboxPlayer4Connected, ui->checkboxPlayer5Connected, ui->checkboxPlayer6Connected,
|
|
|
|
ui->checkboxPlayer7Connected, ui->checkboxPlayer8Connected,
|
|
|
|
};
|
2016-12-09 23:59:09 +00:00
|
|
|
|
2020-08-21 11:39:24 +00:00
|
|
|
std::array<QLabel*, 8> player_connected_labels = {
|
|
|
|
ui->label, ui->label_3, ui->label_4, ui->label_5,
|
|
|
|
ui->label_6, ui->label_7, ui->label_8, ui->label_9,
|
|
|
|
};
|
|
|
|
|
2020-07-22 14:39:53 +00:00
|
|
|
for (std::size_t i = 0; i < player_tabs.size(); ++i) {
|
|
|
|
player_tabs[i]->setLayout(new QHBoxLayout(player_tabs[i]));
|
|
|
|
player_tabs[i]->layout()->addWidget(player_controllers[i]);
|
|
|
|
connect(player_controllers[i], &ConfigureInputPlayer::Connected, [&, i](bool is_connected) {
|
|
|
|
if (is_connected) {
|
|
|
|
for (std::size_t index = 0; index <= i; ++index) {
|
|
|
|
player_connected[index]->setChecked(is_connected);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (std::size_t index = i; index < player_tabs.size(); ++index) {
|
|
|
|
player_connected[index]->setChecked(is_connected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
connect(player_controllers[i], &ConfigureInputPlayer::RefreshInputDevices,
|
2020-08-15 19:26:29 +00:00
|
|
|
[this] { UpdateAllInputDevices(); });
|
|
|
|
connect(player_connected[i], &QCheckBox::stateChanged, [this, i](int state) {
|
|
|
|
player_controllers[i]->ConnectPlayer(state == Qt::Checked);
|
|
|
|
});
|
2020-08-21 11:39:24 +00:00
|
|
|
|
|
|
|
// Remove/hide all the elements that exceed max_players, if applicable.
|
|
|
|
if (i >= max_players) {
|
|
|
|
ui->tabWidget->removeTab(static_cast<int>(max_players));
|
|
|
|
player_connected[i]->hide();
|
|
|
|
player_connected_labels[i]->hide();
|
|
|
|
}
|
2019-05-19 15:23:21 +00:00
|
|
|
}
|
2020-07-22 14:39:53 +00:00
|
|
|
// Only the first player can choose handheld mode so connect the signal just to player 1
|
|
|
|
connect(player_controllers[0], &ConfigureInputPlayer::HandheldStateChanged,
|
2020-08-15 19:26:29 +00:00
|
|
|
[this](bool is_handheld) { UpdateDockedState(is_handheld); });
|
2020-07-22 14:39:53 +00:00
|
|
|
|
|
|
|
advanced = new ConfigureInputAdvanced(this);
|
|
|
|
ui->tabAdvanced->setLayout(new QHBoxLayout(ui->tabAdvanced));
|
|
|
|
ui->tabAdvanced->layout()->addWidget(advanced);
|
2020-08-27 19:16:47 +00:00
|
|
|
connect(advanced, &ConfigureInputAdvanced::CallDebugControllerDialog, [this, input_subsystem] {
|
|
|
|
CallConfigureDialog<ConfigureDebugController>(*this, input_subsystem);
|
|
|
|
});
|
|
|
|
connect(advanced, &ConfigureInputAdvanced::CallMouseConfigDialog, [this, input_subsystem] {
|
|
|
|
CallConfigureDialog<ConfigureMouseAdvanced>(*this, input_subsystem);
|
|
|
|
});
|
2020-07-22 14:39:53 +00:00
|
|
|
connect(advanced, &ConfigureInputAdvanced::CallTouchscreenConfigDialog,
|
2018-11-27 10:14:59 +00:00
|
|
|
[this] { CallConfigureDialog<ConfigureTouchscreenAdvanced>(*this); });
|
2020-08-29 18:56:51 +00:00
|
|
|
connect(advanced, &ConfigureInputAdvanced::CallMotionTouchConfigDialog,
|
|
|
|
[this, input_subsystem] {
|
|
|
|
CallConfigureDialog<ConfigureMotionTouch>(*this, input_subsystem);
|
|
|
|
});
|
2020-07-22 14:39:53 +00:00
|
|
|
|
|
|
|
connect(ui->buttonClearAll, &QPushButton::clicked, [this] { ClearAll(); });
|
|
|
|
connect(ui->buttonRestoreDefaults, &QPushButton::clicked, [this] { RestoreDefaults(); });
|
|
|
|
|
|
|
|
RetranslateUI();
|
|
|
|
LoadConfiguration();
|
2018-08-26 08:23:12 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 14:39:53 +00:00
|
|
|
QList<QWidget*> ConfigureInput::GetSubTabs() const {
|
|
|
|
return {
|
|
|
|
ui->tabPlayer1, ui->tabPlayer2, ui->tabPlayer3, ui->tabPlayer4, ui->tabPlayer5,
|
|
|
|
ui->tabPlayer6, ui->tabPlayer7, ui->tabPlayer8, ui->tabAdvanced,
|
|
|
|
};
|
|
|
|
}
|
2018-11-04 15:18:59 +00:00
|
|
|
|
2020-07-22 14:39:53 +00:00
|
|
|
void ConfigureInput::ApplyConfiguration() {
|
|
|
|
for (auto controller : player_controllers) {
|
|
|
|
controller->ApplyConfiguration();
|
2018-11-02 02:06:48 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 14:39:53 +00:00
|
|
|
advanced->ApplyConfiguration();
|
|
|
|
|
2018-11-04 15:18:59 +00:00
|
|
|
const bool pre_docked_mode = Settings::values.use_docked_mode;
|
2020-07-22 14:39:53 +00:00
|
|
|
Settings::values.use_docked_mode = ui->radioDocked->isChecked();
|
2018-11-04 15:18:59 +00:00
|
|
|
OnDockedModeChanged(pre_docked_mode, Settings::values.use_docked_mode);
|
2020-07-22 14:39:53 +00:00
|
|
|
|
|
|
|
Settings::values.vibration_enabled = ui->vibrationGroup->isChecked();
|
2017-01-22 19:02:29 +00:00
|
|
|
}
|
2016-07-29 12:45:49 +00:00
|
|
|
|
2019-06-05 22:39:46 +00:00
|
|
|
void ConfigureInput::changeEvent(QEvent* event) {
|
|
|
|
if (event->type() == QEvent::LanguageChange) {
|
|
|
|
RetranslateUI();
|
|
|
|
}
|
|
|
|
|
2020-07-22 14:39:53 +00:00
|
|
|
QWidget::changeEvent(event);
|
2019-06-05 22:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureInput::RetranslateUI() {
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
}
|
|
|
|
|
2020-07-22 14:39:53 +00:00
|
|
|
void ConfigureInput::LoadConfiguration() {
|
2019-06-05 22:39:46 +00:00
|
|
|
LoadPlayerControllerIndices();
|
2020-08-21 11:39:24 +00:00
|
|
|
UpdateDockedState(Settings::values.players[8].connected);
|
2019-06-05 22:39:46 +00:00
|
|
|
|
2020-07-22 14:39:53 +00:00
|
|
|
ui->vibrationGroup->setChecked(Settings::values.vibration_enabled);
|
|
|
|
}
|
2016-07-29 12:45:49 +00:00
|
|
|
|
2020-07-22 14:39:53 +00:00
|
|
|
void ConfigureInput::LoadPlayerControllerIndices() {
|
|
|
|
for (std::size_t i = 0; i < player_connected.size(); ++i) {
|
|
|
|
const auto connected = Settings::values.players[i].connected ||
|
|
|
|
(i == 0 && Settings::values.players[8].connected);
|
|
|
|
player_connected[i]->setChecked(connected);
|
2018-11-04 15:18:59 +00:00
|
|
|
}
|
2020-07-22 14:39:53 +00:00
|
|
|
}
|
2018-11-04 15:18:59 +00:00
|
|
|
|
2020-07-22 14:39:53 +00:00
|
|
|
void ConfigureInput::ClearAll() {
|
|
|
|
// We don't have a good way to know what tab is active, but we can find out by getting the
|
|
|
|
// parent of the consoleInputSettings
|
2020-08-15 19:26:29 +00:00
|
|
|
auto* player_tab = static_cast<ConfigureInputPlayer*>(ui->consoleInputSettings->parent());
|
2020-07-22 14:39:53 +00:00
|
|
|
player_tab->ClearAll();
|
2016-07-29 12:45:49 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 14:39:53 +00:00
|
|
|
void ConfigureInput::RestoreDefaults() {
|
|
|
|
// We don't have a good way to know what tab is active, but we can find out by getting the
|
|
|
|
// parent of the consoleInputSettings
|
2020-08-15 19:26:29 +00:00
|
|
|
auto* player_tab = static_cast<ConfigureInputPlayer*>(ui->consoleInputSettings->parent());
|
2020-07-22 14:39:53 +00:00
|
|
|
player_tab->RestoreDefaults();
|
|
|
|
|
|
|
|
ui->radioDocked->setChecked(true);
|
|
|
|
ui->radioUndocked->setChecked(false);
|
|
|
|
ui->vibrationGroup->setChecked(true);
|
|
|
|
}
|
2018-11-04 15:18:59 +00:00
|
|
|
|
2020-07-22 14:39:53 +00:00
|
|
|
void ConfigureInput::UpdateDockedState(bool is_handheld) {
|
2020-08-21 11:39:24 +00:00
|
|
|
// Disallow changing the console mode if the controller type is handheld.
|
2020-07-22 14:39:53 +00:00
|
|
|
ui->radioDocked->setEnabled(!is_handheld);
|
|
|
|
ui->radioUndocked->setEnabled(!is_handheld);
|
2016-12-09 23:59:09 +00:00
|
|
|
|
2020-07-22 14:39:53 +00:00
|
|
|
ui->radioDocked->setChecked(Settings::values.use_docked_mode);
|
|
|
|
ui->radioUndocked->setChecked(!Settings::values.use_docked_mode);
|
2017-12-06 04:26:29 +00:00
|
|
|
|
2020-08-21 11:39:24 +00:00
|
|
|
// Also force into undocked mode if the controller type is handheld.
|
2020-07-22 14:39:53 +00:00
|
|
|
if (is_handheld) {
|
|
|
|
ui->radioUndocked->setChecked(true);
|
2019-06-05 22:39:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-22 14:39:53 +00:00
|
|
|
void ConfigureInput::UpdateAllInputDevices() {
|
|
|
|
for (const auto& player : player_controllers) {
|
|
|
|
player->UpdateInputDevices();
|
2017-12-06 04:26:29 +00:00
|
|
|
}
|
2016-07-29 12:45:49 +00:00
|
|
|
}
|