Trophy Viewer - Select Game (#2678)

* Trophy Viewer - Select Game

* TR - Button in Utils +icon

TR - Button in Utils +icon
I also made a small correction to the game folder list, where the checkboxes were being filled in incorrectly.
This commit is contained in:
DanielSvoboda 2025-03-24 05:25:51 -03:00 committed by GitHub
parent 4f8e5dfd7c
commit 16a68d78eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 193 additions and 14 deletions

View file

@ -104,8 +104,10 @@ void TrophyViewer::updateTableFilters() {
}
}
TrophyViewer::TrophyViewer(QString trophyPath, QString gameTrpPath) : QMainWindow() {
this->setWindowTitle(tr("Trophy Viewer"));
TrophyViewer::TrophyViewer(QString trophyPath, QString gameTrpPath, QString gameName,
const QVector<TrophyGameInfo>& allTrophyGames)
: QMainWindow(), allTrophyGames_(allTrophyGames), currentGameName_(gameName) {
this->setWindowTitle(tr("Trophy Viewer") + " - " + currentGameName_);
this->setAttribute(Qt::WA_DeleteOnClose);
tabWidget = new QTabWidget(this);
@ -127,11 +129,40 @@ TrophyViewer::TrophyViewer(QString trophyPath, QString gameTrpPath) : QMainWindo
<< "PID";
PopulateTrophyWidget(trophyPath);
QDockWidget* trophyInfoDock = new QDockWidget("", this);
trophyInfoDock = new QDockWidget("", this);
QWidget* dockWidget = new QWidget(trophyInfoDock);
QVBoxLayout* dockLayout = new QVBoxLayout(dockWidget);
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->setStyleSheet(
"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->hide();
connect(expandButton, &QPushButton::clicked, this, [this, trophyInfoDock] {
connect(expandButton, &QPushButton::clicked, this, [this] {
trophyInfoDock->setVisible(true);
expandButton->hide();
});
@ -184,13 +215,13 @@ TrophyViewer::TrophyViewer(QString trophyPath, QString gameTrpPath) : QMainWindo
updateTrophyInfo();
updateTableFilters();
connect(trophyInfoDock, &QDockWidget::topLevelChanged, this, [this, trophyInfoDock] {
connect(trophyInfoDock, &QDockWidget::topLevelChanged, this, [this] {
if (!trophyInfoDock->isVisible()) {
expandButton->show();
}
});
connect(trophyInfoDock, &QDockWidget::visibilityChanged, this, [this, trophyInfoDock] {
connect(trophyInfoDock, &QDockWidget::visibilityChanged, this, [this] {
if (!trophyInfoDock->isVisible()) {
expandButton->show();
} 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() {
if (!trophyInfoDock->isVisible()) {
reopenButton->setVisible(true);
@ -389,13 +443,15 @@ void TrophyViewer::PopulateTrophyWidget(QString title) {
tabWidget->addTab(tableWidget,
tabName.insert(6, " ").replace(0, 1, tabName.at(0).toUpper()));
this->resize(width + 400, 720);
QSize mainWindowSize = QApplication::activeWindow()->size();
this->resize(mainWindowSize.width() * 0.8, mainWindowSize.height() * 0.8);
if (!this->isMaximized()) {
this->resize(width + 400, 720);
QSize mainWindowSize = QApplication::activeWindow()->size();
this->resize(mainWindowSize.width() * 0.8, mainWindowSize.height() * 0.8);
}
this->show();
tableWidget->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Fixed);
tableWidget->setColumnWidth(3, 650);
tableWidget->setColumnWidth(3, 500);
}
this->setCentralWidget(tabWidget);
}