2021-01-23 18:44:21 +00:00
|
|
|
// Copyright 2021 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-01-23 18:44:21 +00:00
|
|
|
|
|
|
|
#include "DolphinQt/Config/GamecubeControllersWidget.h"
|
|
|
|
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
#include <optional>
|
2021-07-04 11:17:32 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2021-01-23 18:44:21 +00:00
|
|
|
|
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/HW/SI/SI.h"
|
|
|
|
#include "Core/HW/SI/SI_Device.h"
|
|
|
|
|
|
|
|
#include "DolphinQt/Config/Mapping/GCPadWiiUConfigDialog.h"
|
|
|
|
#include "DolphinQt/Config/Mapping/MappingWindow.h"
|
2022-03-08 07:51:29 +00:00
|
|
|
#include "DolphinQt/QtUtils/NonDefaultQPushButton.h"
|
2022-09-20 03:01:49 +00:00
|
|
|
#include "DolphinQt/QtUtils/SignalBlocking.h"
|
2021-01-23 18:44:21 +00:00
|
|
|
#include "DolphinQt/Settings.h"
|
|
|
|
|
|
|
|
#include "InputCommon/GCAdapter.h"
|
|
|
|
|
2022-09-20 03:01:49 +00:00
|
|
|
using SIDeviceName = std::pair<SerialInterface::SIDevices, const char*>;
|
|
|
|
static constexpr std::array s_gc_types = {
|
|
|
|
SIDeviceName{SerialInterface::SIDEVICE_NONE, _trans("None")},
|
|
|
|
SIDeviceName{SerialInterface::SIDEVICE_GC_CONTROLLER, _trans("Standard Controller")},
|
|
|
|
SIDeviceName{SerialInterface::SIDEVICE_WIIU_ADAPTER, _trans("GameCube Adapter for Wii U")},
|
|
|
|
SIDeviceName{SerialInterface::SIDEVICE_GC_STEERING, _trans("Steering Wheel")},
|
|
|
|
SIDeviceName{SerialInterface::SIDEVICE_DANCEMAT, _trans("Dance Mat")},
|
|
|
|
SIDeviceName{SerialInterface::SIDEVICE_GC_TARUKONGA, _trans("DK Bongos")},
|
2021-07-04 11:17:32 +00:00
|
|
|
#ifdef HAS_LIBMGBA
|
2022-09-20 03:01:49 +00:00
|
|
|
SIDeviceName{SerialInterface::SIDEVICE_GC_GBA_EMULATED, _trans("GBA (Integrated)")},
|
2021-07-04 11:17:32 +00:00
|
|
|
#endif
|
2022-09-20 03:01:49 +00:00
|
|
|
SIDeviceName{SerialInterface::SIDEVICE_GC_GBA, _trans("GBA (TCP)")},
|
|
|
|
SIDeviceName{SerialInterface::SIDEVICE_GC_KEYBOARD, _trans("Keyboard")},
|
|
|
|
};
|
2021-01-23 18:44:21 +00:00
|
|
|
|
|
|
|
static std::optional<int> ToGCMenuIndex(const SerialInterface::SIDevices sidevice)
|
|
|
|
{
|
2021-07-04 11:17:32 +00:00
|
|
|
for (size_t i = 0; i < s_gc_types.size(); ++i)
|
|
|
|
{
|
|
|
|
if (s_gc_types[i].first == sidevice)
|
|
|
|
return static_cast<int>(i);
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
static SerialInterface::SIDevices FromGCMenuIndex(const int menudevice)
|
|
|
|
{
|
|
|
|
return s_gc_types[menudevice].first;
|
2021-01-23 18:44:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GamecubeControllersWidget::GamecubeControllersWidget(QWidget* parent) : QWidget(parent)
|
|
|
|
{
|
|
|
|
CreateLayout();
|
|
|
|
LoadSettings();
|
|
|
|
ConnectWidgets();
|
2022-09-20 03:01:49 +00:00
|
|
|
|
|
|
|
connect(&Settings::Instance(), &Settings::ConfigChanged, this,
|
|
|
|
&GamecubeControllersWidget::LoadSettings);
|
2021-01-23 18:44:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GamecubeControllersWidget::CreateLayout()
|
|
|
|
{
|
|
|
|
m_gc_box = new QGroupBox(tr("GameCube Controllers"));
|
|
|
|
m_gc_layout = new QGridLayout();
|
|
|
|
m_gc_layout->setVerticalSpacing(7);
|
|
|
|
m_gc_layout->setColumnStretch(1, 1);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < m_gc_groups.size(); i++)
|
|
|
|
{
|
|
|
|
auto* gc_label = new QLabel(tr("Port %1").arg(i + 1));
|
|
|
|
auto* gc_box = m_gc_controller_boxes[i] = new QComboBox();
|
2022-03-08 07:51:29 +00:00
|
|
|
auto* gc_button = m_gc_buttons[i] = new NonDefaultQPushButton(tr("Configure"));
|
2021-01-23 18:44:21 +00:00
|
|
|
|
2021-07-04 11:17:32 +00:00
|
|
|
for (const auto& item : s_gc_types)
|
2021-01-23 18:44:21 +00:00
|
|
|
{
|
2021-07-04 11:17:32 +00:00
|
|
|
gc_box->addItem(tr(item.second));
|
2021-01-23 18:44:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int controller_row = m_gc_layout->rowCount();
|
|
|
|
m_gc_layout->addWidget(gc_label, controller_row, 0);
|
|
|
|
m_gc_layout->addWidget(gc_box, controller_row, 1);
|
|
|
|
m_gc_layout->addWidget(gc_button, controller_row, 2);
|
|
|
|
}
|
|
|
|
m_gc_box->setLayout(m_gc_layout);
|
|
|
|
|
|
|
|
auto* layout = new QVBoxLayout;
|
2021-04-25 00:18:28 +00:00
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
2021-01-23 18:44:21 +00:00
|
|
|
layout->setAlignment(Qt::AlignTop);
|
|
|
|
layout->addWidget(m_gc_box);
|
|
|
|
setLayout(layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GamecubeControllersWidget::ConnectWidgets()
|
|
|
|
{
|
2022-09-20 03:01:49 +00:00
|
|
|
for (size_t i = 0; i < m_gc_controller_boxes.size(); ++i)
|
2021-01-23 18:44:21 +00:00
|
|
|
{
|
|
|
|
connect(m_gc_controller_boxes[i], qOverload<int>(&QComboBox::currentIndexChanged), this,
|
2022-09-20 03:01:49 +00:00
|
|
|
[this, i] {
|
|
|
|
OnGCTypeChanged(i);
|
|
|
|
SaveSettings();
|
|
|
|
});
|
|
|
|
connect(m_gc_buttons[i], &QPushButton::clicked, this, [this, i] { OnGCPadConfigure(i); });
|
2021-01-23 18:44:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-20 03:01:49 +00:00
|
|
|
void GamecubeControllersWidget::OnGCTypeChanged(size_t index)
|
2021-01-23 18:44:21 +00:00
|
|
|
{
|
2022-09-20 03:01:49 +00:00
|
|
|
const SerialInterface::SIDevices si_device =
|
|
|
|
FromGCMenuIndex(m_gc_controller_boxes[index]->currentIndex());
|
|
|
|
m_gc_buttons[index]->setEnabled(si_device != SerialInterface::SIDEVICE_NONE &&
|
|
|
|
si_device != SerialInterface::SIDEVICE_GC_GBA);
|
2021-01-23 18:44:21 +00:00
|
|
|
}
|
|
|
|
|
2022-09-20 03:01:49 +00:00
|
|
|
void GamecubeControllersWidget::OnGCPadConfigure(size_t index)
|
2021-01-23 18:44:21 +00:00
|
|
|
{
|
|
|
|
MappingWindow::Type type;
|
|
|
|
|
2021-07-04 11:17:32 +00:00
|
|
|
switch (FromGCMenuIndex(m_gc_controller_boxes[index]->currentIndex()))
|
2021-01-23 18:44:21 +00:00
|
|
|
{
|
2021-07-04 11:17:32 +00:00
|
|
|
case SerialInterface::SIDEVICE_NONE:
|
|
|
|
case SerialInterface::SIDEVICE_GC_GBA:
|
2021-01-23 18:44:21 +00:00
|
|
|
return;
|
2021-07-04 11:17:32 +00:00
|
|
|
case SerialInterface::SIDEVICE_GC_CONTROLLER:
|
2021-01-23 18:44:21 +00:00
|
|
|
type = MappingWindow::Type::MAPPING_GCPAD;
|
|
|
|
break;
|
2021-07-04 11:17:32 +00:00
|
|
|
case SerialInterface::SIDEVICE_WIIU_ADAPTER:
|
2021-01-23 18:44:21 +00:00
|
|
|
GCPadWiiUConfigDialog(static_cast<int>(index), this).exec();
|
|
|
|
return;
|
2021-07-04 11:17:32 +00:00
|
|
|
case SerialInterface::SIDEVICE_GC_STEERING:
|
2021-01-23 18:44:21 +00:00
|
|
|
type = MappingWindow::Type::MAPPING_GC_STEERINGWHEEL;
|
|
|
|
break;
|
2021-07-04 11:17:32 +00:00
|
|
|
case SerialInterface::SIDEVICE_DANCEMAT:
|
2021-01-23 18:44:21 +00:00
|
|
|
type = MappingWindow::Type::MAPPING_GC_DANCEMAT;
|
|
|
|
break;
|
2021-07-04 11:17:32 +00:00
|
|
|
case SerialInterface::SIDEVICE_GC_TARUKONGA:
|
2021-01-23 18:44:21 +00:00
|
|
|
type = MappingWindow::Type::MAPPING_GC_BONGOS;
|
|
|
|
break;
|
2021-07-04 11:17:32 +00:00
|
|
|
case SerialInterface::SIDEVICE_GC_GBA_EMULATED:
|
|
|
|
type = MappingWindow::Type::MAPPING_GC_GBA;
|
|
|
|
break;
|
|
|
|
case SerialInterface::SIDEVICE_GC_KEYBOARD:
|
2021-01-23 18:44:21 +00:00
|
|
|
type = MappingWindow::Type::MAPPING_GC_KEYBOARD;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MappingWindow* window = new MappingWindow(this, type, static_cast<int>(index));
|
|
|
|
window->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
window->setWindowModality(Qt::WindowModality::WindowModal);
|
|
|
|
window->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GamecubeControllersWidget::LoadSettings()
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < m_gc_groups.size(); i++)
|
|
|
|
{
|
2022-01-06 07:08:02 +00:00
|
|
|
const SerialInterface::SIDevices si_device =
|
|
|
|
Config::Get(Config::GetInfoForSIDevice(static_cast<int>(i)));
|
2021-07-04 11:17:32 +00:00
|
|
|
const std::optional<int> gc_index = ToGCMenuIndex(si_device);
|
2021-01-23 18:44:21 +00:00
|
|
|
if (gc_index)
|
|
|
|
{
|
2022-09-20 03:01:49 +00:00
|
|
|
SignalBlocking(m_gc_controller_boxes[i])->setCurrentIndex(*gc_index);
|
|
|
|
OnGCTypeChanged(i);
|
2021-01-23 18:44:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GamecubeControllersWidget::SaveSettings()
|
|
|
|
{
|
|
|
|
{
|
2022-09-20 03:01:49 +00:00
|
|
|
Config::ConfigChangeCallbackGuard config_guard;
|
2021-01-23 18:44:21 +00:00
|
|
|
|
2022-09-20 03:01:49 +00:00
|
|
|
for (size_t i = 0; i < m_gc_groups.size(); ++i)
|
|
|
|
{
|
|
|
|
const SerialInterface::SIDevices si_device =
|
|
|
|
FromGCMenuIndex(m_gc_controller_boxes[i]->currentIndex());
|
|
|
|
Config::SetBaseOrCurrent(Config::GetInfoForSIDevice(static_cast<int>(i)), si_device);
|
2021-01-23 18:44:21 +00:00
|
|
|
|
2022-09-20 03:01:49 +00:00
|
|
|
if (Core::IsRunning())
|
|
|
|
SerialInterface::ChangeDevice(si_device, static_cast<s32>(i));
|
|
|
|
}
|
2021-01-23 18:44:21 +00:00
|
|
|
|
2022-09-20 03:01:49 +00:00
|
|
|
if (GCAdapter::UseAdapter())
|
|
|
|
GCAdapter::StartScanThread();
|
|
|
|
else
|
|
|
|
GCAdapter::StopScanThread();
|
|
|
|
}
|
2021-01-23 18:44:21 +00:00
|
|
|
|
|
|
|
SConfig::GetInstance().SaveSettings();
|
|
|
|
}
|