2018-09-08 17:01:30 +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-12-29 00:24:56 +00:00
|
|
|
#include <QInputDialog>
|
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>
|
2016-12-22 04:49:36 +00:00
|
|
|
#include "citra_qt/configuration/config.h"
|
|
|
|
#include "citra_qt/configuration/configure_input.h"
|
2018-08-11 03:52:13 +00:00
|
|
|
#include "citra_qt/configuration/configure_motion_touch.h"
|
2017-01-22 19:02:29 +00:00
|
|
|
#include "common/param_package.h"
|
2016-07-29 12:45:49 +00:00
|
|
|
|
2017-01-22 19:02:29 +00:00
|
|
|
const std::array<std::string, ConfigureInput::ANALOG_SUB_BUTTONS_NUM>
|
|
|
|
ConfigureInput::analog_sub_buttons{{
|
2018-03-09 17:54:43 +00:00
|
|
|
"up",
|
|
|
|
"down",
|
|
|
|
"left",
|
|
|
|
"right",
|
|
|
|
"modifier",
|
2017-01-22 19:02:29 +00:00
|
|
|
}};
|
|
|
|
|
|
|
|
static QString getKeyName(int key_code) {
|
2016-12-09 23:59:09 +00:00
|
|
|
switch (key_code) {
|
|
|
|
case Qt::Key_Shift:
|
|
|
|
return QObject::tr("Shift");
|
|
|
|
case Qt::Key_Control:
|
|
|
|
return QObject::tr("Ctrl");
|
|
|
|
case Qt::Key_Alt:
|
|
|
|
return QObject::tr("Alt");
|
|
|
|
case Qt::Key_Meta:
|
|
|
|
return "";
|
|
|
|
default:
|
|
|
|
return QKeySequence(key_code).toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 04:26:29 +00:00
|
|
|
static void SetAnalogButton(const Common::ParamPackage& input_param,
|
|
|
|
Common::ParamPackage& analog_param, const std::string& button_name) {
|
2017-01-22 19:02:29 +00:00
|
|
|
if (analog_param.Get("engine", "") != "analog_from_button") {
|
|
|
|
analog_param = {
|
2018-03-09 17:54:43 +00:00
|
|
|
{"engine", "analog_from_button"},
|
|
|
|
{"modifier_scale", "0.5"},
|
2017-01-22 19:02:29 +00:00
|
|
|
};
|
|
|
|
}
|
2017-12-06 04:26:29 +00:00
|
|
|
analog_param.Set(button_name, input_param.Serialize());
|
2017-01-22 19:02:29 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 18:06:14 +00:00
|
|
|
static QString ButtonToText(const Common::ParamPackage& param) {
|
|
|
|
if (!param.Has("engine")) {
|
|
|
|
return QObject::tr("[not set]");
|
|
|
|
} else if (param.Get("engine", "") == "keyboard") {
|
|
|
|
return getKeyName(param.Get("code", 0));
|
|
|
|
} else if (param.Get("engine", "") == "sdl") {
|
|
|
|
if (param.Has("hat")) {
|
2018-09-08 17:01:30 +00:00
|
|
|
return QString(QObject::tr("Hat %1 %2"))
|
|
|
|
.arg(param.Get("hat", "").c_str(), param.Get("direction", "").c_str());
|
2017-12-13 18:06:14 +00:00
|
|
|
}
|
|
|
|
if (param.Has("axis")) {
|
2018-09-08 17:01:30 +00:00
|
|
|
return QString(QObject::tr("Axis %1%2"))
|
|
|
|
.arg(param.Get("axis", "").c_str(), param.Get("direction", "").c_str());
|
2017-12-13 18:06:14 +00:00
|
|
|
}
|
|
|
|
if (param.Has("button")) {
|
2018-09-08 17:01:30 +00:00
|
|
|
return QString(QObject::tr("Button %1")).arg(param.Get("button", "").c_str());
|
2017-12-13 18:06:14 +00:00
|
|
|
}
|
2018-09-08 17:01:30 +00:00
|
|
|
return QString();
|
2017-12-13 18:06:14 +00:00
|
|
|
} else {
|
|
|
|
return QObject::tr("[unknown]");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static QString AnalogToText(const Common::ParamPackage& param, const std::string& dir) {
|
|
|
|
if (!param.Has("engine")) {
|
|
|
|
return QObject::tr("[not set]");
|
|
|
|
} else if (param.Get("engine", "") == "analog_from_button") {
|
|
|
|
return ButtonToText(Common::ParamPackage{param.Get(dir, "")});
|
|
|
|
} else if (param.Get("engine", "") == "sdl") {
|
|
|
|
if (dir == "modifier") {
|
|
|
|
return QString(QObject::tr("[unused]"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dir == "left" || dir == "right") {
|
2018-09-08 17:01:30 +00:00
|
|
|
return QString(QObject::tr("Axis %1")).arg(param.Get("axis_x", "").c_str());
|
2017-12-13 18:06:14 +00:00
|
|
|
} else if (dir == "up" || dir == "down") {
|
2018-09-08 17:01:30 +00:00
|
|
|
return QString(QObject::tr("Axis %1")).arg(param.Get("axis_y", "").c_str());
|
2017-12-13 18:06:14 +00:00
|
|
|
}
|
2018-09-08 17:01:30 +00:00
|
|
|
return QString();
|
2017-12-13 18:06:14 +00:00
|
|
|
} else {
|
|
|
|
return QObject::tr("[unknown]");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-18 00:38:01 +00:00
|
|
|
ConfigureInput::ConfigureInput(QWidget* parent)
|
2016-12-09 23:59:09 +00:00
|
|
|
: QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()),
|
2017-12-06 04:26:29 +00:00
|
|
|
timeout_timer(std::make_unique<QTimer>()), poll_timer(std::make_unique<QTimer>()) {
|
2016-09-19 01:01:46 +00:00
|
|
|
|
2016-07-29 12:45:49 +00:00
|
|
|
ui->setupUi(this);
|
2016-12-09 23:59:09 +00:00
|
|
|
setFocusPolicy(Qt::ClickFocus);
|
2016-07-29 12:45:49 +00:00
|
|
|
|
2018-12-29 00:24:56 +00:00
|
|
|
for (int i = 0; i < Settings::values.profiles.size(); ++i) {
|
|
|
|
ui->profile->addItem(QString::fromStdString(Settings::values.profiles[i].name));
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->profile->setCurrentIndex(Settings::values.profile);
|
|
|
|
|
2016-12-09 23:59:09 +00:00
|
|
|
button_map = {
|
2017-01-22 19:02:29 +00:00
|
|
|
ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, ui->buttonDpadUp,
|
|
|
|
ui->buttonDpadDown, ui->buttonDpadLeft, ui->buttonDpadRight, ui->buttonL, ui->buttonR,
|
|
|
|
ui->buttonStart, ui->buttonSelect, ui->buttonZL, ui->buttonZR, ui->buttonHome,
|
2016-07-29 12:45:49 +00:00
|
|
|
};
|
|
|
|
|
2017-12-06 04:26:29 +00:00
|
|
|
analog_map_buttons = {{
|
2017-01-22 19:02:29 +00:00
|
|
|
{
|
2018-03-09 17:54:43 +00:00
|
|
|
ui->buttonCircleUp,
|
|
|
|
ui->buttonCircleDown,
|
|
|
|
ui->buttonCircleLeft,
|
|
|
|
ui->buttonCircleRight,
|
2017-01-22 19:02:29 +00:00
|
|
|
ui->buttonCircleMod,
|
|
|
|
},
|
|
|
|
{
|
2018-03-09 17:54:43 +00:00
|
|
|
ui->buttonCStickUp,
|
|
|
|
ui->buttonCStickDown,
|
|
|
|
ui->buttonCStickLeft,
|
|
|
|
ui->buttonCStickRight,
|
2017-01-22 19:02:29 +00:00
|
|
|
nullptr,
|
|
|
|
},
|
|
|
|
}};
|
|
|
|
|
2017-12-06 04:26:29 +00:00
|
|
|
analog_map_stick = {ui->buttonCircleAnalog, ui->buttonCStickAnalog};
|
|
|
|
|
2017-01-22 19:02:29 +00:00
|
|
|
for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) {
|
2018-08-26 08:23:12 +00:00
|
|
|
if (!button_map[button_id])
|
|
|
|
continue;
|
|
|
|
button_map[button_id]->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(button_map[button_id], &QPushButton::released, [=]() {
|
|
|
|
handleClick(
|
|
|
|
button_map[button_id],
|
2018-12-29 00:24:56 +00:00
|
|
|
[=](const Common::ParamPackage& params) {
|
|
|
|
buttons_param[button_id] = params;
|
|
|
|
applyConfiguration();
|
|
|
|
Settings::SaveProfile(ui->profile->currentIndex());
|
|
|
|
},
|
2018-08-26 08:23:12 +00:00
|
|
|
InputCommon::Polling::DeviceType::Button);
|
|
|
|
});
|
|
|
|
connect(button_map[button_id], &QPushButton::customContextMenuRequested,
|
|
|
|
[=](const QPoint& menu_location) {
|
|
|
|
QMenu context_menu;
|
|
|
|
context_menu.addAction(tr("Clear"), [&] {
|
|
|
|
buttons_param[button_id].Clear();
|
|
|
|
button_map[button_id]->setText(tr("[not set]"));
|
2018-12-29 00:24:56 +00:00
|
|
|
applyConfiguration();
|
|
|
|
Settings::SaveProfile(ui->profile->currentIndex());
|
2018-08-26 08:23:12 +00:00
|
|
|
});
|
|
|
|
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]));
|
2018-12-29 00:24:56 +00:00
|
|
|
applyConfiguration();
|
|
|
|
Settings::SaveProfile(ui->profile->currentIndex());
|
2018-08-26 08:23:12 +00:00
|
|
|
});
|
|
|
|
context_menu.exec(button_map[button_id]->mapToGlobal(menu_location));
|
|
|
|
});
|
2017-01-22 19:02:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) {
|
|
|
|
for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) {
|
2018-08-26 08:23:12 +00:00
|
|
|
if (!analog_map_buttons[analog_id][sub_button_id])
|
|
|
|
continue;
|
|
|
|
analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy(
|
|
|
|
Qt::CustomContextMenu);
|
|
|
|
connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::released, [=]() {
|
2018-12-29 00:24:56 +00:00
|
|
|
handleClick(
|
|
|
|
analog_map_buttons[analog_id][sub_button_id],
|
|
|
|
[=](const Common::ParamPackage& params) {
|
|
|
|
SetAnalogButton(params, analogs_param[analog_id],
|
|
|
|
analog_sub_buttons[sub_button_id]);
|
|
|
|
applyConfiguration();
|
|
|
|
Settings::SaveProfile(ui->profile->currentIndex());
|
|
|
|
},
|
|
|
|
InputCommon::Polling::DeviceType::Button);
|
2018-08-26 08:23:12 +00:00
|
|
|
});
|
|
|
|
connect(analog_map_buttons[analog_id][sub_button_id],
|
|
|
|
&QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) {
|
|
|
|
QMenu context_menu;
|
|
|
|
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]"));
|
2018-12-29 00:24:56 +00:00
|
|
|
applyConfiguration();
|
|
|
|
Settings::SaveProfile(ui->profile->currentIndex());
|
2017-12-06 04:26:29 +00:00
|
|
|
});
|
2018-08-26 08:23:12 +00:00
|
|
|
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],
|
|
|
|
analog_sub_buttons[sub_button_id]);
|
|
|
|
analog_map_buttons[analog_id][sub_button_id]->setText(AnalogToText(
|
|
|
|
analogs_param[analog_id], analog_sub_buttons[sub_button_id]));
|
2018-12-29 00:24:56 +00:00
|
|
|
applyConfiguration();
|
|
|
|
Settings::SaveProfile(ui->profile->currentIndex());
|
2018-08-26 08:23:12 +00:00
|
|
|
});
|
|
|
|
context_menu.exec(analog_map_buttons[analog_id][sub_button_id]->mapToGlobal(
|
|
|
|
menu_location));
|
|
|
|
});
|
2017-01-22 19:02:29 +00:00
|
|
|
}
|
2017-12-06 04:26:29 +00:00
|
|
|
connect(analog_map_stick[analog_id], &QPushButton::released, [=]() {
|
2018-10-02 23:31:31 +00:00
|
|
|
QMessageBox::information(this, tr("Information"),
|
|
|
|
tr("After pressing OK, first move your joystick horizontally, "
|
|
|
|
"and then vertically."));
|
2017-12-06 04:26:29 +00:00
|
|
|
handleClick(
|
|
|
|
analog_map_stick[analog_id],
|
2018-12-29 00:24:56 +00:00
|
|
|
[=](const Common::ParamPackage& params) {
|
|
|
|
analogs_param[analog_id] = params;
|
|
|
|
applyConfiguration();
|
|
|
|
Settings::SaveProfile(ui->profile->currentIndex());
|
|
|
|
},
|
2017-12-06 04:26:29 +00:00
|
|
|
InputCommon::Polling::DeviceType::Analog);
|
|
|
|
});
|
2016-07-29 12:45:49 +00:00
|
|
|
}
|
2016-12-09 23:59:09 +00:00
|
|
|
|
2018-08-11 03:52:13 +00:00
|
|
|
connect(ui->buttonMotionTouch, &QPushButton::released, [this] {
|
|
|
|
QDialog* motion_touch_dialog = new ConfigureMotionTouch(this);
|
|
|
|
return motion_touch_dialog->exec();
|
|
|
|
});
|
2018-08-26 08:23:12 +00:00
|
|
|
connect(ui->buttonClearAll, &QPushButton::released, [this] { ClearAll(); });
|
2016-12-09 23:59:09 +00:00
|
|
|
connect(ui->buttonRestoreDefaults, &QPushButton::released, [this]() { restoreDefaults(); });
|
2018-12-29 00:24:56 +00:00
|
|
|
connect(ui->buttonNew, &QPushButton::released, [this] { newProfile(); });
|
|
|
|
connect(ui->buttonDelete, &QPushButton::released, [this] { deleteProfile(); });
|
|
|
|
connect(ui->buttonRename, &QPushButton::released, [this] { renameProfile(); });
|
|
|
|
|
|
|
|
connect(ui->profile, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
|
|
|
[this](int i) {
|
|
|
|
applyConfiguration();
|
|
|
|
Settings::SaveProfile(Settings::values.profile);
|
|
|
|
Settings::LoadProfile(i);
|
|
|
|
loadConfiguration();
|
|
|
|
});
|
2016-12-09 23:59:09 +00:00
|
|
|
|
2017-12-06 04:26:29 +00:00
|
|
|
timeout_timer->setSingleShot(true);
|
|
|
|
connect(timeout_timer.get(), &QTimer::timeout, [this]() { setPollingResult({}, true); });
|
|
|
|
|
|
|
|
connect(poll_timer.get(), &QTimer::timeout, [this]() {
|
|
|
|
Common::ParamPackage params;
|
|
|
|
for (auto& poller : device_pollers) {
|
|
|
|
params = poller->GetNextInput();
|
|
|
|
if (params.Has("engine")) {
|
|
|
|
setPollingResult(params, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-09-18 00:38:01 +00:00
|
|
|
});
|
2016-07-29 12:45:49 +00:00
|
|
|
|
2016-12-09 23:59:09 +00:00
|
|
|
this->loadConfiguration();
|
2017-01-22 19:02:29 +00:00
|
|
|
|
2017-02-25 18:56:43 +00:00
|
|
|
// TODO(wwylele): enable this when we actually emulate it
|
2017-01-22 19:02:29 +00:00
|
|
|
ui->buttonHome->setEnabled(false);
|
2016-07-29 12:45:49 +00:00
|
|
|
}
|
|
|
|
|
2018-12-02 19:06:39 +00:00
|
|
|
ConfigureInput::~ConfigureInput() = default;
|
|
|
|
|
2016-07-29 12:45:49 +00:00
|
|
|
void ConfigureInput::applyConfiguration() {
|
2017-01-22 19:02:29 +00:00
|
|
|
std::transform(buttons_param.begin(), buttons_param.end(), Settings::values.buttons.begin(),
|
|
|
|
[](const Common::ParamPackage& param) { return param.Serialize(); });
|
|
|
|
std::transform(analogs_param.begin(), analogs_param.end(), Settings::values.analogs.begin(),
|
|
|
|
[](const Common::ParamPackage& param) { return param.Serialize(); });
|
2016-07-29 12:45:49 +00:00
|
|
|
}
|
|
|
|
|
2018-12-29 00:24:56 +00:00
|
|
|
void ConfigureInput::applyProfile() {
|
|
|
|
Settings::values.profile = ui->profile->currentIndex();
|
|
|
|
}
|
|
|
|
|
2016-12-09 23:59:09 +00:00
|
|
|
void ConfigureInput::loadConfiguration() {
|
2017-01-22 19:02:29 +00:00
|
|
|
std::transform(Settings::values.buttons.begin(), Settings::values.buttons.end(),
|
|
|
|
buttons_param.begin(),
|
|
|
|
[](const std::string& str) { return Common::ParamPackage(str); });
|
|
|
|
std::transform(Settings::values.analogs.begin(), Settings::values.analogs.end(),
|
|
|
|
analogs_param.begin(),
|
|
|
|
[](const std::string& str) { return Common::ParamPackage(str); });
|
2016-12-09 23:59:09 +00:00
|
|
|
updateButtonLabels();
|
2016-07-29 12:45:49 +00:00
|
|
|
}
|
|
|
|
|
2017-01-22 19:02:29 +00:00
|
|
|
void ConfigureInput::restoreDefaults() {
|
|
|
|
for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) {
|
2017-12-06 04:26:29 +00:00
|
|
|
buttons_param[button_id] = Common::ParamPackage{
|
|
|
|
InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])};
|
2017-01-22 19:02:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) {
|
|
|
|
for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) {
|
2017-12-06 04:26:29 +00:00
|
|
|
Common::ParamPackage params{InputCommon::GenerateKeyboardParam(
|
|
|
|
Config::default_analogs[analog_id][sub_button_id])};
|
|
|
|
SetAnalogButton(params, analogs_param[analog_id], analog_sub_buttons[sub_button_id]);
|
2017-01-22 19:02:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
updateButtonLabels();
|
2018-08-26 08:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureInput::ClearAll() {
|
|
|
|
for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) {
|
|
|
|
if (button_map[button_id] && button_map[button_id]->isEnabled())
|
|
|
|
buttons_param[button_id].Clear();
|
|
|
|
}
|
|
|
|
for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) {
|
|
|
|
for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) {
|
|
|
|
if (analog_map_buttons[analog_id][sub_button_id] &&
|
|
|
|
analog_map_buttons[analog_id][sub_button_id]->isEnabled())
|
|
|
|
analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateButtonLabels();
|
2017-01-22 19:02:29 +00:00
|
|
|
}
|
2016-07-29 12:45:49 +00:00
|
|
|
|
2016-12-09 23:59:09 +00:00
|
|
|
void ConfigureInput::updateButtonLabels() {
|
2017-01-22 19:02:29 +00:00
|
|
|
for (int button = 0; button < Settings::NativeButton::NumButtons; button++) {
|
2017-12-08 12:03:43 +00:00
|
|
|
button_map[button]->setText(ButtonToText(buttons_param[button]));
|
2017-01-22 19:02:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) {
|
2017-12-08 12:03:43 +00:00
|
|
|
for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) {
|
|
|
|
if (analog_map_buttons[analog_id][sub_button_id]) {
|
|
|
|
analog_map_buttons[analog_id][sub_button_id]->setText(
|
|
|
|
AnalogToText(analogs_param[analog_id], analog_sub_buttons[sub_button_id]));
|
2017-01-22 19:02:29 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-09 15:11:17 +00:00
|
|
|
analog_map_stick[analog_id]->setText(tr("Set Analog Stick"));
|
2016-12-09 23:59:09 +00:00
|
|
|
}
|
2016-07-29 12:45:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 04:26:29 +00:00
|
|
|
void ConfigureInput::handleClick(QPushButton* button,
|
|
|
|
std::function<void(const Common::ParamPackage&)> new_input_setter,
|
|
|
|
InputCommon::Polling::DeviceType type) {
|
2016-12-09 23:59:09 +00:00
|
|
|
button->setText(tr("[press key]"));
|
|
|
|
button->setFocus();
|
2016-07-29 12:45:49 +00:00
|
|
|
|
2017-12-06 04:26:29 +00:00
|
|
|
input_setter = new_input_setter;
|
|
|
|
|
|
|
|
device_pollers = InputCommon::Polling::GetPollers(type);
|
|
|
|
|
|
|
|
// Keyboard keys can only be used as button devices
|
|
|
|
want_keyboard_keys = type == InputCommon::Polling::DeviceType::Button;
|
|
|
|
|
|
|
|
for (auto& poller : device_pollers) {
|
|
|
|
poller->Start();
|
|
|
|
}
|
2016-07-29 12:45:49 +00:00
|
|
|
|
2016-12-09 23:59:09 +00:00
|
|
|
grabKeyboard();
|
|
|
|
grabMouse();
|
2017-12-06 04:26:29 +00:00
|
|
|
timeout_timer->start(5000); // Cancel after 5 seconds
|
|
|
|
poll_timer->start(200); // Check for new inputs every 200ms
|
2016-07-29 12:45:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 04:26:29 +00:00
|
|
|
void ConfigureInput::setPollingResult(const Common::ParamPackage& params, bool abort) {
|
2016-12-09 23:59:09 +00:00
|
|
|
releaseKeyboard();
|
|
|
|
releaseMouse();
|
2017-12-06 04:26:29 +00:00
|
|
|
timeout_timer->stop();
|
|
|
|
poll_timer->stop();
|
|
|
|
for (auto& poller : device_pollers) {
|
|
|
|
poller->Stop();
|
|
|
|
}
|
2016-12-09 23:59:09 +00:00
|
|
|
|
2018-10-05 14:51:33 +00:00
|
|
|
if (!abort && input_setter) {
|
2017-12-06 04:26:29 +00:00
|
|
|
(*input_setter)(params);
|
|
|
|
}
|
2016-12-09 23:59:09 +00:00
|
|
|
|
|
|
|
updateButtonLabels();
|
2018-10-05 10:37:55 +00:00
|
|
|
input_setter.reset();
|
2017-12-06 04:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureInput::keyPressEvent(QKeyEvent* event) {
|
|
|
|
if (!input_setter || !event)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event->key() != Qt::Key_Escape) {
|
|
|
|
if (want_keyboard_keys) {
|
|
|
|
setPollingResult(Common::ParamPackage{InputCommon::GenerateKeyboardParam(event->key())},
|
|
|
|
false);
|
|
|
|
} else {
|
|
|
|
// Escape key wasn't pressed and we don't want any keyboard keys, so don't stop polling
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setPollingResult({}, true);
|
2016-07-29 12:45:49 +00:00
|
|
|
}
|
2017-09-23 13:13:59 +00:00
|
|
|
|
|
|
|
void ConfigureInput::retranslateUi() {
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
}
|
2018-12-29 00:24:56 +00:00
|
|
|
|
|
|
|
void ConfigureInput::newProfile() {
|
|
|
|
QString name =
|
|
|
|
QInputDialog::getText(this, tr("New Profile"), tr("Enter the name for the new profile."));
|
|
|
|
if (name.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
applyConfiguration();
|
|
|
|
Settings::SaveProfile(ui->profile->currentIndex());
|
|
|
|
Settings::CreateProfile(name.toStdString());
|
|
|
|
ui->profile->addItem(name);
|
|
|
|
ui->profile->setCurrentIndex(Settings::values.profile);
|
|
|
|
loadConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureInput::deleteProfile() {
|
|
|
|
if (ui->profile->count() == 1) {
|
|
|
|
QMessageBox::critical(this, tr("Citra"), tr("You need to have 1 profile at least"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QMessageBox::StandardButton answer = QMessageBox::question(
|
|
|
|
this, tr("Delete Profile"), tr("Delete profile %1?").arg(ui->profile->currentText()));
|
|
|
|
if (answer != QMessageBox::Yes) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int index = ui->profile->currentIndex();
|
|
|
|
ui->profile->removeItem(index);
|
|
|
|
ui->profile->setCurrentIndex(0);
|
|
|
|
Settings::DeleteProfile(index);
|
|
|
|
loadConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureInput::renameProfile() {
|
|
|
|
QString new_name = QInputDialog::getText(this, tr("Rename Profile"), tr("New name:"));
|
|
|
|
if (new_name.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ui->profile->setItemText(ui->profile->currentIndex(), new_name);
|
|
|
|
Settings::RenameCurrentProfile(new_name.toStdString());
|
|
|
|
}
|