InputCommon: Allow Wii remote extension to be set with an input expression.

This commit is contained in:
Jordan Woyak
2020-01-18 11:19:32 -06:00
parent e8152b700f
commit 0a1634bedf
12 changed files with 172 additions and 64 deletions

View File

@ -8,6 +8,8 @@
#include <QFormLayout>
#include <QGridLayout>
#include <QGroupBox>
#include <QLabel>
#include <QPushButton>
#include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
@ -22,7 +24,7 @@ WiimoteEmuGeneral::WiimoteEmuGeneral(MappingWindow* window, WiimoteEmuExtension*
: MappingWidget(window), m_extension_widget(extension)
{
CreateMainLayout();
Connect(window);
Connect();
}
void WiimoteEmuGeneral::CreateMainLayout()
@ -45,14 +47,20 @@ void WiimoteEmuGeneral::CreateMainLayout()
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments);
auto* extension = CreateGroupBox(tr("Extension"), extension_group);
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(extension_group);
m_extension_combo = new QComboBox();
const auto combo_hbox = new QHBoxLayout;
combo_hbox->addWidget(m_extension_combo = new QComboBox());
combo_hbox->addWidget(m_extension_combo_dynamic_indicator = new QLabel(QString::fromUtf8("🎮")));
combo_hbox->addWidget(CreateSettingAdvancedMappingButton(ce_extension->GetSelectionSetting()));
m_extension_combo_dynamic_indicator->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Ignored);
for (const auto& attachment : ce_extension->GetAttachmentList())
m_extension_combo->addItem(tr(attachment->GetDisplayName().c_str()));
extension->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
static_cast<QFormLayout*>(extension->layout())->insertRow(0, m_extension_combo);
static_cast<QFormLayout*>(extension->layout())->insertRow(0, combo_hbox);
layout->addWidget(extension, 0, 3);
layout->addWidget(CreateGroupBox(tr("Rumble"), Wiimote::GetWiimoteGroup(
@ -67,11 +75,14 @@ void WiimoteEmuGeneral::CreateMainLayout()
setLayout(layout);
}
void WiimoteEmuGeneral::Connect(MappingWindow* window)
void WiimoteEmuGeneral::Connect()
{
connect(m_extension_combo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &WiimoteEmuGeneral::OnAttachmentChanged);
connect(window, &MappingWindow::ConfigChanged, this, &WiimoteEmuGeneral::ConfigChanged);
connect(m_extension_combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&WiimoteEmuGeneral::OnAttachmentChanged);
connect(m_extension_combo, QOverload<int>::of(&QComboBox::activated), this,
&WiimoteEmuGeneral::OnAttachmentSelected);
connect(this, &MappingWidget::ConfigChanged, this, &WiimoteEmuGeneral::ConfigChanged);
connect(this, &MappingWidget::Update, this, &WiimoteEmuGeneral::Update);
}
void WiimoteEmuGeneral::OnAttachmentChanged(int extension)
@ -79,15 +90,31 @@ void WiimoteEmuGeneral::OnAttachmentChanged(int extension)
GetParent()->ShowExtensionMotionTabs(extension == WiimoteEmu::ExtensionNumber::NUNCHUK);
m_extension_widget->ChangeExtensionType(extension);
}
void WiimoteEmuGeneral::OnAttachmentSelected(int extension)
{
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments));
ce_extension->SetSelectedAttachment(extension);
ConfigChanged();
SaveSettings();
}
void WiimoteEmuGeneral::ConfigChanged()
{
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments));
m_extension_combo->setCurrentIndex(ce_extension->GetSelectedAttachment());
m_extension_combo_dynamic_indicator->setVisible(
!ce_extension->GetSelectionSetting().IsSimpleValue());
}
void WiimoteEmuGeneral::Update()
{
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments));