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/WiimoteEmuGeneral.h"
|
2018-05-28 01:48:04 +00:00
|
|
|
|
2017-05-20 15:53:17 +00:00
|
|
|
#include <QComboBox>
|
|
|
|
#include <QFormLayout>
|
2019-03-16 16:55:47 +00:00
|
|
|
#include <QGridLayout>
|
2017-05-20 15:53:17 +00:00
|
|
|
#include <QGroupBox>
|
2020-01-18 17:19:32 +00:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QPushButton>
|
2017-05-20 15:53:17 +00:00
|
|
|
|
|
|
|
#include "Core/HW/Wiimote.h"
|
|
|
|
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
2018-05-28 01:48:04 +00:00
|
|
|
|
2018-10-03 03:32:00 +00:00
|
|
|
#include "DolphinQt/Config/Mapping/MappingWindow.h"
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Config/Mapping/WiimoteEmuExtension.h"
|
2018-05-28 01:48:04 +00:00
|
|
|
|
2019-01-01 14:32:39 +00:00
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h"
|
2017-05-20 15:53:17 +00:00
|
|
|
#include "InputCommon/InputConfig.h"
|
|
|
|
|
|
|
|
WiimoteEmuGeneral::WiimoteEmuGeneral(MappingWindow* window, WiimoteEmuExtension* extension)
|
|
|
|
: MappingWidget(window), m_extension_widget(extension)
|
|
|
|
{
|
|
|
|
CreateMainLayout();
|
2020-01-18 17:19:32 +00:00
|
|
|
Connect();
|
2017-05-20 15:53:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WiimoteEmuGeneral::CreateMainLayout()
|
|
|
|
{
|
2019-03-16 16:55:47 +00:00
|
|
|
auto* layout = new QGridLayout;
|
|
|
|
|
|
|
|
layout->addWidget(
|
|
|
|
CreateGroupBox(tr("Buttons"),
|
|
|
|
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Buttons)),
|
|
|
|
0, 0, -1, 1);
|
|
|
|
layout->addWidget(CreateGroupBox(tr("D-Pad"), Wiimote::GetWiimoteGroup(
|
|
|
|
GetPort(), WiimoteEmu::WiimoteGroup::DPad)),
|
|
|
|
0, 1, -1, 1);
|
|
|
|
layout->addWidget(
|
|
|
|
CreateGroupBox(tr("Hotkeys"),
|
|
|
|
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Hotkeys)),
|
|
|
|
0, 2, -1, 1);
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2019-01-01 14:32:39 +00:00
|
|
|
auto* extension_group =
|
|
|
|
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments);
|
2017-05-20 15:53:17 +00:00
|
|
|
auto* extension = CreateGroupBox(tr("Extension"), extension_group);
|
2019-01-01 14:32:39 +00:00
|
|
|
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(extension_group);
|
2020-01-18 17:19:32 +00:00
|
|
|
|
|
|
|
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);
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2019-01-01 14:32:39 +00:00
|
|
|
for (const auto& attachment : ce_extension->GetAttachmentList())
|
2019-05-01 22:25:48 +00:00
|
|
|
m_extension_combo->addItem(tr(attachment->GetDisplayName().c_str()));
|
2017-05-20 15:53:17 +00:00
|
|
|
|
|
|
|
extension->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
2020-01-18 17:19:32 +00:00
|
|
|
static_cast<QFormLayout*>(extension->layout())->insertRow(0, combo_hbox);
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2019-03-16 16:55:47 +00:00
|
|
|
layout->addWidget(extension, 0, 3);
|
|
|
|
layout->addWidget(CreateGroupBox(tr("Rumble"), Wiimote::GetWiimoteGroup(
|
|
|
|
GetPort(), WiimoteEmu::WiimoteGroup::Rumble)),
|
|
|
|
1, 3);
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2019-03-16 16:55:47 +00:00
|
|
|
layout->addWidget(
|
|
|
|
CreateGroupBox(tr("Options"),
|
|
|
|
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Options)),
|
|
|
|
2, 3);
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2019-03-16 16:55:47 +00:00
|
|
|
setLayout(layout);
|
2017-05-20 15:53:17 +00:00
|
|
|
}
|
|
|
|
|
2020-01-18 17:19:32 +00:00
|
|
|
void WiimoteEmuGeneral::Connect()
|
2017-05-20 15:53:17 +00:00
|
|
|
{
|
2019-07-30 13:35:46 +00:00
|
|
|
connect(m_extension_combo, qOverload<int>(&QComboBox::currentIndexChanged), this,
|
2020-01-18 17:19:32 +00:00
|
|
|
&WiimoteEmuGeneral::OnAttachmentChanged);
|
2019-07-30 13:35:46 +00:00
|
|
|
connect(m_extension_combo, qOverload<int>(&QComboBox::activated), this,
|
2020-01-18 17:19:32 +00:00
|
|
|
&WiimoteEmuGeneral::OnAttachmentSelected);
|
|
|
|
connect(this, &MappingWidget::ConfigChanged, this, &WiimoteEmuGeneral::ConfigChanged);
|
|
|
|
connect(this, &MappingWidget::Update, this, &WiimoteEmuGeneral::Update);
|
2017-05-20 15:53:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WiimoteEmuGeneral::OnAttachmentChanged(int extension)
|
|
|
|
{
|
2019-11-04 03:19:33 +00:00
|
|
|
GetParent()->ShowExtensionMotionTabs(extension == WiimoteEmu::ExtensionNumber::NUNCHUK);
|
|
|
|
|
2019-04-27 15:51:57 +00:00
|
|
|
m_extension_widget->ChangeExtensionType(extension);
|
2020-01-18 17:19:32 +00:00
|
|
|
}
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2020-01-18 17:19:32 +00:00
|
|
|
void WiimoteEmuGeneral::OnAttachmentSelected(int extension)
|
|
|
|
{
|
2019-01-01 14:32:39 +00:00
|
|
|
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(
|
|
|
|
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments));
|
2020-01-18 17:19:32 +00:00
|
|
|
|
2019-01-01 14:32:39 +00:00
|
|
|
ce_extension->SetSelectedAttachment(extension);
|
2019-04-27 15:51:57 +00:00
|
|
|
|
2020-01-18 17:19:32 +00:00
|
|
|
ConfigChanged();
|
2017-05-20 15:53:17 +00:00
|
|
|
SaveSettings();
|
|
|
|
}
|
|
|
|
|
2019-04-27 15:51:57 +00:00
|
|
|
void WiimoteEmuGeneral::ConfigChanged()
|
2020-01-18 17:19:32 +00:00
|
|
|
{
|
|
|
|
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()
|
2017-05-20 15:53:17 +00:00
|
|
|
{
|
2019-01-01 14:32:39 +00:00
|
|
|
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(
|
|
|
|
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments));
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2019-01-01 14:32:39 +00:00
|
|
|
m_extension_combo->setCurrentIndex(ce_extension->GetSelectedAttachment());
|
2018-10-03 03:32:00 +00:00
|
|
|
}
|
2017-05-20 15:53:17 +00:00
|
|
|
|
2018-10-03 03:32:00 +00:00
|
|
|
void WiimoteEmuGeneral::LoadSettings()
|
|
|
|
{
|
2017-05-20 15:53:17 +00:00
|
|
|
Wiimote::LoadConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WiimoteEmuGeneral::SaveSettings()
|
|
|
|
{
|
|
|
|
Wiimote::GetConfig()->SaveConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
InputConfig* WiimoteEmuGeneral::GetConfig()
|
|
|
|
{
|
|
|
|
return Wiimote::GetConfig();
|
|
|
|
}
|