2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2008-08-27 19:41:02 +00:00
|
|
|
|
2011-08-31 11:56:04 +00:00
|
|
|
#include <base/tl/string.h>
|
|
|
|
|
2011-02-27 16:56:03 +00:00
|
|
|
#include <engine/engine.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <engine/graphics.h>
|
|
|
|
#include <engine/textrender.h>
|
|
|
|
#include <engine/keys.h>
|
|
|
|
#include <engine/shared/config.h>
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <game/generated/client_data.h>
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <game/client/gameclient.h>
|
2008-08-29 05:34:18 +00:00
|
|
|
|
2010-08-18 01:57:35 +00:00
|
|
|
#include <game/client/components/scoreboard.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <game/client/components/sounds.h>
|
|
|
|
#include <game/localization.h>
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include "chat.h"
|
|
|
|
|
|
|
|
|
|
|
|
CChat::CChat()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
OnReset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CChat::OnReset()
|
|
|
|
{
|
|
|
|
for(int i = 0; i < MAX_LINES; i++)
|
2009-05-31 09:44:20 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_aLines[i].m_Time = 0;
|
|
|
|
m_aLines[i].m_aText[0] = 0;
|
|
|
|
m_aLines[i].m_aName[0] = 0;
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-30 12:01:11 +00:00
|
|
|
m_Show = false;
|
2010-10-11 00:29:30 +00:00
|
|
|
m_InputUpdate = false;
|
|
|
|
m_ChatStringOffset = 0;
|
2010-12-16 01:31:12 +00:00
|
|
|
m_CompletionChosen = -1;
|
|
|
|
m_aCompletionBuffer[0] = 0;
|
|
|
|
m_PlaceholderOffset = 0;
|
|
|
|
m_PlaceholderLength = 0;
|
2011-03-20 15:17:06 +00:00
|
|
|
m_pHistoryEntry = 0x0;
|
2012-01-09 22:13:51 +00:00
|
|
|
m_PendingChatCounter = 0;
|
|
|
|
m_LastChatSend = 0;
|
2012-01-06 18:47:49 +00:00
|
|
|
|
|
|
|
for(int i = 0; i < CHAT_NUM; ++i)
|
2012-01-09 22:13:51 +00:00
|
|
|
m_aLastSoundPlayed[i] = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
|
|
|
|
2010-09-12 10:43:03 +00:00
|
|
|
void CChat::OnRelease()
|
|
|
|
{
|
|
|
|
m_Show = false;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CChat::OnStateChange(int NewState, int OldState)
|
|
|
|
{
|
|
|
|
if(OldState <= IClient::STATE_CONNECTING)
|
|
|
|
{
|
|
|
|
m_Mode = MODE_NONE;
|
2009-05-31 09:44:20 +00:00
|
|
|
for(int i = 0; i < MAX_LINES; i++)
|
2010-05-29 07:25:38 +00:00
|
|
|
m_aLines[i].m_Time = 0;
|
|
|
|
m_CurrentLine = 0;
|
2009-05-31 09:44:20 +00:00
|
|
|
}
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CChat::ConSay(IConsole::IResult *pResult, void *pUserData)
|
2008-08-27 19:41:02 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
((CChat*)pUserData)->Say(0, pResult->GetString(0));
|
2008-08-27 19:41:02 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CChat::ConSayTeam(IConsole::IResult *pResult, void *pUserData)
|
2008-08-27 19:41:02 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
((CChat*)pUserData)->Say(1, pResult->GetString(0));
|
2008-08-27 19:41:02 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CChat::ConChat(IConsole::IResult *pResult, void *pUserData)
|
2008-08-27 19:41:02 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
const char *pMode = pResult->GetString(0);
|
|
|
|
if(str_comp(pMode, "all") == 0)
|
|
|
|
((CChat*)pUserData)->EnableMode(0);
|
|
|
|
else if(str_comp(pMode, "team") == 0)
|
|
|
|
((CChat*)pUserData)->EnableMode(1);
|
2008-08-27 19:41:02 +00:00
|
|
|
else
|
2010-08-17 22:06:00 +00:00
|
|
|
((CChat*)pUserData)->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", "expected all or team as mode");
|
2013-10-13 23:40:42 +00:00
|
|
|
|
|
|
|
((CChat*)pUserData)->m_Input.Set(pResult->GetString(1));
|
2008-08-27 19:41:02 +00:00
|
|
|
}
|
|
|
|
|
2010-05-30 12:01:11 +00:00
|
|
|
void CChat::ConShowChat(IConsole::IResult *pResult, void *pUserData)
|
|
|
|
{
|
|
|
|
((CChat *)pUserData)->m_Show = pResult->GetInteger(0) != 0;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CChat::OnConsoleInit()
|
2008-08-27 19:41:02 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
Console()->Register("say", "r", CFGFLAG_CLIENT, ConSay, this, "Say in chat");
|
|
|
|
Console()->Register("say_team", "r", CFGFLAG_CLIENT, ConSayTeam, this, "Say in team chat");
|
2013-10-13 23:40:42 +00:00
|
|
|
Console()->Register("chat", "s?r", CFGFLAG_CLIENT, ConChat, this, "Enable chat with all/team mode");
|
2010-05-30 12:01:11 +00:00
|
|
|
Console()->Register("+show_chat", "", CFGFLAG_CLIENT, ConShowChat, this, "Show chat");
|
2008-08-27 19:41:02 +00:00
|
|
|
}
|
|
|
|
|
2011-03-20 15:36:10 +00:00
|
|
|
bool CChat::OnInput(IInput::CEvent Event)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_Mode == MODE_NONE)
|
2008-08-27 15:48:50 +00:00
|
|
|
return false;
|
|
|
|
|
2011-03-20 15:36:10 +00:00
|
|
|
if(Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_ESCAPE)
|
2010-09-12 10:43:03 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Mode = MODE_NONE;
|
2010-09-12 10:43:03 +00:00
|
|
|
m_pClient->OnRelease();
|
|
|
|
}
|
2011-03-20 15:36:10 +00:00
|
|
|
else if(Event.m_Flags&IInput::FLAG_PRESS && (Event.m_Key == KEY_RETURN || Event.m_Key == KEY_KP_ENTER))
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_Input.GetString()[0])
|
2011-03-20 15:17:06 +00:00
|
|
|
{
|
2012-04-19 23:09:49 +00:00
|
|
|
bool AddEntry = false;
|
|
|
|
|
2012-01-09 22:13:51 +00:00
|
|
|
if(m_LastChatSend+time_freq() < time_get())
|
2012-04-19 23:09:49 +00:00
|
|
|
{
|
2012-01-09 22:13:51 +00:00
|
|
|
Say(m_Mode == MODE_ALL ? 0 : 1, m_Input.GetString());
|
2012-04-19 23:09:49 +00:00
|
|
|
AddEntry = true;
|
|
|
|
}
|
|
|
|
else if(m_PendingChatCounter < 3)
|
|
|
|
{
|
2012-01-09 22:13:51 +00:00
|
|
|
++m_PendingChatCounter;
|
2012-04-19 23:09:49 +00:00
|
|
|
AddEntry = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(AddEntry)
|
|
|
|
{
|
|
|
|
CHistoryEntry *pEntry = m_History.Allocate(sizeof(CHistoryEntry)+m_Input.GetLength());
|
|
|
|
pEntry->m_Team = m_Mode == MODE_ALL ? 0 : 1;
|
|
|
|
mem_copy(pEntry->m_aText, m_Input.GetString(), m_Input.GetLength()+1);
|
|
|
|
}
|
2011-03-20 15:17:06 +00:00
|
|
|
}
|
|
|
|
m_pHistoryEntry = 0x0;
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Mode = MODE_NONE;
|
2010-09-12 10:43:03 +00:00
|
|
|
m_pClient->OnRelease();
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
2011-03-20 15:36:10 +00:00
|
|
|
if(Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_TAB)
|
2010-12-16 01:31:12 +00:00
|
|
|
{
|
|
|
|
// fill the completion buffer
|
|
|
|
if(m_CompletionChosen < 0)
|
|
|
|
{
|
|
|
|
const char *pCursor = m_Input.GetString()+m_Input.GetCursorOffset();
|
|
|
|
for(int Count = 0; Count < m_Input.GetCursorOffset() && *(pCursor-1) != ' '; --pCursor, ++Count);
|
|
|
|
m_PlaceholderOffset = pCursor-m_Input.GetString();
|
|
|
|
|
|
|
|
for(m_PlaceholderLength = 0; *pCursor && *pCursor != ' '; ++pCursor)
|
|
|
|
++m_PlaceholderLength;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-12-16 01:31:12 +00:00
|
|
|
str_copy(m_aCompletionBuffer, m_Input.GetString()+m_PlaceholderOffset, min(static_cast<int>(sizeof(m_aCompletionBuffer)), m_PlaceholderLength+1));
|
|
|
|
}
|
|
|
|
|
|
|
|
// find next possible name
|
|
|
|
const char *pCompletionString = 0;
|
2011-06-09 21:28:20 +00:00
|
|
|
m_CompletionChosen = (m_CompletionChosen+1)%(2*MAX_CLIENTS);
|
|
|
|
for(int i = 0; i < 2*MAX_CLIENTS; ++i)
|
2010-12-16 01:31:12 +00:00
|
|
|
{
|
2011-06-09 21:28:20 +00:00
|
|
|
int SearchType = ((m_CompletionChosen+i)%(2*MAX_CLIENTS))/MAX_CLIENTS;
|
2010-12-16 01:31:12 +00:00
|
|
|
int Index = (m_CompletionChosen+i)%MAX_CLIENTS;
|
|
|
|
if(!m_pClient->m_Snap.m_paPlayerInfos[Index])
|
|
|
|
continue;
|
|
|
|
|
2011-06-09 21:28:20 +00:00
|
|
|
bool Found = false;
|
|
|
|
if(SearchType == 1)
|
|
|
|
{
|
|
|
|
if(str_comp_nocase_num(m_pClient->m_aClients[Index].m_aName, m_aCompletionBuffer, str_length(m_aCompletionBuffer)) &&
|
|
|
|
str_find_nocase(m_pClient->m_aClients[Index].m_aName, m_aCompletionBuffer))
|
|
|
|
Found = true;
|
|
|
|
}
|
|
|
|
else if(!str_comp_nocase_num(m_pClient->m_aClients[Index].m_aName, m_aCompletionBuffer, str_length(m_aCompletionBuffer)))
|
|
|
|
Found = true;
|
|
|
|
|
|
|
|
if(Found)
|
2010-12-16 01:31:12 +00:00
|
|
|
{
|
|
|
|
pCompletionString = m_pClient->m_aClients[Index].m_aName;
|
2011-06-09 21:28:20 +00:00
|
|
|
m_CompletionChosen = Index+SearchType*MAX_CLIENTS;
|
2010-12-16 01:31:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// insert the name
|
|
|
|
if(pCompletionString)
|
|
|
|
{
|
|
|
|
char aBuf[256];
|
2011-06-09 21:37:59 +00:00
|
|
|
// add part before the name
|
2010-12-16 01:31:12 +00:00
|
|
|
str_copy(aBuf, m_Input.GetString(), min(static_cast<int>(sizeof(aBuf)), m_PlaceholderOffset+1));
|
2011-06-09 21:37:59 +00:00
|
|
|
|
|
|
|
// add the name
|
2010-12-16 01:31:12 +00:00
|
|
|
str_append(aBuf, pCompletionString, sizeof(aBuf));
|
2011-06-09 21:37:59 +00:00
|
|
|
|
|
|
|
// add seperator
|
|
|
|
const char *pSeparator = "";
|
|
|
|
if(*(m_Input.GetString()+m_PlaceholderOffset+m_PlaceholderLength) != ' ')
|
|
|
|
pSeparator = m_PlaceholderOffset == 0 ? ": " : " ";
|
|
|
|
else if(m_PlaceholderOffset == 0)
|
|
|
|
pSeparator = ":";
|
|
|
|
if(*pSeparator)
|
|
|
|
str_append(aBuf, pSeparator, sizeof(aBuf));
|
|
|
|
|
|
|
|
// add part after the name
|
2010-12-16 01:31:12 +00:00
|
|
|
str_append(aBuf, m_Input.GetString()+m_PlaceholderOffset+m_PlaceholderLength, sizeof(aBuf));
|
2011-06-09 21:37:59 +00:00
|
|
|
|
|
|
|
m_PlaceholderLength = str_length(pSeparator)+str_length(pCompletionString);
|
2010-12-16 01:31:12 +00:00
|
|
|
m_OldChatStringLength = m_Input.GetLength();
|
|
|
|
m_Input.Set(aBuf);
|
|
|
|
m_Input.SetCursorOffset(m_PlaceholderOffset+m_PlaceholderLength);
|
|
|
|
m_InputUpdate = true;
|
|
|
|
}
|
|
|
|
}
|
2008-08-27 15:48:50 +00:00
|
|
|
else
|
2010-10-11 00:29:30 +00:00
|
|
|
{
|
2010-12-16 01:31:12 +00:00
|
|
|
// reset name completion process
|
2011-03-20 15:36:10 +00:00
|
|
|
if(Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key != KEY_TAB)
|
2010-12-16 01:31:12 +00:00
|
|
|
m_CompletionChosen = -1;
|
|
|
|
|
2010-10-11 10:31:45 +00:00
|
|
|
m_OldChatStringLength = m_Input.GetLength();
|
2011-03-20 15:36:10 +00:00
|
|
|
m_Input.ProcessInput(Event);
|
2010-10-11 00:29:30 +00:00
|
|
|
m_InputUpdate = true;
|
|
|
|
}
|
2011-03-20 15:36:10 +00:00
|
|
|
if(Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_UP)
|
2011-03-20 15:17:06 +00:00
|
|
|
{
|
2012-01-09 22:13:51 +00:00
|
|
|
if(m_pHistoryEntry)
|
2011-03-20 15:17:06 +00:00
|
|
|
{
|
2012-01-09 22:13:51 +00:00
|
|
|
CHistoryEntry *pTest = m_History.Prev(m_pHistoryEntry);
|
2011-03-20 15:17:06 +00:00
|
|
|
|
2012-01-09 22:13:51 +00:00
|
|
|
if(pTest)
|
2011-03-20 15:17:06 +00:00
|
|
|
m_pHistoryEntry = pTest;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_pHistoryEntry = m_History.Last();
|
|
|
|
|
2012-01-09 22:13:51 +00:00
|
|
|
if(m_pHistoryEntry)
|
|
|
|
m_Input.Set(m_pHistoryEntry->m_aText);
|
2011-03-20 15:17:06 +00:00
|
|
|
}
|
2011-03-20 15:36:10 +00:00
|
|
|
else if (Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_DOWN)
|
2011-03-20 15:17:06 +00:00
|
|
|
{
|
2012-01-09 22:13:51 +00:00
|
|
|
if(m_pHistoryEntry)
|
2011-03-20 15:17:06 +00:00
|
|
|
m_pHistoryEntry = m_History.Next(m_pHistoryEntry);
|
|
|
|
|
|
|
|
if (m_pHistoryEntry)
|
2012-01-09 22:13:51 +00:00
|
|
|
m_Input.Set(m_pHistoryEntry->m_aText);
|
2011-03-20 15:17:06 +00:00
|
|
|
else
|
|
|
|
m_Input.Clear();
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-27 15:48:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CChat::EnableMode(int Team)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-09-07 18:01:51 +00:00
|
|
|
if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
|
|
|
|
return;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_Mode == MODE_NONE)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Team)
|
|
|
|
m_Mode = MODE_TEAM;
|
2008-08-27 15:48:50 +00:00
|
|
|
else
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Mode = MODE_ALL;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Input.Clear();
|
|
|
|
Input()->ClearEvents();
|
2010-12-16 01:31:12 +00:00
|
|
|
m_CompletionChosen = -1;
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CChat::OnMessage(int MsgType, void *pRawMsg)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(MsgType == NETMSGTYPE_SV_CHAT)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CNetMsg_Sv_Chat *pMsg = (CNetMsg_Sv_Chat *)pRawMsg;
|
2011-02-12 10:40:36 +00:00
|
|
|
AddLine(pMsg->m_ClientID, pMsg->m_Team, pMsg->m_pMessage);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-12 10:40:36 +00:00
|
|
|
void CChat::AddLine(int ClientID, int Team, const char *pLine)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2012-06-10 11:07:31 +00:00
|
|
|
if(*pLine == 0 || (ClientID != -1 && (m_pClient->m_aClients[ClientID].m_aName[0] == '\0' || // unknown client
|
2012-01-09 22:29:15 +00:00
|
|
|
m_pClient->m_aClients[ClientID].m_ChatIgnore ||
|
2012-06-10 11:07:31 +00:00
|
|
|
(m_pClient->m_Snap.m_LocalClientID != ClientID && g_Config.m_ClShowChatFriends && !m_pClient->m_aClients[ClientID].m_Friend))))
|
2010-09-06 10:32:41 +00:00
|
|
|
return;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2013-12-27 03:09:45 +00:00
|
|
|
// trim right and set maximum length to 256 utf8-characters
|
2013-04-01 18:30:58 +00:00
|
|
|
int Length = 0;
|
|
|
|
const char *pStr = pLine;
|
|
|
|
const char *pEnd = 0;
|
|
|
|
while(*pStr)
|
|
|
|
{
|
|
|
|
const char *pStrOld = pStr;
|
|
|
|
int Code = str_utf8_decode(&pStr);
|
|
|
|
|
|
|
|
// check if unicode is not empty
|
|
|
|
if(Code > 0x20 && Code != 0xA0 && Code != 0x034F && (Code < 0x2000 || Code > 0x200F) && (Code < 0x2028 || Code > 0x202F) &&
|
|
|
|
(Code < 0x205F || Code > 0x2064) && (Code < 0x206A || Code > 0x206F) && (Code < 0xFE00 || Code > 0xFE0F) &&
|
|
|
|
Code != 0xFEFF && (Code < 0xFFF9 || Code > 0xFFFC))
|
|
|
|
{
|
|
|
|
pEnd = 0;
|
|
|
|
}
|
|
|
|
else if(pEnd == 0)
|
|
|
|
pEnd = pStrOld;
|
|
|
|
|
2013-12-27 03:09:45 +00:00
|
|
|
if(++Length >= 256)
|
2013-04-01 18:30:58 +00:00
|
|
|
{
|
|
|
|
*(const_cast<char *>(pStr)) = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(pEnd != 0)
|
|
|
|
*(const_cast<char *>(pEnd)) = 0;
|
|
|
|
|
2011-03-20 14:58:59 +00:00
|
|
|
bool Highlighted = false;
|
2010-05-29 07:25:38 +00:00
|
|
|
char *p = const_cast<char*>(pLine);
|
|
|
|
while(*p)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2011-06-09 21:49:06 +00:00
|
|
|
Highlighted = false;
|
2010-05-29 07:25:38 +00:00
|
|
|
pLine = p;
|
|
|
|
// find line seperator and strip multiline
|
|
|
|
while(*p)
|
|
|
|
{
|
|
|
|
if(*p++ == '\n')
|
|
|
|
{
|
|
|
|
*(p-1) = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_CurrentLine = (m_CurrentLine+1)%MAX_LINES;
|
|
|
|
m_aLines[m_CurrentLine].m_Time = time_get();
|
2010-10-15 17:26:20 +00:00
|
|
|
m_aLines[m_CurrentLine].m_YOffset[0] = -1.0f;
|
|
|
|
m_aLines[m_CurrentLine].m_YOffset[1] = -1.0f;
|
2011-02-12 10:40:36 +00:00
|
|
|
m_aLines[m_CurrentLine].m_ClientID = ClientID;
|
2010-05-29 07:25:38 +00:00
|
|
|
m_aLines[m_CurrentLine].m_Team = Team;
|
|
|
|
m_aLines[m_CurrentLine].m_NameColor = -2;
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2011-06-09 21:49:06 +00:00
|
|
|
// check for highlighted name
|
|
|
|
const char *pHL = str_find_nocase(pLine, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_aName);
|
|
|
|
if(pHL)
|
|
|
|
{
|
|
|
|
int Length = str_length(m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_aName);
|
2013-12-27 20:39:46 +00:00
|
|
|
if((pLine == pHL || pHL[-1] == ' ') && (pHL[Length] == 0 || pHL[Length] == ' ' || pHL[Length] == '.' || pHL[Length] == '!' || pHL[Length] == ',' || pHL[Length] == '?' || pHL[Length] == ':'))
|
2011-06-09 21:49:06 +00:00
|
|
|
Highlighted = true;
|
|
|
|
}
|
|
|
|
m_aLines[m_CurrentLine].m_Highlighted = Highlighted;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2011-02-12 10:40:36 +00:00
|
|
|
if(ClientID == -1) // server message
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
|
|
|
str_copy(m_aLines[m_CurrentLine].m_aName, "*** ", sizeof(m_aLines[m_CurrentLine].m_aName));
|
|
|
|
str_format(m_aLines[m_CurrentLine].m_aText, sizeof(m_aLines[m_CurrentLine].m_aText), "%s", pLine);
|
|
|
|
}
|
|
|
|
else
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2011-02-12 10:40:36 +00:00
|
|
|
if(m_pClient->m_aClients[ClientID].m_Team == TEAM_SPECTATORS)
|
2011-01-03 11:50:38 +00:00
|
|
|
m_aLines[m_CurrentLine].m_NameColor = TEAM_SPECTATORS;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2011-03-04 16:08:10 +00:00
|
|
|
if(m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags&GAMEFLAG_TEAMS)
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
2011-02-12 10:40:36 +00:00
|
|
|
if(m_pClient->m_aClients[ClientID].m_Team == TEAM_RED)
|
2011-01-03 11:50:38 +00:00
|
|
|
m_aLines[m_CurrentLine].m_NameColor = TEAM_RED;
|
2011-02-12 10:40:36 +00:00
|
|
|
else if(m_pClient->m_aClients[ClientID].m_Team == TEAM_BLUE)
|
2011-01-03 11:50:38 +00:00
|
|
|
m_aLines[m_CurrentLine].m_NameColor = TEAM_BLUE;
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2014-01-30 15:49:15 +00:00
|
|
|
if (Team == 2) // whisper send
|
|
|
|
{
|
|
|
|
str_format(m_aLines[m_CurrentLine].m_aName, sizeof(m_aLines[m_CurrentLine].m_aName), "→ %s", m_pClient->m_aClients[ClientID].m_aName);
|
|
|
|
m_aLines[m_CurrentLine].m_NameColor = TEAM_BLUE;
|
|
|
|
m_aLines[m_CurrentLine].m_Highlighted = false;
|
|
|
|
m_aLines[m_CurrentLine].m_Team = 0;
|
|
|
|
Highlighted = false;
|
|
|
|
}
|
|
|
|
else if (Team == 3) // whisper recv
|
|
|
|
{
|
|
|
|
str_format(m_aLines[m_CurrentLine].m_aName, sizeof(m_aLines[m_CurrentLine].m_aName), "← %s", m_pClient->m_aClients[ClientID].m_aName);
|
|
|
|
m_aLines[m_CurrentLine].m_NameColor = TEAM_RED;
|
|
|
|
m_aLines[m_CurrentLine].m_Highlighted = true;
|
|
|
|
m_aLines[m_CurrentLine].m_Team = 0;
|
|
|
|
Highlighted = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
str_copy(m_aLines[m_CurrentLine].m_aName, m_pClient->m_aClients[ClientID].m_aName, sizeof(m_aLines[m_CurrentLine].m_aName));
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
str_format(m_aLines[m_CurrentLine].m_aText, sizeof(m_aLines[m_CurrentLine].m_aText), ": %s", pLine);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
char aBuf[1024];
|
2010-08-17 22:06:00 +00:00
|
|
|
str_format(aBuf, sizeof(aBuf), "%s%s", m_aLines[m_CurrentLine].m_aName, m_aLines[m_CurrentLine].m_aText);
|
2014-01-30 15:49:15 +00:00
|
|
|
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, Team >= 2?"whisper":(m_aLines[m_CurrentLine].m_Team?"teamchat":"chat"), aBuf);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2009-06-15 13:01:04 +00:00
|
|
|
// play sound
|
2012-01-06 18:47:49 +00:00
|
|
|
int64 Now = time_get();
|
2011-03-21 23:34:07 +00:00
|
|
|
if(ClientID == -1)
|
2012-01-06 18:47:49 +00:00
|
|
|
{
|
2013-12-30 18:32:51 +00:00
|
|
|
if(Now-m_aLastSoundPlayed[CHAT_SERVER] >= time_freq()*3/10)
|
2012-01-06 18:47:49 +00:00
|
|
|
{
|
|
|
|
m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_SERVER, 0);
|
|
|
|
m_aLastSoundPlayed[CHAT_SERVER] = Now;
|
|
|
|
}
|
|
|
|
}
|
2011-03-21 23:34:07 +00:00
|
|
|
else if(Highlighted)
|
2012-01-06 18:47:49 +00:00
|
|
|
{
|
|
|
|
if(Now-m_aLastSoundPlayed[CHAT_HIGHLIGHT] >= time_freq()*3/10)
|
|
|
|
{
|
2013-12-30 18:32:51 +00:00
|
|
|
m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_HIGHLIGHT, 0);
|
2012-01-06 18:47:49 +00:00
|
|
|
m_aLastSoundPlayed[CHAT_HIGHLIGHT] = Now;
|
|
|
|
}
|
|
|
|
}
|
2014-02-06 17:17:29 +00:00
|
|
|
else if(Team != 2)
|
2012-01-06 18:47:49 +00:00
|
|
|
{
|
|
|
|
if(Now-m_aLastSoundPlayed[CHAT_CLIENT] >= time_freq()*3/10)
|
|
|
|
{
|
2012-06-10 11:30:25 +00:00
|
|
|
m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_CLIENT, 0);
|
2012-01-06 18:47:49 +00:00
|
|
|
m_aLastSoundPlayed[CHAT_CLIENT] = Now;
|
|
|
|
}
|
|
|
|
}
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CChat::OnRender()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2013-11-14 15:23:15 +00:00
|
|
|
if (!g_Config.m_ClShowChat)
|
|
|
|
return;
|
|
|
|
|
2012-01-09 22:13:51 +00:00
|
|
|
// send pending chat messages
|
|
|
|
if(m_PendingChatCounter > 0 && m_LastChatSend+time_freq() < time_get())
|
|
|
|
{
|
|
|
|
CHistoryEntry *pEntry = m_History.Last();
|
|
|
|
for(int i = m_PendingChatCounter-1; pEntry; --i, pEntry = m_History.Prev(pEntry))
|
|
|
|
{
|
|
|
|
if(i == 0)
|
|
|
|
{
|
|
|
|
Say(pEntry->m_Team, pEntry->m_aText);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--m_PendingChatCounter;
|
|
|
|
}
|
|
|
|
|
2011-03-27 21:43:45 +00:00
|
|
|
float Width = 300.0f*Graphics()->ScreenAspect();
|
|
|
|
Graphics()->MapScreen(0.0f, 0.0f, Width, 300.0f);
|
2011-03-19 17:28:47 +00:00
|
|
|
float x = 5.0f;
|
2008-09-07 08:44:30 +00:00
|
|
|
float y = 300.0f-20.0f;
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_Mode != MODE_NONE)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
|
|
|
// render chat input
|
2010-05-29 07:25:38 +00:00
|
|
|
CTextCursor Cursor;
|
|
|
|
TextRender()->SetCursor(&Cursor, x, y, 8.0f, TEXTFLAG_RENDER);
|
2011-03-27 21:43:45 +00:00
|
|
|
Cursor.m_LineWidth = Width-190.0f;
|
2010-10-11 00:29:30 +00:00
|
|
|
Cursor.m_MaxLines = 2;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_Mode == MODE_ALL)
|
|
|
|
TextRender()->TextEx(&Cursor, Localize("All"), -1);
|
|
|
|
else if(m_Mode == MODE_TEAM)
|
|
|
|
TextRender()->TextEx(&Cursor, Localize("Team"), -1);
|
2008-08-27 15:48:50 +00:00
|
|
|
else
|
2010-05-29 07:25:38 +00:00
|
|
|
TextRender()->TextEx(&Cursor, Localize("Chat"), -1);
|
2009-06-15 07:34:25 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
TextRender()->TextEx(&Cursor, ": ", -1);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-10-11 00:29:30 +00:00
|
|
|
// check if the visible text has to be moved
|
|
|
|
if(m_InputUpdate)
|
|
|
|
{
|
2010-10-11 10:31:45 +00:00
|
|
|
if(m_ChatStringOffset > 0 && m_Input.GetLength() < m_OldChatStringLength)
|
|
|
|
m_ChatStringOffset = max(0, m_ChatStringOffset-(m_OldChatStringLength-m_Input.GetLength()));
|
|
|
|
|
2010-10-11 00:29:30 +00:00
|
|
|
if(m_ChatStringOffset > m_Input.GetCursorOffset())
|
2010-10-11 10:31:45 +00:00
|
|
|
m_ChatStringOffset -= m_ChatStringOffset-m_Input.GetCursorOffset();
|
2010-10-11 00:29:30 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
CTextCursor Temp = Cursor;
|
|
|
|
Temp.m_Flags = 0;
|
|
|
|
TextRender()->TextEx(&Temp, m_Input.GetString()+m_ChatStringOffset, m_Input.GetCursorOffset()-m_ChatStringOffset);
|
|
|
|
TextRender()->TextEx(&Temp, "|", -1);
|
2010-10-11 10:31:45 +00:00
|
|
|
while(Temp.m_LineCount > 2)
|
|
|
|
{
|
2010-10-11 00:29:30 +00:00
|
|
|
++m_ChatStringOffset;
|
2010-10-11 10:31:45 +00:00
|
|
|
Temp = Cursor;
|
|
|
|
Temp.m_Flags = 0;
|
|
|
|
TextRender()->TextEx(&Temp, m_Input.GetString()+m_ChatStringOffset, m_Input.GetCursorOffset()-m_ChatStringOffset);
|
|
|
|
TextRender()->TextEx(&Temp, "|", -1);
|
|
|
|
}
|
2010-10-11 00:29:30 +00:00
|
|
|
}
|
2010-10-11 10:31:45 +00:00
|
|
|
m_InputUpdate = false;
|
2010-10-11 00:29:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TextRender()->TextEx(&Cursor, m_Input.GetString()+m_ChatStringOffset, m_Input.GetCursorOffset()-m_ChatStringOffset);
|
2011-06-09 21:54:11 +00:00
|
|
|
static float MarkerOffset = TextRender()->TextWidth(0, 8.0f, "|", -1)/3;
|
2010-05-29 07:25:38 +00:00
|
|
|
CTextCursor Marker = Cursor;
|
2011-06-09 21:54:11 +00:00
|
|
|
Marker.m_X -= MarkerOffset;
|
2010-05-29 07:25:38 +00:00
|
|
|
TextRender()->TextEx(&Marker, "|", -1);
|
|
|
|
TextRender()->TextEx(&Cursor, m_Input.GetString()+m_Input.GetCursorOffset(), -1);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
2010-08-16 00:21:18 +00:00
|
|
|
y -= 8.0f;
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int64 Now = time_get();
|
2011-03-19 17:28:47 +00:00
|
|
|
float LineWidth = m_pClient->m_pScoreboard->Active() ? 90.0f : 200.0f;
|
|
|
|
float HeightLimit = m_pClient->m_pScoreboard->Active() ? 230.0f : m_Show ? 50.0f : 200.0f;
|
2010-10-15 17:26:20 +00:00
|
|
|
float Begin = x;
|
|
|
|
float FontSize = 6.0f;
|
|
|
|
CTextCursor Cursor;
|
|
|
|
int OffsetType = m_pClient->m_pScoreboard->Active() ? 1 : 0;
|
2010-08-18 01:57:35 +00:00
|
|
|
for(int i = 0; i < MAX_LINES; i++)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
int r = ((m_CurrentLine-i)+MAX_LINES)%MAX_LINES;
|
2010-12-16 03:20:50 +00:00
|
|
|
if(Now > m_aLines[r].m_Time+16*time_freq() && !m_Show)
|
2008-08-27 15:48:50 +00:00
|
|
|
break;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-10-15 17:26:20 +00:00
|
|
|
// get the y offset (calculate it if we haven't done that yet)
|
|
|
|
if(m_aLines[r].m_YOffset[OffsetType] < 0.0f)
|
|
|
|
{
|
|
|
|
TextRender()->SetCursor(&Cursor, Begin, 0.0f, FontSize, 0);
|
|
|
|
Cursor.m_LineWidth = LineWidth;
|
|
|
|
TextRender()->TextEx(&Cursor, m_aLines[r].m_aName, -1);
|
|
|
|
TextRender()->TextEx(&Cursor, m_aLines[r].m_aText, -1);
|
|
|
|
m_aLines[r].m_YOffset[OffsetType] = Cursor.m_Y + Cursor.m_FontSize;
|
|
|
|
}
|
|
|
|
y -= m_aLines[r].m_YOffset[OffsetType];
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2008-09-07 08:44:30 +00:00
|
|
|
// cut off if msgs waste too much space
|
2010-05-30 12:01:11 +00:00
|
|
|
if(y < HeightLimit)
|
2008-09-07 08:44:30 +00:00
|
|
|
break;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-12-16 03:20:50 +00:00
|
|
|
float Blend = Now > m_aLines[r].m_Time+14*time_freq() && !m_Show ? 1.0f-(Now-m_aLines[r].m_Time-14*time_freq())/(2.0f*time_freq()) : 1.0f;
|
|
|
|
|
2008-08-27 15:48:50 +00:00
|
|
|
// reset the cursor
|
2010-05-29 07:25:38 +00:00
|
|
|
TextRender()->SetCursor(&Cursor, Begin, y, FontSize, TEXTFLAG_RENDER);
|
2010-08-18 01:57:35 +00:00
|
|
|
Cursor.m_LineWidth = LineWidth;
|
2008-08-27 15:48:50 +00:00
|
|
|
|
|
|
|
// render name
|
2011-02-12 10:40:36 +00:00
|
|
|
if(m_aLines[r].m_ClientID == -1)
|
2010-12-16 03:20:50 +00:00
|
|
|
TextRender()->TextColor(1.0f, 1.0f, 0.5f, Blend); // system
|
2010-05-29 07:25:38 +00:00
|
|
|
else if(m_aLines[r].m_Team)
|
2010-12-16 03:20:50 +00:00
|
|
|
TextRender()->TextColor(0.45f, 0.9f, 0.45f, Blend); // team message
|
2011-01-03 11:50:38 +00:00
|
|
|
else if(m_aLines[r].m_NameColor == TEAM_RED)
|
2010-12-16 03:20:50 +00:00
|
|
|
TextRender()->TextColor(1.0f, 0.5f, 0.5f, Blend); // red
|
2011-01-03 11:50:38 +00:00
|
|
|
else if(m_aLines[r].m_NameColor == TEAM_BLUE)
|
2010-12-16 03:20:50 +00:00
|
|
|
TextRender()->TextColor(0.7f, 0.7f, 1.0f, Blend); // blue
|
2011-01-03 11:50:38 +00:00
|
|
|
else if(m_aLines[r].m_NameColor == TEAM_SPECTATORS)
|
2010-12-16 03:20:50 +00:00
|
|
|
TextRender()->TextColor(0.75f, 0.5f, 0.75f, Blend); // spectator
|
2014-04-14 22:49:24 +00:00
|
|
|
else if(m_aLines[r].m_ClientID >= 0 && m_pClient->m_Teams.Team(m_aLines[r].m_ClientID))
|
|
|
|
{
|
|
|
|
vec3 rgb = HslToRgb(vec3(m_pClient->m_Teams.Team(m_aLines[r].m_ClientID) / 64.0f, 1.0f, 0.75f));
|
|
|
|
TextRender()->TextColor(rgb.r, rgb.g, rgb.b, Blend);
|
|
|
|
}
|
2010-10-15 17:26:20 +00:00
|
|
|
else
|
2010-12-16 03:20:50 +00:00
|
|
|
TextRender()->TextColor(0.8f, 0.8f, 0.8f, Blend);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
TextRender()->TextEx(&Cursor, m_aLines[r].m_aName, -1);
|
2008-08-27 15:48:50 +00:00
|
|
|
|
|
|
|
// render line
|
2011-02-12 10:40:36 +00:00
|
|
|
if(m_aLines[r].m_ClientID == -1)
|
2010-12-16 03:20:50 +00:00
|
|
|
TextRender()->TextColor(1.0f, 1.0f, 0.5f, Blend); // system
|
2010-12-16 01:31:12 +00:00
|
|
|
else if(m_aLines[r].m_Highlighted)
|
2010-12-16 03:20:50 +00:00
|
|
|
TextRender()->TextColor(1.0f, 0.5f, 0.5f, Blend); // highlighted
|
2010-05-29 07:25:38 +00:00
|
|
|
else if(m_aLines[r].m_Team)
|
2010-12-16 03:20:50 +00:00
|
|
|
TextRender()->TextColor(0.65f, 1.0f, 0.65f, Blend); // team message
|
2010-10-15 17:26:20 +00:00
|
|
|
else
|
2010-12-16 03:20:50 +00:00
|
|
|
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Blend);
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
TextRender()->TextEx(&Cursor, m_aLines[r].m_aText, -1);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
2010-10-15 17:26:20 +00:00
|
|
|
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CChat::Say(int Team, const char *pLine)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2012-01-09 22:13:51 +00:00
|
|
|
m_LastChatSend = time_get();
|
|
|
|
|
2008-08-27 15:48:50 +00:00
|
|
|
// send chat message
|
2010-05-29 07:25:38 +00:00
|
|
|
CNetMsg_Cl_Say Msg;
|
|
|
|
Msg.m_Team = Team;
|
|
|
|
Msg.m_pMessage = pLine;
|
|
|
|
Client()->SendPackMsg(&Msg, MSGFLAG_VITAL);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|