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.

301 lines
7.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "tf_hud_chat.h"
  8. #include "hud_macros.h"
  9. #include "text_message.h"
  10. #include "vguicenterprint.h"
  11. #include "vgui/ILocalize.h"
  12. #include "engine/IEngineSound.h"
  13. #include "c_tf_team.h"
  14. #include "c_playerresource.h"
  15. #include "c_tf_player.h"
  16. #include "tf_gamerules.h"
  17. #include "ihudlcd.h"
  18. #include "tf_hud_freezepanel.h"
  19. #if defined( REPLAY_ENABLED )
  20. #include "replay/ienginereplay.h"
  21. #endif
  22. // memdbgon must be the last include file in a .cpp file!!!
  23. #include "tier0/memdbgon.h"
  24. DECLARE_HUDELEMENT( CHudChat );
  25. DECLARE_HUD_MESSAGE( CHudChat, SayText );
  26. DECLARE_HUD_MESSAGE( CHudChat, SayText2 );
  27. DECLARE_HUD_MESSAGE( CHudChat, TextMsg );
  28. DECLARE_HUD_MESSAGE( CHudChat, VoiceSubtitle );
  29. //=====================
  30. //CHudChatLine
  31. //=====================
  32. void CHudChatLine::ApplySchemeSettings(vgui::IScheme *pScheme)
  33. {
  34. BaseClass::ApplySchemeSettings( pScheme );
  35. m_hFont = pScheme->GetFont( "ChatFont" );
  36. SetBorder( NULL );
  37. SetBgColor( Color( 0, 0, 0, 0 ) );
  38. SetFgColor( Color( 0, 0, 0, 0 ) );
  39. SetFont( m_hFont );
  40. }
  41. CHudChatLine::CHudChatLine( vgui::Panel *parent, const char *panelName ) : CBaseHudChatLine( parent, panelName )
  42. {
  43. m_text = NULL;
  44. }
  45. //=====================
  46. //CHudChatInputLine
  47. //=====================
  48. void CHudChatInputLine::ApplySchemeSettings(vgui::IScheme *pScheme)
  49. {
  50. BaseClass::ApplySchemeSettings(pScheme);
  51. }
  52. //=====================
  53. //CHudChat
  54. //=====================
  55. CHudChat::CHudChat( const char *pElementName ) : BaseClass( pElementName )
  56. {
  57. #if defined ( _X360 )
  58. RegisterForRenderGroup( "mid" );
  59. #endif
  60. }
  61. void CHudChat::CreateChatInputLine( void )
  62. {
  63. m_pChatInput = new CHudChatInputLine( this, "ChatInputLine" );
  64. m_pChatInput->SetVisible( false );
  65. }
  66. void CHudChat::CreateChatLines( void )
  67. {
  68. #ifndef _XBOX
  69. m_ChatLine = new CHudChatLine( this, "ChatLine1" );
  70. m_ChatLine->SetVisible( false );
  71. #endif
  72. }
  73. void CHudChat::Init( void )
  74. {
  75. BaseClass::Init();
  76. HOOK_HUD_MESSAGE( CHudChat, SayText );
  77. HOOK_HUD_MESSAGE( CHudChat, SayText2 );
  78. HOOK_HUD_MESSAGE( CHudChat, TextMsg );
  79. HOOK_HUD_MESSAGE( CHudChat, VoiceSubtitle );
  80. }
  81. //-----------------------------------------------------------------------------
  82. // Purpose: Hides us when our render group is hidden
  83. // move render group to base chat when its safer
  84. //-----------------------------------------------------------------------------
  85. bool CHudChat::ShouldDraw( void )
  86. {
  87. #if defined( REPLAY_ENABLED )
  88. extern IEngineClientReplay *g_pEngineClientReplay;
  89. if ( g_pEngineClientReplay->IsPlayingReplayDemo() )
  90. return false;
  91. #endif
  92. return CHudElement::ShouldDraw();
  93. }
  94. //-----------------------------------------------------------------------------
  95. // Purpose: Overrides base reset to not cancel chat at round restart
  96. //-----------------------------------------------------------------------------
  97. void CHudChat::Reset( void )
  98. {
  99. }
  100. //-----------------------------------------------------------------------------
  101. // Purpose:
  102. //-----------------------------------------------------------------------------
  103. int CHudChat::GetChatInputOffset( void )
  104. {
  105. if ( m_pChatInput->IsVisible() )
  106. {
  107. return m_iFontHeight;
  108. }
  109. else
  110. {
  111. return 0;
  112. }
  113. }
  114. int CHudChat::GetFilterForString( const char *pString )
  115. {
  116. int iFilter = BaseClass::GetFilterForString( pString );
  117. if ( iFilter == CHAT_FILTER_NONE )
  118. {
  119. if ( !Q_stricmp( pString, "#TF_Name_Change" ) )
  120. {
  121. return CHAT_FILTER_NAMECHANGE;
  122. }
  123. }
  124. return iFilter;
  125. }
  126. //-----------------------------------------------------------------------------
  127. Color CHudChat::GetClientColor( int clientIndex )
  128. {
  129. IScheme *pScheme = scheme()->GetIScheme( GetScheme() );
  130. if ( pScheme == NULL )
  131. return Color( 255, 255, 255, 255 );
  132. if ( clientIndex == 0 ) // console msg
  133. {
  134. return g_ColorGreen;
  135. }
  136. else if( g_PR )
  137. {
  138. int iTeam = g_PR->GetTeam( clientIndex );
  139. C_TFPlayer *pPlayer = ToTFPlayer( UTIL_PlayerByIndex( clientIndex ) );
  140. C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
  141. if ( IsVoiceSubtitle() == true )
  142. {
  143. // if this player is on the other team, disguised as my team, show disguised color
  144. if ( pPlayer && pLocalPlayer && pPlayer->m_Shared.InCond( TF_COND_DISGUISED ) &&
  145. pPlayer->m_Shared.GetDisguiseTeam() == pLocalPlayer->GetTeamNumber() )
  146. {
  147. iTeam = pPlayer->m_Shared.GetDisguiseTeam();
  148. }
  149. }
  150. switch ( iTeam )
  151. {
  152. case TF_TEAM_RED : return pScheme->GetColor( "TFColors.ChatTextRed", g_ColorRed );
  153. case TF_TEAM_BLUE : return pScheme->GetColor( "TFColors.ChatTextBlue", g_ColorBlue );
  154. default : return g_ColorGrey;
  155. }
  156. }
  157. return g_ColorYellow;
  158. }
  159. //-----------------------------------------------------------------------------
  160. // Purpose:
  161. //-----------------------------------------------------------------------------
  162. bool CHudChat::IsVisible( void )
  163. {
  164. if ( IsTakingAFreezecamScreenshot() )
  165. return false;
  166. return BaseClass::IsVisible();
  167. }
  168. const char *CHudChat::GetDisplayedSubtitlePlayerName( int clientIndex )
  169. {
  170. C_TFPlayer *pPlayer = ToTFPlayer( UTIL_PlayerByIndex( clientIndex ) );
  171. C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
  172. if ( !pPlayer || !pLocalPlayer )
  173. return BaseClass::GetDisplayedSubtitlePlayerName( clientIndex );
  174. // If they are disguised as the enemy, and not on our team
  175. if ( pPlayer->m_Shared.InCond( TF_COND_DISGUISED ) &&
  176. pPlayer->m_Shared.GetDisguiseTeam() != pPlayer->GetTeamNumber() &&
  177. !pLocalPlayer->InSameTeam( pPlayer ) )
  178. {
  179. C_TFPlayer *pDisguiseTarget = ToTFPlayer( pPlayer->m_Shared.GetDisguiseTarget() );
  180. Assert( pDisguiseTarget );
  181. if ( !pDisguiseTarget )
  182. {
  183. return BaseClass::GetDisplayedSubtitlePlayerName( clientIndex );
  184. }
  185. return pDisguiseTarget->GetPlayerName();
  186. }
  187. return BaseClass::GetDisplayedSubtitlePlayerName( clientIndex );
  188. }
  189. //-----------------------------------------------------------------------------
  190. // Purpose:
  191. //-----------------------------------------------------------------------------
  192. Color CHudChat::GetTextColorForClient( TextColor colorNum, int clientIndex )
  193. {
  194. IScheme *pScheme = scheme()->GetIScheme( GetScheme() );
  195. if ( pScheme == NULL )
  196. return Color( 255, 255, 255, 255 );
  197. Color c;
  198. switch ( colorNum )
  199. {
  200. case COLOR_CUSTOM:
  201. c = m_ColorCustom;
  202. break;
  203. case COLOR_PLAYERNAME:
  204. c = GetClientColor( clientIndex );
  205. break;
  206. case COLOR_LOCATION:
  207. c = g_ColorDarkGreen;
  208. break;
  209. case COLOR_ACHIEVEMENT:
  210. {
  211. IScheme *pSourceScheme = scheme()->GetIScheme( scheme()->GetScheme( "SourceScheme" ) );
  212. if ( pSourceScheme )
  213. {
  214. c = pSourceScheme->GetColor( "SteamLightGreen", GetBgColor() );
  215. }
  216. else
  217. {
  218. c = pScheme->GetColor( "TFColors.ChatTextYellow", GetBgColor() );
  219. }
  220. }
  221. break;
  222. default:
  223. c = pScheme->GetColor( "TFColors.ChatTextYellow", GetBgColor() );
  224. }
  225. return Color( c[0], c[1], c[2], 255 );
  226. }
  227. int CHudChat::GetFilterFlags( void )
  228. {
  229. //=============================================================================
  230. // HPE_BEGIN:
  231. // [msmith] We don't want to be displaying these chat messages when we're in training.
  232. // This is because we don't want the player seeing when bots join etc.
  233. //=============================================================================
  234. if ( TFGameRules() && TFGameRules()->IsInTraining() )
  235. return CHAT_FILTER_PUBLICCHAT;
  236. //=============================================================================
  237. // HPE_END
  238. //=============================================================================
  239. int iFlags = BaseClass::GetFilterFlags();
  240. if ( TFGameRules() && TFGameRules()->IsInArenaMode() == true )
  241. {
  242. return iFlags &= ~CHAT_FILTER_TEAMCHANGE;
  243. }
  244. return iFlags;
  245. }