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.

128 lines
2.8 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 "cs_gamerules.h"
  12. #include "hud_numericdisplay.h"
  13. class CHudC4 : public CHudElement, public vgui::Panel
  14. {
  15. public:
  16. DECLARE_CLASS_SIMPLE( CHudC4, vgui::Panel );
  17. CHudC4( const char *name );
  18. virtual bool ShouldDraw();
  19. virtual void Paint();
  20. virtual void Init();
  21. private:
  22. CPanelAnimationVar( Color, m_clrIcon, "IconColor", "IconColor" );
  23. CPanelAnimationVar( Color, m_clrFlash, "FlashColor", "FlashColor" );
  24. CHudTexture *m_pIcon;
  25. float m_flNextFlashTime;
  26. bool m_bFlash;
  27. };
  28. DECLARE_HUDELEMENT( CHudC4 );
  29. CHudC4::CHudC4( const char *pName ) :
  30. vgui::Panel( NULL, "HudC4" ), CHudElement( pName )
  31. {
  32. SetParent( g_pClientMode->GetViewport() );
  33. m_pIcon = NULL;
  34. SetHiddenBits( HIDEHUD_PLAYERDEAD );
  35. //=============================================================================
  36. // HPE_BEGIN:
  37. // [tj] Add this to the render group that disappears when the scoreboard is up
  38. //=============================================================================
  39. RegisterForRenderGroup( "hide_for_scoreboard" );
  40. //=============================================================================
  41. // HPE_END
  42. //=============================================================================
  43. }
  44. void CHudC4::Init()
  45. {
  46. m_flNextFlashTime = 0;
  47. m_bFlash = false;
  48. }
  49. bool CHudC4::ShouldDraw()
  50. {
  51. C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
  52. // if we are spectating another player first person, check this player
  53. if ( pPlayer && (pPlayer->GetObserverMode() == OBS_MODE_IN_EYE) )
  54. {
  55. pPlayer = ToCSPlayer( pPlayer->GetObserverTarget() );
  56. }
  57. //=============================================================================
  58. // HPE_BEGIN:
  59. // [tj] Added base class call
  60. //=============================================================================
  61. return pPlayer && pPlayer->HasC4() && CHudElement::ShouldDraw();
  62. //=============================================================================
  63. // HPE_END
  64. //=============================================================================
  65. }
  66. void CHudC4::Paint()
  67. {
  68. if ( !m_pIcon )
  69. {
  70. m_pIcon = gHUD.GetIcon( "c4" );
  71. }
  72. C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
  73. if ( !pPlayer )
  74. return;
  75. if( pPlayer->m_bInBombZone )
  76. {
  77. if( m_flNextFlashTime < gpGlobals->curtime )
  78. {
  79. m_bFlash = !m_bFlash;
  80. m_flNextFlashTime = gpGlobals->curtime + 0.15;
  81. }
  82. }
  83. else
  84. {
  85. m_bFlash = false;
  86. }
  87. int x, y, w, h;
  88. GetBounds( x, y, w, h );
  89. if ( m_pIcon )
  90. {
  91. if( m_bFlash )
  92. {
  93. m_pIcon->DrawSelf( 0, 0, w, h, m_clrFlash );
  94. }
  95. else
  96. {
  97. m_pIcon->DrawSelf( 0, 0, w, h, m_clrIcon );
  98. }
  99. }
  100. }