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.

166 lines
4.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #if defined( REPLAY_ENABLED )
  8. #include "replayconfirmquitdlg.h"
  9. #include "vgui_controls/TextImage.h"
  10. #include "vgui_controls/CheckButton.h"
  11. #include "vgui_controls/TextEntry.h"
  12. #include "vgui/IInput.h"
  13. #include "vgui/ISurface.h"
  14. #include "ienginevgui.h"
  15. #include "replay/genericclassbased_replay.h"
  16. #include "replaybrowserrenderdialog.h"
  17. #include "econ/econ_controls.h"
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include <tier0/memdbgon.h>
  20. using namespace vgui;
  21. //-----------------------------------------------------------------------------
  22. ConVar replay_quitmsg_dontaskagain( "replay_quitmsg_dontaskagain", "0", FCVAR_CLIENTDLL | FCVAR_DONTRECORD | FCVAR_ARCHIVE, "The replay system will ask you to render your replays on quit, unless this cvar is 1.", true, 0, true, 1 );
  23. //-----------------------------------------------------------------------------
  24. CReplayConfirmQuitDialog::CReplayConfirmQuitDialog( Panel *pParent )
  25. : BaseClass( pParent, "confirmquitdlg" ),
  26. m_pDontShowAgain( NULL ),
  27. m_pQuitButton( NULL )
  28. {
  29. SetScheme( "ClientScheme" );
  30. InvalidateLayout( true, true );
  31. }
  32. void CReplayConfirmQuitDialog::ApplySchemeSettings( vgui::IScheme *pScheme )
  33. {
  34. // Link in TF scheme
  35. extern IEngineVGui *enginevgui;
  36. vgui::HScheme pTFScheme = vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/ClientScheme.res", "ClientScheme" );
  37. SetScheme( pTFScheme );
  38. SetProportional( true );
  39. BaseClass::ApplySchemeSettings( vgui::scheme()->GetIScheme( pTFScheme ) );
  40. LoadControlSettings( "Resource/UI/replaybrowser/confirmquitdlg.res", "GAME" );
  41. m_pDontShowAgain = dynamic_cast< CheckButton * >( FindChildByName( "DontShowThisAgainCheckbox" ) );
  42. m_pQuitButton = dynamic_cast< CExButton * >( FindChildByName( "QuitButton" ) );
  43. if ( m_pQuitButton )
  44. {
  45. m_pQuitButton->GetTextImage()->ClearColorChangeStream();
  46. m_pQuitButton->GetTextImage()->AddColorChange( Color(200,80,60,255), 0 );
  47. }
  48. }
  49. void CReplayConfirmQuitDialog::OnCommand( const char *pCommand )
  50. {
  51. // Store the setting of our "never show this again" checkbox if the user picked anything
  52. // except cancel.
  53. if ( !FStrEq( pCommand, "cancel" ) && m_pDontShowAgain && m_pDontShowAgain->IsSelected() )
  54. {
  55. replay_quitmsg_dontaskagain.SetValue( 1 );
  56. }
  57. if ( FStrEq( pCommand, "rendernow_delay" ) )
  58. {
  59. // Delete this
  60. SetVisible( false );
  61. MarkForDeletion();
  62. // Render all unrendered replays now
  63. ReplayUI_ShowRenderDialog( NULL, REPLAY_HANDLE_INVALID, true, -1 );
  64. }
  65. else if ( FStrEq( pCommand, "rendernow" ) )
  66. {
  67. // Sometimes this message comes in just before input is processed when using a controller
  68. // Refire after a delay
  69. PostMessage( this, new KeyValues( "Command", "command", "rendernow_delay" ), 0.001f );
  70. }
  71. else if ( FStrEq( pCommand, "quit" ) )
  72. {
  73. MarkForDeletion();
  74. engine->ClientCmd_Unrestricted( "quit\n" );
  75. }
  76. else if ( FStrEq( pCommand, "cancel" ) )
  77. {
  78. MarkForDeletion();
  79. }
  80. else if ( FStrEq( pCommand, "gotoreplays"))
  81. {
  82. // "Go to replays"
  83. MarkForDeletion();
  84. engine->ClientCmd( "replay_reloadbrowser" );
  85. }
  86. }
  87. void CReplayConfirmQuitDialog::OnKeyCodeTyped( vgui::KeyCode code )
  88. {
  89. if ( code == KEY_ESCAPE )
  90. {
  91. OnCommand( "cancel" );
  92. }
  93. else
  94. {
  95. BaseClass::OnKeyCodeTyped( code );
  96. }
  97. }
  98. void CReplayConfirmQuitDialog::OnKeyCodePressed( vgui::KeyCode code )
  99. {
  100. if ( GetBaseButtonCode( code ) == KEY_XBUTTON_B || GetBaseButtonCode( code ) == STEAMCONTROLLER_B )
  101. {
  102. OnCommand( "cancel" );
  103. }
  104. else if ( GetBaseButtonCode( code ) == KEY_XBUTTON_A || GetBaseButtonCode( code ) == STEAMCONTROLLER_A )
  105. {
  106. OnCommand( "quit" );
  107. }
  108. else if ( GetBaseButtonCode( code ) == KEY_XBUTTON_X || GetBaseButtonCode( code ) == STEAMCONTROLLER_X )
  109. {
  110. if ( m_pDontShowAgain )
  111. {
  112. m_pDontShowAgain->SetSelected( !m_pDontShowAgain->IsSelected() );
  113. }
  114. }
  115. else if ( GetBaseButtonCode( code ) == KEY_XBUTTON_Y || GetBaseButtonCode( code ) == STEAMCONTROLLER_Y )
  116. {
  117. OnCommand( "gotoreplays" );
  118. }
  119. else
  120. {
  121. BaseClass::OnKeyCodePressed( code );
  122. }
  123. }
  124. bool ReplayUI_ShowConfirmQuitDlg()
  125. {
  126. if ( replay_quitmsg_dontaskagain.GetBool() )
  127. return false;
  128. CReplayConfirmQuitDialog *pConfirmQuitDlg = vgui::SETUP_PANEL( new CReplayConfirmQuitDialog( NULL ) );
  129. if ( pConfirmQuitDlg )
  130. {
  131. vgui::surface()->PlaySound( "replay\\replaydialog_warn.wav" );
  132. // Display the panel!
  133. pConfirmQuitDlg->SetVisible( true );
  134. pConfirmQuitDlg->MakePopup();
  135. pConfirmQuitDlg->MoveToFront();
  136. pConfirmQuitDlg->SetKeyBoardInputEnabled( true );
  137. pConfirmQuitDlg->SetMouseInputEnabled( true );
  138. TFModalStack()->PushModal( pConfirmQuitDlg );
  139. }
  140. return true;
  141. }
  142. #endif