Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Achievements: Fix the percentage counter when only unofficial achievements exist #10328

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 31 additions & 21 deletions pcsx2/Achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2185,16 +2185,23 @@ void Achievements::DrawAchievementsWindow()
ImGui::PopFont();

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_core_achievements > 0)
{
text.fmt(TRANSLATE_FS("Achievements", "You have unlocked all achievements and earned {} points!"),
s_game_summary.points_unlocked);
if (s_game_summary.num_unlocked_achievements == s_game_summary.num_core_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.points_core);
}
}
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.points_core);
text.assign(TRANSLATE_SV("Achievements", "This game has no achievements."));
}

top += g_medium_font->FontSize + spacing;
Expand All @@ -2204,21 +2211,24 @@ void Achievements::DrawAchievementsWindow()
summary_bb.Min, summary_bb.Max, text.c_str(), text.end_ptr(), nullptr, ImVec2(0.0f, 0.0f), &summary_bb);
ImGui::PopFont();

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);
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));

text.fmt("{}%", static_cast<int>(std::round(fraction * 100.0f)));
text_size = ImGui::CalcTextSize(text.c_str(), text.end_ptr());
const ImVec2 text_pos(progress_bb.Min.x + ((progress_bb.Max.x - progress_bb.Min.x) / 2.0f) - (text_size.x / 2.0f),
progress_bb.Min.y + ((progress_bb.Max.y - progress_bb.Min.y) / 2.0f) - (text_size.y / 2.0f));
dl->AddText(g_medium_font, g_medium_font->FontSize, text_pos, ImGui::GetColorU32(ImGuiFullscreen::UIPrimaryTextColor),
text.c_str(), text.end_ptr());
top += progress_height + spacing;
if (s_game_summary.num_core_achievements > 0)
{
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);
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));

text.fmt("{}%", static_cast<int>(std::round(fraction * 100.0f)));
text_size = ImGui::CalcTextSize(text.c_str(), text.end_ptr());
const ImVec2 text_pos(progress_bb.Min.x + ((progress_bb.Max.x - progress_bb.Min.x) / 2.0f) - (text_size.x / 2.0f),
progress_bb.Min.y + ((progress_bb.Max.y - progress_bb.Min.y) / 2.0f) - (text_size.y / 2.0f));
dl->AddText(g_medium_font, g_medium_font->FontSize, text_pos, ImGui::GetColorU32(ImGuiFullscreen::UIPrimaryTextColor),
text.c_str(), text.end_ptr());
top += progress_height + spacing;
}
}
}
ImGuiFullscreen::EndFullscreenWindow();
Expand Down