| 1 | // Copyright 2017 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include "DolphinQt/Config/Mapping/WiimoteEmuExtension.h" |
| 5 | |
| 6 | #include <QGridLayout> |
| 7 | #include <QGroupBox> |
| 8 | #include <QHBoxLayout> |
| 9 | #include <QLabel> |
| 10 | |
| 11 | #include "Core/HW/Wiimote.h" |
| 12 | #include "Core/HW/WiimoteEmu/Extension/Classic.h" |
| 13 | #include "Core/HW/WiimoteEmu/Extension/DrawsomeTablet.h" |
| 14 | #include "Core/HW/WiimoteEmu/Extension/Drums.h" |
| 15 | #include "Core/HW/WiimoteEmu/Extension/Guitar.h" |
| 16 | #include "Core/HW/WiimoteEmu/Extension/Nunchuk.h" |
| 17 | #include "Core/HW/WiimoteEmu/Extension/Shinkansen.h" |
| 18 | #include "Core/HW/WiimoteEmu/Extension/TaTaCon.h" |
| 19 | #include "Core/HW/WiimoteEmu/Extension/Turntable.h" |
| 20 | #include "Core/HW/WiimoteEmu/Extension/UDrawTablet.h" |
| 21 | #include "Core/HW/WiimoteEmu/WiimoteEmu.h" |
| 22 | |
| 23 | #include "InputCommon/InputConfig.h" |
| 24 | |
| 25 | WiimoteEmuExtension::WiimoteEmuExtension(MappingWindow* window) : MappingWidget(window) |
| 26 | { |
| 27 | CreateClassicLayout(); |
| 28 | CreateDrumsLayout(); |
| 29 | CreateGuitarLayout(); |
| 30 | CreateNoneLayout(); |
| 31 | CreateNunchukLayout(); |
| 32 | CreateTurntableLayout(); |
| 33 | CreateUDrawTabletLayout(); |
| 34 | CreateDrawsomeTabletLayout(); |
| 35 | CreateTaTaConLayout(); |
| 36 | CreateShinkansenLayout(); |
| 37 | CreateMainLayout(); |
| 38 | |
| 39 | ChangeExtensionType(WiimoteEmu::ExtensionNumber::NONE); |
| 40 | } |
| 41 | |
| 42 | void WiimoteEmuExtension::CreateClassicLayout() |
| 43 | { |
| 44 | auto* layout = new QGridLayout(); |
| 45 | m_classic_box = new QGroupBox(tr("Classic Controller"), this); |
| 46 | |
| 47 | layout->addWidget( |
| 48 | CreateGroupBox(tr("Buttons"), |
| 49 | Wiimote::GetClassicGroup(GetPort(), WiimoteEmu::ClassicGroup::Buttons)), |
| 50 | 0, 0); |
| 51 | layout->addWidget(CreateGroupBox(tr("D-Pad"), Wiimote::GetClassicGroup( |
| 52 | GetPort(), WiimoteEmu::ClassicGroup::DPad)), |
| 53 | 1, 0); |
| 54 | layout->addWidget( |
| 55 | CreateGroupBox(tr("Left Stick"), |
| 56 | Wiimote::GetClassicGroup(GetPort(), WiimoteEmu::ClassicGroup::LeftStick)), |
| 57 | 0, 1, -1, 1); |
| 58 | layout->addWidget( |
| 59 | CreateGroupBox(tr("Right Stick"), |
| 60 | Wiimote::GetClassicGroup(GetPort(), WiimoteEmu::ClassicGroup::RightStick)), |
| 61 | 0, 2, -1, 1); |
| 62 | layout->addWidget( |
| 63 | CreateGroupBox(tr("Triggers"), |
| 64 | Wiimote::GetClassicGroup(GetPort(), WiimoteEmu::ClassicGroup::Triggers)), |
| 65 | 0, 3, -1, 1); |
| 66 | |
| 67 | m_classic_box->setLayout(layout); |
| 68 | } |
| 69 | |
| 70 | void WiimoteEmuExtension::CreateDrumsLayout() |
| 71 | { |
| 72 | auto* layout = new QGridLayout(); |
| 73 | m_drums_box = new QGroupBox(tr("Drum Kit"), this); |
| 74 | |
| 75 | layout->addWidget( |
| 76 | CreateGroupBox(tr("Stick"), Wiimote::GetDrumsGroup(GetPort(), WiimoteEmu::DrumsGroup::Stick)), |
| 77 | 0, 0, -1, 1); |
| 78 | |
| 79 | layout->addWidget( |
| 80 | CreateGroupBox(tr("Pads"), Wiimote::GetDrumsGroup(GetPort(), WiimoteEmu::DrumsGroup::Pads)), |
| 81 | 0, 1); |
| 82 | layout->addWidget(CreateGroupBox(tr("Buttons"), Wiimote::GetDrumsGroup( |
| 83 | GetPort(), WiimoteEmu::DrumsGroup::Buttons)), |
| 84 | 1, 1); |
| 85 | |
| 86 | m_drums_box->setLayout(layout); |
| 87 | } |
| 88 | |
| 89 | void WiimoteEmuExtension::CreateNoneLayout() |
| 90 | { |
| 91 | m_none_box = new QGroupBox(this); |
| 92 | auto* hbox = new QHBoxLayout(); |
| 93 | auto* label = new QLabel(tr("No extension selected.")); |
| 94 | |
| 95 | label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
| 96 | label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); |
| 97 | hbox->addWidget(label); |
| 98 | m_none_box->setLayout(hbox); |
| 99 | } |
| 100 | |
| 101 | void WiimoteEmuExtension::CreateNunchukLayout() |
| 102 | { |
| 103 | auto* layout = new QGridLayout(); |
| 104 | m_nunchuk_box = new QGroupBox(tr("Nunchuk"), this); |
| 105 | |
| 106 | layout->addWidget(CreateGroupBox(tr("Stick"), Wiimote::GetNunchukGroup( |
| 107 | GetPort(), WiimoteEmu::NunchukGroup::Stick)), |
| 108 | 0, 0); |
| 109 | layout->addWidget( |
| 110 | CreateGroupBox(tr("Buttons"), |
| 111 | Wiimote::GetNunchukGroup(GetPort(), WiimoteEmu::NunchukGroup::Buttons)), |
| 112 | 0, 1); |
| 113 | |
| 114 | m_nunchuk_box->setLayout(layout); |
| 115 | } |
| 116 | |
| 117 | void WiimoteEmuExtension::CreateGuitarLayout() |
| 118 | { |
| 119 | auto* hbox = new QHBoxLayout(); |
| 120 | m_guitar_box = new QGroupBox(tr("Guitar"), this); |
| 121 | |
| 122 | auto* vbox = new QVBoxLayout(); |
| 123 | vbox->addWidget(CreateGroupBox( |
| 124 | tr("Stick"), Wiimote::GetGuitarGroup(GetPort(), WiimoteEmu::GuitarGroup::Stick))); |
| 125 | hbox->addLayout(vbox); |
| 126 | |
| 127 | auto* vbox2 = new QVBoxLayout(); |
| 128 | vbox2->addWidget(CreateGroupBox( |
| 129 | tr("Strum"), Wiimote::GetGuitarGroup(GetPort(), WiimoteEmu::GuitarGroup::Strum))); |
| 130 | vbox2->addWidget(CreateGroupBox( |
| 131 | tr("Frets"), Wiimote::GetGuitarGroup(GetPort(), WiimoteEmu::GuitarGroup::Frets))); |
| 132 | hbox->addLayout(vbox2); |
| 133 | |
| 134 | auto* vbox3 = new QVBoxLayout(); |
| 135 | vbox3->addWidget(CreateGroupBox( |
| 136 | tr("Buttons"), Wiimote::GetGuitarGroup(GetPort(), WiimoteEmu::GuitarGroup::Buttons))); |
| 137 | vbox3->addWidget(CreateGroupBox( |
| 138 | tr("Whammy"), Wiimote::GetGuitarGroup(GetPort(), WiimoteEmu::GuitarGroup::Whammy))); |
| 139 | vbox3->addWidget(CreateGroupBox( |
| 140 | tr("Slider Bar"), Wiimote::GetGuitarGroup(GetPort(), WiimoteEmu::GuitarGroup::SliderBar))); |
| 141 | hbox->addLayout(vbox3); |
| 142 | |
| 143 | m_guitar_box->setLayout(hbox); |
| 144 | } |
| 145 | |
| 146 | void WiimoteEmuExtension::CreateTurntableLayout() |
| 147 | { |
| 148 | auto* layout = new QGridLayout(); |
| 149 | m_turntable_box = new QGroupBox(tr("DJ Turntable"), this); |
| 150 | |
| 151 | layout->addWidget(CreateGroupBox(tr("Stick"), Wiimote::GetTurntableGroup( |
| 152 | GetPort(), WiimoteEmu::TurntableGroup::Stick)), |
| 153 | 0, 0, -1, 1); |
| 154 | |
| 155 | layout->addWidget( |
| 156 | CreateGroupBox(tr("Buttons"), |
| 157 | Wiimote::GetTurntableGroup(GetPort(), WiimoteEmu::TurntableGroup::Buttons)), |
| 158 | 0, 1); |
| 159 | layout->addWidget( |
| 160 | CreateGroupBox(tr("Effect"), |
| 161 | Wiimote::GetTurntableGroup(GetPort(), WiimoteEmu::TurntableGroup::EffectDial)), |
| 162 | 1, 1, -1, 1); |
| 163 | |
| 164 | layout->addWidget( |
| 165 | // i18n: "Table" refers to a turntable |
| 166 | CreateGroupBox(tr("Left Table"), |
| 167 | Wiimote::GetTurntableGroup(GetPort(), WiimoteEmu::TurntableGroup::LeftTable)), |
| 168 | 0, 2); |
| 169 | layout->addWidget(CreateGroupBox( |
| 170 | // i18n: "Table" refers to a turntable |
| 171 | tr("Right Table"), Wiimote::GetTurntableGroup( |
| 172 | GetPort(), WiimoteEmu::TurntableGroup::RightTable)), |
| 173 | 1, 2); |
| 174 | layout->addWidget( |
| 175 | CreateGroupBox(tr("Crossfade"), |
| 176 | Wiimote::GetTurntableGroup(GetPort(), WiimoteEmu::TurntableGroup::Crossfade)), |
| 177 | 2, 2); |
| 178 | |
| 179 | m_turntable_box->setLayout(layout); |
| 180 | } |
| 181 | |
| 182 | void WiimoteEmuExtension::CreateUDrawTabletLayout() |
| 183 | { |
| 184 | auto* hbox = new QHBoxLayout(); |
| 185 | m_udraw_tablet_box = new QGroupBox(tr("uDraw GameTablet"), this); |
| 186 | |
| 187 | hbox->addWidget(CreateGroupBox( |
| 188 | tr("Buttons"), |
| 189 | Wiimote::GetUDrawTabletGroup(GetPort(), WiimoteEmu::UDrawTabletGroup::Buttons))); |
| 190 | |
| 191 | hbox->addWidget(CreateGroupBox( |
| 192 | tr("Stylus"), Wiimote::GetUDrawTabletGroup(GetPort(), WiimoteEmu::UDrawTabletGroup::Stylus))); |
| 193 | |
| 194 | hbox->addWidget(CreateGroupBox( |
| 195 | tr("Touch"), Wiimote::GetUDrawTabletGroup(GetPort(), WiimoteEmu::UDrawTabletGroup::Touch))); |
| 196 | |
| 197 | m_udraw_tablet_box->setLayout(hbox); |
| 198 | } |
| 199 | |
| 200 | void WiimoteEmuExtension::CreateDrawsomeTabletLayout() |
| 201 | { |
| 202 | const auto hbox = new QHBoxLayout(); |
| 203 | m_drawsome_tablet_box = new QGroupBox(tr("Drawsome Tablet"), this); |
| 204 | |
| 205 | hbox->addWidget(CreateGroupBox( |
| 206 | tr("Stylus"), |
| 207 | Wiimote::GetDrawsomeTabletGroup(GetPort(), WiimoteEmu::DrawsomeTabletGroup::Stylus))); |
| 208 | |
| 209 | hbox->addWidget(CreateGroupBox( |
| 210 | tr("Touch"), |
| 211 | Wiimote::GetDrawsomeTabletGroup(GetPort(), WiimoteEmu::DrawsomeTabletGroup::Touch))); |
| 212 | |
| 213 | m_drawsome_tablet_box->setLayout(hbox); |
| 214 | } |
| 215 | |
| 216 | void WiimoteEmuExtension::CreateTaTaConLayout() |
| 217 | { |
| 218 | auto* hbox = new QHBoxLayout(); |
| 219 | m_tatacon_box = new QGroupBox(tr("Taiko Drum"), this); |
| 220 | |
| 221 | hbox->addWidget(CreateGroupBox( |
| 222 | tr("Center"), Wiimote::GetTaTaConGroup(GetPort(), WiimoteEmu::TaTaConGroup::Center))); |
| 223 | hbox->addWidget(CreateGroupBox( |
| 224 | tr("Rim"), Wiimote::GetTaTaConGroup(GetPort(), WiimoteEmu::TaTaConGroup::Rim))); |
| 225 | |
| 226 | m_tatacon_box->setLayout(hbox); |
| 227 | } |
| 228 | |
| 229 | void WiimoteEmuExtension::CreateShinkansenLayout() |
| 230 | { |
| 231 | auto* hbox = new QHBoxLayout(); |
| 232 | m_shinkansen_box = new QGroupBox(tr("Shinkansen"), this); |
| 233 | |
| 234 | hbox->addWidget(CreateGroupBox( |
| 235 | tr("Levers"), Wiimote::GetShinkansenGroup(GetPort(), WiimoteEmu::ShinkansenGroup::Levers))); |
| 236 | hbox->addWidget(CreateGroupBox( |
| 237 | tr("Buttons"), Wiimote::GetShinkansenGroup(GetPort(), WiimoteEmu::ShinkansenGroup::Buttons))); |
| 238 | hbox->addWidget(CreateGroupBox( |
| 239 | tr("Light"), Wiimote::GetShinkansenGroup(GetPort(), WiimoteEmu::ShinkansenGroup::Light))); |
| 240 | |
| 241 | m_shinkansen_box->setLayout(hbox); |
| 242 | } |
| 243 | |
| 244 | void WiimoteEmuExtension::CreateMainLayout() |
| 245 | { |
| 246 | m_main_layout = new QHBoxLayout(); |
| 247 | |
| 248 | m_main_layout->addWidget(m_classic_box); |
| 249 | m_main_layout->addWidget(m_drums_box); |
| 250 | m_main_layout->addWidget(m_guitar_box); |
| 251 | m_main_layout->addWidget(m_none_box); |
| 252 | m_main_layout->addWidget(m_nunchuk_box); |
| 253 | m_main_layout->addWidget(m_turntable_box); |
| 254 | m_main_layout->addWidget(m_udraw_tablet_box); |
| 255 | m_main_layout->addWidget(m_drawsome_tablet_box); |
| 256 | m_main_layout->addWidget(m_tatacon_box); |
| 257 | m_main_layout->addWidget(m_shinkansen_box); |
| 258 | |
| 259 | setLayout(m_main_layout); |
| 260 | } |
| 261 | |
| 262 | void WiimoteEmuExtension::LoadSettings() |
| 263 | { |
| 264 | Wiimote::LoadConfig(); |
| 265 | } |
| 266 | |
| 267 | void WiimoteEmuExtension::SaveSettings() |
| 268 | { |
| 269 | Wiimote::GetConfig()->SaveConfig(); |
| 270 | } |
| 271 | |
| 272 | InputConfig* WiimoteEmuExtension::GetConfig() |
| 273 | { |
| 274 | return Wiimote::GetConfig(); |
| 275 | } |
| 276 | |
| 277 | void WiimoteEmuExtension::ChangeExtensionType(u32 type) |
| 278 | { |
| 279 | using WiimoteEmu::ExtensionNumber; |
| 280 | |
| 281 | m_none_box->setHidden(type != ExtensionNumber::NONE); |
| 282 | m_nunchuk_box->setHidden(type != ExtensionNumber::NUNCHUK); |
| 283 | m_classic_box->setHidden(type != ExtensionNumber::CLASSIC); |
| 284 | m_guitar_box->setHidden(type != ExtensionNumber::GUITAR); |
| 285 | m_drums_box->setHidden(type != ExtensionNumber::DRUMS); |
| 286 | m_turntable_box->setHidden(type != ExtensionNumber::TURNTABLE); |
| 287 | m_udraw_tablet_box->setHidden(type != ExtensionNumber::UDRAW_TABLET); |
| 288 | m_drawsome_tablet_box->setHidden(type != ExtensionNumber::DRAWSOME_TABLET); |
| 289 | m_tatacon_box->setHidden(type != ExtensionNumber::TATACON); |
| 290 | m_shinkansen_box->setHidden(type != ExtensionNumber::SHINKANSEN); |
| 291 | } |