summaryrefslogtreecommitdiff
path: root/game/client/tf/c_tf_notification.cpp
blob: 7c84ffc30b3a1d34f2b4a470c998db21b9a23154 (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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//

#include "cbase.h"

#include "tf_notification.h"
#include "c_tf_notification.h"
#include "tf_gc_client.h"
#include "econ/econ_notifications.h"

///
/// Support message notification dialog
///

class CTFSupportNotificationDialog : public CTFMessageBoxDialog
{
	DECLARE_CLASS_SIMPLE( CTFSupportNotificationDialog, CTFMessageBoxDialog );
public:
	CTFSupportNotificationDialog( int iNotificationID, const char *pszSupportMessage )
		: CTFMessageBoxDialog( NULL, pszSupportMessage, NULL, NULL, NULL )
		, m_iNotificationID( iNotificationID )
		, m_pConfirmDialog( NULL )
	{
		SetDialogVariable( "text", GetText() );
	}

	void CleanupConfirmDialog()
	{
		if ( m_pConfirmDialog )
		{
			m_pConfirmDialog->SetVisible( false );
			m_pConfirmDialog->MarkForDeletion();
			m_pConfirmDialog = NULL;
		}
	}

	virtual ~CTFSupportNotificationDialog() {
		CleanupConfirmDialog();
	}

	void ConfirmDialogCallback( bool bConfirmed )
	{
		CleanupConfirmDialog();

		if ( bConfirmed )
		{
			// User acknowledged the message, tell the notification it can go away now
			CClientNotification *pNotification = dynamic_cast< CClientNotification * >( NotificationQueue_Get( m_iNotificationID ) );
			if ( pNotification )
			{
				pNotification->OnDialogAcknowledged();
			}

			BaseClass::OnCommand( "confirm" );
		}
	}

	static void StaticConfirmDialogCallback( bool bConfirmed, void *pContext )
	{
		static_cast< CTFSupportNotificationDialog * >( pContext )->ConfirmDialogCallback( bConfirmed );
	}

	virtual void OnCommand( const char *command ) OVERRIDE
	{
		if ( FStrEq( "acknowledge", command ) )
		{
			// Confirm this, it's going away forever!
			CleanupConfirmDialog();
			m_pConfirmDialog = ShowConfirmDialog( "#DeleteConfirmDefault",
			                                      "#TF_Support_Message_Confirm_Acknowledge_Text",
			                                      "#TF_Support_Message_Acknowledge", "#Cancel",
			                                      &StaticConfirmDialogCallback );
			m_pConfirmDialog->SetContext( this );
			return;
		}
		else if ( FStrEq( "show_later", command ) )
		{
			// User selected "show this later" -- leave notification as is and close.
			CleanupConfirmDialog();
			BaseClass::OnCommand( "confirm" );
			return;
		}

		BaseClass::OnCommand( command );
	}

	virtual const char *GetResFile() OVERRIDE
	{
		return "Resource/UI/SupportNotificationDialog.res";
	}

private:
	// Associated notification to clear
	int m_iNotificationID;
	CTFGenericConfirmDialog *m_pConfirmDialog;
};

///
/// The notification class
///

CClientNotification::CClientNotification()
{
	m_pText = NULL;
	m_flExpireTime = CRTime::RTime32TimeCur();
	m_ulNotificationID = 0;
	m_unAccountID = 0;
	m_bSupportMessage = false;
}

CClientNotification::~CClientNotification()
{}

void CClientNotification::Update( const CTFNotification* notification )
{
	// Custom type handling. For now only support message does anything special.
	m_bSupportMessage = false;
	switch ( notification->Obj().type() )
	{
		case CMsgGCNotification_NotificationType_NOTIFICATION_REPORTED_PLAYER_BANNED:
		case CMsgGCNotification_NotificationType_NOTIFICATION_CUSTOM_STRING:
		case CMsgGCNotification_NotificationType_NOTIFICATION_MM_BAN_DUE_TO_EXCESSIVE_REPORTS:
		case CMsgGCNotification_NotificationType_NOTIFICATION_REPORTED_PLAYER_WAS_BANNED:
			// All identical.
			//
			// Really, the other types could be used to avoid having to send a localization string down? Otherwise
			// they're all just redundant with CUSTOM_STRING for now.
			break;
		case CMsgGCNotification_NotificationType_NOTIFICATION_SUPPORT_MESSAGE:
			m_bSupportMessage = true;
			break;
		default:
			Assert( !"Unhandled enum value" );
	}

	m_pText = NULL;
	m_strText = notification->Obj().notification_string().c_str();

	if ( m_bSupportMessage )
	{
		// Use generic notification, save actual notification contents for dialog
		m_pText = "#TF_Support_Message_Notification";
	}
	else
	{
		// Just use our message
		m_pText = m_strText.Get();
	}

	// 0 -> does not expire
	RTime32 rtExpire = notification->Obj().expiration_time();
	m_flExpireTime = rtExpire > 0 ? (float)rtExpire : FLT_MAX;
	m_ulNotificationID = notification->Obj().notification_id();
	m_unAccountID = notification->Obj().account_id();

}

void CClientNotification::GCAcknowledge() {

	GTFGCClientSystem()->AcknowledgeNotification( m_unAccountID, m_ulNotificationID );
}

void CClientNotification::Deleted()
{
	if ( m_bSupportMessage )
	{
		AssertMsg( !m_bSupportMessage,
		           "Support messages should only be able to be triggered, not deleted" );
		return;
	}

	GCAcknowledge();
}

void CClientNotification::Expired()
{
	// No action, we don't want de-sync'd client clock to acknowledge these incorrectly, GC will expire them on its end.
}

CClientNotification::EType CClientNotification::NotificationType()
{
	// Support messages are "must trigger" type -- no delete action, user must click "view"
	if ( m_bSupportMessage )
	{
		return eType_MustTrigger;
	}

	return eType_Basic;
}

bool CClientNotification::BHighPriority()
{
	return m_bSupportMessage;
}

void CClientNotification::Trigger()
{
	if ( !m_bSupportMessage )
	{
		AssertMsg( m_bSupportMessage,
		           "Don't expect to be trigger-able when not in support message mode" );
		return;
	}

	CTFSupportNotificationDialog *pDialog = vgui::SETUP_PANEL( new CTFSupportNotificationDialog( GetID(), m_strText.Get() ) );
	pDialog->Show();
}

void CClientNotification::OnDialogAcknowledged()
{
	if ( !m_bSupportMessage )
	{
		AssertMsg( m_bSupportMessage,
		           "Don't expect to be getting callbacks from the support message dialog when not in support message mode" );
		return;
	}

	GCAcknowledge();
	MarkForDeletion();
}


//-----------------------------------------------------------------------------
// CAutobalanceVolunteerNotification 
//-----------------------------------------------------------------------------
void CAutobalanceVolunteerNotification::SendResponse( bool bResponse )
{
	KeyValues *kv = new KeyValues( "AutoBalanceVolunteerReply" );
	kv->SetBool( "response", bResponse );
	engine->ServerCmdKeyValues( kv );

	MarkForDeletion();
}