2017-05-20 15:53:17 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Config/Mapping/MappingWidget.h"
|
2018-05-28 01:48:04 +00:00
|
|
|
|
2017-05-20 15:53:17 +00:00
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QPushButton>
|
2019-03-15 01:27:49 +00:00
|
|
|
#include <QTimer>
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Config/Mapping/IOWindow.h"
|
|
|
|
#include "DolphinQt/Config/Mapping/MappingButton.h"
|
|
|
|
#include "DolphinQt/Config/Mapping/MappingIndicator.h"
|
|
|
|
#include "DolphinQt/Config/Mapping/MappingNumeric.h"
|
|
|
|
#include "DolphinQt/Config/Mapping/MappingWindow.h"
|
2019-03-15 01:27:49 +00:00
|
|
|
#include "DolphinQt/Settings.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"
|
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);
|
|
|
|
|
|
|
|
const auto timer = new QTimer(this);
|
|
|
|
connect(timer, &QTimer::timeout, this, [this] {
|
|
|
|
// TODO: The SetControllerStateNeeded interface leaks input into the game.
|
|
|
|
const auto lock = m_parent->GetController()->GetStateLock();
|
|
|
|
Settings::Instance().SetControllerStateNeeded(true);
|
|
|
|
emit Update();
|
|
|
|
Settings::Instance().SetControllerStateNeeded(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
timer->start(1000 / INDICATOR_UPDATE_FREQ);
|
2017-05-20 15:53:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MappingWindow* MappingWidget::GetParent() const
|
|
|
|
{
|
|
|
|
return m_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MappingWidget::GetPort() const
|
|
|
|
{
|
|
|
|
return m_parent->GetPort();
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-02-05 00:50:07 +00:00
|
|
|
const bool need_indicator = group->type == ControllerEmu::GroupType::Cursor ||
|
|
|
|
group->type == ControllerEmu::GroupType::Stick ||
|
|
|
|
group->type == ControllerEmu::GroupType::Tilt ||
|
2019-01-29 20:39:14 +00:00
|
|
|
group->type == ControllerEmu::GroupType::MixedTriggers ||
|
2019-03-29 19:39:48 +00:00
|
|
|
group->type == ControllerEmu::GroupType::Force ||
|
|
|
|
group->type == ControllerEmu::GroupType::Shake;
|
2019-02-05 00:50:07 +00:00
|
|
|
|
|
|
|
const bool need_calibration = group->type == ControllerEmu::GroupType::Cursor ||
|
|
|
|
group->type == ControllerEmu::GroupType::Stick ||
|
2019-01-29 20:39:14 +00:00
|
|
|
group->type == ControllerEmu::GroupType::Tilt ||
|
|
|
|
group->type == ControllerEmu::GroupType::Force;
|
2018-02-06 10:00:23 +00:00
|
|
|
|
2019-04-27 19:23:29 +00:00
|
|
|
if (need_indicator)
|
|
|
|
{
|
|
|
|
MappingIndicator* indicator;
|
|
|
|
|
|
|
|
switch (group->type)
|
|
|
|
{
|
|
|
|
case ControllerEmu::GroupType::Shake:
|
|
|
|
indicator = new ShakeMappingIndicator(static_cast<ControllerEmu::Shake*>(group));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
indicator = new MappingIndicator(group);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
form_layout->addRow(indicator);
|
|
|
|
|
|
|
|
connect(this, &MappingWidget::Update, indicator, QOverload<>::of(&MappingIndicator::update));
|
|
|
|
|
|
|
|
if (need_calibration)
|
|
|
|
{
|
|
|
|
const auto calibrate =
|
|
|
|
new CalibrationWidget(*static_cast<ControllerEmu::ReshapableInput*>(group), *indicator);
|
|
|
|
|
|
|
|
form_layout->addRow(calibrate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:53:17 +00:00
|
|
|
for (auto& control : group->controls)
|
|
|
|
{
|
2018-02-06 10:00:23 +00:00
|
|
|
auto* button = new MappingButton(this, control->control_ref.get(), !need_indicator);
|
2017-06-13 15:16:41 +00:00
|
|
|
|
2017-06-14 04:24:24 +00:00
|
|
|
button->setMinimumWidth(100);
|
2017-05-20 15:53:17 +00:00
|
|
|
button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
2018-04-10 15:22:30 +00:00
|
|
|
const bool translate = control->translate == ControllerEmu::Translate;
|
|
|
|
const QString translated_name =
|
|
|
|
translate ? tr(control->ui_name.c_str()) : QString::fromStdString(control->ui_name);
|
2018-03-30 19:42:26 +00:00
|
|
|
form_layout->addRow(translated_name, button);
|
2017-06-13 15:16:41 +00:00
|
|
|
|
2017-05-20 15:53:17 +00:00
|
|
|
m_buttons.push_back(button);
|
|
|
|
}
|
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
for (auto& setting : group->numeric_settings)
|
2017-05-20 15:53:17 +00:00
|
|
|
{
|
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;
|
|
|
|
}
|
2018-07-02 13:16:43 +00:00
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
if (setting_widget)
|
|
|
|
form_layout->addRow(tr(setting->GetUIName()), setting_widget);
|
2017-05-20 15:53:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return group_box;
|
|
|
|
}
|
|
|
|
|
2017-06-13 15:16:41 +00:00
|
|
|
ControllerEmu::EmulatedController* MappingWidget::GetController() const
|
|
|
|
{
|
|
|
|
return m_parent->GetController();
|
|
|
|
}
|