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.

179 lines
4.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "c_vguiscreen.h"
  10. #include "vgui_controls/Label.h"
  11. #include "vgui_bitmappanel.h"
  12. #include <vgui/IVGui.h>
  13. #include "c_slideshow_display.h"
  14. #include "ienginevgui.h"
  15. #include "fmtstr.h"
  16. #include "vgui_controls/ImagePanel.h"
  17. // NOTE: This has to be the last file included!
  18. #include "tier0/memdbgon.h"
  19. using namespace vgui;
  20. //-----------------------------------------------------------------------------
  21. // Control screen
  22. //-----------------------------------------------------------------------------
  23. class CSlideshowDisplayScreen : public CVGuiScreenPanel
  24. {
  25. DECLARE_CLASS( CSlideshowDisplayScreen, CVGuiScreenPanel );
  26. public:
  27. CSlideshowDisplayScreen( vgui::Panel *parent, const char *panelName );
  28. virtual void ApplySchemeSettings( IScheme *pScheme );
  29. virtual bool Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData );
  30. virtual void OnTick();
  31. private:
  32. void Update( C_SlideshowDisplay *pSlideshowDisplay );
  33. private:
  34. vgui::Label *m_pDisplayTextLabel;
  35. CUtlVector<ImagePanel*> m_pSlideshowImages;
  36. int iLastSlideIndex;
  37. Color m_cDefault;
  38. Color m_cInvisible;
  39. bool bIsAlreadyVisible;
  40. };
  41. DECLARE_VGUI_SCREEN_FACTORY( CSlideshowDisplayScreen, "slideshow_display_screen" );
  42. //-----------------------------------------------------------------------------
  43. // Constructor:
  44. //-----------------------------------------------------------------------------
  45. CSlideshowDisplayScreen::CSlideshowDisplayScreen( vgui::Panel *parent, const char *panelName )
  46. : BaseClass( parent, "CSlideshowDisplayScreen", vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/SlideshowDisplayScreen.res", "SlideshowDisplayScreen" ) )
  47. {
  48. m_pDisplayTextLabel = new vgui::Label( this, "NumberDisplay", "x" );
  49. iLastSlideIndex = 0;
  50. }
  51. void CSlideshowDisplayScreen::ApplySchemeSettings( IScheme *pScheme )
  52. {
  53. assert( pScheme );
  54. m_cDefault = pScheme->GetColor( "CSlideshowDisplayScreen_Default", GetFgColor() );
  55. m_cInvisible = Color( 0, 0, 0, 0 );
  56. m_pDisplayTextLabel->SetFgColor( m_cDefault );
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Initialization
  60. //-----------------------------------------------------------------------------
  61. bool CSlideshowDisplayScreen::Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData )
  62. {
  63. // Make sure we get ticked...
  64. vgui::ivgui()->AddTickSignal( GetVPanel() );
  65. if (!BaseClass::Init(pKeyValues, pInitData))
  66. return false;
  67. return true;
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Update the display string
  71. //-----------------------------------------------------------------------------
  72. void CSlideshowDisplayScreen::OnTick()
  73. {
  74. BaseClass::OnTick();
  75. if ( g_SlideshowDisplays.Count() <= 0 )
  76. return;
  77. C_SlideshowDisplay *pSlideshowDisplay = NULL;
  78. for ( int iDisplayScreens = 0; iDisplayScreens < g_SlideshowDisplays.Count(); ++iDisplayScreens )
  79. {
  80. C_SlideshowDisplay *pSlideshowDisplayTemp = g_SlideshowDisplays[ iDisplayScreens ];
  81. if ( pSlideshowDisplayTemp && pSlideshowDisplayTemp->IsEnabled() )
  82. {
  83. pSlideshowDisplay = pSlideshowDisplayTemp;
  84. break;
  85. }
  86. }
  87. if( !pSlideshowDisplay )
  88. {
  89. // All display screens are disabled
  90. if ( bIsAlreadyVisible )
  91. {
  92. SetVisible( false );
  93. bIsAlreadyVisible = false;
  94. }
  95. return;
  96. }
  97. if ( !bIsAlreadyVisible )
  98. {
  99. SetVisible( true );
  100. bIsAlreadyVisible = true;
  101. }
  102. Update( pSlideshowDisplay );
  103. }
  104. void CSlideshowDisplayScreen::Update( C_SlideshowDisplay *pSlideshowDisplay )
  105. {
  106. char szBuff[ 256 ];
  107. pSlideshowDisplay->GetDisplayText( szBuff );
  108. m_pDisplayTextLabel->SetText( szBuff );
  109. if ( m_pSlideshowImages.Count() == 0 )
  110. {
  111. // Build the list of image panels!
  112. for ( int iSlide = 0; iSlide < pSlideshowDisplay->NumMaterials(); ++iSlide )
  113. {
  114. m_pSlideshowImages.AddToTail( SETUP_PANEL( new ImagePanel( this, "SlideshowImage" ) ) );
  115. int iMatIndex = pSlideshowDisplay->GetMaterialIndex( iSlide );
  116. if ( iMatIndex > 0 )
  117. {
  118. const char *pMaterialName = GetMaterialNameFromIndex( iMatIndex );
  119. if ( pMaterialName )
  120. {
  121. pMaterialName = Q_strnchr( pMaterialName, '/', Q_strlen( pMaterialName ) );
  122. if ( pMaterialName )
  123. {
  124. pMaterialName = pMaterialName + 1;
  125. m_pSlideshowImages[ iSlide ]->SetImage( pMaterialName );
  126. m_pSlideshowImages[ iSlide ]->SetVisible( false );
  127. m_pSlideshowImages[ iSlide ]->SetZPos( -3 );
  128. m_pSlideshowImages[ iSlide ]->SetWide( GetWide() );
  129. m_pSlideshowImages[ iSlide ]->SetTall( GetTall() );
  130. }
  131. }
  132. }
  133. }
  134. }
  135. int iCurrentSlideIndex = pSlideshowDisplay->CurrentSlideIndex();
  136. if ( iCurrentSlideIndex != iLastSlideIndex )
  137. {
  138. m_pSlideshowImages[ iLastSlideIndex ]->SetVisible( false );
  139. m_pSlideshowImages[ iCurrentSlideIndex ]->SetVisible( true );
  140. iLastSlideIndex = iCurrentSlideIndex;
  141. }
  142. }