diff --git a/src/frontend-common/cheevos.cpp b/src/frontend-common/cheevos.cpp index 4bfd09326..0164f803d 100644 --- a/src/frontend-common/cheevos.cpp +++ b/src/frontend-common/cheevos.cpp @@ -1374,6 +1374,13 @@ void SubmitLeaderboard(u32 leaderboard_id, int value) s_http_downloader->CreateRequest(url, SubmitLeaderboardCallback); } +std::pair GetAchievementProgress(const Achievement& achievement) +{ + std::pair result; + rc_runtime_get_achievement_measured(&s_rcheevos_runtime, achievement.id, &result.first, &result.second); + return result; +} + void CheevosEventHandler(const rc_runtime_event_t* runtime_event) { static const char* events[] = {"RC_RUNTIME_EVENT_ACHIEVEMENT_ACTIVATED", "RC_RUNTIME_EVENT_ACHIEVEMENT_PAUSED", diff --git a/src/frontend-common/cheevos.h b/src/frontend-common/cheevos.h index 69d9941b4..7dd6f9a34 100644 --- a/src/frontend-common/cheevos.h +++ b/src/frontend-common/cheevos.h @@ -113,6 +113,8 @@ const Leaderboard* GetLeaderboardByID(u32 id); u32 GetLeaderboardCount(); bool IsLeaderboardTimeType(const Leaderboard& leaderboard); +std::pair GetAchievementProgress(const Achievement& achievement); + void UnlockAchievement(u32 achievement_id, bool add_notification = true); void SubmitLeaderboard(u32 leaderboard_id, int value); diff --git a/src/frontend-common/fullscreen_ui.cpp b/src/frontend-common/fullscreen_ui.cpp index b7ada784d..5aae33d63 100644 --- a/src/frontend-common/fullscreen_ui.cpp +++ b/src/frontend-common/fullscreen_ui.cpp @@ -4119,14 +4119,22 @@ void DrawDebugDebugMenu() static void DrawAchievement(const Cheevos::Achievement& cheevo) { static constexpr float alpha = 0.8f; + static constexpr float progress_height_unscaled = 20.0f; + static constexpr float progress_spacing_unscaled = 5.0f; TinyString id_str; id_str.Format("%u", cheevo.id); + const auto progress = Cheevos::GetAchievementProgress(cheevo); + const bool is_measured = progress.second != 0; + ImRect bb; bool visible, hovered; bool pressed = - MenuButtonFrame(id_str, true, LAYOUT_MENU_BUTTON_HEIGHT, &visible, &hovered, &bb.Min, &bb.Max, 0, alpha); + MenuButtonFrame(id_str, true, + !is_measured ? LAYOUT_MENU_BUTTON_HEIGHT : + LAYOUT_MENU_BUTTON_HEIGHT + progress_height_unscaled + progress_spacing_unscaled, + &visible, &hovered, &bb.Min, &bb.Max, 0, alpha); if (!visible) return; @@ -4162,6 +4170,27 @@ static void DrawAchievement(const Cheevos::Achievement& cheevo) ImGui::PopFont(); } + if (is_measured) + { + ImDrawList* dl = ImGui::GetWindowDrawList(); + const float progress_height = LayoutScale(progress_height_unscaled); + const float progress_spacing = LayoutScale(progress_spacing_unscaled); + const float top = midpoint + g_medium_font->FontSize + progress_spacing; + const ImRect progress_bb(ImVec2(text_start_x, top), ImVec2(bb.Max.x, top + progress_height)); + const float fraction = static_cast(progress.first) / static_cast(progress.second); + 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.Format("%u / %u", progress.first, progress.second); + const ImVec2 text_size = ImGui::CalcTextSize(text); + 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.GetCharArray(), + text.GetCharArray() + text.GetLength()); + } + #if 0 // The API doesn't seem to send us this :( if (!cheevo.locked)