From bc9448747afac15ce33d7c0c1abedf9a114b42bf Mon Sep 17 00:00:00 2001 From: Silent Date: Mon, 27 Nov 2023 16:46:38 +0100 Subject: [PATCH] Achievements: Count unofficial achievements in fullscreen UI Fixes broken percentage display if unofficial achievements are enabled. --- pcsx2/Achievements.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pcsx2/Achievements.cpp b/pcsx2/Achievements.cpp index 7a2e4a0b31694c..21bbb1ed8aeb5b 100644 --- a/pcsx2/Achievements.cpp +++ b/pcsx2/Achievements.cpp @@ -1020,10 +1020,11 @@ void Achievements::DisplayAchievementSummary() title = s_game_title; std::string summary; - if (s_game_summary.num_core_achievements > 0) + const u32 total_num_achievements = s_game_summary.num_core_achievements + s_game_summary.num_unofficial_achievements; + if (total_num_achievements > 0) { summary = fmt::format(TRANSLATE_FS("Achievements", "You have unlocked {0} of {1} achievements, and earned {2} of {3} points."), - s_game_summary.num_unlocked_achievements, s_game_summary.num_core_achievements, s_game_summary.points_unlocked, + s_game_summary.num_unlocked_achievements, total_num_achievements, s_game_summary.points_unlocked, s_game_summary.points_core); } else @@ -2184,8 +2185,9 @@ void Achievements::DrawAchievementsWindow() ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, text.c_str(), text.end_ptr(), nullptr, ImVec2(0.0f, 0.0f), &title_bb); ImGui::PopFont(); + const u32 total_num_achievements = s_game_summary.num_core_achievements + s_game_summary.num_unofficial_achievements; const ImRect summary_bb(ImVec2(left, top), ImVec2(right, top + g_medium_font->FontSize)); - if (s_game_summary.num_unlocked_achievements == s_game_summary.num_core_achievements) + if (s_game_summary.num_unlocked_achievements >= total_num_achievements) { text.fmt(TRANSLATE_FS("Achievements", "You have unlocked all achievements and earned {} points!"), s_game_summary.points_unlocked); @@ -2193,7 +2195,7 @@ void Achievements::DrawAchievementsWindow() else { text.fmt(TRANSLATE_FS("Achievements", "You have unlocked {0} of {1} achievements, earning {2} of {3} possible points."), - s_game_summary.num_unlocked_achievements, s_game_summary.num_core_achievements, s_game_summary.points_unlocked, + s_game_summary.num_unlocked_achievements, total_num_achievements, s_game_summary.points_unlocked, s_game_summary.points_core); } @@ -2206,8 +2208,8 @@ void Achievements::DrawAchievementsWindow() const float progress_height = ImGuiFullscreen::LayoutScale(20.0f); const ImRect progress_bb(ImVec2(left, top), ImVec2(right, top + progress_height)); - const float fraction = - static_cast(s_game_summary.num_unlocked_achievements) / static_cast(s_game_summary.num_core_achievements); + const float fraction = std::min(1.0f, + static_cast(s_game_summary.num_unlocked_achievements) / static_cast(total_num_achievements)); dl->AddRectFilled(progress_bb.Min, progress_bb.Max, ImGui::GetColorU32(ImGuiFullscreen::UIPrimaryDarkColor)); dl->AddRectFilled(progress_bb.Min, ImVec2(progress_bb.Min.x + fraction * progress_bb.GetWidth(), progress_bb.Max.y), ImGui::GetColorU32(ImGuiFullscreen::UISecondaryColor));