diff --git a/src/common/path_util.cpp b/src/common/path_util.cpp index a4312fada..d48e8c3fe 100644 --- a/src/common/path_util.cpp +++ b/src/common/path_util.cpp @@ -128,6 +128,7 @@ static auto UserPaths = [] { create_path(PathType::CheatsDir, user_dir / CHEATS_DIR); create_path(PathType::PatchesDir, user_dir / PATCHES_DIR); create_path(PathType::MetaDataDir, user_dir / METADATA_DIR); + create_path(PathType::CustomTrophy, user_dir / CUSTOM_TROPHY); return paths; }(); diff --git a/src/common/path_util.h b/src/common/path_util.h index 7190378d6..2fd9b1588 100644 --- a/src/common/path_util.h +++ b/src/common/path_util.h @@ -27,6 +27,7 @@ enum class PathType { CheatsDir, // Where cheats are stored. PatchesDir, // Where patches are stored. MetaDataDir, // Where game metadata (e.g. trophies and menu backgrounds) is stored. + CustomTrophy, // Where custom files for trophies are stored. }; constexpr auto PORTABLE_DIR = "user"; @@ -44,6 +45,7 @@ constexpr auto CAPTURES_DIR = "captures"; constexpr auto CHEATS_DIR = "cheats"; constexpr auto PATCHES_DIR = "patches"; constexpr auto METADATA_DIR = "game_data"; +constexpr auto CUSTOM_TROPHY = "custom_trophy"; // Filenames constexpr auto LOG_FILE = "shad_log.txt"; diff --git a/src/core/libraries/np_trophy/trophy_ui.cpp b/src/core/libraries/np_trophy/trophy_ui.cpp index efa02e9c4..acdc1f74a 100644 --- a/src/core/libraries/np_trophy/trophy_ui.cpp +++ b/src/core/libraries/np_trophy/trophy_ui.cpp @@ -2,9 +2,13 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include +#include #include #include +#include #include + #include "common/assert.h" #include "common/config.h" #include "common/singleton.h" @@ -12,7 +16,7 @@ #include "trophy_ui.h" CMRC_DECLARE(res); - +namespace fs = std::filesystem; using namespace ImGui; namespace Libraries::NpTrophy { @@ -31,20 +35,46 @@ TrophyUI::TrophyUI(const std::filesystem::path& trophyIconPath, const std::strin fmt::UTF(trophyIconPath.u8string())); } - std::string pathString; + std::string pathString = "src/images/"; + if (trophy_type == "P") { - pathString = "src/images/platinum.png"; + pathString += "platinum.png"; } else if (trophy_type == "G") { - pathString = "src/images/gold.png"; + pathString += "gold.png"; } else if (trophy_type == "S") { - pathString = "src/images/silver.png"; + pathString += "silver.png"; } else if (trophy_type == "B") { - pathString = "src/images/bronze.png"; + pathString += "bronze.png"; + } + + const auto CustomTrophy_Dir = Common::FS::GetUserPath(Common::FS::PathType::CustomTrophy); + std::string customPath; + + if (trophy_type == "P" && fs::exists(CustomTrophy_Dir / "platinum.png")) { + customPath = (CustomTrophy_Dir / "platinum.png").string(); + } else if (trophy_type == "G" && fs::exists(CustomTrophy_Dir / "gold.png")) { + customPath = (CustomTrophy_Dir / "gold.png").string(); + } else if (trophy_type == "S" && fs::exists(CustomTrophy_Dir / "silver.png")) { + customPath = (CustomTrophy_Dir / "silver.png").string(); + } else if (trophy_type == "B" && fs::exists(CustomTrophy_Dir / "bronze.png")) { + customPath = (CustomTrophy_Dir / "bronze.png").string(); + } + + std::vector imgdata; + if (!customPath.empty()) { + std::ifstream file(customPath, std::ios::binary); + if (file) { + imgdata = std::vector(std::istreambuf_iterator(file), + std::istreambuf_iterator()); + } else { + LOG_ERROR(Lib_NpTrophy, "Could not open custom file for trophy in {}", customPath); + } + } else { + auto resource = cmrc::res::get_filesystem(); + auto file = resource.open(pathString); + imgdata = std::vector(file.begin(), file.end()); } - auto resource = cmrc::res::get_filesystem(); - auto file = resource.open(pathString); - std::vector imgdata(file.begin(), file.end()); trophy_type_icon = RefCountedTexture::DecodePngTexture(imgdata); AddLayer(this); diff --git a/src/qt_gui/trophy_viewer.cpp b/src/qt_gui/trophy_viewer.cpp index 63e9f04dd..6f5cea0c4 100644 --- a/src/qt_gui/trophy_viewer.cpp +++ b/src/qt_gui/trophy_viewer.cpp @@ -1,11 +1,14 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include #include #include #include "common/path_util.h" #include "trophy_viewer.h" +namespace fs = std::filesystem; + CMRC_DECLARE(res); TrophyViewer::TrophyViewer(QString trophyPath, QString gameTrpPath) : QMainWindow() { @@ -122,10 +125,29 @@ void TrophyViewer::PopulateTrophyWidget(QString title) { const std::string filename = GetTrpType(trpType[row].at(0)); QTableWidgetItem* typeitem = new QTableWidgetItem(); - auto resource = cmrc::res::get_filesystem(); - std::string resourceString = "src/images/" + filename; - auto file = resource.open(resourceString); - std::vector imgdata(file.begin(), file.end()); + const auto CustomTrophy_Dir = + Common::FS::GetUserPath(Common::FS::PathType::CustomTrophy); + std::string customPath; + + if (fs::exists(CustomTrophy_Dir / filename)) { + customPath = (CustomTrophy_Dir / filename).string(); + } + + std::vector imgdata; + + if (!customPath.empty()) { + std::ifstream file(customPath, std::ios::binary); + if (file) { + imgdata = std::vector(std::istreambuf_iterator(file), + std::istreambuf_iterator()); + } + } else { + auto resource = cmrc::res::get_filesystem(); + std::string resourceString = "src/images/" + filename; + auto file = resource.open(resourceString); + imgdata = std::vector(file.begin(), file.end()); + } + QImage type_icon = QImage::fromData(imgdata).scaled(QSize(64, 64), Qt::KeepAspectRatio, Qt::SmoothTransformation); typeitem->setData(Qt::DecorationRole, type_icon);