Trophy Viewer - Select Game

This commit is contained in:
DanielSvoboda 2025-03-23 21:47:33 -03:00
parent 10bf3d383c
commit ed45a12adc
3 changed files with 111 additions and 13 deletions

View File

@ -331,7 +331,33 @@ public:
Common::FS::PathToQString(gameTrpPath, game_update_path); Common::FS::PathToQString(gameTrpPath, game_update_path);
} }
} }
TrophyViewer* trophyViewer = new TrophyViewer(trophyPath, gameTrpPath);
// Array with all games and their trophy information
QVector<TrophyGameInfo> allTrophyGames;
for (const auto& game : m_games) {
TrophyGameInfo gameInfo;
gameInfo.name = QString::fromStdString(game.name);
Common::FS::PathToQString(gameInfo.trophyPath, game.serial);
Common::FS::PathToQString(gameInfo.gameTrpPath, game.path);
auto update_path = Common::FS::PathFromQString(gameInfo.gameTrpPath);
update_path += "-UPDATE";
if (std::filesystem::exists(update_path)) {
Common::FS::PathToQString(gameInfo.gameTrpPath, update_path);
} else {
update_path = Common::FS::PathFromQString(gameInfo.gameTrpPath);
update_path += "-patch";
if (std::filesystem::exists(update_path)) {
Common::FS::PathToQString(gameInfo.gameTrpPath, update_path);
}
}
allTrophyGames.append(gameInfo);
}
QString gameName = QString::fromStdString(m_games[itemID].name);
TrophyViewer* trophyViewer =
new TrophyViewer(trophyPath, gameTrpPath, gameName, allTrophyGames);
trophyViewer->show(); trophyViewer->show();
connect(widget->parent(), &QWidget::destroyed, trophyViewer, connect(widget->parent(), &QWidget::destroyed, trophyViewer,
[trophyViewer]() { trophyViewer->deleteLater(); }); [trophyViewer]() { trophyViewer->deleteLater(); });

View File

