Counter Strike : Global Offensive Source Code
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.

173 lines
5.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "hud_chat.h"
  8. #include "hud_macros.h"
  9. #include "text_message.h"
  10. #include "vguicenterprint.h"
  11. #include "hud_basechat.h"
  12. #include <vgui/ILocalize.h>
  13. // NOTE: This has to be the last file included!
  14. #include "tier0/memdbgon.h"
  15. DECLARE_HUDELEMENT_FLAGS( CHudChat, HUDELEMENT_SS_FULLSCREEN_ONLY );
  16. DECLARE_HUD_MESSAGE( CHudChat, SayText );
  17. DECLARE_HUD_MESSAGE( CHudChat, SayText2 );
  18. DECLARE_HUD_MESSAGE( CHudChat, TextMsg );
  19. //=====================
  20. //CHudChat
  21. //=====================
  22. CHudChat::CHudChat( const char *pElementName ) : BaseClass( pElementName )
  23. {
  24. }
  25. void CHudChat::Init( void )
  26. {
  27. BaseClass::Init();
  28. HOOK_HUD_MESSAGE( CHudChat, SayText );
  29. HOOK_HUD_MESSAGE( CHudChat, SayText2 );
  30. HOOK_HUD_MESSAGE( CHudChat, TextMsg );
  31. }
  32. //-----------------------------------------------------------------------------
  33. // Purpose: Reads in a player's Chat text from the server
  34. //-----------------------------------------------------------------------------
  35. void CHudChat::MsgFunc_SayText2( bf_read &msg )
  36. {
  37. int client = msg.ReadByte();
  38. bool bWantsToChat = msg.ReadByte() ? true : false;
  39. wchar_t szBuf[6][256];
  40. char untranslated_msg_text[256];
  41. wchar_t *msg_text = ReadLocalizedString( msg, szBuf[0], sizeof( szBuf[0] ), false, untranslated_msg_text, sizeof( untranslated_msg_text ) );
  42. // keep reading strings and using C format strings for subsituting the strings into the localised text string
  43. ReadChatTextString ( msg, szBuf[1], sizeof( szBuf[1] ) ); // player name
  44. ReadChatTextString ( msg, szBuf[2], sizeof( szBuf[2] ) ); // chat text
  45. ReadLocalizedString( msg, szBuf[3], sizeof( szBuf[3] ), true );
  46. ReadLocalizedString( msg, szBuf[4], sizeof( szBuf[4] ), true );
  47. g_pVGuiLocalize->ConstructString( szBuf[5], sizeof( szBuf[5] ), msg_text, 4, szBuf[1], szBuf[2], szBuf[3], szBuf[4] );
  48. char ansiString[512];
  49. g_pVGuiLocalize->ConvertUnicodeToANSI( ConvertCRtoNL( szBuf[5] ), ansiString, sizeof( ansiString ) );
  50. if ( bWantsToChat )
  51. {
  52. // print raw chat text
  53. ChatPrintf( client, CHAT_FILTER_NONE, "%s", ansiString );
  54. Msg( "%s\n", RemoveColorMarkup(ansiString) );
  55. }
  56. else
  57. {
  58. // print raw chat text
  59. ChatPrintf( client, CHAT_FILTER_NONE, "%s", ansiString );
  60. }
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Purpose:
  64. // Input : *pszName -
  65. // iSize -
  66. // *pbuf -
  67. //-----------------------------------------------------------------------------
  68. void CHudChat::MsgFunc_SayText( bf_read &msg )
  69. {
  70. char szString[256];
  71. msg.ReadByte(); // client ID
  72. msg.ReadString( szString, sizeof(szString) );
  73. Printf( CHAT_FILTER_NONE, "%s", szString );
  74. }
  75. // Message handler for text messages
  76. // displays a string, looking them up from the titles.txt file, which can be localised
  77. // parameters:
  78. // byte: message direction ( HUD_PRINTCONSOLE, HUD_PRINTNOTIFY, HUD_PRINTCENTER, HUD_PRINTTALK )
  79. // string: message
  80. // optional parameters:
  81. // string: message parameter 1
  82. // string: message parameter 2
  83. // string: message parameter 3
  84. // string: message parameter 4
  85. // any string that starts with the character '#' is a message name, and is used to look up the real message in titles.txt
  86. // the next (optional) one to four strings are parameters for that string (which can also be message names if they begin with '#')
  87. void CHudChat::MsgFunc_TextMsg( bf_read &msg )
  88. {
  89. char szString[2048];
  90. int msg_dest = msg.ReadByte();
  91. static char szBuf[6][256];
  92. msg.ReadString( szString, sizeof(szString) );
  93. char *msg_text = hudtextmessage->LookupString( szString, &msg_dest );
  94. Q_strncpy( szBuf[0], msg_text, sizeof( szBuf[0] ) );
  95. msg_text = szBuf[0];
  96. // keep reading strings and using C format strings for subsituting the strings into the localised text string
  97. msg.ReadString( szString, sizeof(szString) );
  98. char *sstr1 = hudtextmessage->LookupString( szString );
  99. Q_strncpy( szBuf[1], sstr1, sizeof( szBuf[1] ) );
  100. sstr1 = szBuf[1];
  101. StripEndNewlineFromString( sstr1 ); // these strings are meant for subsitution into the main strings, so cull the automatic end newlines
  102. msg.ReadString( szString, sizeof(szString) );
  103. char *sstr2 = hudtextmessage->LookupString( szString );
  104. Q_strncpy( szBuf[2], sstr2, sizeof( szBuf[2] ) );
  105. sstr2 = szBuf[2];
  106. StripEndNewlineFromString( sstr2 );
  107. msg.ReadString( szString, sizeof(szString) );
  108. char *sstr3 = hudtextmessage->LookupString( szString );
  109. Q_strncpy( szBuf[3], sstr3, sizeof( szBuf[3] ) );
  110. sstr3 = szBuf[3];
  111. StripEndNewlineFromString( sstr3 );
  112. msg.ReadString( szString, sizeof(szString) );
  113. char *sstr4 = hudtextmessage->LookupString( szString );
  114. Q_strncpy( szBuf[4], sstr4, sizeof( szBuf[4] ) );
  115. sstr4 = szBuf[4];
  116. StripEndNewlineFromString( sstr4 );
  117. char *psz = szBuf[5];
  118. if ( !cl_showtextmsg.GetInt() )
  119. return;
  120. switch ( msg_dest )
  121. {
  122. case HUD_PRINTCENTER:
  123. Q_snprintf( psz, sizeof( szBuf[5] ), msg_text, sstr1, sstr2, sstr3, sstr4 );
  124. GetCenterPrint()->Print( ConvertCRtoNL( psz ) );
  125. break;
  126. case HUD_PRINTNOTIFY:
  127. psz[0] = 1; // mark this message to go into the notify buffer
  128. Q_snprintf( psz+1, sizeof( szBuf[5] ) - 1, msg_text, sstr1, sstr2, sstr3, sstr4 );
  129. Msg( "%s", ConvertCRtoNL( psz ) );
  130. break;
  131. case HUD_PRINTTALK:
  132. Q_snprintf( psz, sizeof( szBuf[5] ), msg_text, sstr1, sstr2, sstr3, sstr4 );
  133. Printf( CHAT_FILTER_NONE, "%s", ConvertCRtoNL( psz ) );
  134. break;
  135. case HUD_PRINTCONSOLE:
  136. Q_snprintf( psz, sizeof( szBuf[5] ), msg_text, sstr1, sstr2, sstr3, sstr4 );
  137. Msg( "%s", ConvertCRtoNL( psz ) );
  138. break;
  139. }
  140. }