Qt: Add game properties dialog

This commit is contained in:
Connor McLaughlin 2020-05-16 20:02:44 +10:00
parent d781de2ce6
commit b2a2366287
13 changed files with 524 additions and 1 deletions

View File

@ -18,6 +18,9 @@ add_executable(duckstation-qt
gamelistsettingswidget.ui
gamelistwidget.cpp
gamelistwidget.h
gamepropertiesdialog.cpp
gamepropertiesdialog.h
gamepropertiesdialog.ui
generalsettingswidget.cpp
generalsettingswidget.h
generalsettingswidget.ui

View File

@ -46,6 +46,7 @@
<ClCompile Include="qtdisplaywidget.cpp" />
<ClCompile Include="gamelistsettingswidget.cpp" />
<ClCompile Include="gamelistwidget.cpp" />
<ClCompile Include="gamepropertiesdialog.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="mainwindow.cpp" />
<ClCompile Include="openglhostdisplay.cpp" />
@ -73,6 +74,7 @@
<QtMoc Include="consolesettingswidget.h" />
<QtMoc Include="gamelistsettingswidget.h" />
<QtMoc Include="gamelistwidget.h" />
<QtMoc Include="gamepropertiesdialog.h" />
<QtMoc Include="mainwindow.h" />
<ClInclude Include="openglhostdisplay.h" />
<QtMoc Include="qthostinterface.h" />
@ -128,6 +130,9 @@
<QtUi Include="advancedsettingswidget.ui">
<FileType>Document</FileType>
</QtUi>
<QtUi Include="gamepropertiesdialog.ui">
<FileType>Document</FileType>
</QtUi>
</ItemGroup>
<ItemGroup>
<QtResource Include="resources\icons.qrc">
@ -140,6 +145,7 @@
<ClCompile Include="$(IntDir)moc_consolesettingswidget.cpp" />
<ClCompile Include="$(IntDir)moc_gamelistsettingswidget.cpp" />
<ClCompile Include="$(IntDir)moc_gamelistwidget.cpp" />
<ClCompile Include="$(IntDir)moc_gamepropertiesdialog.cpp" />
<ClCompile Include="$(IntDir)moc_generalsettingswidget.cpp" />
<ClCompile Include="$(IntDir)moc_gpusettingswidget.cpp" />
<ClCompile Include="$(IntDir)moc_hotkeysettingswidget.cpp" />

View File

@ -0,0 +1,231 @@
#include "gamepropertiesdialog.h"
#include "common/cd_image.h"
#include "core/game_list.h"
#include "core/settings.h"
#include "qthostinterface.h"
#include "qtutils.h"
#include "scmversion/scmversion.h"
#include <QtWidgets/QMessageBox>
GamePropertiesDialog::GamePropertiesDialog(QtHostInterface* host_interface, QWidget* parent /* = nullptr */)
: QDialog(parent), m_host_interface(host_interface)
{
m_ui.setupUi(this);
setupAdditionalUi();
connectUi();
}
GamePropertiesDialog::~GamePropertiesDialog() = default;
void GamePropertiesDialog::clear()
{
m_ui.imagePath->clear();
m_ui.gameCode->clear();
m_ui.title->clear();
m_ui.region->setCurrentIndex(0);
{
QSignalBlocker blocker(m_ui.compatibility);
m_ui.compatibility->setCurrentIndex(0);
}
{
QSignalBlocker blocker(m_ui.upscalingIssues);
m_ui.upscalingIssues->clear();
}
{
QSignalBlocker blocker(m_ui.comments);
m_ui.comments->clear();
}
m_ui.tracks->clearContents();
}
void GamePropertiesDialog::populate(const GameListEntry* ge)
{
const QString title_qstring(QString::fromStdString(ge->title));
setWindowTitle(tr("Game Properties - %1").arg(title_qstring));
m_ui.imagePath->setText(QString::fromStdString(ge->path));
m_ui.title->setText(title_qstring);
m_ui.gameCode->setText(QString::fromStdString(ge->code));
m_ui.region->setCurrentIndex(static_cast<int>(ge->region));
if (ge->code.empty())
{
// can't fill in info without a code
m_ui.compatibility->setDisabled(true);
m_ui.upscalingIssues->setDisabled(true);
m_ui.versionTested->setDisabled(true);
}
else
{
populateCompatibilityInfo(ge->code);
}
populateTracksInfo(ge->path.c_str());
}
void GamePropertiesDialog::populateCompatibilityInfo(const std::string& game_code)
{
const GameListCompatibilityEntry* entry = m_host_interface->getGameList()->GetCompatibilityEntryForCode(game_code);
{
QSignalBlocker blocker(m_ui.compatibility);
m_ui.compatibility->setCurrentIndex(entry ? static_cast<int>(entry->compatibility_rating) : 0);
}
{
QSignalBlocker blocker(m_ui.upscalingIssues);
m_ui.upscalingIssues->setText(entry ? QString::fromStdString(entry->upscaling_issues) : QString());
}
{
QSignalBlocker blocker(m_ui.comments);
m_ui.comments->setText(entry ? QString::fromStdString(entry->comments) : QString());
}
}
void GamePropertiesDialog::setupAdditionalUi()
{
for (u8 i = 0; i < static_cast<u8>(DiscRegion::Count); i++)
m_ui.region->addItem(tr(Settings::GetDiscRegionDisplayName(static_cast<DiscRegion>(i))));
for (int i = 0; i < static_cast<int>(GameListCompatibilityRating::Count); i++)
{
m_ui.compatibility->addItem(
tr(GameList::GetGameListCompatibilityRatingString(static_cast<GameListCompatibilityRating>(i))));
}
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
}
void GamePropertiesDialog::showForEntry(QtHostInterface* host_interface, const GameListEntry* ge)
{
GamePropertiesDialog* gpd = new GamePropertiesDialog(host_interface);
gpd->populate(ge);
gpd->show();
gpd->onResize();
}
static QString MSFTotString(const CDImage::Position& position)
{
return QStringLiteral("%1:%2:%3 (LBA %4)")
.arg(static_cast<uint>(position.minute), 2, 10, static_cast<QChar>('0'))
.arg(static_cast<uint>(position.second), 2, 10, static_cast<QChar>('0'))
.arg(static_cast<uint>(position.frame), 2, 10, static_cast<QChar>('0'))
.arg(static_cast<ulong>(position.ToLBA()));
}
void GamePropertiesDialog::populateTracksInfo(const char* image_path)
{
static constexpr std::array<const char*, 8> track_mode_strings = {
{"Audio", "Mode 1", "Mode 1/Raw", "Mode 2", "Mode 2/Form 1", "Mode 2/Form 2", "Mode 2/Mix", "Mode 2/Raw"}};
m_ui.tracks->clearContents();
std::unique_ptr<CDImage> image = CDImage::Open(image_path);
if (!image)
return;
const u32 num_tracks = image->GetTrackCount();
for (u32 track = 1; track <= num_tracks; track++)
{
const CDImage::Position position = image->GetTrackStartMSFPosition(static_cast<u8>(track));
const CDImage::Position length = image->GetTrackMSFLength(static_cast<u8>(track));
const CDImage::TrackMode mode = image->GetTrackMode(static_cast<u8>(track));
const int row = static_cast<int>(track - 1u);
m_ui.tracks->insertRow(row);
m_ui.tracks->setItem(row, 0, new QTableWidgetItem(tr("%1").arg(track)));
m_ui.tracks->setItem(row, 1, new QTableWidgetItem(tr(track_mode_strings[static_cast<u32>(mode)])));
m_ui.tracks->setItem(row, 2, new QTableWidgetItem(MSFTotString(position)));
m_ui.tracks->setItem(row, 3, new QTableWidgetItem(MSFTotString(length)));
m_ui.tracks->setItem(row, 4, new QTableWidgetItem(tr("<not computed>")));
}
}
void GamePropertiesDialog::closeEvent(QCloseEvent* ev)
{
deleteLater();
}
void GamePropertiesDialog::resizeEvent(QResizeEvent* ev)
{
QDialog::resizeEvent(ev);
onResize();
}
void GamePropertiesDialog::onResize()
{
QtUtils::ResizeColumnsForTableView(m_ui.tracks, {20, 85, 125, 125, -1});
}
void GamePropertiesDialog::connectUi()
{
connect(m_ui.compatibility, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&GamePropertiesDialog::saveCompatibilityInfo);
connect(m_ui.comments, &QLineEdit::textChanged, this, &GamePropertiesDialog::setCompatibilityInfoChanged);
connect(m_ui.comments, &QLineEdit::editingFinished, this, &GamePropertiesDialog::saveCompatibilityInfoIfChanged);
connect(m_ui.upscalingIssues, &QLineEdit::textChanged, this, &GamePropertiesDialog::setCompatibilityInfoChanged);
connect(m_ui.upscalingIssues, &QLineEdit::editingFinished, this,
&GamePropertiesDialog::saveCompatibilityInfoIfChanged);
connect(m_ui.setToCurrent, &QPushButton::clicked, this, &GamePropertiesDialog::onSetVersionTestedToCurrentClicked);
connect(m_ui.computeHashes, &QPushButton::clicked, this, &GamePropertiesDialog::onComputeHashClicked);
connect(m_ui.verifyDump, &QPushButton::clicked, this, &GamePropertiesDialog::onVerifyDumpClicked);
connect(m_ui.exportCompatibilityInfo, &QPushButton::clicked, this,
&GamePropertiesDialog::onExportCompatibilityInfoClicked);
connect(m_ui.close, &QPushButton::clicked, this, &QDialog::close);
}
void GamePropertiesDialog::saveCompatibilityInfo()
{
GameListCompatibilityEntry new_entry;
new_entry.code = m_ui.gameCode->text().toStdString();
new_entry.title = m_ui.title->text().toStdString();
new_entry.version_tested = m_ui.versionTested->text().toStdString();
new_entry.upscaling_issues = m_ui.upscalingIssues->text().toStdString();
new_entry.comments = m_ui.comments->text().toStdString();
new_entry.compatibility_rating = static_cast<GameListCompatibilityRating>(m_ui.compatibility->currentIndex());
new_entry.region = static_cast<DiscRegion>(m_ui.region->currentIndex());
if (new_entry.code.empty())
return;
m_host_interface->getGameList()->UpdateCompatibilityEntry(std::move(new_entry), true);
emit m_host_interface->gameListRefreshed();
m_compatibility_info_changed = false;
}
void GamePropertiesDialog::saveCompatibilityInfoIfChanged()
{
if (!m_compatibility_info_changed)
return;
saveCompatibilityInfo();
}
void GamePropertiesDialog::setCompatibilityInfoChanged()
{
m_compatibility_info_changed = true;
}
void GamePropertiesDialog::onSetVersionTestedToCurrentClicked()
{
m_ui.versionTested->setText(QString::fromUtf8(g_scm_tag_str));
saveCompatibilityInfo();
}
void GamePropertiesDialog::onComputeHashClicked()
{
QMessageBox::critical(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
void GamePropertiesDialog::onVerifyDumpClicked()
{
QMessageBox::critical(this, tr("Not yet implemented"), tr("Not yet implemented"));
}
void GamePropertiesDialog::onExportCompatibilityInfoClicked()
{
QMessageBox::critical(this, tr("Not yet implemented"), tr("Not yet implemented"));
}

View File

@ -0,0 +1,50 @@
#pragma once
#include "ui_gamepropertiesdialog.h"
#include <QtCore/QMap>
#include <QtWidgets/QDialog>
struct GameListEntry;
class QtHostInterface;
class GamePropertiesDialog final : public QDialog
{
Q_OBJECT
public:
GamePropertiesDialog(QtHostInterface* host_interface, QWidget* parent = nullptr);
~GamePropertiesDialog();
static void showForEntry(QtHostInterface* host_interface, const GameListEntry* ge);
public Q_SLOTS:
void clear();
void populate(const GameListEntry* ge);
protected:
void closeEvent(QCloseEvent* ev);
void resizeEvent(QResizeEvent* ev);
private Q_SLOTS:
void saveCompatibilityInfo();
void saveCompatibilityInfoIfChanged();
void setCompatibilityInfoChanged();
void onSetVersionTestedToCurrentClicked();
void onComputeHashClicked();
void onVerifyDumpClicked();
void onExportCompatibilityInfoClicked();
private:
void setupAdditionalUi();
void connectUi();
void populateCompatibilityInfo(const std::string& game_code);
void populateTracksInfo(const char* image_path);
void onResize();
Ui::GamePropertiesDialog m_ui;
QtHostInterface* m_host_interface;
bool m_compatibility_info_changed = false;
};

View File

@ -0,0 +1,225 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GamePropertiesDialog</class>
<widget class="QDialog" name="GamePropertiesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>722</width>
<height>466</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="windowIcon">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/duck.png</normaloff>:/icons/duck.png</iconset>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Image Path:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="imagePath">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Game Code:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="gameCode">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Title:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="title">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Region:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="region">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Compatibility:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="compatibility"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Upscaling Issues:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="upscalingIssues"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Comments:</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="computeHashes">
<property name="text">
<string>Compute Hashes</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="verifyDump">
<property name="text">
<string>Verify Dump</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="exportCompatibilityInfo">
<property name="text">
<string>Export Compatibility Info</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="close">
<property name="text">
<string>Close</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Tracks:</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QTableWidget" name="tracks">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="cornerButtonEnabled">
<bool>false</bool>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>#</string>
</property>
</column>
<column>
<property name="text">
<string>Mode</string>
</property>
</column>
<column>
<property name="text">
<string>Start</string>
</property>
</column>
<column>
<property name="text">
<string>Length</string>
</property>
</column>
<column>
<property name="text">
<string>Hash</string>
</property>
</column>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="comments"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Version Tested:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLineEdit" name="versionTested"/>
</item>
<item>
<widget class="QPushButton" name="setToCurrent">
<property name="text">
<string>Set to Current</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -5,6 +5,7 @@
#include "core/system.h"
#include "gamelistsettingswidget.h"
#include "gamelistwidget.h"
#include "gamepropertiesdialog.h"
#include "qtdisplaywidget.h"
#include "qthostdisplay.h"
#include "qthostinterface.h"
@ -347,7 +348,8 @@ void MainWindow::onGameListContextMenuRequested(const QPoint& point, const GameL
// Hopefully this pointer doesn't disappear... it shouldn't.
if (entry)
{
connect(menu.addAction(tr("Properties...")), &QAction::triggered, [this]() { reportError(tr("TODO")); });
connect(menu.addAction(tr("Properties...")), &QAction::triggered,
[this, entry]() { GamePropertiesDialog::showForEntry(m_host_interface, entry); });
connect(menu.addAction(tr("Open Containing Directory...")), &QAction::triggered, [this, entry]() {
const QFileInfo fi(QString::fromStdString(entry->path));

View File

@ -6,6 +6,12 @@
<file>icons/flag-jp.svg</file>
<file>icons/flag-us.png</file>
<file>icons/flag-us.svg</file>
<file>icons/star-0.png</file>
<file>icons/star-1.png</file>
<file>icons/star-2.png</file>
<file>icons/star-3.png</file>
<file>icons/star-4.png</file>
<file>icons/star-5.png</file>
<file>icons/applications-internet.png</file>
<file>icons/system-search.png</file>
<file>icons/list-add.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB