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.

163 lines
4.1 KiB

  1. //====== Copyright � 1996-2007, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: VGUI panel which can play back video, in-engine
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "vgui_hudvideo.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. using namespace vgui;
  11. #define BIK_MEDIA_FOLDER "media/"
  12. #define BIK_EXTENTION ".bik"
  13. HUDVideoPanel::HUDVideoPanel( vgui::Panel *parent, const char *name ) :
  14. BaseClass( 0, 0, 32, 32 )
  15. {
  16. SetParent( parent );
  17. SetName( name );
  18. m_bStopAllSounds = false;
  19. m_nAllowInterruption = 0;
  20. m_szLoopVideo[ 0 ] = '\0';
  21. m_szLastTempVideo[ 0 ] = '\0';
  22. m_nNumLoopAlternatives = 0;
  23. m_fAlternateChance = 1.0f;
  24. m_bIsLoopVideo = true;
  25. m_bIsTransition = false;
  26. }
  27. void HUDVideoPanel::Paint( void )
  28. {
  29. BaseClass::Paint();
  30. if ( !m_bStarted )
  31. {
  32. BeginPlayback( VarArgs( BIK_MEDIA_FOLDER "%s" BIK_EXTENTION, m_szLoopVideo ) );
  33. }
  34. }
  35. void HUDVideoPanel::Activate( void )
  36. {
  37. SetVisible( true );
  38. SetEnabled( true );
  39. }
  40. void HUDVideoPanel::DoModal( void )
  41. {
  42. Activate();
  43. }
  44. void HUDVideoPanel::OnVideoOver()
  45. {
  46. if ( m_bIsTransition )
  47. {
  48. m_bIsTransition = false;
  49. BeginPlayback( VarArgs( BIK_MEDIA_FOLDER "%s" BIK_EXTENTION, m_szLastTempVideo ) );
  50. }
  51. else if ( !m_bIsLoopVideo )
  52. {
  53. m_bIsLoopVideo = true;
  54. BeginPlayback( VarArgs( BIK_MEDIA_FOLDER "%s" BIK_EXTENTION, m_szLoopVideo ) );
  55. }
  56. else if ( m_nNumLoopAlternatives > 0 && RandomFloat() < m_fAlternateChance )
  57. {
  58. char szAltName[ FILENAME_MAX ];
  59. Q_snprintf( szAltName, sizeof( szAltName ), "%s_alt%02i", m_szLoopVideo, RandomInt( 0, m_nNumLoopAlternatives - 1 ) );
  60. PlayTempVideo( szAltName );
  61. }
  62. else
  63. {
  64. bik->SetFrame( m_BIKHandle, 0.0f );
  65. }
  66. }
  67. void HUDVideoPanel::ReturnToLoopVideo( void )
  68. {
  69. if ( !m_bIsLoopVideo )
  70. {
  71. m_bIsLoopVideo = true;
  72. BeginPlayback( VarArgs( BIK_MEDIA_FOLDER "%s" BIK_EXTENTION, m_szLoopVideo ) );
  73. }
  74. }
  75. void HUDVideoPanel::PlayTempVideo( const char *pFilename, const char *pTransitionFilename /*= NULL*/ )
  76. {
  77. if ( !pFilename || Q_strcmp( GetCurrentVideo(), pFilename ) == 0 )
  78. {
  79. return;
  80. }
  81. Q_strncpy( m_szLastTempVideo, pFilename, sizeof( m_szLastTempVideo ) );
  82. m_bIsLoopVideo = false;
  83. m_bIsTransition = ( pTransitionFilename != NULL && pTransitionFilename[ 0 ] != '\0' );
  84. BeginPlayback( VarArgs( BIK_MEDIA_FOLDER "%s" BIK_EXTENTION, ( m_bIsTransition ? pTransitionFilename : m_szLastTempVideo ) ) );
  85. }
  86. void HUDVideoPanel::SetLoopVideo( const char *pFilename, int nNumLoopAlternatives /*= 0*/, float fAlternateChance /*= 1.0f*/ )
  87. {
  88. m_nNumLoopAlternatives = nNumLoopAlternatives;
  89. m_fAlternateChance = fAlternateChance;
  90. if ( !pFilename || Q_strcmp( m_szLoopVideo, pFilename ) == 0 )
  91. {
  92. return;
  93. }
  94. Q_strncpy( m_szLoopVideo, pFilename, sizeof( m_szLoopVideo ) );
  95. if ( m_bIsLoopVideo && m_bStarted )
  96. {
  97. BeginPlayback( VarArgs( BIK_MEDIA_FOLDER "%s" BIK_EXTENTION, m_szLoopVideo ) );
  98. }
  99. }
  100. const char* HUDVideoPanel::GetCurrentVideo( void ) const
  101. {
  102. return ( m_bIsLoopVideo ? GetLoopVideo() : GetLastTempVideo() );
  103. }
  104. //-----------------------------------------------------------------------------
  105. // Purpose: Create and playback a video in a panel
  106. //-----------------------------------------------------------------------------
  107. HUDVideoPanel *HUDVideoPanel_Create( vgui::Panel *pParent,
  108. unsigned int iWide, unsigned int iTall,
  109. const char *pVideoFilename,
  110. const char *pExitCommand /*= NULL*/,
  111. float flFadeInTime /*= 1*/,
  112. bool bLoop /*= false*/,
  113. bool bPreloadVideo /*= false*/ )
  114. {
  115. // Create the base video panel
  116. HUDVideoPanel *pVideoPanel = new HUDVideoPanel( pParent, "HUDVideoPanel" );
  117. if ( pVideoPanel == NULL )
  118. return NULL;
  119. pVideoPanel->SetSize( iWide, iTall );
  120. pVideoPanel->SetExitCommand( pExitCommand );
  121. pVideoPanel->SetFadeInTime( flFadeInTime );
  122. pVideoPanel->SetLooping( bLoop );
  123. pVideoPanel->SetIsTransitionVideo( false );
  124. //pVideoPanel->SetShouldPreload ( bPreloadVideo );
  125. // Start it going
  126. if ( pVideoPanel->BeginPlayback( pVideoFilename ) == false )
  127. {
  128. delete pVideoPanel;
  129. return NULL;
  130. }
  131. return pVideoPanel;
  132. }