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.

98 lines
3.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "tf_matchmaking_dashboard.h"
  8. #include "tf_gc_client.h"
  9. #include "tf_gamerules.h"
  10. using namespace vgui;
  11. using namespace GCSDK;
  12. #ifdef STAGING_ONLY
  13. extern ConVar tf_mm_popup_state_override;
  14. #endif
  15. class CNewMatchFoundDashboardState : public CTFMatchmakingPopup
  16. {
  17. public:
  18. CNewMatchFoundDashboardState( const char* pszName, const char* pszResFile )
  19. : CTFMatchmakingPopup( pszName, pszResFile )
  20. , m_flAutoJoinTime( 0.f )
  21. {}
  22. virtual void OnEnter() OVERRIDE
  23. {
  24. CTFMatchmakingPopup::OnEnter();
  25. // We want to coincide the auto-join time with a short pause after the match-summary sequence if we're in
  26. // a match.
  27. if ( GTFGCClientSystem()->BConnectedToMatchServer( false ) )
  28. {
  29. Assert( TFGameRules()->State_Get() == GR_STATE_GAME_OVER || TFGameRules()->State_Get() == GR_STATE_TEAM_WIN );
  30. const double flNow = gpGlobals->curtime;
  31. // There's a point that's the earliest we want to autojoin and also a point that's the latest we want to autojoin.
  32. const double flDesiredAutoJoinTime = flNow + 10.;
  33. const double flLatestJoinTime = TFGameRules()->State_Get() == GR_STATE_GAME_OVER ? TFGameRules()->GetStateTransitionTime() - 1. : TFGameRules()->GetStateTransitionTime() + TFGameRules()->GetPostMatchPeriod();
  34. const double flEarliestJoinTime = TFGameRules()->State_Get() == GR_STATE_GAME_OVER ? 0. : TFGameRules()->GetStateTransitionTime() + 10.;
  35. // We also want the minimum time of the autojoin to be 10 seconds long. If the earliest join time is greater than
  36. // the now + 10, go with that. If now + 10 is beyond the latest join time, go with the latest join time.
  37. m_flAutoJoinTime = Max( flEarliestJoinTime, flDesiredAutoJoinTime );
  38. m_flAutoJoinTime = Min( m_flAutoJoinTime, flLatestJoinTime );
  39. }
  40. }
  41. virtual void OnUpdate() OVERRIDE
  42. {
  43. CTFMatchmakingPopup::OnUpdate();
  44. // Autojoin time
  45. wchar_t *pwszAutoJoinTime = NULL;
  46. // Update the countdown label
  47. double flTimeUntilAutoJoin = Max( 0., m_flAutoJoinTime - gpGlobals->curtime );
  48. pwszAutoJoinTime = LocalizeNumberWithToken( "TF_Matchmaking_RollingQueue_AutojoinWarning", ceil( flTimeUntilAutoJoin ) );
  49. SetDialogVariable( "auto_join", pwszAutoJoinTime );
  50. if ( m_flAutoJoinTime != 0.f && gpGlobals->curtime > m_flAutoJoinTime )
  51. {
  52. GTFGCClientSystem()->JoinMMMatch();
  53. }
  54. }
  55. virtual void OnExit() OVERRIDE
  56. {
  57. CTFMatchmakingPopup::OnExit();
  58. // No more auto join timer
  59. m_flAutoJoinTime = 0.f;
  60. }
  61. virtual bool ShouldBeActve() const OVERRIDE
  62. {
  63. #ifdef STAGING_ONLY
  64. if ( FStrEq( const_cast<CNewMatchFoundDashboardState*>(this)->GetName(), tf_mm_popup_state_override.GetString() ) )
  65. return true;
  66. #endif
  67. if ( BInEndOfMatch() && !GTFGCClientSystem()->BConnectedToMatchServer( true ) && GTFGCClientSystem()->BHaveLiveMatch() )
  68. {
  69. return true;
  70. }
  71. return false;
  72. }
  73. private:
  74. double m_flAutoJoinTime;
  75. };
  76. REG_MM_POPUP_FACTORY( CNewMatchFoundDashboardState, "NewMatchFound", "resource/UI/MatchMakingDashboardPopup_NewMatch.res" )