Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

381 lines
9.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #include "cbase.h"
  10. #include "iloadingdisc.h"
  11. #include "vgui_controls/Frame.h"
  12. #include "vgui_controls/Label.h"
  13. #include "vgui_controls/ProgressBar.h"
  14. #include "hud_numericdisplay.h"
  15. #include "vgui/ISurface.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. //-----------------------------------------------------------------------------
  19. const int NumSegments = 7;
  20. static int coord[NumSegments+1] = {
  21. 0,
  22. 1,
  23. 2,
  24. 3,
  25. 4,
  26. 6,
  27. 9,
  28. 10
  29. };
  30. //-----------------------------------------------------------------------------
  31. static void DrawRoundedBackground( Color bgColor, int wide, int tall )
  32. {
  33. int x1, x2, y1, y2;
  34. vgui::surface()->DrawSetColor(bgColor);
  35. vgui::surface()->DrawSetTextColor(bgColor);
  36. int i;
  37. // top-left corner --------------------------------------------------------
  38. int xDir = 1;
  39. int yDir = -1;
  40. int xIndex = 0;
  41. int yIndex = NumSegments - 1;
  42. int xMult = 1;
  43. int yMult = 1;
  44. int x = 0;
  45. int y = 0;
  46. for ( i=0; i<NumSegments; ++i )
  47. {
  48. x1 = MIN( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  49. x2 = MAX( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  50. y1 = MAX( y + coord[yIndex]*yMult, y + coord[yIndex+1]*yMult );
  51. y2 = y + coord[NumSegments];
  52. vgui::surface()->DrawFilledRect( x1, y1, x2, y2 );
  53. xIndex += xDir;
  54. yIndex += yDir;
  55. }
  56. // top-right corner -------------------------------------------------------
  57. xDir = 1;
  58. yDir = -1;
  59. xIndex = 0;
  60. yIndex = NumSegments - 1;
  61. x = wide;
  62. y = 0;
  63. xMult = -1;
  64. yMult = 1;
  65. for ( i=0; i<NumSegments; ++i )
  66. {
  67. x1 = MIN( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  68. x2 = MAX( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  69. y1 = MAX( y + coord[yIndex]*yMult, y + coord[yIndex+1]*yMult );
  70. y2 = y + coord[NumSegments];
  71. vgui::surface()->DrawFilledRect( x1, y1, x2, y2 );
  72. xIndex += xDir;
  73. yIndex += yDir;
  74. }
  75. // bottom-right corner ----------------------------------------------------
  76. xDir = 1;
  77. yDir = -1;
  78. xIndex = 0;
  79. yIndex = NumSegments - 1;
  80. x = wide;
  81. y = tall;
  82. xMult = -1;
  83. yMult = -1;
  84. for ( i=0; i<NumSegments; ++i )
  85. {
  86. x1 = MIN( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  87. x2 = MAX( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  88. y1 = y - coord[NumSegments];
  89. y2 = MIN( y + coord[yIndex]*yMult, y + coord[yIndex+1]*yMult );
  90. vgui::surface()->DrawFilledRect( x1, y1, x2, y2 );
  91. xIndex += xDir;
  92. yIndex += yDir;
  93. }
  94. // bottom-left corner -----------------------------------------------------
  95. xDir = 1;
  96. yDir = -1;
  97. xIndex = 0;
  98. yIndex = NumSegments - 1;
  99. x = 0;
  100. y = tall;
  101. xMult = 1;
  102. yMult = -1;
  103. for ( i=0; i<NumSegments; ++i )
  104. {
  105. x1 = MIN( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  106. x2 = MAX( x + coord[xIndex]*xMult, x + coord[xIndex+1]*xMult );
  107. y1 = y - coord[NumSegments];
  108. y2 = MIN( y + coord[yIndex]*yMult, y + coord[yIndex+1]*yMult );
  109. vgui::surface()->DrawFilledRect( x1, y1, x2, y2 );
  110. xIndex += xDir;
  111. yIndex += yDir;
  112. }
  113. // paint between top left and bottom left ---------------------------------
  114. x1 = 0;
  115. x2 = coord[NumSegments];
  116. y1 = coord[NumSegments];
  117. y2 = tall - coord[NumSegments];
  118. vgui::surface()->DrawFilledRect( x1, y1, x2, y2 );
  119. // paint between left and right -------------------------------------------
  120. x1 = coord[NumSegments];
  121. x2 = wide - coord[NumSegments];
  122. y1 = 0;
  123. y2 = tall;
  124. vgui::surface()->DrawFilledRect( x1, y1, x2, y2 );
  125. // paint between top right and bottom right -------------------------------
  126. x1 = wide - coord[NumSegments];
  127. x2 = wide;
  128. y1 = coord[NumSegments];
  129. y2 = tall - coord[NumSegments];
  130. vgui::surface()->DrawFilledRect( x1, y1, x2, y2 );
  131. }
  132. //-----------------------------------------------------------------------------
  133. // Purpose: Displays the loading plaque
  134. //-----------------------------------------------------------------------------
  135. class CLoadingDiscPanel : public vgui::EditablePanel
  136. {
  137. typedef vgui::EditablePanel BaseClass;
  138. public:
  139. explicit CLoadingDiscPanel( vgui::VPANEL parent );
  140. ~CLoadingDiscPanel();
  141. virtual void ApplySchemeSettings( vgui::IScheme *pScheme )
  142. {
  143. BaseClass::ApplySchemeSettings( pScheme );
  144. int w, h;
  145. w = ScreenWidth();
  146. h = ScreenHeight();
  147. if ( w != m_ScreenSize[ 0 ] ||
  148. h != m_ScreenSize[ 1 ] )
  149. {
  150. m_ScreenSize[ 0 ] = w;
  151. m_ScreenSize[ 1 ] = h;
  152. // Re-perform the layout if the screen size changed
  153. LoadControlSettings( "resource/LoadingDiscPanel.res" );
  154. }
  155. // center the dialog
  156. int wide, tall;
  157. GetSize( wide, tall );
  158. SetPos( ( w - wide ) / 2, ( h - tall ) / 2 );
  159. }
  160. virtual void PaintBackground( void )
  161. {
  162. int wide, tall;
  163. GetSize( wide, tall );
  164. DrawRoundedBackground( Color(0, 0, 0, 255), wide, tall );
  165. }
  166. virtual void SetText( const char *text, int nWidthAdjust = 0 )
  167. {
  168. m_pLoadingLabel->SetText( text );
  169. SetWide( m_nOriginalWidth + nWidthAdjust );
  170. m_pLoadingLabel->SetWide( m_nOriginalWidth + nWidthAdjust );
  171. int wide, tall;
  172. GetSize( wide, tall );
  173. SetPos( ( m_ScreenSize[ 0 ] - wide ) / 2, ( m_ScreenSize[ 1 ] - tall ) / 2 );
  174. }
  175. bool UpdateProgressBar( float progress, const char *statusText )
  176. {
  177. m_pProgressBar->SetBarInset( 2 );
  178. float currentProgress = m_pProgressBar->GetProgress();
  179. m_pProgressBar->SetProgress( progress );
  180. return m_pProgressBar->GetProgress() != currentProgress;
  181. }
  182. vgui::VPANEL GetProgressBarVPanel( void )
  183. {
  184. if ( !m_pProgressBar )
  185. return 0;
  186. return m_pProgressBar->GetVPanel();
  187. }
  188. private:
  189. vgui::Label *m_pLoadingLabel;
  190. vgui::ProgressBar *m_pProgressBar;
  191. int m_ScreenSize[ 2 ];
  192. int m_nOriginalWidth;
  193. };
  194. //-----------------------------------------------------------------------------
  195. // Purpose: Constructor
  196. //-----------------------------------------------------------------------------
  197. CLoadingDiscPanel::CLoadingDiscPanel( vgui::VPANEL parent ) : BaseClass( NULL, "CLoadingDiscPanel" )
  198. {
  199. int w, h;
  200. w = ScreenWidth();
  201. h = ScreenHeight();
  202. SetParent( parent );
  203. SetProportional( true );
  204. SetScheme( "ClientScheme" );
  205. SetVisible( false );
  206. SetCursor( NULL );
  207. m_pLoadingLabel = vgui::SETUP_PANEL(new vgui::Label( this, "LoadingLabel", "" ));
  208. m_pLoadingLabel->SetPaintBackgroundEnabled( false );
  209. m_pProgressBar = vgui::SETUP_PANEL(new vgui::ProgressBar( this, "LoadingProgress" ));
  210. LoadControlSettings( "resource/LoadingDiscPanel.res" );
  211. // center the dialog
  212. int wide, tall;
  213. GetSize( wide, tall );
  214. SetPos( ( w - wide ) / 2, ( h - tall ) / 2 );
  215. m_nOriginalWidth = wide;
  216. m_ScreenSize[ 0 ] = w;
  217. m_ScreenSize[ 1 ] = h;
  218. }
  219. //-----------------------------------------------------------------------------
  220. // Purpose: Destructor
  221. //-----------------------------------------------------------------------------
  222. CLoadingDiscPanel::~CLoadingDiscPanel()
  223. {
  224. }
  225. class CLoadingDisc : public ILoadingDisc
  226. {
  227. private:
  228. CLoadingDiscPanel *loadingDiscPanel;
  229. CLoadingDiscPanel *m_pPauseDiscPanel;
  230. CLoadingDiscPanel *m_pFastForwardDiscPanel;
  231. vgui::VPANEL m_hParent;
  232. public:
  233. CLoadingDisc( void )
  234. {
  235. loadingDiscPanel = NULL;
  236. m_pPauseDiscPanel = NULL;
  237. m_pFastForwardDiscPanel = NULL;
  238. }
  239. void Create( vgui::VPANEL parent )
  240. {
  241. // don't create now, only when it's needed
  242. m_hParent = parent;
  243. }
  244. void Destroy( void )
  245. {
  246. if ( loadingDiscPanel )
  247. {
  248. loadingDiscPanel->SetParent( (vgui::Panel *)NULL );
  249. delete loadingDiscPanel;
  250. }
  251. if ( m_pPauseDiscPanel )
  252. {
  253. m_pPauseDiscPanel->SetParent( (vgui::Panel *)NULL );
  254. delete m_pPauseDiscPanel;
  255. }
  256. if ( m_pFastForwardDiscPanel )
  257. {
  258. m_pFastForwardDiscPanel->SetParent( (vgui::Panel *)NULL );
  259. delete m_pFastForwardDiscPanel;
  260. }
  261. }
  262. void SetLoadingVisible( bool bVisible )
  263. {
  264. // demand-create the dialog
  265. if ( bVisible && !loadingDiscPanel )
  266. {
  267. loadingDiscPanel = vgui::SETUP_PANEL(new CLoadingDiscPanel( m_hParent ) );
  268. }
  269. if ( loadingDiscPanel )
  270. {
  271. loadingDiscPanel->SetVisible( bVisible );
  272. }
  273. }
  274. void SetPausedVisible( bool bVisible )
  275. {
  276. if ( bVisible && !m_pPauseDiscPanel )
  277. {
  278. m_pPauseDiscPanel = vgui::SETUP_PANEL(new CLoadingDiscPanel( m_hParent ) );
  279. m_pPauseDiscPanel->SetText( "#gameui_paused" );
  280. }
  281. if ( m_pPauseDiscPanel )
  282. {
  283. m_pPauseDiscPanel->SetVisible( bVisible );
  284. }
  285. }
  286. void SetFastForwardVisible( bool bVisible, bool bHighlight )
  287. {
  288. if ( bVisible )
  289. {
  290. if ( !m_pFastForwardDiscPanel )
  291. {
  292. m_pFastForwardDiscPanel = vgui::SETUP_PANEL(new CLoadingDiscPanel( m_hParent ) );
  293. }
  294. if ( bHighlight )
  295. {
  296. m_pFastForwardDiscPanel->SetText( "#SFUIHUD_Spectate_SpecMode_Skipping_Highlight", 120 );
  297. }
  298. else
  299. {
  300. m_pFastForwardDiscPanel->SetText( "#SFUIHUD_Spectate_SpecMode_Skipping" );
  301. }
  302. }
  303. if ( m_pFastForwardDiscPanel )
  304. {
  305. m_pFastForwardDiscPanel->SetVisible( bVisible );
  306. }
  307. }
  308. bool UpdateProgressBar( float progress, const char *statusText )
  309. {
  310. if ( loadingDiscPanel && loadingDiscPanel->IsVisible() )
  311. {
  312. return loadingDiscPanel->UpdateProgressBar( progress, statusText );
  313. }
  314. return false;
  315. }
  316. unsigned int GetLoadingVPANEL( void )
  317. {
  318. if ( loadingDiscPanel )
  319. return loadingDiscPanel->GetProgressBarVPanel();
  320. return 0;
  321. }
  322. };
  323. static CLoadingDisc g_LoadingDisc;
  324. ILoadingDisc *loadingdisc = ( ILoadingDisc * )&g_LoadingDisc;