summaryrefslogtreecommitdiff
path: root/game/client/econ/econ_notifications.h
blob: bf1f4608f6f21d5445b469a44de2f41868ce4463 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================

#ifndef ECON_NOTIFICATIONS_H
#define ECON_NOTIFICATIONS_H
#ifdef _WIN32
#pragma once
#endif

// forward declarations
class KeyValues;
namespace vgui
{
	class EditablePanel;
};
class CEconNotificationQueue;

/**
 * Base class for notifications, but is generic enough to use
 */
class CEconNotification
{
public:
	CEconNotification();
	virtual ~CEconNotification();

	void SetText( const char *pText );
	void AddStringToken( const char* pToken, const wchar_t* pValue );

	void SetKeyValues( KeyValues *pKeyValues );
	KeyValues *GetKeyValues() const;

	const char* GetUnlocalizedText() { return m_pText; }
	const wchar_t *GetText();
	int GetID() const;

	virtual void SetLifetime( float flSeconds );
	virtual float GetExpireTime() const;

	virtual float GetInGameLifeTime() const;
	
	void SetIsInUse( bool bInUse );
	bool GetIsInUse() const;

	void SetSteamID( const CSteamID &steamID );
	const CSteamID &GetSteamID() const;

	virtual bool BShowInGameElements() const { return true; }

	virtual void MarkForDeletion();

	enum EType {
		// Can only be deleted
		eType_Basic,
		// Can be accept or declined
		eType_AcceptDecline,
		// Can be triggered or deleted
		eType_Trigger,
		// Can only be triggered
		eType_MustTrigger,
	};

	virtual EType NotificationType();

	// Is this an important/high priority notification.  Triggers higher visibility etc..
	virtual bool BHighPriority();

	// eType_Trigger or eType_MustTrigger
	virtual void Trigger();

	// eType_AcceptDecline
	virtual void Accept();
	virtual void Decline();

	// eType_Basic or eType_Trigger
	virtual void Deleted();

	// All types, if expire time is set
	virtual void Expired();



	virtual void UpdateTick() { }

	virtual const char *GetUnlocalizedHelpText();

	virtual vgui::EditablePanel *CreateUIElement( bool bMainMenu ) const;

	void SetSoundFilename( const char *filename )
	{
		m_pSoundFilename = filename;
	}

	const char *GetSoundFilename() const
	{
		if ( m_pSoundFilename )
		{
			return m_pSoundFilename;
		}

		return "ui/notification_alert.wav";
	}

protected:
	const char *m_pText;
	const char *m_pSoundFilename;
	float m_flExpireTime;
	KeyValues *m_pKeyValues;
	wchar_t m_wszBuffer[1024];
	CSteamID m_steamID;

private:
	friend class CEconNotificationQueue;
	int m_iID;
	bool m_bInUse;
};



/**
 * Filter function for CEconNotification's, used to remove them
 * @return true if the notification matches, false otherwise
 */
typedef bool (*NotificationFilterFunc)( CEconNotification *pNotification );

/**
 * Visitor object for notifications.
 */
class CEconNotificationVisitor
{
public:
	virtual void Visit( CEconNotification &notification ) = 0;
};

/**
 * Adds the notification to the notification queue
 * @param pNotification
 * @return id to retrieve the notification later if necessary
 */
int NotificationQueue_Add( CEconNotification *pNotification );

/**
 * Retrieves a notification by ID
 * @param iID id of the notification
 * @return the CEconNotification, NULL if not found
 */
CEconNotification *NotificationQueue_Get( int iID );

/**
 * Retrieves a notification by index
 * @param idx Index of the notification relative to GetNumNotifications
 * @return the CEconNotification, NULL if not found
 */
CEconNotification *NotificationQueue_GetByIndex( int idx );

/**
 * Removes all notifications from the queue and deletes them
 * @param iID
 */
void NotificationQueue_RemoveAll();

/**
 * Removes the notification from the queue and deletes it
 * @param iID
 */
void NotificationQueue_Remove( int iID );

/**
 * Removes the notification from the queue and deletes it
 * @param pNotification
 */
void NotificationQueue_Remove( CEconNotification *pNotification );

/**
 * Removes notifications that pass the specified filter
 * @param func
 */
void NotificationQueue_Remove( NotificationFilterFunc func );

/**
 * Count up how many notifications of the given kind are already in the queue
 * @param func
 */
int NotificationQueue_Count( NotificationFilterFunc func );

/**
 * The visitor object will "visit" each notification and perform any work necessary.
 * @param visitor object
 */
void NotificationQueue_Visit( CEconNotificationVisitor &visitor );

/**
 * Update the notification queue
 */
void NotificationQueue_Update();

/**
 * @return the number of notifications
 */
int NotificationQueue_GetNumNotifications();

/**
 * Create the main menu ui element
 * @param pParent
 * @param pElementName
 * @return the control that was created
 */
vgui::EditablePanel* NotificationQueue_CreateMainMenuUIElement( vgui::EditablePanel *pParent, const char *pElementName );

#endif // endif