2024-07-30 11:42:36 +00:00
|
|
|
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
|
|
|
|
// SPDX-License-Identifier: GPL-3.0+
|
2022-06-16 00:44:14 +00:00
|
|
|
|
|
|
|
#include "InputRecordingViewer.h"
|
|
|
|
|
|
|
|
#include "QtUtils.h"
|
2024-06-06 12:51:07 +00:00
|
|
|
#include <QtCore/QDir>
|
2022-06-16 00:44:14 +00:00
|
|
|
#include <QtCore/QString>
|
|
|
|
#include <QtWidgets/QDialog>
|
2024-06-07 12:00:35 +00:00
|
|
|
#include <QtWidgets/QMessageBox>
|
2022-06-16 00:44:14 +00:00
|
|
|
#include <QtWidgets/qfiledialog.h>
|
|
|
|
|
|
|
|
// TODO - for now this uses a very naive implementation that fills the entire table
|
|
|
|
// this needs to be replaced with a lazy-loading QTableView implementation
|
2022-11-26 19:40:17 +00:00
|
|
|
//
|
2022-06-16 00:44:14 +00:00
|
|
|
// For now, especially for just debugging input recording issues, its good enough!
|
|
|
|
|
|
|
|
InputRecordingViewer::InputRecordingViewer(QWidget* parent)
|
|
|
|
: QMainWindow(parent)
|
|
|
|
{
|
|
|
|
m_ui.setupUi(this);
|
|
|
|
|
|
|
|
m_ui.tableWidget->setSelectionMode(QAbstractItemView::NoSelection);
|
|
|
|
|
|
|
|
connect(m_ui.actionOpen, &QAction::triggered, this, &InputRecordingViewer::openFile);
|
2022-11-26 19:40:17 +00:00
|
|
|
connect(m_ui.actionClose, &QAction::triggered, this, &InputRecordingViewer::closeFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
QTableWidgetItem* InputRecordingViewer::createRowItem(std::tuple<u8, u8> analog)
|
|
|
|
{
|
|
|
|
const auto [left, right] = analog;
|
|
|
|
return new QTableWidgetItem(tr("%1 %2").arg(left).arg(right));
|
|
|
|
}
|
|
|
|
|
|
|
|
QTableWidgetItem* InputRecordingViewer::createRowItem(bool pressed)
|
|
|
|
{
|
|
|
|
return new QTableWidgetItem(tr("%1").arg(pressed));
|
|
|
|
}
|
|
|
|
|
|
|
|
QTableWidgetItem* InputRecordingViewer::createRowItem(std::tuple<bool, u8> buttonInfo)
|
|
|
|
{
|
|
|
|
const auto [isPressed, pressure] = buttonInfo;
|
|
|
|
return new QTableWidgetItem(tr("%1 [%2]").arg(isPressed).arg(pressure));
|
2022-06-16 00:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputRecordingViewer::loadTable()
|
|
|
|
{
|
2024-01-18 14:44:17 +00:00
|
|
|
static const auto headers = QStringList({tr("Left Analog"), tr("Right Analog"), tr("Cross"), tr("Square"), tr("Triangle"), tr("Circle"), tr("L1"), tr("R1"), tr("L2"), tr("R2"), tr("D-Pad Down"), tr("D-Pad Right"), tr("D-Pad Up"), tr("D-Pad Left"), tr("L3"), tr("R3"), tr("Select"), tr("Start")});
|
2022-09-22 23:49:48 +00:00
|
|
|
m_ui.tableWidget->setColumnCount(headers.length());
|
|
|
|
m_ui.tableWidget->setHorizontalHeaderLabels(headers);
|
|
|
|
|
2022-06-16 00:44:14 +00:00
|
|
|
// TODO - only port 1 for now
|
2022-11-26 19:40:17 +00:00
|
|
|
auto dataColl = m_file.bulkReadPadData(0, m_file.getTotalFrames(), 0);
|
|
|
|
m_ui.tableWidget->setRowCount(dataColl.size());
|
2022-06-16 00:44:14 +00:00
|
|
|
|
|
|
|
int frameNum = 0;
|
2022-11-26 19:40:17 +00:00
|
|
|
for (const auto& frameData : dataColl)
|
2022-06-16 00:44:14 +00:00
|
|
|
{
|
2022-11-26 19:40:17 +00:00
|
|
|
m_ui.tableWidget->setItem(frameNum, 0, createRowItem(frameData.m_leftAnalog));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 1, createRowItem(frameData.m_rightAnalog));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 2, createRowItem(frameData.m_cross));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 3, createRowItem(frameData.m_square));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 4, createRowItem(frameData.m_triangle));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 5, createRowItem(frameData.m_circle));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 6, createRowItem(frameData.m_l1));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 7, createRowItem(frameData.m_l2));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 8, createRowItem(frameData.m_r1));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 9, createRowItem(frameData.m_r2));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 10, createRowItem(frameData.m_down));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 11, createRowItem(frameData.m_right));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 12, createRowItem(frameData.m_up));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 13, createRowItem(frameData.m_left));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 14, createRowItem(frameData.m_l3));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 15, createRowItem(frameData.m_r3));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 16, createRowItem(frameData.m_select));
|
|
|
|
m_ui.tableWidget->setItem(frameNum, 17, createRowItem(frameData.m_select));
|
2022-06-16 00:44:14 +00:00
|
|
|
frameNum++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 19:40:17 +00:00
|
|
|
void InputRecordingViewer::openFile()
|
|
|
|
{
|
2022-06-16 00:44:14 +00:00
|
|
|
QFileDialog dialog(this);
|
|
|
|
dialog.setFileMode(QFileDialog::ExistingFile);
|
|
|
|
dialog.setWindowTitle("Select a File");
|
|
|
|
dialog.setNameFilter(tr("Input Recording Files (*.p2m2)"));
|
|
|
|
QStringList fileNames;
|
|
|
|
if (dialog.exec())
|
|
|
|
{
|
|
|
|
fileNames = dialog.selectedFiles();
|
|
|
|
}
|
|
|
|
if (!fileNames.isEmpty())
|
|
|
|
{
|
2024-06-06 12:51:07 +00:00
|
|
|
const std::string fileName = QDir::toNativeSeparators(fileNames.first()).toStdString();
|
2022-11-26 19:40:17 +00:00
|
|
|
m_file_open = m_file.openExisting(fileName);
|
|
|
|
m_ui.actionClose->setEnabled(m_file_open);
|
|
|
|
if (m_file_open)
|
|
|
|
{
|
|
|
|
loadTable();
|
2024-06-07 12:00:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Opening Recording Failed"), tr("Failed to open file: %1").arg(QString::fromUtf8(fileName.c_str())));
|
|
|
|
}
|
2022-06-16 00:44:14 +00:00
|
|
|
}
|
2022-11-26 19:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputRecordingViewer::closeFile()
|
|
|
|
{
|
|
|
|
if (m_file_open)
|
|
|
|
{
|
|
|
|
m_file_open = !m_file.close();
|
|
|
|
if (!m_file_open)
|
|
|
|
{
|
|
|
|
m_ui.tableWidget->clearContents();
|
|
|
|
m_ui.tableWidget->setRowCount(0);
|
|
|
|
}
|
|
|
|
} // TODO else error
|
|
|
|
m_ui.actionClose->setEnabled(m_file_open);
|
2024-01-18 14:44:17 +00:00
|
|
|
}
|