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.

142 lines
4.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 "hud_macros.h"
  11. #include "c_tf_player.h"
  12. #include "iclientmode.h"
  13. #include "ienginevgui.h"
  14. #include <vgui/ILocalize.h>
  15. #include <vgui/ISurface.h>
  16. #include <vgui/IVGui.h>
  17. #include <vgui_controls/Label.h>
  18. #include <vgui_controls/EditablePanel.h>
  19. #include "tf_imagepanel.h"
  20. #include "tf_gamerules.h"
  21. #include "c_tf_team.h"
  22. #include "tf_controls.h"
  23. #include "hud_basechat.h"
  24. #include "c_team_objectiveresource.h"
  25. #include "tf_hud_training.h"
  26. // memdbgon must be the last include file in a .cpp file!!!
  27. #include "tier0/memdbgon.h"
  28. using namespace vgui;
  29. //-----------------------------------------------------------------------------
  30. // Purpose:
  31. //-----------------------------------------------------------------------------
  32. class CHudTrainingInfoMsg : public CHudElement, public EditablePanel
  33. {
  34. DECLARE_CLASS_SIMPLE( CHudTrainingInfoMsg, EditablePanel );
  35. public:
  36. CHudTrainingInfoMsg( const char *pElementName );
  37. virtual void Init( void );
  38. virtual void Reset( void );
  39. virtual void ApplySchemeSettings( IScheme *scheme );
  40. virtual bool ShouldDraw( void );
  41. void MsgFunc_TrainingInfoMsg( bf_read &msg );
  42. void LocalizeAndDisplay( const char *szRawString );
  43. private:
  44. Label *m_pGoalLabel;
  45. //Color m_cRegularColor;
  46. };
  47. DECLARE_HUDELEMENT( CHudTrainingInfoMsg );
  48. DECLARE_HUD_MESSAGE( CHudTrainingInfoMsg, TrainingInfoMsg );
  49. //-----------------------------------------------------------------------------
  50. // Purpose:
  51. //-----------------------------------------------------------------------------
  52. CHudTrainingInfoMsg::CHudTrainingInfoMsg( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudTrainingInfoMsg" )
  53. {
  54. Panel *pParent = g_pClientMode->GetViewport();
  55. SetParent( pParent );
  56. SetHiddenBits( HIDEHUD_MISCSTATUS );
  57. RegisterForRenderGroup( "commentary" );
  58. SetVisible( false );
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose:
  62. //-----------------------------------------------------------------------------
  63. void CHudTrainingInfoMsg::Reset()
  64. {
  65. SetVisible( false );
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose:
  69. //-----------------------------------------------------------------------------
  70. void CHudTrainingInfoMsg::Init()
  71. {
  72. HOOK_HUD_MESSAGE( CHudTrainingInfoMsg, TrainingInfoMsg );
  73. }
  74. //-----------------------------------------------------------------------------
  75. // Purpose:
  76. //-----------------------------------------------------------------------------
  77. void CHudTrainingInfoMsg::ApplySchemeSettings( IScheme *pScheme )
  78. {
  79. // load control settings...
  80. LoadControlSettings( "resource/UI/HudTrainingInfoMsg.res" );
  81. BaseClass::ApplySchemeSettings( pScheme );
  82. m_pGoalLabel = dynamic_cast<Label *>( FindChildByName("GoalLabel") );
  83. //m_cRegularColor = pScheme->GetColor( "TanLight", Color( 0, 0, 0 ) );
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Purpose:
  87. //-----------------------------------------------------------------------------
  88. bool CHudTrainingInfoMsg::ShouldDraw( void )
  89. {
  90. return IsVisible();
  91. }
  92. //-----------------------------------------------------------------------------
  93. // Purpose: Activates the hint display
  94. //-----------------------------------------------------------------------------
  95. void CHudTrainingInfoMsg::MsgFunc_TrainingInfoMsg( bf_read &msg )
  96. {
  97. // Read the string(s)
  98. char szString[255];
  99. msg.ReadString( szString, sizeof(szString) );
  100. if ( !szString[0] )
  101. {
  102. SetVisible( false );
  103. return;
  104. }
  105. //Localize and display the string.
  106. wchar_t outputText[MAX_TRAINING_MSG_LENGTH];
  107. CTFHudTraining::FormatTrainingText(szString , outputText);
  108. SetVisible( true );
  109. m_pGoalLabel->SetText( outputText );
  110. //g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "HintMessageShow" );
  111. //g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "HintMessageHide" );
  112. C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
  113. if ( pLocalPlayer )
  114. {
  115. pLocalPlayer->EmitSound( "Hud.Hint" );
  116. }
  117. }