Counter Strike : Global Offensive Source Code
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.3 KiB

  1. //========= Copyright � 1996-2005, 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. #if defined( CSTRIKE15 )
  19. extern bool IsTakingAFreezecamScreenshot( void );
  20. extern ConVar cl_drawhud;
  21. //extern ConVar sfcrosshair;
  22. extern ConVar crosshair;
  23. extern ConVar cl_crosshairstyle;
  24. #endif
  25. //-----------------------------------------------------------------------------
  26. // Purpose:
  27. //-----------------------------------------------------------------------------
  28. class CHudWeapon : public CHudElement, public vgui::Panel
  29. {
  30. DECLARE_CLASS_SIMPLE( CHudWeapon, vgui::Panel );
  31. public:
  32. explicit CHudWeapon( const char *pElementName );
  33. virtual void ApplySchemeSettings( vgui::IScheme *scheme );
  34. virtual void Paint( void );
  35. virtual void PerformLayout();
  36. virtual bool ShouldDraw();
  37. private:
  38. CHudCrosshair *m_pCrosshair;
  39. };
  40. DECLARE_HUDELEMENT( CHudWeapon );
  41. CHudWeapon::CHudWeapon( const char *pElementName ) :
  42. CHudElement( pElementName ), BaseClass( NULL, "HudWeapon" )
  43. {
  44. vgui::Panel *pParent = GetClientMode()->GetViewport();
  45. SetParent( pParent );
  46. m_pCrosshair = NULL;
  47. SetHiddenBits( HIDEHUD_PLAYERDEAD | HIDEHUD_CROSSHAIR );
  48. }
  49. bool CHudWeapon::ShouldDraw()
  50. {
  51. #if defined( CSTRIKE15 )
  52. //0 = default
  53. //1 = default static
  54. //2 = classic standard
  55. //3 = classic dynamic
  56. //4 = classic static
  57. if ( !crosshair.GetBool() || cl_crosshairstyle.GetInt() < 2 || IsTakingAFreezecamScreenshot() || !cl_drawhud.GetBool() )
  58. //if ( !crosshair.GetBool() || sfcrosshair.GetBool() || IsTakingAFreezecamScreenshot() || !cl_drawhud.GetBool() )
  59. {
  60. return false;
  61. }
  62. #endif
  63. return CHudElement::ShouldDraw();
  64. }
  65. //-----------------------------------------------------------------------------
  66. // Purpose:
  67. // Input : *scheme -
  68. //-----------------------------------------------------------------------------
  69. void CHudWeapon::ApplySchemeSettings( IScheme *scheme )
  70. {
  71. BaseClass::ApplySchemeSettings( scheme );
  72. SetPaintBackgroundEnabled( false );
  73. m_pCrosshair = GET_HUDELEMENT( CHudCrosshair );
  74. //Assert( m_pCrosshair );
  75. }
  76. //-----------------------------------------------------------------------------
  77. // Performs layout
  78. //-----------------------------------------------------------------------------
  79. void CHudWeapon::PerformLayout()
  80. {
  81. BaseClass::PerformLayout();
  82. vgui::Panel *pParent = GetParent();
  83. int w, h;
  84. pParent->GetSize( w, h );
  85. SetPos( 0, 0 );
  86. SetSize( w, h );
  87. }
  88. //-----------------------------------------------------------------------------
  89. // Purpose:
  90. //-----------------------------------------------------------------------------
  91. void CHudWeapon::Paint( void )
  92. {
  93. C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
  94. if ( !player )
  95. return;
  96. MDLCACHE_CRITICAL_SECTION();
  97. C_BaseCombatWeapon *pWeapon = player->GetActiveWeapon();
  98. // Draw the targeting zone around the pCrosshair
  99. if ( pWeapon )
  100. {
  101. pWeapon->Redraw();
  102. }
  103. else
  104. {
  105. if ( m_pCrosshair )
  106. {
  107. m_pCrosshair->ResetCrosshair();
  108. }
  109. }
  110. }