mirror of https://github.com/PCSX2/pcsx2.git
Achievements: Wrap long achievement descriptions
This commit is contained in:
parent
7dc93bee7e
commit
47f372f215
|
@ -2282,6 +2282,7 @@ void Achievements::DrawAchievement(const rc_client_achievement_t* cheevo)
|
|||
using ImGuiFullscreen::g_large_font;
|
||||
using ImGuiFullscreen::g_medium_font;
|
||||
using ImGuiFullscreen::LayoutScale;
|
||||
using ImGuiFullscreen::LayoutUnscale;
|
||||
|
||||
static constexpr float alpha = 0.8f;
|
||||
static constexpr float progress_height_unscaled = 20.0f;
|
||||
|
@ -2293,12 +2294,23 @@ void Achievements::DrawAchievement(const rc_client_achievement_t* cheevo)
|
|||
const std::string_view measured_progress(cheevo->measured_progress);
|
||||
const bool is_measured = !is_unlocked && !measured_progress.empty();
|
||||
const float unlock_size = is_unlocked ? (spacing + ImGuiFullscreen::LAYOUT_MEDIUM_FONT_SIZE) : 0.0f;
|
||||
const ImVec2 points_template_size(
|
||||
g_medium_font->CalcTextSizeA(g_medium_font->FontSize, FLT_MAX, 0.0f, TRANSLATE("Achievements", "XXX points")));
|
||||
|
||||
const size_t summary_length = std::strlen(cheevo->description);
|
||||
const float summary_wrap_width = (ImGui::GetCurrentWindow()->WorkRect.GetWidth() - (ImGui::GetStyle().FramePadding.x * 2.0f) -
|
||||
LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT + 30.0f) - points_template_size.x);
|
||||
const ImVec2 summary_text_size(g_medium_font->CalcTextSizeA(g_medium_font->FontSize, FLT_MAX, summary_wrap_width, cheevo->description,
|
||||
cheevo->description + summary_length));
|
||||
|
||||
// Messy, but need to undo LayoutScale in MenuButtonFrame()...
|
||||
const float extra_summary_height = LayoutUnscale(std::max(summary_text_size.y - g_medium_font->FontSize, 0.0f));
|
||||
|
||||
ImRect bb;
|
||||
bool visible, hovered;
|
||||
ImGuiFullscreen::MenuButtonFrame(TinyString::from_fmt("chv_{}", cheevo->id), true,
|
||||
!is_measured ? ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT + unlock_size :
|
||||
ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT + progress_height_unscaled + progress_spacing_unscaled,
|
||||
!is_measured ? ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT + extra_summary_height + unlock_size :
|
||||
ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT + extra_summary_height + progress_height_unscaled + progress_spacing_unscaled,
|
||||
&visible, &hovered, &bb.Min, &bb.Max, 0, alpha);
|
||||
if (!visible)
|
||||
return;
|
||||
|
@ -2317,6 +2329,7 @@ void Achievements::DrawAchievement(const rc_client_achievement_t* cheevo)
|
|||
}
|
||||
|
||||
const ImVec2 image_size(LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT));
|
||||
|
||||
if (!badge_path->empty())
|
||||
{
|
||||
GSTexture* badge = ImGuiFullscreen::GetCachedTextureAsync(badge_path->c_str());
|
||||
|
@ -2331,8 +2344,7 @@ void Achievements::DrawAchievement(const rc_client_achievement_t* cheevo)
|
|||
|
||||
const float midpoint = bb.Min.y + g_large_font->FontSize + spacing;
|
||||
text.fmt((cheevo->points != 1) ? TRANSLATE_FS("Achievements", "{} points") : TRANSLATE_FS("Achievements", "{} point"), cheevo->points);
|
||||
const ImVec2 points_template_size(
|
||||
g_medium_font->CalcTextSizeA(g_medium_font->FontSize, FLT_MAX, 0.0f, TRANSLATE("Achievements", "XXX points")));
|
||||
|
||||
const ImVec2 points_size(g_medium_font->CalcTextSizeA(g_medium_font->FontSize, FLT_MAX, 0.0f, text.c_str(), text.end_ptr()));
|
||||
const float points_template_start = bb.Max.x - points_template_size.x;
|
||||
const float points_start = points_template_start + ((points_template_size.x - points_size.x) * 0.5f);
|
||||
|
@ -2363,7 +2375,7 @@ void Achievements::DrawAchievement(const rc_client_achievement_t* 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(points_start, midpoint));
|
||||
const ImRect summary_bb(ImVec2(text_start_x, midpoint), ImVec2(points_start, midpoint + g_medium_font->FontSize));
|
||||
const ImRect summary_bb(ImVec2(text_start_x, midpoint), ImVec2(points_start, midpoint + g_medium_font->FontSize + extra_summary_height));
|
||||
const ImRect points_bb(ImVec2(points_start, midpoint), bb.Max);
|
||||
const ImRect lock_bb(
|
||||
ImVec2(points_template_start + ((points_template_size.x - right_icon_size.x) * 0.5f), bb.Min.y), ImVec2(bb.Max.x, midpoint));
|
||||
|
@ -2374,9 +2386,9 @@ void Achievements::DrawAchievement(const rc_client_achievement_t* cheevo)
|
|||
ImGui::PopFont();
|
||||
|
||||
ImGui::PushFont(g_medium_font);
|
||||
if (cheevo->description && std::strlen(cheevo->description) > 0)
|
||||
if (cheevo->description && summary_length > 0)
|
||||
{
|
||||
ImGui::RenderTextClipped(summary_bb.Min, summary_bb.Max, cheevo->description, nullptr, nullptr, ImVec2(0.0f, 0.0f), &summary_bb);
|
||||
ImGui::RenderTextWrapped(summary_bb.Min, cheevo->description, cheevo->description + summary_length, summary_wrap_width);
|
||||
}
|
||||
ImGui::RenderTextClipped(points_bb.Min, points_bb.Max, text.c_str(), text.end_ptr(), &points_size, ImVec2(0.0f, 0.0f), &points_bb);
|
||||
|
||||
|
|
Loading…
Reference in New Issue