Qt: Implement GC TAS input window

This commit is contained in:
Rukai 2018-01-28 00:35:02 +11:00 committed by Lucas Kent
parent 1e8f4ce84f
commit 3f1ffbad0d
13 changed files with 509 additions and 0 deletions

View File

@ -96,6 +96,7 @@ set(SRCS
QtUtils/ElidedButton.cpp
QtUtils/ListTabWidget.cpp
QtUtils/WindowActivationEventFilter.cpp
QtUtils/AspectRatioWidget.cpp
Settings/AdvancedPane.cpp
Settings/AudioPane.cpp
Settings/GameCubePane.cpp
@ -104,6 +105,8 @@ set(SRCS
Settings/PathPane.cpp
Settings/WiiPane.cpp
Settings/USBDeviceAddToWhitelistDialog.cpp
TAS/GCTASInputWindow.cpp
TAS/StickWidget.cpp
)
list(APPEND LIBS core uicommon)

View File

@ -86,6 +86,8 @@
<QtMoc Include="Config\PropertiesDialog.h" />
<QtMoc Include="Config\SettingsWindow.h" />
<QtMoc Include="FIFOPlayerWindow.h" />
<QtMoc Include="TAS\GCTASInputWindow.h" />
<QtMoc Include="TAS\StickWidget.h" />
<QtMoc Include="Debugger\BreakpointWidget.h" />
<QtMoc Include="Debugger\NewBreakpointDialog.h" />
<QtMoc Include="Debugger\RegisterWidget.h" />
@ -112,6 +114,7 @@
<QtMoc Include="NetPlay\PadMappingDialog.h" />
<QtMoc Include="QtUtils\DoubleClickEventFilter.h" />
<QtMoc Include="QtUtils\WindowActivationEventFilter.h" />
<QtMoc Include="QtUtils\AspectRatioWidget.h" />
<QtMoc Include="RenderWidget.h" />
<QtMoc Include="Settings.h" />
<QtMoc Include="Settings\AdvancedPane.h" />
@ -131,6 +134,8 @@
<ClCompile Include="$(QtMocOutPrefix)ControllersWindow.cpp" />
<ClCompile Include="$(QtMocOutPrefix)EnhancementsWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)FIFOPlayerWindow.cpp" />
<ClCompile Include="$(QtMocOutPrefix)GCTASInputWindow.cpp" />
<ClCompile Include="$(QtMocOutPrefix)StickWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)FilesystemWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)WindowActivationEventFilter.cpp" />
<ClCompile Include="$(QtMocOutPrefix)GameList.cpp" />
@ -220,6 +225,8 @@
<ClCompile Include="Config\PropertiesDialog.cpp" />
<ClCompile Include="Config\SettingsWindow.cpp" />
<ClCompile Include="FIFOPlayerWindow.cpp" />
<ClCompile Include="TAS\GCTASInputWindow.cpp" />
<ClCompile Include="TAS\StickWidget.cpp" />
<ClCompile Include="Debugger\BreakpointWidget.cpp" />
<ClCompile Include="Debugger\NewBreakpointDialog.cpp" />
<ClCompile Include="Debugger\RegisterColumn.cpp" />
@ -249,6 +256,7 @@
<ClCompile Include="QtUtils\ElidedButton.cpp" />
<ClCompile Include="QtUtils\ListTabWidget.cpp" />
<ClCompile Include="QtUtils\WindowActivationEventFilter.cpp" />
<ClCompile Include="QtUtils\AspectRatioWidget.cpp" />
<ClCompile Include="RenderWidget.cpp" />
<ClCompile Include="Resources.cpp" />
<ClCompile Include="Settings.cpp" />

View File

@ -64,6 +64,7 @@
#include "DolphinQt2/QtUtils/WindowActivationEventFilter.h"
#include "DolphinQt2/Resources.h"
#include "DolphinQt2/Settings.h"
#include "DolphinQt2/TAS/GCTASInputWindow.h"
#include "DolphinQt2/WiiUpdate.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
@ -167,6 +168,14 @@ void MainWindow::CreateComponents()
m_controllers_window = new ControllersWindow(this);
m_settings_window = new SettingsWindow(this);
std::generate(m_gc_tas_input_windows.begin(), m_gc_tas_input_windows.end(),
[this] { return new GCTASInputWindow(this); });
Movie::SetGCInputManip([this](GCPadStatus* pad_status, int controller_id) {
m_gc_tas_input_windows[controller_id]->GetValues(pad_status);
});
// TODO: create wii input windows
m_hotkey_window = new MappingWindow(this, MappingWindow::Type::MAPPING_HOTKEYS, 0);
m_log_widget = new LogWidget(this);
@ -249,6 +258,7 @@ void MainWindow::ConnectMenuBar()
connect(m_menu_bar, &MenuBar::StartRecording, this, &MainWindow::OnStartRecording);
connect(m_menu_bar, &MenuBar::StopRecording, this, &MainWindow::OnStopRecording);
connect(m_menu_bar, &MenuBar::ExportRecording, this, &MainWindow::OnExportRecording);
connect(m_menu_bar, &MenuBar::ShowTASInput, this, &MainWindow::ShowTASInput);
// View
connect(m_menu_bar, &MenuBar::ShowList, m_game_list, &GameList::SetListView);
@ -1079,6 +1089,24 @@ void MainWindow::OnExportRecording()
Movie::SaveRecording(dtm_file.toStdString());
}
void MainWindow::ShowTASInput()
{
for (int i = 0; i < 4; i++)
{
if (SConfig::GetInstance().m_SIDevice[i] != SerialInterface::SIDEVICE_NONE &&
SConfig::GetInstance().m_SIDevice[i] != SerialInterface::SIDEVICE_GC_GBA)
{
m_gc_tas_input_windows[i]->show();
m_gc_tas_input_windows[i]->raise();
m_gc_tas_input_windows[i]->activateWindow();
m_gc_tas_input_windows[i]->setWindowTitle(
tr("TAS Input - Gamecube Controller %1").arg(i + 1));
}
}
// TODO: show wii input windows
}
void MainWindow::OnConnectWiiRemote(int id)
{
const auto ios = IOS::HLE::GetIOS();

View File

@ -34,6 +34,7 @@ class DragEnterEvent;
class GraphicsWindow;
class RegisterWidget;
class WatchWidget;
class GCTASInputWindow;
class MainWindow final : public QMainWindow
{
@ -120,6 +121,7 @@ private:
void OnStartRecording();
void OnStopRecording();
void OnExportRecording();
void ShowTASInput();
void EnableScreenSaver(bool enable);
@ -146,6 +148,7 @@ private:
NetPlayDialog* m_netplay_dialog;
NetPlaySetupDialog* m_netplay_setup_dialog;
GraphicsWindow* m_graphics_window;
std::array<GCTASInputWindow*, 4> m_gc_tas_input_windows{};
BreakpointWidget* m_breakpoint_widget;
LogWidget* m_log_widget;

View File

@ -488,6 +488,8 @@ void MenuBar::AddMovieMenu()
m_recording_read_only->setChecked(Movie::IsReadOnly());
connect(m_recording_read_only, &QAction::toggled, [](bool value) { Movie::SetReadOnly(value); });
AddAction(movie_menu, tr("TAS Input"), this, [this] { emit ShowTASInput(); });
movie_menu->addSeparator();
auto* pause_at_end = movie_menu->addAction(tr("Pause at End of Movie"));

View File

@ -87,6 +87,7 @@ signals:
void StartRecording();
void StopRecording();
void ExportRecording();
void ShowTASInput();
void SelectionChanged(QSharedPointer<GameFile> game_file);
void RecordingStatusChanged(bool recording);

View File

@ -0,0 +1,45 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
// Based on:
// https://stackoverflow.com/questions/30005540/keeping-the-aspect-ratio-of-a-sub-classed-qwidget-during-resize
#include "DolphinQt2/QtUtils/AspectRatioWidget.h"
#include <QBoxLayout>
#include <QResizeEvent>
AspectRatioWidget::AspectRatioWidget(QWidget* widget, float width, float height, QWidget* parent)
: QWidget(parent), m_ar_width(width), m_ar_height(height)
{
m_layout = new QBoxLayout(QBoxLayout::LeftToRight, this);
// add spacer, then your widget, then spacer
m_layout->addItem(new QSpacerItem(0, 0));
m_layout->addWidget(widget);
m_layout->addItem(new QSpacerItem(0, 0));
}
void AspectRatioWidget::resizeEvent(QResizeEvent* event)
{
float this_aspect_ratio = (float)event->size().width() / event->size().height();
int widget_stretch, outer_stretch;
if (this_aspect_ratio > (m_ar_width / m_ar_height)) // too wide
{
m_layout->setDirection(QBoxLayout::LeftToRight);
widget_stretch = height() * (m_ar_width / m_ar_height); // i.e., my width
outer_stretch = (width() - widget_stretch) / 2 + 0.5;
}
else // too tall
{
m_layout->setDirection(QBoxLayout::TopToBottom);
widget_stretch = width() * (m_ar_height / m_ar_width); // i.e., my height
outer_stretch = (height() - widget_stretch) / 2 + 0.5;
}
m_layout->setStretch(0, outer_stretch);
m_layout->setStretch(1, widget_stretch);
m_layout->setStretch(2, outer_stretch);
}

View File

@ -0,0 +1,21 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <QWidget>
class QBoxLayout;
class AspectRatioWidget : public QWidget
{
public:
AspectRatioWidget(QWidget* widget, float width, float height, QWidget* parent = 0);
void resizeEvent(QResizeEvent* event);
private:
QBoxLayout* m_layout;
float m_ar_width;
float m_ar_height;
};

View 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();
}

View 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;
};

View 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;
}

View 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();
}

View 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;
};