diff options
| author | oy <Tom_Adams@web.de> | 2010-12-16 02:31:12 +0100 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2010-12-16 02:31:12 +0100 |
| commit | 6063b4c14dd26b84c91a8e8d62f3921b4789a80a (patch) | |
| tree | 2871f293948ee7b4f28745395290e874b8314c7f /src/game/client/components | |
| parent | 1d7df01e9a8e4e2bf77caf6e23f0d1eb24529073 (diff) | |
| download | zcatch-6063b4c14dd26b84c91a8e8d62f3921b4789a80a.tar.gz zcatch-6063b4c14dd26b84c91a8e8d62f3921b4789a80a.zip | |
added auto completion of nicknames and highlighted nicknames in chat. Closes #218
Diffstat (limited to 'src/game/client/components')
| -rw-r--r-- | src/game/client/components/chat.cpp | 58 | ||||
| -rw-r--r-- | src/game/client/components/chat.h | 5 |
2 files changed, 63 insertions, 0 deletions
diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index 0d3efa1c..057cc786 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -35,6 +35,10 @@ void CChat::OnReset() m_Show = false; m_InputUpdate = false; m_ChatStringOffset = 0; + m_CompletionChosen = -1; + m_aCompletionBuffer[0] = 0; + m_PlaceholderOffset = 0; + m_PlaceholderLength = 0; } void CChat::OnRelease() @@ -104,8 +108,58 @@ bool CChat::OnInput(IInput::CEvent e) m_Mode = MODE_NONE; m_pClient->OnRelease(); } + if(e.m_Flags&IInput::FLAG_PRESS && e.m_Key == KEY_TAB) + { + // 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; + + 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; + m_CompletionChosen = (m_CompletionChosen+1)%MAX_CLIENTS; + for(int i = 0; i < MAX_CLIENTS; ++i) + { + int Index = (m_CompletionChosen+i)%MAX_CLIENTS; + if(!m_pClient->m_Snap.m_paPlayerInfos[Index]) + continue; + + if(str_find_nocase(m_pClient->m_aClients[Index].m_aName, m_aCompletionBuffer)) + { + pCompletionString = m_pClient->m_aClients[Index].m_aName; + m_CompletionChosen = Index; + break; + } + } + + // insert the name + if(pCompletionString) + { + char aBuf[256]; + str_copy(aBuf, m_Input.GetString(), min(static_cast<int>(sizeof(aBuf)), m_PlaceholderOffset+1)); + str_append(aBuf, pCompletionString, sizeof(aBuf)); + str_append(aBuf, m_Input.GetString()+m_PlaceholderOffset+m_PlaceholderLength, sizeof(aBuf)); + m_PlaceholderLength = str_length(pCompletionString); + m_OldChatStringLength = m_Input.GetLength(); + m_Input.Set(aBuf); + m_Input.SetCursorOffset(m_PlaceholderOffset+m_PlaceholderLength); + m_InputUpdate = true; + } + } else { + // reset name completion process + if(e.m_Flags&IInput::FLAG_PRESS && e.m_Key != KEY_TAB) + m_CompletionChosen = -1; + m_OldChatStringLength = m_Input.GetLength(); m_Input.ProcessInput(e); m_InputUpdate = true; @@ -129,6 +183,7 @@ void CChat::EnableMode(int Team) m_Input.Clear(); Input()->ClearEvents(); + m_CompletionChosen = -1; } } @@ -167,6 +222,7 @@ void CChat::AddLine(int ClientId, int Team, const char *pLine) m_aLines[m_CurrentLine].m_ClientId = ClientId; m_aLines[m_CurrentLine].m_Team = Team; m_aLines[m_CurrentLine].m_NameColor = -2; + m_aLines[m_CurrentLine].m_Highlighted = str_find_nocase(pLine, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalCid].m_aName) != 0; if(ClientId == -1) // server message { @@ -309,6 +365,8 @@ void CChat::OnRender() // render line if(m_aLines[r].m_ClientId == -1) TextRender()->TextColor(1.0f, 1.0f, 0.5f, 1.0f); // system + else if(m_aLines[r].m_Highlighted) + TextRender()->TextColor(1.0f, 0.5f, 0.5f, 1.0f); // highlighted else if(m_aLines[r].m_Team) TextRender()->TextColor(0.65f, 1.0f, 0.65f, 1.0f); // team message else diff --git a/src/game/client/components/chat.h b/src/game/client/components/chat.h index 8289bb9e..da6a3b16 100644 --- a/src/game/client/components/chat.h +++ b/src/game/client/components/chat.h @@ -23,6 +23,7 @@ class CChat : public CComponent int m_NameColor; char m_aName[64]; char m_aText[512]; + bool m_Highlighted; }; CLine m_aLines[MAX_LINES]; @@ -41,6 +42,10 @@ class CChat : public CComponent bool m_InputUpdate; int m_ChatStringOffset; int m_OldChatStringLength; + int m_CompletionChosen; + char m_aCompletionBuffer[256]; + int m_PlaceholderOffset; + int m_PlaceholderLength; static void ConSay(IConsole::IResult *pResult, void *pUserData); static void ConSayTeam(IConsole::IResult *pResult, void *pUserData); |