Team Fortress 2 Source Code as on 22/4/2020
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.

209 lines
4.9 KiB

  1. //========= Copyright 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 "hud_numericdisplay.h"
  14. #include "vgui/ISurface.h"
  15. #include "vgui/ILocalize.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. extern vgui::ILocalize *g_pVGuiLocalize;
  19. //-----------------------------------------------------------------------------
  20. // Purpose: Displays the loading plaque
  21. //-----------------------------------------------------------------------------
  22. class CLoadingDiscPanel : public vgui::EditablePanel
  23. {
  24. typedef vgui::EditablePanel BaseClass;
  25. public:
  26. CLoadingDiscPanel( vgui::VPANEL parent );
  27. ~CLoadingDiscPanel();
  28. virtual void ApplySchemeSettings( vgui::IScheme *pScheme )
  29. {
  30. BaseClass::ApplySchemeSettings( pScheme );
  31. int w, h;
  32. w = ScreenWidth();
  33. h = ScreenHeight();
  34. if ( w != m_ScreenSize[ 0 ] ||
  35. h != m_ScreenSize[ 1 ] )
  36. {
  37. m_ScreenSize[ 0 ] = w;
  38. m_ScreenSize[ 1 ] = h;
  39. // Re-perform the layout if the screen size changed
  40. LoadControlSettings( "resource/LoadingDiscPanel.res" );
  41. }
  42. // center the dialog
  43. int wide, tall;
  44. GetSize( wide, tall );
  45. SetPos( ( w - wide ) / 2, ( h - tall ) / 2 );
  46. }
  47. virtual void PaintBackground()
  48. {
  49. SetBgColor( Color(0, 0, 0, 128) );
  50. SetPaintBackgroundType( 2 );
  51. BaseClass::PaintBackground();
  52. }
  53. virtual void SetText( const char *text )
  54. {
  55. m_pLoadingLabel->SetText( text );
  56. }
  57. private:
  58. vgui::Label *m_pLoadingLabel;
  59. int m_ScreenSize[ 2 ];
  60. };
  61. //-----------------------------------------------------------------------------
  62. // Purpose: Constructor
  63. //-----------------------------------------------------------------------------
  64. CLoadingDiscPanel::CLoadingDiscPanel( vgui::VPANEL parent ) : BaseClass( NULL, "CLoadingDiscPanel" )
  65. {
  66. int w, h;
  67. w = ScreenWidth();
  68. h = ScreenHeight();
  69. SetParent( parent );
  70. SetProportional( true );
  71. SetScheme( "ClientScheme" );
  72. SetVisible( false );
  73. SetCursor( NULL );
  74. m_pLoadingLabel = vgui::SETUP_PANEL(new vgui::Label( this, "LoadingLabel", "" ));
  75. m_pLoadingLabel->SetPaintBackgroundEnabled( false );
  76. LoadControlSettings( "resource/LoadingDiscPanel.res" );
  77. // center the dialog
  78. int wide, tall;
  79. GetSize( wide, tall );
  80. SetPos( ( w - wide ) / 2, ( h - tall ) / 2 );
  81. m_ScreenSize[ 0 ] = w;
  82. m_ScreenSize[ 1 ] = h;
  83. }
  84. //-----------------------------------------------------------------------------
  85. // Purpose: Destructor
  86. //-----------------------------------------------------------------------------
  87. CLoadingDiscPanel::~CLoadingDiscPanel()
  88. {
  89. }
  90. class CLoadingDisc : public ILoadingDisc
  91. {
  92. private:
  93. CLoadingDiscPanel *loadingDiscPanel;
  94. CLoadingDiscPanel *m_pPauseDiscPanel;
  95. vgui::VPANEL m_hParent;
  96. int m_nPrevTimeRemaining;
  97. public:
  98. CLoadingDisc( void )
  99. {
  100. loadingDiscPanel = NULL;
  101. m_pPauseDiscPanel = NULL;
  102. m_nPrevTimeRemaining = -1;
  103. }
  104. void Create( vgui::VPANEL parent )
  105. {
  106. // don't create now, only when it's needed
  107. m_hParent = parent;
  108. }
  109. void Destroy( void )
  110. {
  111. if ( loadingDiscPanel )
  112. {
  113. loadingDiscPanel->SetParent( (vgui::Panel *)NULL );
  114. loadingDiscPanel->MarkForDeletion();
  115. loadingDiscPanel = NULL;
  116. }
  117. if ( m_pPauseDiscPanel )
  118. {
  119. m_pPauseDiscPanel->SetParent( (vgui::Panel *)NULL );
  120. m_pPauseDiscPanel->MarkForDeletion();
  121. m_pPauseDiscPanel = NULL;
  122. }
  123. m_hParent = NULL;
  124. }
  125. void SetLoadingVisible( bool bVisible )
  126. {
  127. // demand-create the dialog
  128. if ( bVisible && !loadingDiscPanel )
  129. {
  130. loadingDiscPanel = vgui::SETUP_PANEL(new CLoadingDiscPanel( m_hParent ) );
  131. }
  132. if ( loadingDiscPanel )
  133. {
  134. loadingDiscPanel->SetVisible( bVisible );
  135. }
  136. }
  137. void SetPausedVisible( bool bVisible, float flExpireTime /*= -1.f */)
  138. {
  139. if ( bVisible )
  140. {
  141. if ( !m_pPauseDiscPanel )
  142. {
  143. m_pPauseDiscPanel = vgui::SETUP_PANEL(new CLoadingDiscPanel( m_hParent ) );
  144. }
  145. if ( m_pPauseDiscPanel )
  146. {
  147. // Update when we have a timer
  148. if ( flExpireTime != -1.f )
  149. {
  150. int nTime = (int)( flExpireTime - Plat_FloatTime() );
  151. if ( nTime != m_nPrevTimeRemaining )
  152. {
  153. wchar_t wzString[256];
  154. wchar_t wzTime[64];
  155. char szString[256];
  156. _snwprintf( wzTime, sizeof( wzTime ), L"%d", nTime );
  157. g_pVGuiLocalize->ConstructString_safe( wzString, g_pVGuiLocalize->Find( "#GameUI_PausedTimer" ), 1, wzTime );
  158. g_pVGuiLocalize->ConvertUnicodeToANSI( wzString, szString, sizeof( szString ) );
  159. m_pPauseDiscPanel->SetText( szString );
  160. m_nPrevTimeRemaining = nTime;
  161. }
  162. }
  163. else if ( m_pPauseDiscPanel->IsVisible() != bVisible )
  164. {
  165. m_pPauseDiscPanel->SetText( "#gameui_paused" );
  166. }
  167. }
  168. }
  169. if ( m_pPauseDiscPanel )
  170. {
  171. m_pPauseDiscPanel->SetVisible( bVisible );
  172. }
  173. }
  174. };
  175. static CLoadingDisc g_LoadingDisc;
  176. ILoadingDisc *loadingdisc = ( ILoadingDisc * )&g_LoadingDisc;