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.

143 lines
3.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "hudelement.h"
  8. #include "hud_macros.h"
  9. #include "iclientmode.h"
  10. #include "materialsystem/imaterialsystem.h"
  11. #include "materialsystem/imaterial.h"
  12. #include "materialsystem/imaterialvar.h"
  13. #include "hl1_hud_numbers.h"
  14. #include <vgui_controls/Controls.h>
  15. #include <vgui_controls/Panel.h>
  16. #include <vgui/ISurface.h>
  17. using namespace vgui;
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include "tier0/memdbgon.h"
  20. class CHudTrain: public CHudElement, public CHL1HudNumbers
  21. {
  22. DECLARE_CLASS_SIMPLE( CHudTrain, CHL1HudNumbers );
  23. public:
  24. CHudTrain( const char *pElementName );
  25. void Init( void );
  26. void VidInit( void );
  27. bool ShouldDraw( void );
  28. void MsgFunc_Train(bf_read &msg);
  29. private:
  30. void Paint( void );
  31. void ApplySchemeSettings( vgui::IScheme *scheme );
  32. private:
  33. int m_iPos;
  34. CHudTexture *icon_train;
  35. };
  36. //
  37. //-----------------------------------------------------
  38. //
  39. DECLARE_HUDELEMENT( CHudTrain );
  40. DECLARE_HUD_MESSAGE( CHudTrain, Train )
  41. //-----------------------------------------------------------------------------
  42. // Purpose:
  43. //-----------------------------------------------------------------------------
  44. CHudTrain::CHudTrain( const char *pElementName ) : CHudElement( pElementName ), BaseClass(NULL, "HudTrain")
  45. {
  46. SetHiddenBits( HIDEHUD_MISCSTATUS );
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Purpose:
  50. // Input : *scheme -
  51. //-----------------------------------------------------------------------------
  52. void CHudTrain::ApplySchemeSettings( IScheme *scheme )
  53. {
  54. BaseClass::ApplySchemeSettings( scheme );
  55. SetPaintBackgroundEnabled( false );
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Purpose:
  59. //-----------------------------------------------------------------------------
  60. void CHudTrain::Init(void)
  61. {
  62. HOOK_HUD_MESSAGE( CHudTrain, Train );
  63. m_iPos = 0;
  64. }
  65. void CHudTrain::VidInit(void)
  66. {
  67. BaseClass::VidInit();
  68. m_iPos = 0;
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Purpose:
  72. //-----------------------------------------------------------------------------
  73. bool CHudTrain::ShouldDraw( void )
  74. {
  75. return ( CHudElement::ShouldDraw() && m_iPos );
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Purpose:
  79. //-----------------------------------------------------------------------------
  80. void CHudTrain::Paint()
  81. {
  82. if ( !icon_train )
  83. {
  84. icon_train = gHUD.GetIcon( "train" );
  85. }
  86. if ( !icon_train )
  87. {
  88. return;
  89. }
  90. int r, g, b, a;
  91. int x, y;
  92. Color clrTrain;
  93. (gHUD.m_clrYellowish).GetColor( r, g, b, a );
  94. clrTrain.SetColor( r, g, b, a );
  95. int nHudElemWidth, nHudElemHeight;
  96. GetSize( nHudElemWidth, nHudElemHeight );
  97. // This should show up to the right and part way up the armor number
  98. y = nHudElemHeight - icon_train->Height() - GetNumberFontHeight();
  99. x = nHudElemWidth / 3 + icon_train->Width() / 4;
  100. IMaterial *material = materials->FindMaterial( icon_train->szTextureFile, TEXTURE_GROUP_VGUI );
  101. if ( material )
  102. {
  103. bool found;
  104. IMaterialVar* pFrameVar = material->FindVar( "$frame", &found, false );
  105. if ( found )
  106. {
  107. pFrameVar->SetFloatValue( m_iPos - 1 );
  108. }
  109. }
  110. icon_train->DrawSelf( x, y, clrTrain );
  111. }
  112. //-----------------------------------------------------------------------------
  113. // Purpose:
  114. //-----------------------------------------------------------------------------
  115. void CHudTrain::MsgFunc_Train( bf_read &msg )
  116. {
  117. m_iPos = msg.ReadByte();
  118. }