2017-07-21 14:48:21 -06:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-06 16:40:15 -06:00
|
|
|
#include "DolphinQt/NetPlay/PadMappingDialog.h"
|
2017-07-21 14:48:21 -06:00
|
|
|
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QLabel>
|
2018-08-23 05:11:52 -06:00
|
|
|
#include <QSignalBlocker>
|
2017-07-21 14:48:21 -06:00
|
|
|
|
2018-07-08 22:45:27 -06:00
|
|
|
#include "Core/NetPlayClient.h"
|
|
|
|
#include "Core/NetPlayServer.h"
|
|
|
|
|
|
|
|
#include "DolphinQt/Settings.h"
|
|
|
|
|
2017-07-21 14:48:21 -06:00
|
|
|
PadMappingDialog::PadMappingDialog(QWidget* parent) : QDialog(parent)
|
|
|
|
{
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2018-05-14 01:00:40 -06:00
|
|
|
setWindowTitle(tr("Assign Controllers"));
|
2017-07-21 14:48:21 -06: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;
|
|
|
|
m_wii_boxes[i] = new QComboBox;
|
|
|
|
|
|
|
|
m_main_layout->addWidget(new QLabel(tr("GC Port %1").arg(i + 1)), 0, i);
|
2017-08-10 03:36:45 -06:00
|
|
|
m_main_layout->addWidget(new QLabel(tr("Wii Remote %1").arg(i + 1)), 0, 4 + i);
|
2017-07-21 14:48:21 -06:00
|
|
|
m_main_layout->addWidget(m_gc_boxes[i], 1, i);
|
|
|
|
m_main_layout->addWidget(m_wii_boxes[i], 1, 4 + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_main_layout->addWidget(m_button_box, 2, 0, 1, -1);
|
|
|
|
|
|
|
|
setLayout(m_main_layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PadMappingDialog::ConnectWidgets()
|
|
|
|
{
|
|
|
|
connect(m_button_box, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
2018-06-27 05:20:50 -06:00
|
|
|
for (auto& combo_group : {m_gc_boxes, m_wii_boxes})
|
|
|
|
{
|
|
|
|
for (auto& combo : combo_group)
|
|
|
|
{
|
|
|
|
connect(combo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&PadMappingDialog::OnMappingChanged);
|
|
|
|
}
|
|
|
|
}
|
2017-07-21 14:48:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int PadMappingDialog::exec()
|
|
|
|
{
|
2018-07-12 18:37:12 -06:00
|
|
|
auto client = Settings::Instance().GetNetPlayClient();
|
|
|
|
auto server = Settings::Instance().GetNetPlayServer();
|
2018-06-27 05:20:50 -06:00
|
|
|
// Load Settings
|
|
|
|
m_players = client->GetPlayers();
|
|
|
|
m_pad_mapping = server->GetPadMapping();
|
|
|
|
m_wii_mapping = server->GetWiimoteMapping();
|
2017-07-21 14:48:21 -06:00
|
|
|
|
|
|
|
QStringList players;
|
|
|
|
|
|
|
|
players.append(tr("None"));
|
|
|
|
|
|
|
|
for (const auto& player : m_players)
|
2018-06-04 13:10:19 -06:00
|
|
|
{
|
|
|
|
players.append(
|
|
|
|
QStringLiteral("%1 (%2)").arg(QString::fromStdString(player->name)).arg(player->pid));
|
|
|
|
}
|
2017-07-21 14:48:21 -06:00
|
|
|
|
|
|
|
for (auto& combo_group : {m_gc_boxes, m_wii_boxes})
|
|
|
|
{
|
2018-06-27 05:20:50 -06:00
|
|
|
bool gc = combo_group == m_gc_boxes;
|
|
|
|
for (size_t i = 0; i < combo_group.size(); i++)
|
2017-07-21 14:48:21 -06:00
|
|
|
{
|
2018-06-27 05:20:50 -06:00
|
|
|
auto& combo = combo_group[i];
|
2018-08-23 05:11:52 -06:00
|
|
|
const QSignalBlocker blocker(combo);
|
2018-06-27 05:20:50 -06:00
|
|
|
|
2017-07-21 14:48:21 -06:00
|
|
|
combo->clear();
|
|
|
|
combo->addItems(players);
|
2018-06-27 05:20:50 -06:00
|
|
|
|
|
|
|
const auto index = gc ? m_pad_mapping[i] : m_wii_mapping[i];
|
|
|
|
|
|
|
|
combo->setCurrentIndex(index == -1 ? 0 : index);
|
2017-07-21 14:48:21 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QDialog::exec();
|
|
|
|
}
|
2018-07-06 17:39:42 -06:00
|
|
|
|
|
|
|
NetPlay::PadMappingArray PadMappingDialog::GetGCPadArray()
|
2017-07-21 14:48:21 -06:00
|
|
|
{
|
|
|
|
return m_pad_mapping;
|
|
|
|
}
|
|
|
|
|
2018-07-06 17:39:42 -06:00
|
|
|
NetPlay::PadMappingArray PadMappingDialog::GetWiimoteArray()
|
2017-07-21 14:48:21 -06: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();
|
|
|
|
|
|
|
|
m_pad_mapping[i] = gc_id > 0 ? m_players[gc_id - 1]->pid : -1;
|
|
|
|
m_wii_mapping[i] = wii_id > 0 ? m_players[wii_id - 1]->pid : -1;
|
|
|
|
}
|
|
|
|
}
|