CTRL actions work in pre-game console window

This commit is contained in:
BjossiAlfreds 2024-08-02 01:02:34 +00:00
parent d11ba119bc
commit a18ea4b11d
2 changed files with 39 additions and 21 deletions

View file

@ -60,7 +60,9 @@ DrawAltStringScaled(int x, int y, char *s, float factor)
void void
Key_ClearTyping(void) Key_ClearTyping(void)
{ {
key_lines[edit_line][1] = 0; /* clear any typing */ key_lines[edit_line][0] = ']';
key_lines[edit_line][1] = '\0';
key_linepos = 1; key_linepos = 1;
} }
@ -473,6 +475,7 @@ Con_DrawInput(void)
char *text; char *text;
char ch; char ch;
int txtlen; int txtlen;
int linepos;
if (cls.key_dest == key_menu) if (cls.key_dest == key_menu)
{ {
@ -487,18 +490,22 @@ Con_DrawInput(void)
scale = SCR_GetConsoleScale(); scale = SCR_GetConsoleScale();
text = key_lines[edit_line]; text = key_lines[edit_line];
linepos = key_linepos;
/* prestep if horizontally scrolling */ /* prestep if horizontally scrolling */
if (key_linepos >= con.linewidth) if (linepos >= con.linewidth)
{ {
text += 1 + key_linepos - con.linewidth; int ofs = 1 + linepos - con.linewidth;
text += ofs;
linepos -= ofs;
} }
txtlen = strlen(text); txtlen = strlen(text);
for (i = 0; i < con.linewidth; i++) for (i = 0; i < con.linewidth; i++)
{ {
if (i == key_linepos) if (i == linepos)
{ {
if (cls.realtime & 8) if (cls.realtime & 8)
{ {

View file

@ -29,6 +29,7 @@
#include "header/client.h" #include "header/client.h"
void Key_ClearTyping(void);
void IN_GetClipboardText(char *out, size_t n); void IN_GetClipboardText(char *out, size_t n);
int IN_SetClipboardText(const char *s); int IN_SetClipboardText(const char *s);
@ -346,6 +347,14 @@ CompleteMapNameCommand(void)
/* /*
* Interactive line editing and console scrollback * Interactive line editing and console scrollback
*/ */
static int
IsInConsole(void)
{
return cls.key_dest == key_console ||
(cls.key_dest == key_game &&
(cls.state == ca_disconnected || cls.state == ca_connecting));
}
void void
Key_Console(int key) Key_Console(int key)
{ {
@ -391,14 +400,16 @@ Key_Console(int key)
if (key == 'c' || key == 'x') if (key == 'c' || key == 'x')
{ {
if (IN_SetClipboardText(key_lines[edit_line] + 1)) if (key_lines[edit_line][1] != '\0')
{ {
Com_Printf("Copy to clipboard failed.\n"); if (IN_SetClipboardText(key_lines[edit_line] + 1))
} {
else if (key == 'x') Com_Printf("Copy to clipboard failed.\n");
{ }
key_lines[edit_line][1] = '\0'; else if (key == 'x')
key_linepos = 1; {
Key_ClearTyping();
}
} }
return; return;
@ -434,9 +445,8 @@ Key_Console(int key)
Com_Printf("%s\n", key_lines[edit_line]); Com_Printf("%s\n", key_lines[edit_line]);
edit_line = (edit_line + 1) & (NUM_KEY_LINES - 1); edit_line = (edit_line + 1) & (NUM_KEY_LINES - 1);
history_line = edit_line; history_line = edit_line;
key_lines[edit_line][0] = ']';
key_lines[edit_line][1] = '\0'; Key_ClearTyping();
key_linepos = 1;
if (cls.state == ca_disconnected) if (cls.state == ca_disconnected)
{ {
@ -535,8 +545,7 @@ Key_Console(int key)
if (history_line == edit_line) if (history_line == edit_line)
{ {
key_lines[edit_line][0] = ']'; Key_ClearTyping();
key_linepos = 1;
} }
else else
{ {
@ -1042,9 +1051,8 @@ Key_ReadConsoleHistory()
} }
} }
/* input line is always blank */ /* don't remember the input line */
key_linepos = 1; Key_ClearTyping();
strcpy (key_lines[edit_line], "]");
fclose(f); fclose(f);
} }
@ -1418,8 +1426,11 @@ Key_Event(int key, qboolean down, qboolean special)
return; return;
} }
/* FIXME: Better way to do CTRL+letter actions in the console */ /* FIXME: Better way to do CTRL+<key> actions in the console?
if (keydown[K_CTRL] && cls.key_dest == key_console && key >= 'a' && key <= 'z') special should be set to true in this case.
*/
if (keydown[K_CTRL] && IsInConsole() &&
key >= 'a' && key <= 'z')
{ {
special = true; special = true;
} }