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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
//=======================================================================================//
#include "cbase.h"
#if defined( REPLAY_ENABLED )
#include "replaybrowserlistpanel.h"
#include "ienginevgui.h"
#include "vgui/ISurface.h"
#include "vgui/IInput.h"
#include "vgui/IVGui.h"
#include "vgui_controls/ScrollBar.h"
#include "vgui_controls/ScrollBarSlider.h"
#include "replaybrowserlistitempanel.h"
#include "replaybrowserpreviewpanel.h"
#include "replaybrowserbasepage.h"
#include "replay/ireplaymoviemanager.h"
#include "replay/ireplaymanager.h"
#include "replaybrowsermainpanel.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
//-----------------------------------------------------------------------------
extern IClientReplayContext *g_pClientReplayContext;
extern IReplayMovieManager *g_pReplayMovieManager;
extern const char *GetMapDisplayName( const char *mapName );
//-----------------------------------------------------------------------------
DECLARE_BUILD_FACTORY( CReplayListPanel );
//-----------------------------------------------------------------------------
#define MAX_MOVIE_THUMBNAILS 12 // The remaining movies will be put into a single collection
//-----------------------------------------------------------------------------
CReplayListPanel::CReplayListPanel( Panel *pParent, const char *pName )
: BaseClass( pParent, pName ),
m_pPrevHoverPanel( NULL ),
m_pPreviewPanel( NULL )
{
ivgui()->AddTickSignal( GetVPanel(), 10 );
m_pBorderArrowImg = new ImagePanel( this, "ArrowImage" );
// Add replays and movies collections, which will contain all replays & movies.
m_pReplaysCollection = new CReplayThumbnailCollection( this, "ReplayThumbnailCollection", GetReplayItemManager() );
m_pMoviesCollection = new CMovieThumbnailCollection( this, "MovieThumbnailCollection", GetReplayMovieItemManager(), true );
m_vecCollections.AddToTail( m_pReplaysCollection );
m_vecCollections.AddToTail( m_pMoviesCollection );
m_wszFilter[0] = L' ';
m_wszFilter[1] = NULL;
}
CReplayListPanel::~CReplayListPanel()
{
ivgui()->RemoveTickSignal( GetVPanel() );
}
void CReplayListPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
LoadControlSettings( "resource/ui/replaybrowser/replaylistpanel.res", "GAME" );
#if !defined( TF_CLIENT_DLL )
SetPaintBorderEnabled( false );
#endif
MoveScrollBarToTop();
vgui::ScrollBar *pScrollBar = dynamic_cast< vgui::ScrollBar * >( FindChildByName( "PanelListPanelVScroll" ) );
pScrollBar->SetScrollbarButtonsVisible( false );
Color clrButtonColor = GetSchemeColor( "Yellow", Color( 255, 255, 255, 255 ), pScheme );
Color clrBgColor = GetSchemeColor( "TanDark", Color( 255, 255, 255, 255 ), pScheme );
const int nWidth = XRES( 5 );
pScrollBar->SetSize( nWidth, GetTall() );
pScrollBar->GetSlider()->SetSize( nWidth, GetTall() );
}
void CReplayListPanel::PerformLayout()
{
BaseClass::PerformLayout();
}
void CReplayListPanel::OnMouseWheeled(int delta)
{
if ( !GetScrollbar()->IsVisible() )
return;
BaseClass::OnMouseWheeled( delta );
}
void CReplayListPanel::SetupBorderArrow( bool bLeft )
{
m_pBorderArrowImg->SetVisible( true );
m_pBorderArrowImg->SetImage( bLeft ? "replay/replay_balloon_arrow_left" : "replay/replay_balloon_arrow_right" );
m_pBorderArrowImg->SetZPos( 1000 );
m_pBorderArrowImg->GetImage()->GetContentSize( m_aBorderArrowDims[0], m_aBorderArrowDims[1] );
m_pBorderArrowImg->SetSize( m_aBorderArrowDims[0], m_aBorderArrowDims[1] );
}
void CReplayListPanel::ClearPreviewPanel()
{
if ( m_pPreviewPanel )
{
m_pPreviewPanel->MarkForDeletion();
m_pPreviewPanel = NULL;
}
}
void CReplayListPanel::ApplyFilter( const wchar_t *pFilterText )
{
Q_wcsncpy( m_wszFilter, pFilterText, sizeof( m_wszFilter ) );
V_wcslower( m_wszFilter );
m_pReplaysCollection->RemoveAll();
m_pMoviesCollection->RemoveAll();
m_pPrevHoverPanel = NULL;
ClearPreviewPanel();
RemoveAll();
AddReplaysToList();
FOR_EACH_VEC( m_vecCollections, i )
{
m_vecCollections[i]->OnUpdated();
}
InvalidateLayout();
}
void CReplayListPanel::OnTick()
{
if ( !enginevgui->IsGameUIVisible() )
return;
CReplayBrowserPanel *pReplayBrowser = ReplayUI_GetBrowserPanel();
if ( !pReplayBrowser || !pReplayBrowser->IsVisible() )
return;
int x,y;
vgui::input()->GetCursorPos(x, y);
// If the deletion confirmation dialog is up
if ( vgui::input()->GetAppModalSurface() )
{
ClearPreviewPanel();
// Hide the preview arrow
m_pBorderArrowImg->SetVisible( false );
return;
}
CReplayBrowserThumbnail *pOverPanel = FindThumbnailAtCursor( x, y );
if ( m_pPrevHoverPanel != pOverPanel )
{
if ( m_pPrevHoverPanel )
{
OnItemPanelExited( m_pPrevHoverPanel );
}
m_pPrevHoverPanel = pOverPanel;
if ( m_pPrevHoverPanel )
{
OnItemPanelEntered( m_pPrevHoverPanel );
}
}
}
void CReplayListPanel::OnItemPanelEntered( vgui::Panel *pPanel )
{
CReplayBrowserThumbnail *pThumbnail = dynamic_cast< CReplayBrowserThumbnail * >( pPanel );
if ( IsVisible() && pThumbnail && pThumbnail->IsVisible() )
{
ClearPreviewPanel();
// Determine which type of preview panel to display
IReplayItemManager *pItemManager;
IQueryableReplayItem *pReplayItem = FindReplayItem( pThumbnail->m_hReplayItem, &pItemManager );
AssertMsg( pReplayItem, "Why is this happening?" );
if ( !pReplayItem )
return;
if ( pReplayItem->IsItemAMovie() )
{
m_pPreviewPanel = new CReplayPreviewPanelBase( this, pReplayItem->GetItemHandle(), pItemManager );
}
else
{
m_pPreviewPanel = new CReplayPreviewPanelSlideshow( this, pReplayItem->GetItemHandle(), pItemManager );
}
m_pPreviewPanel->InvalidateLayout( true, true );
int x,y;
pThumbnail->GetPosRelativeToAncestor( this, x, y );
int nXPos, nYPos;
int nOffset = XRES( 1 );
nXPos = ( x > GetWide()/2 ) ? ( x - m_pPreviewPanel->GetWide() - nOffset ) : ( x + pThumbnail->GetWide() + nOffset );
nYPos = y + ( pThumbnail->GetTall() - m_pPreviewPanel->GetTall() ) / 2;
// Make sure the popup stays onscreen.
if ( nXPos < 0 )
{
nXPos = 0;
}
else if ( (nXPos + m_pPreviewPanel->GetWide()) > GetWide() )
{
nXPos = GetWide() - m_pPreviewPanel->GetWide();
}
if ( nYPos < 0 )
{
nYPos = 0;
}
else if ( (nYPos + m_pPreviewPanel->GetTall()) > GetTall() )
{
// Move it up as much as we can without it going below the bottom
nYPos = GetTall() - m_pPreviewPanel->GetTall();
}
// Setup the balloon's arrow
bool bLeftArrow = x < (GetWide() / 2);
SetupBorderArrow( bLeftArrow ); // Sets proper image and caches image dims in m_aBorderArrowDims
int nArrowXPos, nArrowYPos;
const int nPreviewBorderWidth = 2; // Should be just big enough to cover the preview's border width
if ( bLeftArrow )
{
// Setup the arrow along the left-hand side
nArrowXPos = nXPos - m_aBorderArrowDims[0] + nPreviewBorderWidth;
}
else
{
nArrowXPos = nXPos + m_pPreviewPanel->GetWide() - nPreviewBorderWidth;
}
nArrowYPos = MIN( nYPos + m_pPreviewPanel->GetTall() - m_pBorderArrowImg->GetTall() * 2, y + ( pThumbnail->m_pScreenshotThumb->GetTall() - m_aBorderArrowDims[1] ) / 2 );
m_pBorderArrowImg->SetPos( nArrowXPos, nArrowYPos );
m_pPreviewPanel->SetPos( nXPos, nYPos );
m_pPreviewPanel->SetVisible( true );
surface()->PlaySound( "replay\\replaypreviewpopup.wav" );
}
}
void CReplayListPanel::OnItemPanelExited( vgui::Panel *pPanel )
{
CReplayBrowserThumbnail *pThumbnail = dynamic_cast < CReplayBrowserThumbnail * > ( pPanel );
if ( pThumbnail && IsVisible() && m_pPreviewPanel )
{
m_pBorderArrowImg->SetVisible( false );
ClearPreviewPanel();
}
}
CBaseThumbnailCollection *CReplayListPanel::FindOrAddReplayThumbnailCollection( const IQueryableReplayItem *pItem, IReplayItemManager *pItemManager )
{
Assert( pItem );
if ( pItem->IsItemAMovie() )
{
return m_pMoviesCollection;
}
return m_pReplaysCollection;
}
void CReplayListPanel::AddReplaysToList()
{
// Cache off list item pointers into a temp list for processing
CUtlLinkedList< IQueryableReplayItem *, int > lstMovies;
CUtlLinkedList< IQueryableReplayItem *, int > lstReplays;
// Add all replays to a replays list
g_pReplayManager->GetReplaysAsQueryableItems( lstReplays );
// Add all movies to a movies list
g_pReplayMovieManager->GetMoviesAsQueryableItems( lstMovies );
// Go through all movies, and add them to the proper collection, based on date
FOR_EACH_LL( lstMovies, i )
{
if ( PassesFilter( lstMovies[ i ] ) )
{
AddReplayItem( lstMovies[ i ]->GetItemHandle() );
}
}
// Add any replays to the "temporary replays" collection
FOR_EACH_LL( lstReplays, i )
{
if ( PassesFilter( lstReplays[ i ] ) )
{
m_pReplaysCollection->AddReplay( lstReplays[ i ] );
}
}
// Add all collection panels to the list panel
FOR_EACH_VEC( m_vecCollections, i )
{
AddItem( NULL, m_vecCollections[ i ] );
}
}
void CReplayListPanel::RemoveCollection( CBaseThumbnailCollection *pCollection )
{
// Never remove our two base collections. If they have no entries, they display messages instead.
if ( pCollection == m_pMoviesCollection || pCollection == m_pReplaysCollection )
return;
// Find the item and remove it
int i = FirstItem();
while ( i != InvalidItemID() )
{
if ( GetItemPanel( i ) == pCollection )
{
int nNextI = NextItem( i );
RemoveItem( i );
i = nNextI;
}
else
{
i = NextItem( i );
}
}
// Remove our own cached ptr
i = m_vecCollections.Find( pCollection );
if ( i != m_vecCollections.InvalidIndex() )
{
m_vecCollections.Remove( i );
}
}
CReplayBrowserThumbnail *CReplayListPanel::FindThumbnailAtCursor( int x, int y )
{
// Is the cursor hovering over any of the thumbnails?
FOR_EACH_VEC( m_vecCollections, i )
{
CBaseThumbnailCollection *pCollection = m_vecCollections[ i ];
if ( pCollection->IsWithin( x, y ) )
{
FOR_EACH_VEC( pCollection->m_vecRows, j )
{
CReplayBrowserThumbnailRow *pRow = pCollection->m_vecRows[ j ];
if ( pRow->IsWithin( x, y ) )
{
FOR_EACH_VEC( pRow->m_vecThumbnails, k )
{
CReplayBrowserThumbnail *pThumbnail = pRow->m_vecThumbnails[ k ];
if ( pThumbnail->IsWithin( x, y ) )
{
return pThumbnail;
}
}
}
}
}
}
return NULL;
}
#if defined( WIN32 )
#define Q_wcstok( text, delimiters, context ) wcstok( text, delimiters ); context;
#elif defined( OSX ) || defined( LINUX )
#define Q_wcstok( text, delimiters, context ) wcstok( text, delimiters, context )
#endif
bool CReplayListPanel::PassesFilter( IQueryableReplayItem *pItem )
{
CGenericClassBasedReplay *pReplay = ToGenericClassBasedReplay( pItem->GetItemReplay() );
if ( !pReplay )
return false;
wchar_t wszSearchableText[1024] = L"";
wchar_t wszTemp[256];
// title
const wchar_t *pTitle = pItem->GetItemTitle();
V_wcscat_safe( wszSearchableText, pTitle );
V_wcscat_safe( wszSearchableText, L" " );
// map
const char *pMapName = GetMapDisplayName( pReplay->m_szMapName );
g_pVGuiLocalize->ConvertANSIToUnicode( pMapName, wszTemp, sizeof( wszTemp ) );
V_wcscat_safe( wszSearchableText, wszTemp );
V_wcscat_safe( wszSearchableText, L" " );
// player class
g_pVGuiLocalize->ConvertANSIToUnicode( pReplay->GetPlayerClass(), wszTemp, sizeof( wszTemp ) );
V_wcscat_safe( wszSearchableText, wszTemp );
V_wcscat_safe( wszSearchableText, L" " );
// killer name
if ( pReplay->WasKilled() )
{
g_pVGuiLocalize->ConvertANSIToUnicode( pReplay->GetKillerName(), wszTemp, sizeof( wszTemp ) );
V_wcscat_safe( wszSearchableText, wszTemp );
V_wcscat_safe( wszSearchableText, L" " );
}
// lower case
V_wcslower( wszSearchableText );
wchar_t wszFilter[256];
Q_wcsncpy( wszFilter, m_wszFilter, sizeof( wszFilter ) );
bool bPasses = true;
wchar_t seps[] = L" ";
wchar_t *last = NULL;
wchar_t *token = Q_wcstok( wszFilter, seps, &last );
while ( token && bPasses )
{
bPasses &= wcsstr( wszSearchableText, token ) != NULL;
token = Q_wcstok( NULL, seps, &last );
}
return bPasses;
}
void CReplayListPanel::AddReplayItem( ReplayItemHandle_t hItem )
{
IReplayItemManager *pItemManager;
const IQueryableReplayItem *pItem = FindReplayItem( hItem, &pItemManager );
if ( !pItem )
return;
// Find or add the collection
CBaseThumbnailCollection *pCollection = FindOrAddReplayThumbnailCollection( pItem, pItemManager );
// Add the replay
pCollection->AddReplay( pItem );
}
void CReplayListPanel::CleanupUIForReplayItem( ReplayItemHandle_t hReplayItem )
{
IReplayItemManager *pItemManager;
const IQueryableReplayItem *pReplayItem = FindReplayItem( hReplayItem, &pItemManager ); AssertValidReadPtr( pReplayItem );
CBaseThumbnailCollection *pCollection = NULL;
FOR_EACH_VEC( m_vecCollections, i )
{
CBaseThumbnailCollection *pCurCollection = m_vecCollections[ i ];
if ( pCurCollection->FindReplayItemThumbnailRow( pReplayItem ) )
{
pCollection = pCurCollection;
break;
}
}
// Find the collection associated with the given replay - NOTE: we pass false here for the "bAddIfNotFound" param
if ( !pCollection )
{
AssertMsg( 0, "REPLAY: Should have found collection while attempting to delete a replay from the browser." );
return;
}
// Clear the previous hover pointer to avoid a potential crash where we've got a stale ptr
m_pPrevHoverPanel = NULL;
// Clear out the preview panel if it exists and is for the given replay necessary
if ( m_pPreviewPanel && m_pPreviewPanel->GetReplayHandle() == pReplayItem->GetItemReplayHandle() )
{
ClearPreviewPanel();
m_pBorderArrowImg->SetVisible( false );
}
pCollection->CleanupUIForReplayItem( hReplayItem );
}
#endif
|