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.

214 lines
4.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #ifndef ECON_NOTIFICATIONS_H
  8. #define ECON_NOTIFICATIONS_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. // forward declarations
  13. class KeyValues;
  14. namespace vgui
  15. {
  16. class EditablePanel;
  17. };
  18. class CEconNotificationQueue;
  19. /**
  20. * Base class for notifications, but is generic enough to use
  21. */
  22. class CEconNotification
  23. {
  24. public:
  25. CEconNotification();
  26. virtual ~CEconNotification();
  27. void SetText( const char *pText );
  28. void AddStringToken( const char* pToken, const wchar_t* pValue );
  29. void SetKeyValues( KeyValues *pKeyValues );
  30. KeyValues *GetKeyValues() const;
  31. const char* GetUnlocalizedText() { return m_pText; }
  32. const wchar_t *GetText();
  33. int GetID() const;
  34. virtual void SetLifetime( float flSeconds );
  35. virtual float GetExpireTime() const;
  36. virtual float GetInGameLifeTime() const;
  37. void SetIsInUse( bool bInUse );
  38. bool GetIsInUse() const;
  39. void SetSteamID( const CSteamID &steamID );
  40. const CSteamID &GetSteamID() const;
  41. virtual bool BShowInGameElements() const { return true; }
  42. virtual void MarkForDeletion();
  43. enum EType {
  44. // Can only be deleted
  45. eType_Basic,
  46. // Can be accept or declined
  47. eType_AcceptDecline,
  48. // Can be triggered or deleted
  49. eType_Trigger,
  50. // Can only be triggered
  51. eType_MustTrigger,
  52. };
  53. virtual EType NotificationType();
  54. // Is this an important/high priority notification. Triggers higher visibility etc..
  55. virtual bool BHighPriority();
  56. // eType_Trigger or eType_MustTrigger
  57. virtual void Trigger();
  58. // eType_AcceptDecline
  59. virtual void Accept();
  60. virtual void Decline();
  61. // eType_Basic or eType_Trigger
  62. virtual void Deleted();
  63. // All types, if expire time is set
  64. virtual void Expired();
  65. virtual void UpdateTick() { }
  66. virtual const char *GetUnlocalizedHelpText();
  67. virtual vgui::EditablePanel *CreateUIElement( bool bMainMenu ) const;
  68. void SetSoundFilename( const char *filename )
  69. {
  70. m_pSoundFilename = filename;
  71. }
  72. const char *GetSoundFilename() const
  73. {
  74. if ( m_pSoundFilename )
  75. {
  76. return m_pSoundFilename;
  77. }
  78. return "ui/notification_alert.wav";
  79. }
  80. protected:
  81. const char *m_pText;
  82. const char *m_pSoundFilename;
  83. float m_flExpireTime;
  84. KeyValues *m_pKeyValues;
  85. wchar_t m_wszBuffer[1024];
  86. CSteamID m_steamID;
  87. private:
  88. friend class CEconNotificationQueue;
  89. int m_iID;
  90. bool m_bInUse;
  91. };
  92. /**
  93. * Filter function for CEconNotification's, used to remove them
  94. * @return true if the notification matches, false otherwise
  95. */
  96. typedef bool (*NotificationFilterFunc)( CEconNotification *pNotification );
  97. /**
  98. * Visitor object for notifications.
  99. */
  100. class CEconNotificationVisitor
  101. {
  102. public:
  103. virtual void Visit( CEconNotification &notification ) = 0;
  104. };
  105. /**
  106. * Adds the notification to the notification queue
  107. * @param pNotification
  108. * @return id to retrieve the notification later if necessary
  109. */
  110. int NotificationQueue_Add( CEconNotification *pNotification );
  111. /**
  112. * Retrieves a notification by ID
  113. * @param iID id of the notification
  114. * @return the CEconNotification, NULL if not found
  115. */
  116. CEconNotification *NotificationQueue_Get( int iID );
  117. /**
  118. * Retrieves a notification by index
  119. * @param idx Index of the notification relative to GetNumNotifications
  120. * @return the CEconNotification, NULL if not found
  121. */
  122. CEconNotification *NotificationQueue_GetByIndex( int idx );
  123. /**
  124. * Removes all notifications from the queue and deletes them
  125. * @param iID
  126. */
  127. void NotificationQueue_RemoveAll();
  128. /**
  129. * Removes the notification from the queue and deletes it
  130. * @param iID
  131. */
  132. void NotificationQueue_Remove( int iID );
  133. /**
  134. * Removes the notification from the queue and deletes it
  135. * @param pNotification
  136. */
  137. void NotificationQueue_Remove( CEconNotification *pNotification );
  138. /**
  139. * Removes notifications that pass the specified filter
  140. * @param func
  141. */
  142. void NotificationQueue_Remove( NotificationFilterFunc func );
  143. /**
  144. * Count up how many notifications of the given kind are already in the queue
  145. * @param func
  146. */
  147. int NotificationQueue_Count( NotificationFilterFunc func );
  148. /**
  149. * The visitor object will "visit" each notification and perform any work necessary.
  150. * @param visitor object
  151. */
  152. void NotificationQueue_Visit( CEconNotificationVisitor &visitor );
  153. /**
  154. * Update the notification queue
  155. */
  156. void NotificationQueue_Update();
  157. /**
  158. * @return the number of notifications
  159. */
  160. int NotificationQueue_GetNumNotifications();
  161. /**
  162. * Create the main menu ui element
  163. * @param pParent
  164. * @param pElementName
  165. * @return the control that was created
  166. */
  167. vgui::EditablePanel* NotificationQueue_CreateMainMenuUIElement( vgui::EditablePanel *pParent, const char *pElementName );
  168. #endif // endif