mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-03-12 14:46:49 +01:00
Qt/GamecubeControllersWidget: Refresh GUI on settings change and refactor a bit.
This commit is contained in:
parent
019dc86b6f
commit
a5dbf6b60d
@ -22,22 +22,25 @@
|
|||||||
#include "DolphinQt/Config/Mapping/GCPadWiiUConfigDialog.h"
|
#include "DolphinQt/Config/Mapping/GCPadWiiUConfigDialog.h"
|
||||||
#include "DolphinQt/Config/Mapping/MappingWindow.h"
|
#include "DolphinQt/Config/Mapping/MappingWindow.h"
|
||||||
#include "DolphinQt/QtUtils/NonDefaultQPushButton.h"
|
#include "DolphinQt/QtUtils/NonDefaultQPushButton.h"
|
||||||
|
#include "DolphinQt/QtUtils/SignalBlocking.h"
|
||||||
#include "DolphinQt/Settings.h"
|
#include "DolphinQt/Settings.h"
|
||||||
|
|
||||||
#include "InputCommon/GCAdapter.h"
|
#include "InputCommon/GCAdapter.h"
|
||||||
|
|
||||||
static const std::vector<std::pair<SerialInterface::SIDevices, const char*>> s_gc_types = {
|
using SIDeviceName = std::pair<SerialInterface::SIDevices, const char*>;
|
||||||
{SerialInterface::SIDEVICE_NONE, _trans("None")},
|
static constexpr std::array s_gc_types = {
|
||||||
{SerialInterface::SIDEVICE_GC_CONTROLLER, _trans("Standard Controller")},
|
SIDeviceName{SerialInterface::SIDEVICE_NONE, _trans("None")},
|
||||||
{SerialInterface::SIDEVICE_WIIU_ADAPTER, _trans("GameCube Adapter for Wii U")},
|
SIDeviceName{SerialInterface::SIDEVICE_GC_CONTROLLER, _trans("Standard Controller")},
|
||||||
{SerialInterface::SIDEVICE_GC_STEERING, _trans("Steering Wheel")},
|
SIDeviceName{SerialInterface::SIDEVICE_WIIU_ADAPTER, _trans("GameCube Adapter for Wii U")},
|
||||||
{SerialInterface::SIDEVICE_DANCEMAT, _trans("Dance Mat")},
|
SIDeviceName{SerialInterface::SIDEVICE_GC_STEERING, _trans("Steering Wheel")},
|
||||||
{SerialInterface::SIDEVICE_GC_TARUKONGA, _trans("DK Bongos")},
|
SIDeviceName{SerialInterface::SIDEVICE_DANCEMAT, _trans("Dance Mat")},
|
||||||
|
SIDeviceName{SerialInterface::SIDEVICE_GC_TARUKONGA, _trans("DK Bongos")},
|
||||||
#ifdef HAS_LIBMGBA
|
#ifdef HAS_LIBMGBA
|
||||||
{SerialInterface::SIDEVICE_GC_GBA_EMULATED, _trans("GBA (Integrated)")},
|
SIDeviceName{SerialInterface::SIDEVICE_GC_GBA_EMULATED, _trans("GBA (Integrated)")},
|
||||||
#endif
|
#endif
|
||||||
{SerialInterface::SIDEVICE_GC_GBA, _trans("GBA (TCP)")},
|
SIDeviceName{SerialInterface::SIDEVICE_GC_GBA, _trans("GBA (TCP)")},
|
||||||
{SerialInterface::SIDEVICE_GC_KEYBOARD, _trans("Keyboard")}};
|
SIDeviceName{SerialInterface::SIDEVICE_GC_KEYBOARD, _trans("Keyboard")},
|
||||||
|
};
|
||||||
|
|
||||||
static std::optional<int> ToGCMenuIndex(const SerialInterface::SIDevices sidevice)
|
static std::optional<int> ToGCMenuIndex(const SerialInterface::SIDevices sidevice)
|
||||||
{
|
{
|
||||||
@ -54,16 +57,14 @@ static SerialInterface::SIDevices FromGCMenuIndex(const int menudevice)
|
|||||||
return s_gc_types[menudevice].first;
|
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)
|
GamecubeControllersWidget::GamecubeControllersWidget(QWidget* parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
CreateLayout();
|
CreateLayout();
|
||||||
LoadSettings();
|
LoadSettings();
|
||||||
ConnectWidgets();
|
ConnectWidgets();
|
||||||
|
|
||||||
|
connect(&Settings::Instance(), &Settings::ConfigChanged, this,
|
||||||
|
&GamecubeControllersWidget::LoadSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamecubeControllersWidget::CreateLayout()
|
void GamecubeControllersWidget::CreateLayout()
|
||||||
@ -100,43 +101,27 @@ void GamecubeControllersWidget::CreateLayout()
|
|||||||
|
|
||||||
void GamecubeControllersWidget::ConnectWidgets()
|
void GamecubeControllersWidget::ConnectWidgets()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_gc_controller_boxes.size(); i++)
|
for (size_t i = 0; i < m_gc_controller_boxes.size(); ++i)
|
||||||
{
|
{
|
||||||
connect(m_gc_controller_boxes[i], qOverload<int>(&QComboBox::currentIndexChanged), this,
|
connect(m_gc_controller_boxes[i], qOverload<int>(&QComboBox::currentIndexChanged), this,
|
||||||
&GamecubeControllersWidget::SaveSettings);
|
[this, i] {
|
||||||
connect(m_gc_controller_boxes[i], qOverload<int>(&QComboBox::currentIndexChanged), this,
|
OnGCTypeChanged(i);
|
||||||
&GamecubeControllersWidget::OnGCTypeChanged);
|
SaveSettings();
|
||||||
connect(m_gc_buttons[i], &QPushButton::clicked, this,
|
});
|
||||||
&GamecubeControllersWidget::OnGCPadConfigure);
|
connect(m_gc_buttons[i], &QPushButton::clicked, this, [this, i] { OnGCPadConfigure(i); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamecubeControllersWidget::OnGCTypeChanged(int type)
|
void GamecubeControllersWidget::OnGCTypeChanged(size_t index)
|
||||||
{
|
{
|
||||||
const auto* box = static_cast<QComboBox*>(QObject::sender());
|
const SerialInterface::SIDevices si_device =
|
||||||
|
FromGCMenuIndex(m_gc_controller_boxes[index]->currentIndex());
|
||||||
for (size_t i = 0; i < m_gc_groups.size(); i++)
|
m_gc_buttons[index]->setEnabled(si_device != SerialInterface::SIDEVICE_NONE &&
|
||||||
{
|
si_device != SerialInterface::SIDEVICE_GC_GBA);
|
||||||
if (m_gc_controller_boxes[i] == box)
|
|
||||||
{
|
|
||||||
const SerialInterface::SIDevices si_device = FromGCMenuIndex(box->currentIndex());
|
|
||||||
m_gc_buttons[i]->setEnabled(IsConfigurable(si_device));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SaveSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamecubeControllersWidget::OnGCPadConfigure()
|
void GamecubeControllersWidget::OnGCPadConfigure(size_t index)
|
||||||
{
|
{
|
||||||
size_t index;
|
|
||||||
for (index = 0; index < m_gc_groups.size(); index++)
|
|
||||||
{
|
|
||||||
if (m_gc_buttons[index] == QObject::sender())
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
MappingWindow::Type type;
|
MappingWindow::Type type;
|
||||||
|
|
||||||
switch (FromGCMenuIndex(m_gc_controller_boxes[index]->currentIndex()))
|
switch (FromGCMenuIndex(m_gc_controller_boxes[index]->currentIndex()))
|
||||||
@ -184,30 +169,32 @@ void GamecubeControllersWidget::LoadSettings()
|
|||||||
const std::optional<int> gc_index = ToGCMenuIndex(si_device);
|
const std::optional<int> gc_index = ToGCMenuIndex(si_device);
|
||||||
if (gc_index)
|
if (gc_index)
|
||||||
{
|
{
|
||||||
m_gc_controller_boxes[i]->setCurrentIndex(*gc_index);
|
SignalBlocking(m_gc_controller_boxes[i])->setCurrentIndex(*gc_index);
|
||||||
m_gc_buttons[i]->setEnabled(IsConfigurable(si_device));
|
OnGCTypeChanged(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamecubeControllersWidget::SaveSettings()
|
void GamecubeControllersWidget::SaveSettings()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_gc_groups.size(); i++)
|
|
||||||
{
|
{
|
||||||
const int index = m_gc_controller_boxes[i]->currentIndex();
|
Config::ConfigChangeCallbackGuard config_guard;
|
||||||
const SerialInterface::SIDevices si_device = FromGCMenuIndex(index);
|
|
||||||
Config::SetBaseOrCurrent(Config::GetInfoForSIDevice(static_cast<int>(i)), si_device);
|
|
||||||
|
|
||||||
if (Core::IsRunning())
|
for (size_t i = 0; i < m_gc_groups.size(); ++i)
|
||||||
SerialInterface::ChangeDevice(si_device, static_cast<s32>(i));
|
{
|
||||||
|
const SerialInterface::SIDevices si_device =
|
||||||
|
FromGCMenuIndex(m_gc_controller_boxes[i]->currentIndex());
|
||||||
|
Config::SetBaseOrCurrent(Config::GetInfoForSIDevice(static_cast<int>(i)), si_device);
|
||||||
|
|
||||||
m_gc_buttons[i]->setEnabled(IsConfigurable(si_device));
|
if (Core::IsRunning())
|
||||||
|
SerialInterface::ChangeDevice(si_device, static_cast<s32>(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GCAdapter::UseAdapter())
|
||||||
|
GCAdapter::StartScanThread();
|
||||||
|
else
|
||||||
|
GCAdapter::StopScanThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GCAdapter::UseAdapter())
|
|
||||||
GCAdapter::StartScanThread();
|
|
||||||
else
|
|
||||||
GCAdapter::StopScanThread();
|
|
||||||
|
|
||||||
SConfig::GetInstance().SaveSettings();
|
SConfig::GetInstance().SaveSettings();
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,8 @@ private:
|
|||||||
void LoadSettings();
|
void LoadSettings();
|
||||||
void SaveSettings();
|
void SaveSettings();
|
||||||
|
|
||||||
void OnGCTypeChanged(int state);
|
void OnGCTypeChanged(size_t index);
|
||||||
void OnGCPadConfigure();
|
void OnGCPadConfigure(size_t index);
|
||||||
|
|
||||||
void CreateLayout();
|
void CreateLayout();
|
||||||
void ConnectWidgets();
|
void ConnectWidgets();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user