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.

118 lines
2.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "hud.h"
  8. #include "hud_subtitles.h"
  9. #include "iclientmode.h"
  10. #include <vgui/ISurface.h>
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. using namespace vgui;
  14. DECLARE_HUDELEMENT( CHudSubtitles );
  15. CHudSubtitles::CHudSubtitles( const char *pElementName ) :
  16. CHudElement( pElementName ),
  17. BaseClass( NULL, "HudSubtitles" )
  18. {
  19. vgui::Panel *pParent = GetClientMode()->GetViewport();
  20. SetParent( pParent );
  21. SetScheme( "basemodui_scheme" );
  22. SetProportional( true );
  23. int nScreenWide, nScreenTall;
  24. vgui::surface()->GetScreenSize( nScreenWide, nScreenTall );
  25. SetPos( 0, 0 );
  26. SetSize( nScreenWide, nScreenTall );
  27. m_pSubtitlePanel = NULL;
  28. m_bIsPaused = false;
  29. }
  30. CHudSubtitles::~CHudSubtitles()
  31. {
  32. delete m_pSubtitlePanel;
  33. m_pSubtitlePanel = NULL;
  34. }
  35. void CHudSubtitles::ApplySchemeSettings( IScheme *pScheme )
  36. {
  37. BaseClass::ApplySchemeSettings( pScheme );
  38. }
  39. void CHudSubtitles::StartCaptions( const char *pFilename )
  40. {
  41. bool bUseCaptioning = ShouldUseCaptioning();
  42. if ( !bUseCaptioning )
  43. return;
  44. StopCaptions();
  45. // start the subtitle sequence
  46. m_pSubtitlePanel = new CSubtitlePanel( this, pFilename, GetTall() );
  47. if ( !m_pSubtitlePanel->StartCaptions() )
  48. {
  49. StopCaptions();
  50. }
  51. }
  52. void CHudSubtitles::StopCaptions()
  53. {
  54. delete m_pSubtitlePanel;
  55. m_pSubtitlePanel = NULL;
  56. }
  57. void CHudSubtitles::LevelShutdown()
  58. {
  59. StopCaptions();
  60. }
  61. void CHudSubtitles::Reset()
  62. {
  63. StopCaptions();
  64. }
  65. //-----------------------------------------------------------------------------
  66. // Purpose: Save CPU cycles by letting the HUD system early cull
  67. // costly traversal. Called per frame, return true if thinking and
  68. // painting need to occur.
  69. //-----------------------------------------------------------------------------
  70. bool CHudSubtitles::ShouldDraw()
  71. {
  72. bool bIsPaused = engine->IsPaused();
  73. if ( m_bIsPaused != bIsPaused )
  74. {
  75. m_bIsPaused = bIsPaused;
  76. if ( m_pSubtitlePanel )
  77. {
  78. m_pSubtitlePanel->Pause( m_bIsPaused );
  79. }
  80. }
  81. bool bNeedsDraw = m_pSubtitlePanel && m_pSubtitlePanel->HasCaptions();
  82. if ( !CHudElement::ShouldDraw() )
  83. {
  84. bNeedsDraw = false;
  85. }
  86. return bNeedsDraw;
  87. }
  88. CON_COMMAND( hud_subtitles, "Plays the Subtitles: <filename>" )
  89. {
  90. if ( args.ArgC() < 2 )
  91. return;
  92. CHudSubtitles *pHudSubtitles = GET_FULLSCREEN_HUDELEMENT( CHudSubtitles );
  93. if ( pHudSubtitles )
  94. {
  95. pHudSubtitles->StartCaptions( args[1] );
  96. }
  97. }