Add support for measured achievements
These achievements show a progress bar in the Achievements screen
This commit is contained in:
parent
d567f1e870
commit
5e9fc91669
|
@ -1374,6 +1374,13 @@ void SubmitLeaderboard(u32 leaderboard_id, int value)
|
|||
s_http_downloader->CreateRequest(url, SubmitLeaderboardCallback);
|
||||
}
|
||||
|
||||
std::pair<u32, u32> GetAchievementProgress(const Achievement& achievement)
|
||||
{
|
||||
std::pair<u32, u32> 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",
|
||||
|
|
|
@ -113,6 +113,8 @@ const Leaderboard* GetLeaderboardByID(u32 id);
|
|||
u32 GetLeaderboardCount();
|
||||
bool IsLeaderboardTimeType(const Leaderboard& leaderboard);
|
||||
|
||||
std::pair<u32, u32> GetAchievementProgress(const Achievement& achievement);
|
||||
|
||||
void UnlockAchievement(u32 achievement_id, bool add_notification = true);
|
||||
void SubmitLeaderboard(u32 leaderboard_id, int value);
|
||||
|
||||
|
|
|
@ -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<float>(progress.first) / static_cast<float>(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)
|
||||
|
|
Loading…
Reference in New Issue