2014-06-01 17:55:23 +00:00
|
|
|
/*
|
2018-09-02 00:57:29 +00:00
|
|
|
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
|
2014-06-01 17:55:23 +00:00
|
|
|
* It is copyright by its individual contributors, as recorded in the
|
|
|
|
* project's Git history. See COPYING.txt at the top level for license
|
|
|
|
* terms and a link to the Git history.
|
|
|
|
*/
|
2006-03-20 17:12:09 +00:00
|
|
|
/*
|
|
|
|
*
|
2008-04-06 20:23:28 +00:00
|
|
|
* Game console
|
2006-03-20 17:12:09 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-12-17 23:30:39 +00:00
|
|
|
#include <algorithm>
|
2006-03-20 17:12:09 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
2017-12-06 05:14:32 +00:00
|
|
|
#include <sys/time.h>
|
2013-06-30 02:22:56 +00:00
|
|
|
#include <SDL.h>
|
2011-01-14 21:56:00 +00:00
|
|
|
#include "window.h"
|
2015-10-09 02:46:10 +00:00
|
|
|
#include "event.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "console.h"
|
2008-04-06 20:23:28 +00:00
|
|
|
#include "args.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "gr.h"
|
2008-04-06 20:23:28 +00:00
|
|
|
#include "physfsx.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "gamefont.h"
|
2012-11-11 00:14:30 +00:00
|
|
|
#include "game.h"
|
2008-04-06 20:23:28 +00:00
|
|
|
#include "key.h"
|
|
|
|
#include "vers_id.h"
|
2010-12-10 23:18:17 +00:00
|
|
|
#include "timer.h"
|
2015-02-11 01:00:36 +00:00
|
|
|
#include "cli.h"
|
2015-06-07 16:20:46 +00:00
|
|
|
#include "cvar.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-07-05 03:32:07 +00:00
|
|
|
#include "dxxsconf.h"
|
2020-05-02 21:18:42 +00:00
|
|
|
#include <array>
|
2014-07-05 03:32:07 +00:00
|
|
|
|
2017-12-06 05:14:32 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DXX_CONSOLE_TIME_SHOW_YMD
|
|
|
|
#define DXX_CONSOLE_TIME_SHOW_YMD 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DXX_CONSOLE_TIME_SHOW_MSEC
|
|
|
|
#define DXX_CONSOLE_TIME_SHOW_MSEC 1
|
|
|
|
#endif
|
|
|
|
|
2017-12-25 05:44:27 +00:00
|
|
|
#ifndef DXX_CONSOLE_SHOW_TIME_STDOUT
|
|
|
|
#define DXX_CONSOLE_SHOW_TIME_STDOUT 0
|
|
|
|
#endif
|
|
|
|
|
2017-03-18 18:07:36 +00:00
|
|
|
constexpr unsigned CON_LINES_ONSCREEN = 18;
|
|
|
|
constexpr auto CON_SCROLL_OFFSET = CON_LINES_ONSCREEN - 3;
|
|
|
|
constexpr unsigned CON_LINES_MAX = 128;
|
|
|
|
|
|
|
|
enum con_state {
|
|
|
|
CON_STATE_CLOSING = -1,
|
|
|
|
CON_STATE_CLOSED = 0,
|
|
|
|
CON_STATE_OPENING = 1,
|
|
|
|
CON_STATE_OPEN = 2
|
|
|
|
};
|
|
|
|
|
2015-01-17 18:31:42 +00:00
|
|
|
static RAIIPHYSFS_File gamelog_fp;
|
2020-05-02 21:18:42 +00:00
|
|
|
static std::array<console_buffer, CON_LINES_MAX> con_buffer;
|
2017-03-18 18:07:36 +00:00
|
|
|
static con_state con_state;
|
|
|
|
static int con_scroll_offset, con_size;
|
2017-06-10 03:31:03 +00:00
|
|
|
static void con_force_puts(con_priority priority, char *buffer, size_t len);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2017-03-18 18:07:36 +00:00
|
|
|
static void con_add_buffer_line(const con_priority priority, const char *const buffer, const size_t len)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2008-04-06 20:23:28 +00:00
|
|
|
/* shift con_buffer for one line */
|
2014-07-05 03:32:07 +00:00
|
|
|
std::move(std::next(con_buffer.begin()), con_buffer.end(), con_buffer.begin());
|
|
|
|
console_buffer &c = con_buffer.back();
|
|
|
|
c.priority=priority;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-12-17 23:30:39 +00:00
|
|
|
size_t copy = std::min(len, CON_LINE_LENGTH - 1);
|
2014-07-05 03:32:07 +00:00
|
|
|
c.line[copy] = 0;
|
2015-05-14 02:23:13 +00:00
|
|
|
memcpy(&c.line,buffer, copy);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 05:14:32 +00:00
|
|
|
void (con_printf)(const con_priority_wrapper priority, const char *const fmt, ...)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
va_list arglist;
|
2008-04-06 20:23:28 +00:00
|
|
|
char buffer[CON_LINE_LENGTH];
|
|
|
|
|
2015-10-18 21:01:21 +00:00
|
|
|
if (priority <= CGameArg.DbgVerbose)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
va_start (arglist, fmt);
|
2017-12-06 05:14:32 +00:00
|
|
|
auto &&leader = priority.insert_location_leader(buffer);
|
|
|
|
size_t len = vsnprintf (leader.first, leader.second, fmt, arglist);
|
2006-03-20 17:12:09 +00:00
|
|
|
va_end (arglist);
|
2017-06-10 03:31:03 +00:00
|
|
|
con_force_puts(priority, buffer, len);
|
2013-12-07 01:01:27 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-12-22 17:18:44 +00:00
|
|
|
static void con_scrub_markup(char *buffer)
|
2013-12-07 01:01:27 +00:00
|
|
|
{
|
2013-12-22 17:18:44 +00:00
|
|
|
char *p1 = buffer, *p2 = p1;
|
|
|
|
do
|
|
|
|
switch (*p1)
|
|
|
|
{
|
|
|
|
case CC_COLOR:
|
|
|
|
case CC_LSPACING:
|
2015-05-14 02:23:13 +00:00
|
|
|
if (!*++p1)
|
2013-12-22 17:18:44 +00:00
|
|
|
break;
|
2019-04-04 04:29:03 +00:00
|
|
|
DXX_BOOST_FALLTHROUGH;
|
2013-12-22 17:18:44 +00:00
|
|
|
case CC_UNDERLINE:
|
|
|
|
p1++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*p2++ = *p1++;
|
|
|
|
}
|
|
|
|
while (*p1);
|
|
|
|
*p2 = 0;
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2017-06-10 03:31:03 +00:00
|
|
|
static void con_print_file(const char *const buffer)
|
2013-12-22 17:18:44 +00:00
|
|
|
{
|
2017-12-06 05:14:32 +00:00
|
|
|
char buf[1024];
|
2017-12-25 05:44:27 +00:00
|
|
|
#if !DXX_CONSOLE_SHOW_TIME_STDOUT
|
2017-12-06 05:14:32 +00:00
|
|
|
#ifndef _WIN32
|
2013-12-22 17:18:44 +00:00
|
|
|
/* Print output to stdout */
|
|
|
|
puts(buffer);
|
2017-12-06 05:14:32 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-12-22 17:18:44 +00:00
|
|
|
/* Print output to gamelog.txt */
|
|
|
|
if (gamelog_fp)
|
2017-12-25 05:44:27 +00:00
|
|
|
#endif
|
2013-12-22 17:18:44 +00:00
|
|
|
{
|
2017-12-06 05:14:32 +00:00
|
|
|
#if DXX_CONSOLE_TIME_SHOW_YMD
|
|
|
|
#define DXX_CONSOLE_TIME_FORMAT_YMD "%04i-%02i-%02i "
|
|
|
|
#define DXX_CONSOLE_TIME_ARG_YMD tm_year, tm_month, tm_day,
|
|
|
|
#else
|
|
|
|
#define DXX_CONSOLE_TIME_FORMAT_YMD ""
|
|
|
|
#define DXX_CONSOLE_TIME_ARG_YMD
|
|
|
|
#endif
|
|
|
|
#if DXX_CONSOLE_TIME_SHOW_MSEC
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define DXX_CONSOLE_TIME_FORMAT_MSEC ".%03i"
|
|
|
|
#else
|
|
|
|
#define DXX_CONSOLE_TIME_FORMAT_MSEC ".%06i"
|
|
|
|
#endif
|
|
|
|
#define DXX_CONSOLE_TIME_ARG_MSEC tm_msec,
|
|
|
|
#else
|
|
|
|
#define DXX_CONSOLE_TIME_FORMAT_MSEC ""
|
|
|
|
#define DXX_CONSOLE_TIME_ARG_MSEC
|
|
|
|
#endif
|
|
|
|
int
|
|
|
|
DXX_CONSOLE_TIME_ARG_YMD
|
|
|
|
DXX_CONSOLE_TIME_ARG_MSEC
|
|
|
|
tm_hour, tm_min, tm_sec;
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define DXX_LF "\r\n"
|
|
|
|
SYSTEMTIME st = {};
|
|
|
|
GetLocalTime(&st);
|
|
|
|
#if DXX_CONSOLE_TIME_SHOW_YMD
|
|
|
|
tm_year = st.wYear;
|
|
|
|
tm_month = st.wMonth;
|
|
|
|
tm_day = st.wDay;
|
|
|
|
#endif
|
|
|
|
tm_hour = st.wHour;
|
|
|
|
tm_min = st.wMinute;
|
|
|
|
tm_sec = st.wSecond;
|
|
|
|
#if DXX_CONSOLE_TIME_SHOW_MSEC
|
|
|
|
tm_msec = st.wMilliseconds;
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define DXX_LF "\n"
|
|
|
|
struct timeval tv;
|
|
|
|
if (gettimeofday(&tv, nullptr))
|
|
|
|
tv = {};
|
|
|
|
if (const auto lt = localtime(&tv.tv_sec))
|
2017-06-10 03:31:03 +00:00
|
|
|
{
|
2017-12-06 05:14:32 +00:00
|
|
|
#if DXX_CONSOLE_TIME_SHOW_YMD
|
|
|
|
tm_year = lt->tm_year;
|
|
|
|
tm_month = lt->tm_mon;
|
|
|
|
tm_day = lt->tm_mday;
|
|
|
|
#endif
|
2017-06-10 03:31:03 +00:00
|
|
|
tm_hour = lt->tm_hour;
|
|
|
|
tm_min = lt->tm_min;
|
|
|
|
tm_sec = lt->tm_sec;
|
2017-12-06 05:14:32 +00:00
|
|
|
#if DXX_CONSOLE_TIME_SHOW_MSEC
|
|
|
|
tm_msec = tv.tv_usec;
|
|
|
|
#endif
|
2017-06-10 03:31:03 +00:00
|
|
|
}
|
|
|
|
else
|
2017-12-06 05:14:32 +00:00
|
|
|
{
|
|
|
|
#if DXX_CONSOLE_TIME_SHOW_YMD
|
|
|
|
tm_year = tm_month = tm_day =
|
|
|
|
#endif
|
|
|
|
#if DXX_CONSOLE_TIME_SHOW_MSEC
|
|
|
|
tm_msec =
|
|
|
|
#endif
|
2017-06-10 03:31:03 +00:00
|
|
|
tm_hour = tm_min = tm_sec = -1;
|
2017-12-06 05:14:32 +00:00
|
|
|
}
|
2008-04-21 23:03:18 +00:00
|
|
|
#endif
|
2017-12-06 05:14:32 +00:00
|
|
|
const size_t len = snprintf(buf, sizeof(buf), DXX_CONSOLE_TIME_FORMAT_YMD "%02i:%02i:%02i" DXX_CONSOLE_TIME_FORMAT_MSEC " %s" DXX_LF, DXX_CONSOLE_TIME_ARG_YMD tm_hour, tm_min, tm_sec, DXX_CONSOLE_TIME_ARG_MSEC buffer);
|
2017-12-25 05:44:27 +00:00
|
|
|
#if DXX_CONSOLE_SHOW_TIME_STDOUT
|
|
|
|
#ifndef _WIN32
|
|
|
|
fputs(buf, stdout);
|
|
|
|
#endif
|
|
|
|
if (gamelog_fp)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
PHYSFS_write(gamelog_fp, buf, 1, len);
|
|
|
|
}
|
2017-06-10 03:31:03 +00:00
|
|
|
#undef DXX_LF
|
2017-12-06 05:14:32 +00:00
|
|
|
#undef DXX_CONSOLE_TIME_ARG_MSEC
|
|
|
|
#undef DXX_CONSOLE_TIME_FORMAT_MSEC
|
|
|
|
#undef DXX_CONSOLE_TIME_ARG_YMD
|
|
|
|
#undef DXX_CONSOLE_TIME_FORMAT_YMD
|
2013-12-22 17:18:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-10 03:31:03 +00:00
|
|
|
/*
|
|
|
|
* The caller is assumed to have checked that the priority allows this
|
|
|
|
* entry to be logged.
|
|
|
|
*/
|
|
|
|
static void con_force_puts(const con_priority priority, char *const buffer, const size_t len)
|
|
|
|
{
|
|
|
|
con_add_buffer_line(priority, buffer, len);
|
|
|
|
con_scrub_markup(buffer);
|
|
|
|
/* Produce a sanitised version and send it to the console */
|
|
|
|
con_print_file(buffer);
|
|
|
|
}
|
|
|
|
|
2017-12-06 05:14:32 +00:00
|
|
|
void con_puts(const con_priority_wrapper priority, char *const buffer, const size_t len)
|
2013-12-22 17:18:44 +00:00
|
|
|
{
|
2015-10-18 21:01:21 +00:00
|
|
|
if (priority <= CGameArg.DbgVerbose)
|
2017-12-06 05:14:32 +00:00
|
|
|
{
|
|
|
|
typename con_priority_wrapper::scratch_buffer<CON_LINE_LENGTH> scratch_buffer;
|
|
|
|
auto &&b = priority.prepare_buffer(scratch_buffer, buffer, len);
|
|
|
|
con_force_puts(priority, b.first, b.second);
|
|
|
|
}
|
2013-12-22 17:18:44 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 05:14:32 +00:00
|
|
|
void con_puts(const con_priority_wrapper priority, const char *const buffer, const size_t len)
|
2013-12-22 17:18:44 +00:00
|
|
|
{
|
2015-10-18 21:01:21 +00:00
|
|
|
if (priority <= CGameArg.DbgVerbose)
|
2013-12-22 17:18:44 +00:00
|
|
|
{
|
2017-12-06 05:14:32 +00:00
|
|
|
typename con_priority_wrapper::scratch_buffer<CON_LINE_LENGTH> scratch_buffer;
|
|
|
|
auto &&b = priority.prepare_buffer(scratch_buffer, buffer, len);
|
2013-12-22 17:18:44 +00:00
|
|
|
/* add given string to con_buffer */
|
2017-12-06 05:14:32 +00:00
|
|
|
con_add_buffer_line(priority, b.first, b.second);
|
|
|
|
con_print_file(b.first);
|
2008-04-06 20:23:28 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 02:31:04 +00:00
|
|
|
static color_palette_index get_console_color_by_priority(const int priority)
|
2015-05-14 02:23:13 +00:00
|
|
|
{
|
2016-12-17 18:39:17 +00:00
|
|
|
int r, g, b;
|
2015-05-14 02:23:13 +00:00
|
|
|
switch (priority)
|
|
|
|
{
|
|
|
|
case CON_CRITICAL:
|
2016-12-17 18:39:17 +00:00
|
|
|
r = 28 * 2, g = 0 * 2, b = 0 * 2;
|
|
|
|
break;
|
2015-05-14 02:23:13 +00:00
|
|
|
case CON_URGENT:
|
2016-12-17 18:39:17 +00:00
|
|
|
r = 54 * 2, g = 54 * 2, b = 0 * 2;
|
|
|
|
break;
|
2015-05-14 02:23:13 +00:00
|
|
|
case CON_DEBUG:
|
|
|
|
case CON_VERBOSE:
|
2016-12-17 18:39:17 +00:00
|
|
|
r = 14 * 2, g = 14 * 2, b = 14 * 2;
|
|
|
|
break;
|
2015-05-14 02:23:13 +00:00
|
|
|
case CON_HUD:
|
2016-12-17 18:39:17 +00:00
|
|
|
r = 0 * 2, g = 28 * 2, b = 0 * 2;
|
|
|
|
break;
|
2015-05-14 02:23:13 +00:00
|
|
|
default:
|
2016-12-17 18:39:17 +00:00
|
|
|
r = 255 * 2, g = 255 * 2, b = 255 * 2;
|
|
|
|
break;
|
2015-05-14 02:23:13 +00:00
|
|
|
}
|
2016-12-17 18:39:17 +00:00
|
|
|
return gr_find_closest_color(r, g, b);
|
2015-05-14 02:23:13 +00:00
|
|
|
}
|
|
|
|
|
2012-11-02 17:24:51 +00:00
|
|
|
static void con_draw(void)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2015-09-29 02:41:22 +00:00
|
|
|
int i = 0, y = 0;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2011-01-14 21:56:00 +00:00
|
|
|
if (con_size <= 0)
|
2008-04-06 20:23:28 +00:00
|
|
|
return;
|
|
|
|
|
2017-11-05 20:49:08 +00:00
|
|
|
gr_set_default_canvas();
|
2017-02-11 21:42:46 +00:00
|
|
|
auto &canvas = *grd_curcanv;
|
2018-05-19 23:21:42 +00:00
|
|
|
auto &game_font = *GAME_FONT;
|
2017-02-11 21:42:46 +00:00
|
|
|
gr_set_curfont(canvas, GAME_FONT);
|
2016-02-12 04:02:28 +00:00
|
|
|
const uint8_t color = BM_XRGB(0, 0, 0);
|
2020-07-16 02:31:04 +00:00
|
|
|
gr_settransblend(canvas, 7, gr_blend::normal);
|
2015-06-13 22:42:20 +00:00
|
|
|
const auto &&fspacy1 = FSPACY(1);
|
2018-05-19 23:21:42 +00:00
|
|
|
const auto &&line_spacing = LINE_SPACING(*canvas.cv_font, *GAME_FONT);
|
2015-06-13 22:42:22 +00:00
|
|
|
y = fspacy1 + (line_spacing * con_size);
|
2017-02-11 21:42:46 +00:00
|
|
|
gr_rect(canvas, 0, 0, SWIDTH, y, color);
|
2020-07-16 02:31:04 +00:00
|
|
|
gr_settransblend(canvas, GR_FADE_OFF, gr_blend::normal);
|
2008-04-06 20:23:28 +00:00
|
|
|
i+=con_scroll_offset;
|
2015-02-11 01:00:36 +00:00
|
|
|
|
2017-02-11 21:42:46 +00:00
|
|
|
gr_set_fontcolor(canvas, BM_XRGB(255, 255, 255), -1);
|
2015-12-22 04:18:52 +00:00
|
|
|
y = cli_draw(y, line_spacing);
|
2015-02-11 01:00:36 +00:00
|
|
|
|
2015-06-13 22:42:20 +00:00
|
|
|
const auto &&fspacx = FSPACX();
|
2015-06-13 22:42:20 +00:00
|
|
|
const auto &&fspacx1 = fspacx(1);
|
2015-09-29 02:41:22 +00:00
|
|
|
for (;;)
|
2008-04-06 20:23:28 +00:00
|
|
|
{
|
2015-12-22 04:18:50 +00:00
|
|
|
auto &b = con_buffer[CON_LINES_MAX - 1 - i];
|
2017-02-11 21:42:46 +00:00
|
|
|
gr_set_fontcolor(canvas, get_console_color_by_priority(b.priority), -1);
|
2015-09-29 02:41:22 +00:00
|
|
|
int w,h;
|
2018-05-19 23:21:42 +00:00
|
|
|
gr_get_string_size(game_font, b.line, &w, &h, nullptr);
|
2015-06-13 22:42:20 +00:00
|
|
|
y -= h + fspacy1;
|
2018-05-19 23:21:42 +00:00
|
|
|
gr_string(canvas, game_font, fspacx1, y, b.line, w, h);
|
2008-04-06 20:23:28 +00:00
|
|
|
i++;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2008-04-06 20:23:28 +00:00
|
|
|
if (y<=0 || CON_LINES_MAX-1-i <= 0 || i < 0)
|
2015-09-29 02:41:22 +00:00
|
|
|
break;
|
2008-04-06 20:23:28 +00:00
|
|
|
}
|
2017-02-11 21:42:46 +00:00
|
|
|
gr_rect(canvas, 0, 0, SWIDTH, line_spacing, color);
|
|
|
|
gr_set_fontcolor(canvas, BM_XRGB(255, 255, 255),-1);
|
2018-05-19 23:21:42 +00:00
|
|
|
gr_printf(canvas, game_font, fspacx1, fspacy1, "%s LOG", DESCENT_VERSION);
|
|
|
|
gr_string(canvas, game_font, SWIDTH - fspacx(110), fspacy1, "PAGE-UP/DOWN TO SCROLL");
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2014-10-16 02:30:29 +00:00
|
|
|
static window_event_result con_handler(window *wind,const d_event &event, const unused_window_userdata_t *)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2011-01-14 21:56:00 +00:00
|
|
|
int key;
|
|
|
|
static fix64 last_scroll_time = 0;
|
|
|
|
|
2014-10-04 21:47:13 +00:00
|
|
|
switch (event.type)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2011-01-14 21:56:00 +00:00
|
|
|
case EVENT_WINDOW_ACTIVATED:
|
2015-02-11 01:00:36 +00:00
|
|
|
key_toggle_repeat(1);
|
2011-01-14 21:56:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENT_WINDOW_DEACTIVATED:
|
2015-02-11 01:00:36 +00:00
|
|
|
key_toggle_repeat(0);
|
2011-01-14 21:56:00 +00:00
|
|
|
con_size = 0;
|
|
|
|
con_state = CON_STATE_CLOSED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENT_KEY_COMMAND:
|
|
|
|
key = event_key_get(event);
|
|
|
|
switch (key)
|
|
|
|
{
|
2011-01-16 18:33:41 +00:00
|
|
|
case KEY_SHIFTED + KEY_ESC:
|
2011-01-14 21:56:00 +00:00
|
|
|
switch (con_state)
|
|
|
|
{
|
|
|
|
case CON_STATE_OPEN:
|
|
|
|
case CON_STATE_OPENING:
|
|
|
|
con_state = CON_STATE_CLOSING;
|
|
|
|
break;
|
|
|
|
case CON_STATE_CLOSED:
|
|
|
|
case CON_STATE_CLOSING:
|
|
|
|
con_state = CON_STATE_OPENING;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KEY_PAGEUP:
|
|
|
|
con_scroll_offset+=CON_SCROLL_OFFSET;
|
|
|
|
if (con_scroll_offset >= CON_LINES_MAX-1)
|
|
|
|
con_scroll_offset = CON_LINES_MAX-1;
|
|
|
|
while (con_buffer[CON_LINES_MAX-1-con_scroll_offset].line[0]=='\0')
|
|
|
|
con_scroll_offset--;
|
|
|
|
break;
|
|
|
|
case KEY_PAGEDOWN:
|
|
|
|
con_scroll_offset-=CON_SCROLL_OFFSET;
|
|
|
|
if (con_scroll_offset<0)
|
|
|
|
con_scroll_offset=0;
|
|
|
|
break;
|
2015-02-11 01:00:36 +00:00
|
|
|
case KEY_CTRLED + KEY_A:
|
|
|
|
case KEY_HOME: cli_cursor_home(); break;
|
|
|
|
case KEY_END:
|
|
|
|
case KEY_CTRLED + KEY_E: cli_cursor_end(); break;
|
|
|
|
case KEY_CTRLED + KEY_C: cli_clear(); break;
|
|
|
|
case KEY_LEFT: cli_cursor_left(); break;
|
|
|
|
case KEY_RIGHT: cli_cursor_right(); break;
|
|
|
|
case KEY_BACKSP: cli_cursor_backspace(); break;
|
|
|
|
case KEY_CTRLED + KEY_D:
|
|
|
|
case KEY_DELETE: cli_cursor_del(); break;
|
|
|
|
case KEY_UP: cli_history_prev(); break;
|
|
|
|
case KEY_DOWN: cli_history_next(); break;
|
|
|
|
case KEY_TAB: cli_autocomplete(); break;
|
|
|
|
case KEY_ENTER: cli_execute(); break;
|
|
|
|
case KEY_INSERT:
|
2015-12-22 04:18:52 +00:00
|
|
|
cli_toggle_overwrite_mode();
|
2015-02-11 01:00:36 +00:00
|
|
|
break;
|
2011-01-14 21:56:00 +00:00
|
|
|
default:
|
2015-02-11 01:00:36 +00:00
|
|
|
int character = key_ascii();
|
|
|
|
if (character == 255)
|
|
|
|
break;
|
|
|
|
cli_add_character(character);
|
2011-01-14 21:56:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-08-06 02:10:49 +00:00
|
|
|
return window_event_result::handled;
|
2011-01-14 21:56:00 +00:00
|
|
|
|
|
|
|
case EVENT_WINDOW_DRAW:
|
2011-01-22 12:30:20 +00:00
|
|
|
timer_delay2(50);
|
2011-01-14 21:56:00 +00:00
|
|
|
if (con_state == CON_STATE_OPENING)
|
|
|
|
{
|
|
|
|
if (con_size < CON_LINES_ONSCREEN && timer_query() >= last_scroll_time+(F1_0/30))
|
|
|
|
{
|
|
|
|
last_scroll_time = timer_query();
|
2015-05-14 02:23:13 +00:00
|
|
|
if (++ con_size >= CON_LINES_ONSCREEN)
|
|
|
|
con_state = CON_STATE_OPEN;
|
2011-01-14 21:56:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (con_state == CON_STATE_CLOSING)
|
|
|
|
{
|
|
|
|
if (con_size > 0 && timer_query() >= last_scroll_time+(F1_0/30))
|
|
|
|
{
|
|
|
|
last_scroll_time = timer_query();
|
2015-05-14 02:23:13 +00:00
|
|
|
if (! -- con_size)
|
|
|
|
con_state = CON_STATE_CLOSED;
|
2011-01-14 21:56:00 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-06 02:10:49 +00:00
|
|
|
con_draw();
|
2011-01-14 21:56:00 +00:00
|
|
|
if (con_state == CON_STATE_CLOSED && wind)
|
2014-08-06 02:10:49 +00:00
|
|
|
{
|
|
|
|
return window_event_result::close;
|
|
|
|
}
|
2011-01-14 21:56:00 +00:00
|
|
|
break;
|
|
|
|
case EVENT_WINDOW_CLOSE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
2011-01-14 21:56:00 +00:00
|
|
|
|
2014-08-06 02:10:49 +00:00
|
|
|
return window_event_result::ignored;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 21:56:00 +00:00
|
|
|
void con_showup(void)
|
|
|
|
{
|
|
|
|
game_flush_inputs();
|
|
|
|
con_state = CON_STATE_OPENING;
|
2016-10-15 00:53:20 +00:00
|
|
|
const auto wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, con_handler, unused_window_userdata);
|
2011-01-14 21:56:00 +00:00
|
|
|
|
|
|
|
if (!wind)
|
|
|
|
{
|
|
|
|
d_event event = { EVENT_WINDOW_CLOSE };
|
2014-10-04 21:47:13 +00:00
|
|
|
con_handler(NULL, event, NULL);
|
2011-01-14 21:56:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-06 20:23:28 +00:00
|
|
|
void con_init(void)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2014-07-05 03:32:07 +00:00
|
|
|
con_buffer = {};
|
2015-10-18 21:01:21 +00:00
|
|
|
if (CGameArg.DbgSafelog)
|
2015-01-17 18:31:42 +00:00
|
|
|
gamelog_fp.reset(PHYSFS_openWrite("gamelog.txt"));
|
2010-11-26 12:15:56 +00:00
|
|
|
else
|
|
|
|
gamelog_fp = PHYSFSX_openWriteBuffered("gamelog.txt");
|
2015-02-11 01:00:36 +00:00
|
|
|
|
|
|
|
cli_init();
|
2015-02-11 07:35:44 +00:00
|
|
|
cmd_init();
|
|
|
|
cvar_init();
|
2015-02-11 01:00:36 +00:00
|
|
|
|
2008-10-28 17:58:54 +00:00
|
|
|
}
|