From 1d7df01e9a8e4e2bf77caf6e23f0d1eb24529073 Mon Sep 17 00:00:00 2001 From: oy Date: Thu, 16 Dec 2010 01:52:29 +0100 Subject: added map download progress by kaddyd --- src/game/client/components/menus.cpp | 73 +++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 6 deletions(-) (limited to 'src/game/client/components/menus.cpp') diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 5d9c1bde..6d3c494e 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -854,8 +854,7 @@ int CMenus::Render() if(Client()->MapDownloadTotalsize() > 0) { pTitle = Localize("Downloading map"); - str_format(aBuf, sizeof(aBuf), "%d/%d KiB", Client()->MapDownloadAmount()/1024, Client()->MapDownloadTotalsize()/1024); - pExtraText = aBuf; + pExtraText = ""; } } else if(m_Popup == POPUP_DISCONNECTED) @@ -971,6 +970,69 @@ int CMenus::Render() static float Offset = 0.0f; DoEditBox(&g_Config.m_Password, &TextBox, g_Config.m_Password, sizeof(g_Config.m_Password), 12.0f, &Offset, true); } + else if(m_Popup == POPUP_CONNECTING) + { + Box = Screen; + Box.VMargin(150.0f, &Box); + Box.HMargin(150.0f, &Box); + Box.HSplitBottom(20.f, &Box, &Part); + Box.HSplitBottom(24.f, &Box, &Part); + Part.VMargin(120.0f, &Part); + + static int s_Button = 0; + if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || m_EscapePressed || m_EnterPressed) + { + Client()->Disconnect(); + m_Popup = POPUP_NONE; + } + + if(Client()->MapDownloadTotalsize() > 0) + { + int64 Now = time_get(); + if(Now-m_DownloadLastCheckTime >= time_freq()) + { + if(m_DownloadLastCheckSize > Client()->MapDownloadAmount()) + { + // map downloaded restarted + m_DownloadLastCheckSize = 0; + } + + // update download speed + float Diff = (Client()->MapDownloadAmount()-m_DownloadLastCheckSize)/1024.0f; + m_DownloadSpeed = (m_DownloadSpeed*(1.0f-(1.0f/m_DownloadSpeed))) + (Diff*(1.0f/m_DownloadSpeed)); + m_DownloadLastCheckTime = Now; + m_DownloadLastCheckSize = Client()->MapDownloadAmount(); + } + + Box.HSplitTop(64.f, 0, &Box); + Box.HSplitTop(24.f, &Part, &Box); + str_format(aBuf, sizeof(aBuf), "%d/%d KiB (%.1f KiB/s)", Client()->MapDownloadAmount()/1024, Client()->MapDownloadTotalsize()/1024, m_DownloadSpeed); + UI()->DoLabel(&Part, aBuf, 20.f, 0, -1); + + // time left + const char *pTimeLeftString; + int TimeLeft = (Client()->MapDownloadTotalsize()-Client()->MapDownloadAmount())/(m_DownloadSpeed*1024)+1; + if(TimeLeft >= 60) + { + TimeLeft /= 60; + pTimeLeftString = TimeLeft == 1 ? Localize("minute") : Localize("minutes"); + } + else + pTimeLeftString = TimeLeft == 1 ? Localize("second") : Localize("seconds"); + Box.HSplitTop(20.f, 0, &Box); + Box.HSplitTop(24.f, &Part, &Box); + str_format(aBuf, sizeof(aBuf), "%i %s %s", TimeLeft, pTimeLeftString, Localize("left")); + UI()->DoLabel(&Part, aBuf, 20.f, 0, -1); + + // progress bar + Box.HSplitTop(20.f, 0, &Box); + Box.HSplitTop(24.f, &Part, &Box); + Part.VMargin(40.0f, &Part); + RenderTools()->DrawUIRect(&Part, vec4(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 5.0f); + Part.w = max(10.0f, (Part.w*Client()->MapDownloadAmount())/Client()->MapDownloadTotalsize()); + RenderTools()->DrawUIRect(&Part, vec4(1.0f, 1.0f, 1.0f, 0.5f), CUI::CORNER_ALL, 5.0f); + } + } else if(m_Popup == POPUP_LANGUAGE) { Box = Screen; @@ -1042,11 +1104,7 @@ int CMenus::Render() static int s_Button = 0; if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || m_EscapePressed || m_EnterPressed) - { - if(m_Popup == POPUP_CONNECTING) - Client()->Disconnect(); m_Popup = POPUP_NONE; - } } } @@ -1149,6 +1207,9 @@ void CMenus::OnStateChange(int NewState, int OldState) else if(NewState == IClient::STATE_LOADING) { m_Popup = POPUP_CONNECTING; + m_DownloadLastCheckTime = time_get(); + m_DownloadLastCheckSize = 0; + m_DownloadSpeed = 1.0f; //client_serverinfo_request(); } else if(NewState == IClient::STATE_CONNECTING) -- cgit 1.4.1