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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "c_tf_freeaccount.h"
#include "gcsdk/sharedobjectcache.h"
#include "tf_gcmessages.h"
#include "econ_game_account_client.h"
#include "tf_item_inventory.h"
#include "tf_player_info.h"
#include <vgui/ILocalize.h>
#include "confirm_dialog.h"
#include "econ/econ_notifications.h"
#include "select_player_dialog.h"
#include "gc_clientsystem.h"
//-----------------------------------------------------------------------------
class CSelectMostHelpfulFriendDialog : public CSelectPlayerDialog
{
public:
CSelectMostHelpfulFriendDialog( vgui::Panel *parent )
: CSelectPlayerDialog( parent )
, m_iNumFriends( 0 )
, m_bRefreshing( false )
{
}
virtual void UpdatePlayerList()
{
CSelectPlayerDialog::UpdatePlayerList();
vgui::Label *pLabelEmpty = dynamic_cast<vgui::Label*>( m_pStatePanels[m_iCurrentState]->FindChildByName("EmptyPlayerListLabel") );
vgui::Label *pLabelQuery = dynamic_cast<vgui::Label*>( m_pStatePanels[m_iCurrentState]->FindChildByName("QueryLabel") );
vgui::Label *pLabelRetrieving = dynamic_cast<vgui::Label*>( m_pStatePanels[m_iCurrentState]->FindChildByName("RetrievingPlayerListLabel") );
if ( pLabelEmpty )
{
pLabelEmpty->SetVisible( m_bRefreshing == false && pLabelEmpty->IsVisible() );
}
if ( pLabelQuery )
{
pLabelQuery->SetVisible( m_bRefreshing == false && pLabelQuery->IsVisible() );
}
if ( pLabelRetrieving )
{
pLabelRetrieving->SetVisible( m_bRefreshing );
}
}
virtual void Reset()
{
CSelectPlayerDialog::Reset();
m_iNumFriends = 0;
if ( m_bRefreshing == false )
{
RequestFriendsFromGC();
}
}
virtual void SetupSelectFriends()
{
m_PlayerInfoList.Purge();
if ( steamapicontext && steamapicontext->SteamFriends() )
{
// Get our game info so we can use that to test if our friends are connected to the same game as us
FriendGameInfo_t myGameInfo;
CSteamID mySteamID = steamapicontext->SteamUser()->GetSteamID();
steamapicontext->SteamFriends()->GetFriendGamePlayed( mySteamID, &myGameInfo );
int iFriends = steamapicontext->SteamFriends()->GetFriendCount( k_EFriendFlagImmediate );
if ( m_iNumFriends != iFriends )
{
RequestFriendsFromGC();
}
else
{
m_PlayerInfoList = m_FriendsWhoOwnTF2;
}
}
UpdatePlayerList();
}
virtual void OnSelectPlayer( const CSteamID &steamID )
{
GCSDK::CProtoBufMsg<CMsgTFFreeTrialChooseMostHelpfulFriend> msg( k_EMsgGCFreeTrial_ChooseMostHelpfulFriend );
msg.Body().set_account_id_friend( steamID.GetAccountID() );
GCClientSystem()->BSendMessage( msg );
}
void OnTF2FriendsReceived( GCSDK::CProtoBufMsg<CMsgTFRequestTF2FriendsResponse> &msg )
{
// populate the list of friends who own TF2
m_bRefreshing = false;
m_FriendsWhoOwnTF2.Purge();
for ( int i = 0; i < msg.Body().account_ids_size(); ++i )
{
uint32 unAccountID = msg.Body().account_ids( i );
FOR_EACH_VEC( m_EntireFriendsList, j )
{
partner_info_t &info = m_EntireFriendsList[j];
if ( info.m_steamID.GetAccountID() == unAccountID )
{
int idx = m_FriendsWhoOwnTF2.AddToTail();
partner_info_t &infoCopy = m_FriendsWhoOwnTF2[idx];
infoCopy = info;
break;
}
}
}
// update UI
if ( m_iCurrentState == SPDS_SELECTING_FROM_FRIENDS )
{
m_PlayerInfoList = m_FriendsWhoOwnTF2;
UpdatePlayerList();
}
}
protected:
virtual const char *GetResFile() { return "resource/ui/SelectMostHelpfulFriendDialog.res"; }
void RequestFriendsFromGC()
{
// send a message to the GC requesting that it validate which friends own TF2
m_bRefreshing = true;
m_EntireFriendsList.Purge();
m_FriendsWhoOwnTF2.Purge();
if ( steamapicontext && steamapicontext->SteamFriends() )
{
// Get our game info so we can use that to test if our friends are connected to the same game as us
FriendGameInfo_t myGameInfo;
CSteamID mySteamID = steamapicontext->SteamUser()->GetSteamID();
steamapicontext->SteamFriends()->GetFriendGamePlayed( mySteamID, &myGameInfo );
m_iNumFriends = steamapicontext->SteamFriends()->GetFriendCount( k_EFriendFlagImmediate );
if ( m_iNumFriends > 0 )
{
GCSDK::CProtoBufMsg<CMsgTFRequestTF2Friends> msg( k_EMsgGCRequestTF2Friends );
for ( int i = 0; i < m_iNumFriends; i++ )
{
CSteamID friendSteamID = steamapicontext->SteamFriends()->GetFriendByIndex( i, k_EFriendFlagImmediate );
const char *pszName = steamapicontext->SteamFriends()->GetFriendPersonaName( friendSteamID );
int idx = m_EntireFriendsList.AddToTail();
partner_info_t &info = m_EntireFriendsList[idx];
info.m_steamID = friendSteamID;
info.m_name = pszName;
msg.Body().add_account_ids( friendSteamID.GetAccountID() );
}
GCClientSystem()->BSendMessage( msg );
}
else
{
m_bRefreshing = false;
}
}
}
// data
bool m_bRefreshing;
int m_iNumFriends;
CUtlVector<partner_info_t> m_EntireFriendsList;
CUtlVector<partner_info_t> m_FriendsWhoOwnTF2;
};
static vgui::DHANDLE<CSelectMostHelpfulFriendDialog> g_hSelectMostHelpfulFriendDialog;
/**
* Notification that the player should choose their most helpful friend.
*/
class CSelectHelpfulFriendNotification : public CEconNotification
{
public:
CSelectHelpfulFriendNotification() {}
virtual void Accept()
{
OpenSelectMostHelpfulFriendDialog( NULL );
MarkForDeletion();
}
virtual void Decline()
{
MarkForDeletion();
}
virtual EType NotificationType() { return eType_AcceptDecline; }
void Trigger()
{
OpenSelectMostHelpfulFriendDialog( NULL );
MarkForDeletion();
}
static bool RemoveOtherNotifications( CEconNotification *pNotification )
{
return dynamic_cast< CSelectHelpfulFriendNotification* >( pNotification ) != NULL;
}
};
class CWasThankedBySomeoneNotification : public CEconNotification
{
public:
CWasThankedBySomeoneNotification( const CSteamID& steamID )
{
SetText( "#TF_Trial_Alert_ThankedBySomeone" );
SetLifetime( 30.0f );
{
extern void GetPlayerNameBySteamID( const CSteamID &steamID, OUT_Z_CAP(maxLenInChars) char *pDestBuffer, int maxLenInChars );
wchar_t wszPlayerName[ MAX_PLAYER_NAME_LENGTH ];
char szPlayerName[ MAX_PLAYER_NAME_LENGTH ];
GetPlayerNameBySteamID( steamID, szPlayerName, sizeof( szPlayerName ) );
g_pVGuiLocalize->ConvertANSIToUnicode( szPlayerName, wszPlayerName, sizeof( wszPlayerName ) );
AddStringToken( "thanker", wszPlayerName );
}
}
static bool RemoveOtherNotifications( CEconNotification *pNotification )
{
return dynamic_cast< CWasThankedBySomeoneNotification* >( pNotification ) != NULL;
}
};
#ifdef _DEBUG
CON_COMMAND( cl_free_trial_select_friend, "Bring up dialog to select most helpful friend" )
{
OpenSelectMostHelpfulFriendDialog( NULL );
}
CON_COMMAND( cl_thanks_test, "Tests the thanked ui notification." )
{
if ( steamapicontext == NULL || steamapicontext->SteamUser() == NULL )
return;
CSteamID steamID = steamapicontext->SteamUser()->GetSteamID();
NotificationQueue_Add( new CWasThankedBySomeoneNotification( steamID ) );
}
#endif
class CGCRequestTF2FriendsResponse : public GCSDK::CGCClientJob
{
public:
CGCRequestTF2FriendsResponse( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
GCSDK::CProtoBufMsg<CMsgTFRequestTF2FriendsResponse> msg( pNetPacket );
if ( g_hSelectMostHelpfulFriendDialog.Get() )
{
g_hSelectMostHelpfulFriendDialog->OnTF2FriendsReceived( msg );
}
return true;
}
};
GC_REG_JOB( GCSDK::CGCClient, CGCRequestTF2FriendsResponse, "CGCRequestTF2FriendsResponse", k_EMsgGCRequestTF2FriendsResponse, GCSDK::k_EServerTypeGCClient );
class CGCThankedBySomeone : public GCSDK::CGCClientJob
{
public:
CGCThankedBySomeone( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
GCSDK::CProtoBufMsg<CMsgTFThankedBySomeone> msg( pNetPacket );
NotificationQueue_Add( new CWasThankedBySomeoneNotification( CSteamID( msg.Body().thanker_steam_id() ) ) );
return true;
}
};
GC_REG_JOB( GCSDK::CGCClient, CGCThankedBySomeone, "CGCThankedBySomeone", k_EMsgGCFreeTrial_ThankedBySomeone, GCSDK::k_EServerTypeGCClient );
class CGCThankedSomeone : public GCSDK::CGCClientJob
{
public:
CGCThankedSomeone( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
ShowMessageBox( "#TF_Trial_ThankSuccess_Title", "#TF_Trial_ThankSuccess_Text", "#GameUI_OK" );
return true;
}
};
GC_REG_JOB( GCSDK::CGCClient, CGCThankedSomeone, "CGCThankedSomeone", k_EMsgGCFreeTrial_ThankedSomeone, GCSDK::k_EServerTypeGCClient );
class CGCFreeTrialConvertedToPremium : public GCSDK::CGCClientJob
{
public:
CGCFreeTrialConvertedToPremium( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
{
ShowMessageBox( "#TF_Trial_Converted_Title", "#TF_Trial_Converted_Text", "#GameUI_OK" );
return true;
}
};
GC_REG_JOB( GCSDK::CGCClient, CGCFreeTrialConvertedToPremium, "CGCFreeTrialConvertedToPremium", k_EMsgGCFreeTrial_ConvertedToPremium, GCSDK::k_EServerTypeGCClient );
//-----------------------------------------------------------------------------
// External API
#if _DEBUG
ConVar tf_forcetrialaccount( "tf_forcetrialaccount", "0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE );
#endif
#ifdef STAGING_ONLY
ConVar tf_thank_a_friend_enabled( "tf_thank_a_friend_enabled", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE );
#endif // STAGING_ONLY
bool IsFreeTrialAccount()
{
#if _DEBUG
if ( tf_forcetrialaccount.GetBool() )
return true;
#endif
if ( InventoryManager() && TFInventoryManager()->GetLocalTFInventory() && TFInventoryManager()->GetLocalTFInventory()->GetSOC() )
{
CEconGameAccountClient *pGameAccountClient = TFInventoryManager()->GetLocalTFInventory()->GetSOC()->GetSingleton<CEconGameAccountClient>();
if ( pGameAccountClient )
return pGameAccountClient->Obj().trial_account();
}
return false;
}
bool NeedsToChooseMostHelpfulFriend()
{
#ifdef STAGING_ONLY
if ( tf_thank_a_friend_enabled.GetBool() )
#endif // STAGING_ONLY
{
if ( InventoryManager() && TFInventoryManager()->GetLocalTFInventory() && TFInventoryManager()->GetLocalTFInventory()->GetSOC() )
{
CEconGameAccountClient *pGameAccountClient = TFInventoryManager()->GetLocalTFInventory()->GetSOC()->GetSingleton<CEconGameAccountClient>();
if ( pGameAccountClient )
{
return !pGameAccountClient->Obj().trial_account()
&& pGameAccountClient->Obj().need_to_choose_most_helpful_friend();
}
}
}
return false;
}
void NotifyNeedsToChooseMostHelpfulFriend()
{
// remove duplicates
NotificationQueue_Remove( &CSelectHelpfulFriendNotification::RemoveOtherNotifications );
// add new notification
CSelectHelpfulFriendNotification *pNotification = new CSelectHelpfulFriendNotification();
pNotification->SetText( "#TF_Trial_Alert_SelectFriend" );
pNotification->SetLifetime( 120.0f );
NotificationQueue_Add( pNotification );
}
CSelectPlayerDialog *OpenSelectMostHelpfulFriendDialog( vgui::Panel *pParent )
{
if (!g_hSelectMostHelpfulFriendDialog.Get())
{
g_hSelectMostHelpfulFriendDialog = vgui::SETUP_PANEL( new CSelectMostHelpfulFriendDialog( pParent ) );
}
g_hSelectMostHelpfulFriendDialog->InvalidateLayout( false, true );
g_hSelectMostHelpfulFriendDialog->Reset();
g_hSelectMostHelpfulFriendDialog->SetVisible( true );
g_hSelectMostHelpfulFriendDialog->MakePopup();
g_hSelectMostHelpfulFriendDialog->MoveToFront();
g_hSelectMostHelpfulFriendDialog->SetKeyBoardInputEnabled(true);
g_hSelectMostHelpfulFriendDialog->SetMouseInputEnabled(true);
TFModalStack()->PushModal( g_hSelectMostHelpfulFriendDialog );
return g_hSelectMostHelpfulFriendDialog;
}
|