diff options
| author | Jakob Fries <jakob.fries@gmail.com> | 2008-01-16 22:14:06 +0000 |
|---|---|---|
| committer | Jakob Fries <jakob.fries@gmail.com> | 2008-01-16 22:14:06 +0000 |
| commit | 75c8b2e9a58e7052f484e43291baa2d9ae1a384a (patch) | |
| tree | 40e065a48cae7e840cc6e8f9fc9771c500910f4a /src/game | |
| parent | a9c90d6ac082dbfea5590c54d5be7a71dd112b5d (diff) | |
| download | zcatch-75c8b2e9a58e7052f484e43291baa2d9ae1a384a.tar.gz zcatch-75c8b2e9a58e7052f484e43291baa2d9ae1a384a.zip | |
Added first version of the console.
Diffstat (limited to 'src/game')
| -rw-r--r-- | src/game/client/gc_client.cpp | 1 | ||||
| -rw-r--r-- | src/game/client/gc_console.cpp | 136 | ||||
| -rw-r--r-- | src/game/client/gc_console.h | 10 | ||||
| -rw-r--r-- | src/game/client/gc_hooks.cpp | 12 | ||||
| -rw-r--r-- | src/game/g_variables.h | 1 |
5 files changed, 158 insertions, 2 deletions
diff --git a/src/game/client/gc_client.cpp b/src/game/client/gc_client.cpp index e460abe0..d72efe8e 100644 --- a/src/game/client/gc_client.cpp +++ b/src/game/client/gc_client.cpp @@ -20,6 +20,7 @@ extern "C" { #include "gc_client.h" #include "gc_render.h" #include "gc_anim.h" +#include "gc_console.h" struct data_container *data = 0; static int64 debug_firedelay = 0; diff --git a/src/game/client/gc_console.cpp b/src/game/client/gc_console.cpp new file mode 100644 index 00000000..277cb675 --- /dev/null +++ b/src/game/client/gc_console.cpp @@ -0,0 +1,136 @@ +#include "gc_console.h" + +extern "C" { + #include <engine/e_system.h> + #include <engine/e_interface.h> + #include <engine/e_config.h> + #include <engine/e_console.h> + #include <engine/client/ec_font.h> +} + +#include <cstring> +#include <cstdio> + +#include "gc_ui.h" + +static unsigned int console_input_len = 0; +static char console_input[256] = {0}; +static int active = 0; + +static char backlog[256][256] = {0}; +static int backlog_len; + +static void client_console_print(const char *str) +{ + int len = strlen(str); + + if (len > 255) + len = 255; + + if (backlog_len >= 256) + { + puts("console backlog full"); + } + + memcpy(backlog[backlog_len], str, len); + backlog[backlog_len][len] = 0; + + backlog_len++; + + //dbg_msg("console", "FROM CLIENT!! %s", str); +} + +void client_console_init() +{ + console_register_print_callback(client_console_print); +} + +void console_handle_input() +{ + for(int i = 0; i < inp_num_events(); i++) + { + INPUTEVENT e = inp_get_event(i); + + if (e.key == KEY_F3) + { + console_toggle(); + } + + if (active) + { + if (!(e.ch >= 0 && e.ch < 32)) + { + if (console_input_len < sizeof(console_input) - 1) + { + console_input[console_input_len] = e.ch; + console_input[console_input_len+1] = 0; + console_input_len++; + } + } + + if(e.key == KEY_BACKSPACE) + { + if(console_input_len > 0) + { + console_input[console_input_len-1] = 0; + console_input_len--; + } + } + else if(e.key == KEY_ENTER) + { + console_execute(console_input); + console_input[0] = 0; + console_input_len = 0; + } + } + } + + if (active) + inp_clear_events(); +} + +void console_toggle() +{ + active ^= 1; +} + +void console_render() +{ + RECT screen = *ui_screen(); + float console_height = screen.h*3/5.0f; + gfx_mapscreen(screen.x, screen.y, screen.w, screen.h); + + gfx_texture_set(-1); + gfx_quads_begin(); + gfx_setcolor(0.4,0.2,0.2,0.8); + gfx_quads_drawTL(0,0,screen.w,console_height); + gfx_quads_end(); + + { + float font_size = 12.0f; + float row_spacing = font_size*1.4f; + float width = gfx_text_width(0, 12, console_input, -1); + float x = 3, y = console_height - row_spacing - 2; + int backlog_index = backlog_len-1; + + gfx_text(0, x, y, font_size, console_input, -1); + gfx_text(0, x+width+1, y, font_size, "_", -1); + + y -= row_spacing; + + while (y > 0.0f && backlog_index >= 0) + { + const char *line = backlog[backlog_index]; + gfx_text(0, x, y, font_size, line, -1); + + backlog_index--; + y -= row_spacing; + } + } +} + +int console_active() +{ + return active; +} + diff --git a/src/game/client/gc_console.h b/src/game/client/gc_console.h new file mode 100644 index 00000000..87628a2a --- /dev/null +++ b/src/game/client/gc_console.h @@ -0,0 +1,10 @@ +#ifndef _GC_CONSOLE_H +#define _GC_CONSOLE_H + +void console_handle_input(); +void console_toggle(); +void console_render(); +int console_active(); +void client_console_init(); + +#endif diff --git a/src/game/client/gc_hooks.cpp b/src/game/client/gc_hooks.cpp index a58b554a..d70e84a5 100644 --- a/src/game/client/gc_hooks.cpp +++ b/src/game/client/gc_hooks.cpp @@ -17,6 +17,7 @@ extern "C" { #include "gc_skin.h" #include "gc_render.h" #include "gc_map_image.h" +#include "gc_console.h" extern unsigned char internal_data[]; @@ -36,6 +37,8 @@ extern "C" void modc_init() gfx_text_set_default_font(&default_font); menu_init(); + + client_console_init(); // setup sound channels snd_set_channel(CHN_GUI, 1.0f, 0.0f); @@ -288,10 +291,10 @@ extern "C" void modc_newsnapshot() client_datas[i].update_render_info(); } - - extern "C" void modc_render() { + console_handle_input(); + // this should be moved around abit if(client_state() == CLIENTSTATE_ONLINE) { @@ -310,6 +313,11 @@ extern "C" void modc_render() else // if (client_state() != CLIENTSTATE_CONNECTING && client_state() != CLIENTSTATE_LOADING) { menu_render(); + if (console_active()) + { + console_render(); + return; + } } // diff --git a/src/game/g_variables.h b/src/game/g_variables.h index 6a9fb35d..08abe313 100644 --- a/src/game/g_variables.h +++ b/src/game/g_variables.h @@ -23,6 +23,7 @@ MACRO_CONFIG_INT(key_teamchat, 'Y', 32, 512) MACRO_CONFIG_INT(key_console, 256+2, 32, 512) MACRO_CONFIG_INT(key_remoteconsole, 256+3, 32, 512) +MACRO_CONFIG_INT(key_toggleconsole, 256+4, 32, 512) MACRO_CONFIG_INT(dbg_bots, 0, 0, 11) |