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.

124 lines
2.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. //====== Copyright � 1996-2003, Valve Corporation, All rights reserved. =======
  9. //
  10. // Purpose:
  11. //
  12. //=============================================================================
  13. #include "cbase.h"
  14. #include "hudelement.h"
  15. #include <vgui_controls/Panel.h>
  16. #include <vgui/ISurface.h>
  17. #include "clientmode_csnormal.h"
  18. #include "cs_gamerules.h"
  19. #include "hud_numericdisplay.h"
  20. class CHudArmor : public CHudElement, public CHudNumericDisplay
  21. {
  22. public:
  23. DECLARE_CLASS_SIMPLE( CHudArmor, CHudNumericDisplay );
  24. CHudArmor( const char *name );
  25. virtual bool ShouldDraw();
  26. virtual void Paint();
  27. virtual void Init();
  28. virtual void ApplySchemeSettings( IScheme *scheme );
  29. private:
  30. CHudTexture *m_pArmorIcon;
  31. CHudTexture *m_pArmor_HelmetIcon;
  32. CPanelAnimationVarAliasType( float, icon_xpos, "icon_xpos", "0", "proportional_float" );
  33. CPanelAnimationVarAliasType( float, icon_ypos, "icon_ypos", "2", "proportional_float" );
  34. float icon_wide;
  35. float icon_tall;
  36. };
  37. DECLARE_HUDELEMENT( CHudArmor );
  38. CHudArmor::CHudArmor( const char *pName ) : CHudNumericDisplay( NULL, "HudArmor" ), CHudElement( pName )
  39. {
  40. SetHiddenBits( HIDEHUD_HEALTH | HIDEHUD_PLAYERDEAD );
  41. }
  42. void CHudArmor::Init()
  43. {
  44. SetIndent(true);
  45. }
  46. void CHudArmor::ApplySchemeSettings( IScheme *scheme )
  47. {
  48. BaseClass::ApplySchemeSettings( scheme );
  49. if( !m_pArmorIcon )
  50. {
  51. m_pArmorIcon = gHUD.GetIcon( "shield_bright" );
  52. }
  53. if( !m_pArmor_HelmetIcon )
  54. {
  55. m_pArmor_HelmetIcon = gHUD.GetIcon( "shield_kevlar_bright" );
  56. }
  57. if( m_pArmorIcon )
  58. {
  59. icon_tall = GetTall() - YRES(2);
  60. float scale = icon_tall / (float)m_pArmorIcon->Height();
  61. icon_wide = ( scale ) * (float)m_pArmorIcon->Width();
  62. }
  63. }
  64. bool CHudArmor::ShouldDraw()
  65. {
  66. C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
  67. if ( pPlayer )
  68. {
  69. return !pPlayer->IsObserver();
  70. }
  71. else
  72. {
  73. return false;
  74. }
  75. }
  76. void CHudArmor::Paint()
  77. {
  78. // Update the time.
  79. C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
  80. if ( pPlayer )
  81. {
  82. if( pPlayer->HasHelmet() && (int)pPlayer->ArmorValue() > 0 )
  83. {
  84. if( m_pArmor_HelmetIcon )
  85. {
  86. m_pArmor_HelmetIcon->DrawSelf( icon_xpos, icon_ypos, icon_wide, icon_tall, GetFgColor() );
  87. }
  88. }
  89. else
  90. {
  91. if( m_pArmorIcon )
  92. {
  93. m_pArmorIcon->DrawSelf( icon_xpos, icon_ypos, icon_wide, icon_tall, GetFgColor() );
  94. }
  95. }
  96. SetDisplayValue( (int)pPlayer->ArmorValue() );
  97. SetShouldDisplayValue( true );
  98. BaseClass::Paint();
  99. }
  100. }