dolphin/Source/Core/DolphinQt/Config/Mapping/WiimoteEmuGeneral.cpp

123 lines
4.1 KiB
C++
Raw Normal View History

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/WiimoteEmuGeneral.h"
2018-05-28 01:48:04 +00:00
2017-05-20 15:53:17 +00:00
#include <QComboBox>
#include <QFormLayout>
#include <QGridLayout>
2017-05-20 15:53:17 +00:00
#include <QGroupBox>
#include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
2018-05-28 01:48:04 +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
#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();
Connect(window);
2017-05-20 15:53:17 +00:00
}
void WiimoteEmuGeneral::CreateMainLayout()
{
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
auto* extension_group =
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments);
2017-05-20 15:53:17 +00:00
auto* extension = CreateGroupBox(tr("Extension"), extension_group);
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(extension_group);
2017-05-20 15:53:17 +00:00
m_extension_combo = new QComboBox();
for (const auto& attachment : ce_extension->GetAttachmentList())
2017-05-20 15:53:17 +00:00
{
// TODO: Figure out how to localize this
m_extension_combo->addItem(QString::fromStdString(attachment->GetName()));
}
extension->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
static_cast<QFormLayout*>(extension->layout())->addRow(m_extension_combo);
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
layout->addWidget(
CreateGroupBox(tr("Options"),
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Options)),
2, 3);
2017-05-20 15:53:17 +00:00
setLayout(layout);
2017-05-20 15:53:17 +00:00
}
void WiimoteEmuGeneral::Connect(MappingWindow* window)
2017-05-20 15:53:17 +00:00
{
connect(m_extension_combo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &WiimoteEmuGeneral::OnAttachmentChanged);
connect(window, &MappingWindow::Update, this, &WiimoteEmuGeneral::Update);
2017-05-20 15:53:17 +00:00
}
void WiimoteEmuGeneral::OnAttachmentChanged(int extension)
{
const QString value = m_extension_combo->currentText();
static const QMap<QString, WiimoteEmuExtension::Type> value_map = {
{QStringLiteral("None"), WiimoteEmuExtension::Type::NONE},
{QStringLiteral("Classic"), WiimoteEmuExtension::Type::CLASSIC_CONTROLLER},
{QStringLiteral("Drums"), WiimoteEmuExtension::Type::DRUMS},
{QStringLiteral("Guitar"), WiimoteEmuExtension::Type::GUITAR},
{QStringLiteral("Nunchuk"), WiimoteEmuExtension::Type::NUNCHUK},
{QStringLiteral("Turntable"), WiimoteEmuExtension::Type::TURNTABLE}};
m_extension_widget->ChangeExtensionType(value_map[value]);
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments));
ce_extension->SetSelectedAttachment(extension);
2017-05-20 15:53:17 +00:00
SaveSettings();
}
void WiimoteEmuGeneral::Update()
2017-05-20 15:53:17 +00:00
{
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments));
2017-05-20 15:53:17 +00:00
m_extension_combo->setCurrentIndex(ce_extension->GetSelectedAttachment());
}
2017-05-20 15:53:17 +00:00
void WiimoteEmuGeneral::LoadSettings()
{
Update();
2017-05-20 15:53:17 +00:00
Wiimote::LoadConfig();
}
void WiimoteEmuGeneral::SaveSettings()
{
Wiimote::GetConfig()->SaveConfig();
}
InputConfig* WiimoteEmuGeneral::GetConfig()
{
return Wiimote::GetConfig();
}