Merge pull request #11075 from AdmiralCurtiss/controller-gui-refresh

Qt/Controllers: Refresh GUI on settings change.
This commit is contained in:
Admiral H. Curtiss 2022-09-24 00:14:54 +02:00 committed by GitHub
commit 3fa9fdf57a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 152 additions and 163 deletions

View File

@ -13,12 +13,17 @@
#include "DolphinQt/Config/ControllerInterface/ControllerInterfaceWindow.h" #include "DolphinQt/Config/ControllerInterface/ControllerInterfaceWindow.h"
#include "DolphinQt/QtUtils/NonDefaultQPushButton.h" #include "DolphinQt/QtUtils/NonDefaultQPushButton.h"
#include "DolphinQt/QtUtils/SignalBlocking.h"
#include "DolphinQt/Settings.h"
CommonControllersWidget::CommonControllersWidget(QWidget* parent) : QWidget(parent) CommonControllersWidget::CommonControllersWidget(QWidget* parent) : QWidget(parent)
{ {
CreateLayout(); CreateLayout();
LoadSettings(); LoadSettings();
ConnectWidgets(); ConnectWidgets();
connect(&Settings::Instance(), &Settings::ConfigChanged, this,
&CommonControllersWidget::LoadSettings);
} }
void CommonControllersWidget::CreateLayout() void CommonControllersWidget::CreateLayout()
@ -59,7 +64,7 @@ void CommonControllersWidget::OnControllerInterfaceConfigure()
void CommonControllersWidget::LoadSettings() void CommonControllersWidget::LoadSettings()
{ {
m_common_bg_input->setChecked(Config::Get(Config::MAIN_INPUT_BACKGROUND_INPUT)); SignalBlocking(m_common_bg_input)->setChecked(Config::Get(Config::MAIN_INPUT_BACKGROUND_INPUT));
} }
void CommonControllersWidget::SaveSettings() void CommonControllersWidget::SaveSettings()

View File

@ -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);
connect(m_gc_buttons[i], &QPushButton::clicked, this,
&GamecubeControllersWidget::OnGCPadConfigure);
}
}
void GamecubeControllersWidget::OnGCTypeChanged(int type)
{
const auto* box = static_cast<QComboBox*>(QObject::sender());
for (size_t i = 0; i < m_gc_groups.size(); i++)
{
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(); SaveSettings();
});
connect(m_gc_buttons[i], &QPushButton::clicked, this, [this, i] { OnGCPadConfigure(i); });
}
} }
void GamecubeControllersWidget::OnGCPadConfigure() void GamecubeControllersWidget::OnGCTypeChanged(size_t index)
{ {
size_t index; const SerialInterface::SIDevices si_device =
for (index = 0; index < m_gc_groups.size(); index++) FromGCMenuIndex(m_gc_controller_boxes[index]->currentIndex());
{ m_gc_buttons[index]->setEnabled(si_device != SerialInterface::SIDEVICE_NONE &&
if (m_gc_buttons[index] == QObject::sender()) si_device != SerialInterface::SIDEVICE_GC_GBA);
break;
} }
void GamecubeControllersWidget::OnGCPadConfigure(size_t index)
{
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);
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); Config::SetBaseOrCurrent(Config::GetInfoForSIDevice(static_cast<int>(i)), si_device);
if (Core::IsRunning()) if (Core::IsRunning())
SerialInterface::ChangeDevice(si_device, static_cast<s32>(i)); SerialInterface::ChangeDevice(si_device, static_cast<s32>(i));
m_gc_buttons[i]->setEnabled(IsConfigurable(si_device));
} }
if (GCAdapter::UseAdapter()) if (GCAdapter::UseAdapter())
GCAdapter::StartScanThread(); GCAdapter::StartScanThread();
else else
GCAdapter::StopScanThread(); GCAdapter::StopScanThread();
}
SConfig::GetInstance().SaveSettings(); SConfig::GetInstance().SaveSettings();
} }

View File

@ -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();

View File

