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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "pch_serverbrowser.h"
#include <vgui_controls/HTML.h>
#include <vgui_controls/MessageDialog.h>
using namespace vgui;
#define NUM_COMMON_TAGS 20
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
TagMenuButton::TagMenuButton(Panel *parent, const char *panelName, const char *text) : BaseClass(parent,panelName,text)
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void TagMenuButton::OnShowMenu( vgui::Menu *menu )
{
PostActionSignal(new KeyValues("TagMenuButtonOpened"));
BaseClass::OnShowMenu(menu);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CCustomServerInfoURLQuery : public vgui::QueryBox
{
DECLARE_CLASS_SIMPLE( CCustomServerInfoURLQuery, vgui::QueryBox );
public:
CCustomServerInfoURLQuery(const char *title, const char *queryText,vgui::Panel *parent) : BaseClass( title, queryText, parent )
{
SetOKButtonText( "#ServerBrowser_CustomServerURLButton" );
}
};
DECLARE_BUILD_FACTORY( TagInfoLabel );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
TagInfoLabel::TagInfoLabel(Panel *parent, const char *panelName) : BaseClass(parent,panelName, (const char *)NULL, NULL)
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
TagInfoLabel::TagInfoLabel(Panel *parent, const char *panelName, const char *text, const char *pszURL) : BaseClass(parent,panelName,text,pszURL)
{
}
//-----------------------------------------------------------------------------
// Purpose: If we were left clicked on, launch the URL
//-----------------------------------------------------------------------------
void TagInfoLabel::OnMousePressed(MouseCode code)
{
if (code == MOUSE_LEFT)
{
if ( GetURL() )
{
// Pop up the dialog with the url in it
CCustomServerInfoURLQuery *qb = new CCustomServerInfoURLQuery( "#ServerBrowser_CustomServerURLWarning", "#ServerBrowser_CustomServerURLOpen", this );
if (qb != NULL)
{
qb->SetOKCommand( new KeyValues("DoOpenCustomServerInfoURL") );
qb->AddActionSignalTarget(this);
qb->MoveToFront();
qb->DoModal();
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void TagInfoLabel::DoOpenCustomServerInfoURL( void )
{
if ( GetURL() )
{
system()->ShellExecute("open", GetURL() );
}
}
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CCustomGames::CCustomGames(vgui::Panel *parent) :
BaseClass(parent, "CustomGames", eInternetServer )
{
m_pGameList->AddColumnHeader(10, "Tags", "#ServerBrowser_Tags", 200);
m_pGameList->SetSortFunc(10, TagsCompare);
if ( !IsSteamGameServerBrowsingEnabled() )
{
m_pGameList->SetEmptyListText("#ServerBrowser_OfflineMode");
m_pConnect->SetEnabled( false );
m_pRefreshAll->SetEnabled( false );
m_pRefreshQuick->SetEnabled( false );
m_pAddServer->SetEnabled( false );
m_pFilter->SetEnabled( false );
}
m_szTagFilter[0] = 0;
m_pTagFilter = new TextEntry(this, "TagFilter");
m_pTagFilter->SetEnabled( false );
m_pTagFilter->SetMaximumCharCount( MAX_TAG_CHARACTERS );
m_pAddTagList = new TagMenuButton( this, "AddTagList", "#ServerBrowser_AddCommonTags" );
m_pTagListMenu = new Menu( m_pAddTagList, "TagList" );
m_pAddTagList->SetMenu( m_pTagListMenu );
m_pAddTagList->SetOpenDirection( Menu::UP );
m_pAddTagList->SetEnabled( false );
}
//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
CCustomGames::~CCustomGames()
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCustomGames::UpdateDerivedLayouts( void )
{
const char *pPathID = "PLATFORM";
KeyValues *pConditions = NULL;
if ( ServerBrowser().IsWorkshopEnabled() )
{
pConditions = new KeyValues( "conditions" );
if ( pConditions )
{
KeyValues *pNewKey = new KeyValues( "if_workshop_enabled" );
if ( pNewKey )
{
pConditions->AddSubKey( pNewKey );
}
}
}
if ( m_pFilter->IsSelected() )
{
if ( g_pFullFileSystem->FileExists( "servers/CustomGamesPage_Filters.res", "MOD" ) )
{
pPathID = "MOD";
}
LoadControlSettings( "servers/CustomGamesPage_Filters.res", pPathID, NULL, pConditions );
}
else
{
if ( g_pFullFileSystem->FileExists( "servers/CustomGamesPage.res", "MOD" ) )
{
pPathID = "MOD";
}
LoadControlSettings( "servers/CustomGamesPage.res", pPathID, NULL, pConditions );
}
if ( pConditions )
{
pConditions->deleteThis();
}
if ( !GameSupportsReplay() )
{
HideReplayFilter();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCustomGames::OnLoadFilter(KeyValues *filter)
{
BaseClass::OnLoadFilter( filter );
Q_strncpy(m_szTagFilter, filter->GetString("gametype"), sizeof(m_szTagFilter));
if ( m_pTagFilter )
{
m_pTagFilter->SetText(m_szTagFilter);
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CCustomGames::CheckTagFilter( gameserveritem_t &server )
{
bool bRetVal = true;
// Custom games substring matches tags with the server's tags
int count = Q_strlen( m_szTagFilter );
if ( count )
{
CUtlVector<char*> TagList;
V_SplitString( m_szTagFilter, ",", TagList );
for ( int i = 0; i < TagList.Count(); i++ )
{
if ( ( Q_strnistr( server.m_szGameTags, TagList[i], MAX_TAG_CHARACTERS ) > 0 ) == TagsExclude() )
{
bRetVal = false;
break;
}
}
TagList.PurgeAndDeleteElements();
}
return bRetVal;
}
//-----------------------------------------------------------------------------
// Purpose: Checks the workshop filtering setting, taking into account workshop filtering might be disabled
//-----------------------------------------------------------------------------
bool CCustomGames::CheckWorkshopFilter( gameserveritem_t &server )
{
eWorkshopMode workshopMode = WorkshopMode();
const char szWorkshopPrefix[] = "workshop/";
if ( workshopMode == eWorkshop_WorkshopOnly )
{
return V_strncasecmp( server.m_szMap, szWorkshopPrefix, sizeof( szWorkshopPrefix ) - 1 ) == 0;
}
else if ( workshopMode == eWorkshop_SubscribedOnly )
{
return ServerBrowser().IsWorkshopSubscribedMap( server.m_szMap );
}
Assert( workshopMode == eWorkshop_None );
return true;
}
//-----------------------------------------------------------------------------
// Purpose: gets filter settings from controls
//-----------------------------------------------------------------------------
void CCustomGames::OnSaveFilter(KeyValues *filter)
{
BaseClass::OnSaveFilter( filter );
if ( m_pTagFilter )
{
// tags
m_pTagFilter->GetText(m_szTagFilter, sizeof(m_szTagFilter) - 1);
}
if ( m_szTagFilter[0] )
{
Q_strlower(m_szTagFilter);
}
if ( TagsExclude() )
{
m_vecServerFilters.AddToTail( MatchMakingKeyValuePair_t( "gametype", "" ) );
}
else
{
m_vecServerFilters.AddToTail( MatchMakingKeyValuePair_t( "gametype", m_szTagFilter ) );
}
filter->SetString("gametype", m_szTagFilter);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCustomGames::SetRefreshing(bool state)
{
if ( state )
{
m_pAddTagList->SetEnabled( false );
}
BaseClass::SetRefreshing( state );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCustomGames::ServerResponded( int iServer, gameserveritem_t *pServerItem )
{
CBaseGamesPage::ServerResponded( iServer, pServerItem );
// If we've found a server with some tags, enable the add tag button
if ( pServerItem->m_szGameTags[0] )
{
m_pAddTagList->SetEnabled( true );
}
}
struct tagentry_t
{
const char *pszTag;
int iCount;
};
int __cdecl SortTagsInUse( const tagentry_t *pTag1, const tagentry_t *pTag2 )
{
return (pTag1->iCount < pTag2->iCount);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCustomGames::RecalculateCommonTags( void )
{
// Regenerate our tag list
m_pTagListMenu->DeleteAllItems();
// Loop through our servers, and build a list of all the tags
CUtlVector<tagentry_t> aTagsInUse;
int iCount = m_pGameList->GetItemCount();
for ( int i = 0; i < iCount; i++ )
{
int serverID = m_pGameList->GetItemUserData( i );
gameserveritem_t *pServer = GetServer( serverID );
if ( pServer && pServer->m_szGameTags && pServer->m_szGameTags[0] )
{
CUtlVector<char*> TagList;
V_SplitString( pServer->m_szGameTags, ",", TagList );
for ( int iTag = 0; iTag < TagList.Count(); iTag++ )
{
// First make sure it's not already in our list
bool bFound = false;
for ( int iCheck = 0; iCheck < aTagsInUse.Count(); iCheck++ )
{
if ( !Q_strnicmp(TagList[iTag], aTagsInUse[iCheck].pszTag, MAX_TAG_CHARACTERS ) )
{
aTagsInUse[iCheck].iCount++;
bFound = true;
}
}
if ( !bFound )
{
int iIdx = aTagsInUse.AddToTail();
aTagsInUse[iIdx].pszTag = TagList[iTag];
aTagsInUse[iIdx].iCount = 0;
}
}
}
}
aTagsInUse.Sort( SortTagsInUse );
int iTagsToAdd = min( aTagsInUse.Count(), NUM_COMMON_TAGS );
for ( int i = 0; i < iTagsToAdd; i++ )
{
const char *pszTag = aTagsInUse[i].pszTag;
m_pTagListMenu->AddMenuItem( pszTag, new KeyValues("AddTag", "tag", pszTag), this, new KeyValues( "data", "tag", pszTag ) );
}
m_pTagListMenu->SetFixedWidth( m_pAddTagList->GetWide() );
m_pTagListMenu->InvalidateLayout( true, false );
m_pTagListMenu->PositionRelativeToPanel( m_pAddTagList, Menu::UP );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCustomGames::OnTagMenuButtonOpened( void )
{
RecalculateCommonTags();
}
//-----------------------------------------------------------------------------
// Purpose: Sets the text from the message
//-----------------------------------------------------------------------------
void CCustomGames::OnAddTag(KeyValues *params)
{
KeyValues *pkvText = params->FindKey("tag", false);
if (!pkvText)
return;
AddTagToFilterList( pkvText->GetString() );
}
int SortServerTags( char* const *p1, char* const *p2 )
{
return ( Q_strcmp( *p1, *p2 ) > 0 );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCustomGames::AddTagToFilterList( const char *pszTag )
{
char txt[ 128 ];
m_pTagFilter->GetText( txt, sizeof( txt ) );
CUtlVector<char*> TagList;
V_SplitString( txt, ",", TagList );
if ( txt[0] )
{
for ( int i = 0; i < TagList.Count(); i++ )
{
// Already in the tag list?
if ( !Q_stricmp( TagList[i], pszTag ) )
{
TagList.PurgeAndDeleteElements();
return;
}
}
}
char *pszNewTag = new char[64];
Q_strncpy( pszNewTag, pszTag, 64 );
TagList.AddToHead( pszNewTag );
TagList.Sort( SortServerTags );
// Append it
char tmptags[MAX_TAG_CHARACTERS];
tmptags[0] = '\0';
for ( int i = 0; i < TagList.Count(); i++ )
{
if ( i > 0 )
{
Q_strncat( tmptags, ",", MAX_TAG_CHARACTERS );
}
Q_strncat( tmptags, TagList[i], MAX_TAG_CHARACTERS );
}
m_pTagFilter->SetText( tmptags );
TagList.PurgeAndDeleteElements();
// Update & apply filters now that the tag list has changed
UpdateFilterSettings();
ApplyGameFilters();
}
|