From 1eb600f7e093cb8c39e06af999febf8ba49aee22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 18 Dec 2022 23:21:35 +0100 Subject: [PATCH] Render bar below server browser to show loading progression Render a slim bar below the server browser listbox to show the loading progression, instead of showing a percentage on the Refresh button, as suggested in https://github.com/ddnet/ddnet/pull/5878#issuecomment-1257227947. The margin around the bottom status elements is removed to make more space and improve the alignment of the elements with the rest of the server browser. --- src/game/client/components/menus_browser.cpp | 25 +++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 79aec9288..275f473a4 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -57,7 +57,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) CUIRect Status; View.HSplitTop(ms_ListheaderHeight, &Headers, &View); - View.HSplitBottom(70.0f, &View, &Status); + View.HSplitBottom(65.0f, &View, &Status); // split of the scrollbar Headers.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 5.0f); @@ -510,8 +510,23 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) Connect(g_Config.m_UiServerAddress); } - //Status.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 5.0f); - Status.Margin(5.0f, &Status); + // Render bar that shows the loading progression. + // The bar is only shown while loading and fades out when it's done. + CUIRect RefreshBar; + Status.HSplitTop(5.0f, &RefreshBar, &Status); + static float s_LoadingProgressionFadeEnd = 0.0f; + if(ServerBrowser()->IsRefreshing() && ServerBrowser()->LoadingProgression() < 100) + { + s_LoadingProgressionFadeEnd = Client()->GlobalTime() + 2.0f; + } + const float LoadingProgressionTimeDiff = s_LoadingProgressionFadeEnd - Client()->GlobalTime(); + if(LoadingProgressionTimeDiff > 0.0f) + { + const float RefreshBarAlpha = minimum(LoadingProgressionTimeDiff, 0.8f); + RefreshBar.h = 2.0f; + RefreshBar.w *= ServerBrowser()->LoadingProgression() / 100.0f; + RefreshBar.Draw(ColorRGBA(1.0f, 1.0f, 1.0f, RefreshBarAlpha), IGraphics::CORNER_NONE, 0.0f); + } CUIRect SearchInfoAndAddr, ServersAndConnect, Status3; Status.VSplitRight(250.0f, &SearchInfoAndAddr, &ServersAndConnect); @@ -637,9 +652,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) static int s_RefreshButton = 0; auto Func = [this]() mutable -> const char * { - if(ServerBrowser()->IsRefreshing()) - str_format(m_aLocalStringHelper, sizeof(m_aLocalStringHelper), "%s (%d%%)", Localize("Refresh"), ServerBrowser()->LoadingProgression()); - else if(ServerBrowser()->IsGettingServerlist()) + if(ServerBrowser()->IsRefreshing() || ServerBrowser()->IsGettingServerlist()) str_copy(m_aLocalStringHelper, Localize("Refreshing...")); else str_copy(m_aLocalStringHelper, Localize("Refresh"));