@ -32,6 +32,7 @@
#include "DolphinQt/Config/Mapping/MappingWindow.h" #include "DolphinQt/Config/Mapping/MappingWindow.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.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 "UICommon/UICommon.h" #include "UICommon/UICommon.h"
@ -39,8 +40,13 @@
WiimoteControllersWidget::WiimoteControllersWidget(QWidget* parent) : QWidget(parent) WiimoteControllersWidget::WiimoteControllersWidget(QWidget* parent) : QWidget(parent)
{ {
CreateLayout(); CreateLayout();
LoadSettings();
ConnectWidgets(); ConnectWidgets();
connect(&Settings::Instance(), &Settings::ConfigChanged, this,
[this] { LoadSettings(Core::GetState()); });
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
[this](Core::State state) { LoadSettings(state); });
LoadSettings(Core::GetState());
} }
static int GetRadioButtonIndicatorWidth() static int GetRadioButtonIndicatorWidth()
@ -153,20 +159,20 @@ void WiimoteControllersWidget::CreateLayout()
void WiimoteControllersWidget::ConnectWidgets() void WiimoteControllersWidget::ConnectWidgets()
{ {
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, connect(m_wiimote_passthrough, &QRadioButton::toggled, this, [this] {
&WiimoteControllersWidget::UpdateDisabledWiimoteControls); SaveSettings();
LoadSettings(Core::GetState());
});
connect(m_wiimote_ciface, &QCheckBox::toggled, this, [this] {
SaveSettings();
LoadSettings(Core::GetState());
WiimoteReal::HandleWiimotesInControllerInterfaceSettingChange();
});
connect(m_wiimote_continuous_scanning, &QCheckBox::toggled, this, [this] {
SaveSettings();
LoadSettings(Core::GetState());
});
connect(m_wiimote_passthrough, &QRadioButton::toggled, this,
&WiimoteControllersWidget::OnWiimoteModeChanged);
connect(m_wiimote_ciface, &QCheckBox::toggled, this,
&WiimoteControllersWidget::OnWiimoteModeChanged);
connect(m_wiimote_ciface, &QCheckBox::toggled, this,
&WiimoteReal::HandleWiimotesInControllerInterfaceSettingChange);
connect(m_wiimote_continuous_scanning, &QCheckBox::toggled, this,
&WiimoteControllersWidget::OnWiimoteModeChanged);
connect(m_wiimote_continuous_scanning, &QCheckBox::toggled, this,
&WiimoteControllersWidget::SaveSettings);
connect(m_wiimote_real_balance_board, &QCheckBox::toggled, this, connect(m_wiimote_real_balance_board, &QCheckBox::toggled, this,
&WiimoteControllersWidget::SaveSettings); &WiimoteControllersWidget::SaveSettings);
connect(m_wiimote_speaker_data, &QCheckBox::toggled, this, connect(m_wiimote_speaker_data, &QCheckBox::toggled, this,
@ -180,59 +186,13 @@ void WiimoteControllersWidget::ConnectWidgets()
for (size_t i = 0; i < m_wiimote_groups.size(); i++) for (size_t i = 0; i < m_wiimote_groups.size(); i++)
{ {
connect(m_wiimote_boxes[i], qOverload<int>(&QComboBox::currentIndexChanged), this, connect(m_wiimote_boxes[i], qOverload<int>(&QComboBox::currentIndexChanged), this, [this] {
&WiimoteControllersWidget::SaveSettings);
connect(m_wiimote_boxes[i], qOverload<int>(&QComboBox::currentIndexChanged), this,
&WiimoteControllersWidget::OnWiimoteModeChanged);
connect(m_wiimote_buttons[i], &QPushButton::clicked, this,
&WiimoteControllersWidget::OnWiimoteConfigure);
}
}
void WiimoteControllersWidget::OnWiimoteModeChanged()
{
SaveSettings(); SaveSettings();
LoadSettings(Core::GetState());
// Make sure continuous scanning setting is applied. });
WiimoteReal::Initialize(::Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES); connect(m_wiimote_buttons[i], &QPushButton::clicked, this,
[this, i] { OnWiimoteConfigure(i); });
UpdateDisabledWiimoteControls();
} }
void WiimoteControllersWidget::UpdateDisabledWiimoteControls()
{
const bool running = Core::GetState() != Core::State::Uninitialized;
m_wiimote_emu->setEnabled(!running);
m_wiimote_passthrough->setEnabled(!running);
const bool running_gc = running && !SConfig::GetInstance().bWii;
const bool enable_passthrough = m_wiimote_passthrough->isChecked() && !running_gc;
const bool enable_emu_bt = !m_wiimote_passthrough->isChecked() && !running_gc;
m_wiimote_sync->setEnabled(enable_passthrough);
m_wiimote_reset->setEnabled(enable_passthrough);
for (auto* pt_label : m_wiimote_pt_labels)
pt_label->setEnabled(enable_passthrough);
for (size_t i = 0; i < m_wiimote_groups.size(); i++)
{
m_wiimote_labels[i]->setEnabled(enable_emu_bt);
m_wiimote_boxes[i]->setEnabled(enable_emu_bt);
const bool is_emu_wiimote = m_wiimote_boxes[i]->currentIndex() == 1;
m_wiimote_buttons[i]->setEnabled(enable_emu_bt && is_emu_wiimote);
}
m_wiimote_real_balance_board->setEnabled(enable_emu_bt);
m_wiimote_speaker_data->setEnabled(enable_emu_bt);
const bool ciface_wiimotes = m_wiimote_ciface->isChecked();
m_wiimote_refresh->setEnabled((enable_emu_bt || ciface_wiimotes) &&
!m_wiimote_continuous_scanning->isChecked());
m_wiimote_continuous_scanning->setEnabled(enable_emu_bt || ciface_wiimotes);
} }
void WiimoteControllersWidget::OnBluetoothPassthroughResetPressed() void WiimoteControllersWidget::OnBluetoothPassthroughResetPressed()
@ -273,15 +233,8 @@ void WiimoteControllersWidget::OnWiimoteRefreshPressed()
WiimoteReal::Refresh(); WiimoteReal::Refresh();
} }
void WiimoteControllersWidget::OnWiimoteConfigure() void WiimoteControllersWidget::OnWiimoteConfigure(size_t index)
{ {
size_t index;
for (index = 0; index < m_wiimote_groups.size(); index++)
{
if (m_wiimote_buttons[index] == QObject::sender())
break;
}
MappingWindow::Type type; MappingWindow::Type type;
switch (m_wiimote_boxes[index]->currentIndex()) switch (m_wiimote_boxes[index]->currentIndex())
{ {
@ -301,28 +254,68 @@ void WiimoteControllersWidget::OnWiimoteConfigure()
window->show(); window->show();
} }
void WiimoteControllersWidget::LoadSettings() void WiimoteControllersWidget::LoadSettings(Core::State state)
{ {
for (size_t i = 0; i < m_wiimote_groups.size(); i++) for (size_t i = 0; i < m_wiimote_groups.size(); i++)
{ {
m_wiimote_boxes[i]->setCurrentIndex(int(Config::Get(Config::GetInfoForWiimoteSource(int(i))))); SignalBlocking(m_wiimote_boxes[i])
->setCurrentIndex(int(Config::Get(Config::GetInfoForWiimoteSource(int(i)))));
} }
m_wiimote_real_balance_board->setChecked(Config::Get(Config::WIIMOTE_BB_SOURCE) == SignalBlocking(m_wiimote_real_balance_board)
WiimoteSource::Real); ->setChecked(Config::Get(Config::WIIMOTE_BB_SOURCE) == WiimoteSource::Real);
m_wiimote_speaker_data->setChecked(Config::Get(Config::MAIN_WIIMOTE_ENABLE_SPEAKER)); SignalBlocking(m_wiimote_speaker_data)
m_wiimote_ciface->setChecked(Config::Get(Config::MAIN_CONNECT_WIIMOTES_FOR_CONTROLLER_INTERFACE)); ->setChecked(Config::Get(Config::MAIN_WIIMOTE_ENABLE_SPEAKER));
m_wiimote_continuous_scanning->setChecked(Config::Get(Config::MAIN_WIIMOTE_CONTINUOUS_SCANNING)); SignalBlocking(m_wiimote_ciface)
->setChecked(Config::Get(Config::MAIN_CONNECT_WIIMOTES_FOR_CONTROLLER_INTERFACE));
SignalBlocking(m_wiimote_continuous_scanning)
->setChecked(Config::Get(Config::MAIN_WIIMOTE_CONTINUOUS_SCANNING));
if (Config::Get(Config::MAIN_BLUETOOTH_PASSTHROUGH_ENABLED)) if (Config::Get(Config::MAIN_BLUETOOTH_PASSTHROUGH_ENABLED))
m_wiimote_passthrough->setChecked(true); SignalBlocking(m_wiimote_passthrough)->setChecked(true);
else else
m_wiimote_emu->setChecked(true); SignalBlocking(m_wiimote_emu)->setChecked(true);
OnWiimoteModeChanged(); // Make sure continuous scanning setting is applied.
WiimoteReal::Initialize(::Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES);
const bool running = state != Core::State::Uninitialized;
m_wiimote_emu->setEnabled(!running);
m_wiimote_passthrough->setEnabled(!running);
const bool running_gc = running && !SConfig::GetInstance().bWii;
const bool enable_passthrough = m_wiimote_passthrough->isChecked() && !running_gc;
const bool enable_emu_bt = !m_wiimote_passthrough->isChecked() && !running_gc;
m_wiimote_sync->setEnabled(enable_passthrough);
m_wiimote_reset->setEnabled(enable_passthrough);
for (auto* pt_label : m_wiimote_pt_labels)
pt_label->setEnabled(enable_passthrough);
for (size_t i = 0; i < m_wiimote_groups.size(); i++)
{
m_wiimote_labels[i]->setEnabled(enable_emu_bt);
m_wiimote_boxes[i]->setEnabled(enable_emu_bt);
const bool is_emu_wiimote = m_wiimote_boxes[i]->currentIndex() == 1;
m_wiimote_buttons[i]->setEnabled(enable_emu_bt && is_emu_wiimote);
}
m_wiimote_real_balance_board->setEnabled(enable_emu_bt);
m_wiimote_speaker_data->setEnabled(enable_emu_bt);
const bool ciface_wiimotes = m_wiimote_ciface->isChecked();
m_wiimote_refresh->setEnabled((enable_emu_bt || ciface_wiimotes) &&
!m_wiimote_continuous_scanning->isChecked());
m_wiimote_continuous_scanning->setEnabled(enable_emu_bt || ciface_wiimotes);
} }
void WiimoteControllersWidget::SaveSettings() void WiimoteControllersWidget::SaveSettings()
{ {
{
Config::ConfigChangeCallbackGuard config_guard;
Config::SetBaseOrCurrent(Config::MAIN_WIIMOTE_ENABLE_SPEAKER, Config::SetBaseOrCurrent(Config::MAIN_WIIMOTE_ENABLE_SPEAKER,
m_wiimote_speaker_data->isChecked()); m_wiimote_speaker_data->isChecked());
Config::SetBaseOrCurrent(Config::MAIN_CONNECT_WIIMOTES_FOR_CONTROLLER_INTERFACE, Config::SetBaseOrCurrent(Config::MAIN_CONNECT_WIIMOTES_FOR_CONTROLLER_INTERFACE,
@ -341,6 +334,7 @@ void WiimoteControllersWidget::SaveSettings()
const int index = m_wiimote_boxes[i]->currentIndex(); const int index = m_wiimote_boxes[i]->currentIndex();
Config::SetBaseOrCurrent(Config::GetInfoForWiimoteSource(int(i)), WiimoteSource(index)); Config::SetBaseOrCurrent(Config::GetInfoForWiimoteSource(int(i)), WiimoteSource(index));
} }
}
SConfig::GetInstance().SaveSettings(); SConfig::GetInstance().SaveSettings();
} }

View File

@ -16,6 +16,11 @@ class QLabel;
class QPushButton; class QPushButton;
class QRadioButton; class QRadioButton;
namespace Core
{
enum class State;
}
class WiimoteControllersWidget final : public QWidget class WiimoteControllersWidget final : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -23,17 +28,15 @@ public:
explicit WiimoteControllersWidget(QWidget* parent); explicit WiimoteControllersWidget(QWidget* parent);
private: private:
void OnWiimoteModeChanged();
void UpdateDisabledWiimoteControls();
void SaveSettings(); void SaveSettings();
void OnBluetoothPassthroughSyncPressed(); void OnBluetoothPassthroughSyncPressed();
void OnBluetoothPassthroughResetPressed(); void OnBluetoothPassthroughResetPressed();
void OnWiimoteRefreshPressed(); void OnWiimoteRefreshPressed();
void OnWiimoteConfigure(); void OnWiimoteConfigure(size_t index);
void CreateLayout(); void CreateLayout();
void ConnectWidgets(); void ConnectWidgets();
void LoadSettings(); void LoadSettings(Core::State state);
QGroupBox* m_wiimote_box; QGroupBox* m_wiimote_box;
QGridLayout* m_wiimote_layout; QGridLayout* m_wiimote_layout;