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.

113 lines
3.0 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef HINTMESSAGE_H
  7. #define HINTMESSAGE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "utlvector.h"
  12. #include "simtimer.h"
  13. #ifdef GAME_DLL
  14. #include "player.h"
  15. #else
  16. #include "c_baseplayer.h"
  17. #endif
  18. class CHintSystem;
  19. //--------------------------------------------------------------------------------------------------------------
  20. class CHintMessage
  21. {
  22. public:
  23. CHintMessage( const char * hintString, CUtlVector< const char * > * args, float duration );
  24. ~CHintMessage();
  25. float GetDuration() const { return m_duration; }
  26. void Send( CBasePlayer *client );
  27. bool IsEquivalent( const char *hintString, CUtlVector< const char * > * args ) const;
  28. private:
  29. const char * m_hintString; ///< hintString is a pointer to a string that should never be deleted.
  30. CUtlVector< char * > m_args; ///< list of arguments. The memory for these strings is internal to the CHintMessage.
  31. float m_duration; ///< time until the next message can be displayed
  32. };
  33. //--------------------------------------------------------------------------------------------------------------
  34. class CHintMessageQueue
  35. {
  36. public:
  37. CHintMessageQueue( CBasePlayer *pPlayer );
  38. void Reset();
  39. void Update();
  40. bool AddMessage( const char* message, float duration = 6.0f, CUtlVector< const char * > * args = NULL );
  41. inline bool IsEmpty() { return m_messages.Count() == 0; }
  42. private:
  43. float m_tmMessageEnd;
  44. CUtlVector< CHintMessage * > m_messages;
  45. CBasePlayer *m_pPlayer;
  46. };
  47. //--------------------------------------------------------------------------------------------------------------
  48. //--------------------------------------------------------------------------------------------------------------
  49. // Timers that manage hint messages that should be displayed after some time.
  50. class CHintMessageTimers
  51. {
  52. public:
  53. CHintMessageTimers( void );
  54. CHintMessageTimers( CHintSystem *pSystem, CHintMessageQueue *pQueue );
  55. void Reset();
  56. void Update();
  57. // Add / Register timers that will be started/stopped during play
  58. void AddTimer( int iHintID, float timer_duration, float message_duration = 6.0f, CUtlVector< const char * > * args = NULL );
  59. void RemoveTimer( int iHintID );
  60. // Start / Stop timers that were previously registered via AddTimer()
  61. void StartTimer( int iHintID );
  62. void StopTimer( int iHintID );
  63. private:
  64. int GetTimerIndex( int iHintID );
  65. private:
  66. struct hintmessagetime_t
  67. {
  68. hintmessagetime_t( float flTimerDuration ) :
  69. timer(flTimerDuration)
  70. {
  71. iHintID = 0;
  72. flMessageDuration = 6.0;
  73. }
  74. ~hintmessagetime_t()
  75. {
  76. for ( int i=0; i<args.Count(); ++i )
  77. {
  78. delete[] args[i];
  79. }
  80. args.RemoveAll();
  81. }
  82. int iHintID;
  83. CStopwatch timer;
  84. float flMessageDuration;
  85. CUtlVector< char * > args;
  86. };
  87. CUtlVector< hintmessagetime_t* > m_Timers;
  88. CHintMessageQueue *m_pQueue;
  89. CHintSystem *m_pHintSystem;
  90. };
  91. #endif // HINTMESSAGE_H