Skip to content

Commit

Permalink
Achievements: Count unofficial achievements in fullscreen UI
Browse files Browse the repository at this point in the history
Fixes broken percentage display if unofficial achievements are enabled.
  • Loading branch information
CookiePLMonster committed Nov 27, 2023
1 parent 88989bf commit bc94487
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pcsx2/Achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2184,16 +2185,17 @@ 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);
}
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);
}

Expand All @@ -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<float>(s_game_summary.num_unlocked_achievements) / static_cast<float>(s_game_summary.num_core_achievements);
const float fraction = std::min(1.0f,
static_cast<float>(s_game_summary.num_unlocked_achievements) / static_cast<float>(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));
Expand Down

0 comments on commit bc94487

Please sign in to comment.