2008-01-16 22:14:06 +00:00
|
|
|
#include "gc_console.h"
|
2008-02-10 01:48:39 +00:00
|
|
|
#include "../generated/gc_data.h"
|
2008-01-16 22:14:06 +00:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <engine/e_system.h>
|
2008-01-19 10:57:25 +00:00
|
|
|
#include <engine/e_client_interface.h>
|
2008-01-16 22:14:06 +00:00
|
|
|
#include <engine/e_config.h>
|
|
|
|
#include <engine/e_console.h>
|
2008-02-04 00:13:34 +00:00
|
|
|
#include <engine/e_ringbuffer.h>
|
2008-01-16 22:14:06 +00:00
|
|
|
#include <engine/client/ec_font.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
#include "gc_ui.h"
|
2008-01-29 21:39:41 +00:00
|
|
|
#include "gc_client.h"
|
2008-01-16 22:14:06 +00:00
|
|
|
|
2008-01-30 13:15:58 +00:00
|
|
|
#include "../g_version.h"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
CONSOLE_CLOSED,
|
|
|
|
CONSOLE_OPENING,
|
|
|
|
CONSOLE_OPEN,
|
|
|
|
CONSOLE_CLOSING,
|
|
|
|
};
|
|
|
|
|
2008-03-01 14:36:36 +00:00
|
|
|
class CONSOLE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
char history_data[65536];
|
|
|
|
RINGBUFFER *history;
|
|
|
|
char *history_entry;
|
|
|
|
|
|
|
|
char backlog_data[65536];
|
|
|
|
RINGBUFFER *backlog;
|
|
|
|
|
|
|
|
unsigned int input_len;
|
|
|
|
char input[256];
|
|
|
|
|
|
|
|
int type;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CONSOLE(int t)
|
|
|
|
{
|
|
|
|
// clear input
|
|
|
|
input_len = 0;
|
|
|
|
mem_zero(input, sizeof(input));
|
|
|
|
|
|
|
|
// init ringbuffers
|
|
|
|
history = ringbuf_init(history_data, sizeof(history_data));
|
|
|
|
backlog = ringbuf_init(backlog_data, sizeof(backlog_data));
|
|
|
|
|
|
|
|
history_entry = 0x0;
|
|
|
|
|
|
|
|
type = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
void execute_line(const char *line)
|
|
|
|
{
|
|
|
|
if(type == 0)
|
|
|
|
console_execute_line(line);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(client_rcon_authed())
|
|
|
|
client_rcon(line);
|
|
|
|
else
|
|
|
|
client_rcon_auth("", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_event(INPUT_EVENT e)
|
|
|
|
{
|
|
|
|
if (!(e.ch >= 0 && e.ch < 32))
|
|
|
|
{
|
|
|
|
if (input_len < sizeof(input) - 1)
|
|
|
|
{
|
|
|
|
input[input_len] = e.ch;
|
|
|
|
input[input_len+1] = 0;
|
|
|
|
input_len++;
|
|
|
|
|
|
|
|
history_entry = 0x0;
|
|
|
|
}
|
|
|
|
}
|
2008-02-04 00:13:34 +00:00
|
|
|
|
2008-03-01 20:03:04 +00:00
|
|
|
if(e.flags&INPFLAG_PRESS)
|
2008-03-01 14:36:36 +00:00
|
|
|
{
|
2008-03-01 20:03:04 +00:00
|
|
|
if(e.key == KEY_BACKSPACE)
|
2008-03-01 14:36:36 +00:00
|
|
|
{
|
2008-03-01 20:03:04 +00:00
|
|
|
if(input_len > 0)
|
|
|
|
{
|
|
|
|
input[input_len-1] = 0;
|
|
|
|
input_len--;
|
2008-02-04 00:13:34 +00:00
|
|
|
|
2008-03-01 20:03:04 +00:00
|
|
|
history_entry = 0x0;
|
|
|
|
}
|
2008-03-01 14:36:36 +00:00
|
|
|
}
|
2008-03-01 20:03:04 +00:00
|
|
|
else if(e.key == KEY_ENTER || e.key == KEY_KP_ENTER)
|
2008-03-01 14:36:36 +00:00
|
|
|
{
|
2008-03-01 20:03:04 +00:00
|
|
|
if (input_len)
|
|
|
|
{
|
|
|
|
char *entry = (char *)ringbuf_allocate(history, input_len+1);
|
|
|
|
mem_copy(entry, input, input_len+1);
|
|
|
|
|
|
|
|
execute_line(input);
|
|
|
|
input[0] = 0;
|
|
|
|
input_len = 0;
|
|
|
|
|
|
|
|
history_entry = 0x0;
|
|
|
|
}
|
2008-03-01 14:36:36 +00:00
|
|
|
}
|
2008-03-01 20:03:04 +00:00
|
|
|
else if (e.key == KEY_UP)
|
2008-03-01 14:36:36 +00:00
|
|
|
{
|
2008-03-01 20:03:04 +00:00
|
|
|
if (history_entry)
|
|
|
|
{
|
|
|
|
char *test = (char *)ringbuf_prev(history, history_entry);
|
2008-03-01 14:36:36 +00:00
|
|
|
|
2008-03-01 20:03:04 +00:00
|
|
|
if (test)
|
|
|
|
history_entry = test;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
history_entry = (char *)ringbuf_last(history);
|
2008-03-01 14:36:36 +00:00
|
|
|
|
2008-03-01 20:03:04 +00:00
|
|
|
if (history_entry)
|
2008-03-01 14:36:36 +00:00
|
|
|
{
|
2008-03-01 20:03:04 +00:00
|
|
|
unsigned int len = strlen(history_entry);
|
|
|
|
if (len < sizeof(input) - 1)
|
|
|
|
{
|
|
|
|
mem_copy(input, history_entry, len+1);
|
|
|
|
input_len = len;
|
|
|
|
}
|
2008-03-01 14:36:36 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 20:03:04 +00:00
|
|
|
}
|
|
|
|
else if (e.key == KEY_DOWN)
|
2008-03-01 14:36:36 +00:00
|
|
|
{
|
2008-03-01 20:03:04 +00:00
|
|
|
if (history_entry)
|
|
|
|
history_entry = (char *)ringbuf_next(history, history_entry);
|
|
|
|
|
|
|
|
if (history_entry)
|
2008-03-01 14:36:36 +00:00
|
|
|
{
|
2008-03-01 20:03:04 +00:00
|
|
|
unsigned int len = strlen(history_entry);
|
|
|
|
if (len < sizeof(input) - 1)
|
|
|
|
{
|
|
|
|
mem_copy(input, history_entry, len+1);
|
2008-03-01 14:36:36 +00:00
|
|
|
|
2008-03-01 20:03:04 +00:00
|
|
|
input_len = len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
input[0] = 0;
|
|
|
|
input_len = 0;
|
2008-03-01 14:36:36 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-01 20:03:04 +00:00
|
|
|
}
|
2008-03-01 14:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_line(const char *line)
|
|
|
|
{
|
|
|
|
int len = strlen(line);
|
|
|
|
|
|
|
|
if (len > 255)
|
|
|
|
len = 255;
|
|
|
|
|
|
|
|
char *entry = (char *)ringbuf_allocate(backlog, len+1);
|
|
|
|
mem_copy(entry, line, len+1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static CONSOLE local_console(0);
|
|
|
|
static CONSOLE remote_console(1);
|
|
|
|
|
|
|
|
static int console_type = 0;
|
2008-01-30 13:15:58 +00:00
|
|
|
static int console_state = CONSOLE_CLOSED;
|
|
|
|
static float state_change_end = 0.0f;
|
2008-02-02 11:08:31 +00:00
|
|
|
static const float state_change_duration = 0.1f;
|
2008-01-16 22:14:06 +00:00
|
|
|
|
2008-01-30 13:15:58 +00:00
|
|
|
static float time_now()
|
|
|
|
{
|
|
|
|
static long long time_start = time_get();
|
|
|
|
return float(time_get()-time_start)/float(time_freq());
|
|
|
|
}
|
|
|
|
|
2008-03-01 14:36:36 +00:00
|
|
|
static CONSOLE *current_console()
|
2008-01-16 22:14:06 +00:00
|
|
|
{
|
2008-03-01 14:36:36 +00:00
|
|
|
if(console_type != 0)
|
|
|
|
return &remote_console;
|
|
|
|
return &local_console;
|
|
|
|
}
|
2008-01-16 22:14:06 +00:00
|
|
|
|
2008-03-01 14:36:36 +00:00
|
|
|
static void client_console_print(const char *str)
|
|
|
|
{
|
|
|
|
local_console.print_line(str);
|
2008-01-16 22:14:06 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 14:36:36 +00:00
|
|
|
void console_rcon_print(const char *line)
|
|
|
|
{
|
|
|
|
remote_console.print_line(line);
|
|
|
|
}
|
2008-01-18 15:55:03 +00:00
|
|
|
|
2008-02-02 12:38:36 +00:00
|
|
|
static void con_team(void *result, void *user_data)
|
2008-01-29 21:39:41 +00:00
|
|
|
{
|
|
|
|
int new_team;
|
2008-02-02 12:38:36 +00:00
|
|
|
console_result_int(result, 1, &new_team);
|
2008-01-29 21:39:41 +00:00
|
|
|
send_switch_team(new_team);
|
|
|
|
}
|
|
|
|
|
2008-03-01 20:03:04 +00:00
|
|
|
static void con_say(void *result, void *user_data)
|
2008-02-04 00:13:34 +00:00
|
|
|
{
|
2008-03-01 20:03:04 +00:00
|
|
|
const char *str;
|
|
|
|
console_result_string(result, 1, &str);
|
|
|
|
chat_say(0, str);
|
|
|
|
}
|
2008-02-04 00:13:34 +00:00
|
|
|
|
2008-03-01 20:03:04 +00:00
|
|
|
static void con_sayteam(void *result, void *user_data)
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
console_result_string(result, 1, &str);
|
|
|
|
chat_say(1, str);
|
|
|
|
}
|
2008-02-04 00:13:34 +00:00
|
|
|
|
|
|
|
void send_kill(int client_id);
|
|
|
|
|
2008-03-01 14:36:36 +00:00
|
|
|
static void con_kill(void *result, void *user_data)
|
2008-02-04 00:13:34 +00:00
|
|
|
{
|
|
|
|
send_kill(-1);
|
|
|
|
}
|
|
|
|
|
2008-03-01 20:03:04 +00:00
|
|
|
static char keybindings[KEY_LAST][128] = {{0}};
|
|
|
|
|
|
|
|
const char *binds_get(int keyid)
|
|
|
|
{
|
|
|
|
if(keyid > 0 && keyid < KEY_LAST)
|
|
|
|
return keybindings[keyid];
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void binds_set(int keyid, const char *str)
|
|
|
|
{
|
|
|
|
if(keyid < 0 && keyid >= KEY_LAST)
|
|
|
|
return;
|
|
|
|
|
|
|
|
str_copy(keybindings[keyid], str, sizeof(keybindings[keyid]));
|
|
|
|
if(!keybindings[keyid][0])
|
|
|
|
dbg_msg("binds", "unbound %s (%d)", inp_key_name(keyid), keyid);
|
|
|
|
else
|
|
|
|
dbg_msg("binds", "bound %s (%d) = %s", inp_key_name(keyid), keyid, keybindings[keyid]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_key_id(const char *key_name)
|
|
|
|
{
|
|
|
|
int i = atoi(key_name);
|
|
|
|
if(i > 0 && i < KEY_LAST)
|
|
|
|
return i; // numeric
|
|
|
|
|
|
|
|
// search for key
|
|
|
|
for(int i = 0; i < KEY_LAST; i++)
|
|
|
|
{
|
|
|
|
if(strcmp(key_name, inp_key_name(i)) == 0)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void con_binds_set(void *result, void *user_data)
|
|
|
|
{
|
|
|
|
const char *key_name;
|
|
|
|
const char *bind_str;
|
|
|
|
console_result_string(result, 1, &key_name);
|
|
|
|
console_result_string(result, 2, &bind_str);
|
|
|
|
int id = get_key_id(key_name);
|
|
|
|
|
|
|
|
if(!id)
|
|
|
|
{
|
|
|
|
dbg_msg("binds", "key %s not found", key_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
binds_set(id, bind_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void con_binds_remove(void *result, void *user_data)
|
|
|
|
{
|
|
|
|
const char *key_name;
|
|
|
|
console_result_string(result, 1, &key_name);
|
|
|
|
int id = get_key_id(key_name);
|
|
|
|
|
|
|
|
if(!id)
|
|
|
|
{
|
|
|
|
dbg_msg("binds", "key %s not found", key_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
binds_set(id, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void con_binds_dump(void *result, void *user_data)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < KEY_LAST; i++)
|
|
|
|
{
|
|
|
|
if(keybindings[i][0] == 0)
|
|
|
|
continue;
|
|
|
|
dbg_msg("binds", "%s (%d) = %s", inp_key_name(i), i, keybindings[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void binds_save()
|
|
|
|
{
|
|
|
|
char buffer[256];
|
|
|
|
for(int i = 0; i < KEY_LAST; i++)
|
|
|
|
{
|
|
|
|
if(keybindings[i][0] == 0)
|
|
|
|
continue;
|
|
|
|
str_format(buffer, sizeof(buffer), "binds_set %s \"%s\"", inp_key_name(i), keybindings[i]);
|
|
|
|
client_save_line(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void con_key_input_state(void *result, void *user_data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
console_result_int(result, 1, &i);
|
|
|
|
((int *)user_data)[0] = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void con_key_input_counter(void *result, void *user_data)
|
|
|
|
{
|
|
|
|
int stroke;
|
|
|
|
int *v = (int *)user_data;
|
|
|
|
console_result_int(result, 1, &stroke);
|
|
|
|
if(((*v)&1) != stroke)
|
|
|
|
(*v)++;
|
|
|
|
*v &= INPUT_STATE_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void con_key_input_weapon(void *result, void *user_data)
|
|
|
|
{
|
|
|
|
int w = (char *)user_data - (char *)0;
|
|
|
|
int stroke;
|
|
|
|
console_result_int(result, 1, &stroke);
|
|
|
|
if(stroke)
|
|
|
|
input_data.wanted_weapon = w;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void con_chat(void *result, void *user_data)
|
|
|
|
{
|
|
|
|
const char *mode;
|
|
|
|
console_result_string(result, 1, &mode);
|
|
|
|
if(strcmp(mode, "all") == 0)
|
|
|
|
chat_enable_mode(0);
|
|
|
|
else if(strcmp(mode, "team") == 0)
|
|
|
|
chat_enable_mode(1);
|
|
|
|
else
|
|
|
|
dbg_msg("console", "expected all or team as mode");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void con_toggle_local_console(void *result, void *user_data)
|
|
|
|
{
|
|
|
|
console_toggle(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void con_toggle_remote_console(void *result, void *user_data)
|
|
|
|
{
|
|
|
|
console_toggle(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void con_emote(void *result, void *user_data)
|
|
|
|
{
|
|
|
|
int emote;
|
|
|
|
console_result_int(result, 1, &emote);
|
|
|
|
send_emoticon(emote);
|
|
|
|
}
|
|
|
|
|
2008-01-16 22:14:06 +00:00
|
|
|
void client_console_init()
|
|
|
|
{
|
|
|
|
console_register_print_callback(client_console_print);
|
2008-03-01 20:03:04 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
MACRO_REGISTER_COMMAND("toggle_local_console", "", con_toggle_local_console, 0x0);
|
|
|
|
MACRO_REGISTER_COMMAND("toggle_remote_console", "", con_toggle_remote_console, 0x0);
|
|
|
|
|
|
|
|
//
|
2008-01-29 21:39:41 +00:00
|
|
|
MACRO_REGISTER_COMMAND("team", "i", con_team, 0x0);
|
2008-03-01 14:36:36 +00:00
|
|
|
MACRO_REGISTER_COMMAND("kill", "", con_kill, 0x0);
|
2008-03-01 20:03:04 +00:00
|
|
|
|
|
|
|
// bindings
|
|
|
|
MACRO_REGISTER_COMMAND("binds_set", "ss", con_binds_set, 0x0);
|
|
|
|
MACRO_REGISTER_COMMAND("binds_remove", "s", con_binds_remove, 0x0);
|
|
|
|
MACRO_REGISTER_COMMAND("binds_dump", "", con_binds_dump, 0x0);
|
|
|
|
|
|
|
|
// chatting
|
|
|
|
MACRO_REGISTER_COMMAND("say", "s", con_say, 0x0);
|
|
|
|
MACRO_REGISTER_COMMAND("say_team", "s", con_sayteam, 0x0);
|
|
|
|
MACRO_REGISTER_COMMAND("chat", "s", con_chat, 0x0);
|
|
|
|
MACRO_REGISTER_COMMAND("emote", "i", con_emote, 0);
|
|
|
|
|
|
|
|
// game commands
|
|
|
|
MACRO_REGISTER_COMMAND("+left", "i", con_key_input_state, &input_data.left);
|
|
|
|
MACRO_REGISTER_COMMAND("+right", "i", con_key_input_state, &input_data.right);
|
|
|
|
MACRO_REGISTER_COMMAND("+jump", "i", con_key_input_state, &input_data.jump);
|
|
|
|
MACRO_REGISTER_COMMAND("+hook", "i", con_key_input_state, &input_data.hook);
|
|
|
|
MACRO_REGISTER_COMMAND("+fire", "i", con_key_input_counter, &input_data.fire);
|
|
|
|
MACRO_REGISTER_COMMAND("+weapon1", "i", con_key_input_weapon, (void *)1);
|
|
|
|
MACRO_REGISTER_COMMAND("+weapon2", "i", con_key_input_weapon, (void *)2);
|
|
|
|
MACRO_REGISTER_COMMAND("+weapon3", "i", con_key_input_weapon, (void *)3);
|
|
|
|
MACRO_REGISTER_COMMAND("+weapon4", "i", con_key_input_weapon, (void *)4);
|
|
|
|
MACRO_REGISTER_COMMAND("+weapon5", "i", con_key_input_weapon, (void *)5);
|
|
|
|
|
|
|
|
MACRO_REGISTER_COMMAND("+nextweapon", "i", con_key_input_counter, &input_data.next_weapon);
|
|
|
|
MACRO_REGISTER_COMMAND("+prevweapon", "i", con_key_input_counter, &input_data.prev_weapon);
|
|
|
|
|
|
|
|
MACRO_REGISTER_COMMAND("+emote", "i", con_key_input_state, &emoticon_selector_active);
|
|
|
|
MACRO_REGISTER_COMMAND("+scoreboard", "i", con_key_input_state, &scoreboard_active);
|
|
|
|
|
|
|
|
// set default key bindings
|
|
|
|
binds_set(KEY_F1, "toggle_local_console");
|
|
|
|
binds_set(KEY_F2, "toggle_remote_console");
|
|
|
|
binds_set(KEY_TAB, "+scoreboard");
|
|
|
|
binds_set(KEY_F10, "screenshot");
|
|
|
|
|
|
|
|
binds_set('A', "+left");
|
|
|
|
binds_set('D', "+right");
|
|
|
|
binds_set(KEY_SPACE, "+jump");
|
|
|
|
binds_set(KEY_MOUSE_1, "+fire");
|
|
|
|
binds_set(KEY_MOUSE_2, "+hook");
|
|
|
|
binds_set(KEY_LSHIFT, "+emote");
|
|
|
|
|
|
|
|
binds_set('1', "+weapon1");
|
|
|
|
binds_set('2', "+weapon2");
|
|
|
|
binds_set('3', "+weapon3");
|
|
|
|
binds_set('4', "+weapon4");
|
|
|
|
binds_set('5', "+weapon5");
|
|
|
|
|
|
|
|
binds_set(KEY_MOUSE_WHEEL_UP, "+prevweapon");
|
|
|
|
binds_set(KEY_MOUSE_WHEEL_DOWN, "+nextweapon");
|
|
|
|
|
|
|
|
binds_set('T', "chat all");
|
|
|
|
binds_set('Y', "chat team");
|
2008-01-16 22:14:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void console_handle_input()
|
|
|
|
{
|
2008-01-30 13:15:58 +00:00
|
|
|
int was_active = console_active();
|
2008-01-18 15:55:03 +00:00
|
|
|
|
2008-01-16 22:14:06 +00:00
|
|
|
for(int i = 0; i < inp_num_events(); i++)
|
|
|
|
{
|
2008-01-19 10:57:25 +00:00
|
|
|
INPUT_EVENT e = inp_get_event(i);
|
2008-03-01 20:03:04 +00:00
|
|
|
|
|
|
|
if(console_active())
|
|
|
|
{
|
|
|
|
if(e.key == KEY_ESC && e.flags&INPFLAG_PRESS)
|
|
|
|
console_toggle(console_type);
|
|
|
|
else
|
|
|
|
current_console()->handle_event(e);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(e.key > 0 && e.key < KEY_LAST && keybindings[e.key][0] != 0)
|
|
|
|
{
|
|
|
|
int stroke = 0;
|
|
|
|
if(e.flags&INPFLAG_PRESS)
|
|
|
|
stroke = 1;
|
|
|
|
console_execute_line_stroked(stroke, keybindings[e.key]);
|
|
|
|
}
|
|
|
|
}
|
2008-01-16 22:14:06 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 20:03:04 +00:00
|
|
|
if(was_active || console_active())
|
2008-01-18 15:55:03 +00:00
|
|
|
{
|
2008-01-16 22:14:06 +00:00
|
|
|
inp_clear_events();
|
2008-01-18 15:55:03 +00:00
|
|
|
inp_clear_key_states();
|
|
|
|
}
|
2008-01-16 22:14:06 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 14:36:36 +00:00
|
|
|
void console_toggle(int type)
|
2008-01-16 22:14:06 +00:00
|
|
|
{
|
2008-03-01 14:36:36 +00:00
|
|
|
if(console_type != type && (console_state == CONSOLE_OPEN || console_state == CONSOLE_OPENING))
|
2008-01-30 13:15:58 +00:00
|
|
|
{
|
2008-03-01 14:36:36 +00:00
|
|
|
// don't toggle console, just switch what console to use
|
2008-01-30 13:15:58 +00:00
|
|
|
}
|
|
|
|
else
|
2008-03-01 14:36:36 +00:00
|
|
|
{
|
|
|
|
if (console_state == CONSOLE_CLOSED || console_state == CONSOLE_OPEN)
|
|
|
|
{
|
|
|
|
state_change_end = time_now()+state_change_duration;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float progress = state_change_end-time_now();
|
|
|
|
float reversed_progress = state_change_duration-progress;
|
|
|
|
|
|
|
|
state_change_end = time_now()+reversed_progress;
|
|
|
|
}
|
2008-01-30 13:15:58 +00:00
|
|
|
|
2008-03-01 14:36:36 +00:00
|
|
|
if (console_state == CONSOLE_CLOSED || console_state == CONSOLE_CLOSING)
|
|
|
|
console_state = CONSOLE_OPENING;
|
|
|
|
else
|
|
|
|
console_state = CONSOLE_CLOSING;
|
2008-01-30 13:15:58 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 14:36:36 +00:00
|
|
|
console_type = type;
|
2008-01-30 13:15:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// only defined for 0<=t<=1
|
|
|
|
static float console_scale_func(float t)
|
|
|
|
{
|
|
|
|
//return t;
|
2008-02-02 11:08:31 +00:00
|
|
|
return sinf(acosf(1.0f-t));
|
2008-01-16 22:14:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void console_render()
|
|
|
|
{
|
|
|
|
RECT screen = *ui_screen();
|
2008-01-30 13:15:58 +00:00
|
|
|
float console_max_height = screen.h*3/5.0f;
|
|
|
|
float console_height;
|
|
|
|
|
|
|
|
float progress = (time_now()-(state_change_end-state_change_duration))/float(state_change_duration);
|
|
|
|
|
|
|
|
if (progress >= 1.0f)
|
|
|
|
{
|
|
|
|
if (console_state == CONSOLE_CLOSING)
|
|
|
|
console_state = CONSOLE_CLOSED;
|
|
|
|
else if (console_state == CONSOLE_OPENING)
|
|
|
|
console_state = CONSOLE_OPEN;
|
|
|
|
|
|
|
|
progress = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (console_state == CONSOLE_CLOSED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
float console_height_scale;
|
|
|
|
|
|
|
|
if (console_state == CONSOLE_OPENING)
|
|
|
|
console_height_scale = console_scale_func(progress);
|
|
|
|
else if (console_state == CONSOLE_CLOSING)
|
|
|
|
console_height_scale = console_scale_func(1.0f-progress);
|
|
|
|
else //if (console_state == CONSOLE_OPEN)
|
|
|
|
console_height_scale = console_scale_func(1.0f);
|
|
|
|
|
|
|
|
console_height = console_height_scale*console_max_height;
|
|
|
|
|
2008-01-16 22:14:06 +00:00
|
|
|
gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);
|
|
|
|
|
2008-03-01 20:03:04 +00:00
|
|
|
// do console shadow
|
2008-02-11 08:24:59 +00:00
|
|
|
gfx_texture_set(-1);
|
|
|
|
gfx_quads_begin();
|
|
|
|
gfx_setcolorvertex(0, 0,0,0, 0.5f);
|
|
|
|
gfx_setcolorvertex(1, 0,0,0, 0.5f);
|
|
|
|
gfx_setcolorvertex(2, 0,0,0, 0.0f);
|
|
|
|
gfx_setcolorvertex(3, 0,0,0, 0.0f);
|
|
|
|
gfx_quads_drawTL(0,console_height,screen.w,10.0f);
|
|
|
|
gfx_quads_end();
|
2008-01-30 13:15:58 +00:00
|
|
|
|
2008-02-11 08:24:59 +00:00
|
|
|
// do background
|
2008-02-10 01:48:39 +00:00
|
|
|
gfx_texture_set(data->images[IMAGE_CONSOLE_BG].id);
|
2008-01-16 22:14:06 +00:00
|
|
|
gfx_quads_begin();
|
2008-02-10 15:32:30 +00:00
|
|
|
gfx_setcolor(0.2f, 0.2f, 0.2f,0.9f);
|
2008-03-01 14:36:36 +00:00
|
|
|
if(console_type != 0)
|
|
|
|
gfx_setcolor(0.4f, 0.2f, 0.2f,0.9f);
|
2008-02-10 01:48:39 +00:00
|
|
|
gfx_quads_setsubset(0,-console_height*0.075f,screen.w*0.075f*0.5f,0);
|
2008-01-16 22:14:06 +00:00
|
|
|
gfx_quads_drawTL(0,0,screen.w,console_height);
|
2008-03-01 20:03:04 +00:00
|
|
|
gfx_quads_end();
|
|
|
|
|
|
|
|
// do small bar shadow
|
|
|
|
gfx_texture_set(-1);
|
|
|
|
gfx_quads_begin();
|
|
|
|
gfx_setcolorvertex(0, 0,0,0, 0.0f);
|
|
|
|
gfx_setcolorvertex(1, 0,0,0, 0.0f);
|
|
|
|
gfx_setcolorvertex(2, 0,0,0, 0.25f);
|
|
|
|
gfx_setcolorvertex(3, 0,0,0, 0.25f);
|
|
|
|
gfx_quads_drawTL(0,console_height-20,screen.w,10);
|
2008-01-16 22:14:06 +00:00
|
|
|
gfx_quads_end();
|
|
|
|
|
2008-02-11 08:24:59 +00:00
|
|
|
// do the lower bar
|
2008-02-10 01:48:39 +00:00
|
|
|
gfx_texture_set(data->images[IMAGE_CONSOLE_BAR].id);
|
|
|
|
gfx_quads_begin();
|
2008-02-10 15:32:30 +00:00
|
|
|
gfx_setcolor(1.0f, 1.0f, 1.0f, 0.9f);
|
2008-02-10 01:48:39 +00:00
|
|
|
gfx_quads_setsubset(0,0.1f,screen.w*0.015f,1-0.1f);
|
|
|
|
gfx_quads_drawTL(0,console_height-10.0f,screen.w,10.0f);
|
|
|
|
gfx_quads_end();
|
|
|
|
|
|
|
|
console_height -= 10.0f;
|
2008-03-01 14:36:36 +00:00
|
|
|
|
|
|
|
CONSOLE *console = current_console();
|
2008-02-10 01:48:39 +00:00
|
|
|
|
2008-01-16 22:14:06 +00:00
|
|
|
{
|
2008-02-11 08:24:59 +00:00
|
|
|
float font_size = 10.0f;
|
|
|
|
float row_height = font_size*1.25f;
|
2008-03-01 14:36:36 +00:00
|
|
|
float width = gfx_text_width(0, font_size, console->input, -1);
|
2008-01-18 15:55:03 +00:00
|
|
|
float x = 3, y = console_height - row_height - 2;
|
2008-03-01 14:36:36 +00:00
|
|
|
const char *prompt = ">";
|
|
|
|
if(console_type)
|
|
|
|
{
|
|
|
|
if(client_rcon_authed())
|
|
|
|
prompt = "rcon>";
|
|
|
|
else
|
|
|
|
prompt = "rcon password>";
|
|
|
|
}
|
|
|
|
|
|
|
|
float prompt_width = gfx_text_width(0, font_size,prompt, -1)+2;
|
2008-01-16 22:14:06 +00:00
|
|
|
|
2008-03-01 14:36:36 +00:00
|
|
|
gfx_text(0, x, y, font_size, prompt, -1);
|
|
|
|
gfx_text(0, x+prompt_width, y, font_size, console->input, -1);
|
2008-01-18 15:55:03 +00:00
|
|
|
gfx_text(0, x+prompt_width+width+1, y, font_size, "_", -1);
|
2008-01-16 22:14:06 +00:00
|
|
|
|
2008-03-01 14:36:36 +00:00
|
|
|
char buf[128];
|
|
|
|
str_format(buf, sizeof(buf), "Teewars v%s %s", TEEWARS_VERSION);
|
2008-01-30 13:15:58 +00:00
|
|
|
float version_width = gfx_text_width(0, font_size, buf, -1);
|
|
|
|
gfx_text(0, screen.w-version_width-5, y, font_size, buf, -1);
|
|
|
|
|
2008-01-18 15:55:03 +00:00
|
|
|
y -= row_height;
|
2008-01-16 22:14:06 +00:00
|
|
|
|
2008-03-01 14:36:36 +00:00
|
|
|
char *entry = (char *)ringbuf_last(console->backlog);
|
2008-02-04 00:13:34 +00:00
|
|
|
while (y > 0.0f && entry)
|
2008-01-16 22:14:06 +00:00
|
|
|
{
|
2008-02-04 00:13:34 +00:00
|
|
|
gfx_text(0, x, y, font_size, entry, -1);
|
2008-01-18 15:55:03 +00:00
|
|
|
y -= row_height;
|
2008-02-04 00:13:34 +00:00
|
|
|
|
2008-03-01 14:36:36 +00:00
|
|
|
entry = (char *)ringbuf_prev(console->backlog, entry);
|
2008-01-16 22:14:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int console_active()
|
|
|
|
{
|
2008-01-30 13:15:58 +00:00
|
|
|
return console_state != CONSOLE_CLOSED;
|
2008-01-16 22:14:06 +00:00
|
|
|
}
|
|
|
|
|