Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
5.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #if defined( REPLAY_ENABLED )
  8. #include "vgui/IInput.h"
  9. #include "vgui/ISurface.h"
  10. #include "vgui_controls/TextEntry.h"
  11. #include "replaybrowserbasepage.h"
  12. #include "replaybrowserdetailspanel.h"
  13. #include "replaybrowsermainpanel.h"
  14. #include "replaybrowserlistpanel.h"
  15. #include "replay/ireplaymoviemanager.h"
  16. #include "replay/ireplaymanager.h"
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include <tier0/memdbgon.h>
  19. //-----------------------------------------------------------------------------
  20. extern IReplayMovieManager *g_pReplayMovieManager;
  21. //-----------------------------------------------------------------------------
  22. CReplayBrowserBasePage::CReplayBrowserBasePage( Panel *pParent )
  23. : BaseClass( pParent, "BasePage" )
  24. {
  25. m_pReplayList = new CReplayListPanel( this, "ReplayList" );
  26. m_pReplayList->SetFirstColumnWidth( 0 );
  27. m_pSearchTextEntry = new vgui::TextEntry( this, "SearchTextEntry" );
  28. m_pSearchTextEntry->SelectAllOnFocusAlways( true );
  29. m_pSearchTextEntry->AddActionSignalTarget( this );
  30. m_pSearchTextEntry->SetCatchEnterKey( true );
  31. InvalidateLayout( true, true );
  32. m_pReplayList->AddReplaysToList();
  33. ivgui()->AddTickSignal( GetVPanel(), 100 );
  34. }
  35. CReplayBrowserBasePage::~CReplayBrowserBasePage()
  36. {
  37. ivgui()->RemoveTickSignal( GetVPanel() );
  38. }
  39. void CReplayBrowserBasePage::OnTick()
  40. {
  41. if ( !IsVisible() )
  42. return;
  43. int nCursorX, nCursorY;
  44. input()->GetCursorPos( nCursorX, nCursorY );
  45. if ( input()->IsMouseDown( MOUSE_LEFT ) &&
  46. !m_pSearchTextEntry->IsWithin( nCursorX, nCursorY ) &&
  47. m_pSearchTextEntry->HasFocus() )
  48. {
  49. RequestFocus();
  50. }
  51. }
  52. void CReplayBrowserBasePage::ApplySchemeSettings( vgui::IScheme *pScheme )
  53. {
  54. BaseClass::ApplySchemeSettings( pScheme );
  55. LoadControlSettings( "resource/ui/replaybrowser/basepage.res", "GAME" );
  56. m_pSearchTextEntry->SetText( "#Replay_SearchText" );
  57. }
  58. void CReplayBrowserBasePage::OnPageShow()
  59. {
  60. BaseClass::OnPageShow();
  61. m_pSearchTextEntry->SetText( "#Replay_SearchText" );
  62. }
  63. void CReplayBrowserBasePage::OnSelectionStarted()
  64. {
  65. PostActionSignal( new KeyValues("SelectionUpdate", "open", 1 ) );
  66. }
  67. void CReplayBrowserBasePage::OnSelectionEnded()
  68. {
  69. PostActionSignal( new KeyValues("SelectionUpdate", "open", 0 ) );
  70. }
  71. void CReplayBrowserBasePage::CleanupUIForReplayItem( ReplayItemHandle_t hReplayItem )
  72. {
  73. m_pReplayList->CleanupUIForReplayItem( hReplayItem );
  74. }
  75. void CReplayBrowserBasePage::AddReplay( ReplayHandle_t hReplay )
  76. {
  77. m_pReplayList->AddReplayItem( hReplay );
  78. }
  79. void CReplayBrowserBasePage::DeleteReplay( ReplayHandle_t hReplayItem )
  80. {
  81. IReplayItemManager *pItemManager;
  82. if ( FindReplayItem( hReplayItem, &pItemManager ) )
  83. {
  84. ReplayUI_GetBrowserPanel()->AttemptToDeleteReplayItem( this, hReplayItem, pItemManager, -1 );
  85. }
  86. }
  87. void CReplayBrowserBasePage::OnCancelSelection()
  88. {
  89. }
  90. void CReplayBrowserBasePage::GoBack()
  91. {
  92. DeleteDetailsPanelAndShowReplayList();
  93. }
  94. void CReplayBrowserBasePage::OnReplayItemDeleted( KeyValues *pParams )
  95. {
  96. GoBack();
  97. }
  98. void CReplayBrowserBasePage::OnTextChanged( KeyValues *data )
  99. {
  100. wchar_t wszText[256];
  101. m_pSearchTextEntry->GetText( wszText, ARRAYSIZE( wszText ) );
  102. m_pReplayList->ApplyFilter( wszText );
  103. InvalidateLayout();
  104. }
  105. void CReplayBrowserBasePage::OnCommand( const char *pCommand )
  106. {
  107. // User wants details on a replay?
  108. if ( !V_strnicmp( pCommand, "details", 7 ) )
  109. {
  110. // Get rid of preview panel
  111. m_pReplayList->ClearPreviewPanel();
  112. QueryableReplayItemHandle_t hReplayItem = (QueryableReplayItemHandle_t)atoi( pCommand + 7 );
  113. IReplayItemManager *pItemManager;
  114. IQueryableReplayItem *pReplayItem = FindReplayItem( hReplayItem, &pItemManager ); Assert( pReplayItem );
  115. if ( pReplayItem )
  116. {
  117. // Get performance
  118. int iPerformance = -1;
  119. const char *pPerformanceStr = V_strstr( pCommand + 8, "_" );
  120. if ( pPerformanceStr )
  121. {
  122. iPerformance = atoi( pPerformanceStr + 1 );
  123. }
  124. m_hReplayDetailsPanel = vgui::SETUP_PANEL( new CReplayDetailsPanel( this, hReplayItem, iPerformance, pItemManager ) );
  125. m_hReplayDetailsPanel->SetVisible( true );
  126. m_hReplayDetailsPanel->MoveToFront();
  127. m_pReplayList->SetVisible( false );
  128. surface()->PlaySound( "replay\\showdetails.wav" );
  129. }
  130. }
  131. // "back" button was hit in details panel?
  132. else if ( FStrEq( pCommand, "back" ) )
  133. {
  134. GoBack();
  135. }
  136. BaseClass::OnCommand( pCommand );
  137. }
  138. void CReplayBrowserBasePage::DeleteDetailsPanelAndShowReplayList()
  139. {
  140. // Delete the panel
  141. if ( m_hReplayDetailsPanel )
  142. {
  143. m_hReplayDetailsPanel->MarkForDeletion();
  144. m_hReplayDetailsPanel = NULL;
  145. }
  146. m_pReplayList->SetVisible( true );
  147. }
  148. void CReplayBrowserBasePage::PerformLayout()
  149. {
  150. BaseClass::PerformLayout();
  151. if ( m_pSearchTextEntry )
  152. {
  153. const bool bHasReplays = g_pReplayManager && g_pReplayManager->GetReplayCount();
  154. const bool bHasMovies = g_pReplayMovieManager && g_pReplayMovieManager->GetMovieCount();
  155. int aListPos[2];
  156. m_pReplayList->GetPos( aListPos[0], aListPos[1] );
  157. m_pSearchTextEntry->SetPos( aListPos[0] + m_pReplayList->GetWide() - m_pSearchTextEntry->GetWide(), YRES( 5 ) );
  158. m_pSearchTextEntry->SetVisible( bHasReplays || bHasMovies );
  159. }
  160. // Invalidate the list too, because we might be laying out due to a replay being removed from the list.
  161. m_pReplayList->InvalidateLayout();
  162. }
  163. void CReplayBrowserBasePage::FreeDetailsPanelMovieLock()
  164. {
  165. m_hReplayDetailsPanel->FreeMovieFileLock();
  166. }
  167. bool CReplayBrowserBasePage::IsDetailsViewOpen()
  168. {
  169. return m_hReplayDetailsPanel.Get() != NULL && m_hReplayDetailsPanel->IsVisible();
  170. }
  171. #endif