Fix trophy pop-up icons

This commit is contained in:
rainmakerv2 2025-02-24 10:28:43 +08:00
parent 81f211a82a
commit f1cd552f05

View File

@ -11,6 +11,8 @@
#include "imgui/imgui_std.h" #include "imgui/imgui_std.h"
#include "trophy_ui.h" #include "trophy_ui.h"
CMRC_DECLARE(res);
using namespace ImGui; using namespace ImGui;
namespace Libraries::NpTrophy { namespace Libraries::NpTrophy {
@ -29,6 +31,22 @@ TrophyUI::TrophyUI(const std::filesystem::path& trophyIconPath, const std::strin
fmt::UTF(trophyIconPath.u8string())); fmt::UTF(trophyIconPath.u8string()));
} }
std::string pathString;
if (trophy_type == "P") {
pathString = "Resources/platinum.png";
} else if (trophy_type == "G") {
pathString = "Resources/gold.png";
} else if (trophy_type == "S") {
pathString = "Resources/silver.png";
} else if (trophy_type == "B") {
pathString = "Resources/bronze.png";
}
auto resource = cmrc::res::get_filesystem();
auto file = resource.open(pathString);
std::vector<u8> imgdata(file.begin(), file.end());
trophy_type_icon = RefCountedTexture::DecodePngTexture(imgdata);
AddLayer(this); AddLayer(this);
} }
@ -57,9 +75,10 @@ void TrophyUI::Draw() {
if (Begin("Trophy Window", nullptr, if (Begin("Trophy Window", nullptr,
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoInputs)) { ImGuiWindowFlags_NoInputs)) {
if (trophy_icon) { if (trophy_type_icon) {
SetCursorPosY((window_size.y * 0.5f) - (25 * AdjustHeight)); SetCursorPosY((window_size.y * 0.5f) - (25 * AdjustHeight));
Image(trophy_icon.GetTexture().im_id, ImVec2((50 * AdjustWidth), (50 * AdjustHeight))); Image(trophy_type_icon.GetTexture().im_id,
ImVec2((50 * AdjustWidth), (50 * AdjustHeight)));
ImGui::SameLine(); ImGui::SameLine();
} else { } else {
// placeholder // placeholder
@ -74,7 +93,20 @@ void TrophyUI::Draw() {
const float text_height = const float text_height =
ImGui::CalcTextSize(std::strcat(earned_text, trophy_name.c_str())).y; ImGui::CalcTextSize(std::strcat(earned_text, trophy_name.c_str())).y;
SetCursorPosY((window_size.y - text_height) * 0.5f); SetCursorPosY((window_size.y - text_height) * 0.5f);
ImGui::PushTextWrapPos(window_size.x - (60 * AdjustWidth));
TextWrapped("Trophy earned!\n%s", trophy_name.c_str()); TextWrapped("Trophy earned!\n%s", trophy_name.c_str());
ImGui::SameLine(window_size.x - (60 * AdjustWidth));
if (trophy_icon) {
SetCursorPosY((window_size.y * 0.5f) - (25 * AdjustHeight));
Image(trophy_icon.GetTexture().im_id, ImVec2((50 * AdjustWidth), (50 * AdjustHeight)));
} else {
// placeholder
const auto pos = GetCursorScreenPos();
ImGui::GetWindowDrawList()->AddRectFilled(pos, pos + ImVec2{30.0f * AdjustHeight},
GetColorU32(ImVec4{0.7f}));
}
} }
End(); End();