MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / DrawAchievement

Method DrawAchievement

pcsx2/Achievements.cpp:2808–3012  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2806}
2807
2808void Achievements::DrawAchievement(const rc_client_achievement_t* cheevo)
2809{
2810 using ImGuiFullscreen::g_large_font;
2811 using ImGuiFullscreen::g_medium_font;
2812 using ImGuiFullscreen::GetLineHeight;
2813 using ImGuiFullscreen::LayoutScale;
2814 using ImGuiFullscreen::LayoutUnscale;
2815
2816 static constexpr float alpha = 0.8f;
2817 static constexpr float progress_height_unscaled = 20.0f;
2818 static constexpr float progress_spacing_unscaled = 5.0f;
2819
2820 const float spacing = ImGuiFullscreen::LayoutScale(4.0f);
2821
2822 const bool is_unlocked = (cheevo->state == RC_CLIENT_ACHIEVEMENT_STATE_UNLOCKED);
2823 const std::string_view measured_progress(cheevo->measured_progress);
2824 const bool is_measured = !is_unlocked && !measured_progress.empty();
2825 const float unlock_size = is_unlocked ? (spacing + ImGuiFullscreen::LAYOUT_MEDIUM_FONT_SIZE) : 0.0f;
2826 const ImVec2 points_template_size(
2827 g_medium_font.first->CalcTextSizeA(g_medium_font.second, FLT_MAX, 0.0f, TRANSLATE("Achievements", "XXX points")));
2828
2829 const size_t summary_length = std::strlen(cheevo->description);
2830 const float summary_wrap_width = (ImGui::GetCurrentWindow()->WorkRect.GetWidth() - (ImGui::GetStyle().FramePadding.x * 2.0f) -
2831 LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT + 30.0f) - points_template_size.x);
2832 const ImVec2 summary_text_size(g_medium_font.first->CalcTextSizeA(g_medium_font.second, FLT_MAX, summary_wrap_width, cheevo->description,
2833 cheevo->description + summary_length));
2834
2835 // Messy, but need to undo LayoutScale in MenuButtonFrame()...
2836 const float extra_summary_height = LayoutUnscale(std::max(summary_text_size.y - GetLineHeight(g_medium_font), 0.0f));
2837
2838 ImRect bb;
2839 bool visible, hovered;
2840 ImGuiFullscreen::MenuButtonFrame(TinyString::from_format("chv_{}", cheevo->id), true,
2841 !is_measured ? ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT + extra_summary_height + unlock_size :
2842 ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT + extra_summary_height + progress_height_unscaled + progress_spacing_unscaled,
2843 &visible, &hovered, &bb.Min, &bb.Max, 0, alpha);
2844 if (!visible)
2845 return;
2846
2847 std::string* badge_path;
2848 if (const auto badge_it = std::find_if(
2849 s_achievement_badge_paths.begin(), s_achievement_badge_paths.end(), [cheevo](const auto& it) { return (it.first == cheevo); });
2850 badge_it != s_achievement_badge_paths.end())
2851 {
2852 badge_path = &badge_it->second;
2853 }
2854 else
2855 {
2856 std::string new_badge_path = Achievements::GetAchievementBadgePath(cheevo, cheevo->state);
2857 badge_path = &s_achievement_badge_paths.emplace_back(cheevo, std::move(new_badge_path)).second;
2858 }
2859
2860 const ImVec2 image_size(LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT));
2861
2862 if (!badge_path->empty())
2863 {
2864 GSTexture* badge = ImGuiFullscreen::GetCachedTextureAsync(badge_path->c_str());
2865 if (badge)

Callers

nothing calls this directly

Calls 15

LayoutScaleFunction · 0.85
GetCurrentWindowFunction · 0.85
LayoutUnscaleFunction · 0.85
GetLineHeightFunction · 0.85
ImVec4Class · 0.85
PushFontFunction · 0.85
CalcTextSizeAMethod · 0.80
AddImageMethod · 0.80
end_ptrMethod · 0.80
AddRectFilledMethod · 0.80
AddTextMethod · 0.80
maxFunction · 0.50

Tested by

no test coverage detected