From 794770f94e098647915f312c566f4a81ff955fb0 Mon Sep 17 00:00:00 2001 From: CrazyBloo Date: Mon, 9 Sep 2024 06:42:41 -0400 Subject: [PATCH] queue to handle multiple trophies at once --- src/core/libraries/np_trophy/np_trophy.cpp | 2 +- src/core/libraries/np_trophy/trophy_ui.cpp | 48 ++++++++++++++++------ src/core/libraries/np_trophy/trophy_ui.h | 15 ++++--- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/core/libraries/np_trophy/np_trophy.cpp b/src/core/libraries/np_trophy/np_trophy.cpp index 53a6650c4..83c45a562 100644 --- a/src/core/libraries/np_trophy/np_trophy.cpp +++ b/src/core/libraries/np_trophy/np_trophy.cpp @@ -588,7 +588,7 @@ int PS4_SYSV_ABI sceNpTrophyUnlockTrophy(OrbisNpTrophyContext context, OrbisNpTr it->attribute("unlockstate").set_value("unlocked"); } - g_trophy_ui = TrophyUI(trophyId, currentTrophyName, TrophyType::BRONZE); + g_trophy_ui.AddTrophyToQueue(trophyId, currentTrophyName, TrophyType::BRONZE); //doc.save_file((trophyDir.string() + "\\trophy00\\Xml\\TROP.XML").c_str()); } diff --git a/src/core/libraries/np_trophy/trophy_ui.cpp b/src/core/libraries/np_trophy/trophy_ui.cpp index cbca31ce0..ce79211f9 100644 --- a/src/core/libraries/np_trophy/trophy_ui.cpp +++ b/src/core/libraries/np_trophy/trophy_ui.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include #include "common/assert.h" #include "imgui/imgui_std.h" #include "trophy_ui.h" @@ -9,12 +10,6 @@ using namespace ImGui; using namespace Libraries::NpTrophy; -TrophyUI::TrophyUI(int trophyId, std::string trophyName, TrophyType trophyType) - : trophyId(trophyId), trophyName(trophyName), trophyType(trophyType) { - first_render = true; - AddLayer(this); -} - TrophyUI::TrophyUI() { first_render = true; AddLayer(this); @@ -25,10 +20,22 @@ TrophyUI::~TrophyUI() { Finish(); } +void Libraries::NpTrophy::TrophyUI::AddTrophyToQueue(int trophyId, std::string trophyName, + TrophyType trophyType) { + TrophyInfo newInfo; + newInfo.trophyId = trophyId; + newInfo.trophyName = trophyName; + newInfo.trophyType = trophyType; + trophyQueue.push_back(newInfo); +} + void TrophyUI::Finish() { RemoveLayer(this); } +bool displayingTrophy; +std::chrono::steady_clock::time_point trophyStartedTime; + void TrophyUI::Draw() { const auto& io = GetIO(); @@ -45,13 +52,30 @@ void TrophyUI::Draw() { PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0)); KeepNavHighlight(); - if (trophyId != -1) { - if (Begin("Trophy Window", nullptr, - ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings)) { - Text("Trophy earned!"); - Text(trophyName.c_str()); + if (trophyQueue.size() != 0) { + if (!displayingTrophy) { + displayingTrophy = true; + trophyStartedTime = std::chrono::steady_clock::now(); + } - End(); + std::chrono::steady_clock::time_point timeNow = std::chrono::steady_clock::now(); + std::chrono::seconds duration = + std::chrono::duration_cast(timeNow - trophyStartedTime); + + if (duration.count() >= 5) { + trophyQueue.erase(trophyQueue.begin()); + displayingTrophy = false; + } + + if (trophyQueue.size() != 0) { + TrophyInfo currentTrophyInfo = trophyQueue[0]; + if (Begin("Trophy Window", nullptr, + ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings)) { + Text("Trophy earned!"); + Text(currentTrophyInfo.trophyName.c_str()); + + End(); + } } } diff --git a/src/core/libraries/np_trophy/trophy_ui.h b/src/core/libraries/np_trophy/trophy_ui.h index 4af4370a5..b281f516f 100644 --- a/src/core/libraries/np_trophy/trophy_ui.h +++ b/src/core/libraries/np_trophy/trophy_ui.h @@ -4,6 +4,8 @@ #pragma once #include +#include +#include #include "common/fixed_value.h" #include "common/types.h" @@ -20,19 +22,22 @@ enum TrophyType { BRONZE, }; -class TrophyUI final : public ImGui::Layer { - bool first_render{false}; - +struct TrophyInfo { int trophyId = -1; std::string trophyName; - std::string trophyDescription; TrophyType trophyType; +}; + +class TrophyUI final : public ImGui::Layer { + bool first_render{false}; + std::vector trophyQueue; public: - explicit TrophyUI(int trophyId, std::string trophyName, TrophyType trophyType); TrophyUI(); ~TrophyUI() override; + void AddTrophyToQueue(int trophyId, std::string trophyName, TrophyType trophyType); + void Finish(); void Draw() override;