mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Qt: Implement GC TAS input window
This commit is contained in:
121
Source/Core/DolphinQt2/TAS/GCTASInputWindow.cpp
Normal file
121
Source/Core/DolphinQt2/TAS/GCTASInputWindow.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
// Copyright 2018 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "DolphinQt2/TAS/GCTASInputWindow.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "DolphinQt2/TAS/Shared.h"
|
||||
#include "InputCommon/GCPadStatus.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
GCTASInputWindow::GCTASInputWindow(QWidget* parent) : QDialog(parent)
|
||||
{
|
||||
auto* main_stick_box = CreateStickInputs(this, tr("Main Stick ALT+F/G"), &m_x_main_stick_byte,
|
||||
&m_y_main_stick_byte, 255, 255, Qt::Key_F, Qt::Key_G);
|
||||
auto* c_stick_box = CreateStickInputs(this, tr("C Stick ALT+H/J"), &m_x_c_stick_byte,
|
||||
&m_y_c_stick_byte, 255, 255, Qt::Key_H, Qt::Key_J);
|
||||
|
||||
auto* top_layout = new QHBoxLayout;
|
||||
top_layout->addWidget(main_stick_box);
|
||||
top_layout->addWidget(c_stick_box);
|
||||
|
||||
auto* l_trigger_layout = new QHBoxLayout;
|
||||
m_l_trigger_byte = CreateTriggerInputs(this, l_trigger_layout, Qt::Key_N, Qt::Horizontal);
|
||||
|
||||
auto* l_trigger_box = new QGroupBox(tr("Left Trigger ALT+N"));
|
||||
l_trigger_box->setLayout(l_trigger_layout);
|
||||
|
||||
auto* r_trigger_layout = new QHBoxLayout;
|
||||
m_r_trigger_byte = CreateTriggerInputs(this, r_trigger_layout, Qt::Key_M, Qt::Horizontal);
|
||||
|
||||
auto* r_trigger_box = new QGroupBox(tr("Right Trigger ALT+M"));
|
||||
r_trigger_box->setLayout(r_trigger_layout);
|
||||
|
||||
m_a_button = new QCheckBox(QStringLiteral("&A"));
|
||||
m_b_button = new QCheckBox(QStringLiteral("&B"));
|
||||
m_x_button = new QCheckBox(QStringLiteral("&X"));
|
||||
m_y_button = new QCheckBox(QStringLiteral("&Y"));
|
||||
m_z_button = new QCheckBox(QStringLiteral("&Z"));
|
||||
m_l_button = new QCheckBox(QStringLiteral("&L"));
|
||||
m_r_button = new QCheckBox(QStringLiteral("&R"));
|
||||
m_start_button = new QCheckBox(QStringLiteral("&START"));
|
||||
m_left_button = new QCheckBox(QStringLiteral("L&eft"));
|
||||
m_up_button = new QCheckBox(QStringLiteral("&Up"));
|
||||
m_down_button = new QCheckBox(QStringLiteral("&Down"));
|
||||
m_right_button = new QCheckBox(QStringLiteral("R&ight"));
|
||||
|
||||
auto* buttons_layout1 = new QHBoxLayout;
|
||||
buttons_layout1->addWidget(m_a_button);
|
||||
buttons_layout1->addWidget(m_b_button);
|
||||
buttons_layout1->addWidget(m_x_button);
|
||||
buttons_layout1->addWidget(m_y_button);
|
||||
buttons_layout1->addWidget(m_z_button);
|
||||
buttons_layout1->addWidget(m_l_button);
|
||||
buttons_layout1->addWidget(m_r_button);
|
||||
|
||||
auto* buttons_layout2 = new QHBoxLayout;
|
||||
buttons_layout2->addWidget(m_start_button);
|
||||
buttons_layout2->addWidget(m_left_button);
|
||||
buttons_layout2->addWidget(m_up_button);
|
||||
buttons_layout2->addWidget(m_down_button);
|
||||
buttons_layout2->addWidget(m_right_button);
|
||||
|
||||
auto* buttons_layout = new QVBoxLayout;
|
||||
buttons_layout->setSizeConstraint(QLayout::SetFixedSize);
|
||||
buttons_layout->addLayout(buttons_layout1);
|
||||
buttons_layout->addLayout(buttons_layout2);
|
||||
|
||||
auto* buttons_box = new QGroupBox(tr("Buttons"));
|
||||
buttons_box->setLayout(buttons_layout);
|
||||
|
||||
auto* layout = new QVBoxLayout;
|
||||
layout->addLayout(top_layout);
|
||||
layout->addWidget(l_trigger_box);
|
||||
layout->addWidget(r_trigger_box);
|
||||
layout->addWidget(buttons_box);
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void GCTASInputWindow::GetValues(GCPadStatus* pad)
|
||||
{
|
||||
if (!isVisible())
|
||||
return;
|
||||
|
||||
SetButton(m_a_button, pad, PAD_BUTTON_A);
|
||||
SetButton(m_b_button, pad, PAD_BUTTON_B);
|
||||
SetButton(m_x_button, pad, PAD_BUTTON_X);
|
||||
SetButton(m_y_button, pad, PAD_BUTTON_Y);
|
||||
SetButton(m_z_button, pad, PAD_TRIGGER_Z);
|
||||
SetButton(m_l_button, pad, PAD_TRIGGER_L);
|
||||
SetButton(m_r_button, pad, PAD_TRIGGER_R);
|
||||
SetButton(m_left_button, pad, PAD_BUTTON_LEFT);
|
||||
SetButton(m_up_button, pad, PAD_BUTTON_UP);
|
||||
SetButton(m_down_button, pad, PAD_BUTTON_DOWN);
|
||||
SetButton(m_right_button, pad, PAD_BUTTON_RIGHT);
|
||||
SetButton(m_start_button, pad, PAD_BUTTON_START);
|
||||
|
||||
if (m_a_button->isChecked())
|
||||
pad->analogA = 0xFF;
|
||||
else
|
||||
pad->analogA = 0x00;
|
||||
|
||||
if (m_b_button->isChecked())
|
||||
pad->analogB = 0xFF;
|
||||
else
|
||||
pad->analogB = 0x00;
|
||||
|
||||
pad->triggerLeft = m_l_trigger_byte->value();
|
||||
pad->triggerRight = m_r_trigger_byte->value();
|
||||
|
||||
pad->stickX = m_x_main_stick_byte->value();
|
||||
pad->stickY = m_y_main_stick_byte->value();
|
||||
pad->substickX = m_x_c_stick_byte->value();
|
||||
pad->substickY = m_y_c_stick_byte->value();
|
||||
}
|
41
Source/Core/DolphinQt2/TAS/GCTASInputWindow.h
Normal file
41
Source/Core/DolphinQt2/TAS/GCTASInputWindow.h
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright 2018 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
class QCheckBox;
|
||||
class QSpinBox;
|
||||
struct GCPadStatus;
|
||||
|
||||
class GCTASInputWindow : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GCTASInputWindow(QWidget* parent);
|
||||
void GetValues(GCPadStatus* pad);
|
||||
|
||||
private:
|
||||
QCheckBox* m_a_button;
|
||||
QCheckBox* m_b_button;
|
||||
QCheckBox* m_x_button;
|
||||
QCheckBox* m_y_button;
|
||||
QCheckBox* m_z_button;
|
||||
QCheckBox* m_l_button;
|
||||
QCheckBox* m_r_button;
|
||||
QCheckBox* m_start_button;
|
||||
QCheckBox* m_left_button;
|
||||
QCheckBox* m_up_button;
|
||||
QCheckBox* m_down_button;
|
||||
QCheckBox* m_right_button;
|
||||
QSpinBox* m_l_trigger_byte;
|
||||
QSpinBox* m_r_trigger_byte;
|
||||
QSpinBox* m_x_main_stick_byte;
|
||||
QSpinBox* m_y_main_stick_byte;
|
||||
QSpinBox* m_x_c_stick_byte;
|
||||
QSpinBox* m_y_c_stick_byte;
|
||||
};
|
112
Source/Core/DolphinQt2/TAS/Shared.h
Normal file
112
Source/Core/DolphinQt2/TAS/Shared.h
Normal file
@ -0,0 +1,112 @@
|
||||
// Copyright 2018 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "DolphinQt2/QtUtils/AspectRatioWidget.h"
|
||||
#include "DolphinQt2/TAS/StickWidget.h"
|
||||
#include "InputCommon/GCPadStatus.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QShortcut>
|
||||
#include <QSlider>
|
||||
#include <QSpinBox>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
QGroupBox* CreateStickInputs(QDialog* window, QString name, QSpinBox** x_byte, QSpinBox** y_byte,
|
||||
u16 max_x, u16 max_y, Qt::Key x_shortcut_key, Qt::Key y_shortcut_key);
|
||||
QSpinBox* CreateTriggerInputs(QDialog* window, QBoxLayout* layout, Qt::Key shortcut_key,
|
||||
Qt::Orientation orientation);
|
||||
QSpinBox* CreateByteBox(QDialog* window);
|
||||
void SetButton(QCheckBox* button, GCPadStatus* pad, u16 mask);
|
||||
|
||||
QGroupBox* CreateStickInputs(QDialog* window, QString name, QSpinBox** x_byte, QSpinBox** y_byte,
|
||||
u16 max_x, u16 max_y, Qt::Key x_shortcut_key, Qt::Key y_shortcut_key)
|
||||
{
|
||||
auto* x_layout = new QHBoxLayout;
|
||||
*x_byte = CreateTriggerInputs(window, x_layout, x_shortcut_key, Qt::Horizontal);
|
||||
|
||||
auto* y_layout = new QVBoxLayout;
|
||||
*y_byte = CreateTriggerInputs(window, y_layout, y_shortcut_key, Qt::Vertical);
|
||||
(*y_byte)->setMaximumWidth(60);
|
||||
|
||||
auto* visual = new StickWidget(window, max_x, max_y);
|
||||
window->connect(*x_byte, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), visual,
|
||||
&StickWidget::SetX);
|
||||
window->connect(*y_byte, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), visual,
|
||||
&StickWidget::SetY);
|
||||
window->connect(visual, &StickWidget::ChangedX, *x_byte, &QSpinBox::setValue);
|
||||
window->connect(visual, &StickWidget::ChangedY, *y_byte, &QSpinBox::setValue);
|
||||
|
||||
(*x_byte)->setValue(max_x / 2);
|
||||
(*y_byte)->setValue(max_y / 2);
|
||||
|
||||
auto* visual_ar = new AspectRatioWidget(visual, max_x, max_y);
|
||||
|
||||
auto* visual_layout = new QHBoxLayout;
|
||||
visual_layout->addWidget(visual_ar);
|
||||
visual_layout->addLayout(y_layout);
|
||||
|
||||
auto* layout = new QVBoxLayout;
|
||||
layout->addLayout(x_layout);
|
||||
layout->addLayout(visual_layout);
|
||||
|
||||
auto* box = new QGroupBox(name);
|
||||
box->setLayout(layout);
|
||||
|
||||
return box;
|
||||
}
|
||||
|
||||
QSpinBox* CreateTriggerInputs(QDialog* window, QBoxLayout* layout, Qt::Key shortcut_key,
|
||||
Qt::Orientation orientation)
|
||||
{
|
||||
auto* byte = CreateByteBox(window);
|
||||
auto* slider = new QSlider(orientation);
|
||||
slider->setRange(0, 255);
|
||||
slider->setFocusPolicy(Qt::ClickFocus);
|
||||
|
||||
window->connect(slider, &QSlider::valueChanged, byte, &QSpinBox::setValue);
|
||||
window->connect(byte, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), slider,
|
||||
&QSlider::setValue);
|
||||
|
||||
auto* shortcut = new QShortcut(QKeySequence(Qt::ALT + shortcut_key), window);
|
||||
window->connect(shortcut, &QShortcut::activated, [byte] {
|
||||
byte->setFocus();
|
||||
byte->selectAll();
|
||||
});
|
||||
|
||||
layout->addWidget(slider);
|
||||
layout->addWidget(byte);
|
||||
if (orientation == Qt::Vertical)
|
||||
layout->setAlignment(slider, Qt::AlignRight);
|
||||
|
||||
return byte;
|
||||
}
|
||||
|
||||
// In cases where there are multiple widgets setup to sync the same value
|
||||
// the spinbox is considered the master that other widgets should set/get from
|
||||
|
||||
QSpinBox* CreateByteBox(QDialog* window)
|
||||
{
|
||||
auto* byte_box = new QSpinBox();
|
||||
byte_box->setRange(0, 9999);
|
||||
window->connect(byte_box, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
|
||||
[byte_box](int i) {
|
||||
if (i > 255)
|
||||
byte_box->setValue(255);
|
||||
});
|
||||
|
||||
return byte_box;
|
||||
}
|
||||
|
||||
void SetButton(QCheckBox* button, GCPadStatus* pad, u16 mask)
|
||||
{
|
||||
if (button->isChecked())
|
||||
pad->button |= mask;
|
||||
else
|
||||
pad->button &= ~mask;
|
||||
}
|
82
Source/Core/DolphinQt2/TAS/StickWidget.cpp
Normal file
82
Source/Core/DolphinQt2/TAS/StickWidget.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
// Copyright 2018 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "DolphinQt2/TAS/StickWidget.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "InputCommon/GCPadStatus.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
StickWidget::StickWidget(QWidget* parent, u16 max_x, u16 max_y) : QWidget(parent)
|
||||
{
|
||||
m_max_x = max_x;
|
||||
m_max_y = max_y;
|
||||
m_x = 0;
|
||||
m_y = 0;
|
||||
|
||||
setMouseTracking(false);
|
||||
}
|
||||
|
||||
void StickWidget::SetX(u16 x)
|
||||
{
|
||||
m_x = std::min(m_max_x, x);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void StickWidget::SetY(u16 y)
|
||||
{
|
||||
m_y = std::min(m_max_y, y);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void StickWidget::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
painter.setBrush(Qt::white);
|
||||
painter.drawEllipse(0, 0, width() - 1, height() - 1);
|
||||
|
||||
painter.drawLine(0, height() / 2, width(), height() / 2);
|
||||
painter.drawLine(width() / 2, 0, width() / 2, height());
|
||||
|
||||
// convert from value space to widget space
|
||||
u16 x = (m_x * width()) / m_max_x;
|
||||
u16 y = height() - (m_y * height()) / m_max_y;
|
||||
|
||||
painter.drawLine(width() / 2, height() / 2, x, y);
|
||||
|
||||
painter.setBrush(Qt::blue);
|
||||
int wh_avg = (width() + height()) / 2;
|
||||
int radius = wh_avg / 30;
|
||||
painter.drawEllipse(x - radius, y - radius, radius * 2, radius * 2);
|
||||
}
|
||||
|
||||
void StickWidget::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
handleMouseEvent(event);
|
||||
}
|
||||
|
||||
void StickWidget::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
handleMouseEvent(event);
|
||||
}
|
||||
|
||||
void StickWidget::handleMouseEvent(QMouseEvent* event)
|
||||
{
|
||||
// convert from widget space to value space
|
||||
int new_x = ((int)event->x() * m_max_x) / width();
|
||||
int new_y = m_max_y - ((int)event->y() * m_max_y) / height();
|
||||
|
||||
m_x = std::max(0, std::min((int)m_max_x, new_x));
|
||||
m_y = std::max(0, std::min((int)m_max_y, new_y));
|
||||
|
||||
emit ChangedX(m_x);
|
||||
emit ChangedY(m_y);
|
||||
update();
|
||||
}
|
42
Source/Core/DolphinQt2/TAS/StickWidget.h
Normal file
42
Source/Core/DolphinQt2/TAS/StickWidget.h
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright 2018 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
class QBoxLayout;
|
||||
class QCheckBox;
|
||||
class QGroupBox;
|
||||
class QSpinBox;
|
||||
struct GCPadStatus;
|
||||
|
||||
class StickWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit StickWidget(QWidget* parent, u16 width, u16 height);
|
||||
|
||||
signals:
|
||||
void ChangedX(u16 x);
|
||||
void ChangedY(u16 y);
|
||||
|
||||
public slots:
|
||||
void SetX(u16 x);
|
||||
void SetY(u16 y);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
void handleMouseEvent(QMouseEvent* event);
|
||||
|
||||
private:
|
||||
u16 m_max_x;
|
||||
u16 m_max_y;
|
||||
u16 m_x;
|
||||
u16 m_y;
|
||||
};
|
Reference in New Issue
Block a user