From d86b510291f40cdb0c31d48f51fad705ed980f06 Mon Sep 17 00:00:00 2001 From: furo Date: Tue, 17 Sep 2024 01:08:49 +0200 Subject: [PATCH] Add autocompletion hint for chat commands --- src/game/client/components/chat.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index e73b94f73..6aede374d 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -355,8 +355,6 @@ bool CChat::OnInput(const IInput::CEvent &Event) // add separator const char *pSeparator = pCompletionCommand->m_aParams[0] == '\0' ? "" : " "; str_append(aBuf, pSeparator); - if(*pSeparator) - str_append(aBuf, pSeparator); // add part after the name str_append(aBuf, m_Input.GetString() + m_PlaceholderOffset + m_PlaceholderLength); @@ -1233,6 +1231,23 @@ void CChat::OnRender() m_Input.SetScrollOffset(ScrollOffset); m_Input.SetScrollOffsetChange(ScrollOffsetChange); + + // Autocompletion hint + if(m_Input.GetString()[0] == '/' && m_Input.GetString()[1] != '\0' && !m_vCommands.empty()) + { + for(const auto &Command : m_vCommands) + { + if(str_startswith_nocase(Command.m_aName, m_Input.GetString() + 1)) + { + Cursor.m_X = m_Input.GetCaretPosition().x; + Cursor.m_Y = m_Input.GetCaretPosition().y; + TextRender()->TextColor(1.0f, 1.0f, 1.0f, 0.5f); + TextRender()->TextEx(&Cursor, Command.m_aName + str_length(m_Input.GetString() + 1)); + TextRender()->TextColor(TextRender()->DefaultTextColor()); + break; + } + } + } } #if defined(CONF_VIDEORECORDER)