|
|
@@ -19,13 +19,13 @@
|
|
|
#include "yuzu/configuration/configure_input_player.h"
|
|
|
|
|
|
const std::array<std::string, ConfigureInputPlayer::ANALOG_SUB_BUTTONS_NUM>
|
|
|
- ConfigureInputPlayer::analog_sub_buttons{{
|
|
|
- "up",
|
|
|
- "down",
|
|
|
- "left",
|
|
|
- "right",
|
|
|
- "modifier",
|
|
|
- }};
|
|
|
+ConfigureInputPlayer::analog_sub_buttons{{
|
|
|
+ "up",
|
|
|
+ "down",
|
|
|
+ "left",
|
|
|
+ "right",
|
|
|
+ "modifier",
|
|
|
+}};
|
|
|
|
|
|
static void LayerGridElements(QGridLayout* grid, QWidget* item, QWidget* onTopOf) {
|
|
|
const int index1 = grid->indexOf(item);
|
|
|
@@ -70,6 +70,20 @@ static QString ButtonToText(const Common::ParamPackage& param) {
|
|
|
return GetKeyName(param.Get("code", 0));
|
|
|
}
|
|
|
|
|
|
+ if (param.Get("engine", "") == "gcpad") {
|
|
|
+ if (param.Has("axis")) {
|
|
|
+ const QString axis_str = QString::fromStdString(param.Get("axis", ""));
|
|
|
+ const QString direction_str = QString::fromStdString(param.Get("direction", ""));
|
|
|
+
|
|
|
+ return QObject::tr("Axis %1%2").arg(axis_str, direction_str);
|
|
|
+ }
|
|
|
+ if (param.Has("button")) {
|
|
|
+ const QString button_str = QString::number(int(std::log2(param.Get("button", 0))));
|
|
|
+ return QObject::tr("Button %1").arg(button_str);
|
|
|
+ }
|
|
|
+ return GetKeyName(param.Get("code", 0));
|
|
|
+ }
|
|
|
+
|
|
|
if (param.Get("engine", "") == "sdl") {
|
|
|
if (param.Has("hat")) {
|
|
|
const QString hat_str = QString::fromStdString(param.Get("hat", ""));
|
|
|
@@ -106,7 +120,7 @@ static QString AnalogToText(const Common::ParamPackage& param, const std::string
|
|
|
return ButtonToText(Common::ParamPackage{param.Get(dir, "")});
|
|
|
}
|
|
|
|
|
|
- if (param.Get("engine", "") == "sdl") {
|
|
|
+ if (param.Get("engine", "") == "sdl" || param.Get("engine", "") == "gcpad") {
|
|
|
if (dir == "modifier") {
|
|
|
return QObject::tr("[unused]");
|
|
|
}
|
|
|
@@ -137,13 +151,13 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
|
|
setFocusPolicy(Qt::ClickFocus);
|
|
|
|
|
|
button_map = {
|
|
|
- ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY,
|
|
|
- ui->buttonLStick, ui->buttonRStick, ui->buttonL, ui->buttonR,
|
|
|
- ui->buttonZL, ui->buttonZR, ui->buttonPlus, ui->buttonMinus,
|
|
|
- ui->buttonDpadLeft, ui->buttonDpadUp, ui->buttonDpadRight, ui->buttonDpadDown,
|
|
|
+ ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY,
|
|
|
+ ui->buttonLStick, ui->buttonRStick, ui->buttonL, ui->buttonR,
|
|
|
+ ui->buttonZL, ui->buttonZR, ui->buttonPlus, ui->buttonMinus,
|
|
|
+ ui->buttonDpadLeft, ui->buttonDpadUp, ui->buttonDpadRight, ui->buttonDpadDown,
|
|
|
ui->buttonLStickLeft, ui->buttonLStickUp, ui->buttonLStickRight, ui->buttonLStickDown,
|
|
|
ui->buttonRStickLeft, ui->buttonRStickUp, ui->buttonRStickRight, ui->buttonRStickDown,
|
|
|
- ui->buttonSL, ui->buttonSR, ui->buttonHome, ui->buttonScreenshot,
|
|
|
+ ui->buttonSL, ui->buttonSR, ui->buttonHome, ui->buttonScreenshot,
|
|
|
};
|
|
|
|
|
|
analog_map_buttons = {{
|
|
|
@@ -164,11 +178,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
|
|
}};
|
|
|
|
|
|
debug_hidden = {
|
|
|
- ui->buttonSL, ui->labelSL,
|
|
|
- ui->buttonSR, ui->labelSR,
|
|
|
- ui->buttonLStick, ui->labelLStickPressed,
|
|
|
- ui->buttonRStick, ui->labelRStickPressed,
|
|
|
- ui->buttonHome, ui->labelHome,
|
|
|
+ ui->buttonSL, ui->labelSL,
|
|
|
+ ui->buttonSR, ui->labelSR,
|
|
|
+ ui->buttonLStick, ui->labelLStickPressed,
|
|
|
+ ui->buttonRStick, ui->labelRStickPressed,
|
|
|
+ ui->buttonHome, ui->labelHome,
|
|
|
ui->buttonScreenshot, ui->labelScreenshot,
|
|
|
};
|
|
|
|
|
|
@@ -207,12 +221,12 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
|
|
case Settings::ControllerType::RightJoycon:
|
|
|
layout_hidden = {
|
|
|
ui->left_body_button, ui->left_buttons_button,
|
|
|
- ui->left_body_label, ui->left_buttons_label,
|
|
|
- ui->buttonL, ui->labelL,
|
|
|
- ui->buttonZL, ui->labelZL,
|
|
|
- ui->labelScreenshot, ui->buttonScreenshot,
|
|
|
- ui->buttonMinus, ui->labelMinus,
|
|
|
- ui->LStick, ui->Dpad,
|
|
|
+ ui->left_body_label, ui->left_buttons_label,
|
|
|
+ ui->buttonL, ui->labelL,
|
|
|
+ ui->buttonZL, ui->labelZL,
|
|
|
+ ui->labelScreenshot, ui->buttonScreenshot,
|
|
|
+ ui->buttonMinus, ui->labelMinus,
|
|
|
+ ui->LStick, ui->Dpad,
|
|
|
};
|
|
|
break;
|
|
|
}
|
|
|
@@ -247,9 +261,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
|
|
}
|
|
|
|
|
|
button->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
- connect(button, &QPushButton::clicked, [=] {
|
|
|
+ connect(button, &QPushButton::clicked, [=]
|
|
|
+ {
|
|
|
HandleClick(button_map[button_id],
|
|
|
- [=](Common::ParamPackage params) {
|
|
|
+ [=](Common::ParamPackage params)
|
|
|
+ {
|
|
|
// Workaround for ZL & ZR for analog triggers like on XBOX controllors.
|
|
|
// Analog triggers (from controllers like the XBOX controller) would not
|
|
|
// work due to a different range of their signals (from 0 to 255 on
|
|
|
@@ -267,13 +283,16 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
|
|
},
|
|
|
InputCommon::Polling::DeviceType::Button);
|
|
|
});
|
|
|
- connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) {
|
|
|
+ connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location)
|
|
|
+ {
|
|
|
QMenu context_menu;
|
|
|
- context_menu.addAction(tr("Clear"), [&] {
|
|
|
+ context_menu.addAction(tr("Clear"), [&]
|
|
|
+ {
|
|
|
buttons_param[button_id].Clear();
|
|
|
button_map[button_id]->setText(tr("[not set]"));
|
|
|
});
|
|
|
- context_menu.addAction(tr("Restore Default"), [&] {
|
|
|
+ context_menu.addAction(tr("Restore Default"), [&]
|
|
|
+ {
|
|
|
buttons_param[button_id] = Common::ParamPackage{
|
|
|
InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])};
|
|
|
button_map[button_id]->setText(ButtonToText(buttons_param[button_id]));
|
|
|
@@ -290,22 +309,27 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
|
|
}
|
|
|
|
|
|
analog_button->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
- connect(analog_button, &QPushButton::clicked, [=]() {
|
|
|
+ connect(analog_button, &QPushButton::clicked, [=]()
|
|
|
+ {
|
|
|
HandleClick(analog_map_buttons[analog_id][sub_button_id],
|
|
|
- [=](const Common::ParamPackage& params) {
|
|
|
+ [=](const Common::ParamPackage& params)
|
|
|
+ {
|
|
|
SetAnalogButton(params, analogs_param[analog_id],
|
|
|
analog_sub_buttons[sub_button_id]);
|
|
|
},
|
|
|
InputCommon::Polling::DeviceType::Button);
|
|
|
});
|
|
|
connect(analog_button, &QPushButton::customContextMenuRequested,
|
|
|
- [=](const QPoint& menu_location) {
|
|
|
+ [=](const QPoint& menu_location)
|
|
|
+ {
|
|
|
QMenu context_menu;
|
|
|
- context_menu.addAction(tr("Clear"), [&] {
|
|
|
+ context_menu.addAction(tr("Clear"), [&]
|
|
|
+ {
|
|
|
analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]);
|
|
|
analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]"));
|
|
|
});
|
|
|
- context_menu.addAction(tr("Restore Default"), [&] {
|
|
|
+ context_menu.addAction(tr("Restore Default"), [&]
|
|
|
+ {
|
|
|
Common::ParamPackage params{InputCommon::GenerateKeyboardParam(
|
|
|
Config::default_analogs[analog_id][sub_button_id])};
|
|
|
SetAnalogButton(params, analogs_param[analog_id],
|
|
|
@@ -317,11 +341,12 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
|
|
menu_location));
|
|
|
});
|
|
|
}
|
|
|
- connect(analog_map_stick[analog_id], &QPushButton::clicked, [=] {
|
|
|
+ connect(analog_map_stick[analog_id], &QPushButton::clicked, [=]
|
|
|
+ {
|
|
|
if (QMessageBox::information(
|
|
|
this, tr("Information"),
|
|
|
tr("After pressing OK, first move your joystick horizontally, "
|
|
|
- "and then vertically."),
|
|
|
+ "and then vertically."),
|
|
|
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
|
|
|
HandleClick(
|
|
|
analog_map_stick[analog_id],
|
|
|
@@ -330,9 +355,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- connect(analog_map_deadzone_and_modifier_slider[analog_id], &QSlider::valueChanged, [=] {
|
|
|
+ connect(analog_map_deadzone_and_modifier_slider[analog_id], &QSlider::valueChanged, [=]
|
|
|
+ {
|
|
|
const float slider_value = analog_map_deadzone_and_modifier_slider[analog_id]->value();
|
|
|
- if (analogs_param[analog_id].Get("engine", "") == "sdl") {
|
|
|
+ if (analogs_param[analog_id].Get("engine", "") == "sdl" ||
|
|
|
+ analogs_param[analog_id].Get("engine", "") == "gcpad") {
|
|
|
analog_map_deadzone_and_modifier_slider_label[analog_id]->setText(
|
|
|
tr("Deadzone: %1%").arg(slider_value));
|
|
|
analogs_param[analog_id].Set("deadzone", slider_value / 100.0f);
|
|
|
@@ -350,8 +377,23 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
|
|
timeout_timer->setSingleShot(true);
|
|
|
connect(timeout_timer.get(), &QTimer::timeout, [this] { SetPollingResult({}, true); });
|
|
|
|
|
|
- connect(poll_timer.get(), &QTimer::timeout, [this] {
|
|
|
+ connect(poll_timer.get(), &QTimer::timeout, [this]
|
|
|
+ {
|
|
|
Common::ParamPackage params;
|
|
|
+ if (InputCommon::GetGCButtons()->IsPolling()) {
|
|
|
+ params = InputCommon::GetGCButtons()->GetNextInput();
|
|
|
+ if (params.Has("engine")) {
|
|
|
+ SetPollingResult(params, false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (InputCommon::GetGCAnalogs()->IsPolling()) {
|
|
|
+ params = InputCommon::GetGCAnalogs()->GetNextInput();
|
|
|
+ if (params.Has("engine")) {
|
|
|
+ SetPollingResult(params, false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
for (auto& poller : device_pollers) {
|
|
|
params = poller->GetNextInput();
|
|
|
if (params.Has("engine")) {
|
|
|
@@ -463,7 +505,7 @@ void ConfigureInputPlayer::LoadConfiguration() {
|
|
|
for (std::size_t i = 0; i < colors.size(); ++i) {
|
|
|
controller_color_buttons[i]->setStyleSheet(
|
|
|
QStringLiteral("QPushButton { background-color: %1 }")
|
|
|
- .arg(controller_colors[i].name()));
|
|
|
+ .arg(controller_colors[i].name()));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -534,7 +576,7 @@ void ConfigureInputPlayer::UpdateButtonLabels() {
|
|
|
analog_map_deadzone_and_modifier_slider_label[analog_id];
|
|
|
|
|
|
if (param.Has("engine")) {
|
|
|
- if (param.Get("engine", "") == "sdl") {
|
|
|
+ if (param.Get("engine", "") == "sdl" || param.Get("engine", "") == "gcpad") {
|
|
|
if (!param.Has("deadzone")) {
|
|
|
param.Set("deadzone", 0.1f);
|
|
|
}
|
|
|
@@ -583,6 +625,10 @@ void ConfigureInputPlayer::HandleClick(
|
|
|
|
|
|
grabKeyboard();
|
|
|
grabMouse();
|
|
|
+ if (type == InputCommon::Polling::DeviceType::Button)
|
|
|
+ InputCommon::GetGCButtons()->BeginConfiguration();
|
|
|
+ else
|
|
|
+ InputCommon::GetGCAnalogs()->BeginConfiguration();
|
|
|
timeout_timer->start(5000); // Cancel after 5 seconds
|
|
|
poll_timer->start(200); // Check for new inputs every 200ms
|
|
|
}
|
|
|
@@ -596,6 +642,9 @@ void ConfigureInputPlayer::SetPollingResult(const Common::ParamPackage& params,
|
|
|
poller->Stop();
|
|
|
}
|
|
|
|
|
|
+ InputCommon::GetGCButtons()->EndConfiguration();
|
|
|
+ InputCommon::GetGCAnalogs()->EndConfiguration();
|
|
|
+
|
|
|
if (!abort) {
|
|
|
(*input_setter)(params);
|
|
|
}
|