more fixes

This commit is contained in:
Valentin Vanelslande 2018-12-28 21:26:50 -05:00
parent 39140bbff8
commit 860860397b
1 changed files with 125 additions and 126 deletions

View File

@ -100,163 +100,162 @@ ConfigureInput::ConfigureInput(QWidget* parent)
ui->setupUi(this);
setFocusPolicy(Qt::ClickFocus);
for (const auto& profile : Settings::values::profiles) {
for (const auto& profile : Settings::values.input_profiles) {
ui->profile->addItem(QString::fromStdString(profile.name));
}
ui->profile->addItem(QString::fromStdString(Settings::values.profiles[i].name));
}
ui->profile->setCurrentIndex(Settings::values.current_input_profile);
ui->profile->setCurrentIndex(Settings::values.current_input_profile);
button_map = {
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,
};
button_map = {
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,
};
analog_map_buttons = {{
{
ui->buttonCircleUp,
ui->buttonCircleDown,
ui->buttonCircleLeft,
ui->buttonCircleRight,
ui->buttonCircleMod,
},
{
ui->buttonCStickUp,
ui->buttonCStickDown,
ui->buttonCStickLeft,
ui->buttonCStickRight,
nullptr,
},
}};
analog_map_buttons = {{
{
ui->buttonCircleUp,
ui->buttonCircleDown,
ui->buttonCircleLeft,
ui->buttonCircleRight,
ui->buttonCircleMod,
},
{
ui->buttonCStickUp,
ui->buttonCStickDown,
ui->buttonCStickLeft,
ui->buttonCStickRight,
nullptr,
},
}};
analog_map_stick = {ui->buttonCircleAnalog, ui->buttonCStickAnalog};
analog_map_stick = {ui->buttonCircleAnalog, ui->buttonCStickAnalog};
for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) {
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],
[=](const Common::ParamPackage& params) {
buttons_param[button_id] = params;
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
},
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]"));
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
});
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]));
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
});
context_menu.exec(button_map[button_id]->mapToGlobal(menu_location));
});
}
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])
for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) {
if (!button_map[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, [=]() {
button_map[button_id]->setContextMenuPolicy(Qt::CustomContextMenu);
connect(button_map[button_id], &QPushButton::released, [=]() {
handleClick(
analog_map_buttons[analog_id][sub_button_id],
button_map[button_id],
[=](const Common::ParamPackage& params) {
SetAnalogButton(params, analogs_param[analog_id],
analog_sub_buttons[sub_button_id]);
buttons_param[button_id] = params;
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
},
InputCommon::Polling::DeviceType::Button);
});
connect(analog_map_buttons[analog_id][sub_button_id],
&QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) {
connect(button_map[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]"));
buttons_param[button_id].Clear();
button_map[button_id]->setText(tr("[not set]"));
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
});
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]));
buttons_param[button_id] = Common::ParamPackage{
InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])};
button_map[button_id]->setText(ButtonToText(buttons_param[button_id]));
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
});
context_menu.exec(
analog_map_buttons[analog_id][sub_button_id]->mapToGlobal(menu_location));
context_menu.exec(button_map[button_id]->mapToGlobal(menu_location));
});
}
connect(analog_map_stick[analog_id], &QPushButton::released, [=]() {
QMessageBox::information(this, tr("Information"),
tr("After pressing OK, first move your joystick horizontally, "
"and then vertically."));
handleClick(
analog_map_stick[analog_id],
[=](const Common::ParamPackage& params) {
analogs_param[analog_id] = params;
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
},
InputCommon::Polling::DeviceType::Analog);
});
}
connect(ui->buttonMotionTouch, &QPushButton::released, [this] {
QDialog* motion_touch_dialog = new ConfigureMotionTouch(this);
return motion_touch_dialog->exec();
});
connect(ui->buttonClearAll, &QPushButton::released, [this] { ClearAll(); });
connect(ui->buttonRestoreDefaults, &QPushButton::released, [this]() { restoreDefaults(); });
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.current_input_profile);
Settings::LoadProfile(i);
loadConfiguration();
});
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;
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])
continue;
analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy(
Qt::CustomContextMenu);
connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::released, [=]() {
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);
});
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]"));
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
});
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]));
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
});
context_menu.exec(analog_map_buttons[analog_id][sub_button_id]->mapToGlobal(
menu_location));
});
}
connect(analog_map_stick[analog_id], &QPushButton::released, [=]() {
QMessageBox::information(this, tr("Information"),
tr("After pressing OK, first move your joystick horizontally, "
"and then vertically."));
handleClick(
analog_map_stick[analog_id],
[=](const Common::ParamPackage& params) {
analogs_param[analog_id] = params;
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
},
InputCommon::Polling::DeviceType::Analog);
});
}
});
this->loadConfiguration();
connect(ui->buttonMotionTouch, &QPushButton::released, [this] {
QDialog* motion_touch_dialog = new ConfigureMotionTouch(this);
return motion_touch_dialog->exec();
});
connect(ui->buttonClearAll, &QPushButton::released, [this] { ClearAll(); });
connect(ui->buttonRestoreDefaults, &QPushButton::released, [this]() { restoreDefaults(); });
connect(ui->buttonNew, &QPushButton::released, [this] { newProfile(); });
connect(ui->buttonDelete, &QPushButton::released, [this] { deleteProfile(); });
connect(ui->buttonRename, &QPushButton::released, [this] { renameProfile(); });
// TODO(wwylele): enable this when we actually emulate it
ui->buttonHome->setEnabled(false);
connect(ui->profile, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
[this](int i) {
applyConfiguration();
Settings::SaveProfile(Settings::values.current_input_profile);
Settings::LoadProfile(i);
loadConfiguration();
});
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;
}
}
});
this->loadConfiguration();
// TODO(wwylele): enable this when we actually emulate it
ui->buttonHome->setEnabled(false);
}
ConfigureInput::~ConfigureInput() = default;