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.

162 lines
4.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #if defined( REPLAY_ENABLED )
  9. #include "replayreminderpanel.h"
  10. #include "replay/ireplaysystem.h"
  11. #include "replay/replay.h"
  12. #include "replay/ireplayscreenshotmanager.h"
  13. #include "replay/ireplaymanager.h"
  14. #include "replay/screenshot.h"
  15. #include "iclientmode.h"
  16. #include "vgui_controls/AnimationController.h"
  17. //-----------------------------------------------------------------------------
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include "tier0/memdbgon.h"
  20. //-----------------------------------------------------------------------------
  21. DECLARE_HUDELEMENT( CReplayReminderPanel );
  22. //-----------------------------------------------------------------------------
  23. CReplayReminderPanel::CReplayReminderPanel( const char *pElementName )
  24. : EditablePanel( g_pClientMode->GetViewport(), "ReplayReminder" ),
  25. CHudElement( pElementName )
  26. {
  27. SetScheme( "ClientScheme" );
  28. m_flShowTime = 0;
  29. m_bShouldDraw = false;
  30. }
  31. //-----------------------------------------------------------------------------
  32. // Purpose:
  33. //-----------------------------------------------------------------------------
  34. void CReplayReminderPanel::SetupText()
  35. {
  36. // Get current key binding, if any.
  37. const char *pBoundKey = engine->Key_LookupBinding( "save_replay" );
  38. if ( !pBoundKey || FStrEq( pBoundKey, "(null)" ) )
  39. {
  40. pBoundKey = " ";
  41. }
  42. char szKey[16];
  43. Q_snprintf( szKey, sizeof(szKey), "%s", pBoundKey );
  44. wchar_t wKey[16];
  45. wchar_t wLabel[256];
  46. g_pVGuiLocalize->ConvertANSIToUnicode( szKey, wKey, sizeof( wKey ) );
  47. g_pVGuiLocalize->ConstructString_safe( wLabel, g_pVGuiLocalize->Find("#Replay_freezecam_replay" ), 1, wKey );
  48. // Set the text
  49. SetDialogVariable( "text", wLabel );
  50. }
  51. //-----------------------------------------------------------------------------
  52. // Purpose:
  53. //-----------------------------------------------------------------------------
  54. void CReplayReminderPanel::ApplySchemeSettings( IScheme *pScheme )
  55. {
  56. LoadControlSettings("Resource/UI/ReplayReminder.res", "GAME");
  57. BaseClass::ApplySchemeSettings( pScheme );
  58. SetupText();
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose:
  62. //-----------------------------------------------------------------------------
  63. void CReplayReminderPanel::Show()
  64. {
  65. m_flShowTime = gpGlobals->curtime;
  66. SetVisible( true );
  67. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( GetParent(), "HudReplayReminderIn" );
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Purpose:
  71. //-----------------------------------------------------------------------------
  72. void CReplayReminderPanel::Hide()
  73. {
  74. SetVisible( false );
  75. m_flShowTime = 0;
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Purpose:
  79. //-----------------------------------------------------------------------------
  80. int CReplayReminderPanel::HudElementKeyInput( int down, ButtonCode_t keynum, const char *pszCurrentBinding )
  81. {
  82. if ( ShouldDraw() && pszCurrentBinding )
  83. {
  84. if ( FStrEq (pszCurrentBinding, "save_replay" ) )
  85. {
  86. SetVisible( false );
  87. }
  88. }
  89. return 0;
  90. }
  91. //-----------------------------------------------------------------------------
  92. // Purpose:
  93. //-----------------------------------------------------------------------------
  94. void CReplayReminderPanel::OnThink()
  95. {
  96. BaseClass::OnThink();
  97. if ( !IsVisible() )
  98. return;
  99. // If we're displaying the element for some specific duration...
  100. if ( m_flShowTime )
  101. {
  102. // Get maximum duration
  103. ConVarRef replay_postwinreminderduration( "replay_postwinreminderduration" );
  104. float flShowLength = replay_postwinreminderduration.IsValid() ? replay_postwinreminderduration.GetFloat() : 5.0f;
  105. if ( gpGlobals->curtime >= m_flShowTime + flShowLength )
  106. {
  107. m_flShowTime = 0;
  108. SetVisible( false );
  109. }
  110. }
  111. }
  112. //-----------------------------------------------------------------------------
  113. // Purpose:
  114. //-----------------------------------------------------------------------------
  115. void CReplayReminderPanel::SetVisible( bool bState )
  116. {
  117. if ( bState )
  118. {
  119. SetupText();
  120. }
  121. // Store this state for ShouldDraw()
  122. m_bShouldDraw = bState;
  123. BaseClass::SetVisible( bState );
  124. }
  125. //-----------------------------------------------------------------------------
  126. // Purpose:
  127. //-----------------------------------------------------------------------------
  128. bool CReplayReminderPanel::ShouldDraw()
  129. {
  130. return m_bShouldDraw;
  131. }
  132. #endif // #if defined( REPLAY_ENABLED )