queue to handle multiple trophies at once

This commit is contained in:
CrazyBloo 2024-09-09 06:42:41 -04:00
parent 6dc8ef3f70
commit 794770f94e
3 changed files with 47 additions and 18 deletions

View file

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

View file

@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <imgui.h>
#include <chrono>
#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<std::chrono::seconds>(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();
}
}
}

View file

@ -4,6 +4,8 @@
#pragma once
#include <variant>
#include <vector>
#include <string>
#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<TrophyInfo> 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;