mirror of
https://git.code.sf.net/p/quake/newtree
synced 2025-05-31 17:21:46 +00:00
Console editing stuff
This commit is contained in:
parent
476b299074
commit
a73a779486
3 changed files with 164 additions and 120 deletions
|
@ -41,6 +41,7 @@ typedef struct
|
||||||
int current; // line where next message will be printed
|
int current; // line where next message will be printed
|
||||||
int x; // offset in current line for next print
|
int x; // offset in current line for next print
|
||||||
int display; // bottom of console displays this line
|
int display; // bottom of console displays this line
|
||||||
|
int numlines; // number of non-blank text lines, used for backscroling
|
||||||
} console_t;
|
} console_t;
|
||||||
|
|
||||||
extern console_t con_main;
|
extern console_t con_main;
|
||||||
|
|
|
@ -128,6 +128,8 @@ Con_Clear_f
|
||||||
*/
|
*/
|
||||||
void Con_Clear_f (void)
|
void Con_Clear_f (void)
|
||||||
{
|
{
|
||||||
|
con_main.numlines = 0;
|
||||||
|
con_chat.numlines = 0;
|
||||||
memset (con_main.text, ' ', CON_TEXTSIZE);
|
memset (con_main.text, ' ', CON_TEXTSIZE);
|
||||||
memset (con_chat.text, ' ', CON_TEXTSIZE);
|
memset (con_chat.text, ' ', CON_TEXTSIZE);
|
||||||
}
|
}
|
||||||
|
@ -154,6 +156,8 @@ Con_MessageMode_f
|
||||||
*/
|
*/
|
||||||
void Con_MessageMode_f (void)
|
void Con_MessageMode_f (void)
|
||||||
{
|
{
|
||||||
|
if (cls.state != ca_active)
|
||||||
|
return;
|
||||||
chat_team = false;
|
chat_team = false;
|
||||||
key_dest = key_message;
|
key_dest = key_message;
|
||||||
}
|
}
|
||||||
|
@ -165,6 +169,8 @@ Con_MessageMode2_f
|
||||||
*/
|
*/
|
||||||
void Con_MessageMode2_f (void)
|
void Con_MessageMode2_f (void)
|
||||||
{
|
{
|
||||||
|
if (cls.state != ca_active)
|
||||||
|
return;
|
||||||
chat_team = true;
|
chat_team = true;
|
||||||
key_dest = key_message;
|
key_dest = key_message;
|
||||||
}
|
}
|
||||||
|
@ -285,6 +291,8 @@ void Con_Linefeed (void)
|
||||||
if (con->display == con->current)
|
if (con->display == con->current)
|
||||||
con->display++;
|
con->display++;
|
||||||
con->current++;
|
con->current++;
|
||||||
|
if (con->numlines < con_totallines)
|
||||||
|
con->numlines++;
|
||||||
memset (&con->text[(con->current%con_totallines)*con_linewidth]
|
memset (&con->text[(con->current%con_totallines)*con_linewidth]
|
||||||
, ' ', con_linewidth);
|
, ' ', con_linewidth);
|
||||||
}
|
}
|
||||||
|
@ -457,31 +465,30 @@ void Con_DrawInput (void)
|
||||||
int y;
|
int y;
|
||||||
int i;
|
int i;
|
||||||
char *text;
|
char *text;
|
||||||
|
char temp[MAXCMDLINE];
|
||||||
|
|
||||||
if (key_dest != key_console && cls.state == ca_active)
|
if (key_dest != key_console && cls.state == ca_active)
|
||||||
return; // don't draw anything (allways draw if not active)
|
return; // don't draw anything (allways draw if not active)
|
||||||
|
|
||||||
text = key_lines[edit_line];
|
text = strcpy (temp, key_lines[edit_line]);
|
||||||
|
|
||||||
// add the cursor frame
|
|
||||||
text[key_linepos] = 10+((int)(realtime*con_cursorspeed)&1);
|
|
||||||
|
|
||||||
// fill out remainder with spaces
|
// fill out remainder with spaces
|
||||||
for (i=key_linepos+1 ; i< con_linewidth ; i++)
|
for (i=strlen(text) ; i < MAXCMDLINE ; i++)
|
||||||
text[i] = ' ';
|
text[i] = ' ';
|
||||||
|
|
||||||
|
// add the cursor frame
|
||||||
|
if ( (int)(realtime*con_cursorspeed) & 1 )
|
||||||
|
text[key_linepos] = 11;
|
||||||
|
|
||||||
// prestep if horizontally scrolling
|
// prestep if horizontally scrolling
|
||||||
if (key_linepos >= con_linewidth)
|
if (key_linepos >= con_linewidth)
|
||||||
text += 1 + key_linepos - con_linewidth;
|
text += 1 + key_linepos - con_linewidth;
|
||||||
|
|
||||||
// draw it
|
// draw it
|
||||||
y = con_vislines-22;
|
y = con_vislines-22;
|
||||||
|
|
||||||
for (i=0 ; i<con_linewidth ; i++)
|
for (i=0 ; i<con_linewidth ; i++)
|
||||||
Draw_Character ( (i+1)<<3, con_vislines - 22, text[i]);
|
Draw_Character ( (i+1)<<3, con_vislines - 22, text[i]);
|
||||||
|
|
||||||
// remove cursor
|
|
||||||
key_lines[edit_line][key_linepos] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
254
source/keys.c
254
source/keys.c
|
@ -53,6 +53,7 @@ key up events are sent even if in console mode
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
cvar_t *cl_chatmode;
|
||||||
|
|
||||||
#define MAXCMDLINE 256
|
#define MAXCMDLINE 256
|
||||||
char key_lines[32][MAXCMDLINE];
|
char key_lines[32][MAXCMDLINE];
|
||||||
|
@ -264,113 +265,133 @@ Interactive line editing and console scrollback
|
||||||
*/
|
*/
|
||||||
void Key_Console (int key)
|
void Key_Console (int key)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
|
||||||
// char *cmd, *s;
|
|
||||||
int i;
|
int i;
|
||||||
|
#ifdef _WIN32
|
||||||
HANDLE th;
|
HANDLE th;
|
||||||
char *clipText, *textCopied;
|
char *clipText, *textCopied;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (key == K_ENTER)
|
switch (key)
|
||||||
{ // backslash text are commands, else chat
|
{
|
||||||
if (key_lines[edit_line][1] == '\\' || key_lines[edit_line][1] == '/')
|
case K_ENTER:
|
||||||
Cbuf_AddText (key_lines[edit_line]+2); // skip the >
|
// backslash text are commands
|
||||||
else if (CheckForCommand())
|
if (key_lines[edit_line][1] == '/' && key_lines[edit_line][2] == '/')
|
||||||
Cbuf_AddText (key_lines[edit_line]+1); // valid command
|
goto no_lf;
|
||||||
else
|
else if (key_lines[edit_line][1] == '\\' || key_lines[edit_line][1] == '/')
|
||||||
{ // convert to a chat message
|
Cbuf_AddText (key_lines[edit_line]+2); // skip the ]/
|
||||||
if (cls.state >= ca_connected)
|
else if (cl_chatmode->value != 2 && CheckForCommand())
|
||||||
|
Cbuf_AddText (key_lines[edit_line]+1); // valid command
|
||||||
|
else if ((cls.state >= ca_connected && cl_chatmode->value == 1) || cl_chatmode->value == 2)
|
||||||
|
{
|
||||||
|
if (cls.state < ca_connected) // can happen if cl_constyle == 2
|
||||||
|
goto no_lf; // drop the whole line
|
||||||
|
|
||||||
|
// convert to a chat message
|
||||||
Cbuf_AddText ("say ");
|
Cbuf_AddText ("say ");
|
||||||
Cbuf_AddText (key_lines[edit_line]+1); // skip the >
|
Cbuf_AddText (key_lines[edit_line]+1);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
Cbuf_AddText (key_lines[edit_line]+1); // skip the ]
|
||||||
|
|
||||||
Cbuf_AddText ("\n");
|
Cbuf_AddText ("\n");
|
||||||
Con_Printf ("%s\n",key_lines[edit_line]);
|
no_lf:
|
||||||
edit_line = (edit_line + 1) & 31;
|
Con_Printf ("%s\n",key_lines[edit_line]);
|
||||||
history_line = edit_line;
|
edit_line = (edit_line + 1) & 31;
|
||||||
key_lines[edit_line][0] = ']';
|
history_line = edit_line;
|
||||||
key_linepos = 1;
|
|
||||||
if (cls.state == ca_disconnected)
|
|
||||||
SCR_UpdateScreen (); // force an update, because the command
|
|
||||||
// may take some time
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key == K_TAB)
|
|
||||||
{ // command completion
|
|
||||||
CompleteCommand ();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key == K_BACKSPACE || key == K_LEFTARROW)
|
|
||||||
{
|
|
||||||
if (key_linepos > 1)
|
|
||||||
key_linepos--;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key == K_UPARROW)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
history_line = (history_line - 1) & 31;
|
|
||||||
} while (history_line != edit_line
|
|
||||||
&& !key_lines[history_line][1]);
|
|
||||||
if (history_line == edit_line)
|
|
||||||
history_line = (edit_line+1)&31;
|
|
||||||
strcpy(key_lines[edit_line], key_lines[history_line]);
|
|
||||||
key_linepos = strlen(key_lines[edit_line]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key == K_DOWNARROW)
|
|
||||||
{
|
|
||||||
if (history_line == edit_line) return;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
history_line = (history_line + 1) & 31;
|
|
||||||
}
|
|
||||||
while (history_line != edit_line
|
|
||||||
&& !key_lines[history_line][1]);
|
|
||||||
if (history_line == edit_line)
|
|
||||||
{
|
|
||||||
key_lines[edit_line][0] = ']';
|
key_lines[edit_line][0] = ']';
|
||||||
|
key_lines[edit_line][1] = 0;
|
||||||
key_linepos = 1;
|
key_linepos = 1;
|
||||||
}
|
if (cls.state == ca_disconnected)
|
||||||
else
|
SCR_UpdateScreen (); // force an update, because the command
|
||||||
{
|
// may take some time
|
||||||
|
return;
|
||||||
|
|
||||||
|
case K_TAB:
|
||||||
|
// command completion
|
||||||
|
CompleteCommand ();
|
||||||
|
return;
|
||||||
|
|
||||||
|
case K_BACKSPACE:
|
||||||
|
if (key_linepos > 1)
|
||||||
|
{
|
||||||
|
strcpy(key_lines[edit_line] + key_linepos - 1, key_lines[edit_line] + key_linepos);
|
||||||
|
key_linepos--;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
case K_DEL:
|
||||||
|
if (key_linepos < strlen(key_lines[edit_line]))
|
||||||
|
strcpy(key_lines[edit_line] + key_linepos, key_lines[edit_line] + key_linepos + 1);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case K_RIGHTARROW:
|
||||||
|
if (key_linepos < strlen(key_lines[edit_line]))
|
||||||
|
key_linepos++;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case K_LEFTARROW:
|
||||||
|
if (key_linepos > 1)
|
||||||
|
key_linepos--;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case K_UPARROW:
|
||||||
|
do {
|
||||||
|
history_line = (history_line - 1) & 31;
|
||||||
|
} while (history_line != edit_line
|
||||||
|
&& !key_lines[history_line][1]);
|
||||||
|
if (history_line == edit_line)
|
||||||
|
history_line = (edit_line+1)&31;
|
||||||
strcpy(key_lines[edit_line], key_lines[history_line]);
|
strcpy(key_lines[edit_line], key_lines[history_line]);
|
||||||
key_linepos = strlen(key_lines[edit_line]);
|
key_linepos = strlen(key_lines[edit_line]);
|
||||||
}
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key == K_PGUP || key==K_MWHEELUP)
|
case K_DOWNARROW:
|
||||||
{
|
if (history_line == edit_line) return;
|
||||||
con->display -= 2;
|
do {
|
||||||
return;
|
history_line = (history_line + 1) & 31;
|
||||||
}
|
} while (history_line != edit_line
|
||||||
|
&& !key_lines[history_line][1]);
|
||||||
|
|
||||||
if (key == K_PGDN || key==K_MWHEELDOWN)
|
if (history_line == edit_line) {
|
||||||
{
|
key_lines[edit_line][0] = ']';
|
||||||
con->display += 2;
|
key_lines[edit_line][1] = 0;
|
||||||
if (con->display > con->current)
|
key_linepos = 1;
|
||||||
con->display = con->current;
|
} else {
|
||||||
return;
|
strcpy(key_lines[edit_line], key_lines[history_line]);
|
||||||
}
|
key_linepos = strlen(key_lines[edit_line]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
if (key == K_HOME)
|
case K_MWHEELUP:
|
||||||
{
|
case K_PGUP:
|
||||||
con->display = con->current - con_totallines + 10;
|
if (con->display - con->current + con->numlines > 2)
|
||||||
return;
|
con->display -= 2;
|
||||||
}
|
return;
|
||||||
|
|
||||||
if (key == K_END)
|
case K_MWHEELDOWN:
|
||||||
{
|
case K_PGDN:
|
||||||
con->display = con->current;
|
con->display += 2;
|
||||||
return;
|
if (con->display > con->current)
|
||||||
|
con->display = con->current;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case K_HOME:
|
||||||
|
if (keydown[K_CTRL])
|
||||||
|
{
|
||||||
|
if (con->numlines > 10)
|
||||||
|
con->display = con->current - con->numlines + 10;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
key_linepos = 1;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case K_END:
|
||||||
|
if (keydown[K_CTRL])
|
||||||
|
con->display = con->current;
|
||||||
|
else
|
||||||
|
key_linepos = strlen(key_lines[edit_line]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if ((key=='V' || key=='v') && GetKeyState(VK_CONTROL)<0) {
|
if ((key=='V' || key=='v') && GetKeyState(VK_CONTROL)<0) {
|
||||||
if (OpenClipboard(NULL)) {
|
if (OpenClipboard(NULL)) {
|
||||||
|
@ -382,12 +403,14 @@ void Key_Console (int key)
|
||||||
strcpy(textCopied, clipText);
|
strcpy(textCopied, clipText);
|
||||||
/* Substitutes a NULL for every token */strtok(textCopied, "\n\r\b");
|
/* Substitutes a NULL for every token */strtok(textCopied, "\n\r\b");
|
||||||
i = strlen(textCopied);
|
i = strlen(textCopied);
|
||||||
if (i+key_linepos>=MAXCMDLINE)
|
if (i + strlen(key_lines[edit_line]) >= MAXCMDLINE-1)
|
||||||
i=MAXCMDLINE-key_linepos;
|
i = MAXCMDLINE-1 - strlen(key_lines[edit_line]);
|
||||||
if (i>0) {
|
if (i > 0)
|
||||||
textCopied[i]=0;
|
{ // insert the string
|
||||||
strcat(key_lines[edit_line], textCopied);
|
memcpy (key_lines[edit_line] + key_linepos + i,
|
||||||
key_linepos+=i;;
|
key_lines[edit_line] + key_linepos, strlen(key_lines[edit_line]) - key_linepos + 1);
|
||||||
|
memcpy (key_lines[edit_line] + key_linepos, textCopied, i);
|
||||||
|
key_linepos += i;
|
||||||
}
|
}
|
||||||
free(textCopied);
|
free(textCopied);
|
||||||
}
|
}
|
||||||
|
@ -401,12 +424,18 @@ void Key_Console (int key)
|
||||||
|
|
||||||
if (key < 32 || key > 127)
|
if (key < 32 || key > 127)
|
||||||
return; // non printable
|
return; // non printable
|
||||||
|
|
||||||
if (key_linepos < MAXCMDLINE-1)
|
if (key_linepos < MAXCMDLINE-1)
|
||||||
{
|
{
|
||||||
|
i = strlen(key_lines[edit_line]) - 1;
|
||||||
|
if (i == MAXCMDLINE-2) i--;
|
||||||
|
for (; i >= key_linepos; i--)
|
||||||
|
key_lines[edit_line][i + 1] = key_lines[edit_line][i];
|
||||||
|
i = key_lines[edit_line][key_linepos];
|
||||||
key_lines[edit_line][key_linepos] = key;
|
key_lines[edit_line][key_linepos] = key;
|
||||||
key_linepos++;
|
key_linepos++;
|
||||||
key_lines[edit_line][key_linepos] = 0;
|
if (!i) // // only null terminate if at the end
|
||||||
|
key_lines[edit_line][key_linepos] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -676,6 +705,7 @@ void Key_Init (void)
|
||||||
consolekeys[K_UPARROW] = true;
|
consolekeys[K_UPARROW] = true;
|
||||||
consolekeys[K_DOWNARROW] = true;
|
consolekeys[K_DOWNARROW] = true;
|
||||||
consolekeys[K_BACKSPACE] = true;
|
consolekeys[K_BACKSPACE] = true;
|
||||||
|
consolekeys[K_DEL] = true;
|
||||||
consolekeys[K_HOME] = true;
|
consolekeys[K_HOME] = true;
|
||||||
consolekeys[K_END] = true;
|
consolekeys[K_END] = true;
|
||||||
consolekeys[K_PGUP] = true;
|
consolekeys[K_PGUP] = true;
|
||||||
|
@ -723,7 +753,9 @@ void Key_Init (void)
|
||||||
Cmd_AddCommand ("unbind",Key_Unbind_f);
|
Cmd_AddCommand ("unbind",Key_Unbind_f);
|
||||||
Cmd_AddCommand ("unbindall",Key_Unbindall_f);
|
Cmd_AddCommand ("unbindall",Key_Unbindall_f);
|
||||||
|
|
||||||
|
cl_chatmode = Cvar_Get ("cl_chatmode", "1", 0,
|
||||||
|
"Controls when console text will be treated as a chat message"
|
||||||
|
"0 - never, 1 - smart, 2 - always");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -757,17 +789,20 @@ void Key_Event (int key, qboolean down)
|
||||||
if (down)
|
if (down)
|
||||||
{
|
{
|
||||||
key_repeats[key]++;
|
key_repeats[key]++;
|
||||||
if (key != K_BACKSPACE
|
if ((key != K_BACKSPACE && key != K_DEL
|
||||||
&& key != K_PAUSE
|
&& key != K_LEFTARROW && key != K_RIGHTARROW
|
||||||
&& key != K_PGUP
|
&& key != K_PGUP && key != K_PGDN
|
||||||
&& key != K_PGDN
|
&& key_repeats[key] > 1) ||
|
||||||
&& key_repeats[key] > 1)
|
(key_dest == key_game && cls.state == ca_active))
|
||||||
return; // ignore most autorepeats
|
return; // ignore most autorepeats
|
||||||
|
|
||||||
if (key >= 200 && !keybindings[key])
|
if (key >= 200 && !keybindings[key])
|
||||||
Con_Printf ("%s is unbound, hit F4 to set.\n", Key_KeynumToString (key) );
|
Con_Printf ("%s is unbound, hit F4 to set.\n", Key_KeynumToString (key) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exit message mode is disconnected
|
||||||
|
if (key_dest == key_message && cls.state != ca_active)
|
||||||
|
key_dest = key_console;
|
||||||
|
|
||||||
//
|
//
|
||||||
// handle escape specialy, so the user can never unbind it
|
// handle escape specialy, so the user can never unbind it
|
||||||
|
@ -806,7 +841,7 @@ void Key_Event (int key, qboolean down)
|
||||||
kb = keybindings[key];
|
kb = keybindings[key];
|
||||||
if (kb && kb[0] == '+')
|
if (kb && kb[0] == '+')
|
||||||
{
|
{
|
||||||
snprintf (cmd, sizeof(cmd), "-%s %i\n", kb+1, key);
|
snprintf (cmd, sizeof(cmd), "-%s %i\n", kb+1, key);
|
||||||
Cbuf_AddText (cmd);
|
Cbuf_AddText (cmd);
|
||||||
}
|
}
|
||||||
if (keyshift[key] != key)
|
if (keyshift[key] != key)
|
||||||
|
@ -814,7 +849,7 @@ void Key_Event (int key, qboolean down)
|
||||||
kb = keybindings[keyshift[key]];
|
kb = keybindings[keyshift[key]];
|
||||||
if (kb && kb[0] == '+')
|
if (kb && kb[0] == '+')
|
||||||
{
|
{
|
||||||
snprintf (cmd, sizeof(cmd), "-%s %i\n", kb+1, key);
|
snprintf (cmd, sizeof(cmd), "-%s %i\n", kb+1, key);
|
||||||
Cbuf_AddText (cmd);
|
Cbuf_AddText (cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -824,7 +859,8 @@ void Key_Event (int key, qboolean down)
|
||||||
//
|
//
|
||||||
// during demo playback, most keys bring up the main menu
|
// during demo playback, most keys bring up the main menu
|
||||||
//
|
//
|
||||||
if (cls.demoplayback && down && consolekeys[key] && key_dest == key_game)
|
if (cls.demoplayback && down && consolekeys[key] && key_dest == key_game
|
||||||
|
&& key != K_CTRL && key != K_DEL && key != K_HOME && key != K_END && key != K_TAB)
|
||||||
{
|
{
|
||||||
M_ToggleMenu_f ();
|
M_ToggleMenu_f ();
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue