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.

63 lines
1.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: CTrainingAnnotation Entity. This entity is used to place
  4. // annotations on maps.
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "entity_training_annotations.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. //-----------------------------------------------------------------------------
  11. // Purpose: Show an anotation in 3D space in the hud to point out things of
  12. // interest to the player.
  13. //-----------------------------------------------------------------------------
  14. BEGIN_DATADESC( CTrainingAnnotation )
  15. DEFINE_KEYFIELD( m_displayText, FIELD_STRING, "display_text" ),
  16. DEFINE_KEYFIELD( m_flLifetime, FIELD_FLOAT, "lifetime" ),
  17. DEFINE_KEYFIELD( m_flVerticalOffset, FIELD_FLOAT, "offset" ),
  18. DEFINE_INPUTFUNC( FIELD_VOID, "Show", InputShow ),
  19. DEFINE_INPUTFUNC( FIELD_VOID, "Hide", InputHide ),
  20. END_DATADESC()
  21. LINK_ENTITY_TO_CLASS( training_annotation, CTrainingAnnotation );
  22. CTrainingAnnotation::CTrainingAnnotation()
  23. : m_flLifetime(1.0f),
  24. m_flVerticalOffset(0.0f)
  25. {
  26. }
  27. void CTrainingAnnotation::Show()
  28. {
  29. IGameEvent *pEvent = gameeventmanager->CreateEvent( "show_annotation" );
  30. if ( pEvent )
  31. {
  32. Vector location = GetAbsOrigin();
  33. pEvent->SetString( "text", STRING( m_displayText ) );
  34. pEvent->SetInt( "id", (long)this );
  35. pEvent->SetFloat( "worldPosX", location.x );
  36. pEvent->SetFloat( "worldPosY", location.y );
  37. pEvent->SetFloat( "worldPosZ", location.z + m_flVerticalOffset );
  38. pEvent->SetFloat( "lifetime", m_flLifetime );
  39. pEvent->SetInt( "follow_entindex", 0 );
  40. gameeventmanager->FireEvent( pEvent );
  41. }
  42. }
  43. void CTrainingAnnotation::Hide()
  44. {
  45. IGameEvent *pEvent = gameeventmanager->CreateEvent( "hide_annotation" );
  46. if ( pEvent )
  47. {
  48. pEvent->SetInt( "id", (long)this );
  49. gameeventmanager->FireEventClientSide( pEvent );
  50. }
  51. }