diff options
| author | oy <Tom_Adams@web.de> | 2010-12-16 01:52:29 +0100 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2010-12-16 01:52:29 +0100 |
| commit | 1d7df01e9a8e4e2bf77caf6e23f0d1eb24529073 (patch) | |
| tree | 8f4227ce52fc8947094cc99ac8a664fdb5d9a863 /src/game | |
| parent | c0530b0d0910e85941b6b4158f2e4b1c9e406ff1 (diff) | |
| download | zcatch-1d7df01e9a8e4e2bf77caf6e23f0d1eb24529073.tar.gz zcatch-1d7df01e9a8e4e2bf77caf6e23f0d1eb24529073.zip | |
added map download progress by kaddyd
Diffstat (limited to 'src/game')
| -rw-r--r-- | src/game/client/components/menus.cpp | 73 | ||||
| -rw-r--r-- | src/game/client/components/menus.h | 5 |
2 files changed, 72 insertions, 6 deletions
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) diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 9ca21dae..37d34224 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -150,6 +150,11 @@ class CMenus : public CComponent bool m_EscapePressed; bool m_EnterPressed; bool m_DeletePressed; + + // for map download popup + int64 m_DownloadLastCheckTime; + int m_DownloadLastCheckSize; + float m_DownloadSpeed; // for call vote int m_CallvoteSelectedOption; |