diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b0619438..3d1237791 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -293,6 +293,8 @@ set(NP_LIBS src/core/libraries/np_manager/np_manager.cpp src/core/libraries/np_score/np_score.h src/core/libraries/np_trophy/np_trophy.cpp src/core/libraries/np_trophy/np_trophy.h + src/core/libraries/np_trophy/trophy_ui.cpp + src/core/libraries/np_trophy/trophy_ui.h ) set(MISC_LIBS src/core/libraries/screenshot/screenshot.cpp diff --git a/src/core/libraries/np_trophy/np_trophy.cpp b/src/core/libraries/np_trophy/np_trophy.cpp index 9f4c8a54a..53a6650c4 100644 --- a/src/core/libraries/np_trophy/np_trophy.cpp +++ b/src/core/libraries/np_trophy/np_trophy.cpp @@ -9,10 +9,13 @@ #include "core/libraries/error_codes.h" #include "core/libraries/libs.h" #include "externals/pugixml/src/pugixml.hpp" +#include "trophy_ui.h" #include "np_trophy.h" namespace Libraries::NpTrophy { +static TrophyUI g_trophy_ui; + std::string game_serial; static constexpr auto MaxTrophyHandles = 4u; @@ -561,18 +564,21 @@ int PS4_SYSV_ABI sceNpTrophyUnlockTrophy(OrbisNpTrophyContext context, OrbisNpTr for (pugi::xml_node_iterator it = trophyconf.children().begin(); it != trophyconf.children().end() && !foundTrophy; ++it) { - std::string childTrophyId = reinterpret_cast(it->attribute("id").value()); - std::string childTrophyName = reinterpret_cast(it->name()); - std::string childTrophyType = + std::string currentTrophyId = reinterpret_cast(it->attribute("id").value()); + std::string currentTrophyName = reinterpret_cast(it->child("name").text().as_string()); + std::string currentTrophyDescription = + reinterpret_cast(it->child("detail").text().as_string()); + std::string currentTrophyType = reinterpret_cast(it->attribute("ttype").value()); - std::string childTrophyUnlockState = + std::string currentTrophyUnlockState = reinterpret_cast(it->attribute("unlockstate").value()); - if (std::string(childTrophyName) == "trophy" && std::stoi(childTrophyId) == trophyId) { + if (std::string(it->name()) == "trophy" && std::stoi(currentTrophyId) == trophyId) { + LOG_INFO(Lib_NpTrophy, "Found trophy to unlock {} : {}", it->child("name").text().as_string(), it->child("detail").text().as_string()); - if (childTrophyUnlockState == "unlocked") { + if (currentTrophyUnlockState == "unlocked") { LOG_INFO(Lib_NpTrophy, "Trophy already unlocked"); return ORBIS_NP_TROPHY_ERROR_TROPHY_ALREADY_UNLOCKED; } else { @@ -582,7 +588,9 @@ int PS4_SYSV_ABI sceNpTrophyUnlockTrophy(OrbisNpTrophyContext context, OrbisNpTr it->attribute("unlockstate").set_value("unlocked"); } - doc.save_file((trophyDir.string() + "\\trophy00\\Xml\\TROP.XML").c_str()); + g_trophy_ui = TrophyUI(trophyId, currentTrophyName, TrophyType::BRONZE); + + //doc.save_file((trophyDir.string() + "\\trophy00\\Xml\\TROP.XML").c_str()); } foundTrophy = true; } diff --git a/src/core/libraries/np_trophy/trophy_ui.cpp b/src/core/libraries/np_trophy/trophy_ui.cpp new file mode 100644 index 000000000..cbca31ce0 --- /dev/null +++ b/src/core/libraries/np_trophy/trophy_ui.cpp @@ -0,0 +1,60 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include "common/assert.h" +#include "imgui/imgui_std.h" +#include "trophy_ui.h" + +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); +} + + +TrophyUI::~TrophyUI() { + Finish(); +} + +void TrophyUI::Finish() { + RemoveLayer(this); +} + +void TrophyUI::Draw() { + const auto& io = GetIO(); + + const ImVec2 window_size{ + std::min(io.DisplaySize.x, 200.f), + std::min(io.DisplaySize.y, 125.f), + }; + + CentralizeWindow(); + SetNextWindowSize(window_size); + SetNextWindowFocus(); + SetNextWindowCollapsed(false); + SetNextWindowPos(ImVec2(io.DisplaySize.x - 200, 50)); + 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()); + + End(); + } + } + + PopStyleColor(); + first_render = false; +} \ No newline at end of file diff --git a/src/core/libraries/np_trophy/trophy_ui.h b/src/core/libraries/np_trophy/trophy_ui.h new file mode 100644 index 000000000..4af4370a5 --- /dev/null +++ b/src/core/libraries/np_trophy/trophy_ui.h @@ -0,0 +1,45 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include + +#include "common/fixed_value.h" +#include "common/types.h" +#include "core/libraries/np_trophy/np_trophy.h" +#include "imgui/imgui_layer.h" + +namespace Libraries::NpTrophy { + +enum TrophyType { + UNKNOWN, + PLATINUM, + GOLD, + SILVER, + BRONZE, +}; + +class TrophyUI final : public ImGui::Layer { + bool first_render{false}; + + int trophyId = -1; + std::string trophyName; + std::string trophyDescription; + TrophyType trophyType; + +public: + explicit TrophyUI(int trophyId, std::string trophyName, TrophyType trophyType); + TrophyUI(); + ~TrophyUI() override; + + void Finish(); + + void Draw() override; + + bool ShouldGrabGamepad() override { + return false; + } +}; + +}; // namespace Libraries::NpTrophy \ No newline at end of file