trophy icon + platinum fixes

cleaned up some parts too
This commit is contained in:
CrazyBloo 2024-09-26 19:58:59 -04:00
parent 0c63267b1c
commit 6798266232
3 changed files with 93 additions and 93 deletions

View File

@ -223,6 +223,14 @@ int PS4_SYSV_ABI sceNpTrophyGetGameIcon(OrbisNpTrophyContext context, OrbisNpTro
return ORBIS_OK; return ORBIS_OK;
} }
struct GameTrophyInfo {
uint32_t numGroups;
uint32_t numTrophies;
uint32_t numTrophiesByRarity[5];
uint32_t unlockedTrophies;
uint32_t unlockedTrophiesByRarity[5];
};
int PS4_SYSV_ABI sceNpTrophyGetGameInfo(OrbisNpTrophyContext context, OrbisNpTrophyHandle handle, int PS4_SYSV_ABI sceNpTrophyGetGameInfo(OrbisNpTrophyContext context, OrbisNpTrophyHandle handle,
OrbisNpTrophyGameDetails* details, OrbisNpTrophyGameDetails* details,
OrbisNpTrophyGameData* data) { OrbisNpTrophyGameData* data) {
@ -249,19 +257,8 @@ int PS4_SYSV_ABI sceNpTrophyGetGameInfo(OrbisNpTrophyContext context, OrbisNpTro
if (result) { if (result) {
uint32_t numGroups = 0; GameTrophyInfo gameInfo;
uint32_t numTrophies = 0; memset(&gameInfo, 0, sizeof(GameTrophyInfo));
uint32_t numTrophiesByRarity[5];
numTrophiesByRarity[1] = 0;
numTrophiesByRarity[2] = 0;
numTrophiesByRarity[3] = 0;
numTrophiesByRarity[4] = 0;
uint32_t unlockedTrophies = 0;
uint32_t unlockedTrophiesByRarity[5];
unlockedTrophiesByRarity[1] = 0;
unlockedTrophiesByRarity[2] = 0;
unlockedTrophiesByRarity[3] = 0;
unlockedTrophiesByRarity[4] = 0;
auto trophyconf = doc.child("trophyconf"); auto trophyconf = doc.child("trophyconf");
for (pugi::xml_node_iterator it = trophyconf.children().begin(); for (pugi::xml_node_iterator it = trophyconf.children().begin();
@ -278,35 +275,35 @@ int PS4_SYSV_ABI sceNpTrophyGetGameInfo(OrbisNpTrophyContext context, OrbisNpTro
} }
if (std::string(it->name()) == "group") if (std::string(it->name()) == "group")
numGroups++; gameInfo.numGroups++;
if (std::string(it->name()) == "trophy") { if (std::string(it->name()) == "trophy") {
std::string currentTrophyUnlockState = it->attribute("unlockstate").value(); std::string currentTrophyUnlockState = it->attribute("unlockstate").value();
std::string currentTrophyGrade = it->attribute("ttype").value(); std::string currentTrophyGrade = it->attribute("ttype").value();
numTrophies++; gameInfo.numTrophies++;
if (!currentTrophyGrade.empty()) { if (!currentTrophyGrade.empty()) {
int trophyGrade = GetTrophyGradeFromChar(currentTrophyGrade.at(0)); int trophyGrade = GetTrophyGradeFromChar(currentTrophyGrade.at(0));
numTrophiesByRarity[trophyGrade]++; gameInfo.numTrophiesByRarity[trophyGrade]++;
if (currentTrophyUnlockState == "unlocked") { if (currentTrophyUnlockState == "unlocked") {
unlockedTrophies++; gameInfo.unlockedTrophies++;
unlockedTrophiesByRarity[trophyGrade]++; gameInfo.unlockedTrophiesByRarity[trophyGrade]++;
} }
} }
} }
} }
details->numGroups = numGroups; details->numGroups = gameInfo.numGroups;
details->numTrophies = numTrophies; details->numTrophies = gameInfo.numTrophies;
details->numPlatinum = numTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_PLATINUM]; details->numPlatinum = gameInfo.numTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_PLATINUM];
details->numGold = numTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_GOLD]; details->numGold = gameInfo.numTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_GOLD];
details->numSilver = numTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_SILVER]; details->numSilver = gameInfo.numTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_SILVER];
details->numBronze = numTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_BRONZE]; details->numBronze = gameInfo.numTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_BRONZE];
data->unlockedTrophies = unlockedTrophies; data->unlockedTrophies = gameInfo.unlockedTrophies;
data->unlockedPlatinum = unlockedTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_PLATINUM]; data->unlockedPlatinum = gameInfo.unlockedTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_PLATINUM];
data->unlockedGold = unlockedTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_GOLD]; data->unlockedGold = gameInfo.unlockedTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_GOLD];
data->unlockedSilver = unlockedTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_SILVER]; data->unlockedSilver = gameInfo.unlockedTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_SILVER];
data->unlockedBronze = unlockedTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_BRONZE]; data->unlockedBronze = gameInfo.unlockedTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_BRONZE];
// maybe this should be 1 instead of 100? // maybe this should be 1 instead of 100?
data->progressPercentage = 100; data->progressPercentage = 100;
@ -323,6 +320,13 @@ int PS4_SYSV_ABI sceNpTrophyGetGroupIcon(OrbisNpTrophyContext context, OrbisNpTr
return ORBIS_OK; return ORBIS_OK;
} }
struct GroupTrophyInfo {
uint32_t numTrophies;
uint32_t numTrophiesByRarity[5];
uint32_t unlockedTrophies;
uint32_t unlockedTrophiesByRarity[5];
};
int PS4_SYSV_ABI sceNpTrophyGetGroupInfo(OrbisNpTrophyContext context, OrbisNpTrophyHandle handle, int PS4_SYSV_ABI sceNpTrophyGetGroupInfo(OrbisNpTrophyContext context, OrbisNpTrophyHandle handle,
OrbisNpTrophyGroupId groupId, OrbisNpTrophyGroupId groupId,
OrbisNpTrophyGroupDetails* details, OrbisNpTrophyGroupDetails* details,
@ -350,26 +354,14 @@ int PS4_SYSV_ABI sceNpTrophyGetGroupInfo(OrbisNpTrophyContext context, OrbisNpTr
if (result) { if (result) {
uint32_t numGroups = 0; GroupTrophyInfo groupInfo;
uint32_t numTrophies = 0; memset(&groupInfo, 0, sizeof(GroupTrophyInfo));
uint32_t numTrophiesByRarity[5];
numTrophiesByRarity[1] = 0;
numTrophiesByRarity[2] = 0;
numTrophiesByRarity[3] = 0;
numTrophiesByRarity[4] = 0;
uint32_t unlockedTrophies = 0;
uint32_t unlockedTrophiesByRarity[5];
unlockedTrophiesByRarity[1] = 0;
unlockedTrophiesByRarity[2] = 0;
unlockedTrophiesByRarity[3] = 0;
unlockedTrophiesByRarity[4] = 0;
auto trophyconf = doc.child("trophyconf"); auto trophyconf = doc.child("trophyconf");
for (pugi::xml_node_iterator it = trophyconf.children().begin(); for (pugi::xml_node_iterator it = trophyconf.children().begin();
it != trophyconf.children().end(); ++it) { it != trophyconf.children().end(); ++it) {
if (std::string(it->name()) == "group") { if (std::string(it->name()) == "group") {
numGroups++;
std::string currentGroupId = it->attribute("id").value(); std::string currentGroupId = it->attribute("id").value();
if (!currentGroupId.empty()) { if (!currentGroupId.empty()) {
if (std::stoi(currentGroupId) == groupId) { if (std::stoi(currentGroupId) == groupId) {
@ -385,6 +377,7 @@ int PS4_SYSV_ABI sceNpTrophyGetGroupInfo(OrbisNpTrophyContext context, OrbisNpTr
} }
} }
details->groupId = groupId;
data->groupId = groupId; data->groupId = groupId;
if (std::string(it->name()) == "trophy") { if (std::string(it->name()) == "trophy") {
@ -394,30 +387,31 @@ int PS4_SYSV_ABI sceNpTrophyGetGroupInfo(OrbisNpTrophyContext context, OrbisNpTr
if (!currentTrophyGroupID.empty()) { if (!currentTrophyGroupID.empty()) {
if (std::stoi(currentTrophyGroupID) == groupId) { if (std::stoi(currentTrophyGroupID) == groupId) {
numTrophies++; groupInfo.numTrophies++;
if (!currentTrophyGrade.empty()) { if (!currentTrophyGrade.empty()) {
int trophyGrade = GetTrophyGradeFromChar(currentTrophyGrade.at(0)); int trophyGrade = GetTrophyGradeFromChar(currentTrophyGrade.at(0));
numTrophiesByRarity[trophyGrade]++; groupInfo.numTrophiesByRarity[trophyGrade]++;
if (currentTrophyUnlockState == "unlocked") { if (currentTrophyUnlockState == "unlocked") {
unlockedTrophies++; groupInfo.unlockedTrophies++;
unlockedTrophiesByRarity[trophyGrade]++; groupInfo.unlockedTrophiesByRarity[trophyGrade]++;
} }
} }
} }
} }
} }
} }
details->numTrophies = numTrophies; details->numTrophies = groupInfo.numTrophies;
details->numPlatinum = numTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_PLATINUM]; details->numPlatinum = groupInfo.numTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_PLATINUM];
details->numGold = numTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_GOLD]; details->numGold = groupInfo.numTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_GOLD];
details->numSilver = numTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_SILVER]; details->numSilver = groupInfo.numTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_SILVER];
details->numBronze = numTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_BRONZE]; details->numBronze = groupInfo.numTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_BRONZE];
data->unlockedTrophies = unlockedTrophies; data->unlockedTrophies = groupInfo.unlockedTrophies;
data->unlockedPlatinum = unlockedTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_PLATINUM]; data->unlockedPlatinum =
data->unlockedGold = unlockedTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_GOLD]; groupInfo.unlockedTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_PLATINUM];
data->unlockedSilver = unlockedTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_SILVER]; data->unlockedGold = groupInfo.unlockedTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_GOLD];
data->unlockedBronze = unlockedTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_BRONZE]; data->unlockedSilver = groupInfo.unlockedTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_SILVER];
data->unlockedBronze = groupInfo.unlockedTrophiesByRarity[ORBIS_NP_TROPHY_GRADE_BRONZE];
// maybe this should be 1 instead of 100? // maybe this should be 1 instead of 100?
data->progressPercentage = 100; data->progressPercentage = 100;
@ -925,7 +919,6 @@ int PS4_SYSV_ABI sceNpTrophyUnlockTrophy(OrbisNpTrophyContext context, OrbisNpTr
int numTrophiesUnlocked = 0; int numTrophiesUnlocked = 0;
pugi::xml_node_iterator platinumIt; pugi::xml_node_iterator platinumIt;
int platinumTrophyGroup = -1;
if (result) { if (result) {
auto trophyconf = doc.child("trophyconf"); auto trophyconf = doc.child("trophyconf");
@ -937,40 +930,25 @@ int PS4_SYSV_ABI sceNpTrophyUnlockTrophy(OrbisNpTrophyContext context, OrbisNpTr
std::string currentTrophyDescription = it->child("detail").text().as_string(); std::string currentTrophyDescription = it->child("detail").text().as_string();
std::string currentTrophyType = it->attribute("ttype").value(); std::string currentTrophyType = it->attribute("ttype").value();
std::string currentTrophyUnlockState = it->attribute("unlockstate").value(); std::string currentTrophyUnlockState = it->attribute("unlockstate").value();
std::string currentIconPath =
trophyDir.string() + "/trophy00/Icons/TROP" + currentTrophyId + ".PNG";
if (currentTrophyType == "P") { if (currentTrophyType == "P") {
platinumIt = it; platinumIt = it;
if (std::string(platinumIt->attribute("gid").value()).empty()) {
platinumTrophyGroup = -1;
} else {
platinumTrophyGroup =
std::stoi(std::string(platinumIt->attribute("gid").value()));
}
if (trophyId == std::stoi(currentTrophyId)) { if (trophyId == std::stoi(currentTrophyId)) {
return ORBIS_NP_TROPHY_ERROR_PLATINUM_CANNOT_UNLOCK; return ORBIS_NP_TROPHY_ERROR_PLATINUM_CANNOT_UNLOCK;
} }
} }
if (std::string(it->name()) == "trophy") { if (std::string(it->name()) == "trophy") {
if (platinumTrophyGroup == -1) { if (!std::string(it->attribute("pid").value()).empty()) {
if (std::string(it->attribute("gid").value()).empty()) { if (std::stoi(std::string(it->attribute("pid").value())) !=
ORBIS_NP_TROPHY_INVALID_TROPHY_ID) {
numTrophies++; numTrophies++;
if (currentTrophyUnlockState == "unlocked") { if (currentTrophyUnlockState == "unlocked") {
numTrophiesUnlocked++; numTrophiesUnlocked++;
} }
} }
} else {
if (!std::string(it->attribute("gid").value()).empty()) {
if (std::stoi(std::string(it->attribute("gid").value())) ==
platinumTrophyGroup) {
numTrophies++;
if (currentTrophyUnlockState == "unlocked") {
numTrophiesUnlocked++;
}
}
}
} }
if (std::stoi(currentTrophyId) == trophyId) { if (std::stoi(currentTrophyId) == trophyId) {
@ -998,14 +976,14 @@ int PS4_SYSV_ABI sceNpTrophyUnlockTrophy(OrbisNpTrophyContext context, OrbisNpTr
.set_value(std::to_string(trophyTimestamp.tick).c_str()); .set_value(std::to_string(trophyTimestamp.tick).c_str());
} }
g_trophy_ui.AddTrophyToQueue(trophyId, currentTrophyName); g_trophy_ui.AddTrophyToQueue(currentIconPath, currentTrophyName);
} }
} }
} }
} }
if (std::string(platinumIt->attribute("unlockstate").value()).empty()) { if (std::string(platinumIt->attribute("unlockstate").value()).empty()) {
if ((numTrophies - 2) == numTrophiesUnlocked) { if ((numTrophies - 1) == numTrophiesUnlocked) {
platinumIt->append_attribute("unlockstate") = "unlocked"; platinumIt->append_attribute("unlockstate") = "unlocked";
@ -1022,12 +1000,14 @@ int PS4_SYSV_ABI sceNpTrophyUnlockTrophy(OrbisNpTrophyContext context, OrbisNpTr
std::string platinumTrophyId = platinumIt->attribute("id").value(); std::string platinumTrophyId = platinumIt->attribute("id").value();
std::string platinumTrophyName = platinumIt->child("name").text().as_string(); std::string platinumTrophyName = platinumIt->child("name").text().as_string();
std::string platinumIconPath =
trophyDir.string() + "/trophy00/Icons/TROP" + platinumTrophyId + ".PNG";
*platinumId = std::stoi(platinumTrophyId); *platinumId = std::stoi(platinumTrophyId);
g_trophy_ui.AddTrophyToQueue(*platinumId, platinumTrophyName); g_trophy_ui.AddTrophyToQueue(platinumIconPath, platinumTrophyName);
} }
} else if (std::string(platinumIt->attribute("unlockstate").value()) == "locked") { } else if (std::string(platinumIt->attribute("unlockstate").value()) == "locked") {
if ((numTrophies - 2) == numTrophiesUnlocked) { if ((numTrophies - 1) == numTrophiesUnlocked) {
platinumIt->attribute("unlockstate").set_value("unlocked"); platinumIt->attribute("unlockstate").set_value("unlocked");
@ -1044,9 +1024,11 @@ int PS4_SYSV_ABI sceNpTrophyUnlockTrophy(OrbisNpTrophyContext context, OrbisNpTr
std::string platinumTrophyId = platinumIt->attribute("id").value(); std::string platinumTrophyId = platinumIt->attribute("id").value();
std::string platinumTrophyName = platinumIt->child("name").text().as_string(); std::string platinumTrophyName = platinumIt->child("name").text().as_string();
std::string platinumIconPath =
trophyDir.string() + "/trophy00/Icons/TROP" + platinumTrophyId + ".PNG";
*platinumId = std::stoi(platinumTrophyId); *platinumId = std::stoi(platinumTrophyId);
g_trophy_ui.AddTrophyToQueue(*platinumId, platinumTrophyName); g_trophy_ui.AddTrophyToQueue(platinumIconPath, platinumTrophyName);
} }
} }

View File

@ -5,6 +5,7 @@
#include <imgui.h> #include <imgui.h>
#include "common/assert.h" #include "common/assert.h"
#include "imgui/imgui_std.h" #include "imgui/imgui_std.h"
#include "imgui/imgui_texture.h"
#include "trophy_ui.h" #include "trophy_ui.h"
using namespace ImGui; using namespace ImGui;
@ -18,9 +19,9 @@ TrophyUI::~TrophyUI() {
Finish(); Finish();
} }
void Libraries::NpTrophy::TrophyUI::AddTrophyToQueue(int trophyId, std::string trophyName) { void Libraries::NpTrophy::TrophyUI::AddTrophyToQueue(std::string trophyIconPath, std::string trophyName) {
TrophyInfo newInfo; TrophyInfo newInfo;
newInfo.trophyId = trophyId; newInfo.trophyIconPath = trophyIconPath;
newInfo.trophyName = trophyName; newInfo.trophyName = trophyName;
trophyQueue.push_back(newInfo); trophyQueue.push_back(newInfo);
} }
@ -31,13 +32,15 @@ void TrophyUI::Finish() {
bool displayingTrophy; bool displayingTrophy;
std::chrono::steady_clock::time_point trophyStartedTime; std::chrono::steady_clock::time_point trophyStartedTime;
bool iconLoaded = false;
RefCountedTexture trophyIcon;
void TrophyUI::Draw() { void TrophyUI::Draw() {
const auto& io = GetIO(); const auto& io = GetIO();
const ImVec2 window_size{ const ImVec2 window_size{
std::min(io.DisplaySize.x, 200.f), std::min(io.DisplaySize.x, 250.f),
std::min(io.DisplaySize.y, 75.f), std::min(io.DisplaySize.y, 70.f),
}; };
if (trophyQueue.size() != 0) { if (trophyQueue.size() != 0) {
@ -53,20 +56,35 @@ void TrophyUI::Draw() {
if (duration.count() >= 5) { if (duration.count() >= 5) {
trophyQueue.erase(trophyQueue.begin()); trophyQueue.erase(trophyQueue.begin());
displayingTrophy = false; displayingTrophy = false;
iconLoaded = false;
} }
if (trophyQueue.size() != 0) { if (trophyQueue.size() != 0) {
SetNextWindowSize(window_size); SetNextWindowSize(window_size);
SetNextWindowCollapsed(false); SetNextWindowCollapsed(false);
SetNextWindowPos(ImVec2(io.DisplaySize.x - 200, 50)); SetNextWindowPos(ImVec2(io.DisplaySize.x - 250, 50));
KeepNavHighlight(); KeepNavHighlight();
TrophyInfo currentTrophyInfo = trophyQueue[0]; TrophyInfo currentTrophyInfo = trophyQueue[0];
if (!iconLoaded) {
if (std::filesystem::exists(currentTrophyInfo.trophyIconPath)) {
trophyIcon = RefCountedTexture::DecodePngFile(currentTrophyInfo.trophyIconPath);
iconLoaded = true;
} else {
LOG_ERROR(Lib_NpTrophy, "Couldnt load trophy icon at {}",
currentTrophyInfo.trophyIconPath);
}
}
if (Begin("Trophy Window", nullptr, if (Begin("Trophy Window", nullptr,
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoInputs)) { ImGuiWindowFlags_NoInputs)) {
Text("Trophy earned!"); if (iconLoaded) {
TextWrapped("%s", currentTrophyInfo.trophyName.c_str()); Image(trophyIcon.GetTexture().im_id, ImVec2(50, 50));
ImGui::SameLine();
}
TextWrapped("Trophy earned!\n%s", currentTrophyInfo.trophyName.c_str());
} }
End(); End();
} }

View File

@ -15,7 +15,7 @@
namespace Libraries::NpTrophy { namespace Libraries::NpTrophy {
struct TrophyInfo { struct TrophyInfo {
int trophyId = -1; std::string trophyIconPath;
std::string trophyName; std::string trophyName;
}; };
@ -26,7 +26,7 @@ public:
TrophyUI(); TrophyUI();
~TrophyUI() override; ~TrophyUI() override;
void AddTrophyToQueue(int trophyId, std::string trophyName); void AddTrophyToQueue(std::string trophyIconPath, std::string trophyName);
void Finish(); void Finish();