2017-07-21 20:48:21 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-07-21 20:48:21 +00:00
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/NetPlay/PadMappingDialog.h"
|
2017-07-21 20:48:21 +00:00
|
|
|
|
2021-07-04 11:33:58 +00:00
|
|
|
#include <QCheckBox>
|
2017-07-21 20:48:21 +00:00
|
|
|
#include <QComboBox>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QLabel>
|
2018-08-23 11:11:52 +00:00
|
|
|
#include <QSignalBlocker>
|
2017-07-21 20:48:21 +00:00
|
|
|
|
2018-07-09 04:45:27 +00:00
|
|
|
#include "Core/NetPlayClient.h"
|
|
|
|
#include "Core/NetPlayServer.h"
|
|
|
|
|
|
|
|
#include "DolphinQt/Settings.h"
|
|
|
|
|
2017-07-21 20:48:21 +00:00
|
|
|
PadMappingDialog::PadMappingDialog(QWidget* parent) : QDialog(parent)
|
|
|
|
{
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2018-05-14 07:00:40 +00:00
|
|
|
setWindowTitle(tr("Assign Controllers"));
|
2017-07-21 20:48:21 +00:00
|
|
|
|
|
|
|
CreateWidgets();
|
|
|
|
ConnectWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PadMappingDialog::CreateWidgets()
|
|
|
|
{
|
|
|
|
m_main_layout = new QGridLayout;
|
|
|
|
m_button_box = new QDialogButtonBox(QDialogButtonBox::Ok);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < m_wii_boxes.size(); i++)
|
|
|
|
{
|
|
|
|
m_gc_boxes[i] = new QComboBox;
|
2021-07-04 11:33:58 +00:00
|
|
|
m_gba_boxes[i] = new QCheckBox(tr("GBA Port %1").arg(i + 1));
|
2017-07-21 20:48:21 +00:00
|
|
|
m_wii_boxes[i] = new QComboBox;
|
|
|
|
|
|
|
|
m_main_layout->addWidget(new QLabel(tr("GC Port %1").arg(i + 1)), 0, i);
|
|
|
|
m_main_layout->addWidget(m_gc_boxes[i], 1, i);
|
2021-07-04 11:33:58 +00:00
|
|
|
#ifdef HAS_LIBMGBA
|
|
|
|
m_main_layout->addWidget(m_gba_boxes[i], 2, i);
|
|
|
|
#endif
|
|
|
|
m_main_layout->addWidget(new QLabel(tr("Wii Remote %1").arg(i + 1)), 3, i);
|
|
|
|
m_main_layout->addWidget(m_wii_boxes[i], 4, i);
|
2017-07-21 20:48:21 +00:00
|
|
|
}
|
|
|
|
|
2021-07-04 11:33:58 +00:00
|
|
|
m_main_layout->addWidget(m_button_box, 5, 0, 1, -1);
|
2017-07-21 20:48:21 +00:00
|
|
|
|
|
|
|
setLayout(m_main_layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PadMappingDialog::ConnectWidgets()
|
|
|
|
{
|
|
|
|
connect(m_button_box, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
2019-07-30 13:35:46 +00:00
|
|
|
for (const auto& combo_group : {m_gc_boxes, m_wii_boxes})
|
2018-06-27 11:20:50 +00:00
|
|
|
{
|
2019-07-30 13:35:46 +00:00
|
|
|
for (const auto& combo : combo_group)
|
2018-06-27 11:20:50 +00:00
|
|
|
{
|
2023-11-04 21:01:39 +00:00
|
|
|
connect(combo, &QComboBox::currentIndexChanged, this, &PadMappingDialog::OnMappingChanged);
|
2018-06-27 11:20:50 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-04 11:33:58 +00:00
|
|
|
for (const auto& checkbox : m_gba_boxes)
|
|
|
|
{
|
2023-11-04 21:01:39 +00:00
|
|
|
connect(checkbox, &QCheckBox::stateChanged, this, &PadMappingDialog::OnMappingChanged);
|
2021-07-04 11:33:58 +00:00
|
|
|
}
|
2017-07-21 20:48:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int PadMappingDialog::exec()
|
|
|
|
{
|
2018-07-13 00:37:12 +00:00
|
|
|
auto client = Settings::Instance().GetNetPlayClient();
|
|
|
|
auto server = Settings::Instance().GetNetPlayServer();
|
2018-06-27 11:20:50 +00:00
|
|
|
// Load Settings
|
|
|
|
m_players = client->GetPlayers();
|
|
|
|
m_pad_mapping = server->GetPadMapping();
|
2021-07-04 11:33:58 +00:00
|
|
|
m_gba_config = server->GetGBAConfig();
|
2018-06-27 11:20:50 +00:00
|
|
|
m_wii_mapping = server->GetWiimoteMapping();
|
2017-07-21 20:48:21 +00:00
|
|
|
|
|
|
|
QStringList players;
|
|
|
|
|
|
|
|
players.append(tr("None"));
|
|
|
|
|
|
|
|
for (const auto& player : m_players)
|
2018-06-04 19:10:19 +00:00
|
|
|
{
|
|
|
|
players.append(
|
|
|
|
QStringLiteral("%1 (%2)").arg(QString::fromStdString(player->name)).arg(player->pid));
|
|
|
|
}
|
2017-07-21 20:48:21 +00:00
|
|
|
|
|
|
|
for (auto& combo_group : {m_gc_boxes, m_wii_boxes})
|
|
|
|
{
|
2018-06-27 11:20:50 +00:00
|
|
|
bool gc = combo_group == m_gc_boxes;
|
|
|
|
for (size_t i = 0; i < combo_group.size(); i++)
|
2017-07-21 20:48:21 +00:00
|
|
|
{
|
2018-06-27 11:20:50 +00:00
|
|
|
auto& combo = combo_group[i];
|
2018-08-23 11:11:52 +00:00
|
|
|
const QSignalBlocker blocker(combo);
|
2018-06-27 11:20:50 +00:00
|
|
|
|
2017-07-21 20:48:21 +00:00
|
|
|
combo->clear();
|
|
|
|
combo->addItems(players);
|
2018-06-27 11:20:50 +00:00
|
|
|
|
|
|
|
const auto index = gc ? m_pad_mapping[i] : m_wii_mapping[i];
|
|
|
|
|
2018-11-19 10:30:39 +00:00
|
|
|
combo->setCurrentIndex(index);
|
2017-07-21 20:48:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-04 11:33:58 +00:00
|
|
|
for (size_t i = 0; i < m_gba_boxes.size(); i++)
|
|
|
|
{
|
|
|
|
const QSignalBlocker blocker(m_gba_boxes[i]);
|
|
|
|
|
|
|
|
m_gba_boxes[i]->setChecked(m_gba_config[i].enabled);
|
|
|
|
}
|
|
|
|
|
2017-07-21 20:48:21 +00:00
|
|
|
return QDialog::exec();
|
|
|
|
}
|
2018-07-06 23:39:42 +00:00
|
|
|
|
|
|
|
NetPlay::PadMappingArray PadMappingDialog::GetGCPadArray()
|
2017-07-21 20:48:21 +00:00
|
|
|
{
|
|
|
|
return m_pad_mapping;
|
|
|
|
}
|
|
|
|
|
2021-07-04 11:33:58 +00:00
|
|
|
NetPlay::GBAConfigArray PadMappingDialog::GetGBAArray()
|
|
|
|
{
|
|
|
|
return m_gba_config;
|
|
|
|
}
|
|
|
|
|
2018-07-06 23:39:42 +00:00
|
|
|
NetPlay::PadMappingArray PadMappingDialog::GetWiimoteArray()
|
2017-07-21 20:48:21 +00:00
|
|
|
{
|
|
|
|
return m_wii_mapping;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PadMappingDialog::OnMappingChanged()
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < m_wii_boxes.size(); i++)
|
|
|
|
{
|
|
|
|
int gc_id = m_gc_boxes[i]->currentIndex();
|
|
|
|
int wii_id = m_wii_boxes[i]->currentIndex();
|
|
|
|
|
2018-11-19 10:30:39 +00:00
|
|
|
m_pad_mapping[i] = gc_id > 0 ? m_players[gc_id - 1]->pid : 0;
|
2021-07-04 11:33:58 +00:00
|
|
|
m_gba_config[i].enabled = m_gba_boxes[i]->isChecked();
|
2018-11-19 10:30:39 +00:00
|
|
|
m_wii_mapping[i] = wii_id > 0 ? m_players[wii_id - 1]->pid : 0;
|
2017-07-21 20:48:21 +00:00
|
|
|
}
|
|
|
|
}
|