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.

109 lines
2.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "hudelement.h"
  8. #include <vgui_controls/Panel.h>
  9. #include <vgui/ISurface.h>
  10. #include "clientmode_csnormal.h"
  11. #include "c_cs_player.h"
  12. #include "cs_gamerules.h"
  13. #include "c_cs_hostage.h"
  14. #include "c_plantedc4.h"
  15. class CHudScenarioIcon : public CHudElement, public vgui::Panel
  16. {
  17. public:
  18. DECLARE_CLASS_SIMPLE( CHudScenarioIcon, vgui::Panel );
  19. CHudScenarioIcon( const char *name );
  20. virtual bool ShouldDraw();
  21. virtual void Paint();
  22. private:
  23. CPanelAnimationVar( Color, m_clrIcon, "IconColor", "IconColor" );
  24. CHudTexture *m_pC4Icon;
  25. CHudTexture *m_pHostageIcon;
  26. };
  27. DECLARE_HUDELEMENT( CHudScenarioIcon );
  28. CHudScenarioIcon::CHudScenarioIcon( const char *pName ) :
  29. vgui::Panel( NULL, "HudScenarioIcon" ), CHudElement( pName )
  30. {
  31. SetParent( g_pClientMode->GetViewport() );
  32. m_pC4Icon = NULL;
  33. m_pHostageIcon = NULL;
  34. SetHiddenBits( HIDEHUD_PLAYERDEAD );
  35. }
  36. bool CHudScenarioIcon::ShouldDraw()
  37. {
  38. C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
  39. return pPlayer && pPlayer->IsAlive();
  40. }
  41. void CHudScenarioIcon::Paint()
  42. {
  43. // If there is a bomb planted, draw that
  44. if( g_PlantedC4s.Count() > 0 )
  45. {
  46. if ( !m_pC4Icon )
  47. {
  48. m_pC4Icon = gHUD.GetIcon( "scenario_c4" );
  49. }
  50. if ( m_pC4Icon )
  51. {
  52. int x, y, w, h;
  53. GetBounds( x, y, w, h );
  54. C_PlantedC4 *pC4 = g_PlantedC4s[0];
  55. Color c = m_clrIcon;
  56. c[3] = 80;
  57. if( pC4->m_flNextGlow - gpGlobals->curtime < 0.1 )
  58. {
  59. c[3] = 255;
  60. }
  61. if( pC4->IsBombActive() )
  62. m_pC4Icon->DrawSelf( 0, 0, h, h, c ); //draw it square!
  63. }
  64. }
  65. CCSGameRules *pRules = CSGameRules();
  66. // If there are hostages, draw how many there are
  67. if( pRules && pRules->GetNumHostagesRemaining() )
  68. {
  69. if ( !m_pHostageIcon )
  70. {
  71. m_pHostageIcon = gHUD.GetIcon( "scenario_hostage" );
  72. }
  73. if( m_pHostageIcon )
  74. {
  75. int xpos = 0;
  76. int iconWidth = m_pHostageIcon->Width();
  77. for(int i=0;i<pRules->GetNumHostagesRemaining();i++)
  78. {
  79. m_pHostageIcon->DrawSelf( xpos, 0, m_clrIcon );
  80. xpos += iconWidth;
  81. }
  82. }
  83. }
  84. }