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.

107 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "hud.h"
  9. #include "hudelement.h"
  10. #include "iclientmode.h"
  11. #include <vgui_controls/Controls.h>
  12. #include <vgui/ISurface.h>
  13. #include <vgui_controls/Panel.h>
  14. #include "hud_crosshair.h"
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include "tier0/memdbgon.h"
  17. using namespace vgui;
  18. //-----------------------------------------------------------------------------
  19. // Purpose:
  20. //-----------------------------------------------------------------------------
  21. class CHudWeapon : public CHudElement, public vgui::Panel
  22. {
  23. DECLARE_CLASS_SIMPLE( CHudWeapon, vgui::Panel );
  24. public:
  25. CHudWeapon( const char *pElementName );
  26. virtual void ApplySchemeSettings( vgui::IScheme *scheme );
  27. virtual void Paint( void );
  28. virtual void PerformLayout();
  29. private:
  30. CHudCrosshair *m_pCrosshair;
  31. };
  32. DECLARE_HUDELEMENT( CHudWeapon );
  33. CHudWeapon::CHudWeapon( const char *pElementName ) :
  34. CHudElement( pElementName ), BaseClass( NULL, "HudWeapon" )
  35. {
  36. vgui::Panel *pParent = g_pClientMode->GetViewport();
  37. SetParent( pParent );
  38. m_pCrosshair = NULL;
  39. SetHiddenBits( HIDEHUD_WEAPONSELECTION );
  40. }
  41. //-----------------------------------------------------------------------------
  42. // Purpose:
  43. // Input : *scheme -
  44. //-----------------------------------------------------------------------------
  45. void CHudWeapon::ApplySchemeSettings( IScheme *scheme )
  46. {
  47. BaseClass::ApplySchemeSettings( scheme );
  48. SetPaintBackgroundEnabled( false );
  49. m_pCrosshair = GET_HUDELEMENT( CHudCrosshair );
  50. //Assert( m_pCrosshair );
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Performs layout
  54. //-----------------------------------------------------------------------------
  55. void CHudWeapon::PerformLayout()
  56. {
  57. BaseClass::PerformLayout();
  58. vgui::Panel *pParent = GetParent();
  59. int w, h;
  60. pParent->GetSize( w, h );
  61. SetPos( 0, 0 );
  62. SetSize( w, h );
  63. }
  64. //-----------------------------------------------------------------------------
  65. // Purpose:
  66. //-----------------------------------------------------------------------------
  67. void CHudWeapon::Paint( void )
  68. {
  69. C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
  70. if ( !player )
  71. return;
  72. MDLCACHE_CRITICAL_SECTION();
  73. C_BaseCombatWeapon *pWeapon = player->GetActiveWeapon();
  74. if ( pWeapon )
  75. {
  76. pWeapon->Redraw();
  77. }
  78. else
  79. {
  80. if ( m_pCrosshair )
  81. {
  82. m_pCrosshair->ResetCrosshair();
  83. }
  84. }
  85. }