2017-05-20 15:53:17 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Config/Mapping/MappingWidget.h"
|
2018-05-28 01:48:04 +00:00
|
|
|
|
2019-10-30 01:05:42 +00:00
|
|
|
#include <QCheckBox>
|
2022-05-20 03:47:30 +00:00
|
|
|
#include <QDialogButtonBox>
|
2017-05-20 15:53:17 +00:00
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QGroupBox>
|
2021-07-04 10:56:07 +00:00
|
|
|
#include <QHBoxLayout>
|
2019-10-30 01:05:42 +00:00
|
|
|
#include <QLabel>
|
2017-05-20 15:53:17 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
|
2019-10-18 19:54:02 +00:00
|
|
|
#include "DolphinQt/Config/Mapping/IOWindow.h"
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Config/Mapping/MappingButton.h"
|
|
|
|
#include "DolphinQt/Config/Mapping/MappingIndicator.h"
|
|
|
|
#include "DolphinQt/Config/Mapping/MappingNumeric.h"
|
|
|
|
#include "DolphinQt/Config/Mapping/MappingWindow.h"
|
2018-05-28 01:48:04 +00:00
|
|
|
|
2017-05-20 15:53:17 +00:00
|
|
|
#include "InputCommon/ControlReference/ControlReference.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Control/Control.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
2020-02-23 19:34:05 +00:00
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h"
|
2019-03-15 01:27:49 +00:00
|
|
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
2017-05-20 15:53:17 +00:00
|
|
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
2019-02-05 00:50:07 +00:00
|
|
|
#include "InputCommon/ControllerEmu/StickGate.h"
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2019-03-15 01:27:49 +00:00
|
|
|
MappingWidget::MappingWidget(MappingWindow* parent) : m_parent(parent)
|
2017-05-20 15:53:17 +00:00
|
|
|
{
|
2019-03-15 01:27:49 +00:00
|
|
|
connect(parent, &MappingWindow::Update, this, &MappingWidget::Update);
|
|
|
|
connect(parent, &MappingWindow::Save, this, &MappingWidget::SaveSettings);
|
|
|
|
connect(parent, &MappingWindow::ConfigChanged, this, &MappingWidget::ConfigChanged);
|
2017-05-20 15:53:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MappingWindow* MappingWidget::GetParent() const
|
|
|
|
{
|
|
|
|
return m_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MappingWidget::GetPort() const
|
|
|
|
{
|
|
|
|
return m_parent->GetPort();
|
|
|
|
}
|
|
|
|
|
2019-04-20 17:53:13 +00:00
|
|
|
QGroupBox* MappingWidget::CreateGroupBox(ControllerEmu::ControlGroup* group)
|
|
|
|
{
|
|
|
|
return CreateGroupBox(tr(group->ui_name.c_str()), group);
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:53:17 +00:00
|
|
|
QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::ControlGroup* group)
|
|
|
|
{
|
|
|
|
QGroupBox* group_box = new QGroupBox(name);
|
|
|
|
QFormLayout* form_layout = new QFormLayout();
|
|
|
|
|
|
|
|
group_box->setLayout(form_layout);
|
|
|
|
|
2020-02-23 19:34:05 +00:00
|
|
|
MappingIndicator* indicator = nullptr;
|
|
|
|
|
|
|
|
switch (group->type)
|
2019-04-27 19:23:29 +00:00
|
|
|
{
|
2020-02-23 19:34:05 +00:00
|
|
|
case ControllerEmu::GroupType::Shake:
|
|
|
|
indicator = new ShakeMappingIndicator(*static_cast<ControllerEmu::Shake*>(group));
|
|
|
|
break;
|
2019-04-27 19:23:29 +00:00
|
|
|
|
2020-02-23 19:34:05 +00:00
|
|
|
case ControllerEmu::GroupType::MixedTriggers:
|
|
|
|
indicator = new MixedTriggersIndicator(*static_cast<ControllerEmu::MixedTriggers*>(group));
|
|
|
|
break;
|
2019-04-27 19:23:29 +00:00
|
|
|
|
2020-02-23 19:34:05 +00:00
|
|
|
case ControllerEmu::GroupType::Tilt:
|
|
|
|
indicator = new TiltIndicator(*static_cast<ControllerEmu::Tilt*>(group));
|
|
|
|
break;
|
2019-11-06 00:51:23 +00:00
|
|
|
|
2020-02-23 19:34:05 +00:00
|
|
|
case ControllerEmu::GroupType::Cursor:
|
|
|
|
indicator = new CursorIndicator(*static_cast<ControllerEmu::Cursor*>(group));
|
|
|
|
break;
|
2019-11-06 00:51:23 +00:00
|
|
|
|
2020-02-23 19:34:05 +00:00
|
|
|
case ControllerEmu::GroupType::Force:
|
|
|
|
indicator = new SwingIndicator(*static_cast<ControllerEmu::Force*>(group));
|
|
|
|
break;
|
2019-04-27 19:23:29 +00:00
|
|
|
|
2020-02-23 19:34:05 +00:00
|
|
|
case ControllerEmu::GroupType::IMUAccelerometer:
|
|
|
|
indicator =
|
|
|
|
new AccelerometerMappingIndicator(*static_cast<ControllerEmu::IMUAccelerometer*>(group));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ControllerEmu::GroupType::IMUGyroscope:
|
|
|
|
indicator = new GyroMappingIndicator(*static_cast<ControllerEmu::IMUGyroscope*>(group));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ControllerEmu::GroupType::Stick:
|
|
|
|
indicator = new AnalogStickIndicator(*static_cast<ControllerEmu::ReshapableInput*>(group));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (indicator)
|
|
|
|
{
|
2020-02-24 02:00:44 +00:00
|
|
|
const auto indicator_layout = new QBoxLayout(QBoxLayout::Direction::Down);
|
|
|
|
indicator_layout->addWidget(indicator);
|
|
|
|
indicator_layout->setAlignment(Qt::AlignCenter);
|
|
|
|
form_layout->addRow(indicator_layout);
|
2019-04-27 19:23:29 +00:00
|
|
|
|
2019-07-30 13:35:46 +00:00
|
|
|
connect(this, &MappingWidget::Update, indicator, qOverload<>(&MappingIndicator::update));
|
2019-04-27 19:23:29 +00:00
|
|
|
|
2020-02-23 19:34:05 +00:00
|
|
|
const bool need_calibration = group->type == ControllerEmu::GroupType::Cursor ||
|
|
|
|
group->type == ControllerEmu::GroupType::Stick ||
|
|
|
|
group->type == ControllerEmu::GroupType::Tilt ||
|
|
|
|
group->type == ControllerEmu::GroupType::Force;
|
|
|
|
|
2019-04-27 19:23:29 +00:00
|
|
|
if (need_calibration)
|
|
|
|
{
|
|
|
|
const auto calibrate =
|
2020-02-23 19:34:05 +00:00
|
|
|
new CalibrationWidget(*static_cast<ControllerEmu::ReshapableInput*>(group),
|
|
|
|
*static_cast<ReshapableInputIndicator*>(indicator));
|
2019-04-27 19:23:29 +00:00
|
|
|
|
|
|
|
form_layout->addRow(calibrate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:53:17 +00:00
|
|
|
for (auto& control : group->controls)
|
2021-07-04 10:56:07 +00:00
|
|
|
CreateControl(control.get(), form_layout, !indicator);
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2022-05-20 03:47:30 +00:00
|
|
|
AddSettingWidgets(form_layout, group, ControllerEmu::SettingVisibility::Normal);
|
|
|
|
|
|
|
|
if (group->default_value != ControllerEmu::ControlGroup::DefaultValue::AlwaysEnabled)
|
|
|
|
{
|
|
|
|
QLabel* group_enable_label = new QLabel(tr("Enable"));
|
|
|
|
QCheckBox* group_enable_checkbox = new QCheckBox();
|
|
|
|
group_enable_checkbox->setChecked(group->enabled);
|
|
|
|
form_layout->insertRow(0, group_enable_label, group_enable_checkbox);
|
|
|
|
auto enable_group_by_checkbox = [group, form_layout, group_enable_label,
|
|
|
|
group_enable_checkbox] {
|
|
|
|
group->enabled = group_enable_checkbox->isChecked();
|
|
|
|
for (int i = 0; i < form_layout->count(); ++i)
|
|
|
|
{
|
|
|
|
QWidget* widget = form_layout->itemAt(i)->widget();
|
|
|
|
if (widget != nullptr && widget != group_enable_label && widget != group_enable_checkbox)
|
|
|
|
widget->setEnabled(group->enabled);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
enable_group_by_checkbox();
|
|
|
|
connect(group_enable_checkbox, &QCheckBox::toggled, this, enable_group_by_checkbox);
|
|
|
|
connect(this, &MappingWidget::ConfigChanged, this,
|
|
|
|
[group_enable_checkbox, group] { group_enable_checkbox->setChecked(group->enabled); });
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto advanced_setting_count = std::count_if(
|
|
|
|
group->numeric_settings.begin(), group->numeric_settings.end(), [](auto& setting) {
|
|
|
|
return setting->GetVisibility() == ControllerEmu::SettingVisibility::Advanced;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (advanced_setting_count != 0)
|
|
|
|
{
|
|
|
|
const auto advanced_button = new QPushButton(tr("Advanced"));
|
|
|
|
form_layout->addRow(advanced_button);
|
|
|
|
connect(advanced_button, &QPushButton::clicked,
|
|
|
|
[this, group] { ShowAdvancedControlGroupDialog(group); });
|
|
|
|
}
|
|
|
|
|
|
|
|
return group_box;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingWidget::AddSettingWidgets(QFormLayout* layout, ControllerEmu::ControlGroup* group,
|
|
|
|
ControllerEmu::SettingVisibility visibility)
|
|
|
|
{
|
2019-03-27 00:31:03 +00:00
|
|
|
for (auto& setting : group->numeric_settings)
|
2017-05-20 15:53:17 +00:00
|
|
|
{
|
2022-05-20 03:47:30 +00:00
|
|
|
if (setting->GetVisibility() != visibility)
|
|
|
|
continue;
|
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
QWidget* setting_widget = nullptr;
|
2018-07-02 13:16:43 +00:00
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
switch (setting->GetType())
|
|
|
|
{
|
|
|
|
case ControllerEmu::SettingType::Double:
|
|
|
|
setting_widget = new MappingDouble(
|
|
|
|
this, static_cast<ControllerEmu::NumericSetting<double>*>(setting.get()));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ControllerEmu::SettingType::Bool:
|
|
|
|
setting_widget =
|
|
|
|
new MappingBool(this, static_cast<ControllerEmu::NumericSetting<bool>*>(setting.get()));
|
|
|
|
break;
|
2020-01-18 17:19:32 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
// FYI: Widgets for additional types can be implemented as needed.
|
|
|
|
break;
|
2019-03-27 00:31:03 +00:00
|
|
|
}
|
2018-07-02 13:16:43 +00:00
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
if (setting_widget)
|
2019-10-18 19:54:02 +00:00
|
|
|
{
|
|
|
|
const auto hbox = new QHBoxLayout;
|
|
|
|
|
2020-01-18 17:19:32 +00:00
|
|
|
hbox->addWidget(setting_widget);
|
|
|
|
hbox->addWidget(CreateSettingAdvancedMappingButton(*setting));
|
2019-10-18 19:54:02 +00:00
|
|
|
|
2022-05-20 03:47:30 +00:00
|
|
|
layout->addRow(tr(setting->GetUIName()), hbox);
|
2019-10-18 19:54:02 +00:00
|
|
|
}
|
2017-05-20 15:53:17 +00:00
|
|
|
}
|
2022-05-20 03:47:30 +00:00
|
|
|
}
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2022-05-20 03:47:30 +00:00
|
|
|
void MappingWidget::ShowAdvancedControlGroupDialog(ControllerEmu::ControlGroup* group)
|
|
|
|
{
|
|
|
|
QDialog dialog{this};
|
|
|
|
dialog.setWindowTitle(tr(group->ui_name.c_str()));
|
2019-10-30 01:05:42 +00:00
|
|
|
|
2022-05-20 03:47:30 +00:00
|
|
|
const auto group_box = new QGroupBox(tr("Advanced Settings"));
|
|
|
|
|
|
|
|
QFormLayout* form_layout = new QFormLayout();
|
|
|
|
|
|
|
|
AddSettingWidgets(form_layout, group, ControllerEmu::SettingVisibility::Advanced);
|
|
|
|
|
|
|
|
const auto reset_button = new QPushButton(tr("Reset All"));
|
|
|
|
form_layout->addRow(reset_button);
|
|
|
|
|
|
|
|
connect(reset_button, &QPushButton::clicked, [this, group] {
|
|
|
|
for (auto& setting : group->numeric_settings)
|
|
|
|
{
|
|
|
|
if (setting->GetVisibility() != ControllerEmu::SettingVisibility::Advanced)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
setting->SetToDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
emit ConfigChanged();
|
|
|
|
});
|
|
|
|
|
|
|
|
const auto main_layout = new QVBoxLayout();
|
|
|
|
const auto button_box = new QDialogButtonBox(QDialogButtonBox::Close);
|
|
|
|
|
|
|
|
group_box->setLayout(form_layout);
|
|
|
|
|
|
|
|
main_layout->addWidget(group_box);
|
|
|
|
main_layout->addWidget(button_box);
|
|
|
|
|
|
|
|
dialog.setLayout(main_layout);
|
|
|
|
|
|
|
|
// Focusing something else by default instead of the first spin box.
|
|
|
|
// Dynamically changing expression-backed settings pause when taking input.
|
|
|
|
// This just avoids that weird edge case behavior when the dialog is first open.
|
|
|
|
button_box->setFocus();
|
|
|
|
|
|
|
|
// Signal the newly created numeric setting widgets to display the current values.
|
|
|
|
emit ConfigChanged();
|
|
|
|
|
|
|
|
// Enable "Close" button functionality.
|
|
|
|
connect(button_box, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
|
|
|
|
|
|
|
|
dialog.exec();
|
2017-05-20 15:53:17 +00:00
|
|
|
}
|
|
|
|
|
2021-07-04 10:56:07 +00:00
|
|
|
QGroupBox* MappingWidget::CreateControlsBox(const QString& name, ControllerEmu::ControlGroup* group,
|
|
|
|
int columns)
|
|
|
|
{
|
|
|
|
auto* group_box = new QGroupBox(name);
|
|
|
|
auto* hbox_layout = new QHBoxLayout();
|
|
|
|
|
|
|
|
group_box->setLayout(hbox_layout);
|
|
|
|
|
|
|
|
std::vector<QFormLayout*> form_layouts;
|
|
|
|
for (int i = 0; i < columns; ++i)
|
|
|
|
{
|
|
|
|
form_layouts.push_back(new QFormLayout());
|
|
|
|
hbox_layout->addLayout(form_layouts[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < group->controls.size(); ++i)
|
|
|
|
{
|
|
|
|
CreateControl(group->controls[i].get(), form_layouts[i % columns], true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return group_box;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingWidget::CreateControl(const ControllerEmu::Control* control, QFormLayout* layout,
|
|
|
|
bool indicator)
|
|
|
|
{
|
|
|
|
auto* button = new MappingButton(this, control->control_ref.get(), indicator);
|
|
|
|
|
|
|
|
button->setMinimumWidth(100);
|
|
|
|
button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
const bool translate = control->translate == ControllerEmu::Translate;
|
|
|
|
const QString translated_name =
|
|
|
|
translate ? tr(control->ui_name.c_str()) : QString::fromStdString(control->ui_name);
|
|
|
|
layout->addRow(translated_name, button);
|
|
|
|
}
|
|
|
|
|
2017-06-13 15:16:41 +00:00
|
|
|
ControllerEmu::EmulatedController* MappingWidget::GetController() const
|
|
|
|
{
|
|
|
|
return m_parent->GetController();
|
|
|
|
}
|
2020-01-18 17:19:32 +00:00
|
|
|
|
|
|
|
QPushButton*
|
|
|
|
MappingWidget::CreateSettingAdvancedMappingButton(ControllerEmu::NumericSettingBase& setting)
|
|
|
|
{
|
|
|
|
const auto button = new QPushButton(tr("..."));
|
|
|
|
button->setFixedWidth(QFontMetrics(font()).boundingRect(button->text()).width() * 2);
|
|
|
|
|
|
|
|
button->connect(button, &QPushButton::clicked, [this, &setting]() {
|
|
|
|
if (setting.IsSimpleValue())
|
|
|
|
setting.SetExpressionFromValue();
|
|
|
|
|
|
|
|
IOWindow io(this, GetController(), &setting.GetInputReference(), IOWindow::Type::Input);
|
|
|
|
io.exec();
|
|
|
|
|
|
|
|
setting.SimplifyIfPossible();
|
|
|
|
|
|
|
|
ConfigChanged();
|
|
|
|
SaveSettings();
|
|
|
|
});
|
|
|
|
|
|
|
|
return button;
|
|
|
|
}
|