Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.84 KB | None | 0 0
  1. diff -Naur a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp
  2. --- a/src/game/client/components/menus.cpp  2010-11-19 16:24:16.441000000 +0500
  3. +++ b/src/game/client/components/menus.cpp  2010-11-19 23:34:43.919000000 +0500
  4. @@ -24,6 +24,8 @@
  5.  #include <game/localization.h>
  6.  #include <mastersrv/mastersrv.h>
  7.  
  8. +#include <time.h>
  9. +
  10.  vec4 CMenus::ms_GuiColor;
  11.  vec4 CMenus::ms_ColorTabbarInactiveOutgame;
  12.  vec4 CMenus::ms_ColorTabbarActiveOutgame;
  13. @@ -101,6 +103,8 @@
  14.    
  15.     str_copy(m_aCurrentDemoFolder, "demos", sizeof(m_aCurrentDemoFolder));
  16.     m_aCallvoteReason[0] = 0;
  17. +  
  18. +   m_DownloadLastCheckSize = 0;
  19.  }
  20.  
  21.  vec4 CMenus::ButtonColorMul(const void *pID)
  22. @@ -838,6 +842,8 @@
  23.         const char *pExtraText = "";
  24.         const char *pButtonText = "";
  25.         int ExtraAlign = 0;
  26. +       bool bProgressBar = false;
  27. +       float fProgress = 0.0f;
  28.        
  29.         if(m_Popup == POPUP_MESSAGE)
  30.         {
  31. @@ -852,9 +858,69 @@
  32.             pButtonText = Localize("Abort");
  33.             if(Client()->MapDownloadTotalsize() > 0)
  34.             {
  35. +               int currTime = (int)time(0);
  36. +
  37. +               if (!m_DownloadLastCheckSize || m_DownloadLastCheckSize > (unsigned long)Client()->MapDownloadAmount())
  38. +               {
  39. +                   m_DownloadSpeed = 0;
  40. +                   m_DownloadLastCheckSize = 1; // we'll think that we've got 1 byte
  41. +                   m_DownloadLastCheckTime = currTime;
  42. +               } else {
  43. +                   int diffTime = currTime - m_DownloadLastCheckTime;
  44. +                   int diffSize = Client()->MapDownloadAmount() - m_DownloadLastCheckSize;
  45. +                   float currSpeed = diffTime ? diffSize / diffTime : 0;
  46. +
  47. +                   if (diffTime >= 1.0f && diffSize > 0)
  48. +                   {
  49. +                       if (m_DownloadSpeed == 0)
  50. +                           m_DownloadSpeed = currSpeed;
  51. +                       else
  52. +                           m_DownloadSpeed = (m_DownloadSpeed + currSpeed) * 0.5f;
  53. +
  54. +                       m_DownloadLastCheckSize = Client()->MapDownloadAmount();
  55. +                       m_DownloadLastCheckTime = currTime;
  56. +                   }
  57. +               }
  58. +
  59.                 pTitle = Localize("Downloading map");
  60. -               str_format(aBuf, sizeof(aBuf), "%d/%d KiB", Client()->MapDownloadAmount()/1024, Client()->MapDownloadTotalsize()/1024);
  61. +               if (m_DownloadSpeed == 0)
  62. +               {
  63. +                   str_format(aBuf, sizeof(aBuf), Localize("%d/%d KiB"), Client()->MapDownloadAmount()/1024, Client()->MapDownloadTotalsize()/1024);
  64. +               } else {
  65. +                   char aBuf2[256];
  66. +
  67. +                   double remaining = abs( (Client()->MapDownloadTotalsize() - Client()->MapDownloadAmount()) / m_DownloadSpeed );
  68. +                   str_format(aBuf, sizeof(aBuf), Localize("%d/%d KiB (%.1f KiB/sec)"), Client()->MapDownloadAmount() / 1024, Client()->MapDownloadTotalsize() / 1024, m_DownloadSpeed / 1024.0f);
  69. +
  70. +                   char * aBufEnd = aBuf + str_length(aBuf);
  71. +                   char * aBufMax = aBuf + sizeof(aBuf);
  72. +                                                                      
  73. +                   str_format(aBufEnd, aBufMax - aBufEnd, "\n\n%s ", Localize("Please wait"));
  74. +                   while (aBufEnd[0]) aBufEnd++;
  75. +
  76. +                   if (remaining > 60.0)
  77. +                   {
  78. +                       int minutes = (int)(remaining / 60.0);
  79. +                       int seconds = (int)remaining % 60;
  80. +
  81. +                       str_format(aBuf2, sizeof(aBuf2), Localize("%d minute(s)"), minutes);
  82. +                       str_format(aBufEnd, aBufMax - aBufEnd, "%s ", Localize(aBuf2)); // localize number texts
  83. +                       while (aBufEnd[0]) aBufEnd++;
  84. +
  85. +                       if (seconds)
  86. +                       {
  87. +                           str_format(aBuf2, sizeof(aBuf2), Localize("%d second(s)"), seconds);
  88. +                           str_format(aBufEnd, aBufMax - aBufEnd, "%s", Localize(aBuf2)); // localize number texts
  89. +                       }
  90. +                   } else {
  91. +                       str_format(aBuf2, sizeof(aBuf2), Localize("%d second(s)"), (int)remaining);
  92. +                       str_format(aBufEnd, aBufMax - aBufEnd, "%s", Localize(aBuf2)); // localize number texts
  93. +                   }
  94. +               }
  95.                 pExtraText = aBuf;
  96. +
  97. +               bProgressBar = true;
  98. +               fProgress = clamp((float)Client()->MapDownloadAmount() / (float)Client()->MapDownloadTotalsize(), 0.0f, 1.0f);
  99.             }
  100.         }
  101.         else if(m_Popup == POPUP_DISCONNECTED)
  102. @@ -916,6 +982,19 @@
  103.         else
  104.             UI()->DoLabel(&Part, pExtraText, 20.f, 0, -1);
  105.  
  106. +       if(bProgressBar)
  107. +       {
  108. +           CUIRect Rect;
  109. +           Rect.x = Screen.x + 175.0f;
  110. +           Rect.y = Screen.h - 225.0f;
  111. +           Rect.w = Screen.w - 350.0f;
  112. +           Rect.h = 25.0f;
  113. +           RenderTools()->DrawUIRect(&Rect, vec4(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 5.0f);
  114. +
  115. +           Rect.w *= fProgress;
  116. +           RenderTools()->DrawUIRect(&Rect, vec4(1.0f, 1.0f, 1.0f, 0.5f), CUI::CORNER_ALL, 5.0f);
  117. +       }
  118. +
  119.         if(m_Popup == POPUP_QUIT)
  120.         {
  121.             CUIRect Yes, No;
  122. diff -Naur a/src/game/client/components/menus.h b/src/game/client/components/menus.h
  123. --- a/src/game/client/components/menus.h    2010-11-19 16:25:07.572000000 +0500
  124. +++ b/src/game/client/components/menus.h    2010-11-19 16:11:19.481000000 +0500
  125. @@ -174,6 +174,11 @@
  126.     int m_DemolistSelectedIndex;
  127.     bool m_DemolistSelectedIsDir;
  128.     int m_DemolistStorageType;
  129. +
  130. +   // for download bar
  131. +   int m_DownloadLastCheckTime;
  132. +   unsigned long m_DownloadLastCheckSize;
  133. +   float m_DownloadSpeed;
  134.    
  135.     void DemolistOnUpdate(bool Reset);
  136.     void DemolistPopulate();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement