From 81cd2d9be902561a90a105e20abf10566aede5f4 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 7 May 2022 16:32:44 +1000 Subject: [PATCH] Qt: Add placeholder for when no games are in list --- pcsx2-qt/CMakeLists.txt | 1 + pcsx2-qt/GameList/EmptyGameListWidget.ui | 141 +++++++++++++++++++++++ pcsx2-qt/GameList/GameListWidget.cpp | 25 +++- pcsx2-qt/GameList/GameListWidget.h | 6 + pcsx2-qt/MainWindow.cpp | 2 + pcsx2-qt/pcsx2-qt.vcxproj | 3 + pcsx2-qt/pcsx2-qt.vcxproj.filters | 3 + 7 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 pcsx2-qt/GameList/EmptyGameListWidget.ui diff --git a/pcsx2-qt/CMakeLists.txt b/pcsx2-qt/CMakeLists.txt index f1702e01c3..9643bf325f 100644 --- a/pcsx2-qt/CMakeLists.txt +++ b/pcsx2-qt/CMakeLists.txt @@ -30,6 +30,7 @@ target_sources(pcsx2-qt PRIVATE QtUtils.cpp QtUtils.h SettingWidgetBinder.h + GameList/EmptyGameListWidget.ui GameList/GameListModel.cpp GameList/GameListModel.h GameList/GameListRefreshThread.cpp diff --git a/pcsx2-qt/GameList/EmptyGameListWidget.ui b/pcsx2-qt/GameList/EmptyGameListWidget.ui new file mode 100644 index 0000000000..53e8a99048 --- /dev/null +++ b/pcsx2-qt/GameList/EmptyGameListWidget.ui @@ -0,0 +1,141 @@ + + + EmptyGameListWidget + + + + 0 + 0 + 687 + 470 + + + + Form + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + <html><head/><body><p><span style=" font-weight:700;">No games in supported formats were found.</span></p><p>Please add a directory with games to begin.</p><p>Game dumps in the following formats will be scanned and listed:</p></body></html> + + + Qt::AlignCenter + + + + + + + TextLabel + + + Qt::AlignCenter + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Add Game Directory... + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Scan For New Games + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/pcsx2-qt/GameList/GameListWidget.cpp b/pcsx2-qt/GameList/GameListWidget.cpp index c35cfceaac..b1f147d3ae 100644 --- a/pcsx2-qt/GameList/GameListWidget.cpp +++ b/pcsx2-qt/GameList/GameListWidget.cpp @@ -32,6 +32,12 @@ #include "QtHost.h" #include "QtUtils.h" +static const char* SUPPORTED_FORMATS_STRING = QT_TRANSLATE_NOOP(GameListWidget, + ".bin/.iso (ISO Disc Images)\n" + ".chd (Compressed Hunks of Data)\n" + ".cso (Compressed ISO)\n" + ".gz (Gzip Compressed ISO)"); + class GameListSortModel final : public QSortFilterProxyModel { public: @@ -124,6 +130,13 @@ void GameListWidget::initialize() insertWidget(1, m_list_view); + m_empty_widget = new QWidget(this); + m_empty_ui.setupUi(m_empty_widget); + m_empty_ui.supportedFormats->setText(qApp->translate("GameListWidget", SUPPORTED_FORMATS_STRING)); + connect(m_empty_ui.addGameDirectory, &QPushButton::clicked, this, [this]() { emit addGameDirectoryRequested(); }); + connect(m_empty_ui.scanForNewGames, &QPushButton::clicked, this, [this]() { refresh(false); }); + insertWidget(2, m_empty_widget); + if (QtHost::GetBaseBoolSettingValue("UI", "GameListGridView", false)) setCurrentIndex(1); else @@ -167,6 +180,10 @@ void GameListWidget::refresh(bool invalidate_cache) void GameListWidget::onRefreshProgress(const QString& status, int current, int total) { + // switch away from the placeholder while we scan, in case we find anything + if (currentIndex() == 2) + setCurrentIndex(QtHost::GetBaseBoolSettingValue("UI", "GameListGridView", false) ? 1 : 0); + m_model->refresh(); emit refreshProgress(status, current, total); } @@ -180,6 +197,10 @@ void GameListWidget::onRefreshComplete() m_refresh_thread->wait(); delete m_refresh_thread; m_refresh_thread = nullptr; + + // if we still had no games, switch to the helper widget + if (m_model->rowCount() == 0) + setCurrentIndex(2); } void GameListWidget::onSelectionModelCurrentChanged(const QModelIndex& current, const QModelIndex& previous) @@ -276,7 +297,7 @@ void GameListWidget::refreshGridCovers() void GameListWidget::showGameList() { - if (currentIndex() == 0) + if (currentIndex() == 0 || m_model->rowCount() == 0) return; QtHost::SetBaseBoolSettingValue("UI", "GameListGridView", false); @@ -286,7 +307,7 @@ void GameListWidget::showGameList() void GameListWidget::showGameGrid() { - if (currentIndex() == 1) + if (currentIndex() == 1 || m_model->rowCount() == 0) return; QtHost::SetBaseBoolSettingValue("UI", "GameListGridView", true); diff --git a/pcsx2-qt/GameList/GameListWidget.h b/pcsx2-qt/GameList/GameListWidget.h index 46567d42a1..9ca5f116d9 100644 --- a/pcsx2-qt/GameList/GameListWidget.h +++ b/pcsx2-qt/GameList/GameListWidget.h @@ -15,6 +15,7 @@ #pragma once #include "pcsx2/Frontend/GameList.h" +#include "ui_EmptyGameListWidget.h" #include #include #include @@ -69,6 +70,8 @@ Q_SIGNALS: void entryActivated(); void entryContextMenuRequested(const QPoint& point); + void addGameDirectoryRequested(); + private Q_SLOTS: void onRefreshProgress(const QString& status, int current, int total); void onRefreshComplete(); @@ -107,5 +110,8 @@ private: QTableView* m_table_view = nullptr; GameListGridListView* m_list_view = nullptr; + QWidget* m_empty_widget = nullptr; + Ui::EmptyGameListWidget m_empty_ui; + GameListRefreshThread* m_refresh_thread = nullptr; }; diff --git a/pcsx2-qt/MainWindow.cpp b/pcsx2-qt/MainWindow.cpp index 5c28864e8d..26c86b0898 100644 --- a/pcsx2-qt/MainWindow.cpp +++ b/pcsx2-qt/MainWindow.cpp @@ -215,6 +215,8 @@ void MainWindow::connectSignals() connect(m_game_list_widget, &GameListWidget::entryActivated, this, &MainWindow::onGameListEntryActivated, Qt::QueuedConnection); connect( m_game_list_widget, &GameListWidget::entryContextMenuRequested, this, &MainWindow::onGameListEntryContextMenuRequested, Qt::QueuedConnection); + connect(m_game_list_widget, &GameListWidget::addGameDirectoryRequested, this, + [this]() { getSettingsDialog()->getGameListSettingsWidget()->addSearchDirectory(this); }); } void MainWindow::connectVMThreadSignals(EmuThread* thread) diff --git a/pcsx2-qt/pcsx2-qt.vcxproj b/pcsx2-qt/pcsx2-qt.vcxproj index 7991f98ede..b8366e2815 100644 --- a/pcsx2-qt/pcsx2-qt.vcxproj +++ b/pcsx2-qt/pcsx2-qt.vcxproj @@ -262,6 +262,9 @@ Document + + Document + Document diff --git a/pcsx2-qt/pcsx2-qt.vcxproj.filters b/pcsx2-qt/pcsx2-qt.vcxproj.filters index 326f754c78..e627e082f8 100644 --- a/pcsx2-qt/pcsx2-qt.vcxproj.filters +++ b/pcsx2-qt/pcsx2-qt.vcxproj.filters @@ -363,5 +363,8 @@ Settings + + GameList + \ No newline at end of file