2017-05-20 09:53:17 -06:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-04 19:22:19 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-05-20 09:53:17 -06:00
|
|
|
|
2018-07-06 16:40:15 -06:00
|
|
|
#include "DolphinQt/Config/Mapping/GCPadWiiUConfigDialog.h"
|
2018-05-27 19:48:04 -06:00
|
|
|
|
2017-05-20 09:53:17 -06:00
|
|
|
#include <QCheckBox>
|
2017-11-03 15:47:36 -06:00
|
|
|
#include <QDialogButtonBox>
|
2017-05-20 09:53:17 -06:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
2022-01-04 19:25:19 -07:00
|
|
|
#include "Core/Config/MainSettings.h"
|
2017-06-22 16:11:53 -06:00
|
|
|
#include "Core/ConfigManager.h"
|
2018-07-19 00:23:16 -06:00
|
|
|
#include "DolphinQt/QtUtils/QueueOnObject.h"
|
2018-05-27 19:48:04 -06:00
|
|
|
|
2017-05-20 09:53:17 -06:00
|
|
|
#include "InputCommon/GCAdapter.h"
|
|
|
|
|
2017-11-04 19:45:37 -06:00
|
|
|
GCPadWiiUConfigDialog::GCPadWiiUConfigDialog(int port, QWidget* parent)
|
|
|
|
: QDialog(parent), m_port{port}
|
2017-05-20 09:53:17 -06:00
|
|
|
{
|
2018-05-04 18:29:16 -06:00
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
|
2017-05-20 09:53:17 -06:00
|
|
|
CreateLayout();
|
|
|
|
|
|
|
|
LoadSettings();
|
2018-06-05 05:04:57 -06:00
|
|
|
ConnectWidgets();
|
2017-05-20 09:53:17 -06:00
|
|
|
}
|
|
|
|
|
2018-07-19 00:23:16 -06:00
|
|
|
GCPadWiiUConfigDialog::~GCPadWiiUConfigDialog()
|
|
|
|
{
|
|
|
|
GCAdapter::SetAdapterCallback(nullptr);
|
|
|
|
}
|
|
|
|
|
2017-11-04 19:45:37 -06:00
|
|
|
void GCPadWiiUConfigDialog::CreateLayout()
|
2017-05-20 09:53:17 -06:00
|
|
|
{
|
2017-11-03 15:47:36 -06:00
|
|
|
setWindowTitle(tr("GameCube Adapter for Wii U at Port %1").arg(m_port + 1));
|
|
|
|
|
2017-05-20 09:53:17 -06:00
|
|
|
m_layout = new QVBoxLayout();
|
2018-07-19 00:23:16 -06:00
|
|
|
m_status_label = new QLabel();
|
2017-05-20 09:53:17 -06:00
|
|
|
m_rumble = new QCheckBox(tr("Enable Rumble"));
|
|
|
|
m_simulate_bongos = new QCheckBox(tr("Simulate DK Bongos"));
|
2017-11-03 15:47:36 -06:00
|
|
|
m_button_box = new QDialogButtonBox(QDialogButtonBox::Ok);
|
2017-05-20 09:53:17 -06:00
|
|
|
|
2018-07-19 00:23:16 -06:00
|
|
|
UpdateAdapterStatus();
|
|
|
|
|
|
|
|
auto callback = [this] { QueueOnObject(this, &GCPadWiiUConfigDialog::UpdateAdapterStatus); };
|
|
|
|
GCAdapter::SetAdapterCallback(callback);
|
|
|
|
|
2017-05-20 09:53:17 -06:00
|
|
|
m_layout->addWidget(m_status_label);
|
|
|
|
m_layout->addWidget(m_rumble);
|
|
|
|
m_layout->addWidget(m_simulate_bongos);
|
2017-11-03 15:47:36 -06:00
|
|
|
m_layout->addWidget(m_button_box);
|
2017-05-20 09:53:17 -06:00
|
|
|
|
|
|
|
setLayout(m_layout);
|
|
|
|
}
|
|
|
|
|
2017-11-04 19:45:37 -06:00
|
|
|
void GCPadWiiUConfigDialog::ConnectWidgets()
|
2017-05-20 09:53:17 -06:00
|
|
|
{
|
2017-11-04 19:45:37 -06:00
|
|
|
connect(m_rumble, &QCheckBox::toggled, this, &GCPadWiiUConfigDialog::SaveSettings);
|
|
|
|
connect(m_simulate_bongos, &QCheckBox::toggled, this, &GCPadWiiUConfigDialog::SaveSettings);
|
|
|
|
connect(m_button_box, &QDialogButtonBox::accepted, this, &GCPadWiiUConfigDialog::accept);
|
2017-05-20 09:53:17 -06:00
|
|
|
}
|
|
|
|
|
2018-07-19 00:23:16 -06:00
|
|
|
void GCPadWiiUConfigDialog::UpdateAdapterStatus()
|
|
|
|
{
|
|
|
|
const char* error_message = nullptr;
|
|
|
|
const bool detected = GCAdapter::IsDetected(&error_message);
|
|
|
|
QString status_text;
|
|
|
|
|
|
|
|
if (detected)
|
|
|
|
{
|
|
|
|
status_text = tr("Adapter Detected");
|
|
|
|
}
|
|
|
|
else if (error_message)
|
|
|
|
{
|
|
|
|
status_text = tr("Error Opening Adapter: %1").arg(QString::fromUtf8(error_message));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status_text = tr("No Adapter Detected");
|
|
|
|
}
|
|
|
|
|
|
|
|
m_status_label->setText(status_text);
|
|
|
|
|
|
|
|
m_rumble->setEnabled(detected);
|
|
|
|
m_simulate_bongos->setEnabled(detected);
|
|
|
|
}
|
|
|
|
|
2017-11-04 19:45:37 -06:00
|
|
|
void GCPadWiiUConfigDialog::LoadSettings()
|
2017-05-20 09:53:17 -06:00
|
|
|
{
|
2022-01-04 19:25:19 -07:00
|
|
|
m_rumble->setChecked(Config::Get(Config::GetInfoForAdapterRumble(m_port)));
|
|
|
|
m_simulate_bongos->setChecked(Config::Get(Config::GetInfoForSimulateKonga(m_port)));
|
2017-05-20 09:53:17 -06:00
|
|
|
}
|
|
|
|
|
2017-11-04 19:45:37 -06:00
|
|
|
void GCPadWiiUConfigDialog::SaveSettings()
|
2017-05-20 09:53:17 -06:00
|
|
|
{
|
2022-01-04 19:25:19 -07:00
|
|
|
Config::SetBaseOrCurrent(Config::GetInfoForAdapterRumble(m_port), m_rumble->isChecked());
|
|
|
|
Config::SetBaseOrCurrent(Config::GetInfoForSimulateKonga(m_port), m_simulate_bongos->isChecked());
|
2017-05-20 09:53:17 -06:00
|
|
|
}
|