mirror of https://github.com/stenzek/duckstation
GameList: Merge multi-disc games
parent
9bdf23cba7
commit
1adaea9005
@ -0,0 +1,89 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
|
||||||
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||||
|
|
||||||
|
#include "selectdiscdialog.h"
|
||||||
|
#include "qtutils.h"
|
||||||
|
|
||||||
|
#include "core/game_list.h"
|
||||||
|
|
||||||
|
#include "common/assert.h"
|
||||||
|
#include "common/path.h"
|
||||||
|
|
||||||
|
#include <QtWidgets/QTreeWidget>
|
||||||
|
|
||||||
|
SelectDiscDialog::SelectDiscDialog(const std::string& disc_set_name, QWidget* parent /* = nullptr */) : QDialog(parent)
|
||||||
|
{
|
||||||
|
m_ui.setupUi(this);
|
||||||
|
populateList(disc_set_name);
|
||||||
|
updateStartEnabled();
|
||||||
|
|
||||||
|
connect(m_ui.select, &QPushButton::clicked, this, &SelectDiscDialog::onSelectClicked);
|
||||||
|
connect(m_ui.cancel, &QPushButton::clicked, this, &SelectDiscDialog::onCancelClicked);
|
||||||
|
connect(m_ui.discList, &QTreeWidget::itemActivated, this, &SelectDiscDialog::onListItemActivated);
|
||||||
|
connect(m_ui.discList, &QTreeWidget::itemSelectionChanged, this, &SelectDiscDialog::updateStartEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
SelectDiscDialog::~SelectDiscDialog() = default;
|
||||||
|
|
||||||
|
void SelectDiscDialog::resizeEvent(QResizeEvent* ev)
|
||||||
|
{
|
||||||
|
QDialog::resizeEvent(ev);
|
||||||
|
|
||||||
|
QtUtils::ResizeColumnsForTreeView(m_ui.discList, {50, -1, 100});
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectDiscDialog::onListItemActivated(const QTreeWidgetItem* item)
|
||||||
|
{
|
||||||
|
if (!item)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_selected_path = item->data(0, Qt::UserRole).toString().toStdString();
|
||||||
|
done(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectDiscDialog::updateStartEnabled()
|
||||||
|
{
|
||||||
|
const QList<QTreeWidgetItem*> items = m_ui.discList->selectedItems();
|
||||||
|
m_ui.select->setEnabled(!items.isEmpty());
|
||||||
|
if (!items.isEmpty())
|
||||||
|
m_selected_path = items.first()->data(0, Qt::UserRole).toString().toStdString();
|
||||||
|
else
|
||||||
|
m_selected_path = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectDiscDialog::onSelectClicked()
|
||||||
|
{
|
||||||
|
done(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectDiscDialog::onCancelClicked()
|
||||||
|
{
|
||||||
|
done(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectDiscDialog::populateList(const std::string& disc_set_name)
|
||||||
|
{
|
||||||
|
const auto lock = GameList::GetLock();
|
||||||
|
const std::vector<const GameList::Entry*> entries = GameList::GetDiscSetMembers(disc_set_name);
|
||||||
|
const GameList::Entry* last_played_entry = nullptr;
|
||||||
|
|
||||||
|
for (const GameList::Entry* entry : entries)
|
||||||
|
{
|
||||||
|
QTreeWidgetItem* item = new QTreeWidgetItem();
|
||||||
|
item->setData(0, Qt::UserRole, QString::fromStdString(entry->path));
|
||||||
|
item->setIcon(0, QtUtils::GetIconForEntryType(GameList::EntryType::Disc));
|
||||||
|
item->setText(0, QString::number(entry->disc_set_index + 1));
|
||||||
|
item->setText(1, QtUtils::StringViewToQString(Path::GetFileName(entry->path)));
|
||||||
|
item->setText(2, QtUtils::StringViewToQString(GameList::FormatTimestamp(entry->last_played_time)));
|
||||||
|
m_ui.discList->addTopLevelItem(item);
|
||||||
|
|
||||||
|
if (!last_played_entry ||
|
||||||
|
(entry->last_played_time > 0 && entry->last_played_time > last_played_entry->last_played_time))
|
||||||
|
{
|
||||||
|
last_played_entry = entry;
|
||||||
|
m_ui.discList->setCurrentItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setWindowTitle(tr("Select Disc for %1").arg(QString::fromStdString(disc_set_name)));
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
|
||||||
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "common/timer.h"
|
||||||
|
#include "common/types.h"
|
||||||
|
#include "qtprogresscallback.h"
|
||||||
|
#include "ui_selectdiscdialog.h"
|
||||||
|
#include <QtWidgets/QDialog>
|
||||||
|
#include <array>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class SelectDiscDialog final : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
SelectDiscDialog(const std::string& disc_set_name, QWidget* parent = nullptr);
|
||||||
|
~SelectDiscDialog();
|
||||||
|
|
||||||
|
ALWAYS_INLINE const std::string& getSelectedDiscPath() { return m_selected_path; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void resizeEvent(QResizeEvent* ev);
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onListItemActivated(const QTreeWidgetItem* item);
|
||||||
|
void updateStartEnabled();
|
||||||
|
void onSelectClicked();
|
||||||
|
void onCancelClicked();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void populateList(const std::string& disc_set_name);
|
||||||
|
|
||||||
|
Ui::SelectDiscDialog m_ui;
|
||||||
|
std::string m_selected_path;
|
||||||
|
};
|
||||||
@ -0,0 +1,84 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>SelectDiscDialog</class>
|
||||||
|
<widget class="QDialog" name="SelectDiscDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>553</width>
|
||||||
|
<height>206</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Select the disc that you want to boot.</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTreeWidget" name="discList">
|
||||||
|
<property name="rootIsDecorated">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Disc</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>File Name</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Last Played</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<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="select">
|
||||||
|
<property name="text">
|
||||||
|
<string>Select</string>
|
||||||
|
</property>
|
||||||
|
<property name="default">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="cancel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Cancel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Loading…
Reference in New Issue