From dbbbf35d0936cdc4317589fc09a072a45077e29f Mon Sep 17 00:00:00 2001 From: DanielSvoboda Date: Fri, 28 Feb 2025 19:06:26 -0300 Subject: [PATCH] improvements to trophy pr * improvements * Note: The sound will only work in QT versions * -. * Update path_util.cpp * Update path_util.cpp --- src/common/config.cpp | 28 ++++++----------- src/common/config.h | 6 ++-- src/common/path_util.cpp | 18 ++++++++++- src/core/libraries/np_trophy/trophy_ui.cpp | 22 ++++++++----- src/qt_gui/settings_dialog.cpp | 27 +++++++++++----- src/qt_gui/settings_dialog.ui | 27 ++++++++-------- src/qt_gui/translations/en_US.ts | 12 ++++++-- src/qt_gui/trophy_viewer.cpp | 36 ++++++++++++++++++++++ src/qt_gui/trophy_viewer.h | 8 +++++ 9 files changed, 130 insertions(+), 54 deletions(-) diff --git a/src/common/config.cpp b/src/common/config.cpp index d39b74868..514024c30 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -53,8 +53,7 @@ static bool isShaderDebug = false; static bool isShowSplash = false; static bool isAutoUpdate = false; static bool isAlwaysShowChangelog = false; -static bool isTopSideTrophy = false; -static bool isLeftSideTrophy = false; +static std::string isSideTrophy = "right"; static bool isNullGpu = false; static bool shouldCopyGPUBuffers = false; static bool shouldDumpShaders = false; @@ -271,12 +270,8 @@ bool alwaysShowChangelog() { return isAlwaysShowChangelog; } -bool TopSideTrophy() { - return isTopSideTrophy; -} - -bool leftSideTrophy() { - return isLeftSideTrophy; +std::string sideTrophy() { + return isSideTrophy; } bool nullGpu() { @@ -386,11 +381,9 @@ void setAutoUpdate(bool enable) { void setAlwaysShowChangelog(bool enable) { isAlwaysShowChangelog = enable; } -void setTopSideTrophy(bool enable) { - isTopSideTrophy = enable; -} -void setLeftSideTrophy(bool enable) { - isLeftSideTrophy = enable; + +void setSideTrophy(std::string side) { + isSideTrophy = side; } void setNullGpu(bool enable) { @@ -745,8 +738,7 @@ void load(const std::filesystem::path& path) { isShowSplash = toml::find_or(general, "showSplash", true); isAutoUpdate = toml::find_or(general, "autoUpdate", false); isAlwaysShowChangelog = toml::find_or(general, "alwaysShowChangelog", false); - isTopSideTrophy = toml::find_or(general, "TopSideTrophy", false); - isLeftSideTrophy = toml::find_or(general, "leftSideTrophy", false); + isSideTrophy = toml::find_or(general, "sideTrophy", "right"); separateupdatefolder = toml::find_or(general, "separateUpdateEnabled", false); compatibilityData = toml::find_or(general, "compatibilityEnabled", false); checkCompatibilityOnStartup = @@ -897,8 +889,7 @@ void save(const std::filesystem::path& path) { data["General"]["showSplash"] = isShowSplash; data["General"]["autoUpdate"] = isAutoUpdate; data["General"]["alwaysShowChangelog"] = isAlwaysShowChangelog; - data["General"]["TopSideTrophy"] = isTopSideTrophy; - data["General"]["leftSideTrophy"] = isLeftSideTrophy; + data["General"]["sideTrophy"] = isSideTrophy; data["General"]["separateUpdateEnabled"] = separateupdatefolder; data["General"]["compatibilityEnabled"] = compatibilityData; data["General"]["checkCompatibilityOnStartup"] = checkCompatibilityOnStartup; @@ -1028,8 +1019,7 @@ void setDefaultValues() { isShowSplash = false; isAutoUpdate = false; isAlwaysShowChangelog = false; - isTopSideTrophy = false; - isLeftSideTrophy = false; + isSideTrophy = "right"; isNullGpu = false; shouldDumpShaders = false; vblankDivider = 1; diff --git a/src/common/config.h b/src/common/config.h index 81826b26a..82d65d30e 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -63,8 +63,7 @@ bool collectShadersForDebug(); bool showSplash(); bool autoUpdate(); bool alwaysShowChangelog(); -bool TopSideTrophy(); -bool leftSideTrophy(); +std::string sideTrophy(); bool nullGpu(); bool copyGPUCmdBuffers(); bool dumpShaders(); @@ -78,8 +77,7 @@ void setCollectShaderForDebug(bool enable); void setShowSplash(bool enable); void setAutoUpdate(bool enable); void setAlwaysShowChangelog(bool enable); -void setTopSideTrophy(bool enable); -void setLeftSideTrophy(bool enable); +void setSideTrophy(std::string side); void setNullGpu(bool enable); void setAllowHDR(bool enable); void setCopyGPUCmdBuffers(bool enable); diff --git a/src/common/path_util.cpp b/src/common/path_util.cpp index d48e8c3fe..6bc73ee43 100644 --- a/src/common/path_util.cpp +++ b/src/common/path_util.cpp @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include #include #include "common/logging/log.h" #include "common/path_util.h" @@ -130,6 +131,21 @@ static auto UserPaths = [] { create_path(PathType::MetaDataDir, user_dir / METADATA_DIR); create_path(PathType::CustomTrophy, user_dir / CUSTOM_TROPHY); + std::ofstream notice_file(user_dir / CUSTOM_TROPHY / "Notice.txt"); + if (notice_file.is_open()) { + notice_file + << "++++++++++++++++++++++++++++++++\n+ Custom Trophy Images / Sound " + "+\n++++++++++++++++++++++++++++++++\n\nYou can add custom images to the " + "trophies.\n*We recommend a square resolution image, for example 200x200, 500x500, " + "the same size as the height and width.\nIn this folder ('user\\custom_trophy'), " + "add the files with the following " + "names:\n\nbronze.png\nsilver.png\ngold.png\nplatinum.png\n\nYou can add a custom " + "sound for trophy notifications.\n*By default, no audio is played unless it is in " + "this folder and you are using the QT version.\nIn this folder " + "('user\\custom_trophy'), add the files with the following names:\n\ntrophy.mp3"; + notice_file.close(); + } + return paths; }(); @@ -223,4 +239,4 @@ std::filesystem::path PathFromQString(const QString& path) { } #endif -} // namespace Common::FS \ No newline at end of file +} // namespace Common::FS diff --git a/src/core/libraries/np_trophy/trophy_ui.cpp b/src/core/libraries/np_trophy/trophy_ui.cpp index 4dbf9ffc0..71f173e43 100644 --- a/src/core/libraries/np_trophy/trophy_ui.cpp +++ b/src/core/libraries/np_trophy/trophy_ui.cpp @@ -27,16 +27,17 @@ namespace Libraries::NpTrophy { std::optional current_trophy_ui; std::queue trophy_queue; std::mutex queueMtx; -bool isTopSide; -bool isLeftSide; + +std::string side = "right"; + double trophy_timer; TrophyUI::TrophyUI(const std::filesystem::path& trophyIconPath, const std::string& trophyName, const std::string_view& rarity) : trophy_name(trophyName), trophy_type(rarity) { - isTopSide = Config::TopSideTrophy(); - isLeftSide = Config::leftSideTrophy(); + side = Config::sideTrophy(); + trophy_timer = Config::getTrophyNotificationDuration(); if (std::filesystem::exists(trophyIconPath)) { @@ -130,21 +131,26 @@ void TrophyUI::Draw() { float final_pos_x, start_x; float final_pos_y, start_y; - if (isTopSide) { + if (side == "top") { start_x = (io.DisplaySize.x - window_size.x) * 0.5f; start_y = -window_size.y; final_pos_x = start_x; - final_pos_y = 50 * AdjustHeight; - } else if (isLeftSide) { + final_pos_y = 20 * AdjustHeight; + } else if (side == "left") { start_x = -window_size.x; start_y = 50 * AdjustHeight; final_pos_x = 20 * AdjustWidth; final_pos_y = start_y; - } else { + } else if (side == "right") { start_x = io.DisplaySize.x; start_y = 50 * AdjustHeight; final_pos_x = io.DisplaySize.x - window_size.x - 20 * AdjustWidth; final_pos_y = start_y; + } else if (side == "bottom") { + start_x = (io.DisplaySize.x - window_size.x) * 0.5f; + start_y = io.DisplaySize.y; + final_pos_x = start_x; + final_pos_y = io.DisplaySize.y - window_size.y - 20 * AdjustHeight; } ImVec2 current_pos = ImVec2(start_x + (final_pos_x - start_x) * progress, diff --git a/src/qt_gui/settings_dialog.cpp b/src/qt_gui/settings_dialog.cpp index 6205eee29..a3890b548 100644 --- a/src/qt_gui/settings_dialog.cpp +++ b/src/qt_gui/settings_dialog.cpp @@ -418,10 +418,14 @@ void SettingsDialog::LoadValuesFromConfig() { ui->disableTrophycheckBox->setChecked( toml::find_or(data, "General", "isTrophyPopupDisabled", false)); ui->popUpDurationSpinBox->setValue(Config::getTrophyNotificationDuration()); - ui->radioButton_Top->setChecked(Config::TopSideTrophy()); - ui->radioButton_Left->setChecked(Config::leftSideTrophy()); - ui->radioButton_Right->setChecked( - !(ui->radioButton_Left->isChecked() || ui->radioButton_Top->isChecked())); + + QString side = QString::fromStdString(Config::sideTrophy()); + + ui->radioButton_Left->setChecked(side == "left"); + ui->radioButton_Right->setChecked(side == "right"); + ui->radioButton_Top->setChecked(side == "top"); + ui->radioButton_Bottom->setChecked(side == "bottom"); + ui->BGMVolumeSlider->setValue(toml::find_or(data, "General", "BGMvolume", 50)); ui->discordRPCCheckbox->setChecked( toml::find_or(data, "General", "enableDiscordRPC", true)); @@ -614,7 +618,7 @@ void SettingsDialog::updateNoteTextEdit(const QString& elementName) { //User if (elementName == "OpenCustomTrophyLocationButton") { - text = tr("Open the custom trophy images/sounds folder:\\nYou can add custom images to the trophies and an audio.\\nAdd the files to custom_trophy with the following names:\\nthophy.mp3, bronze.png, gold.png, platinum.png, silver.png"); + text = tr("Open the custom trophy images/sounds folder:\\nYou can add custom images to the trophies and an audio.\\nAdd the files to custom_trophy with the following names:\\nthophy.mp3, bronze.png, gold.png, platinum.png, silver.png\\nNote: The sound will only work in QT versions."); } // Input @@ -708,8 +712,17 @@ void SettingsDialog::UpdateSettings() { Config::setIsMotionControlsEnabled(ui->motionControlsCheckBox->isChecked()); Config::setisTrophyPopupDisabled(ui->disableTrophycheckBox->isChecked()); Config::setTrophyNotificationDuration(ui->popUpDurationSpinBox->value()); - Config::setTopSideTrophy(ui->radioButton_Top->isChecked()); - Config::setLeftSideTrophy(ui->radioButton_Left->isChecked()); + + if (ui->radioButton_Top->isChecked()) { + Config::setSideTrophy("top"); + } else if (ui->radioButton_Left->isChecked()) { + Config::setSideTrophy("left"); + } else if (ui->radioButton_Right->isChecked()) { + Config::setSideTrophy("right"); + } else if (ui->radioButton_Bottom->isChecked()) { + Config::setSideTrophy("bottom"); + } + Config::setPlayBGM(ui->playBGMCheckBox->isChecked()); Config::setAllowHDR(ui->enableHDRCheckBox->isChecked()); Config::setLogType(logTypeMap.value(ui->logTypeComboBox->currentText()).toStdString()); diff --git a/src/qt_gui/settings_dialog.ui b/src/qt_gui/settings_dialog.ui index b44a385f0..7db0afa59 100644 --- a/src/qt_gui/settings_dialog.ui +++ b/src/qt_gui/settings_dialog.ui @@ -1286,13 +1286,6 @@ - - - - Top - - - @@ -1302,17 +1295,25 @@ - - - 0 - 0 - - Right + + + + Top + + + + + + + Bottom + + + diff --git a/src/qt_gui/translations/en_US.ts b/src/qt_gui/translations/en_US.ts index 92fb59a02..29ce27f07 100644 --- a/src/qt_gui/translations/en_US.ts +++ b/src/qt_gui/translations/en_US.ts @@ -1632,8 +1632,8 @@ Update Compatibility Database:\nImmediately update the compatibility database. - Open the custom trophy images/sounds folder:\nYou can add custom images to the trophies and an audio.\nAdd the files to custom_trophy with the following names:\nthophy.mp3, bronze.png, gold.png, platinum.png, silver.png - Open the custom trophy images/sounds folder:\nYou can add custom images to the trophies and an audio.\nAdd the files to custom_trophy with the following names:\nthophy.mp3, bronze.png, gold.png, platinum.png, silver.png + Open the custom trophy images/sounds folder:\nYou can add custom images to the trophies and an audio.\nAdd the files to custom_trophy with the following names:\nthophy.mp3, bronze.png, gold.png, platinum.png, silver.png\nNote: The sound will only work in QT versions. + Open the custom trophy images/sounds folder:\nYou can add custom images to the trophies and an audio.\nAdd the files to custom_trophy with the following names:\nthophy.mp3, bronze.png, gold.png, platinum.png, silver.png\nNote: The sound will only work in QT versions. Never @@ -1839,6 +1839,14 @@ Right Right + + Top + Top + + + Bottom + Bottom + Notification Duration Notification Duration diff --git a/src/qt_gui/trophy_viewer.cpp b/src/qt_gui/trophy_viewer.cpp index 148cbee06..8116f6f1a 100644 --- a/src/qt_gui/trophy_viewer.cpp +++ b/src/qt_gui/trophy_viewer.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include "common/path_util.h" @@ -157,6 +158,15 @@ TrophyViewer::TrophyViewer(QString trophyPath, QString gameTrpPath) : QMainWindo // Adds the dock to the left area this->addDockWidget(Qt::LeftDockWidgetArea, trophyInfoDock); + expandButton = new QPushButton(">>", this); + expandButton->setGeometry(80, 0, 27, 27); + expandButton->hide(); + + connect(expandButton, &QPushButton::clicked, this, [this, trophyInfoDock] { + trophyInfoDock->setVisible(true); + expandButton->hide(); + }); + // Connects checkbox signals to update trophy display #if (QT_VERSION < QT_VERSION_CHECK(6, 7, 0)) connect(showEarnedCheck, &QCheckBox::stateChanged, this, &TrophyViewer::updateTableFilters); @@ -173,6 +183,31 @@ TrophyViewer::TrophyViewer(QString trophyPath, QString gameTrpPath) : QMainWindo updateTrophyInfo(); updateTableFilters(); + + connect(trophyInfoDock, &QDockWidget::topLevelChanged, this, [this, trophyInfoDock] { + if (!trophyInfoDock->isVisible()) { + expandButton->show(); + } + }); + + connect(trophyInfoDock, &QDockWidget::visibilityChanged, this, [this, trophyInfoDock] { + if (!trophyInfoDock->isVisible()) { + expandButton->show(); + } else { + expandButton->hide(); + } + }); +} + +void TrophyViewer::onDockClosed() { + if (!trophyInfoDock->isVisible()) { + reopenButton->setVisible(true); + } +} + +void TrophyViewer::reopenLeftDock() { + trophyInfoDock->show(); + reopenButton->setVisible(false); } void TrophyViewer::PopulateTrophyWidget(QString title) { @@ -354,6 +389,7 @@ void TrophyViewer::PopulateTrophyWidget(QString title) { tabWidget->addTab(tableWidget, tabName.insert(6, " ").replace(0, 1, tabName.at(0).toUpper())); + this->resize(width + 400, 720); this->showMaximized(); tableWidget->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Fixed); diff --git a/src/qt_gui/trophy_viewer.h b/src/qt_gui/trophy_viewer.h index bd99e1a8c..75fb500e7 100644 --- a/src/qt_gui/trophy_viewer.h +++ b/src/qt_gui/trophy_viewer.h @@ -4,12 +4,15 @@ #pragma once #include +#include #include +#include #include #include #include #include #include +#include #include #include #include @@ -26,6 +29,8 @@ public: void updateTrophyInfo(); void updateTableFilters(); + void onDockClosed(); + void reopenLeftDock(); private: void PopulateTrophyWidget(QString title); @@ -39,6 +44,9 @@ private: QCheckBox* showEarnedCheck; QCheckBox* showNotEarnedCheck; QCheckBox* showHiddenCheck; + QPushButton* expandButton; + QDockWidget* trophyInfoDock; + QPushButton* reopenButton; std::string GetTrpType(const QChar trp_) { switch (trp_.toLatin1()) {