@ -104,8 +104,10 @@ void TrophyViewer::updateTableFilters() {
} }
} }
TrophyViewer::TrophyViewer(QString trophyPath, QString gameTrpPath) : QMainWindow() { TrophyViewer::TrophyViewer(QString trophyPath, QString gameTrpPath, QString gameName,
this->setWindowTitle(tr("Trophy Viewer")); const QVector<TrophyGameInfo>& allTrophyGames)
: QMainWindow(), allTrophyGames_(allTrophyGames), currentGameName_(gameName) {
this->setWindowTitle(tr("Trophy Viewer") + " - " + currentGameName_);
this->setAttribute(Qt::WA_DeleteOnClose); this->setAttribute(Qt::WA_DeleteOnClose);
tabWidget = new QTabWidget(this); tabWidget = new QTabWidget(this);
@ -127,11 +129,40 @@ TrophyViewer::TrophyViewer(QString trophyPath, QString gameTrpPath) : QMainWindo
<< "PID"; << "PID";
PopulateTrophyWidget(trophyPath); PopulateTrophyWidget(trophyPath);
QDockWidget* trophyInfoDock = new QDockWidget("", this); trophyInfoDock = new QDockWidget("", this);
QWidget* dockWidget = new QWidget(trophyInfoDock); QWidget* dockWidget = new QWidget(trophyInfoDock);
QVBoxLayout* dockLayout = new QVBoxLayout(dockWidget); QVBoxLayout* dockLayout = new QVBoxLayout(dockWidget);
dockLayout->setAlignment(Qt::AlignTop); dockLayout->setAlignment(Qt::AlignTop);
// ComboBox for game selection
if (!allTrophyGames_.isEmpty()) {
QLabel* gameSelectionLabel = new QLabel(tr("Select Game:"), dockWidget);
dockLayout->addWidget(gameSelectionLabel);
gameSelectionComboBox = new QComboBox(dockWidget);
for (const auto& game : allTrophyGames_) {
gameSelectionComboBox->addItem(game.name);
}
// Select current game in ComboBox
if (!currentGameName_.isEmpty()) {
int index = gameSelectionComboBox->findText(currentGameName_);
if (index >= 0) {
gameSelectionComboBox->setCurrentIndex(index);
}
}
dockLayout->addWidget(gameSelectionComboBox);
connect(gameSelectionComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&TrophyViewer::onGameSelectionChanged);
QFrame* line = new QFrame(dockWidget);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
dockLayout->addWidget(line);
}
trophyInfoLabel = new QLabel(tr("Progress") + ": 0% (0/0)", dockWidget); trophyInfoLabel = new QLabel(tr("Progress") + ": 0% (0/0)", dockWidget);
trophyInfoLabel->setStyleSheet( trophyInfoLabel->setStyleSheet(
"font-weight: bold; font-size: 16px; color: white; background: #333; padding: 5px;"); "font-weight: bold; font-size: 16px; color: white; background: #333; padding: 5px;");
@ -162,7 +193,7 @@ TrophyViewer::TrophyViewer(QString trophyPath, QString gameTrpPath) : QMainWindo
expandButton->setGeometry(80, 0, 27, 27); expandButton->setGeometry(80, 0, 27, 27);
expandButton->hide(); expandButton->hide();
connect(expandButton, &QPushButton::clicked, this, [this, trophyInfoDock] { connect(expandButton, &QPushButton::clicked, this, [this] {
trophyInfoDock->setVisible(true); trophyInfoDock->setVisible(true);
expandButton->hide(); expandButton->hide();
}); });
@ -184,13 +215,13 @@ TrophyViewer::TrophyViewer(QString trophyPath, QString gameTrpPath) : QMainWindo
updateTrophyInfo(); updateTrophyInfo();
updateTableFilters(); updateTableFilters();
connect(trophyInfoDock, &QDockWidget::topLevelChanged, this, [this, trophyInfoDock] { connect(trophyInfoDock, &QDockWidget::topLevelChanged, this, [this] {
if (!trophyInfoDock->isVisible()) { if (!trophyInfoDock->isVisible()) {
expandButton->show(); expandButton->show();
} }
}); });
connect(trophyInfoDock, &QDockWidget::visibilityChanged, this, [this, trophyInfoDock] { connect(trophyInfoDock, &QDockWidget::visibilityChanged, this, [this] {
if (!trophyInfoDock->isVisible()) { if (!trophyInfoDock->isVisible()) {
expandButton->show(); expandButton->show();
} else { } else {
@ -199,6 +230,29 @@ TrophyViewer::TrophyViewer(QString trophyPath, QString gameTrpPath) : QMainWindo
}); });
} }
void TrophyViewer::onGameSelectionChanged(int index) {
if (index < 0 || index >= allTrophyGames_.size()) {
return;
}
while (tabWidget->count() > 0) {
QWidget* widget = tabWidget->widget(0);
tabWidget->removeTab(0);
delete widget;
}
const TrophyGameInfo& selectedGame = allTrophyGames_[index];
currentGameName_ = selectedGame.name;
gameTrpPath_ = selectedGame.gameTrpPath;
this->setWindowTitle(tr("Trophy Viewer") + " - " + currentGameName_);
PopulateTrophyWidget(selectedGame.trophyPath);
updateTrophyInfo();
updateTableFilters();
}
void TrophyViewer::onDockClosed() { void TrophyViewer::onDockClosed() {
if (!trophyInfoDock->isVisible()) { if (!trophyInfoDock->isVisible()) {
reopenButton->setVisible(true); reopenButton->setVisible(true);
@ -389,13 +443,15 @@ void TrophyViewer::PopulateTrophyWidget(QString title) {
tabWidget->addTab(tableWidget, tabWidget->addTab(tableWidget,
tabName.insert(6, " ").replace(0, 1, tabName.at(0).toUpper())); tabName.insert(6, " ").replace(0, 1, tabName.at(0).toUpper()));
this->resize(width + 400, 720); if (!this->isMaximized()) {
QSize mainWindowSize = QApplication::activeWindow()->size(); this->resize(width + 400, 720);
this->resize(mainWindowSize.width() * 0.8, mainWindowSize.height() * 0.8); QSize mainWindowSize = QApplication::activeWindow()->size();
this->resize(mainWindowSize.width() * 0.8, mainWindowSize.height() * 0.8);
}
this->show(); this->show();
tableWidget->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Fixed); tableWidget->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Fixed);
tableWidget->setColumnWidth(3, 650); tableWidget->setColumnWidth(3, 500);
} }
this->setCentralWidget(tabWidget); this->setCentralWidget(tabWidget);
} }

View File

@ -5,6 +5,7 @@
#include <QApplication> #include <QApplication>
#include <QCheckBox> #include <QCheckBox>
#include <QComboBox>
#include <QDir> #include <QDir>
#include <QDockWidget> #include <QDockWidget>
#include <QFileInfoList> #include <QFileInfoList>
@ -12,26 +13,38 @@
#include <QHeaderView> #include <QHeaderView>
#include <QLabel> #include <QLabel>
#include <QMainWindow> #include <QMainWindow>
#include <QPair>
#include <QPushButton> #include <QPushButton>
#include <QTableWidget> #include <QTableWidget>
#include <QTableWidgetItem> #include <QTableWidgetItem>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QVector>
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include "common/types.h" #include "common/types.h"
#include "core/file_format/trp.h" #include "core/file_format/trp.h"
struct TrophyGameInfo {
QString name;
QString trophyPath;
QString gameTrpPath;
};
class TrophyViewer : public QMainWindow { class TrophyViewer : public QMainWindow {
Q_OBJECT Q_OBJECT
public: public:
explicit TrophyViewer(QString trophyPath, QString gameTrpPath); explicit TrophyViewer(
QString trophyPath, QString gameTrpPath, QString gameName = "",
const QVector<TrophyGameInfo>& allTrophyGames = QVector<TrophyGameInfo>());
void updateTrophyInfo(); void updateTrophyInfo();
void updateTableFilters(); void updateTableFilters();
void onDockClosed(); void onDockClosed();
void reopenLeftDock(); void reopenLeftDock();
private slots:
void onGameSelectionChanged(int index);
private: private:
void PopulateTrophyWidget(QString title); void PopulateTrophyWidget(QString title);
void SetTableItem(QTableWidget* parent, int row, int column, QString str); void SetTableItem(QTableWidget* parent, int row, int column, QString str);
@ -39,14 +52,17 @@ private:
QTabWidget* tabWidget = nullptr; QTabWidget* tabWidget = nullptr;
QStringList headers; QStringList headers;
QString gameTrpPath_; QString gameTrpPath_;
QString currentGameName_;
TRP trp; TRP trp;
QLabel* trophyInfoLabel; QLabel* trophyInfoLabel;
QCheckBox* showEarnedCheck; QCheckBox* showEarnedCheck;
QCheckBox* showNotEarnedCheck; QCheckBox* showNotEarnedCheck;
QCheckBox* showHiddenCheck; QCheckBox* showHiddenCheck;
QComboBox* gameSelectionComboBox;
QPushButton* expandButton; QPushButton* expandButton;
QDockWidget* trophyInfoDock; QDockWidget* trophyInfoDock;
QPushButton* reopenButton; QPushButton* reopenButton;
QVector<TrophyGameInfo> allTrophyGames_;
std::string GetTrpType(const QChar trp_) { std::string GetTrpType(const QChar trp_) {
switch (trp_.toLatin1()) { switch (trp_.toLatin1()) {