From 17dc694e160ac60083d761f15be078d9d452c135 Mon Sep 17 00:00:00 2001 From: Des Date: Fri, 16 Aug 2024 19:11:16 -0300 Subject: [PATCH] Add #N SHIFT+TAB completion for player# names --- console.c | 21 ++++++++++++++++----- console.h | 2 +- keys.c | 4 +++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/console.c b/console.c index 09c64a67..f0dd9e32 100644 --- a/console.c +++ b/console.c @@ -2517,12 +2517,13 @@ static int Nicks_strncasecmp(char *a, char *b, unsigned int a_len) Count the number of possible nicks to complete */ -static int Nicks_CompleteCountPossible(char *line, int pos, char *s, qbool isCon) +static int Nicks_CompleteCountPossible(char *line, int pos, char *s, qbool isCon, qbool only_pnumbers) { char name[MAX_SCOREBOARDNAME]; int i, p; int match; int spos; + int digits = 0; int count = 0; if(!con_nickcompletion.integer) @@ -2559,7 +2560,17 @@ static int Nicks_CompleteCountPossible(char *line, int pos, char *s, qbool isCon } if(isCon && spos == 0) break; - if(Nicks_strncasecmp(line+spos, name, pos-spos) == 0) + if(only_pnumbers) + { + if(line[spos] == '#') + { + digits = (int) strspn(line+spos+1, "0123456789"); + // word lenght EQUAL digits count OR digits count + 1 trailing space + if(((pos)-(spos+1)) == (line[pos-1] == ' ' ? digits+1 : digits) && p == (atoi(line+spos+1)-1)) + match = spos; + } + } + else if(Nicks_strncasecmp(line+spos, name, pos-spos) == 0) match = spos; --spos; } @@ -2872,7 +2883,7 @@ static size_t Con_EscapeSpaces(char *dst, const char *src, size_t dsize) Directory support by divVerent Escaping support by bones_was_here */ -int Con_CompleteCommandLine(cmd_state_t *cmd, qbool is_console) +int Con_CompleteCommandLine(cmd_state_t *cmd, qbool is_console, qbool only_pnumbers) { const char *text = ""; char *s; @@ -2918,7 +2929,7 @@ int Con_CompleteCommandLine(cmd_state_t *cmd, qbool is_console) line[linepos] = 0; //hide them c = v = a = n = cmd_len = 0; - if (!is_console) + if (!is_console || only_pnumbers) goto nicks; space = strchr(line + 1, ' '); @@ -3137,7 +3148,7 @@ int Con_CompleteCommandLine(cmd_state_t *cmd, qbool is_console) } nicks: - n = Nicks_CompleteCountPossible(line, linepos, s, is_console); + n = Nicks_CompleteCountPossible(line, linepos, s, is_console, only_pnumbers); if (n) { Con_Printf("\n%i possible nick%s\n", n, (n > 1) ? "s: " : ":"); diff --git a/console.h b/console.h index 7ea1ecd0..503f14e5 100644 --- a/console.h +++ b/console.h @@ -80,7 +80,7 @@ size_t GetMapList (const char *s, char *completedname, int completednamebuffersi /// or to list possible matches grouped by type /// (i.e. will display possible variables, aliases, commands /// that match what they've typed so far) -int Con_CompleteCommandLine(cmd_state_t *cmd, qbool is_console); +int Con_CompleteCommandLine(cmd_state_t *cmd, qbool is_console, qbool only_pnumbers); /// Generic libs/util/console.c function to display a list /// formatted in columns on the console diff --git a/keys.c b/keys.c index 0762490e..0b9f60c1 100644 --- a/keys.c +++ b/keys.c @@ -864,8 +864,10 @@ int Key_Parse_CommonKeys(cmd_state_t *cmd, qbool is_console, int key, int unicod return linepos; } + if (KM_SHIFT) // only complete player references #N as names + return Con_CompleteCommandLine(cmd, is_console, true); if (KM_NONE) - return Con_CompleteCommandLine(cmd, is_console); + return Con_CompleteCommandLine(cmd, is_console, false); } // Advanced Console Editing by Radix radix@planetquake.com -- 2.39.2