2017-05-20 15:53:17 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QPushButton>
|
|
|
|
|
|
|
|
#include "DolphinQt2/Config/Mapping/MappingWidget.h"
|
|
|
|
|
2017-06-13 15:16:41 +00:00
|
|
|
#include "DolphinQt2/Config/Mapping/IOWindow.h"
|
2017-05-20 15:53:17 +00:00
|
|
|
#include "DolphinQt2/Config/Mapping/MappingBool.h"
|
|
|
|
#include "DolphinQt2/Config/Mapping/MappingButton.h"
|
2018-02-07 17:16:15 +00:00
|
|
|
#include "DolphinQt2/Config/Mapping/MappingIndicator.h"
|
2017-05-20 15:53:17 +00:00
|
|
|
#include "DolphinQt2/Config/Mapping/MappingNumeric.h"
|
|
|
|
#include "DolphinQt2/Config/Mapping/MappingWindow.h"
|
|
|
|
#include "InputCommon/ControlReference/ControlReference.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Control/Control.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Setting/BooleanSetting.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
|
|
|
|
|
|
|
MappingWidget::MappingWidget(MappingWindow* window) : m_parent(window)
|
|
|
|
{
|
|
|
|
connect(window, &MappingWindow::ClearFields, this, &MappingWidget::OnClearFields);
|
|
|
|
connect(window, &MappingWindow::Update, this, &MappingWidget::Update);
|
|
|
|
}
|
|
|
|
|
|
|
|
MappingWindow* MappingWidget::GetParent() const
|
|
|
|
{
|
|
|
|
return m_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<ciface::Core::Device> MappingWidget::GetDevice() const
|
|
|
|
{
|
|
|
|
return m_parent->GetDevice();
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-02-06 10:00:23 +00:00
|
|
|
bool need_indicator = group->type == ControllerEmu::GroupType::Cursor ||
|
|
|
|
group->type == ControllerEmu::GroupType::Stick ||
|
2018-02-07 17:16:15 +00:00
|
|
|
group->type == ControllerEmu::GroupType::Tilt ||
|
|
|
|
group->type == ControllerEmu::GroupType::MixedTriggers;
|
2018-02-06 10:00:23 +00:00
|
|
|
|
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);
|
|
|
|
form_layout->addRow(QString::fromStdString(control->name), button);
|
2017-06-13 15:16:41 +00:00
|
|
|
|
|
|
|
auto* control_ref = control->control_ref.get();
|
|
|
|
|
2017-11-03 20:28:45 +00:00
|
|
|
connect(button, &MappingButton::AdvancedPressed, [this, button, control_ref] {
|
2017-06-13 15:16:41 +00:00
|
|
|
if (m_parent->GetDevice() == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
IOWindow io(this, m_parent->GetController(), control_ref,
|
|
|
|
control_ref->IsInput() ? IOWindow::Type::Input : IOWindow::Type::Output);
|
|
|
|
io.exec();
|
2017-11-03 20:28:45 +00:00
|
|
|
SaveSettings();
|
|
|
|
button->Update();
|
2017-06-13 15:16:41 +00:00
|
|
|
});
|
|
|
|
|
2017-05-20 15:53:17 +00:00
|
|
|
m_buttons.push_back(button);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& numeric : group->numeric_settings)
|
|
|
|
{
|
|
|
|
auto* spinbox = new MappingNumeric(this, numeric.get());
|
|
|
|
spinbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
form_layout->addRow(QString::fromStdString(numeric->m_name), spinbox);
|
|
|
|
m_numerics.push_back(spinbox);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& boolean : group->boolean_settings)
|
|
|
|
{
|
|
|
|
auto* checkbox = new MappingBool(this, boolean.get());
|
|
|
|
checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
form_layout->addRow(checkbox);
|
|
|
|
m_bools.push_back(checkbox);
|
|
|
|
}
|
|
|
|
|
2018-02-06 10:00:23 +00:00
|
|
|
if (need_indicator)
|
|
|
|
form_layout->addRow(new MappingIndicator(group));
|
|
|
|
|
2017-05-20 15:53:17 +00:00
|
|
|
return group_box;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingWidget::OnClearFields()
|
|
|
|
{
|
|
|
|
for (auto* button : m_buttons)
|
|
|
|
button->Clear();
|
2017-06-13 23:56:14 +00:00
|
|
|
|
|
|
|
for (auto* spinbox : m_numerics)
|
|
|
|
spinbox->Clear();
|
|
|
|
|
|
|
|
for (auto* checkbox : m_bools)
|
|
|
|
checkbox->Clear();
|
2017-05-20 15:53:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MappingWidget::Update()
|
|
|
|
{
|
|
|
|
for (auto* button : m_buttons)
|
|
|
|
button->Update();
|
|
|
|
|
|
|
|
for (auto* spinbox : m_numerics)
|
|
|
|
spinbox->Update();
|
|
|
|
|
2017-06-13 23:56:33 +00:00
|
|
|
for (auto* checkbox : m_bools)
|
2017-05-20 15:53:17 +00:00
|
|
|
checkbox->Update();
|
|
|
|
}
|
|
|
|
|
2017-06-13 15:16:41 +00:00
|
|
|
ControllerEmu::EmulatedController* MappingWidget::GetController() const
|
|
|
|
{
|
|
|
|
return m_parent->GetController();
|
|
|
|
}
|