2017-05-09 16:49:10 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Config/ControllersWindow.h"
|
2018-05-28 01:11:27 +00:00
|
|
|
|
2017-05-27 10:05:00 +00:00
|
|
|
#include <QApplication>
|
2017-05-09 16:49:10 +00:00
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QDialogButtonBox>
|
2017-05-27 02:14:20 +00:00
|
|
|
#include <QGridLayout>
|
2017-05-09 16:49:10 +00:00
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QRadioButton>
|
2017-05-27 10:05:00 +00:00
|
|
|
#include <QScreen>
|
2017-05-09 16:49:10 +00:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
2017-09-04 06:55:08 +00:00
|
|
|
#include <map>
|
2018-05-02 16:34:13 +00:00
|
|
|
#include <optional>
|
2017-05-09 16:49:10 +00:00
|
|
|
|
|
|
|
#include "Core/ConfigManager.h"
|
2017-09-04 18:12:13 +00:00
|
|
|
#include "Core/Core.h"
|
2017-05-09 16:49:10 +00:00
|
|
|
#include "Core/HW/SI/SI.h"
|
2019-06-07 22:25:32 +00:00
|
|
|
#include "Core/HW/SI/SI_Device.h"
|
2017-05-09 16:49:10 +00:00
|
|
|
#include "Core/HW/Wiimote.h"
|
|
|
|
#include "Core/HW/WiimoteReal/WiimoteReal.h"
|
|
|
|
#include "Core/IOS/IOS.h"
|
|
|
|
#include "Core/IOS/USB/Bluetooth/BTReal.h"
|
2018-05-28 01:11:27 +00:00
|
|
|
|
2019-10-22 23:49:48 +00:00
|
|
|
#include "DolphinQt/Config/ControllerInterface/ControllerInterfaceWindow.h"
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Config/Mapping/GCPadWiiUConfigDialog.h"
|
|
|
|
#include "DolphinQt/Config/Mapping/MappingWindow.h"
|
2019-03-04 19:49:00 +00:00
|
|
|
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/QtUtils/WrapInScrollArea.h"
|
|
|
|
#include "DolphinQt/Settings.h"
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2018-05-28 01:11:27 +00:00
|
|
|
#include "InputCommon/GCAdapter.h"
|
2018-05-28 01:48:04 +00:00
|
|
|
|
2018-05-28 01:11:27 +00:00
|
|
|
#include "UICommon/UICommon.h"
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2017-09-04 06:55:08 +00:00
|
|
|
static const std::map<SerialInterface::SIDevices, int> s_gc_types = {
|
2017-05-09 16:49:10 +00:00
|
|
|
{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}};
|
|
|
|
|
2018-05-02 16:34:13 +00:00
|
|
|
static std::optional<int> ToGCMenuIndex(const SerialInterface::SIDevices sidevice)
|
2017-05-09 16:49:10 +00:00
|
|
|
{
|
2018-05-02 16:34:13 +00:00
|
|
|
auto it = s_gc_types.find(sidevice);
|
|
|
|
return it != s_gc_types.end() ? it->second : std::optional<int>();
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
2018-05-02 16:34:13 +00:00
|
|
|
static std::optional<SerialInterface::SIDevices> FromGCMenuIndex(const int menudevice)
|
2017-05-09 16:49:10 +00:00
|
|
|
{
|
|
|
|
auto it = std::find_if(s_gc_types.begin(), s_gc_types.end(),
|
|
|
|
[=](auto pair) { return pair.second == menudevice; });
|
2018-05-02 16:34:13 +00:00
|
|
|
return it != s_gc_types.end() ? it->first : std::optional<SerialInterface::SIDevices>();
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
2017-05-27 02:49:20 +00:00
|
|
|
ControllersWindow::ControllersWindow(QWidget* parent) : QDialog(parent)
|
2017-05-09 16:49:10 +00:00
|
|
|
{
|
|
|
|
setWindowTitle(tr("Controller Settings"));
|
2017-06-30 00:52:53 +00:00
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
|
|
|
CreateGamecubeLayout();
|
|
|
|
CreateWiimoteLayout();
|
2019-10-21 23:43:37 +00:00
|
|
|
CreateCommonLayout();
|
2017-05-09 16:49:10 +00:00
|
|
|
CreateMainLayout();
|
|
|
|
LoadSettings();
|
|
|
|
ConnectWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllersWindow::CreateGamecubeLayout()
|
|
|
|
{
|
2017-05-27 02:49:20 +00:00
|
|
|
m_gc_box = new QGroupBox(tr("GameCube Controllers"));
|
2017-05-27 02:14:20 +00:00
|
|
|
m_gc_layout = new QGridLayout();
|
|
|
|
m_gc_layout->setVerticalSpacing(7);
|
|
|
|
m_gc_layout->setColumnStretch(1, 1);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < m_gc_groups.size(); i++)
|
|
|
|
{
|
2017-07-23 10:58:32 +00:00
|
|
|
auto* gc_label = new QLabel(tr("Port %1").arg(i + 1));
|
2017-05-09 16:49:10 +00:00
|
|
|
auto* gc_box = m_gc_controller_boxes[i] = new QComboBox();
|
2017-05-27 02:49:20 +00:00
|
|
|
auto* gc_button = m_gc_buttons[i] = new QPushButton(tr("Configure"));
|
2017-05-09 16:49:10 +00:00
|
|
|
|
|
|
|
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")})
|
|
|
|
{
|
|
|
|
gc_box->addItem(item);
|
|
|
|
}
|
|
|
|
|
2017-05-27 02:14:20 +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);
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
|
|
|
m_gc_box->setLayout(m_gc_layout);
|
|
|
|
}
|
|
|
|
|
2017-05-27 10:05:00 +00:00
|
|
|
static int GetRadioButtonIndicatorWidth()
|
2017-05-09 16:49:10 +00:00
|
|
|
{
|
2017-05-27 10:05:00 +00:00
|
|
|
const QStyle* style = QApplication::style();
|
|
|
|
QStyleOptionButton opt;
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2017-05-27 10:05:00 +00:00
|
|
|
// TODO: why does the macOS style act different? Is it because of the magic with
|
|
|
|
// Cocoa widgets it does behind the scenes?
|
|
|
|
if (style->objectName() == QStringLiteral("macintosh"))
|
|
|
|
return style->subElementRect(QStyle::SE_RadioButtonIndicator, &opt).width();
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2017-05-27 10:05:00 +00:00
|
|
|
return style->subElementRect(QStyle::SE_RadioButtonContents, &opt).left();
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
2017-05-27 10:05:00 +00:00
|
|
|
static int GetLayoutHorizontalSpacing(const QGridLayout* layout)
|
2017-05-09 16:49:10 +00:00
|
|
|
{
|
2017-05-27 10:05:00 +00:00
|
|
|
// TODO: shouldn't layout->horizontalSpacing() do all this? Why does it return -1?
|
|
|
|
int hspacing = layout->horizontalSpacing();
|
|
|
|
if (hspacing >= 0)
|
|
|
|
return hspacing;
|
|
|
|
|
|
|
|
// According to docs, this is the fallback if horizontalSpacing() isn't set.
|
|
|
|
auto style = layout->parentWidget()->style();
|
|
|
|
hspacing = style->pixelMetric(QStyle::PM_LayoutHorizontalSpacing);
|
|
|
|
if (hspacing >= 0)
|
|
|
|
return hspacing;
|
|
|
|
|
|
|
|
// Docs claim this is deprecated, but on macOS with Qt 5.8 this is the only one that actually
|
|
|
|
// works.
|
|
|
|
float pixel_ratio = QGuiApplication::primaryScreen()->devicePixelRatio();
|
|
|
|
hspacing = pixel_ratio * style->pixelMetric(QStyle::PM_DefaultLayoutSpacing);
|
|
|
|
if (hspacing >= 0)
|
|
|
|
return hspacing;
|
|
|
|
|
|
|
|
// Ripped from qtbase/src/widgets/styles/qcommonstyle.cpp
|
|
|
|
return pixel_ratio * 6;
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControllersWindow::CreateWiimoteLayout()
|
|
|
|
{
|
2017-05-27 02:14:20 +00:00
|
|
|
m_wiimote_layout = new QGridLayout();
|
2017-05-27 02:49:20 +00:00
|
|
|
m_wiimote_box = new QGroupBox(tr("Wii Remotes"));
|
2017-05-27 10:05:00 +00:00
|
|
|
m_wiimote_box->setLayout(m_wiimote_layout);
|
|
|
|
|
2017-07-23 10:58:32 +00:00
|
|
|
m_wiimote_passthrough = new QRadioButton(tr("Passthrough a Bluetooth adapter"));
|
2017-05-09 16:49:10 +00:00
|
|
|
m_wiimote_sync = new QPushButton(tr("Sync"));
|
|
|
|
m_wiimote_reset = new QPushButton(tr("Reset"));
|
2017-05-15 03:14:45 +00:00
|
|
|
m_wiimote_refresh = new QPushButton(tr("Refresh"));
|
2017-05-09 16:49:10 +00:00
|
|
|
m_wiimote_pt_labels[0] = new QLabel(tr("Sync real Wii Remotes and pair them"));
|
|
|
|
m_wiimote_pt_labels[1] = new QLabel(tr("Reset all saved Wii Remote pairings"));
|
2017-08-01 12:34:44 +00:00
|
|
|
m_wiimote_emu = new QRadioButton(tr("Emulate the Wii's Bluetooth adapter"));
|
2017-05-09 16:49:10 +00:00
|
|
|
m_wiimote_continuous_scanning = new QCheckBox(tr("Continuous Scanning"));
|
|
|
|
m_wiimote_real_balance_board = new QCheckBox(tr("Real Balance Board"));
|
|
|
|
m_wiimote_speaker_data = new QCheckBox(tr("Enable Speaker Data"));
|
2020-01-22 00:50:05 +00:00
|
|
|
m_wiimote_ciface = new QCheckBox(tr("Connect Wii Remotes for Emulated Controllers"));
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2017-05-27 02:14:20 +00:00
|
|
|
m_wiimote_layout->setVerticalSpacing(7);
|
2017-05-27 10:05:00 +00:00
|
|
|
m_wiimote_layout->setColumnMinimumWidth(0, GetRadioButtonIndicatorWidth() -
|
|
|
|
GetLayoutHorizontalSpacing(m_wiimote_layout));
|
|
|
|
m_wiimote_layout->setColumnStretch(2, 1);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
|
|
|
// Passthrough BT
|
2017-05-27 02:14:20 +00:00
|
|
|
m_wiimote_layout->addWidget(m_wiimote_passthrough, m_wiimote_layout->rowCount(), 0, 1, -1);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2017-05-27 02:14:20 +00:00
|
|
|
int sync_row = m_wiimote_layout->rowCount();
|
2017-05-27 10:05:00 +00:00
|
|
|
m_wiimote_layout->addWidget(m_wiimote_pt_labels[0], sync_row, 1, 1, 2);
|
|
|
|
m_wiimote_layout->addWidget(m_wiimote_sync, sync_row, 3);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2017-05-27 02:14:20 +00:00
|
|
|
int reset_row = m_wiimote_layout->rowCount();
|
2017-05-27 10:05:00 +00:00
|
|
|
m_wiimote_layout->addWidget(m_wiimote_pt_labels[1], reset_row, 1, 1, 2);
|
|
|
|
m_wiimote_layout->addWidget(m_wiimote_reset, reset_row, 3);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
|
|
|
// Emulated BT
|
2017-05-27 02:14:20 +00:00
|
|
|
m_wiimote_layout->addWidget(m_wiimote_emu, m_wiimote_layout->rowCount(), 0, 1, -1);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < m_wiimote_groups.size(); i++)
|
|
|
|
{
|
|
|
|
auto* wm_label = m_wiimote_labels[i] = new QLabel(tr("Wii Remote %1").arg(i + 1));
|
|
|
|
auto* wm_box = m_wiimote_boxes[i] = new QComboBox();
|
2017-05-27 02:49:20 +00:00
|
|
|
auto* wm_button = m_wiimote_buttons[i] = new QPushButton(tr("Configure"));
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2018-04-17 20:40:11 +00:00
|
|
|
for (const auto& item : {tr("None"), tr("Emulated Wii Remote"), tr("Real Wii Remote")})
|
2017-05-09 16:49:10 +00:00
|
|
|
wm_box->addItem(item);
|
|
|
|
|
2017-05-27 02:14:20 +00:00
|
|
|
int wm_row = m_wiimote_layout->rowCount();
|
2017-05-27 10:05:00 +00:00
|
|
|
m_wiimote_layout->addWidget(wm_label, wm_row, 1);
|
|
|
|
m_wiimote_layout->addWidget(wm_box, wm_row, 2);
|
|
|
|
m_wiimote_layout->addWidget(wm_button, wm_row, 3);
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
2017-05-27 10:05:00 +00:00
|
|
|
m_wiimote_layout->addWidget(m_wiimote_real_balance_board, m_wiimote_layout->rowCount(), 1, 1, -1);
|
|
|
|
m_wiimote_layout->addWidget(m_wiimote_speaker_data, m_wiimote_layout->rowCount(), 1, 1, -1);
|
2020-01-22 00:50:05 +00:00
|
|
|
|
|
|
|
m_wiimote_layout->addWidget(m_wiimote_ciface, m_wiimote_layout->rowCount(), 0, 1, -1);
|
|
|
|
|
|
|
|
int continuous_scanning_row = m_wiimote_layout->rowCount();
|
|
|
|
m_wiimote_layout->addWidget(m_wiimote_continuous_scanning, continuous_scanning_row, 0, 1, 3);
|
|
|
|
m_wiimote_layout->addWidget(m_wiimote_refresh, continuous_scanning_row, 3);
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
2019-10-21 23:43:37 +00:00
|
|
|
void ControllersWindow::CreateCommonLayout()
|
2017-05-09 16:49:10 +00:00
|
|
|
{
|
2019-10-21 23:43:37 +00:00
|
|
|
// i18n: This is "common" as in "shared", not the opposite of "uncommon"
|
|
|
|
m_common_box = new QGroupBox(tr("Common"));
|
2019-10-22 23:49:48 +00:00
|
|
|
m_common_layout = new QVBoxLayout();
|
2019-10-21 23:43:37 +00:00
|
|
|
m_common_bg_input = new QCheckBox(tr("Background Input"));
|
2019-10-22 23:49:48 +00:00
|
|
|
m_common_configure_controller_interface = new QPushButton(tr("Alternate Input Sources"));
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2019-10-21 23:43:37 +00:00
|
|
|
m_common_layout->addWidget(m_common_bg_input);
|
2019-10-22 23:49:48 +00:00
|
|
|
m_common_layout->addWidget(m_common_configure_controller_interface);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2019-10-21 23:43:37 +00:00
|
|
|
m_common_box->setLayout(m_common_layout);
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControllersWindow::CreateMainLayout()
|
|
|
|
{
|
2018-03-17 15:07:51 +00:00
|
|
|
auto* layout = new QVBoxLayout();
|
2018-03-20 09:12:11 +00:00
|
|
|
m_button_box = new QDialogButtonBox(QDialogButtonBox::Close);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2018-03-17 15:07:51 +00:00
|
|
|
layout->addWidget(m_gc_box);
|
|
|
|
layout->addWidget(m_wiimote_box);
|
2019-10-21 23:43:37 +00:00
|
|
|
layout->addWidget(m_common_box);
|
2019-10-22 23:49:48 +00:00
|
|
|
layout->addStretch();
|
2018-03-17 15:07:51 +00:00
|
|
|
layout->addWidget(m_button_box);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2018-03-17 15:07:51 +00:00
|
|
|
WrapInScrollArea(this, layout);
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControllersWindow::ConnectWidgets()
|
|
|
|
{
|
2018-03-20 09:12:11 +00:00
|
|
|
connect(m_button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
2017-09-04 18:12:13 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
|
2020-01-22 00:50:05 +00:00
|
|
|
&ControllersWindow::UpdateDisabledWiimoteControls);
|
2017-09-04 18:12:13 +00:00
|
|
|
|
2017-05-09 16:49:10 +00:00
|
|
|
connect(m_wiimote_passthrough, &QRadioButton::toggled, this,
|
|
|
|
&ControllersWindow::OnWiimoteModeChanged);
|
2020-01-22 00:50:05 +00:00
|
|
|
connect(m_wiimote_ciface, &QCheckBox::toggled, this, &ControllersWindow::OnWiimoteModeChanged);
|
|
|
|
connect(m_wiimote_ciface, &QCheckBox::toggled, this,
|
|
|
|
&WiimoteReal::HandleWiimotesInControllerInterfaceSettingChange);
|
|
|
|
connect(m_wiimote_continuous_scanning, &QCheckBox::toggled, this,
|
|
|
|
&ControllersWindow::OnWiimoteModeChanged);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2019-10-21 23:43:37 +00:00
|
|
|
connect(m_common_bg_input, &QCheckBox::toggled, this, &ControllersWindow::SaveSettings);
|
2019-10-22 23:49:48 +00:00
|
|
|
connect(m_common_configure_controller_interface, &QPushButton::clicked, this,
|
|
|
|
&ControllersWindow::OnControllerInterfaceConfigure);
|
2017-05-09 16:49:10 +00:00
|
|
|
connect(m_wiimote_continuous_scanning, &QCheckBox::toggled, this,
|
|
|
|
&ControllersWindow::SaveSettings);
|
|
|
|
connect(m_wiimote_real_balance_board, &QCheckBox::toggled, this,
|
|
|
|
&ControllersWindow::SaveSettings);
|
|
|
|
connect(m_wiimote_speaker_data, &QCheckBox::toggled, this, &ControllersWindow::SaveSettings);
|
|
|
|
connect(m_wiimote_sync, &QPushButton::clicked, this,
|
|
|
|
&ControllersWindow::OnBluetoothPassthroughSyncPressed);
|
|
|
|
connect(m_wiimote_reset, &QPushButton::clicked, this,
|
|
|
|
&ControllersWindow::OnBluetoothPassthroughResetPressed);
|
2017-05-15 03:14:45 +00:00
|
|
|
connect(m_wiimote_refresh, &QPushButton::clicked, this,
|
|
|
|
&ControllersWindow::OnWiimoteRefreshPressed);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < m_wiimote_groups.size(); i++)
|
|
|
|
{
|
|
|
|
connect(m_wiimote_boxes[i],
|
|
|
|
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&ControllersWindow::SaveSettings);
|
|
|
|
connect(m_wiimote_boxes[i],
|
|
|
|
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
2020-01-22 00:50:05 +00:00
|
|
|
&ControllersWindow::OnWiimoteModeChanged);
|
2017-05-09 16:49:10 +00:00
|
|
|
connect(m_wiimote_buttons[i], &QPushButton::clicked, this,
|
|
|
|
&ControllersWindow::OnWiimoteConfigure);
|
|
|
|
|
|
|
|
connect(m_gc_controller_boxes[i],
|
|
|
|
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&ControllersWindow::SaveSettings);
|
|
|
|
connect(m_gc_controller_boxes[i],
|
|
|
|
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&ControllersWindow::OnGCTypeChanged);
|
|
|
|
connect(m_gc_buttons[i], &QPushButton::clicked, this, &ControllersWindow::OnGCPadConfigure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 00:50:05 +00:00
|
|
|
void ControllersWindow::OnWiimoteModeChanged()
|
2017-05-09 16:49:10 +00:00
|
|
|
{
|
|
|
|
SaveSettings();
|
|
|
|
|
2020-01-22 00:50:05 +00:00
|
|
|
// Make sure continuous scanning setting is applied.
|
|
|
|
WiimoteReal::Initialize(::Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2020-01-22 00:50:05 +00:00
|
|
|
UpdateDisabledWiimoteControls();
|
|
|
|
}
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2020-01-22 00:50:05 +00:00
|
|
|
void ControllersWindow::UpdateDisabledWiimoteControls()
|
|
|
|
{
|
|
|
|
const bool running = Core::GetState() != Core::State::Uninitialized;
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2020-01-22 00:50:05 +00:00
|
|
|
m_wiimote_emu->setEnabled(!running);
|
|
|
|
m_wiimote_passthrough->setEnabled(!running);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2020-01-22 00:50:05 +00:00
|
|
|
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);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < m_wiimote_groups.size(); i++)
|
|
|
|
{
|
2020-01-22 00:50:05 +00:00
|
|
|
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);
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
2018-05-13 10:16:30 +00:00
|
|
|
|
2020-01-22 00:50:05 +00:00
|
|
|
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);
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControllersWindow::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 int index = box->currentIndex();
|
|
|
|
m_gc_buttons[i]->setEnabled(index != 0 && index != 6);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-05-13 10:16:30 +00:00
|
|
|
|
|
|
|
SaveSettings();
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControllersWindow::OnBluetoothPassthroughResetPressed()
|
|
|
|
{
|
|
|
|
const auto ios = IOS::HLE::GetIOS();
|
|
|
|
|
|
|
|
if (!ios)
|
|
|
|
{
|
2019-03-04 19:49:00 +00:00
|
|
|
ModalMessageBox::warning(
|
|
|
|
this, tr("Warning"),
|
|
|
|
tr("Saved Wii Remote pairings can only be reset when a Wii game is running."));
|
2017-05-09 16:49:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto device = ios->GetDeviceByName("/dev/usb/oh1/57e/305");
|
|
|
|
if (device != nullptr)
|
|
|
|
{
|
|
|
|
std::static_pointer_cast<IOS::HLE::Device::BluetoothBase>(device)->TriggerSyncButtonHeldEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllersWindow::OnBluetoothPassthroughSyncPressed()
|
|
|
|
{
|
|
|
|
const auto ios = IOS::HLE::GetIOS();
|
|
|
|
|
|
|
|
if (!ios)
|
|
|
|
{
|
2019-03-04 19:49:00 +00:00
|
|
|
ModalMessageBox::warning(this, tr("Warning"),
|
|
|
|
tr("A sync can only be triggered when a Wii game is running."));
|
2017-05-09 16:49:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto device = ios->GetDeviceByName("/dev/usb/oh1/57e/305");
|
|
|
|
|
|
|
|
if (device != nullptr)
|
|
|
|
{
|
|
|
|
std::static_pointer_cast<IOS::HLE::Device::BluetoothBase>(device)
|
|
|
|
->TriggerSyncButtonPressedEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-15 03:14:45 +00:00
|
|
|
void ControllersWindow::OnWiimoteRefreshPressed()
|
|
|
|
{
|
|
|
|
WiimoteReal::Refresh();
|
|
|
|
}
|
|
|
|
|
2017-05-09 16:49:10 +00:00
|
|
|
void ControllersWindow::OnGCPadConfigure()
|
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
for (index = 0; index < m_gc_groups.size(); index++)
|
|
|
|
{
|
|
|
|
if (m_gc_buttons[index] == QObject::sender())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:53:17 +00:00
|
|
|
MappingWindow::Type type;
|
|
|
|
|
2017-05-09 16:49:10 +00:00
|
|
|
switch (m_gc_controller_boxes[index]->currentIndex())
|
|
|
|
{
|
|
|
|
case 0: // None
|
|
|
|
case 6: // GBA
|
|
|
|
return;
|
|
|
|
case 1: // Standard Controller
|
2017-05-20 15:53:17 +00:00
|
|
|
type = MappingWindow::Type::MAPPING_GCPAD;
|
|
|
|
break;
|
2017-05-09 16:49:10 +00:00
|
|
|
case 2: // GameCube Adapter for Wii U
|
2017-11-05 01:45:37 +00:00
|
|
|
GCPadWiiUConfigDialog(static_cast<int>(index), this).exec();
|
2017-11-03 21:47:36 +00:00
|
|
|
return;
|
2017-05-09 16:49:10 +00:00
|
|
|
case 3: // Steering Wheel
|
2017-05-20 15:53:17 +00:00
|
|
|
type = MappingWindow::Type::MAPPING_GC_STEERINGWHEEL;
|
|
|
|
break;
|
2017-05-09 16:49:10 +00:00
|
|
|
case 4: // Dance Mat
|
2017-05-20 15:53:17 +00:00
|
|
|
type = MappingWindow::Type::MAPPING_GC_DANCEMAT;
|
|
|
|
break;
|
2017-05-09 16:49:10 +00:00
|
|
|
case 5: // DK Bongos
|
2017-05-20 15:53:17 +00:00
|
|
|
type = MappingWindow::Type::MAPPING_GC_BONGOS;
|
|
|
|
break;
|
2017-05-09 16:49:10 +00:00
|
|
|
case 7: // Keyboard
|
2017-05-20 15:53:17 +00:00
|
|
|
type = MappingWindow::Type::MAPPING_GC_KEYBOARD;
|
|
|
|
break;
|
|
|
|
default:
|
2017-05-09 16:49:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-11-03 21:31:17 +00:00
|
|
|
|
2019-05-09 00:04:46 +00:00
|
|
|
MappingWindow* window = new MappingWindow(this, type, static_cast<int>(index));
|
|
|
|
window->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
window->setWindowModality(Qt::WindowModality::WindowModal);
|
|
|
|
window->show();
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControllersWindow::OnWiimoteConfigure()
|
|
|
|
{
|
|
|
|
size_t index;
|
|
|
|
for (index = 0; index < m_wiimote_groups.size(); index++)
|
|
|
|
{
|
|
|
|
if (m_wiimote_buttons[index] == QObject::sender())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:53:17 +00:00
|
|
|
MappingWindow::Type type;
|
2017-05-09 16:49:10 +00:00
|
|
|
switch (m_wiimote_boxes[index]->currentIndex())
|
|
|
|
{
|
|
|
|
case 0: // None
|
|
|
|
case 2: // Real Wii Remote
|
|
|
|
return;
|
|
|
|
case 1: // Emulated Wii Remote
|
2017-05-20 15:53:17 +00:00
|
|
|
type = MappingWindow::Type::MAPPING_WIIMOTE_EMU;
|
|
|
|
break;
|
|
|
|
default:
|
2017-05-09 16:49:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-11-03 21:31:17 +00:00
|
|
|
|
2019-05-09 00:04:46 +00:00
|
|
|
MappingWindow* window = new MappingWindow(this, type, static_cast<int>(index));
|
|
|
|
window->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
window->setWindowModality(Qt::WindowModality::WindowModal);
|
|
|
|
window->show();
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
2019-10-22 23:49:48 +00:00
|
|
|
void ControllersWindow::OnControllerInterfaceConfigure()
|
|
|
|
{
|
|
|
|
ControllerInterfaceWindow* window = new ControllerInterfaceWindow(this);
|
|
|
|
window->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
window->setWindowModality(Qt::WindowModality::WindowModal);
|
|
|
|
window->show();
|
|
|
|
}
|
|
|
|
|
2017-05-09 16:49:10 +00:00
|
|
|
void ControllersWindow::LoadSettings()
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < m_wiimote_groups.size(); i++)
|
|
|
|
{
|
2018-05-02 16:34:13 +00:00
|
|
|
const std::optional<int> gc_index = ToGCMenuIndex(SConfig::GetInstance().m_SIDevice[i]);
|
|
|
|
if (gc_index)
|
2018-11-23 09:46:14 +00:00
|
|
|
{
|
2018-05-02 16:34:13 +00:00
|
|
|
m_gc_controller_boxes[i]->setCurrentIndex(*gc_index);
|
2018-11-23 09:46:14 +00:00
|
|
|
m_gc_buttons[i]->setEnabled(*gc_index != 0 && *gc_index != 6);
|
|
|
|
}
|
2020-01-22 00:50:05 +00:00
|
|
|
m_wiimote_boxes[i]->setCurrentIndex(int(WiimoteCommon::GetSource(u32(i))));
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
2019-11-13 00:50:16 +00:00
|
|
|
m_wiimote_real_balance_board->setChecked(WiimoteCommon::GetSource(WIIMOTE_BALANCE_BOARD) ==
|
|
|
|
WiimoteSource::Real);
|
2017-06-22 22:11:53 +00:00
|
|
|
m_wiimote_speaker_data->setChecked(SConfig::GetInstance().m_WiimoteEnableSpeaker);
|
2020-01-22 00:50:05 +00:00
|
|
|
m_wiimote_ciface->setChecked(SConfig::GetInstance().connect_wiimotes_for_ciface);
|
2017-06-22 22:11:53 +00:00
|
|
|
m_wiimote_continuous_scanning->setChecked(SConfig::GetInstance().m_WiimoteContinuousScanning);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2019-10-21 23:43:37 +00:00
|
|
|
m_common_bg_input->setChecked(SConfig::GetInstance().m_BackgroundInput);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2017-06-22 22:11:53 +00:00
|
|
|
if (SConfig::GetInstance().m_bt_passthrough_enabled)
|
2017-05-09 16:49:10 +00:00
|
|
|
m_wiimote_passthrough->setChecked(true);
|
|
|
|
else
|
|
|
|
m_wiimote_emu->setChecked(true);
|
|
|
|
|
2020-01-22 00:50:05 +00:00
|
|
|
OnWiimoteModeChanged();
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControllersWindow::SaveSettings()
|
|
|
|
{
|
2017-06-22 22:11:53 +00:00
|
|
|
SConfig::GetInstance().m_WiimoteEnableSpeaker = m_wiimote_speaker_data->isChecked();
|
2020-01-22 00:50:05 +00:00
|
|
|
SConfig::GetInstance().connect_wiimotes_for_ciface = m_wiimote_ciface->isChecked();
|
2017-06-22 22:11:53 +00:00
|
|
|
SConfig::GetInstance().m_WiimoteContinuousScanning = m_wiimote_continuous_scanning->isChecked();
|
|
|
|
SConfig::GetInstance().m_bt_passthrough_enabled = m_wiimote_passthrough->isChecked();
|
2019-10-21 23:43:37 +00:00
|
|
|
SConfig::GetInstance().m_BackgroundInput = m_common_bg_input->isChecked();
|
2017-05-09 16:49:10 +00:00
|
|
|
|
2019-11-13 00:50:16 +00:00
|
|
|
WiimoteCommon::SetSource(WIIMOTE_BALANCE_BOARD, m_wiimote_real_balance_board->isChecked() ?
|
|
|
|
WiimoteSource::Real :
|
|
|
|
WiimoteSource::None);
|
2017-05-09 16:49:10 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < m_wiimote_groups.size(); i++)
|
|
|
|
{
|
2020-01-22 00:50:05 +00:00
|
|
|
const int index = m_wiimote_boxes[i]->currentIndex();
|
|
|
|
WiimoteCommon::SetSource(u32(i), WiimoteSource(index));
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UICommon::SaveWiimoteSources();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < m_gc_groups.size(); i++)
|
|
|
|
{
|
|
|
|
const int index = m_gc_controller_boxes[i]->currentIndex();
|
2018-05-02 16:34:13 +00:00
|
|
|
const std::optional<SerialInterface::SIDevices> si_device = FromGCMenuIndex(index);
|
|
|
|
if (si_device)
|
2018-05-13 10:16:30 +00:00
|
|
|
{
|
2018-05-02 16:34:13 +00:00
|
|
|
SConfig::GetInstance().m_SIDevice[i] = *si_device;
|
2018-05-13 10:16:30 +00:00
|
|
|
|
|
|
|
if (Core::IsRunning())
|
|
|
|
SerialInterface::ChangeDevice(*si_device, static_cast<s32>(i));
|
|
|
|
}
|
|
|
|
|
2017-05-09 16:49:10 +00:00
|
|
|
m_gc_buttons[i]->setEnabled(index != 0 && index != 6);
|
|
|
|
}
|
2018-05-28 01:11:27 +00:00
|
|
|
|
|
|
|
if (GCAdapter::UseAdapter())
|
|
|
|
GCAdapter::StartScanThread();
|
|
|
|
else
|
|
|
|
GCAdapter::StopScanThread();
|
|
|
|
|
2017-06-22 22:11:53 +00:00
|
|
|
SConfig::GetInstance().SaveSettings();
|
2017-05-09 16:49:10 +00:00
|
|
|
}
|