mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
move the chat code from keys.c to client.c.
oops, chat just got input history, dear me
This commit is contained in:
parent
ceec1a87e2
commit
9e5c7da8e6
3 changed files with 70 additions and 69 deletions
|
@ -67,6 +67,7 @@ static old_console_t *con;
|
|||
static float con_cursorspeed = 4;
|
||||
|
||||
static cvar_t *con_notifytime; // seconds
|
||||
static cvar_t *cl_chatmode;
|
||||
|
||||
#define NUM_CON_TIMES 4
|
||||
static float con_times[NUM_CON_TIMES]; // realtime time the line was generated
|
||||
|
@ -77,9 +78,12 @@ static int con_vislines;
|
|||
static int con_notifylines; // scan lines to clear for notify lines
|
||||
|
||||
static qboolean con_debuglog;
|
||||
static qboolean chat_team;
|
||||
|
||||
#define MAXCMDLINE 256
|
||||
static inputline_t *input_line;
|
||||
static inputline_t *say_line;
|
||||
static inputline_t *say_team_line;
|
||||
|
||||
static qboolean con_initialized;
|
||||
|
||||
|
@ -143,6 +147,7 @@ MessageMode_f (void)
|
|||
return;
|
||||
chat_team = false;
|
||||
key_dest = key_message;
|
||||
game_target = IMT_CONSOLE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -152,6 +157,7 @@ MessageMode2_f (void)
|
|||
return;
|
||||
chat_team = true;
|
||||
key_dest = key_message;
|
||||
game_target = IMT_CONSOLE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -168,12 +174,16 @@ Resize (old_console_t *con)
|
|||
if (width < 1) { // video hasn't been initialized yet
|
||||
width = 38;
|
||||
con_linewidth = width;
|
||||
say_team_line->width = con_linewidth - 9;
|
||||
say_line->width = con_linewidth - 4;
|
||||
input_line->width = con_linewidth;
|
||||
con_totallines = CON_TEXTSIZE / con_linewidth;
|
||||
memset (con->text, ' ', CON_TEXTSIZE);
|
||||
} else {
|
||||
oldwidth = con_linewidth;
|
||||
con_linewidth = width;
|
||||
say_team_line->width = con_linewidth - 9;
|
||||
say_line->width = con_linewidth - 4;
|
||||
input_line->width = con_linewidth;
|
||||
oldtotallines = con_totallines;
|
||||
con_totallines = CON_TEXTSIZE / con_linewidth;
|
||||
|
@ -262,6 +272,26 @@ C_ExecLine (const char *line)
|
|||
Cbuf_AddText (line);
|
||||
}
|
||||
|
||||
static void
|
||||
C_Say (const char *line)
|
||||
{
|
||||
Cbuf_AddText ("say \"");
|
||||
Cbuf_AddText (line);
|
||||
Cbuf_AddText ("\"\n");
|
||||
key_dest = key_game;
|
||||
game_target = IMT_0;
|
||||
}
|
||||
|
||||
static void
|
||||
C_SayTeam (const char *line)
|
||||
{
|
||||
Cbuf_AddText ("say_team \"");
|
||||
Cbuf_AddText (line);
|
||||
Cbuf_AddText ("\"\n");
|
||||
key_dest = key_game;
|
||||
game_target = IMT_0;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
C_Init (void)
|
||||
|
@ -269,6 +299,9 @@ C_Init (void)
|
|||
con_notifytime = Cvar_Get ("con_notifytime", "3", CVAR_NONE, NULL,
|
||||
"How long in seconds messages are displayed "
|
||||
"on screen");
|
||||
cl_chatmode = Cvar_Get ("cl_chatmode", "2", CVAR_NONE, NULL,
|
||||
"Controls when console text will be treated as a "
|
||||
"chat message: 0 - never, 1 - always, 2 - smart");
|
||||
|
||||
con_debuglog = COM_CheckParm ("-condebug");
|
||||
|
||||
|
@ -282,6 +315,20 @@ C_Init (void)
|
|||
input_line->user_data = 0;
|
||||
input_line->draw = 0;//C_DrawInput;
|
||||
|
||||
say_line = Con_CreateInputLine (32, MAXCMDLINE, ' ');
|
||||
say_line->complete = 0;
|
||||
say_line->enter = C_Say;
|
||||
say_line->width = con_linewidth - 4;
|
||||
say_line->user_data = 0;
|
||||
say_line->draw = 0;//C_DrawInput;
|
||||
|
||||
say_team_line = Con_CreateInputLine (32, MAXCMDLINE, ' ');
|
||||
say_team_line->complete = 0;
|
||||
say_team_line->enter = C_SayTeam;
|
||||
say_team_line->width = con_linewidth - 9;
|
||||
say_team_line->user_data = 0;
|
||||
say_team_line->draw = 0;//C_DrawInput;
|
||||
|
||||
C_CheckResize ();
|
||||
|
||||
Con_Printf ("Console initialized.\n");
|
||||
|
@ -416,7 +463,21 @@ C_KeyEvent (key_t key, short unicode, qboolean down)
|
|||
{
|
||||
if (!down)
|
||||
return;
|
||||
Con_ProcessInputLine (input_line, key);
|
||||
|
||||
if (key_dest == key_message) {
|
||||
if (key == QFK_ESCAPE) {
|
||||
key_dest = key_game;
|
||||
game_target = IMT_0;
|
||||
return;
|
||||
}
|
||||
if (chat_team) {
|
||||
Con_ProcessInputLine (say_team_line, key);
|
||||
} else {
|
||||
Con_ProcessInputLine (say_line, key);
|
||||
}
|
||||
} else {
|
||||
Con_ProcessInputLine (input_line, key);
|
||||
}
|
||||
}
|
||||
|
||||
/* DRAWING */
|
||||
|
@ -491,14 +552,16 @@ DrawNotify (void)
|
|||
if (chat_team) {
|
||||
Draw_String (8, v, "say_team:");
|
||||
skip = 11;
|
||||
text = say_team_line->lines[say_team_line->edit_line]
|
||||
+ say_team_line->scroll;
|
||||
} else {
|
||||
Draw_String (8, v, "say:");
|
||||
skip = 5;
|
||||
text = say_line->lines[say_line->edit_line]
|
||||
+ say_line->scroll;
|
||||
}
|
||||
|
||||
s = chat_buffer;
|
||||
if (chat_bufferlen > (vid.width >> 3) - (skip + 1))
|
||||
s += chat_bufferlen - ((vid.width >> 3) - (skip + 1));
|
||||
s = text;
|
||||
x = 0;
|
||||
Draw_String (skip << 3, v, s);
|
||||
Draw_Character ((strlen(s) + skip) << 3, v,
|
||||
|
|
|
@ -146,7 +146,7 @@ Con_ProcessInputLine (inputline_t *il, int ch)
|
|||
break; // don't let it wrap
|
||||
il->history_line = (il->history_line + 1) % il->num_lines;
|
||||
if (il->history_line == il->edit_line) {
|
||||
il->lines[il->edit_line][0] = ']';
|
||||
il->lines[il->edit_line][0] = il->prompt_char;
|
||||
il->lines[il->edit_line][1] = 0;
|
||||
il->linepos = 1;
|
||||
} else {
|
||||
|
|
|
@ -54,24 +54,14 @@ static const char rcsid[] =
|
|||
|
||||
/* key up events are sent even if in console mode */
|
||||
|
||||
cvar_t *cl_chatmode;
|
||||
cvar_t *in_bind_imt;
|
||||
|
||||
int key_lastpress;
|
||||
|
||||
int edit_line = 0;
|
||||
int history_line = 0;
|
||||
|
||||
keydest_t key_dest = key_console;
|
||||
imt_t game_target = IMT_CONSOLE;
|
||||
|
||||
char *keybindings[IMT_LAST][QFK_LAST];
|
||||
int keydown[QFK_LAST];
|
||||
|
||||
qboolean chat_team;
|
||||
char chat_buffer[MAXCMDLINE];
|
||||
int chat_bufferlen = 0;
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
imt_t imtnum;
|
||||
|
@ -436,53 +426,6 @@ Key_Console (knum_t key, short unicode)
|
|||
Con_KeyEvent (key, unicode, keydown[key]);
|
||||
}
|
||||
|
||||
void
|
||||
Key_Message (knum_t key, short unicode)
|
||||
{
|
||||
if (keydown[key] != 1)
|
||||
return;
|
||||
|
||||
if (unicode == '\x0D' || key == QFK_RETURN) {
|
||||
if (chat_team)
|
||||
Cbuf_AddText ("say_team \"");
|
||||
else
|
||||
Cbuf_AddText ("say \"");
|
||||
Cbuf_AddText (chat_buffer);
|
||||
Cbuf_AddText ("\"\n");
|
||||
|
||||
key_dest = key_game;
|
||||
game_target = IMT_0;
|
||||
chat_bufferlen = 0;
|
||||
chat_buffer[0] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (unicode == '\x1b' || key == QFK_ESCAPE) {
|
||||
key_dest = key_game;
|
||||
game_target = IMT_0;
|
||||
chat_bufferlen = 0;
|
||||
chat_buffer[0] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (unicode == '\x08') {
|
||||
if (chat_bufferlen) {
|
||||
chat_bufferlen--;
|
||||
chat_buffer[chat_bufferlen] = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (chat_bufferlen == sizeof (chat_buffer) - 1)
|
||||
return; // all full
|
||||
|
||||
if (key < 32 || key > 127)
|
||||
return; // non printable
|
||||
|
||||
chat_buffer[chat_bufferlen++] = unicode;
|
||||
chat_buffer[chat_bufferlen] = 0;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
||||
/*
|
||||
|
@ -782,15 +725,13 @@ Key_Event (knum_t key, short unicode, qboolean down)
|
|||
else
|
||||
keydown[key] = 0;
|
||||
|
||||
key_lastpress = key;
|
||||
|
||||
// handle escape specially, so the user can never unbind it
|
||||
if (unicode == '\x1b' || key == QFK_ESCAPE) {
|
||||
if (!down || (keydown[key] > 1))
|
||||
return;
|
||||
switch (key_dest) {
|
||||
case key_message:
|
||||
Key_Message (key, unicode);
|
||||
Key_Console (key, unicode);
|
||||
break;
|
||||
case key_game:
|
||||
case key_console:
|
||||
|
@ -808,7 +749,7 @@ Key_Event (knum_t key, short unicode, qboolean down)
|
|||
// if not a consolekey, send to the interpreter no matter what mode is
|
||||
switch (key_dest) {
|
||||
case key_message:
|
||||
Key_Message (key, unicode);
|
||||
Key_Console (key, unicode);
|
||||
break;
|
||||
case key_game:
|
||||
Key_Game (key, unicode);
|
||||
|
@ -858,9 +799,6 @@ Key_Init (void)
|
|||
void
|
||||
Key_Init_Cvars (void)
|
||||
{
|
||||
cl_chatmode = Cvar_Get ("cl_chatmode", "2", CVAR_NONE, NULL,
|
||||
"Controls when console text will be treated as a "
|
||||
"chat message: 0 - never, 1 - always, 2 - smart");
|
||||
in_bind_imt = Cvar_Get ("in_bind_imt", "imt_default", CVAR_ARCHIVE,
|
||||
in_bind_imt_f, "imt parameter for the bind and "
|
||||
"unbind wrappers to in_bind and in_unbind");
|
||||
|
|
Loading…
Reference in a new issue