2020-08-21 13:39:24 +02:00
|
|
|
// Copyright 2020 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <algorithm>
|
2020-10-27 18:33:25 +01:00
|
|
|
#include <thread>
|
2020-08-21 13:39:24 +02:00
|
|
|
|
2020-08-28 18:45:15 +02:00
|
|
|
#include "common/assert.h"
|
2020-08-27 07:21:48 +02:00
|
|
|
#include "common/string_util.h"
|
2020-08-21 13:39:24 +02:00
|
|
|
#include "core/core.h"
|
2021-10-21 00:53:14 +02:00
|
|
|
#include "core/hid/emulated_controller.h"
|
2021-11-01 21:17:53 +01:00
|
|
|
#include "core/hid/hid_core.h"
|
2021-10-21 00:53:14 +02:00
|
|
|
#include "core/hid/hid_types.h"
|
2020-08-21 13:39:24 +02:00
|
|
|
#include "core/hle/service/hid/controllers/npad.h"
|
|
|
|
#include "core/hle/service/hid/hid.h"
|
|
|
|
#include "core/hle/service/sm/sm.h"
|
2021-07-14 06:29:12 +02:00
|
|
|
#include "ui_qt_controller.h"
|
|
|
|
#include "yuzu/applets/qt_controller.h"
|
2020-10-26 08:28:03 +01:00
|
|
|
#include "yuzu/configuration/configure_input.h"
|
|
|
|
#include "yuzu/configuration/configure_input_profile_dialog.h"
|
2021-04-13 16:05:07 +02:00
|
|
|
#include "yuzu/configuration/configure_motion_touch.h"
|
2020-10-17 15:38:12 +02:00
|
|
|
#include "yuzu/configuration/configure_vibration.h"
|
2020-10-26 08:28:03 +01:00
|
|
|
#include "yuzu/configuration/input_profiles.h"
|
2020-08-21 13:39:24 +02:00
|
|
|
#include "yuzu/main.h"
|
|
|
|
|
2020-08-28 18:45:15 +02:00
|
|
|
namespace {
|
|
|
|
|
2021-10-24 08:02:56 +02:00
|
|
|
void UpdateController(Core::HID::EmulatedController* controller,
|
2021-11-04 19:08:54 +01:00
|
|
|
Core::HID::NpadStyleIndex controller_type, bool connected) {
|
2021-11-27 01:55:28 +01:00
|
|
|
if (controller->IsConnected(true)) {
|
2021-10-21 00:53:14 +02:00
|
|
|
controller->Disconnect();
|
|
|
|
}
|
2021-11-04 19:08:54 +01:00
|
|
|
controller->SetNpadStyleIndex(controller_type);
|
2021-10-21 00:53:14 +02:00
|
|
|
if (connected) {
|
2021-12-30 05:15:08 +01:00
|
|
|
controller->Connect(true);
|
2020-08-21 13:39:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-27 07:21:48 +02:00
|
|
|
// Returns true if the given controller type is compatible with the given parameters.
|
2021-11-04 19:08:54 +01:00
|
|
|
bool IsControllerCompatible(Core::HID::NpadStyleIndex controller_type,
|
2020-08-21 13:39:24 +02:00
|
|
|
Core::Frontend::ControllerParameters parameters) {
|
|
|
|
switch (controller_type) {
|
2021-11-04 19:08:54 +01:00
|
|
|
case Core::HID::NpadStyleIndex::ProController:
|
2020-08-21 13:39:24 +02:00
|
|
|
return parameters.allow_pro_controller;
|
2021-11-04 19:08:54 +01:00
|
|
|
case Core::HID::NpadStyleIndex::JoyconDual:
|
2020-08-21 13:39:24 +02:00
|
|
|
return parameters.allow_dual_joycons;
|
2021-11-04 19:08:54 +01:00
|
|
|
case Core::HID::NpadStyleIndex::JoyconLeft:
|
2020-08-21 13:39:24 +02:00
|
|
|
return parameters.allow_left_joycon;
|
2021-11-04 19:08:54 +01:00
|
|
|
case Core::HID::NpadStyleIndex::JoyconRight:
|
2020-08-21 13:39:24 +02:00
|
|
|
return parameters.allow_right_joycon;
|
2021-11-04 19:08:54 +01:00
|
|
|
case Core::HID::NpadStyleIndex::Handheld:
|
2020-08-21 13:39:24 +02:00
|
|
|
return parameters.enable_single_mode && parameters.allow_handheld;
|
2021-11-04 19:08:54 +01:00
|
|
|
case Core::HID::NpadStyleIndex::GameCube:
|
2021-02-06 18:53:25 +01:00
|
|
|
return parameters.allow_gamecube_controller;
|
2020-08-21 13:39:24 +02:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
QtControllerSelectorDialog::QtControllerSelectorDialog(
|
2020-08-28 17:44:36 +02:00
|
|
|
QWidget* parent, Core::Frontend::ControllerParameters parameters_,
|
2021-09-03 03:40:55 +02:00
|
|
|
InputCommon::InputSubsystem* input_subsystem_, Core::System& system_)
|
2020-08-21 13:39:24 +02:00
|
|
|
: QDialog(parent), ui(std::make_unique<Ui::QtControllerSelectorDialog>()),
|
2020-10-26 08:28:03 +01:00
|
|
|
parameters(std::move(parameters_)), input_subsystem{input_subsystem_},
|
2021-09-03 03:40:55 +02:00
|
|
|
input_profiles(std::make_unique<InputProfiles>(system_)), system{system_} {
|
2020-08-21 13:39:24 +02:00
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
player_widgets = {
|
|
|
|
ui->widgetPlayer1, ui->widgetPlayer2, ui->widgetPlayer3, ui->widgetPlayer4,
|
|
|
|
ui->widgetPlayer5, ui->widgetPlayer6, ui->widgetPlayer7, ui->widgetPlayer8,
|
|
|
|
};
|
|
|
|
|
|
|
|
player_groupboxes = {
|
|
|
|
ui->groupPlayer1Connected, ui->groupPlayer2Connected, ui->groupPlayer3Connected,
|
|
|
|
ui->groupPlayer4Connected, ui->groupPlayer5Connected, ui->groupPlayer6Connected,
|
|
|
|
ui->groupPlayer7Connected, ui->groupPlayer8Connected,
|
|
|
|
};
|
|
|
|
|
|
|
|
connected_controller_icons = {
|
|
|
|
ui->controllerPlayer1, ui->controllerPlayer2, ui->controllerPlayer3, ui->controllerPlayer4,
|
|
|
|
ui->controllerPlayer5, ui->controllerPlayer6, ui->controllerPlayer7, ui->controllerPlayer8,
|
|
|
|
};
|
|
|
|
|
|
|
|
led_patterns_boxes = {{
|
|
|
|
{ui->checkboxPlayer1LED1, ui->checkboxPlayer1LED2, ui->checkboxPlayer1LED3,
|
|
|
|
ui->checkboxPlayer1LED4},
|
|
|
|
{ui->checkboxPlayer2LED1, ui->checkboxPlayer2LED2, ui->checkboxPlayer2LED3,
|
|
|
|
ui->checkboxPlayer2LED4},
|
|
|
|
{ui->checkboxPlayer3LED1, ui->checkboxPlayer3LED2, ui->checkboxPlayer3LED3,
|
|
|
|
ui->checkboxPlayer3LED4},
|
|
|
|
{ui->checkboxPlayer4LED1, ui->checkboxPlayer4LED2, ui->checkboxPlayer4LED3,
|
|
|
|
ui->checkboxPlayer4LED4},
|
|
|
|
{ui->checkboxPlayer5LED1, ui->checkboxPlayer5LED2, ui->checkboxPlayer5LED3,
|
|
|
|
ui->checkboxPlayer5LED4},
|
|
|
|
{ui->checkboxPlayer6LED1, ui->checkboxPlayer6LED2, ui->checkboxPlayer6LED3,
|
|
|
|
ui->checkboxPlayer6LED4},
|
|
|
|
{ui->checkboxPlayer7LED1, ui->checkboxPlayer7LED2, ui->checkboxPlayer7LED3,
|
|
|
|
ui->checkboxPlayer7LED4},
|
|
|
|
{ui->checkboxPlayer8LED1, ui->checkboxPlayer8LED2, ui->checkboxPlayer8LED3,
|
|
|
|
ui->checkboxPlayer8LED4},
|
|
|
|
}};
|
|
|
|
|
2020-08-27 07:21:48 +02:00
|
|
|
explain_text_labels = {
|
|
|
|
ui->labelPlayer1Explain, ui->labelPlayer2Explain, ui->labelPlayer3Explain,
|
|
|
|
ui->labelPlayer4Explain, ui->labelPlayer5Explain, ui->labelPlayer6Explain,
|
|
|
|
ui->labelPlayer7Explain, ui->labelPlayer8Explain,
|
|
|
|
};
|
|
|
|
|
2020-08-21 13:39:24 +02:00
|
|
|
emulated_controllers = {
|
|
|
|
ui->comboPlayer1Emulated, ui->comboPlayer2Emulated, ui->comboPlayer3Emulated,
|
|
|
|
ui->comboPlayer4Emulated, ui->comboPlayer5Emulated, ui->comboPlayer6Emulated,
|
|
|
|
ui->comboPlayer7Emulated, ui->comboPlayer8Emulated,
|
|
|
|
};
|
|
|
|
|
|
|
|
player_labels = {
|
|
|
|
ui->labelPlayer1, ui->labelPlayer2, ui->labelPlayer3, ui->labelPlayer4,
|
|
|
|
ui->labelPlayer5, ui->labelPlayer6, ui->labelPlayer7, ui->labelPlayer8,
|
|
|
|
};
|
|
|
|
|
|
|
|
connected_controller_labels = {
|
|
|
|
ui->labelConnectedPlayer1, ui->labelConnectedPlayer2, ui->labelConnectedPlayer3,
|
|
|
|
ui->labelConnectedPlayer4, ui->labelConnectedPlayer5, ui->labelConnectedPlayer6,
|
|
|
|
ui->labelConnectedPlayer7, ui->labelConnectedPlayer8,
|
|
|
|
};
|
|
|
|
|
|
|
|
connected_controller_checkboxes = {
|
|
|
|
ui->checkboxPlayer1Connected, ui->checkboxPlayer2Connected, ui->checkboxPlayer3Connected,
|
|
|
|
ui->checkboxPlayer4Connected, ui->checkboxPlayer5Connected, ui->checkboxPlayer6Connected,
|
|
|
|
ui->checkboxPlayer7Connected, ui->checkboxPlayer8Connected,
|
|
|
|
};
|
|
|
|
|
2020-08-27 09:52:26 +02:00
|
|
|
// Setup/load everything prior to setting up connections.
|
|
|
|
// This avoids unintentionally changing the states of elements while loading them in.
|
|
|
|
SetSupportedControllers();
|
|
|
|
DisableUnsupportedPlayers();
|
2020-11-20 17:04:27 +01:00
|
|
|
|
|
|
|
for (std::size_t player_index = 0; player_index < NUM_PLAYERS; ++player_index) {
|
|
|
|
SetEmulatedControllers(player_index);
|
|
|
|
}
|
|
|
|
|
2020-08-27 09:52:26 +02:00
|
|
|
LoadConfiguration();
|
|
|
|
|
2020-08-27 07:46:14 +02:00
|
|
|
for (std::size_t i = 0; i < NUM_PLAYERS; ++i) {
|
2020-08-27 09:52:26 +02:00
|
|
|
SetExplainText(i);
|
|
|
|
UpdateControllerIcon(i);
|
|
|
|
UpdateLEDPattern(i);
|
|
|
|
UpdateBorderColor(i);
|
|
|
|
|
2020-08-21 13:39:24 +02:00
|
|
|
connect(player_groupboxes[i], &QGroupBox::toggled, [this, i](bool checked) {
|
|
|
|
if (checked) {
|
|
|
|
for (std::size_t index = 0; index <= i; ++index) {
|
|
|
|
connected_controller_checkboxes[index]->setChecked(checked);
|
|
|
|
}
|
|
|
|
} else {
|
2020-08-27 07:46:14 +02:00
|
|
|
for (std::size_t index = i; index < NUM_PLAYERS; ++index) {
|
2020-08-21 13:39:24 +02:00
|
|
|
connected_controller_checkboxes[index]->setChecked(checked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(emulated_controllers[i], qOverload<int>(&QComboBox::currentIndexChanged),
|
|
|
|
[this, i](int) {
|
|
|
|
UpdateControllerIcon(i);
|
|
|
|
UpdateControllerState(i);
|
|
|
|
UpdateLEDPattern(i);
|
|
|
|
CheckIfParametersMet();
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(connected_controller_checkboxes[i], &QCheckBox::stateChanged, [this, i](int state) {
|
|
|
|
player_groupboxes[i]->setChecked(state == Qt::Checked);
|
|
|
|
UpdateControllerIcon(i);
|
|
|
|
UpdateControllerState(i);
|
|
|
|
UpdateLEDPattern(i);
|
|
|
|
UpdateBorderColor(i);
|
|
|
|
CheckIfParametersMet();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
connect(emulated_controllers[i], qOverload<int>(&QComboBox::currentIndexChanged),
|
2020-11-20 17:04:27 +01:00
|
|
|
[this, i](int index) {
|
|
|
|
UpdateDockedState(GetControllerTypeFromIndex(index, i) ==
|
2021-11-04 19:08:54 +01:00
|
|
|
Core::HID::NpadStyleIndex::Handheld);
|
2020-08-21 13:39:24 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 15:38:12 +02:00
|
|
|
connect(ui->vibrationButton, &QPushButton::clicked, this,
|
|
|
|
&QtControllerSelectorDialog::CallConfigureVibrationDialog);
|
|
|
|
|
2021-04-13 16:05:07 +02:00
|
|
|
connect(ui->motionButton, &QPushButton::clicked, this,
|
|
|
|
&QtControllerSelectorDialog::CallConfigureMotionTouchDialog);
|
|
|
|
|
2020-08-21 13:39:24 +02:00
|
|
|
connect(ui->inputConfigButton, &QPushButton::clicked, this,
|
2020-10-26 08:28:03 +01:00
|
|
|
&QtControllerSelectorDialog::CallConfigureInputProfileDialog);
|
2020-08-21 13:39:24 +02:00
|
|
|
|
|
|
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, this,
|
|
|
|
&QtControllerSelectorDialog::ApplyConfiguration);
|
|
|
|
|
2020-09-27 17:18:07 +02:00
|
|
|
// Enhancement: Check if the parameters have already been met before disconnecting controllers.
|
|
|
|
// If all the parameters are met AND only allows a single player,
|
|
|
|
// stop the constructor here as we do not need to continue.
|
|
|
|
if (CheckIfParametersMet() && parameters.enable_single_mode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-21 13:39:24 +02:00
|
|
|
// If keep_controllers_connected is false, forcefully disconnect all controllers
|
|
|
|
if (!parameters.keep_controllers_connected) {
|
|
|
|
for (auto player : player_groupboxes) {
|
|
|
|
player->setChecked(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resize(0, 0);
|
|
|
|
}
|
|
|
|
|
2021-11-30 00:01:05 +01:00
|
|
|
QtControllerSelectorDialog::~QtControllerSelectorDialog() {
|
|
|
|
system.HIDCore().DisableAllControllerConfiguration();
|
|
|
|
}
|
2020-08-21 13:39:24 +02:00
|
|
|
|
2020-09-27 17:18:07 +02:00
|
|
|
int QtControllerSelectorDialog::exec() {
|
|
|
|
if (parameters_met && parameters.enable_single_mode) {
|
|
|
|
return QDialog::Accepted;
|
|
|
|
}
|
|
|
|
return QDialog::exec();
|
|
|
|
}
|
|
|
|
|
2020-08-21 13:39:24 +02:00
|
|
|
void QtControllerSelectorDialog::ApplyConfiguration() {
|
2020-09-28 16:00:15 +02:00
|
|
|
const bool pre_docked_mode = Settings::values.use_docked_mode.GetValue();
|
|
|
|
Settings::values.use_docked_mode.SetValue(ui->radioDocked->isChecked());
|
2021-09-03 03:40:55 +02:00
|
|
|
OnDockedModeChanged(pre_docked_mode, Settings::values.use_docked_mode.GetValue(), system);
|
2020-08-21 13:39:24 +02:00
|
|
|
|
2020-09-28 16:00:15 +02:00
|
|
|
Settings::values.vibration_enabled.SetValue(ui->vibrationGroup->isChecked());
|
2020-10-09 05:43:07 +02:00
|
|
|
Settings::values.motion_enabled.SetValue(ui->motionGroup->isChecked());
|
2020-08-21 13:39:24 +02:00
|
|
|
}
|
|
|
|
|
2020-08-27 09:52:26 +02:00
|
|
|
void QtControllerSelectorDialog::LoadConfiguration() {
|
2021-11-30 00:01:05 +01:00
|
|
|
system.HIDCore().EnableAllControllerConfiguration();
|
|
|
|
|
2021-10-21 00:53:14 +02:00
|
|
|
const auto* handheld = system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
|
2020-08-27 09:52:26 +02:00
|
|
|
for (std::size_t index = 0; index < NUM_PLAYERS; ++index) {
|
2021-10-21 00:53:14 +02:00
|
|
|
const auto* controller = system.HIDCore().GetEmulatedControllerByIndex(index);
|
2021-11-27 01:55:28 +01:00
|
|
|
const auto connected =
|
|
|
|
controller->IsConnected(true) || (index == 0 && handheld->IsConnected(true));
|
2020-08-27 09:52:26 +02:00
|
|
|
player_groupboxes[index]->setChecked(connected);
|
|
|
|
connected_controller_checkboxes[index]->setChecked(connected);
|
2021-10-21 00:53:14 +02:00
|
|
|
emulated_controllers[index]->setCurrentIndex(
|
2021-11-27 01:55:28 +01:00
|
|
|
GetIndexFromControllerType(controller->GetNpadStyleIndex(true), index));
|
2020-08-27 09:52:26 +02:00
|
|
|
}
|
|
|
|
|
2021-11-27 01:55:28 +01:00
|
|
|
UpdateDockedState(handheld->IsConnected(true));
|
2020-08-27 09:52:26 +02:00
|
|
|
|
2020-09-28 16:00:15 +02:00
|
|
|
ui->vibrationGroup->setChecked(Settings::values.vibration_enabled.GetValue());
|
2020-10-09 05:43:07 +02:00
|
|
|
ui->motionGroup->setChecked(Settings::values.motion_enabled.GetValue());
|
2020-08-27 09:52:26 +02:00
|
|
|
}
|
|
|
|
|
2020-10-17 15:38:12 +02:00
|
|
|
void QtControllerSelectorDialog::CallConfigureVibrationDialog() {
|
2022-02-02 21:53:15 +01:00
|
|
|
ConfigureVibration dialog(this, system.HIDCore());
|
2020-10-17 15:38:12 +02:00
|
|
|
|
|
|
|
dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint |
|
|
|
|
Qt::WindowSystemMenuHint);
|
|
|
|
dialog.setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
|
|
|
dialog.ApplyConfiguration();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-13 16:05:07 +02:00
|
|
|
void QtControllerSelectorDialog::CallConfigureMotionTouchDialog() {
|
|
|
|
ConfigureMotionTouch dialog(this, input_subsystem);
|
|
|
|
|
|
|
|
dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint |
|
|
|
|
Qt::WindowSystemMenuHint);
|
|
|
|
dialog.setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
|
|
|
dialog.ApplyConfiguration();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-26 08:28:03 +01:00
|
|
|
void QtControllerSelectorDialog::CallConfigureInputProfileDialog() {
|
2021-09-03 03:40:55 +02:00
|
|
|
ConfigureInputProfileDialog dialog(this, input_subsystem, input_profiles.get(), system);
|
2020-08-21 13:39:24 +02:00
|
|
|
|
|
|
|
dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint |
|
|
|
|
Qt::WindowSystemMenuHint);
|
|
|
|
dialog.setWindowModality(Qt::WindowModal);
|
|
|
|
dialog.exec();
|
|
|
|
}
|
|
|
|
|
2020-09-27 17:18:07 +02:00
|
|
|
bool QtControllerSelectorDialog::CheckIfParametersMet() {
|
2020-08-21 13:39:24 +02:00
|
|
|
// Here, we check and validate the current configuration against all applicable parameters.
|
2020-08-28 19:14:19 +02:00
|
|
|
const auto num_connected_players = static_cast<int>(
|
2020-08-21 13:39:24 +02:00
|
|
|
std::count_if(player_groupboxes.begin(), player_groupboxes.end(),
|
2020-08-28 19:14:19 +02:00
|
|
|
[this](const QGroupBox* player) { return player->isChecked(); }));
|
2020-08-21 13:39:24 +02:00
|
|
|
|
|
|
|
const auto min_supported_players = parameters.enable_single_mode ? 1 : parameters.min_players;
|
|
|
|
const auto max_supported_players = parameters.enable_single_mode ? 1 : parameters.max_players;
|
|
|
|
|
|
|
|
// First, check against the number of connected players.
|
|
|
|
if (num_connected_players < min_supported_players ||
|
|
|
|
num_connected_players > max_supported_players) {
|
|
|
|
parameters_met = false;
|
|
|
|
ui->buttonBox->setEnabled(parameters_met);
|
2020-09-27 17:18:07 +02:00
|
|
|
return parameters_met;
|
2020-08-21 13:39:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Next, check against all connected controllers.
|
|
|
|
const auto all_controllers_compatible = [this] {
|
2020-08-27 07:46:14 +02:00
|
|
|
for (std::size_t index = 0; index < NUM_PLAYERS; ++index) {
|
2020-08-21 13:39:24 +02:00
|
|
|
// Skip controllers that are not used, we only care about the currently connected ones.
|
|
|
|
if (!player_groupboxes[index]->isChecked() || !player_groupboxes[index]->isEnabled()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto compatible = IsControllerCompatible(
|
2020-11-20 17:04:27 +01:00
|
|
|
GetControllerTypeFromIndex(emulated_controllers[index]->currentIndex(), index),
|
2020-08-21 13:39:24 +02:00
|
|
|
parameters);
|
|
|
|
|
|
|
|
// If any controller is found to be incompatible, return false early.
|
|
|
|
if (!compatible) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reaching here means all currently connected controllers are compatible.
|
|
|
|
return true;
|
|
|
|
}();
|
|
|
|
|
2020-09-27 17:18:07 +02:00
|
|
|
parameters_met = all_controllers_compatible;
|
2020-08-21 13:39:24 +02:00
|
|
|
ui->buttonBox->setEnabled(parameters_met);
|
2020-09-27 17:18:07 +02:00
|
|
|
return parameters_met;
|
2020-08-21 13:39:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QtControllerSelectorDialog::SetSupportedControllers() {
|
2020-10-27 18:33:25 +01:00
|
|
|
const QString theme = [] {
|
2020-08-21 13:39:24 +02:00
|
|
|
if (QIcon::themeName().contains(QStringLiteral("dark"))) {
|
|
|
|
return QStringLiteral("_dark");
|
|
|
|
} else if (QIcon::themeName().contains(QStringLiteral("midnight"))) {
|
|
|
|
return QStringLiteral("_midnight");
|
|
|
|
} else {
|
|
|
|
return QString{};
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
|
|
|
if (parameters.enable_single_mode && parameters.allow_handheld) {
|
|
|
|
ui->controllerSupported1->setStyleSheet(
|
|
|
|
QStringLiteral("image: url(:/controller/applet_handheld%0); ").arg(theme));
|
|
|
|
} else {
|
|
|
|
ui->controllerSupported1->setStyleSheet(
|
|
|
|
QStringLiteral("image: url(:/controller/applet_handheld%0_disabled); ").arg(theme));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parameters.allow_dual_joycons) {
|
|
|
|
ui->controllerSupported2->setStyleSheet(
|
|
|
|
QStringLiteral("image: url(:/controller/applet_dual_joycon%0); ").arg(theme));
|
|
|
|
} else {
|
|
|
|
ui->controllerSupported2->setStyleSheet(
|
|
|
|
QStringLiteral("image: url(:/controller/applet_dual_joycon%0_disabled); ").arg(theme));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parameters.allow_left_joycon) {
|
|
|
|
ui->controllerSupported3->setStyleSheet(
|
|
|
|
QStringLiteral("image: url(:/controller/applet_joycon_left%0); ").arg(theme));
|
|
|
|
} else {
|
|
|
|
ui->controllerSupported3->setStyleSheet(
|
|
|
|
QStringLiteral("image: url(:/controller/applet_joycon_left%0_disabled); ").arg(theme));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parameters.allow_right_joycon) {
|
|
|
|
ui->controllerSupported4->setStyleSheet(
|
|
|
|
QStringLiteral("image: url(:/controller/applet_joycon_right%0); ").arg(theme));
|
|
|
|
} else {
|
|
|
|
ui->controllerSupported4->setStyleSheet(
|
|
|
|
QStringLiteral("image: url(:/controller/applet_joycon_right%0_disabled); ").arg(theme));
|
|
|
|
}
|
|
|
|
|
2021-02-06 18:53:25 +01:00
|
|
|
if (parameters.allow_pro_controller || parameters.allow_gamecube_controller) {
|
2020-08-21 13:39:24 +02:00
|
|
|
ui->controllerSupported5->setStyleSheet(
|
|
|
|
QStringLiteral("image: url(:/controller/applet_pro_controller%0); ").arg(theme));
|
|
|
|
} else {
|
|
|
|
ui->controllerSupported5->setStyleSheet(
|
|
|
|
QStringLiteral("image: url(:/controller/applet_pro_controller%0_disabled); ")
|
|
|
|
.arg(theme));
|
|
|
|
}
|
|
|
|
|
|
|
|
// enable_single_mode overrides min_players and max_players.
|
|
|
|
if (parameters.enable_single_mode) {
|
|
|
|
ui->numberSupportedLabel->setText(QStringLiteral("1"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parameters.min_players == parameters.max_players) {
|
|
|
|
ui->numberSupportedLabel->setText(QStringLiteral("%1").arg(parameters.max_players));
|
|
|
|
} else {
|
|
|
|
ui->numberSupportedLabel->setText(
|
|
|
|
QStringLiteral("%1 - %2").arg(parameters.min_players).arg(parameters.max_players));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 17:04:27 +01:00
|
|
|
void QtControllerSelectorDialog::SetEmulatedControllers(std::size_t player_index) {
|
2022-01-02 03:44:28 +01:00
|
|
|
const auto npad_style_set = system.HIDCore().GetSupportedStyleTag();
|
2020-11-20 17:04:27 +01:00
|
|
|
auto& pairs = index_controller_type_pairs[player_index];
|
|
|
|
|
|
|
|
pairs.clear();
|
|
|
|
emulated_controllers[player_index]->clear();
|
|
|
|
|
2022-01-02 03:44:28 +01:00
|
|
|
const auto add_item = [&](Core::HID::NpadStyleIndex controller_type,
|
|
|
|
const QString& controller_name) {
|
|
|
|
pairs.emplace_back(emulated_controllers[player_index]->count(), controller_type);
|
|
|
|
emulated_controllers[player_index]->addItem(controller_name);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (npad_style_set.fullkey == 1) {
|
|
|
|
add_item(Core::HID::NpadStyleIndex::ProController, tr("Pro Controller"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (npad_style_set.joycon_dual == 1) {
|
|
|
|
add_item(Core::HID::NpadStyleIndex::JoyconDual, tr("Dual Joycons"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (npad_style_set.joycon_left == 1) {
|
|
|
|
add_item(Core::HID::NpadStyleIndex::JoyconLeft, tr("Left Joycon"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (npad_style_set.joycon_right == 1) {
|
|
|
|
add_item(Core::HID::NpadStyleIndex::JoyconRight, tr("Right Joycon"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (player_index == 0 && npad_style_set.handheld == 1) {
|
|
|
|
add_item(Core::HID::NpadStyleIndex::Handheld, tr("Handheld"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (npad_style_set.gamecube == 1) {
|
|
|
|
add_item(Core::HID::NpadStyleIndex::GameCube, tr("GameCube Controller"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable all unsupported controllers
|
|
|
|
if (!Settings::values.enable_all_controllers) {
|
|
|
|
return;
|
|
|
|
}
|
2020-11-20 17:04:27 +01:00
|
|
|
|
2022-01-02 03:44:28 +01:00
|
|
|
if (npad_style_set.palma == 1) {
|
|
|
|
add_item(Core::HID::NpadStyleIndex::Pokeball, tr("Poke Ball Plus"));
|
|
|
|
}
|
2020-11-20 17:04:27 +01:00
|
|
|
|
2022-01-02 03:44:28 +01:00
|
|
|
if (npad_style_set.lark == 1) {
|
|
|
|
add_item(Core::HID::NpadStyleIndex::NES, tr("NES Controller"));
|
|
|
|
}
|
2020-11-20 17:04:27 +01:00
|
|
|
|
2022-01-02 03:44:28 +01:00
|
|
|
if (npad_style_set.lucia == 1) {
|
|
|
|
add_item(Core::HID::NpadStyleIndex::SNES, tr("SNES Controller"));
|
|
|
|
}
|
2020-11-20 17:04:27 +01:00
|
|
|
|
2022-01-02 03:44:28 +01:00
|
|
|
if (npad_style_set.lagoon == 1) {
|
|
|
|
add_item(Core::HID::NpadStyleIndex::N64, tr("N64 Controller"));
|
2020-11-20 17:04:27 +01:00
|
|
|
}
|
2021-02-06 18:53:25 +01:00
|
|
|
|
2022-01-02 03:44:28 +01:00
|
|
|
if (npad_style_set.lager == 1) {
|
|
|
|
add_item(Core::HID::NpadStyleIndex::SegaGenesis, tr("Sega Genesis"));
|
|
|
|
}
|
2020-11-20 17:04:27 +01:00
|
|
|
}
|
|
|
|
|
2021-11-04 19:08:54 +01:00
|
|
|
Core::HID::NpadStyleIndex QtControllerSelectorDialog::GetControllerTypeFromIndex(
|
2020-11-20 17:04:27 +01:00
|
|
|
int index, std::size_t player_index) const {
|
|
|
|
const auto& pairs = index_controller_type_pairs[player_index];
|
|
|
|
|
|
|
|
const auto it = std::find_if(pairs.begin(), pairs.end(),
|
|
|
|
[index](const auto& pair) { return pair.first == index; });
|
|
|
|
|
|
|
|
if (it == pairs.end()) {
|
2021-11-04 19:08:54 +01:00
|
|
|
return Core::HID::NpadStyleIndex::ProController;
|
2020-11-20 17:04:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2021-11-04 19:08:54 +01:00
|
|
|
int QtControllerSelectorDialog::GetIndexFromControllerType(Core::HID::NpadStyleIndex type,
|
2020-11-20 17:04:27 +01:00
|
|
|
std::size_t player_index) const {
|
|
|
|
const auto& pairs = index_controller_type_pairs[player_index];
|
|
|
|
|
|
|
|
const auto it = std::find_if(pairs.begin(), pairs.end(),
|
|
|
|
[type](const auto& pair) { return pair.second == type; });
|
|
|
|
|
|
|
|
if (it == pairs.end()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return it->first;
|
|
|
|
}
|
|
|
|
|
2020-08-21 13:39:24 +02:00
|
|
|
void QtControllerSelectorDialog::UpdateControllerIcon(std::size_t player_index) {
|
|
|
|
if (!player_groupboxes[player_index]->isChecked()) {
|
|
|
|
connected_controller_icons[player_index]->setStyleSheet(QString{});
|
|
|
|
player_labels[player_index]->show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString stylesheet = [this, player_index] {
|
2020-11-20 17:04:27 +01:00
|
|
|
switch (GetControllerTypeFromIndex(emulated_controllers[player_index]->currentIndex(),
|
|
|
|
player_index)) {
|
2021-11-04 19:08:54 +01:00
|
|
|
case Core::HID::NpadStyleIndex::ProController:
|
|
|
|
case Core::HID::NpadStyleIndex::GameCube:
|
2020-08-21 13:39:24 +02:00
|
|
|
return QStringLiteral("image: url(:/controller/applet_pro_controller%0); ");
|
2021-11-04 19:08:54 +01:00
|
|
|
case Core::HID::NpadStyleIndex::JoyconDual:
|
2020-08-21 13:39:24 +02:00
|
|
|
return QStringLiteral("image: url(:/controller/applet_dual_joycon%0); ");
|
2021-11-04 19:08:54 +01:00
|
|
|
case Core::HID::NpadStyleIndex::JoyconLeft:
|
2020-08-21 13:39:24 +02:00
|
|
|
return QStringLiteral("image: url(:/controller/applet_joycon_left%0); ");
|
2021-11-04 19:08:54 +01:00
|
|
|
case Core::HID::NpadStyleIndex::JoyconRight:
|
2020-08-21 13:39:24 +02:00
|
|
|
return QStringLiteral("image: url(:/controller/applet_joycon_right%0); ");
|
2021-11-04 19:08:54 +01:00
|
|
|
case Core::HID::NpadStyleIndex::Handheld:
|
2020-08-21 13:39:24 +02:00
|
|
|
return QStringLiteral("image: url(:/controller/applet_handheld%0); ");
|
|
|
|
default:
|
|
|
|
return QString{};
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
2020-11-20 17:04:27 +01:00
|
|
|
if (stylesheet.isEmpty()) {
|
|
|
|
connected_controller_icons[player_index]->setStyleSheet(QString{});
|
|
|
|
player_labels[player_index]->show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-27 18:33:25 +01:00
|
|
|
const QString theme = [] {
|
2020-08-21 13:39:24 +02:00
|
|
|
if (QIcon::themeName().contains(QStringLiteral("dark"))) {
|
|
|
|
return QStringLiteral("_dark");
|
|
|
|
} else if (QIcon::themeName().contains(QStringLiteral("midnight"))) {
|
|
|
|
return QStringLiteral("_midnight");
|
|
|
|
} else {
|
|
|
|
return QString{};
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
|
|
|
connected_controller_icons[player_index]->setStyleSheet(stylesheet.arg(theme));
|
|
|
|
player_labels[player_index]->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtControllerSelectorDialog::UpdateControllerState(std::size_t player_index) {
|
2021-10-21 00:53:14 +02:00
|
|
|
auto* controller = system.HIDCore().GetEmulatedControllerByIndex(player_index);
|
2020-08-21 13:39:24 +02:00
|
|
|
|
2020-11-20 17:04:27 +01:00
|
|
|
const auto controller_type = GetControllerTypeFromIndex(
|
|
|
|
emulated_controllers[player_index]->currentIndex(), player_index);
|
2020-10-23 18:09:28 +02:00
|
|
|
const auto player_connected = player_groupboxes[player_index]->isChecked() &&
|
2021-11-04 19:08:54 +01:00
|
|
|
controller_type != Core::HID::NpadStyleIndex::Handheld;
|
2020-08-21 13:39:24 +02:00
|
|
|
|
2021-11-27 01:55:28 +01:00
|
|
|
if (controller->GetNpadStyleIndex(true) == controller_type &&
|
|
|
|
controller->IsConnected(true) == player_connected) {
|
2020-08-21 13:39:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-23 18:09:28 +02:00
|
|
|
// Disconnect the controller first.
|
2021-10-21 00:53:14 +02:00
|
|
|
UpdateController(controller, controller_type, false);
|
2020-10-23 18:09:28 +02:00
|
|
|
|
|
|
|
// Handheld
|
|
|
|
if (player_index == 0) {
|
2021-11-04 19:08:54 +01:00
|
|
|
if (controller_type == Core::HID::NpadStyleIndex::Handheld) {
|
2021-10-21 00:53:14 +02:00
|
|
|
auto* handheld =
|
|
|
|
system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
|
2021-11-04 19:08:54 +01:00
|
|
|
UpdateController(handheld, Core::HID::NpadStyleIndex::Handheld,
|
2021-10-21 00:53:14 +02:00
|
|
|
player_groupboxes[player_index]->isChecked());
|
2020-10-23 18:09:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-21 00:53:14 +02:00
|
|
|
UpdateController(controller, controller_type, player_connected);
|
2020-08-21 13:39:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QtControllerSelectorDialog::UpdateLEDPattern(std::size_t player_index) {
|
|
|
|
if (!player_groupboxes[player_index]->isChecked() ||
|
2020-11-20 17:04:27 +01:00
|
|
|
GetControllerTypeFromIndex(emulated_controllers[player_index]->currentIndex(),
|
2021-11-04 19:08:54 +01:00
|
|
|
player_index) == Core::HID::NpadStyleIndex::Handheld) {
|
2020-08-21 13:39:24 +02:00
|
|
|
led_patterns_boxes[player_index][0]->setChecked(false);
|
|
|
|
led_patterns_boxes[player_index][1]->setChecked(false);
|
|
|
|
led_patterns_boxes[player_index][2]->setChecked(false);
|
|
|
|
led_patterns_boxes[player_index][3]->setChecked(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-21 00:53:14 +02:00
|
|
|
const auto* controller = system.HIDCore().GetEmulatedControllerByIndex(player_index);
|
|
|
|
const auto led_pattern = controller->GetLedPattern();
|
|
|
|
led_patterns_boxes[player_index][0]->setChecked(led_pattern.position1);
|
|
|
|
led_patterns_boxes[player_index][1]->setChecked(led_pattern.position2);
|
|
|
|
led_patterns_boxes[player_index][2]->setChecked(led_pattern.position3);
|
|
|
|
led_patterns_boxes[player_index][3]->setChecked(led_pattern.position4);
|
2020-08-21 13:39:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QtControllerSelectorDialog::UpdateBorderColor(std::size_t player_index) {
|
2020-08-28 19:14:19 +02:00
|
|
|
if (!parameters.enable_border_color ||
|
|
|
|
player_index >= static_cast<std::size_t>(parameters.max_players) ||
|
2020-08-21 13:39:24 +02:00
|
|
|
player_groupboxes[player_index]->styleSheet().contains(QStringLiteral("QGroupBox"))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
player_groupboxes[player_index]->setStyleSheet(
|
|
|
|
player_groupboxes[player_index]->styleSheet().append(
|
|
|
|
QStringLiteral("QGroupBox#groupPlayer%1Connected:checked "
|
|
|
|
"{ border: 1px solid rgba(%2, %3, %4, %5); }")
|
|
|
|
.arg(player_index + 1)
|
|
|
|
.arg(parameters.border_colors[player_index][0])
|
|
|
|
.arg(parameters.border_colors[player_index][1])
|
|
|
|
.arg(parameters.border_colors[player_index][2])
|
|
|
|
.arg(parameters.border_colors[player_index][3])));
|
|
|
|
}
|
|
|
|
|
2020-08-27 07:21:48 +02:00
|
|
|
void QtControllerSelectorDialog::SetExplainText(std::size_t player_index) {
|
2020-08-28 19:14:19 +02:00
|
|
|
if (!parameters.enable_explain_text ||
|
|
|
|
player_index >= static_cast<std::size_t>(parameters.max_players)) {
|
2020-08-27 07:21:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
explain_text_labels[player_index]->setText(QString::fromStdString(
|
|
|
|
Common::StringFromFixedZeroTerminatedBuffer(parameters.explain_text[player_index].data(),
|
|
|
|
parameters.explain_text[player_index].size())));
|
|
|
|
}
|
|
|
|
|
2020-08-21 13:39:24 +02:00
|
|
|
void QtControllerSelectorDialog::UpdateDockedState(bool is_handheld) {
|
|
|
|
// Disallow changing the console mode if the controller type is handheld.
|
|
|
|
ui->radioDocked->setEnabled(!is_handheld);
|
|
|
|
ui->radioUndocked->setEnabled(!is_handheld);
|
|
|
|
|
2020-09-28 16:00:15 +02:00
|
|
|
ui->radioDocked->setChecked(Settings::values.use_docked_mode.GetValue());
|
|
|
|
ui->radioUndocked->setChecked(!Settings::values.use_docked_mode.GetValue());
|
2020-08-21 13:39:24 +02:00
|
|
|
|
|
|
|
// Also force into undocked mode if the controller type is handheld.
|
|
|
|
if (is_handheld) {
|
|
|
|
ui->radioUndocked->setChecked(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtControllerSelectorDialog::DisableUnsupportedPlayers() {
|
|
|
|
const auto max_supported_players = parameters.enable_single_mode ? 1 : parameters.max_players;
|
|
|
|
|
|
|
|
switch (max_supported_players) {
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return;
|
|
|
|
case 1:
|
|
|
|
ui->widgetSpacer->hide();
|
|
|
|
ui->widgetSpacer2->hide();
|
|
|
|
ui->widgetSpacer3->hide();
|
|
|
|
ui->widgetSpacer4->hide();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ui->widgetSpacer->hide();
|
|
|
|
ui->widgetSpacer2->hide();
|
|
|
|
ui->widgetSpacer3->hide();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ui->widgetSpacer->hide();
|
|
|
|
ui->widgetSpacer2->hide();
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
ui->widgetSpacer->hide();
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
case 7:
|
|
|
|
case 8:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-08-27 07:46:14 +02:00
|
|
|
for (std::size_t index = max_supported_players; index < NUM_PLAYERS; ++index) {
|
2021-10-21 00:53:14 +02:00
|
|
|
auto* controller = system.HIDCore().GetEmulatedControllerByIndex(index);
|
2020-08-21 13:39:24 +02:00
|
|
|
// Disconnect any unsupported players here and disable or hide them if applicable.
|
2021-11-27 01:55:28 +01:00
|
|
|
UpdateController(controller, controller->GetNpadStyleIndex(true), false);
|
2020-08-21 13:39:24 +02:00
|
|
|
// Hide the player widgets when max_supported_controllers is less than or equal to 4.
|
|
|
|
if (max_supported_players <= 4) {
|
|
|
|
player_widgets[index]->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable and hide the following to prevent these from interaction.
|
|
|
|
player_widgets[index]->setDisabled(true);
|
|
|
|
connected_controller_checkboxes[index]->setDisabled(true);
|
|
|
|
connected_controller_labels[index]->hide();
|
|
|
|
connected_controller_checkboxes[index]->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QtControllerSelector::QtControllerSelector(GMainWindow& parent) {
|
|
|
|
connect(this, &QtControllerSelector::MainWindowReconfigureControllers, &parent,
|
|
|
|
&GMainWindow::ControllerSelectorReconfigureControllers, Qt::QueuedConnection);
|
|
|
|
connect(&parent, &GMainWindow::ControllerSelectorReconfigureFinished, this,
|
|
|
|
&QtControllerSelector::MainWindowReconfigureFinished, Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
QtControllerSelector::~QtControllerSelector() = default;
|
|
|
|
|
|
|
|
void QtControllerSelector::ReconfigureControllers(
|
2020-12-05 14:37:13 +01:00
|
|
|
std::function<void()> callback_, const Core::Frontend::ControllerParameters& parameters) const {
|
|
|
|
callback = std::move(callback_);
|
2020-08-21 13:39:24 +02:00
|
|
|
emit MainWindowReconfigureControllers(parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtControllerSelector::MainWindowReconfigureFinished() {
|
|
|
|
callback();
|
|
|
|
}
|