2001-07-16 21:39:50 +00:00
|
|
|
/*
|
|
|
|
console.c
|
|
|
|
|
|
|
|
(description)
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
2001-09-28 06:26:31 +00:00
|
|
|
static const char rcsid[] =
|
|
|
|
"$Id$";
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2002-01-16 21:53:42 +00:00
|
|
|
#include <errno.h>
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
#include "QF/cbuf.h"
|
2001-07-16 21:39:50 +00:00
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/draw.h"
|
2002-03-18 16:47:04 +00:00
|
|
|
#include "QF/dstring.h"
|
2001-07-16 21:39:50 +00:00
|
|
|
#include "QF/input.h"
|
|
|
|
#include "QF/keys.h"
|
2001-07-20 18:51:00 +00:00
|
|
|
#include "QF/plugin.h"
|
2001-07-16 21:39:50 +00:00
|
|
|
#include "QF/qargs.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2001-07-16 21:39:50 +00:00
|
|
|
#include "QF/screen.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/va.h"
|
2001-07-20 18:51:00 +00:00
|
|
|
#include "QF/vid.h"
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2001-07-20 18:51:00 +00:00
|
|
|
#include "compat.h"
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2002-08-20 21:19:53 +00:00
|
|
|
// XXX check InputLine.h in ruamoko/include
|
|
|
|
typedef struct {
|
|
|
|
int x, y;
|
|
|
|
int cursor;
|
|
|
|
} il_data_t;
|
|
|
|
|
2001-09-19 03:39:04 +00:00
|
|
|
static general_data_t plugin_info_general_data;
|
2002-01-18 19:19:33 +00:00
|
|
|
console_data_t con_data;
|
2001-09-19 03:39:04 +00:00
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static old_console_t con_main;
|
|
|
|
static old_console_t con_chat;
|
|
|
|
static old_console_t *con;
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static float con_cursorspeed = 4;
|
|
|
|
|
|
|
|
static cvar_t *con_notifytime; // seconds
|
2002-01-16 23:06:28 +00:00
|
|
|
static cvar_t *cl_chatmode;
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
#define NUM_CON_TIMES 4
|
2002-01-16 21:53:42 +00:00
|
|
|
static float con_times[NUM_CON_TIMES]; // realtime time the line was generated
|
2001-07-16 21:39:50 +00:00
|
|
|
// for transparent notify lines
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static int con_totallines; // total lines in console scrollback
|
|
|
|
static int con_vislines;
|
|
|
|
static int con_notifylines; // scan lines to clear for notify lines
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static qboolean con_debuglog;
|
2002-01-16 23:06:28 +00:00
|
|
|
static qboolean chat_team;
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
#define MAXCMDLINE 256
|
2002-01-16 21:53:42 +00:00
|
|
|
static inputline_t *input_line;
|
2002-01-16 23:06:28 +00:00
|
|
|
static inputline_t *say_line;
|
|
|
|
static inputline_t *say_team_line;
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static qboolean con_initialized;
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static void
|
|
|
|
ClearNotify (void)
|
2002-01-16 16:27:56 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_CON_TIMES; i++)
|
|
|
|
con_times[i] = 0;
|
|
|
|
}
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
ToggleConsole_f (void)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
2002-08-28 16:02:43 +00:00
|
|
|
Con_ClearTyping (input_line, 0);
|
2002-01-16 16:27:56 +00:00
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
if (key_dest == key_console && !con_data.force_commandline) {
|
|
|
|
key_dest = key_game;
|
|
|
|
game_target = IMT_0;
|
|
|
|
} else {
|
2001-07-16 21:39:50 +00:00
|
|
|
key_dest = key_console;
|
2002-01-16 21:53:42 +00:00
|
|
|
game_target = IMT_CONSOLE;
|
|
|
|
}
|
2002-01-16 16:27:56 +00:00
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
ClearNotify ();
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static void
|
|
|
|
ToggleChat_f (void)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
2002-08-28 16:02:43 +00:00
|
|
|
Con_ClearTyping (input_line, 0);
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
if (key_dest == key_console && !con_data.force_commandline) {
|
|
|
|
key_dest = key_game;
|
|
|
|
game_target = IMT_0;
|
2001-08-16 09:19:36 +00:00
|
|
|
} else {
|
2001-07-16 21:39:50 +00:00
|
|
|
key_dest = key_console;
|
2001-08-17 07:06:01 +00:00
|
|
|
game_target = IMT_CONSOLE;
|
2001-08-16 09:19:36 +00:00
|
|
|
}
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
ClearNotify ();
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static void
|
|
|
|
Clear_f (void)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
|
|
|
con_main.numlines = 0;
|
|
|
|
con_chat.numlines = 0;
|
|
|
|
memset (con_main.text, ' ', CON_TEXTSIZE);
|
|
|
|
memset (con_chat.text, ' ', CON_TEXTSIZE);
|
|
|
|
con_main.display = con_main.current;
|
|
|
|
}
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static void
|
|
|
|
MessageMode_f (void)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
2002-01-16 16:27:56 +00:00
|
|
|
if (con_data.force_commandline)
|
2001-07-16 21:39:50 +00:00
|
|
|
return;
|
|
|
|
chat_team = false;
|
|
|
|
key_dest = key_message;
|
2002-01-16 23:06:28 +00:00
|
|
|
game_target = IMT_CONSOLE;
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static void
|
|
|
|
MessageMode2_f (void)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
2002-01-16 16:27:56 +00:00
|
|
|
if (con_data.force_commandline)
|
2001-07-16 21:39:50 +00:00
|
|
|
return;
|
|
|
|
chat_team = true;
|
|
|
|
key_dest = key_message;
|
2002-01-16 23:06:28 +00:00
|
|
|
game_target = IMT_CONSOLE;
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static void
|
|
|
|
Resize (old_console_t *con)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
2001-09-10 12:56:23 +00:00
|
|
|
char tbuf[CON_TEXTSIZE];
|
|
|
|
int width, oldwidth, oldtotallines, numlines, numchars, i, j;
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
width = (vid.width >> 3) - 2;
|
|
|
|
|
|
|
|
if (width == con_linewidth)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (width < 1) { // video hasn't been initialized yet
|
|
|
|
width = 38;
|
|
|
|
con_linewidth = width;
|
|
|
|
con_totallines = CON_TEXTSIZE / con_linewidth;
|
|
|
|
memset (con->text, ' ', CON_TEXTSIZE);
|
|
|
|
} else {
|
|
|
|
oldwidth = con_linewidth;
|
|
|
|
con_linewidth = width;
|
|
|
|
oldtotallines = con_totallines;
|
|
|
|
con_totallines = CON_TEXTSIZE / con_linewidth;
|
|
|
|
numlines = oldtotallines;
|
|
|
|
|
|
|
|
if (con_totallines < numlines)
|
|
|
|
numlines = con_totallines;
|
|
|
|
|
|
|
|
numchars = oldwidth;
|
|
|
|
|
|
|
|
if (con_linewidth < numchars)
|
|
|
|
numchars = con_linewidth;
|
|
|
|
|
|
|
|
memcpy (tbuf, con->text, CON_TEXTSIZE);
|
|
|
|
memset (con->text, ' ', CON_TEXTSIZE);
|
|
|
|
|
|
|
|
for (i = 0; i < numlines; i++) {
|
|
|
|
for (j = 0; j < numchars; j++) {
|
|
|
|
con->text[(con_totallines - 1 - i) * con_linewidth + j] =
|
|
|
|
tbuf[((con->current - i + oldtotallines) %
|
|
|
|
oldtotallines) * oldwidth + j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
ClearNotify ();
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
2002-02-16 04:21:03 +00:00
|
|
|
say_team_line->width = con_linewidth - 9;
|
|
|
|
say_line->width = con_linewidth - 4;
|
|
|
|
input_line->width = con_linewidth;
|
|
|
|
|
2001-07-16 21:39:50 +00:00
|
|
|
con->current = con_totallines - 1;
|
|
|
|
con->display = con->current;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-01-16 21:53:42 +00:00
|
|
|
C_CheckResize
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
If the line width has changed, reformat the buffer.
|
|
|
|
*/
|
2002-01-16 21:53:42 +00:00
|
|
|
static void
|
|
|
|
C_CheckResize (void)
|
|
|
|
{
|
|
|
|
Resize (&con_main);
|
|
|
|
Resize (&con_chat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Condump_f (void)
|
|
|
|
{
|
|
|
|
int line = con->current - con->numlines;
|
|
|
|
const char *start, *end;
|
2002-08-27 07:16:28 +00:00
|
|
|
QFile *file;
|
2002-01-16 21:53:42 +00:00
|
|
|
char name[MAX_OSPATH];
|
|
|
|
|
|
|
|
if (Cmd_Argc () != 2) {
|
|
|
|
Con_Printf ("usage: condump <filename>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strchr (Cmd_Argv (1), '/') || strchr (Cmd_Argv (1), '\\')) {
|
|
|
|
Con_Printf ("invalid character in filename\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
snprintf (name, sizeof (name), "%s/%s.txt", com_gamedir, Cmd_Argv (1));
|
|
|
|
|
|
|
|
if (!(file = Qopen (name, "wt"))) {
|
|
|
|
Con_Printf ("could not open %s for writing: %s\n", name,
|
|
|
|
strerror (errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (line < con->current) {
|
|
|
|
start = &con->text[(line % con_totallines) * con_linewidth];
|
|
|
|
end = start + con_linewidth;
|
|
|
|
while (end > start && end[-1] != ' ')
|
|
|
|
end--;
|
|
|
|
Qprintf (file, "%.*s\n", (int)(end - start), start);
|
|
|
|
line++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qclose (file);
|
|
|
|
}
|
|
|
|
|
2002-02-28 04:12:20 +00:00
|
|
|
qboolean
|
|
|
|
CheckForCommand (const char *line)
|
|
|
|
{
|
|
|
|
char command[128];
|
|
|
|
const char *cmd;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 127; i++)
|
|
|
|
|
|
|
|
if (line[i] <= ' ')
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
command[i] = line[i];
|
|
|
|
command[i] = 0;
|
|
|
|
|
|
|
|
cmd = Cmd_CompleteCommand (command);
|
|
|
|
if (!cmd || strcmp (cmd, command))
|
|
|
|
cmd = Cvar_CompleteVariable (command);
|
|
|
|
if (!cmd || strcmp (cmd, command))
|
|
|
|
return false; // just a chat message
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static void
|
|
|
|
C_ExecLine (const char *line)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
2002-02-28 04:12:20 +00:00
|
|
|
if (line[0] == '/' && line [1] == '/')
|
|
|
|
goto no_lf;
|
2002-03-03 08:29:28 +00:00
|
|
|
else if (line[0] == '|')
|
2002-07-31 05:19:03 +00:00
|
|
|
Cbuf_AddText (con_data.cbuf, line);
|
2002-02-28 04:12:20 +00:00
|
|
|
else if (line[0] == '\\' || line[0] == '/')
|
2002-07-31 05:19:03 +00:00
|
|
|
Cbuf_AddText (con_data.cbuf, line + 1);
|
2002-02-28 04:12:20 +00:00
|
|
|
else if (cl_chatmode->int_val != 1 && CheckForCommand (line))
|
2002-07-31 05:19:03 +00:00
|
|
|
Cbuf_AddText (con_data.cbuf, line);
|
2002-02-28 04:12:20 +00:00
|
|
|
else if (cl_chatmode->int_val) {
|
2002-07-31 05:19:03 +00:00
|
|
|
Cbuf_AddText (con_data.cbuf, "say ");
|
|
|
|
Cbuf_AddText (con_data.cbuf, line);
|
2002-02-28 04:12:20 +00:00
|
|
|
} else
|
2002-07-31 05:19:03 +00:00
|
|
|
Cbuf_AddText (con_data.cbuf, line);
|
|
|
|
Cbuf_AddText (con_data.cbuf, "\n");
|
2002-02-28 04:12:20 +00:00
|
|
|
no_lf:
|
|
|
|
Con_Printf ("%s\n", line);
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
|
|
|
|
2002-01-16 23:06:28 +00:00
|
|
|
static void
|
|
|
|
C_Say (const char *line)
|
|
|
|
{
|
2002-08-28 16:02:43 +00:00
|
|
|
if (!*line)
|
|
|
|
return;
|
2002-08-28 21:03:24 +00:00
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
Cbuf_AddText (con_data.cbuf, "say \"");
|
2002-08-28 21:03:24 +00:00
|
|
|
Cbuf_AddText (con_data.cbuf, line);
|
2002-07-31 05:19:03 +00:00
|
|
|
Cbuf_AddText (con_data.cbuf, "\"\n");
|
2002-01-16 23:06:28 +00:00
|
|
|
key_dest = key_game;
|
|
|
|
game_target = IMT_0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
C_SayTeam (const char *line)
|
|
|
|
{
|
2002-08-28 16:02:43 +00:00
|
|
|
if (!*line)
|
|
|
|
return;
|
2002-08-28 21:03:24 +00:00
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
Cbuf_AddText (con_data.cbuf, "say_team \"");
|
2002-08-28 21:03:24 +00:00
|
|
|
Cbuf_AddText (con_data.cbuf, line);
|
2002-07-31 05:19:03 +00:00
|
|
|
Cbuf_AddText (con_data.cbuf, "\"\n");
|
2002-01-16 23:06:28 +00:00
|
|
|
key_dest = key_game;
|
|
|
|
game_target = IMT_0;
|
|
|
|
}
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
|
2001-07-20 18:51:00 +00:00
|
|
|
static void
|
|
|
|
C_Init (void)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
2002-01-18 19:19:33 +00:00
|
|
|
Menu_Init ();
|
|
|
|
|
2002-01-16 16:27:56 +00:00
|
|
|
con_notifytime = Cvar_Get ("con_notifytime", "3", CVAR_NONE, NULL,
|
|
|
|
"How long in seconds messages are displayed "
|
|
|
|
"on screen");
|
2002-01-16 23:06:28 +00:00
|
|
|
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");
|
2002-01-16 16:27:56 +00:00
|
|
|
|
2001-07-16 21:39:50 +00:00
|
|
|
con_debuglog = COM_CheckParm ("-condebug");
|
|
|
|
|
|
|
|
con = &con_main;
|
|
|
|
con_linewidth = -1;
|
2002-01-16 21:53:42 +00:00
|
|
|
|
|
|
|
input_line = Con_CreateInputLine (32, MAXCMDLINE, ']');
|
|
|
|
input_line->complete = Con_BasicCompleteCommandLine;
|
|
|
|
input_line->enter = C_ExecLine;
|
|
|
|
input_line->width = con_linewidth;
|
|
|
|
input_line->user_data = 0;
|
2002-08-20 21:19:53 +00:00
|
|
|
input_line->draw = 0;
|
2002-01-16 21:53:42 +00:00
|
|
|
|
2002-01-16 23:06:28 +00:00
|
|
|
say_line = Con_CreateInputLine (32, MAXCMDLINE, ' ');
|
|
|
|
say_line->complete = 0;
|
|
|
|
say_line->enter = C_Say;
|
2002-01-17 00:05:30 +00:00
|
|
|
say_line->width = con_linewidth - 5;
|
2002-01-16 23:06:28 +00:00
|
|
|
say_line->user_data = 0;
|
2002-08-20 21:19:53 +00:00
|
|
|
say_line->draw = 0;
|
2002-01-16 23:06:28 +00:00
|
|
|
|
|
|
|
say_team_line = Con_CreateInputLine (32, MAXCMDLINE, ' ');
|
|
|
|
say_team_line->complete = 0;
|
|
|
|
say_team_line->enter = C_SayTeam;
|
2002-01-17 00:05:30 +00:00
|
|
|
say_team_line->width = con_linewidth - 10;
|
2002-01-16 23:06:28 +00:00
|
|
|
say_team_line->user_data = 0;
|
2002-08-20 21:19:53 +00:00
|
|
|
say_team_line->draw = 0;
|
2002-01-16 23:06:28 +00:00
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
C_CheckResize ();
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
Con_Printf ("Console initialized.\n");
|
|
|
|
|
|
|
|
// register our commands
|
2002-01-16 21:53:42 +00:00
|
|
|
Cmd_AddCommand ("toggleconsole", ToggleConsole_f,
|
2001-07-16 21:39:50 +00:00
|
|
|
"Toggle the console up and down");
|
2002-01-16 21:53:42 +00:00
|
|
|
Cmd_AddCommand ("togglechat", ToggleChat_f,
|
2001-07-16 21:39:50 +00:00
|
|
|
"Toggle the console up and down");
|
2002-01-16 21:53:42 +00:00
|
|
|
Cmd_AddCommand ("messagemode", MessageMode_f,
|
2001-07-16 21:39:50 +00:00
|
|
|
"Prompt to send a message to everyone");
|
2002-01-16 21:53:42 +00:00
|
|
|
Cmd_AddCommand ("messagemode2", MessageMode2_f,
|
2001-07-16 21:39:50 +00:00
|
|
|
"Prompt to send a message to only people on your team");
|
2002-01-16 21:53:42 +00:00
|
|
|
Cmd_AddCommand ("clear", Clear_f, "Clear the console");
|
|
|
|
Cmd_AddCommand ("condump", Condump_f, "dump the console text to a "
|
|
|
|
"file");
|
2001-07-16 21:39:50 +00:00
|
|
|
con_initialized = true;
|
|
|
|
}
|
|
|
|
|
2001-07-20 18:51:00 +00:00
|
|
|
static void
|
|
|
|
C_Shutdown (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static void
|
|
|
|
Linefeed (void)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
|
|
|
con->x = 0;
|
|
|
|
if (con->display == con->current)
|
|
|
|
con->display++;
|
|
|
|
con->current++;
|
|
|
|
if (con->numlines < con_totallines)
|
|
|
|
con->numlines++;
|
|
|
|
memset (&con->text[(con->current % con_totallines) * con_linewidth],
|
|
|
|
' ', con_linewidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-07-20 18:51:00 +00:00
|
|
|
C_Print
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
Handles cursor positioning, line wrapping, etc
|
|
|
|
All console printing must go through this in order to be logged to disk
|
|
|
|
If no console is visible, the notify window will pop up.
|
|
|
|
*/
|
|
|
|
void
|
2001-07-20 18:51:00 +00:00
|
|
|
C_Print (const char *fmt, va_list args)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
2002-01-16 21:53:42 +00:00
|
|
|
char *s;
|
2002-03-08 23:11:42 +00:00
|
|
|
static dstring_t *buffer;
|
|
|
|
int mask, c, l, y;
|
|
|
|
static int cr;
|
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
buffer = dstring_new ();
|
|
|
|
|
|
|
|
dvsprintf (buffer, fmt, args);
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
// log all messages to file
|
|
|
|
if (con_debuglog)
|
2002-03-08 23:11:42 +00:00
|
|
|
Sys_DebugLog (va ("%s/qconsole.log", com_gamedir), "%s", buffer->str);
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
if (!con_initialized)
|
|
|
|
return;
|
|
|
|
|
2002-03-08 23:11:42 +00:00
|
|
|
s = buffer->str;
|
2002-01-16 21:53:42 +00:00
|
|
|
|
|
|
|
if (s[0] == 1 || s[0] == 2) {
|
2001-07-16 21:39:50 +00:00
|
|
|
mask = 128; // go to colored text
|
2002-01-16 21:53:42 +00:00
|
|
|
s++;
|
2001-07-16 21:39:50 +00:00
|
|
|
} else
|
|
|
|
mask = 0;
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
while ((c = (byte)*s)) {
|
2001-07-16 21:39:50 +00:00
|
|
|
// count word length
|
|
|
|
for (l = 0; l < con_linewidth; l++)
|
2002-01-16 21:53:42 +00:00
|
|
|
if (s[l] <= ' ')
|
2001-07-16 21:39:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// word wrap
|
|
|
|
if (l != con_linewidth && (con->x + l > con_linewidth))
|
|
|
|
con->x = 0;
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
*s++ = sys_char_map[c];
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
if (cr) {
|
|
|
|
con->current--;
|
|
|
|
cr = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!con->x) {
|
2002-01-16 21:53:42 +00:00
|
|
|
Linefeed ();
|
2001-07-16 21:39:50 +00:00
|
|
|
// mark time for transparent overlay
|
|
|
|
if (con->current >= 0)
|
2002-01-16 21:53:42 +00:00
|
|
|
con_times[con->current % NUM_CON_TIMES] = *con_data.realtime;
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case '\n':
|
|
|
|
con->x = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\r':
|
|
|
|
con->x = 0;
|
|
|
|
cr = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: // display character and advance
|
|
|
|
y = con->current % con_totallines;
|
2002-01-16 21:53:42 +00:00
|
|
|
con->text[y * con_linewidth + con->x] = c | mask | con_data.ormask;
|
2001-07-16 21:39:50 +00:00
|
|
|
con->x++;
|
|
|
|
if (con->x >= con_linewidth)
|
|
|
|
con->x = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2002-01-16 21:53:42 +00:00
|
|
|
|
|
|
|
// echo to debugging console
|
2002-03-08 23:11:42 +00:00
|
|
|
if ((byte)buffer->str[0] > 2)
|
|
|
|
fputs (buffer->str, stdout);
|
|
|
|
else if ((byte)buffer->str[0])
|
|
|
|
fputs (buffer->str + 1, stdout);
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static void
|
2002-01-18 22:02:59 +00:00
|
|
|
C_KeyEvent (knum_t key, short unicode, qboolean down)
|
2002-01-16 21:53:42 +00:00
|
|
|
{
|
2002-01-17 21:27:31 +00:00
|
|
|
inputline_t *il;
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
if (!down)
|
|
|
|
return;
|
2002-01-16 23:06:28 +00:00
|
|
|
|
2002-01-18 23:45:28 +00:00
|
|
|
if (down && (key == QFK_ESCAPE || unicode == '\x1b')) {
|
|
|
|
switch (key_dest) {
|
|
|
|
case key_menu:
|
|
|
|
Menu_Leave ();
|
|
|
|
return;
|
|
|
|
case key_message:
|
2002-08-28 16:02:43 +00:00
|
|
|
if (chat_team) {
|
|
|
|
Con_ClearTyping (say_team_line, 1);
|
|
|
|
} else {
|
|
|
|
Con_ClearTyping (say_line, 1);
|
|
|
|
}
|
2002-01-18 23:45:28 +00:00
|
|
|
key_dest = key_game;
|
|
|
|
game_target = IMT_0;
|
|
|
|
return;
|
|
|
|
case key_console:
|
|
|
|
if (!con_data.force_commandline) {
|
2002-07-31 05:19:03 +00:00
|
|
|
Cbuf_AddText (con_data.cbuf, "toggleconsole\n");
|
2002-01-18 23:45:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case key_game:
|
|
|
|
Menu_Enter ();
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
Sys_Error ("Bad key_dest");
|
2002-01-16 23:06:28 +00:00
|
|
|
}
|
2002-01-18 23:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (key_dest == key_menu) {
|
|
|
|
Menu_KeyEvent (key, unicode, down);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key_dest == key_message) {
|
2002-01-16 23:06:28 +00:00
|
|
|
if (chat_team) {
|
2002-01-17 21:27:31 +00:00
|
|
|
il = say_team_line;
|
2002-01-16 23:06:28 +00:00
|
|
|
} else {
|
2002-01-17 21:27:31 +00:00
|
|
|
il = say_line;
|
2002-01-16 23:06:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-01-17 21:27:31 +00:00
|
|
|
switch (key) {
|
|
|
|
case QFK_PAGEUP:
|
|
|
|
if (keydown[QFK_RCTRL] || keydown[QFK_LCTRL])
|
|
|
|
con->display = 0;
|
|
|
|
else
|
|
|
|
con->display -= 10;
|
|
|
|
if (con->display < con->current - con->numlines)
|
|
|
|
con->display = con->current - con->numlines;
|
|
|
|
return;
|
|
|
|
case QFK_PAGEDOWN:
|
|
|
|
if (keydown[QFK_RCTRL] || keydown[QFK_LCTRL])
|
|
|
|
con->display = con->current;
|
|
|
|
else
|
|
|
|
con->display += 10;
|
|
|
|
if (con->display > con->current)
|
|
|
|
con->display = con->current;
|
|
|
|
return;
|
|
|
|
case QFM_WHEEL_UP:
|
|
|
|
con->display -= 3;
|
|
|
|
if (con->display < con->current - con->numlines)
|
|
|
|
con->display = con->current - con->numlines;
|
|
|
|
return;
|
|
|
|
case QFM_WHEEL_DOWN:
|
|
|
|
con->display += 3;
|
|
|
|
if (con->display > con->current)
|
|
|
|
con->display = con->current;
|
|
|
|
return;
|
2002-01-18 22:02:59 +00:00
|
|
|
default:
|
|
|
|
break;
|
2002-01-17 21:27:31 +00:00
|
|
|
}
|
|
|
|
il = input_line;
|
2002-01-16 23:06:28 +00:00
|
|
|
}
|
2002-01-17 21:49:47 +00:00
|
|
|
Con_ProcessInputLine (il, key >= 256 ? key : unicode);
|
2002-01-16 21:53:42 +00:00
|
|
|
}
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
/* DRAWING */
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2002-01-17 02:27:53 +00:00
|
|
|
static void
|
2002-08-20 21:19:53 +00:00
|
|
|
DrawInputLine (int x, int y, int cursor, inputline_t *il)
|
2002-01-17 02:27:53 +00:00
|
|
|
{
|
|
|
|
const char *s = il->lines[il->edit_line] + il->scroll;
|
|
|
|
|
|
|
|
if (il->scroll) {
|
|
|
|
Draw_Character (x, y, '<' | 0x80);
|
|
|
|
Draw_nString (x + 8, y, s + 1, il->width - 2);
|
|
|
|
} else {
|
|
|
|
Draw_nString (x, y, s, il->width - 1);
|
|
|
|
}
|
2002-08-20 21:19:53 +00:00
|
|
|
if (cursor) {
|
|
|
|
float t = *con_data.realtime * con_cursorspeed;
|
|
|
|
int ch = 10 + ((int) (t) & 1);
|
|
|
|
Draw_Character (x + ((il->linepos - il->scroll) << 3), y, ch);
|
|
|
|
}
|
2002-01-17 02:27:53 +00:00
|
|
|
if (strlen (s) >= il->width)
|
|
|
|
Draw_Character (x + ((il->width - 1) << 3), y, '>' | 0x80);
|
|
|
|
}
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2002-08-20 21:19:53 +00:00
|
|
|
void
|
|
|
|
C_DrawInputLine (inputline_t *il)
|
|
|
|
{
|
|
|
|
il_data_t *data = il->user_data;
|
|
|
|
DrawInputLine (data->x, data->y, data->cursor, il);
|
|
|
|
}
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static void
|
|
|
|
DrawInput (void)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
2002-01-20 00:06:08 +00:00
|
|
|
if (key_dest != key_console)// && !con_data.force_commandline)
|
2001-07-16 21:39:50 +00:00
|
|
|
return; // don't draw anything (always draw if not active)
|
|
|
|
|
2002-08-20 21:19:53 +00:00
|
|
|
DrawInputLine (8, con_vislines - 22, 1, input_line);
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-01-16 21:53:42 +00:00
|
|
|
DrawNotify
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
Draws the last few lines of output transparently over the game top
|
|
|
|
*/
|
2002-01-16 21:53:42 +00:00
|
|
|
static void
|
|
|
|
DrawNotify (void)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
2002-01-17 02:27:53 +00:00
|
|
|
int i, v;
|
|
|
|
char *text;
|
2001-09-10 12:56:23 +00:00
|
|
|
float time;
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
v = 0;
|
|
|
|
for (i = con->current - NUM_CON_TIMES + 1; i <= con->current; i++) {
|
|
|
|
if (i < 0)
|
|
|
|
continue;
|
|
|
|
time = con_times[i % NUM_CON_TIMES];
|
|
|
|
if (time == 0)
|
|
|
|
continue;
|
2002-01-16 21:53:42 +00:00
|
|
|
time = *con_data.realtime - time;
|
2001-07-16 21:39:50 +00:00
|
|
|
if (time > con_notifytime->value)
|
|
|
|
continue;
|
|
|
|
text = con->text + (i % con_totallines) * con_linewidth;
|
|
|
|
|
|
|
|
clearnotify = 0;
|
|
|
|
scr_copytop = 1;
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
Draw_nString (8, v, text, con_linewidth);
|
2001-07-16 21:39:50 +00:00
|
|
|
v += 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key_dest == key_message) {
|
|
|
|
clearnotify = 0;
|
|
|
|
scr_copytop = 1;
|
|
|
|
|
|
|
|
if (chat_team) {
|
2001-08-25 02:47:11 +00:00
|
|
|
Draw_String (8, v, "say_team:");
|
2002-08-20 21:19:53 +00:00
|
|
|
DrawInputLine (80, v, 1, say_team_line);
|
2001-07-16 21:39:50 +00:00
|
|
|
} else {
|
2001-08-25 02:47:11 +00:00
|
|
|
Draw_String (8, v, "say:");
|
2002-08-20 21:19:53 +00:00
|
|
|
DrawInputLine (40, v, 1, say_line);
|
2002-01-17 00:05:30 +00:00
|
|
|
}
|
2001-07-16 21:39:50 +00:00
|
|
|
v += 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v > con_notifylines)
|
|
|
|
con_notifylines = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-01-16 21:53:42 +00:00
|
|
|
DrawConsole
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
Draws the console with the solid background
|
|
|
|
*/
|
2002-01-16 21:53:42 +00:00
|
|
|
static void
|
|
|
|
DrawConsole (int lines)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
2001-09-10 12:56:23 +00:00
|
|
|
char *text;
|
|
|
|
int row, rows, i, x, y;
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
if (lines <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// draw the background
|
|
|
|
Draw_ConsoleBackground (lines);
|
|
|
|
|
|
|
|
// draw the text
|
|
|
|
con_vislines = lines;
|
|
|
|
|
|
|
|
// changed to line things up better
|
|
|
|
rows = (lines - 22) >> 3; // rows of text to draw
|
|
|
|
|
|
|
|
y = lines - 30;
|
|
|
|
|
|
|
|
// draw from the bottom up
|
|
|
|
if (con->display != con->current) {
|
|
|
|
// draw arrows to show the buffer is backscrolled
|
|
|
|
for (x = 0; x < con_linewidth; x += 4)
|
2001-08-25 02:47:11 +00:00
|
|
|
Draw_Character ((x + 1) << 3, y, '^');
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
y -= 8;
|
|
|
|
rows--;
|
|
|
|
}
|
|
|
|
|
|
|
|
row = con->display;
|
|
|
|
for (i = 0; i < rows; i++, y -= 8, row--) {
|
|
|
|
if (row < 0)
|
|
|
|
break;
|
|
|
|
if (con->current - row >= con_totallines)
|
|
|
|
break; // past scrollback wrap point
|
|
|
|
|
|
|
|
text = con->text + (row % con_totallines) * con_linewidth;
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
Draw_nString(8, y, text, con_linewidth);
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// draw the input prompt, user text, and cursor if desired
|
2002-01-16 21:53:42 +00:00
|
|
|
DrawInput ();
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static void
|
|
|
|
DrawDownload (int lines)
|
2001-07-16 21:39:50 +00:00
|
|
|
{
|
2001-09-10 12:56:23 +00:00
|
|
|
char dlbar[1024];
|
2001-09-19 03:39:04 +00:00
|
|
|
const char *text;
|
|
|
|
int i, j, x, y, n;
|
2001-07-16 21:39:50 +00:00
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
if (!con_data.dl_name || !*con_data.dl_name)
|
2001-07-16 21:39:50 +00:00
|
|
|
return;
|
|
|
|
|
2001-09-19 03:39:04 +00:00
|
|
|
text = COM_SkipPath(con_data.dl_name);
|
2001-07-16 21:39:50 +00:00
|
|
|
|
|
|
|
x = con_linewidth - ((con_linewidth * 7) / 40);
|
|
|
|
y = x - strlen (text) - 8;
|
|
|
|
i = con_linewidth / 3;
|
|
|
|
if (strlen (text) > i) {
|
|
|
|
y = x - i - 11;
|
|
|
|
strncpy (dlbar, text, i);
|
|
|
|
dlbar[i] = 0;
|
|
|
|
strncat (dlbar, "...", sizeof (dlbar) - strlen (dlbar));
|
|
|
|
} else
|
|
|
|
strncpy (dlbar, text, sizeof (dlbar));
|
|
|
|
strncat (dlbar, ": ", sizeof (dlbar) - strlen (dlbar));
|
|
|
|
i = strlen (dlbar);
|
|
|
|
dlbar[i++] = '\x80';
|
|
|
|
// where's the dot go?
|
2001-09-19 03:39:04 +00:00
|
|
|
if (con_data.dl_percent == 0)
|
2001-07-16 21:39:50 +00:00
|
|
|
n = 0;
|
|
|
|
else
|
2002-01-16 21:53:42 +00:00
|
|
|
n = y * *con_data.dl_percent / 100;
|
2001-07-16 21:39:50 +00:00
|
|
|
for (j = 0; j < y; j++)
|
|
|
|
if (j == n)
|
|
|
|
dlbar[i++] = '\x83';
|
|
|
|
else
|
|
|
|
dlbar[i++] = '\x81';
|
|
|
|
dlbar[i++] = '\x82';
|
|
|
|
dlbar[i] = 0;
|
|
|
|
|
|
|
|
snprintf (dlbar + strlen (dlbar), sizeof (dlbar) - strlen (dlbar),
|
2002-01-16 21:53:42 +00:00
|
|
|
" %02d%%", *con_data.dl_percent);
|
2001-09-19 03:39:04 +00:00
|
|
|
|
2001-07-16 21:39:50 +00:00
|
|
|
// draw it
|
|
|
|
y = lines - 22 + 8;
|
|
|
|
for (i = 0; i < strlen (dlbar); i++)
|
2001-08-25 02:47:11 +00:00
|
|
|
Draw_Character ((i + 1) << 3, y, dlbar[i]);
|
2001-07-16 21:39:50 +00:00
|
|
|
}
|
2001-07-20 18:51:00 +00:00
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
static void
|
|
|
|
C_DrawConsole (int lines)
|
|
|
|
{
|
|
|
|
if (lines) {
|
|
|
|
DrawConsole (lines);
|
|
|
|
DrawDownload (lines);
|
|
|
|
} else {
|
|
|
|
if (key_dest == key_game || key_dest == key_message)
|
|
|
|
DrawNotify (); // only draw notify in game
|
|
|
|
}
|
2002-01-18 23:45:28 +00:00
|
|
|
if (key_dest == key_menu)
|
|
|
|
Menu_Draw ();
|
2002-01-16 21:53:42 +00:00
|
|
|
}
|
|
|
|
|
2001-09-16 05:41:28 +00:00
|
|
|
static void
|
|
|
|
C_ProcessInput (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-01-18 19:19:33 +00:00
|
|
|
static void
|
|
|
|
C_NewMap (void)
|
|
|
|
{
|
|
|
|
static char old_gamedir[MAX_OSPATH];
|
|
|
|
|
|
|
|
if (!strequal (old_gamedir, com_gamedir))
|
|
|
|
Menu_Load ();
|
2002-08-26 19:50:00 +00:00
|
|
|
strcpy (old_gamedir, com_gamedir);
|
2002-01-18 19:19:33 +00:00
|
|
|
}
|
|
|
|
|
2001-07-20 18:51:00 +00:00
|
|
|
static general_funcs_t plugin_info_general_funcs = {
|
|
|
|
C_Init,
|
|
|
|
C_Shutdown,
|
|
|
|
};
|
|
|
|
|
|
|
|
static console_funcs_t plugin_info_console_funcs = {
|
|
|
|
C_Print,
|
2001-09-16 05:41:28 +00:00
|
|
|
C_ProcessInput,
|
2002-01-16 21:53:42 +00:00
|
|
|
C_KeyEvent,
|
|
|
|
C_DrawConsole,
|
|
|
|
C_CheckResize,
|
2002-01-18 19:19:33 +00:00
|
|
|
C_NewMap,
|
2001-07-20 18:51:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static plugin_funcs_t plugin_info_funcs = {
|
|
|
|
&plugin_info_general_funcs,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&plugin_info_console_funcs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static plugin_data_t plugin_info_data = {
|
|
|
|
&plugin_info_general_data,
|
|
|
|
0,
|
|
|
|
0,
|
2002-01-18 19:19:33 +00:00
|
|
|
&con_data,
|
2001-07-20 18:51:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static plugin_t plugin_info = {
|
|
|
|
qfp_console,
|
|
|
|
0,
|
|
|
|
QFPLUGIN_VERSION,
|
|
|
|
"0.1",
|
|
|
|
"client console driver",
|
|
|
|
"Copyright (C) 1996-1997 id Software, Inc.\n"
|
2001-09-10 12:56:23 +00:00
|
|
|
"Copyright (C) 1999,2000,2001 contributors of the QuakeForge "
|
|
|
|
"project\n"
|
2001-07-20 18:51:00 +00:00
|
|
|
"Please see the file \"AUTHORS\" for a list of contributors",
|
|
|
|
&plugin_info_funcs,
|
|
|
|
&plugin_info_data,
|
|
|
|
};
|
|
|
|
|
2001-10-08 05:54:46 +00:00
|
|
|
QFPLUGIN plugin_t *
|
2002-04-19 20:08:54 +00:00
|
|
|
PLUGIN_INFO(console, client) (void)
|
2001-07-20 18:51:00 +00:00
|
|
|
{
|
|
|
|
return &plugin_info;
|
|
|
|
}
|