Achievements: Make login progress indeterminate

This commit is contained in:
Connor McLaughlin 2022-10-03 23:50:34 +10:00
parent c3eccf51d1
commit df06931e36
2 changed files with 28 additions and 16 deletions

View file

@ -920,9 +920,7 @@ bool Achievements::LoginAsync(const char* username, const char* password)
return false; return false;
if (FullscreenUI::IsInitialized()) if (FullscreenUI::IsInitialized())
{ ImGuiFullscreen::OpenBackgroundProgressDialog("cheevos_async_login", "Logging in to RetroAchivements...", 0, 0, 0);
ImGuiFullscreen::OpenBackgroundProgressDialog("cheevos_async_login", "Logging in to RetroAchivements...", 0, 1, 0);
}
SendLogin(username, password, s_http_downloader.get(), LoginASyncCallback); SendLogin(username, password, s_http_downloader.get(), LoginASyncCallback);
return true; return true;

View file

@ -264,9 +264,8 @@ std::optional<Common::RGBA8Image> ImGuiFullscreen::LoadTextureImage(const char*
std::shared_ptr<GPUTexture> ImGuiFullscreen::UploadTexture(const char* path, const Common::RGBA8Image& image) std::shared_ptr<GPUTexture> ImGuiFullscreen::UploadTexture(const char* path, const Common::RGBA8Image& image)
{ {
std::unique_ptr<GPUTexture> texture = std::unique_ptr<GPUTexture> texture = g_host_display->CreateTexture(
g_host_display->CreateTexture(image.GetWidth(), image.GetHeight(), 1, 1, 1, GPUTexture::Format::RGBA8, image.GetWidth(), image.GetHeight(), 1, 1, 1, GPUTexture::Format::RGBA8, image.GetPixels(), image.GetPitch());
image.GetPixels(), image.GetPitch());
if (!texture) if (!texture)
{ {
Log_ErrorPrintf("failed to create %ux%u texture for resource", image.GetWidth(), image.GetHeight()); Log_ErrorPrintf("failed to create %ux%u texture for resource", image.GetWidth(), image.GetHeight());
@ -2264,17 +2263,32 @@ void ImGuiFullscreen::DrawBackgroundProgressDialogs(ImVec2& position, float spac
nullptr, 0.0f); nullptr, 0.0f);
pos.y += g_medium_font->FontSize + LayoutScale(10.0f); pos.y += g_medium_font->FontSize + LayoutScale(10.0f);
ImVec2 bar_end(pos.x + window_width - LayoutScale(10.0f * 2.0f), pos.y + LayoutScale(25.0f)); const ImVec2 box_end(pos.x + window_width - LayoutScale(10.0f * 2.0f), pos.y + LayoutScale(25.0f));
float fraction = static_cast<float>(data.value - data.min) / static_cast<float>(data.max - data.min); dl->AddRectFilled(pos, box_end, ImGui::GetColorU32(UIPrimaryDarkColor));
dl->AddRectFilled(pos, bar_end, ImGui::GetColorU32(UIPrimaryDarkColor));
dl->AddRectFilled(pos, ImVec2(pos.x + fraction * (bar_end.x - pos.x), bar_end.y), if (data.min != data.max)
{
const float fraction = static_cast<float>(data.value - data.min) / static_cast<float>(data.max - data.min);
dl->AddRectFilled(pos, ImVec2(pos.x + fraction * (box_end.x - pos.x), box_end.y),
ImGui::GetColorU32(UISecondaryColor)); ImGui::GetColorU32(UISecondaryColor));
const std::string text(fmt::format("{}%", static_cast<int>(std::round(fraction * 100.0f)))); const auto text = TinyString::FromFmt("{}%", static_cast<int>(std::round(fraction * 100.0f)));
const ImVec2 text_size(ImGui::CalcTextSize(text.c_str())); const ImVec2 text_size(ImGui::CalcTextSize(text));
const ImVec2 text_pos(pos.x + ((bar_end.x - pos.x) / 2.0f) - (text_size.x / 2.0f), const ImVec2 text_pos(pos.x + ((box_end.x - pos.x) / 2.0f) - (text_size.x / 2.0f),
pos.y + ((bar_end.y - pos.y) / 2.0f) - (text_size.y / 2.0f)); pos.y + ((box_end.y - pos.y) / 2.0f) - (text_size.y / 2.0f));
dl->AddText(g_medium_font, g_medium_font->FontSize, text_pos, ImGui::GetColorU32(UIPrimaryTextColor), text.c_str()); dl->AddText(g_medium_font, g_medium_font->FontSize, text_pos, ImGui::GetColorU32(UIPrimaryTextColor),
text.GetCharArray(), text.GetCharArray() + text.GetLength());
}
else
{
// indeterminate, so draw a scrolling bar
const float bar_width = LayoutScale(30.0f);
const float fraction = static_cast<float>(std::fmod(ImGui::GetTime(), 2.0) * 0.5);
const ImVec2 bar_start(pos.x + ImLerp(0.0f, box_end.x, fraction) - bar_width, pos.y);
const ImVec2 bar_end(std::min(bar_start.x + bar_width, box_end.x), pos.y + LayoutScale(25.0f));
dl->AddRectFilled(ImClamp(bar_start, pos, box_end), ImClamp(bar_end, pos, box_end),
ImGui::GetColorU32(UISecondaryColor));
}
position.y += s_notification_vertical_direction * (window_height + spacing); position.y += s_notification_vertical_direction * (window_height + spacing);
} }