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.

205 lines
6.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "hud.h"
  8. #include "hudelement.h"
  9. #include "hud_macros.h"
  10. #include "iclientmode.h"
  11. #include "vgui_controls/AnimationController.h"
  12. #include "vgui_controls/Label.h"
  13. #include "vgui/ILocalize.h"
  14. #include "vgui/ISurface.h"
  15. #include "text_message.h"
  16. #include "dod_gamerules.h"
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include "tier0/memdbgon.h"
  19. //-----------------------------------------------------------------------------
  20. // Purpose: Displays current ammunition level
  21. //-----------------------------------------------------------------------------
  22. class CDODReadyRestartLabel : public vgui::Panel, public CHudElement
  23. {
  24. DECLARE_CLASS_SIMPLE( CDODReadyRestartLabel, vgui::Panel );
  25. public:
  26. CDODReadyRestartLabel( const char *pElementName );
  27. virtual void Reset();
  28. virtual void Init();
  29. virtual void PerformLayout();
  30. void FireGameEvent( IGameEvent * event);
  31. protected:
  32. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  33. virtual void OnThink();
  34. private:
  35. vgui::HFont m_hFont;
  36. Color m_bgColor;
  37. vgui::Label *m_pRestartLabel; // "Round will restart in 0:00"
  38. vgui::Label *m_pAlliesReady; // "Allies are READY"
  39. vgui::Label *m_pAxisReady; // "Axis are NOT READY"
  40. vgui::Label *m_pBackground;
  41. float m_flLastRestartTime;
  42. CPanelAnimationVarAliasType( int, m_iTextX, "text_xpos", "8", "proportional_int" );
  43. CPanelAnimationVarAliasType( int, m_iTextY, "text_ypos", "8", "proportional_int" );
  44. };
  45. DECLARE_HUDELEMENT( CDODReadyRestartLabel );
  46. //-----------------------------------------------------------------------------
  47. // Purpose: Constructor
  48. //-----------------------------------------------------------------------------
  49. CDODReadyRestartLabel::CDODReadyRestartLabel( const char *pElementName ) : BaseClass(NULL, "ReadyRestartLabel"), CHudElement( pElementName )
  50. {
  51. vgui::Panel *pParent = g_pClientMode->GetViewport();
  52. SetParent( pParent );
  53. SetVisible( false );
  54. SetAlpha( 0 );
  55. m_pBackground = new vgui::Label( this, "Background", "" );
  56. wchar_t labelText[128];
  57. g_pVGuiLocalize->ConstructString( labelText, sizeof(labelText), g_pVGuiLocalize->Find( "#clan_game_restart" ), 2, L"0", L"00" );
  58. m_pRestartLabel = new vgui::Label( this, "RoundState_waiting", g_pVGuiLocalize->Find( "#Clan_awaiting_ready" ) );
  59. m_pRestartLabel->SetFgColor( GetFgColor() );
  60. m_pRestartLabel->SizeToContents();
  61. m_pAlliesReady = new vgui::Label( this, "RoundState_allies", L"" );
  62. m_pAlliesReady->SetFgColor( GetFgColor() );
  63. m_pAxisReady = new vgui::Label( this, "RoundState_axis", L"" );
  64. m_pAxisReady->SetFgColor( GetFgColor() );
  65. m_flLastRestartTime = 0;
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose:
  69. //-----------------------------------------------------------------------------
  70. void CDODReadyRestartLabel::Reset()
  71. {
  72. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "ReadyRestartLabelHide" );
  73. }
  74. //-----------------------------------------------------------------------------
  75. // Purpose:
  76. //-----------------------------------------------------------------------------
  77. void CDODReadyRestartLabel::Init()
  78. {
  79. // listen for events
  80. ListenForGameEvent( "dod_round_start" );
  81. ListenForGameEvent( "dod_ready_restart" );
  82. ListenForGameEvent( "dod_allies_ready" );
  83. ListenForGameEvent( "dod_axis_ready" );
  84. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "ReadyRestartLabelHide" );
  85. }
  86. //-----------------------------------------------------------------------------
  87. // Purpose:
  88. //-----------------------------------------------------------------------------
  89. void CDODReadyRestartLabel::ApplySchemeSettings( vgui::IScheme *pScheme )
  90. {
  91. BaseClass::ApplySchemeSettings( pScheme );
  92. SetFgColor( Color(0,0,0,0) );
  93. m_hFont = pScheme->GetFont( "HudHintText", true );
  94. m_pBackground->SetBgColor( GetSchemeColor("HintMessageBg", pScheme) );
  95. m_pBackground->SetPaintBackgroundType( 2 );
  96. SetAlpha( 0 );
  97. }
  98. //-----------------------------------------------------------------------------
  99. // Purpose: Resizes the label
  100. //-----------------------------------------------------------------------------
  101. void CDODReadyRestartLabel::PerformLayout()
  102. {
  103. BaseClass::PerformLayout();
  104. int wide, tall;
  105. GetSize( wide, tall );
  106. // find the widest line
  107. int labelWide = m_pRestartLabel->GetWide();
  108. // find the total height
  109. int fontTall = vgui::surface()->GetFontTall( m_hFont );
  110. labelWide += m_iTextX*2;
  111. int labelTall = fontTall*3 + m_iTextY*2;
  112. m_pBackground->SetBounds( 0, 0, labelWide, labelTall );
  113. int xOffset = (labelWide - m_pRestartLabel->GetWide())/2;
  114. m_pRestartLabel->SetPos( xOffset, m_iTextY );
  115. m_pAlliesReady->SetPos( xOffset, m_iTextY + fontTall );
  116. m_pAxisReady->SetPos( xOffset, m_iTextY + 2 *fontTall );
  117. }
  118. //-----------------------------------------------------------------------------
  119. // Purpose: Updates the label color each frame
  120. //-----------------------------------------------------------------------------
  121. void CDODReadyRestartLabel::OnThink()
  122. {
  123. float flRoundRestartTime = DODGameRules()->GetRoundRestartTime();
  124. if( flRoundRestartTime != m_flLastRestartTime )
  125. {
  126. if( flRoundRestartTime > 0 )
  127. {
  128. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "ReadyRestartLabelHide" );
  129. }
  130. m_flLastRestartTime = flRoundRestartTime;
  131. }
  132. m_pBackground->SetFgColor(GetFgColor());
  133. m_pRestartLabel->SetFgColor(GetFgColor());
  134. m_pAlliesReady->SetFgColor(GetFgColor());
  135. m_pAxisReady->SetFgColor(GetFgColor());
  136. }
  137. //-----------------------------------------------------------------------------
  138. // Purpose: Activates the hint display upon receiving a hint
  139. //-----------------------------------------------------------------------------
  140. void CDODReadyRestartLabel::FireGameEvent( IGameEvent * event)
  141. {
  142. if( Q_strcmp( "dod_round_start", event->GetName() ) == 0 )
  143. {
  144. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "ReadyRestartLabelHide" );
  145. }
  146. else if( Q_strcmp( "dod_ready_restart", event->GetName() ) == 0 )
  147. {
  148. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "ReadyRestartLabelShow" );
  149. m_pAlliesReady->SetText( g_pVGuiLocalize->Find( "#clan_allies_not_ready" ) );
  150. m_pAlliesReady->SizeToContents();
  151. m_pAxisReady->SetText( g_pVGuiLocalize->Find( "#clan_axis_not_ready" ) );
  152. m_pAxisReady->SizeToContents();
  153. }
  154. else if( Q_strcmp( "dod_allies_ready", event->GetName() ) == 0 )
  155. {
  156. m_pAlliesReady->SetText( g_pVGuiLocalize->Find( "#clan_allies_ready" ) );
  157. m_pAlliesReady->SizeToContents();
  158. }
  159. else if( Q_strcmp( "dod_axis_ready", event->GetName() ) == 0 )
  160. {
  161. m_pAxisReady->SetText( g_pVGuiLocalize->Find( "#clan_axis_ready" ) );
  162. m_pAxisReady->SizeToContents();
  163. }
  164. }