mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-04-21 20:14:45 +00:00
initial imgui popup
This commit is contained in:
parent
b8d7ea66c4
commit
6dc8ef3f70
4 changed files with 122 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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<const char*>(it->attribute("id").value());
|
||||
std::string childTrophyName = reinterpret_cast<const char*>(it->name());
|
||||
std::string childTrophyType =
|
||||
std::string currentTrophyId = reinterpret_cast<const char*>(it->attribute("id").value());
|
||||
std::string currentTrophyName = reinterpret_cast<const char*>(it->child("name").text().as_string());
|
||||
std::string currentTrophyDescription =
|
||||
reinterpret_cast<const char*>(it->child("detail").text().as_string());
|
||||
std::string currentTrophyType =
|
||||
reinterpret_cast<const char*>(it->attribute("ttype").value());
|
||||
std::string childTrophyUnlockState =
|
||||
std::string currentTrophyUnlockState =
|
||||
reinterpret_cast<const char*>(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;
|
||||
}
|
||||
|
|
60
src/core/libraries/np_trophy/trophy_ui.cpp
Normal file
60
src/core/libraries/np_trophy/trophy_ui.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <imgui.h>
|
||||
#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;
|
||||
}
|
45
src/core/libraries/np_trophy/trophy_ui.h
Normal file
45
src/core/libraries/np_trophy/trophy_ui.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <variant>
|
||||
|
||||
#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
|
Loading…
Add table
Reference in a new issue