mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
buffered chat input. Closes #916
This commit is contained in:
parent
0b0f8e2f1c
commit
e97cfaecad
|
@ -41,9 +41,11 @@ void CChat::OnReset()
|
||||||
m_PlaceholderOffset = 0;
|
m_PlaceholderOffset = 0;
|
||||||
m_PlaceholderLength = 0;
|
m_PlaceholderLength = 0;
|
||||||
m_pHistoryEntry = 0x0;
|
m_pHistoryEntry = 0x0;
|
||||||
|
m_PendingChatCounter = 0;
|
||||||
|
m_LastChatSend = 0;
|
||||||
|
|
||||||
for(int i = 0; i < CHAT_NUM; ++i)
|
for(int i = 0; i < CHAT_NUM; ++i)
|
||||||
m_aLastSoundPlayed[i] = -1;
|
m_aLastSoundPlayed[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CChat::OnRelease()
|
void CChat::OnRelease()
|
||||||
|
@ -110,9 +112,13 @@ bool CChat::OnInput(IInput::CEvent Event)
|
||||||
{
|
{
|
||||||
if(m_Input.GetString()[0])
|
if(m_Input.GetString()[0])
|
||||||
{
|
{
|
||||||
Say(m_Mode == MODE_ALL ? 0 : 1, m_Input.GetString());
|
if(m_LastChatSend+time_freq() < time_get())
|
||||||
char *pEntry = m_History.Allocate(m_Input.GetLength()+1);
|
Say(m_Mode == MODE_ALL ? 0 : 1, m_Input.GetString());
|
||||||
mem_copy(pEntry, m_Input.GetString(), m_Input.GetLength()+1);
|
else
|
||||||
|
++m_PendingChatCounter;
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
m_pHistoryEntry = 0x0;
|
m_pHistoryEntry = 0x0;
|
||||||
m_Mode = MODE_NONE;
|
m_Mode = MODE_NONE;
|
||||||
|
@ -202,26 +208,26 @@ bool CChat::OnInput(IInput::CEvent Event)
|
||||||
}
|
}
|
||||||
if(Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_UP)
|
if(Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_UP)
|
||||||
{
|
{
|
||||||
if (m_pHistoryEntry)
|
if(m_pHistoryEntry)
|
||||||
{
|
{
|
||||||
char *pTest = m_History.Prev(m_pHistoryEntry);
|
CHistoryEntry *pTest = m_History.Prev(m_pHistoryEntry);
|
||||||
|
|
||||||
if (pTest)
|
if(pTest)
|
||||||
m_pHistoryEntry = pTest;
|
m_pHistoryEntry = pTest;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_pHistoryEntry = m_History.Last();
|
m_pHistoryEntry = m_History.Last();
|
||||||
|
|
||||||
if (m_pHistoryEntry)
|
if(m_pHistoryEntry)
|
||||||
m_Input.Set(m_pHistoryEntry);
|
m_Input.Set(m_pHistoryEntry->m_aText);
|
||||||
}
|
}
|
||||||
else if (Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_DOWN)
|
else if (Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_DOWN)
|
||||||
{
|
{
|
||||||
if (m_pHistoryEntry)
|
if(m_pHistoryEntry)
|
||||||
m_pHistoryEntry = m_History.Next(m_pHistoryEntry);
|
m_pHistoryEntry = m_History.Next(m_pHistoryEntry);
|
||||||
|
|
||||||
if (m_pHistoryEntry)
|
if (m_pHistoryEntry)
|
||||||
m_Input.Set(m_pHistoryEntry);
|
m_Input.Set(m_pHistoryEntry->m_aText);
|
||||||
else
|
else
|
||||||
m_Input.Clear();
|
m_Input.Clear();
|
||||||
}
|
}
|
||||||
|
@ -354,6 +360,21 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine)
|
||||||
|
|
||||||
void CChat::OnRender()
|
void CChat::OnRender()
|
||||||
{
|
{
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
float Width = 300.0f*Graphics()->ScreenAspect();
|
float Width = 300.0f*Graphics()->ScreenAspect();
|
||||||
Graphics()->MapScreen(0.0f, 0.0f, Width, 300.0f);
|
Graphics()->MapScreen(0.0f, 0.0f, Width, 300.0f);
|
||||||
float x = 5.0f;
|
float x = 5.0f;
|
||||||
|
@ -479,6 +500,8 @@ void CChat::OnRender()
|
||||||
|
|
||||||
void CChat::Say(int Team, const char *pLine)
|
void CChat::Say(int Team, const char *pLine)
|
||||||
{
|
{
|
||||||
|
m_LastChatSend = time_get();
|
||||||
|
|
||||||
// send chat message
|
// send chat message
|
||||||
CNetMsg_Cl_Say Msg;
|
CNetMsg_Cl_Say Msg;
|
||||||
Msg.m_Team = Team;
|
Msg.m_Team = Team;
|
||||||
|
|
|
@ -52,8 +52,16 @@ class CChat : public CComponent
|
||||||
char m_aCompletionBuffer[256];
|
char m_aCompletionBuffer[256];
|
||||||
int m_PlaceholderOffset;
|
int m_PlaceholderOffset;
|
||||||
int m_PlaceholderLength;
|
int m_PlaceholderLength;
|
||||||
char *m_pHistoryEntry;
|
|
||||||
TStaticRingBuffer<char, 64*1024, CRingBufferBase::FLAG_RECYCLE> m_History;
|
struct CHistoryEntry
|
||||||
|
{
|
||||||
|
int m_Team;
|
||||||
|
char m_aText[1];
|
||||||
|
};
|
||||||
|
CHistoryEntry *m_pHistoryEntry;
|
||||||
|
TStaticRingBuffer<CHistoryEntry, 64*1024, CRingBufferBase::FLAG_RECYCLE> m_History;
|
||||||
|
int m_PendingChatCounter;
|
||||||
|
int64 m_LastChatSend;
|
||||||
int64 m_aLastSoundPlayed[CHAT_NUM];
|
int64 m_aLastSoundPlayed[CHAT_NUM];
|
||||||
|
|
||||||
static void ConSay(IConsole::IResult *pResult, void *pUserData);
|
static void ConSay(IConsole::IResult *pResult, void *pUserData);
|
||||||
|
|
Loading…
Reference in a new issue