Auto complete when chaining multiple commands

closed #7966
This commit is contained in:
ChillerDragon 2024-05-11 13:41:41 +08:00
parent 89437b7ef7
commit 54977d5745
2 changed files with 13 additions and 3 deletions

View file

@ -321,7 +321,13 @@ void CGameConsole::CInstance::PossibleCommandsCompleteCallback(int Index, const
{ {
CGameConsole::CInstance *pInstance = (CGameConsole::CInstance *)pUser; CGameConsole::CInstance *pInstance = (CGameConsole::CInstance *)pUser;
if(pInstance->m_CompletionChosen == Index) if(pInstance->m_CompletionChosen == Index)
pInstance->m_Input.Set(pStr); {
char aCurrent[512];
str_truncate(aCurrent, sizeof(aCurrent), pInstance->m_aCompletionBuffer, pInstance->m_CompletionCommandStart);
char aBuf[512];
str_format(aBuf, sizeof(aBuf), "%s%s", aCurrent, pStr);
pInstance->m_Input.Set(aBuf);
}
} }
const char *CGameConsole::CInstance::GetCommand(const char *pInput) const const char *CGameConsole::CInstance::GetCommand(const char *pInput) const
@ -452,9 +458,12 @@ bool CGameConsole::CInstance::OnInput(const IInput::CEvent &Event)
if(!m_Searching) if(!m_Searching)
{ {
const char *pSearch = GetCommand(m_aCompletionBuffer);
m_CompletionCommandStart = pSearch - m_aCompletionBuffer;
// command completion // command completion
const bool UseTempCommands = m_Type == CGameConsole::CONSOLETYPE_REMOTE && m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands(); const bool UseTempCommands = m_Type == CGameConsole::CONSOLETYPE_REMOTE && m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands();
int CompletionEnumerationCount = m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, UseTempCommands); int CompletionEnumerationCount = m_pGameConsole->m_pConsole->PossibleCommands(pSearch, m_CompletionFlagmask, UseTempCommands);
if(m_Type == CGameConsole::CONSOLETYPE_LOCAL || m_pGameConsole->Client()->RconAuthed()) if(m_Type == CGameConsole::CONSOLETYPE_LOCAL || m_pGameConsole->Client()->RconAuthed())
{ {
if(CompletionEnumerationCount) if(CompletionEnumerationCount)
@ -463,7 +472,7 @@ bool CGameConsole::CInstance::OnInput(const IInput::CEvent &Event)
m_CompletionChosen = 0; m_CompletionChosen = 0;
m_CompletionChosen = (m_CompletionChosen + Direction + CompletionEnumerationCount) % CompletionEnumerationCount; m_CompletionChosen = (m_CompletionChosen + Direction + CompletionEnumerationCount) % CompletionEnumerationCount;
m_CompletionArgumentPosition = 0; m_CompletionArgumentPosition = 0;
m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, UseTempCommands, PossibleCommandsCompleteCallback, this); m_pGameConsole->m_pConsole->PossibleCommands(pSearch, m_CompletionFlagmask, UseTempCommands, PossibleCommandsCompleteCallback, this);
} }
else if(m_CompletionChosen != -1) else if(m_CompletionChosen != -1)
{ {

View file

@ -69,6 +69,7 @@ class CGameConsole : public CComponent
float m_CompletionRenderOffset; float m_CompletionRenderOffset;
float m_CompletionRenderOffsetChange; float m_CompletionRenderOffsetChange;
int m_CompletionArgumentPosition; int m_CompletionArgumentPosition;
int m_CompletionCommandStart = 0;
char m_aUser[32]; char m_aUser[32];
bool m_UserGot; bool m_UserGot;