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.

189 lines
5.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: HUD Target ID element
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "hud.h"
  9. #include "hudelement.h"
  10. #include "c_hl2mp_player.h"
  11. #include "c_playerresource.h"
  12. #include "vgui_entitypanel.h"
  13. #include "iclientmode.h"
  14. #include "vgui/ILocalize.h"
  15. #include "hl2mp_gamerules.h"
  16. #include "c_team.h"
  17. #include <vgui_controls/AnimationController.h>
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include "tier0/memdbgon.h"
  20. //-----------------------------------------------------------------------------
  21. // Purpose: Displays current ammunition level
  22. //-----------------------------------------------------------------------------
  23. class CTeamPlayHud : public vgui::Panel, public CHudElement
  24. {
  25. DECLARE_CLASS_SIMPLE( CTeamPlayHud, vgui::Panel );
  26. public:
  27. CTeamPlayHud( const char *pElementName );
  28. void Reset();
  29. virtual void PerformLayout();
  30. protected:
  31. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  32. virtual void OnThink();
  33. private:
  34. vgui::HFont m_hFont;
  35. Color m_bgColor;
  36. vgui::Label *m_pWarmupLabel; // "Warmup Mode"
  37. vgui::Label *m_pBackground; // black box
  38. bool m_bSuitAuxPowerUsed;
  39. CPanelAnimationVarAliasType( int, m_iTextX, "text_xpos", "8", "proportional_int" );
  40. CPanelAnimationVarAliasType( int, m_iTextY, "text_ypos", "8", "proportional_int" );
  41. };
  42. DECLARE_HUDELEMENT( CTeamPlayHud );
  43. //-----------------------------------------------------------------------------
  44. // Purpose: Constructor
  45. //-----------------------------------------------------------------------------
  46. CTeamPlayHud::CTeamPlayHud( const char *pElementName ) : BaseClass(NULL, "TeamDisplay"), CHudElement( pElementName )
  47. {
  48. vgui::Panel *pParent = g_pClientMode->GetViewport();
  49. SetParent( pParent );
  50. SetVisible( false );
  51. SetAlpha( 255 );
  52. m_pBackground = new vgui::Label( this, "Background", "" );
  53. m_pWarmupLabel = new vgui::Label( this, "RoundState_warmup", "test label" /*g_pVGuiLocalize->Find( "#Clan_warmup_mode" )*/ );
  54. m_pWarmupLabel->SetPaintBackgroundEnabled( false );
  55. m_pWarmupLabel->SetPaintBorderEnabled( false );
  56. m_pWarmupLabel->SizeToContents();
  57. m_pWarmupLabel->SetContentAlignment( vgui::Label::a_west );
  58. m_pWarmupLabel->SetFgColor( GetFgColor() );
  59. m_bSuitAuxPowerUsed = false;
  60. }
  61. //-----------------------------------------------------------------------------
  62. // Purpose:
  63. //-----------------------------------------------------------------------------
  64. void CTeamPlayHud::Reset()
  65. {
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose:
  69. //-----------------------------------------------------------------------------
  70. void CTeamPlayHud::ApplySchemeSettings( vgui::IScheme *pScheme )
  71. {
  72. BaseClass::ApplySchemeSettings( pScheme );
  73. SetFgColor( Color(0,0,0,0) ); //GetSchemeColor("RoundStateFg", pScheme) );
  74. m_hFont = pScheme->GetFont( "Default", true );
  75. m_pBackground->SetBgColor( GetSchemeColor("BgColor", pScheme) );
  76. m_pBackground->SetPaintBackgroundType( 2 );
  77. SetAlpha( 255 );
  78. SetBgColor( Color( 0, 0, 0, 0 ) );
  79. SetPaintBackgroundType( 0 );
  80. }
  81. //-----------------------------------------------------------------------------
  82. // Purpose: Resizes the label
  83. //-----------------------------------------------------------------------------
  84. void CTeamPlayHud::PerformLayout()
  85. {
  86. BaseClass::PerformLayout();
  87. int wide, tall;
  88. GetSize( wide, tall );
  89. // find the widest line
  90. int labelWide = m_pWarmupLabel->GetWide();
  91. // find the total height
  92. int fontTall = vgui::surface()->GetFontTall( m_hFont );
  93. int labelTall = fontTall;
  94. labelWide += m_iTextX*2;
  95. labelTall += m_iTextY*2;
  96. m_pBackground->SetBounds( 0, 0, labelWide, labelTall );
  97. int xOffset = (labelWide - m_pWarmupLabel->GetWide())/2;
  98. m_pWarmupLabel->SetPos( 0 + xOffset, 0 + m_iTextY );
  99. }
  100. //-----------------------------------------------------------------------------
  101. // Purpose: Updates the label color each frame
  102. //-----------------------------------------------------------------------------
  103. void CTeamPlayHud::OnThink()
  104. {
  105. SetVisible( false );
  106. C_BaseHLPlayer *pLocalPlayer = (C_BaseHLPlayer *)C_BasePlayer::GetLocalPlayer();
  107. if ( pLocalPlayer == NULL )
  108. return;
  109. if ( HL2MPRules()->IsTeamplay() == false )
  110. return;
  111. if ( pLocalPlayer->IsAlive() == false )
  112. return;
  113. if ( pLocalPlayer->m_HL2Local.m_flSuitPower < 100 )
  114. {
  115. if ( m_bSuitAuxPowerUsed == false )
  116. {
  117. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("FadeOutTeamLine");
  118. m_bSuitAuxPowerUsed = true;
  119. }
  120. }
  121. else
  122. {
  123. if ( m_bSuitAuxPowerUsed == true )
  124. {
  125. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("FadeInTeamLine");
  126. m_bSuitAuxPowerUsed = false;
  127. }
  128. }
  129. int iTeamNumber = pLocalPlayer->GetTeamNumber();
  130. Color c = GameResources()->GetTeamColor( iTeamNumber );
  131. wchar_t string1[1024];
  132. C_Team *pTeam = GetGlobalTeam( iTeamNumber );
  133. if ( pTeam )
  134. {
  135. wchar_t TeamName[64];
  136. g_pVGuiLocalize->ConvertANSIToUnicode( pTeam->Get_Name(), TeamName, sizeof(TeamName) );
  137. g_pVGuiLocalize->ConstructString( string1, sizeof(string1), g_pVGuiLocalize->Find("#Team"), 1, TeamName );
  138. m_pBackground->SetFgColor( GetFgColor() );
  139. m_pWarmupLabel->SetFgColor(c);
  140. m_pWarmupLabel->SetText( string1 );
  141. m_pWarmupLabel->SetVisible( true );
  142. m_pWarmupLabel->SizeToContents();
  143. SetVisible( true );
  144. }
  145. InvalidateLayout();
  146. }