Custom Trophy images

This commit is contained in:
DanielSvoboda 2025-02-25 13:59:13 -03:00
parent 15d10e47ea
commit 3d6b882aa1
4 changed files with 68 additions and 13 deletions

View File

@ -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;
}();

View File

@ -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";

View File

@ -2,9 +2,13 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <chrono>
#include <filesystem>
#include <fstream>
#include <mutex>
#include <cmrc/cmrc.hpp>
#include <common/path_util.h>
#include <imgui.h>
#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<u8> imgdata;
if (!customPath.empty()) {
std::ifstream file(customPath, std::ios::binary);
if (file) {
imgdata = std::vector<u8>(std::istreambuf_iterator<char>(file),
std::istreambuf_iterator<char>());
} 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);
std::vector<u8> imgdata(file.begin(), file.end());
imgdata = std::vector<u8>(file.begin(), file.end());
}
trophy_type_icon = RefCountedTexture::DecodePngTexture(imgdata);
AddLayer(this);

View File

@ -1,11 +1,14 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <fstream>
#include <QMessageBox>
#include <cmrc/cmrc.hpp>
#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();
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<char> imgdata;
if (!customPath.empty()) {
std::ifstream file(customPath, std::ios::binary);
if (file) {
imgdata = std::vector<char>(std::istreambuf_iterator<char>(file),
std::istreambuf_iterator<char>());
}
} else {
auto resource = cmrc::res::get_filesystem();
std::string resourceString = "src/images/" + filename;
auto file = resource.open(resourceString);
std::vector<char> imgdata(file.begin(), file.end());
imgdata = std::vector<char>(file.begin(), file.end());
}
QImage type_icon = QImage::fromData(imgdata).scaled(QSize(64, 64), Qt::KeepAspectRatio,
Qt::SmoothTransformation);
typeitem->setData(Qt::DecorationRole, type_icon);