mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 22:18:19 +00:00
Merge pull request #8315 from ChillerDragon/pr_chat_cleanup
Rename chat `Say()` to `SendChat()`
This commit is contained in:
commit
c727b87601
|
@ -32,7 +32,7 @@ CChat::CChat()
|
|||
|
||||
m_Mode = MODE_NONE;
|
||||
|
||||
m_Input.SetClipboardLineCallback([this](const char *pStr) { SayChat(pStr); });
|
||||
m_Input.SetClipboardLineCallback([this](const char *pStr) { SendChatQueued(pStr); });
|
||||
m_Input.SetCalculateOffsetCallback([this]() { return m_IsInputCensored; });
|
||||
m_Input.SetDisplayTextCallback([this](char *pStr, size_t NumChars) {
|
||||
m_IsInputCensored = false;
|
||||
|
@ -150,12 +150,12 @@ void CChat::OnStateChange(int NewState, int OldState)
|
|||
|
||||
void CChat::ConSay(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
((CChat *)pUserData)->Say(0, pResult->GetString(0));
|
||||
((CChat *)pUserData)->SendChat(0, pResult->GetString(0));
|
||||
}
|
||||
|
||||
void CChat::ConSayTeam(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
((CChat *)pUserData)->Say(1, pResult->GetString(0));
|
||||
((CChat *)pUserData)->SendChat(1, pResult->GetString(0));
|
||||
}
|
||||
|
||||
void CChat::ConChat(IConsole::IResult *pResult, void *pUserData)
|
||||
|
@ -249,28 +249,7 @@ bool CChat::OnInput(const IInput::CEvent &Event)
|
|||
m_CommandsNeedSorting = false;
|
||||
}
|
||||
|
||||
if(m_Input.GetString()[0])
|
||||
{
|
||||
bool AddEntry = false;
|
||||
|
||||
if(m_LastChatSend + time_freq() < time())
|
||||
{
|
||||
Say(m_Mode == MODE_ALL ? 0 : 1, m_Input.GetString());
|
||||
AddEntry = true;
|
||||
}
|
||||
else if(m_PendingChatCounter < 3)
|
||||
{
|
||||
++m_PendingChatCounter;
|
||||
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);
|
||||
}
|
||||
}
|
||||
SendChatQueued(m_Input.GetString());
|
||||
m_pHistoryEntry = nullptr;
|
||||
DisableMode();
|
||||
m_pClient->OnRelease();
|
||||
|
@ -1177,7 +1156,7 @@ void CChat::OnRender()
|
|||
{
|
||||
if(i == 0)
|
||||
{
|
||||
Say(pEntry->m_Team, pEntry->m_aText);
|
||||
SendChat(pEntry->m_Team, pEntry->m_aText);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1324,47 +1303,6 @@ void CChat::OnRender()
|
|||
}
|
||||
}
|
||||
|
||||
void CChat::Say(int Team, const char *pLine)
|
||||
{
|
||||
// don't send empty messages
|
||||
if(*str_utf8_skip_whitespaces(pLine) == '\0')
|
||||
return;
|
||||
|
||||
m_LastChatSend = time();
|
||||
|
||||
// send chat message
|
||||
CNetMsg_Cl_Say Msg;
|
||||
Msg.m_Team = Team;
|
||||
Msg.m_pMessage = pLine;
|
||||
Client()->SendPackMsgActive(&Msg, MSGFLAG_VITAL);
|
||||
}
|
||||
|
||||
void CChat::SayChat(const char *pLine)
|
||||
{
|
||||
if(!pLine || str_length(pLine) < 1)
|
||||
return;
|
||||
|
||||
bool AddEntry = false;
|
||||
|
||||
if(m_LastChatSend + time_freq() < time())
|
||||
{
|
||||
Say(m_Mode == MODE_ALL ? 0 : 1, pLine);
|
||||
AddEntry = true;
|
||||
}
|
||||
else if(m_PendingChatCounter < 3)
|
||||
{
|
||||
++m_PendingChatCounter;
|
||||
AddEntry = true;
|
||||
}
|
||||
|
||||
if(AddEntry)
|
||||
{
|
||||
CHistoryEntry *pEntry = m_History.Allocate(sizeof(CHistoryEntry) + str_length(pLine) - 1);
|
||||
pEntry->m_Team = m_Mode == MODE_ALL ? 0 : 1;
|
||||
mem_copy(pEntry->m_aText, pLine, str_length(pLine));
|
||||
}
|
||||
}
|
||||
|
||||
void CChat::EnsureCoherentFontSize() const
|
||||
{
|
||||
// Adjust font size based on width
|
||||
|
@ -1384,3 +1322,46 @@ void CChat::EnsureCoherentWidth() const
|
|||
// We want to keep a ration between font size and font width so that we don't have a weird rendering
|
||||
g_Config.m_ClChatWidth = CHAT_FONTSIZE_WIDTH_RATIO * g_Config.m_ClChatFontSize;
|
||||
}
|
||||
|
||||
// ----- send functions -----
|
||||
|
||||
void CChat::SendChat(int Team, const char *pLine)
|
||||
{
|
||||
// don't send empty messages
|
||||
if(*str_utf8_skip_whitespaces(pLine) == '\0')
|
||||
return;
|
||||
|
||||
m_LastChatSend = time();
|
||||
|
||||
// send chat message
|
||||
CNetMsg_Cl_Say Msg;
|
||||
Msg.m_Team = Team;
|
||||
Msg.m_pMessage = pLine;
|
||||
Client()->SendPackMsgActive(&Msg, MSGFLAG_VITAL);
|
||||
}
|
||||
|
||||
void CChat::SendChatQueued(const char *pLine)
|
||||
{
|
||||
if(!pLine || str_length(pLine) < 1)
|
||||
return;
|
||||
|
||||
bool AddEntry = false;
|
||||
|
||||
if(m_LastChatSend + time_freq() < time())
|
||||
{
|
||||
SendChat(m_Mode == MODE_ALL ? 0 : 1, pLine);
|
||||
AddEntry = true;
|
||||
}
|
||||
else if(m_PendingChatCounter < 3)
|
||||
{
|
||||
++m_PendingChatCounter;
|
||||
AddEntry = true;
|
||||
}
|
||||
|
||||
if(AddEntry)
|
||||
{
|
||||
CHistoryEntry *pEntry = m_History.Allocate(sizeof(CHistoryEntry) + str_length(pLine) - 1);
|
||||
pEntry->m_Team = m_Mode == MODE_ALL ? 0 : 1;
|
||||
mem_copy(pEntry->m_aText, pLine, str_length(pLine));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,8 +155,6 @@ public:
|
|||
void AddLine(int ClientId, int Team, const char *pLine);
|
||||
void EnableMode(int Team);
|
||||
void DisableMode();
|
||||
void Say(int Team, const char *pLine);
|
||||
void SayChat(const char *pLine);
|
||||
void RegisterCommand(const char *pName, const char *pParams, const char *pHelpText);
|
||||
void UnregisterCommand(const char *pName);
|
||||
void Echo(const char *pString);
|
||||
|
@ -183,5 +181,22 @@ public:
|
|||
float MessagePaddingY() const { return FontSize() * (1 / 6.f); }
|
||||
float MessageTeeSize() const { return FontSize() * (7 / 6.f); }
|
||||
float MessageRounding() const { return FontSize() * (1 / 2.f); }
|
||||
|
||||
// ----- send functions -----
|
||||
|
||||
// Sends a chat message to the server.
|
||||
//
|
||||
// @param Team MODE_ALL=0 MODE_TEAM=1
|
||||
// @param pLine the chat message
|
||||
void SendChat(int Team, const char *pLine);
|
||||
|
||||
// Sends a chat message to the server.
|
||||
//
|
||||
// It uses a queue with a maximum of 3 entries
|
||||
// that ensures there is a minimum delay of one second
|
||||
// between sent messages.
|
||||
//
|
||||
// It uses team or public chat depending on m_Mode.
|
||||
void SendChatQueued(const char *pLine);
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -203,5 +203,5 @@ void CEmoticon::EyeEmote(int Emote)
|
|||
str_format(aBuf, sizeof(aBuf), "/emote blink %d", g_Config.m_ClEyeDuration);
|
||||
break;
|
||||
}
|
||||
GameClient()->m_Chat.Say(0, aBuf);
|
||||
GameClient()->m_Chat.SendChat(0, aBuf);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue