mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Fix shift + tab selecting second last index in console, player name chat & command chat
This commit is contained in:
parent
d4df63d239
commit
4982f8536e
|
@ -92,6 +92,7 @@ void CChat::Reset()
|
|||
m_Show = false;
|
||||
m_InputUpdate = false;
|
||||
m_ChatStringOffset = 0;
|
||||
m_CompletionUsed = false;
|
||||
m_CompletionChosen = -1;
|
||||
m_aCompletionBuffer[0] = 0;
|
||||
m_PlaceholderOffset = 0;
|
||||
|
@ -309,7 +310,7 @@ bool CChat::OnInput(IInput::CEvent Event)
|
|||
if(Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key == KEY_TAB)
|
||||
{
|
||||
// fill the completion buffer
|
||||
if(m_CompletionChosen < 0)
|
||||
if(!m_CompletionUsed)
|
||||
{
|
||||
const char *pCursor = m_Input.GetString() + m_Input.GetCursorOffset();
|
||||
for(int Count = 0; Count < m_Input.GetCursorOffset() && *(pCursor - 1) != ' '; --pCursor, ++Count)
|
||||
|
@ -328,10 +329,13 @@ bool CChat::OnInput(IInput::CEvent Event)
|
|||
|
||||
const size_t NumCommands = m_Commands.size();
|
||||
|
||||
if(m_ReverseTAB)
|
||||
m_CompletionChosen = (m_CompletionChosen - 1 + 2 * NumCommands) % (2 * NumCommands);
|
||||
else
|
||||
m_CompletionChosen = (m_CompletionChosen + 1) % (2 * NumCommands);
|
||||
if(m_ReverseTAB && m_CompletionUsed)
|
||||
m_CompletionChosen--;
|
||||
else if(!m_ReverseTAB)
|
||||
m_CompletionChosen++;
|
||||
m_CompletionChosen = (m_CompletionChosen + 2 * NumCommands) % (2 * NumCommands);
|
||||
|
||||
m_CompletionUsed = true;
|
||||
|
||||
const char *pCommandStart = m_aCompletionBuffer + 1;
|
||||
for(size_t i = 0; i < 2 * NumCommands; ++i)
|
||||
|
@ -392,10 +396,13 @@ bool CChat::OnInput(IInput::CEvent Event)
|
|||
// find next possible name
|
||||
const char *pCompletionString = 0;
|
||||
|
||||
if(m_ReverseTAB)
|
||||
m_CompletionChosen = (m_CompletionChosen - 1 + 2 * MAX_CLIENTS) % (2 * MAX_CLIENTS);
|
||||
else
|
||||
m_CompletionChosen = (m_CompletionChosen + 1) % (2 * MAX_CLIENTS);
|
||||
if(m_ReverseTAB && m_CompletionUsed)
|
||||
m_CompletionChosen--;
|
||||
else if(!m_ReverseTAB)
|
||||
m_CompletionChosen++;
|
||||
m_CompletionChosen = (m_CompletionChosen + 2 * MAX_CLIENTS) % (2 * MAX_CLIENTS);
|
||||
|
||||
m_CompletionUsed = true;
|
||||
|
||||
for(int i = 0; i < 2 * MAX_CLIENTS; ++i)
|
||||
{
|
||||
|
@ -470,8 +477,13 @@ bool CChat::OnInput(IInput::CEvent Event)
|
|||
{
|
||||
// reset name completion process
|
||||
if(Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key != KEY_TAB)
|
||||
{
|
||||
if(Event.m_Key != KEY_LSHIFT)
|
||||
{
|
||||
m_CompletionChosen = -1;
|
||||
m_CompletionUsed = false;
|
||||
}
|
||||
}
|
||||
|
||||
m_OldChatStringLength = m_Input.GetLength();
|
||||
m_Input.ProcessInput(Event);
|
||||
|
@ -529,6 +541,7 @@ void CChat::EnableMode(int Team)
|
|||
Input()->SetIMEState(true);
|
||||
Input()->Clear();
|
||||
m_CompletionChosen = -1;
|
||||
m_CompletionUsed = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,6 +75,7 @@ class CChat : public CComponent
|
|||
bool m_InputUpdate;
|
||||
int m_ChatStringOffset;
|
||||
int m_OldChatStringLength;
|
||||
bool m_CompletionUsed;
|
||||
int m_CompletionChosen;
|
||||
char m_aCompletionBuffer[256];
|
||||
int m_PlaceholderOffset;
|
||||
|
|
|
@ -47,6 +47,7 @@ CGameConsole::CInstance::CInstance(int Type)
|
|||
m_CompletionFlagmask = CFGFLAG_SERVER;
|
||||
|
||||
m_aCompletionBuffer[0] = 0;
|
||||
m_CompletionUsed = false;
|
||||
m_CompletionChosen = -1;
|
||||
m_CompletionRenderOffset = 0.0f;
|
||||
m_ReverseTAB = false;
|
||||
|
@ -255,13 +256,15 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event)
|
|||
{
|
||||
if(m_Type == CGameConsole::CONSOLETYPE_LOCAL || m_pGameConsole->Client()->RconAuthed())
|
||||
{
|
||||
if(m_ReverseTAB)
|
||||
if(m_ReverseTAB && m_CompletionUsed)
|
||||
m_CompletionChosen--;
|
||||
else
|
||||
else if(!m_ReverseTAB)
|
||||
m_CompletionChosen++;
|
||||
m_CompletionEnumerationCount = 0;
|
||||
m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, m_Type != CGameConsole::CONSOLETYPE_LOCAL && m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands(), PossibleCommandsCompleteCallback, this);
|
||||
|
||||
m_CompletionUsed = true;
|
||||
|
||||
// handle wrapping
|
||||
if(m_CompletionEnumerationCount && (m_CompletionChosen >= m_CompletionEnumerationCount || m_CompletionChosen < 0))
|
||||
{
|
||||
|
@ -310,6 +313,7 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event)
|
|||
{
|
||||
if((Event.m_Key != KEY_TAB) && (Event.m_Key != KEY_LSHIFT))
|
||||
{
|
||||
m_CompletionUsed = false;
|
||||
m_CompletionChosen = -1;
|
||||
str_copy(m_aCompletionBuffer, m_Input.GetString(), sizeof(m_aCompletionBuffer));
|
||||
m_CompletionRenderOffset = 0.0f;
|
||||
|
@ -540,7 +544,7 @@ void CGameConsole::OnRender()
|
|||
|
||||
CRenderInfo Info;
|
||||
Info.m_pSelf = this;
|
||||
Info.m_WantedCompletion = pConsole->m_CompletionChosen;
|
||||
Info.m_WantedCompletion = pConsole->m_CompletionUsed ? pConsole->m_CompletionChosen : -1;
|
||||
Info.m_EnumCount = 0;
|
||||
Info.m_Offset = pConsole->m_CompletionRenderOffset;
|
||||
Info.m_Width = Screen.w;
|
||||
|
|
|
@ -40,6 +40,7 @@ class CGameConsole : public CComponent
|
|||
CGameConsole *m_pGameConsole;
|
||||
|
||||
char m_aCompletionBuffer[128];
|
||||
bool m_CompletionUsed;
|
||||
int m_CompletionChosen;
|
||||
int m_CompletionFlagmask;
|
||||
float m_CompletionRenderOffset;
|
||||
|
|
Loading…
Reference in a new issue