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.

183 lines
5.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "cbase.h"
  8. #include "hud.h"
  9. #include "hudelement.h"
  10. #include "c_tf_player.h"
  11. #include "iclientmode.h"
  12. #include "ienginevgui.h"
  13. #include <vgui/ILocalize.h>
  14. #include <vgui/ISurface.h>
  15. #include <vgui/IVGui.h>
  16. #include <vgui_controls/Label.h>
  17. #include <vgui_controls/EditablePanel.h>
  18. #include "tf_imagepanel.h"
  19. #include "tf_gamerules.h"
  20. #include "c_tf_team.h"
  21. // memdbgon must be the last include file in a .cpp file!!!
  22. #include "tier0/memdbgon.h"
  23. using namespace vgui;
  24. //-----------------------------------------------------------------------------
  25. // Purpose:
  26. //-----------------------------------------------------------------------------
  27. class CHudStalemate : public CHudElement, public EditablePanel
  28. {
  29. DECLARE_CLASS_SIMPLE( CHudStalemate, EditablePanel );
  30. public:
  31. CHudStalemate( const char *pElementName );
  32. virtual void Init( void );
  33. virtual void OnTick( void );
  34. virtual void LevelInit( void );
  35. virtual void ApplySchemeSettings( IScheme *scheme );
  36. virtual bool ShouldDraw( void );
  37. virtual void FireGameEvent( IGameEvent * event );
  38. void SetupStalematePanel( int iReason );
  39. private:
  40. Label *m_pStalemateLabel;
  41. Label *m_pReasonLabel;
  42. float m_flHideAt;
  43. };
  44. DECLARE_HUDELEMENT( CHudStalemate );
  45. //-----------------------------------------------------------------------------
  46. // Purpose:
  47. //-----------------------------------------------------------------------------
  48. CHudStalemate::CHudStalemate( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudStalemate" )
  49. {
  50. Panel *pParent = g_pClientMode->GetViewport();
  51. SetParent( pParent );
  52. SetHiddenBits( HIDEHUD_MISCSTATUS );
  53. m_flHideAt = 0;
  54. vgui::ivgui()->AddTickSignal( GetVPanel() );
  55. }
  56. //-----------------------------------------------------------------------------
  57. // Purpose:
  58. //-----------------------------------------------------------------------------
  59. void CHudStalemate::Init( void )
  60. {
  61. // listen for events
  62. ListenForGameEvent( "teamplay_round_stalemate" );
  63. SetVisible( false );
  64. CHudElement::Init();
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose:
  68. //-----------------------------------------------------------------------------
  69. void CHudStalemate::FireGameEvent( IGameEvent * event )
  70. {
  71. const char *pEventName = event->GetName();
  72. if ( Q_strcmp( "teamplay_round_stalemate", pEventName ) == 0 )
  73. {
  74. int iReason = event->GetInt( "reason" );
  75. SetupStalematePanel( iReason );
  76. m_flHideAt = gpGlobals->curtime + 15.0;
  77. SetVisible( true );
  78. }
  79. }
  80. //-----------------------------------------------------------------------------
  81. // Purpose:
  82. // Input : -
  83. //-----------------------------------------------------------------------------
  84. void CHudStalemate::OnTick( void )
  85. {
  86. if ( m_flHideAt && m_flHideAt < gpGlobals->curtime )
  87. {
  88. SetVisible( false );
  89. m_flHideAt = 0;
  90. }
  91. }
  92. //-----------------------------------------------------------------------------
  93. // Purpose:
  94. //-----------------------------------------------------------------------------
  95. void CHudStalemate::LevelInit( void )
  96. {
  97. m_flHideAt = 0;
  98. SetVisible( false );
  99. }
  100. //-----------------------------------------------------------------------------
  101. // Purpose:
  102. //-----------------------------------------------------------------------------
  103. bool CHudStalemate::ShouldDraw( void )
  104. {
  105. return ( IsVisible() );
  106. }
  107. //-----------------------------------------------------------------------------
  108. // Purpose:
  109. //-----------------------------------------------------------------------------
  110. void CHudStalemate::ApplySchemeSettings( IScheme *pScheme )
  111. {
  112. // load control settings...
  113. LoadControlSettings( "resource/UI/HudStalemate.res" );
  114. BaseClass::ApplySchemeSettings( pScheme );
  115. m_pStalemateLabel = dynamic_cast<Label *>( FindChildByName("StalemateLabel") );
  116. m_pReasonLabel = dynamic_cast<Label *>( FindChildByName("ReasonLabel") );
  117. }
  118. const char *pszStalemateReasons[NUM_STALEMATE_REASONS] =
  119. {
  120. "#TF_suddendeath_join", // STALEMATE_JOIN_MID = 0,
  121. "#TF_suddendeath_timer", // STALEMATE_TIMER,
  122. "#TF_suddendeath_limit", // STALEMATE_SERVER_TIMELIMIT,
  123. };
  124. //-----------------------------------------------------------------------------
  125. // Purpose:
  126. //-----------------------------------------------------------------------------
  127. void CHudStalemate::SetupStalematePanel( int iReason )
  128. {
  129. if ( TFGameRules() && TFGameRules()->IsInArenaMode() == true )
  130. {
  131. if ( m_pStalemateLabel )
  132. {
  133. m_pStalemateLabel->SetText( g_pVGuiLocalize->Find( "#TF_Arena_SuddenDeathPanel" ) );
  134. }
  135. if ( m_pReasonLabel && iReason == STALEMATE_JOIN_MID )
  136. {
  137. m_pReasonLabel->SetText( g_pVGuiLocalize->Find( "#TF_Arena_SuddenDeathPanelReason" ) );
  138. }
  139. }
  140. else
  141. {
  142. if ( m_pStalemateLabel )
  143. {
  144. if ( iReason == STALEMATE_JOIN_MID )
  145. {
  146. m_pStalemateLabel->SetText( g_pVGuiLocalize->Find( "#TF_suddendeath_mode" ) );
  147. }
  148. else
  149. {
  150. m_pStalemateLabel->SetText( g_pVGuiLocalize->Find( "#TF_suddendeath" ) );
  151. }
  152. }
  153. if ( m_pReasonLabel && iReason >= 0 && iReason < NUM_STALEMATE_REASONS )
  154. {
  155. m_pReasonLabel->SetText( g_pVGuiLocalize->Find( pszStalemateReasons[iReason] ) );
  156. }
  157. }
  158. }