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.

148 lines
4.4 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 CDODHudWarmupLabel : public vgui::Panel, public CHudElement
  23. {
  24. DECLARE_CLASS_SIMPLE( CDODHudWarmupLabel, vgui::Panel );
  25. public:
  26. CDODHudWarmupLabel( const char *pElementName );
  27. virtual void Reset();
  28. virtual void PerformLayout();
  29. protected:
  30. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  31. virtual void OnThink();
  32. private:
  33. vgui::HFont m_hFont;
  34. Color m_bgColor;
  35. vgui::Label *m_pWarmupLabel; // "Warmup Mode"
  36. vgui::Label *m_pBackground; // black box
  37. bool m_bInWarmup;
  38. CPanelAnimationVarAliasType( int, m_iTextX, "text_xpos", "8", "proportional_int" );
  39. CPanelAnimationVarAliasType( int, m_iTextY, "text_ypos", "8", "proportional_int" );
  40. };
  41. DECLARE_HUDELEMENT( CDODHudWarmupLabel );
  42. //-----------------------------------------------------------------------------
  43. // Purpose: Constructor
  44. //-----------------------------------------------------------------------------
  45. CDODHudWarmupLabel::CDODHudWarmupLabel( const char *pElementName ) : BaseClass(NULL, "WarmupLabel"), CHudElement( pElementName )
  46. {
  47. vgui::Panel *pParent = g_pClientMode->GetViewport();
  48. SetParent( pParent );
  49. SetVisible( false );
  50. SetAlpha( 0 );
  51. m_pBackground = new vgui::Label( this, "Background", "" );
  52. m_pWarmupLabel = new vgui::Label( this, "RoundState_warmup", g_pVGuiLocalize->Find( "#Clan_warmup_mode" ) );
  53. m_pWarmupLabel->SetPaintBackgroundEnabled( false );
  54. m_pWarmupLabel->SetPaintBorderEnabled( false );
  55. m_pWarmupLabel->SizeToContents();
  56. m_pWarmupLabel->SetContentAlignment( vgui::Label::a_west );
  57. m_pWarmupLabel->SetFgColor( GetFgColor() );
  58. m_bInWarmup = false;
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose:
  62. //-----------------------------------------------------------------------------
  63. void CDODHudWarmupLabel::Reset()
  64. {
  65. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "WarmupLabelHide" );
  66. m_bInWarmup = false;
  67. }
  68. //-----------------------------------------------------------------------------
  69. // Purpose:
  70. //-----------------------------------------------------------------------------
  71. void CDODHudWarmupLabel::ApplySchemeSettings( vgui::IScheme *pScheme )
  72. {
  73. BaseClass::ApplySchemeSettings( pScheme );
  74. SetFgColor( Color(0,0,0,0) ); //GetSchemeColor("RoundStateFg", pScheme) );
  75. m_hFont = pScheme->GetFont( "HudHintText", true );
  76. m_pBackground->SetBgColor( GetSchemeColor("HintMessageBg", pScheme) );
  77. m_pBackground->SetPaintBackgroundType( 2 );
  78. SetAlpha( 0 );
  79. }
  80. //-----------------------------------------------------------------------------
  81. // Purpose: Resizes the label
  82. //-----------------------------------------------------------------------------
  83. void CDODHudWarmupLabel::PerformLayout()
  84. {
  85. BaseClass::PerformLayout();
  86. int wide, tall;
  87. GetSize( wide, tall );
  88. // find the widest line
  89. int labelWide = m_pWarmupLabel->GetWide();
  90. // find the total height
  91. int fontTall = vgui::surface()->GetFontTall( m_hFont );
  92. int labelTall = fontTall;
  93. labelWide += m_iTextX*2;
  94. labelTall += m_iTextY*2;
  95. m_pBackground->SetBounds( 0, 0, labelWide, labelTall );
  96. int xOffset = (labelWide - m_pWarmupLabel->GetWide())/2;
  97. m_pWarmupLabel->SetPos( 0 + xOffset, 0 + m_iTextY );
  98. }
  99. //-----------------------------------------------------------------------------
  100. // Purpose: Updates the label color each frame
  101. //-----------------------------------------------------------------------------
  102. void CDODHudWarmupLabel::OnThink()
  103. {
  104. m_pBackground->SetFgColor(GetFgColor());
  105. m_pWarmupLabel->SetFgColor(GetFgColor());
  106. bool bInWarmup = DODGameRules()->IsInWarmup();
  107. if( bInWarmup != m_bInWarmup )
  108. {
  109. if( bInWarmup )
  110. {
  111. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "WarmupLabelShow" );
  112. InvalidateLayout();
  113. }
  114. m_bInWarmup = bInWarmup;
  115. }
  116. }