| 1 | // Copyright 2018 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include "DolphinQt/TAS/GCTASInputWindow.h" |
| 5 | |
| 6 | #include <QCheckBox> |
| 7 | #include <QGridLayout> |
| 8 | #include <QGroupBox> |
| 9 | #include <QHBoxLayout> |
| 10 | #include <QSpacerItem> |
| 11 | #include <QSpinBox> |
| 12 | #include <QStyle> |
| 13 | #include <QVBoxLayout> |
| 14 | |
| 15 | #include "Core/HW/GCPad.h" |
| 16 | #include "Core/HW/GCPadEmu.h" |
| 17 | |
| 18 | #include "DolphinQt/TAS/TASCheckBox.h" |
| 19 | |
| 20 | #include "InputCommon/ControllerEmu/ControllerEmu.h" |
| 21 | #include "InputCommon/InputConfig.h" |
| 22 | |
| 23 | #include "DolphinQt/QtUtils/AspectRatioWidget.h" |
| 24 | |
| 25 | GCTASInputWindow::GCTASInputWindow(QWidget* parent, int controller_id) |
| 26 | : TASInputWindow(parent), m_controller_id(controller_id) |
| 27 | { |
| 28 | setWindowTitle(tr("GameCube TAS Input %1").arg(controller_id + 1)); |
| 29 | |
| 30 | m_main_stick_box = CreateStickInputs(tr("Main Stick"), GCPad::MAIN_STICK_GROUP, &m_overrider, 1, |
| 31 | 1, 255, 255, Qt::Key_F, Qt::Key_G); |
| 32 | m_c_stick_box = CreateStickInputs(tr("C Stick"), GCPad::C_STICK_GROUP, &m_overrider, 1, 1, 255, |
| 33 | 255, Qt::Key_H, Qt::Key_J); |
| 34 | |
| 35 | auto* top_layout = new QHBoxLayout; |
| 36 | top_layout->addWidget(new AspectRatioWidget(m_main_stick_box, 1, 1.02f)); |
| 37 | top_layout->addWidget(new AspectRatioWidget(m_c_stick_box, 1, 1.02f)); |
| 38 | |
| 39 | m_triggers_box = new QGroupBox(tr("Triggers")); |
| 40 | |
| 41 | auto* l_trigger_layout = |
| 42 | CreateSliderValuePairLayout(tr("Left"), GCPad::TRIGGERS_GROUP, GCPad::L_ANALOG, &m_overrider, |
| 43 | 0, 0, 0, 255, Qt::Key_N, m_triggers_box); |
| 44 | |
| 45 | auto* r_trigger_layout = |
| 46 | CreateSliderValuePairLayout(tr("Right"), GCPad::TRIGGERS_GROUP, GCPad::R_ANALOG, &m_overrider, |
| 47 | 0, 0, 0, 255, Qt::Key_M, m_triggers_box); |
| 48 | |
| 49 | auto* triggers_layout = new QVBoxLayout; |
| 50 | triggers_layout->addLayout(l_trigger_layout); |
| 51 | triggers_layout->addLayout(r_trigger_layout); |
| 52 | m_triggers_box->setLayout(triggers_layout); |
| 53 | |
| 54 | m_a_button = |
| 55 | CreateButton(QStringLiteral("&A"), GCPad::BUTTONS_GROUP, GCPad::A_BUTTON, &m_overrider); |
| 56 | m_b_button = |
| 57 | CreateButton(QStringLiteral("&B"), GCPad::BUTTONS_GROUP, GCPad::B_BUTTON, &m_overrider); |
| 58 | m_x_button = |
| 59 | CreateButton(QStringLiteral("&X"), GCPad::BUTTONS_GROUP, GCPad::X_BUTTON, &m_overrider); |
| 60 | m_y_button = |
| 61 | CreateButton(QStringLiteral("&Y"), GCPad::BUTTONS_GROUP, GCPad::Y_BUTTON, &m_overrider); |
| 62 | m_z_button = |
| 63 | CreateButton(QStringLiteral("&Z"), GCPad::BUTTONS_GROUP, GCPad::Z_BUTTON, &m_overrider); |
| 64 | m_start_button = CreateButton(QStringLiteral("&START"), GCPad::BUTTONS_GROUP, GCPad::START_BUTTON, |
| 65 | &m_overrider); |
| 66 | |
| 67 | m_l_button = |
| 68 | CreateButton(QStringLiteral("&L"), GCPad::TRIGGERS_GROUP, GCPad::L_DIGITAL, &m_overrider); |
| 69 | m_r_button = |
| 70 | CreateButton(QStringLiteral("&R"), GCPad::TRIGGERS_GROUP, GCPad::R_DIGITAL, &m_overrider); |
| 71 | |
| 72 | m_left_button = |
| 73 | CreateButton(QStringLiteral("L&eft"), GCPad::DPAD_GROUP, DIRECTION_LEFT, &m_overrider); |
| 74 | m_up_button = CreateButton(QStringLiteral("&Up"), GCPad::DPAD_GROUP, DIRECTION_UP, &m_overrider); |
| 75 | m_down_button = |
| 76 | CreateButton(QStringLiteral("&Down"), GCPad::DPAD_GROUP, DIRECTION_DOWN, &m_overrider); |
| 77 | m_right_button = |
| 78 | CreateButton(QStringLiteral("R&ight"), GCPad::DPAD_GROUP, DIRECTION_RIGHT, &m_overrider); |
| 79 | |
| 80 | auto* buttons_layout = new QGridLayout; |
| 81 | buttons_layout->addWidget(m_a_button, 0, 0); |
| 82 | buttons_layout->addWidget(m_b_button, 0, 1); |
| 83 | buttons_layout->addWidget(m_x_button, 0, 2); |
| 84 | buttons_layout->addWidget(m_y_button, 0, 3); |
| 85 | buttons_layout->addWidget(m_z_button, 0, 4); |
| 86 | buttons_layout->addWidget(m_l_button, 0, 5); |
| 87 | buttons_layout->addWidget(m_r_button, 0, 6); |
| 88 | |
| 89 | buttons_layout->addWidget(m_start_button, 1, 0); |
| 90 | buttons_layout->addWidget(m_left_button, 1, 1); |
| 91 | buttons_layout->addWidget(m_up_button, 1, 2); |
| 92 | buttons_layout->addWidget(m_down_button, 1, 3); |
| 93 | buttons_layout->addWidget(m_right_button, 1, 4); |
| 94 | |
| 95 | buttons_layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding), 0, 7); |
| 96 | |
| 97 | m_buttons_box = new QGroupBox(tr("Buttons")); |
| 98 | m_buttons_box->setLayout(buttons_layout); |
| 99 | |
| 100 | auto* layout = new QVBoxLayout; |
| 101 | layout->addLayout(top_layout); |
| 102 | layout->addWidget(m_triggers_box); |
| 103 | layout->addWidget(m_buttons_box); |
| 104 | layout->addWidget(m_settings_box); |
| 105 | |
| 106 | SetupScrollArea(layout); |
| 107 | const QSize hint = m_scroll_widget->sizeHint(); |
| 108 | const int scrollbar_buffer = style()->pixelMetric(QStyle::PM_ScrollBarExtent) + 10; |
| 109 | resize(hint.width() + scrollbar_buffer, hint.height() + scrollbar_buffer); |
| 110 | } |
| 111 | |
| 112 | void GCTASInputWindow::hideEvent(QHideEvent* event) |
| 113 | { |
| 114 | Pad::GetConfig()->GetController(m_controller_id)->ClearInputOverrideFunction(); |
| 115 | } |
| 116 | |
| 117 | void GCTASInputWindow::showEvent(QShowEvent* event) |
| 118 | { |
| 119 | Pad::GetConfig() |
| 120 | ->GetController(m_controller_id) |
| 121 | ->SetInputOverrideFunction(m_overrider.GetInputOverrideFunction()); |
| 122 | } |