mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Rename CChat::SayChat
to CChat::SendChatQueued
Also replace one code snippet with a call to SendChatQueued
This commit is contained in:
parent
33baeb8f28
commit
44d065888f
|
@ -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;
|
||||
|
@ -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())
|
||||
{
|
||||
SendChat(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();
|
||||
|
@ -1324,6 +1303,28 @@ void CChat::OnRender()
|
|||
}
|
||||
}
|
||||
|
||||
void CChat::EnsureCoherentFontSize() const
|
||||
{
|
||||
// Adjust font size based on width
|
||||
if(g_Config.m_ClChatWidth / (float)g_Config.m_ClChatFontSize >= CHAT_FONTSIZE_WIDTH_RATIO)
|
||||
return;
|
||||
|
||||
// We want to keep a ration between font size and font width so that we don't have a weird rendering
|
||||
g_Config.m_ClChatFontSize = g_Config.m_ClChatWidth / CHAT_FONTSIZE_WIDTH_RATIO;
|
||||
}
|
||||
|
||||
void CChat::EnsureCoherentWidth() const
|
||||
{
|
||||
// Adjust width based on font size
|
||||
if(g_Config.m_ClChatWidth / (float)g_Config.m_ClChatFontSize >= CHAT_FONTSIZE_WIDTH_RATIO)
|
||||
return;
|
||||
|
||||
// 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
|
||||
|
@ -1339,7 +1340,7 @@ void CChat::SendChat(int Team, const char *pLine)
|
|||
Client()->SendPackMsgActive(&Msg, MSGFLAG_VITAL);
|
||||
}
|
||||
|
||||
void CChat::SayChat(const char *pLine)
|
||||
void CChat::SendChatQueued(const char *pLine)
|
||||
{
|
||||
if(!pLine || str_length(pLine) < 1)
|
||||
return;
|
||||
|
@ -1364,23 +1365,3 @@ void CChat::SayChat(const char *pLine)
|
|||
mem_copy(pEntry->m_aText, pLine, str_length(pLine));
|
||||
}
|
||||
}
|
||||
|
||||
void CChat::EnsureCoherentFontSize() const
|
||||
{
|
||||
// Adjust font size based on width
|
||||
if(g_Config.m_ClChatWidth / (float)g_Config.m_ClChatFontSize >= CHAT_FONTSIZE_WIDTH_RATIO)
|
||||
return;
|
||||
|
||||
// We want to keep a ration between font size and font width so that we don't have a weird rendering
|
||||
g_Config.m_ClChatFontSize = g_Config.m_ClChatWidth / CHAT_FONTSIZE_WIDTH_RATIO;
|
||||
}
|
||||
|
||||
void CChat::EnsureCoherentWidth() const
|
||||
{
|
||||
// Adjust width based on font size
|
||||
if(g_Config.m_ClChatWidth / (float)g_Config.m_ClChatFontSize >= CHAT_FONTSIZE_WIDTH_RATIO)
|
||||
return;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
|
|
@ -155,8 +155,6 @@ public:
|
|||
void AddLine(int ClientId, int Team, const char *pLine);
|
||||
void EnableMode(int Team);
|
||||
void DisableMode();
|
||||
void SendChat(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
|
||||
|
|
Loading…
Reference in a new issue