From 9414f68f518d0d1e0721289e952151b963e430e8 Mon Sep 17 00:00:00 2001 From: Silent Date: Fri, 7 Jan 2022 16:44:45 +0100 Subject: [PATCH] Add Cheevos::GetAchievementProgressText Measured achievements formatting is now up to rcheevos, not DuckStation --- src/frontend-common/cheevos.cpp | 10 +++++++++- src/frontend-common/cheevos.h | 2 ++ src/frontend-common/fullscreen_ui.cpp | 3 +-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/frontend-common/cheevos.cpp b/src/frontend-common/cheevos.cpp index 5cae1a522..8c4e48925 100644 --- a/src/frontend-common/cheevos.cpp +++ b/src/frontend-common/cheevos.cpp @@ -4,7 +4,6 @@ #include "common/log.h" #include "common/md5_digest.h" #include "common/platform.h" -#include "common/string.h" #include "common/string_util.h" #include "common/timestamp.h" #include "common_host_interface.h" @@ -1377,6 +1376,15 @@ std::pair GetAchievementProgress(const Achievement& achievement) return result; } +TinyString GetAchievementProgressText(const Achievement& achievement) +{ + TinyString result; + rc_runtime_format_achievement_measured(&s_rcheevos_runtime, achievement.id, result.GetWriteableCharArray(), + result.GetWritableBufferSize()); + result.UpdateSize(); + 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 7dd6f9a34..7e18229e2 100644 --- a/src/frontend-common/cheevos.h +++ b/src/frontend-common/cheevos.h @@ -1,4 +1,5 @@ #pragma once +#include "common/string.h" #include "core/types.h" #include #include @@ -114,6 +115,7 @@ u32 GetLeaderboardCount(); bool IsLeaderboardTimeType(const Leaderboard& leaderboard); std::pair GetAchievementProgress(const Achievement& achievement); +TinyString GetAchievementProgressText(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 384ba3ed9..b79de8cb0 100644 --- a/src/frontend-common/fullscreen_ui.cpp +++ b/src/frontend-common/fullscreen_ui.cpp @@ -4101,7 +4101,6 @@ static void DrawAchievement(const Cheevos::Achievement& cheevo) const float text_start_x = bb.Min.x + image_size.x + LayoutScale(15.0f); const ImRect title_bb(ImVec2(text_start_x, bb.Min.y), ImVec2(bb.Max.x, midpoint)); const ImRect summary_bb(ImVec2(text_start_x, midpoint), bb.Max); - SmallString text; ImGui::PushFont(g_large_font); ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, cheevo.title.c_str(), cheevo.title.c_str() + cheevo.title.size(), @@ -4129,7 +4128,7 @@ static void DrawAchievement(const Cheevos::Achievement& cheevo) 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 TinyString text(GetAchievementProgressText(cheevo)); 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));