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.

116 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: A class embedded in players to provide hints to that player
  4. //
  5. //=============================================================================
  6. #ifndef HINTSYSTEM_H
  7. #define HINTSYSTEM_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #ifdef CLIENT_DLL
  12. #include "c_baseplayer.h"
  13. #else
  14. #include "player.h"
  15. #endif
  16. #include "bitvec.h"
  17. class CHintMessageQueue;
  18. class CHintMessageTimers;
  19. typedef bool (*HintTimerCallback)( CBasePlayer *pOnPlayer );
  20. //-----------------------------------------------------------------------------
  21. // Purpose: A class embedded in players to provide hints to that player
  22. //-----------------------------------------------------------------------------
  23. class CHintSystem
  24. {
  25. DECLARE_CLASS_NOBASE( CHintSystem );
  26. public:
  27. CHintSystem();
  28. ~CHintSystem();
  29. //-----------------------------------------------------
  30. // Call this from your player constructor
  31. void Init( CBasePlayer *pPlayer, int iMaxHintTypes, const char **pszHintStrings );
  32. //-----------------------------------------------------
  33. // CBasePlayer calls these for you, if you fall back to its
  34. // versions of Spawn(), Event_Killed(), and PreThink().
  35. // Call this when your player respawns
  36. void ResetHints( void );
  37. // Call this when your player dies
  38. void ResetHintTimers( void );
  39. // Call this when in your player PreThink()
  40. void Update( void );
  41. //-----------------------------------------------------
  42. // Hint addition
  43. // Call these to add a hint directly onscreen
  44. bool HintMessage( int hint, bool bForce = false, bool bOnlyIfClear = false );
  45. void HintMessage( const char *pMessage );
  46. // Call this to add a hint timer. It'll be reset for you automatically
  47. // everytime ResetHintTimers() is called.
  48. void RegisterHintTimer( int iHintID, float flTimerDuration, bool bOnlyIfClear = false, HintTimerCallback pfnCallback = NULL );
  49. // Call these to start & stop registered hint timers
  50. void StartHintTimer( int iHintID );
  51. void StopHintTimer( int iHintID );
  52. void RemoveHintTimer( int iHintID );
  53. bool TimerShouldFire( int iHintID );
  54. // Set whether a player should see any hints at all
  55. void SetShowHints( bool bShowHints ) { m_bShowHints = bShowHints; }
  56. void SetHintPlayed( int iHintID );
  57. bool ShouldShowHints( void );
  58. // Returns true if the hint has been played already
  59. bool HasPlayedHint( int iHintID );
  60. void PlayedAHint( void );
  61. void ClearHintHistory( void ) { m_HintHistory.ClearAll(); }
  62. // Not really an optimal solution, but saves us querying the hud element,
  63. // which wouldn't be easy with derived versions in different mods.
  64. bool HintIsCurrentlyVisible( void ) { return (gpGlobals->curtime - m_flLastHintPlayedAt < 11 ); }
  65. private:
  66. void ReAddHintTimerIfNotDisplayed( int iHintID, float flTimerDuration );
  67. private:
  68. CBasePlayer *m_pPlayer;
  69. float m_flLastHintPlayedAt;
  70. bool m_bShowHints;
  71. CVarBitVec m_HintHistory;
  72. const char **m_pszHintMessages;
  73. CHintMessageQueue *m_pHintMessageQueue;
  74. CHintMessageTimers *m_pHintMessageTimers;
  75. struct onresethints_t
  76. {
  77. int iHintID;
  78. float flTimer;
  79. bool bOnlyIfClear;
  80. HintTimerCallback pfnCallback;
  81. };
  82. CUtlVector<onresethints_t> m_RegisteredResetHints;
  83. };
  84. #ifdef CLIENT_DLL
  85. // Derive from this if you have an entity that wants to display a hint
  86. // when the player waves his target ID over it on the client.
  87. abstract_class ITargetIDProvidesHint
  88. {
  89. public:
  90. virtual void DisplayHintTo( C_BasePlayer *pPlayer ) = 0;
  91. };
  92. #endif
  93. #endif // HINTSYSTEM_H