-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Copy pathPadMappingDialog.cpp
141 lines (113 loc) · 3.61 KB
/
PadMappingDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2017 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "DolphinQt/NetPlay/PadMappingDialog.h"
#include <QCheckBox>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QLabel>
#include <QSignalBlocker>
#include "Core/NetPlayClient.h"
#include "Core/NetPlayServer.h"
#include "DolphinQt/Settings.h"
PadMappingDialog::PadMappingDialog(QWidget* parent) : QDialog(parent)
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setWindowTitle(tr("Assign Controllers"));
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_gba_boxes[i] = new QCheckBox(tr("GBA Port %1").arg(i + 1));
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);
#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);
}
m_main_layout->addWidget(m_button_box, 5, 0, 1, -1);
setLayout(m_main_layout);
}
void PadMappingDialog::ConnectWidgets()
{
connect(m_button_box, &QDialogButtonBox::accepted, this, &QDialog::accept);
for (const auto& combo_group : {m_gc_boxes, m_wii_boxes})
{
for (const auto& combo : combo_group)
{
connect(combo, &QComboBox::currentIndexChanged, this, &PadMappingDialog::OnMappingChanged);
}
}
for (const auto& checkbox : m_gba_boxes)
{
connect(checkbox, &QCheckBox::stateChanged, this, &PadMappingDialog::OnMappingChanged);
}
}
int PadMappingDialog::exec()
{
const auto client = Settings::Instance().GetNetPlayClient();
const auto server = Settings::Instance().GetNetPlayServer();
// Load Settings
m_players = client->GetPlayers();
m_pad_mapping = server->GetPadMapping();
m_gba_config = server->GetGBAConfig();
m_wii_mapping = server->GetWiimoteMapping();
QStringList players;
players.append(tr("None"));
for (const auto& player : m_players)
{
players.append(
QStringLiteral("%1 (%2)").arg(QString::fromStdString(player->name)).arg(player->pid));
}
for (auto& combo_group : {m_gc_boxes, m_wii_boxes})
{
const bool gc = combo_group == m_gc_boxes;
for (size_t i = 0; i < combo_group.size(); i++)
{
auto& combo = combo_group[i];
const QSignalBlocker blocker(combo);
combo->clear();
combo->addItems(players);
const auto index = gc ? m_pad_mapping[i] : m_wii_mapping[i];
combo->setCurrentIndex(index);
}
}
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);
}
return QDialog::exec();
}
NetPlay::PadMappingArray PadMappingDialog::GetGCPadArray()
{
return m_pad_mapping;
}
NetPlay::GBAConfigArray PadMappingDialog::GetGBAArray()
{
return m_gba_config;
}
NetPlay::PadMappingArray PadMappingDialog::GetWiimoteArray()
{
return m_wii_mapping;
}
void PadMappingDialog::OnMappingChanged()
{
for (unsigned int i = 0; i < m_wii_boxes.size(); i++)
{
const int gc_id = m_gc_boxes[i]->currentIndex();
const int wii_id = m_wii_boxes[i]->currentIndex();
m_pad_mapping[i] = gc_id > 0 ? m_players[gc_id - 1]->pid : 0;
m_gba_config[i].enabled = m_gba_boxes[i]->isChecked();
m_wii_mapping[i] = wii_id > 0 ? m_players[wii_id - 1]->pid : 0;
}
}