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.

89 lines
2.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 "hud_vehicle.h"
  10. #include "iclientmode.h"
  11. #include "view.h"
  12. #include <vgui_controls/Controls.h>
  13. #include <vgui/ISurface.h>
  14. #include "iclientvehicle.h"
  15. #include "c_prop_vehicle.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. using namespace vgui;
  19. DECLARE_HUDELEMENT( CHudVehicle );
  20. CHudVehicle::CHudVehicle( const char *pElementName ) :
  21. CHudElement( pElementName ), BaseClass( NULL, "HudVehicle" )
  22. {
  23. vgui::Panel *pParent = GetClientMode()->GetViewport();
  24. SetParent( pParent );
  25. SetHiddenBits( HIDEHUD_PLAYERDEAD | HIDEHUD_VEHICLE_CROSSHAIR );
  26. }
  27. void CHudVehicle::ApplySchemeSettings( IScheme *scheme )
  28. {
  29. BaseClass::ApplySchemeSettings( scheme );
  30. SetPaintBackgroundEnabled( false );
  31. }
  32. //-----------------------------------------------------------------------------
  33. // Purpose:
  34. // Output : IClientVehicle
  35. //-----------------------------------------------------------------------------
  36. IClientVehicle *CHudVehicle::GetLocalPlayerVehicle()
  37. {
  38. C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
  39. if ( !pPlayer || !pPlayer->IsInAVehicle() )
  40. {
  41. return NULL;
  42. }
  43. return pPlayer->GetVehicle();
  44. }
  45. //-----------------------------------------------------------------------------
  46. // Purpose:
  47. // Output : Returns true on success, false on failure.
  48. //-----------------------------------------------------------------------------
  49. bool CHudVehicle::ShouldDraw()
  50. {
  51. // Don't draw if we're getting into/out of the vehicle
  52. IClientVehicle *pVehicle = GetLocalPlayerVehicle();
  53. if ( pVehicle )
  54. {
  55. C_PropVehicleDriveable *pDrivable = dynamic_cast<C_PropVehicleDriveable*>(pVehicle);
  56. if ( ( pDrivable ) && ( pDrivable->IsRunningEnterExitAnim() ) )
  57. return false;
  58. return CHudElement::ShouldDraw();
  59. }
  60. return false;
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Purpose:
  64. //-----------------------------------------------------------------------------
  65. void CHudVehicle::Paint( void )
  66. {
  67. IClientVehicle *v = GetLocalPlayerVehicle();
  68. if ( !v )
  69. return;
  70. // Vehicle-based hud...
  71. v->DrawHudElements();
  72. }