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.

142 lines
3.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implements visual effects entities: sprites, beams, bubbles, etc.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "engine/IEngineSound.h"
  9. #include "baseentity.h"
  10. #include "entityoutput.h"
  11. #include "recipientfilter.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. #define SF_HUDHINT_ALLPLAYERS 0x0001
  15. //-----------------------------------------------------------------------------
  16. // Purpose:
  17. //-----------------------------------------------------------------------------
  18. class CEnvHudHint : public CPointEntity
  19. {
  20. public:
  21. DECLARE_CLASS( CEnvHudHint, CPointEntity );
  22. void Spawn( void );
  23. void Precache( void );
  24. private:
  25. inline bool AllPlayers( void ) { return (m_spawnflags & SF_HUDHINT_ALLPLAYERS) != 0; }
  26. void InputShowHudHint( inputdata_t &inputdata );
  27. void InputHideHudHint( inputdata_t &inputdata );
  28. string_t m_iszMessage;
  29. DECLARE_DATADESC();
  30. };
  31. LINK_ENTITY_TO_CLASS( env_hudhint, CEnvHudHint );
  32. BEGIN_DATADESC( CEnvHudHint )
  33. DEFINE_KEYFIELD( m_iszMessage, FIELD_STRING, "message" ),
  34. DEFINE_INPUTFUNC( FIELD_VOID, "ShowHudHint", InputShowHudHint ),
  35. DEFINE_INPUTFUNC( FIELD_VOID, "HideHudHint", InputHideHudHint ),
  36. END_DATADESC()
  37. //-----------------------------------------------------------------------------
  38. // Purpose:
  39. //-----------------------------------------------------------------------------
  40. void CEnvHudHint::Spawn( void )
  41. {
  42. Precache();
  43. SetSolid( SOLID_NONE );
  44. SetMoveType( MOVETYPE_NONE );
  45. }
  46. //-----------------------------------------------------------------------------
  47. // Purpose:
  48. //-----------------------------------------------------------------------------
  49. void CEnvHudHint::Precache( void )
  50. {
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Purpose: Input handler for showing the message and/or playing the sound.
  54. //-----------------------------------------------------------------------------
  55. void CEnvHudHint::InputShowHudHint( inputdata_t &inputdata )
  56. {
  57. if ( AllPlayers() )
  58. {
  59. CReliableBroadcastRecipientFilter user;
  60. UserMessageBegin( user, "KeyHintText" );
  61. WRITE_BYTE( 1 ); // one message
  62. WRITE_STRING( STRING(m_iszMessage) );
  63. MessageEnd();
  64. }
  65. else
  66. {
  67. CBaseEntity *pPlayer = NULL;
  68. if ( inputdata.pActivator && inputdata.pActivator->IsPlayer() )
  69. {
  70. pPlayer = inputdata.pActivator;
  71. }
  72. else
  73. {
  74. pPlayer = UTIL_GetLocalPlayer();
  75. }
  76. if ( !pPlayer || !pPlayer->IsNetClient() )
  77. return;
  78. CSingleUserRecipientFilter user( (CBasePlayer *)pPlayer );
  79. user.MakeReliable();
  80. UserMessageBegin( user, "KeyHintText" );
  81. WRITE_BYTE( 1 ); // one message
  82. WRITE_STRING( STRING(m_iszMessage) );
  83. MessageEnd();
  84. }
  85. }
  86. //-----------------------------------------------------------------------------
  87. //-----------------------------------------------------------------------------
  88. void CEnvHudHint::InputHideHudHint( inputdata_t &inputdata )
  89. {
  90. if ( AllPlayers() )
  91. {
  92. CReliableBroadcastRecipientFilter user;
  93. UserMessageBegin( user, "KeyHintText" );
  94. WRITE_BYTE( 1 ); // one message
  95. WRITE_STRING( STRING(NULL_STRING) );
  96. MessageEnd();
  97. }
  98. else
  99. {
  100. CBaseEntity *pPlayer = NULL;
  101. if ( inputdata.pActivator && inputdata.pActivator->IsPlayer() )
  102. {
  103. pPlayer = inputdata.pActivator;
  104. }
  105. else
  106. {
  107. pPlayer = UTIL_GetLocalPlayer();
  108. }
  109. if ( !pPlayer || !pPlayer->IsNetClient() )
  110. return;
  111. CSingleUserRecipientFilter user( (CBasePlayer *)pPlayer );
  112. user.MakeReliable();
  113. UserMessageBegin( user, "KeyHintText" );
  114. WRITE_BYTE( 1 ); // one message
  115. WRITE_STRING( STRING(NULL_STRING) );
  116. MessageEnd();
  117. }
  118. }