diff --git a/Source/Core/DolphinQt/CMakeLists.txt b/Source/Core/DolphinQt/CMakeLists.txt index 9ae4714317..004eb2b86f 100644 --- a/Source/Core/DolphinQt/CMakeLists.txt +++ b/Source/Core/DolphinQt/CMakeLists.txt @@ -124,6 +124,8 @@ add_executable(dolphin-emu Config/Mapping/FreeLookGeneral.h Config/Mapping/FreeLookRotation.cpp Config/Mapping/FreeLookRotation.h + Config/Mapping/GBAPadEmu.cpp + Config/Mapping/GBAPadEmu.h Config/Mapping/GCKeyboardEmu.cpp Config/Mapping/GCKeyboardEmu.h Config/Mapping/GCMicrophone.cpp diff --git a/Source/Core/DolphinQt/Config/GamecubeControllersWidget.cpp b/Source/Core/DolphinQt/Config/GamecubeControllersWidget.cpp index 9a9fdd2be0..d940f46461 100644 --- a/Source/Core/DolphinQt/Config/GamecubeControllersWidget.cpp +++ b/Source/Core/DolphinQt/Config/GamecubeControllersWidget.cpp @@ -10,8 +10,9 @@ #include #include -#include #include +#include +#include #include "Core/ConfigManager.h" #include "Core/Core.h" @@ -24,23 +25,37 @@ #include "InputCommon/GCAdapter.h" -static const std::map s_gc_types = { - {SerialInterface::SIDEVICE_NONE, 0}, {SerialInterface::SIDEVICE_GC_CONTROLLER, 1}, - {SerialInterface::SIDEVICE_WIIU_ADAPTER, 2}, {SerialInterface::SIDEVICE_GC_STEERING, 3}, - {SerialInterface::SIDEVICE_DANCEMAT, 4}, {SerialInterface::SIDEVICE_GC_TARUKONGA, 5}, - {SerialInterface::SIDEVICE_GC_GBA, 6}, {SerialInterface::SIDEVICE_GC_KEYBOARD, 7}}; +static const std::vector> s_gc_types = { + {SerialInterface::SIDEVICE_NONE, _trans("None")}, + {SerialInterface::SIDEVICE_GC_CONTROLLER, _trans("Standard Controller")}, + {SerialInterface::SIDEVICE_WIIU_ADAPTER, _trans("GameCube Adapter for Wii U")}, + {SerialInterface::SIDEVICE_GC_STEERING, _trans("Steering Wheel")}, + {SerialInterface::SIDEVICE_DANCEMAT, _trans("Dance Mat")}, + {SerialInterface::SIDEVICE_GC_TARUKONGA, _trans("DK Bongos")}, +#ifdef HAS_LIBMGBA + {SerialInterface::SIDEVICE_GC_GBA_EMULATED, _trans("GBA (Integrated)")}, +#endif + {SerialInterface::SIDEVICE_GC_GBA, _trans("GBA (TCP)")}, + {SerialInterface::SIDEVICE_GC_KEYBOARD, _trans("Keyboard")}}; static std::optional ToGCMenuIndex(const SerialInterface::SIDevices sidevice) { - auto it = s_gc_types.find(sidevice); - return it != s_gc_types.end() ? it->second : std::optional(); + for (size_t i = 0; i < s_gc_types.size(); ++i) + { + if (s_gc_types[i].first == sidevice) + return static_cast(i); + } + return {}; } -static std::optional FromGCMenuIndex(const int menudevice) +static SerialInterface::SIDevices FromGCMenuIndex(const int menudevice) { - auto it = std::find_if(s_gc_types.begin(), s_gc_types.end(), - [=](auto pair) { return pair.second == menudevice; }); - return it != s_gc_types.end() ? it->first : std::optional(); + return s_gc_types[menudevice].first; +} + +static bool IsConfigurable(SerialInterface::SIDevices sidevice) +{ + return sidevice != SerialInterface::SIDEVICE_NONE && sidevice != SerialInterface::SIDEVICE_GC_GBA; } GamecubeControllersWidget::GamecubeControllersWidget(QWidget* parent) : QWidget(parent) @@ -63,11 +78,9 @@ void GamecubeControllersWidget::CreateLayout() auto* gc_box = m_gc_controller_boxes[i] = new QComboBox(); auto* gc_button = m_gc_buttons[i] = new QPushButton(tr("Configure")); - for (const auto& item : - {tr("None"), tr("Standard Controller"), tr("GameCube Adapter for Wii U"), - tr("Steering Wheel"), tr("Dance Mat"), tr("DK Bongos"), tr("GBA"), tr("Keyboard")}) + for (const auto& item : s_gc_types) { - gc_box->addItem(item); + gc_box->addItem(tr(item.second)); } int controller_row = m_gc_layout->rowCount(); @@ -105,8 +118,8 @@ void GamecubeControllersWidget::OnGCTypeChanged(int type) { if (m_gc_controller_boxes[i] == box) { - const int index = box->currentIndex(); - m_gc_buttons[i]->setEnabled(index != 0 && index != 6); + const SerialInterface::SIDevices si_device = FromGCMenuIndex(box->currentIndex()); + m_gc_buttons[i]->setEnabled(IsConfigurable(si_device)); return; } } @@ -125,27 +138,30 @@ void GamecubeControllersWidget::OnGCPadConfigure() MappingWindow::Type type; - switch (m_gc_controller_boxes[index]->currentIndex()) + switch (FromGCMenuIndex(m_gc_controller_boxes[index]->currentIndex())) { - case 0: // None - case 6: // GBA + case SerialInterface::SIDEVICE_NONE: + case SerialInterface::SIDEVICE_GC_GBA: return; - case 1: // Standard Controller + case SerialInterface::SIDEVICE_GC_CONTROLLER: type = MappingWindow::Type::MAPPING_GCPAD; break; - case 2: // GameCube Adapter for Wii U + case SerialInterface::SIDEVICE_WIIU_ADAPTER: GCPadWiiUConfigDialog(static_cast(index), this).exec(); return; - case 3: // Steering Wheel + case SerialInterface::SIDEVICE_GC_STEERING: type = MappingWindow::Type::MAPPING_GC_STEERINGWHEEL; break; - case 4: // Dance Mat + case SerialInterface::SIDEVICE_DANCEMAT: type = MappingWindow::Type::MAPPING_GC_DANCEMAT; break; - case 5: // DK Bongos + case SerialInterface::SIDEVICE_GC_TARUKONGA: type = MappingWindow::Type::MAPPING_GC_BONGOS; break; - case 7: // Keyboard + case SerialInterface::SIDEVICE_GC_GBA_EMULATED: + type = MappingWindow::Type::MAPPING_GC_GBA; + break; + case SerialInterface::SIDEVICE_GC_KEYBOARD: type = MappingWindow::Type::MAPPING_GC_KEYBOARD; break; default: @@ -162,11 +178,12 @@ void GamecubeControllersWidget::LoadSettings() { for (size_t i = 0; i < m_gc_groups.size(); i++) { - const std::optional gc_index = ToGCMenuIndex(SConfig::GetInstance().m_SIDevice[i]); + const SerialInterface::SIDevices si_device = SConfig::GetInstance().m_SIDevice[i]; + const std::optional gc_index = ToGCMenuIndex(si_device); if (gc_index) { m_gc_controller_boxes[i]->setCurrentIndex(*gc_index); - m_gc_buttons[i]->setEnabled(*gc_index != 0 && *gc_index != 6); + m_gc_buttons[i]->setEnabled(IsConfigurable(si_device)); } } } @@ -176,16 +193,13 @@ void GamecubeControllersWidget::SaveSettings() for (size_t i = 0; i < m_gc_groups.size(); i++) { const int index = m_gc_controller_boxes[i]->currentIndex(); - const std::optional si_device = FromGCMenuIndex(index); - if (si_device) - { - SConfig::GetInstance().m_SIDevice[i] = *si_device; + const SerialInterface::SIDevices si_device = FromGCMenuIndex(index); + SConfig::GetInstance().m_SIDevice[i] = si_device; - if (Core::IsRunning()) - SerialInterface::ChangeDevice(*si_device, static_cast(i)); - } + if (Core::IsRunning()) + SerialInterface::ChangeDevice(si_device, static_cast(i)); - m_gc_buttons[i]->setEnabled(index != 0 && index != 6); + m_gc_buttons[i]->setEnabled(IsConfigurable(si_device)); } if (GCAdapter::UseAdapter()) diff --git a/Source/Core/DolphinQt/Config/Mapping/GBAPadEmu.cpp b/Source/Core/DolphinQt/Config/Mapping/GBAPadEmu.cpp new file mode 100644 index 0000000000..648d5aec64 --- /dev/null +++ b/Source/Core/DolphinQt/Config/Mapping/GBAPadEmu.cpp @@ -0,0 +1,45 @@ +// Copyright 2021 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "DolphinQt/Config/Mapping/GBAPadEmu.h" + +#include +#include + +#include "Core/HW/GBAPad.h" +#include "Core/HW/GBAPadEmu.h" +#include "InputCommon/InputConfig.h" + +GBAPadEmu::GBAPadEmu(MappingWindow* window) : MappingWidget(window) +{ + CreateMainLayout(); +} + +void GBAPadEmu::CreateMainLayout() +{ + auto* layout = new QGridLayout; + + layout->addWidget( + CreateControlsBox(tr("D-Pad"), Pad::GetGBAGroup(GetPort(), GBAPadGroup::DPad), 2), 0, 0, -1, + 1); + layout->addWidget( + CreateControlsBox(tr("Buttons"), Pad::GetGBAGroup(GetPort(), GBAPadGroup::Buttons), 2), 0, 1, + -1, 1); + + setLayout(layout); +} + +void GBAPadEmu::LoadSettings() +{ + Pad::LoadGBAConfig(); +} + +void GBAPadEmu::SaveSettings() +{ + Pad::GetGBAConfig()->SaveConfig(); +} + +InputConfig* GBAPadEmu::GetConfig() +{ + return Pad::GetGBAConfig(); +} diff --git a/Source/Core/DolphinQt/Config/Mapping/GBAPadEmu.h b/Source/Core/DolphinQt/Config/Mapping/GBAPadEmu.h new file mode 100644 index 0000000000..5e06121c70 --- /dev/null +++ b/Source/Core/DolphinQt/Config/Mapping/GBAPadEmu.h @@ -0,0 +1,20 @@ +// Copyright 2021 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "DolphinQt/Config/Mapping/MappingWidget.h" + +class GBAPadEmu final : public MappingWidget +{ + Q_OBJECT +public: + explicit GBAPadEmu(MappingWindow* window); + + InputConfig* GetConfig() override; + +private: + void LoadSettings() override; + void SaveSettings() override; + void CreateMainLayout(); +}; diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingWindow.cpp b/Source/Core/DolphinQt/Config/Mapping/MappingWindow.cpp index 10bf604268..3191f42fd9 100644 --- a/Source/Core/DolphinQt/Config/Mapping/MappingWindow.cpp +++ b/Source/Core/DolphinQt/Config/Mapping/MappingWindow.cpp @@ -23,6 +23,7 @@ #include "DolphinQt/Config/Mapping/FreeLookGeneral.h" #include "DolphinQt/Config/Mapping/FreeLookRotation.h" +#include "DolphinQt/Config/Mapping/GBAPadEmu.h" #include "DolphinQt/Config/Mapping/GCKeyboardEmu.h" #include "DolphinQt/Config/Mapping/GCMicrophone.h" #include "DolphinQt/Config/Mapping/GCPadEmu.h" @@ -374,10 +375,15 @@ void MappingWindow::SetMappingType(MappingWindow::Type type) switch (type) { + case Type::MAPPING_GC_GBA: + widget = new GBAPadEmu(this); + setWindowTitle(tr("GameBoy Advance at Port %1").arg(GetPort() + 1)); + AddWidget(tr("GameBoy Advance"), widget); + break; case Type::MAPPING_GC_KEYBOARD: widget = new GCKeyboardEmu(this); - AddWidget(tr("GameCube Keyboard"), widget); setWindowTitle(tr("GameCube Keyboard at Port %1").arg(GetPort() + 1)); + AddWidget(tr("GameCube Keyboard"), widget); break; case Type::MAPPING_GC_BONGOS: case Type::MAPPING_GC_STEERINGWHEEL: diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingWindow.h b/Source/Core/DolphinQt/Config/Mapping/MappingWindow.h index 2724170397..493c07f72d 100644 --- a/Source/Core/DolphinQt/Config/Mapping/MappingWindow.h +++ b/Source/Core/DolphinQt/Config/Mapping/MappingWindow.h @@ -34,6 +34,7 @@ public: // GameCube MAPPING_GC_BONGOS, MAPPING_GC_DANCEMAT, + MAPPING_GC_GBA, MAPPING_GC_KEYBOARD, MAPPING_GCPAD, MAPPING_GC_STEERINGWHEEL, diff --git a/Source/Core/DolphinQt/DolphinQt.vcxproj b/Source/Core/DolphinQt/DolphinQt.vcxproj index 18a838896e..e8e3822cd1 100644 --- a/Source/Core/DolphinQt/DolphinQt.vcxproj +++ b/Source/Core/DolphinQt/DolphinQt.vcxproj @@ -81,6 +81,7 @@ + @@ -256,6 +257,7 @@ +