mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge #4161
4161: Fix shift + tab selecting second last index in console, player name c… r=def- a=Jupeyy …hat & command chat example: - In console type `scoreboard`and press shift+tab and you wont get the last element - in chat: - with player names it would be noticable on a full server, since it goes from index 62 - with commands type `/` and shift + tab will give `/w`, but pressing tab again gives `/whisper` so second last ## Checklist - [x] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
commit
6aaaaf1ab4
|
@ -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