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.

95 lines
2.2 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 "c_tf_player.h"
  11. #include "clientmode_tf.h"
  12. class CHudSmokeBomb : public CHudElement, public vgui::Panel
  13. {
  14. public:
  15. DECLARE_CLASS_SIMPLE( CHudSmokeBomb, vgui::Panel );
  16. CHudSmokeBomb( const char *name );
  17. virtual bool ShouldDraw();
  18. virtual void Paint();
  19. virtual void Init();
  20. private:
  21. CHudTexture *m_pIcon;
  22. };
  23. DECLARE_HUDELEMENT( CHudSmokeBomb );
  24. CHudSmokeBomb::CHudSmokeBomb( const char *pName ) :
  25. vgui::Panel( NULL, "HudSmokeBomb" ), CHudElement( pName )
  26. {
  27. SetParent( g_pClientMode->GetViewport() );
  28. m_pIcon = NULL;
  29. SetHiddenBits( HIDEHUD_PLAYERDEAD );
  30. }
  31. void CHudSmokeBomb::Init()
  32. {
  33. }
  34. bool CHudSmokeBomb::ShouldDraw()
  35. {
  36. C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  37. // if we are spectating another player first person, check this player
  38. if ( pPlayer && ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) )
  39. {
  40. pPlayer = ToTFPlayer( pPlayer->GetObserverTarget() );
  41. }
  42. return ( pPlayer && pPlayer->IsAlive() && pPlayer->m_Shared.InCond( TF_COND_SMOKE_BOMB ) );
  43. }
  44. extern ConVar tf_smoke_bomb_time;
  45. void CHudSmokeBomb::Paint()
  46. {
  47. if ( !m_pIcon )
  48. {
  49. m_pIcon = gHUD.GetIcon( "cond_smoke_bomb" );
  50. }
  51. int x, y, w, h;
  52. GetBounds( x, y, w, h );
  53. if ( m_pIcon )
  54. {
  55. m_pIcon->DrawSelf( 0, 0, w, w, Color(255,255,255,255) );
  56. }
  57. // Draw a progress bar for time remaining
  58. int barX = XRES(5);
  59. int barW = w - XRES(10);
  60. int barY = w + YRES(5);
  61. int barH = YRES(10);
  62. C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  63. if ( !pPlayer )
  64. return;
  65. float flExpireTime = pPlayer->m_Shared.GetSmokeBombExpireTime();
  66. float flPercent = ( flExpireTime - gpGlobals->curtime ) / tf_smoke_bomb_time.GetFloat();
  67. surface()->DrawSetColor( Color(0,0,0,255) );
  68. surface()->DrawFilledRect( barX - 1, barY - 1, barX + barW + 1, barY + barH + 1 );
  69. surface()->DrawSetColor( Color(200,200,200,255) );
  70. surface()->DrawFilledRect( barX, barY, barX + (int)( (float)barW * flPercent ), barY + barH );
  71. }