diff options
Diffstat (limited to 'src/game/client')
| -rw-r--r-- | src/game/client/gc_client.cpp | 33 | ||||
| -rw-r--r-- | src/game/client/gc_client.h | 4 | ||||
| -rw-r--r-- | src/game/client/gc_console.cpp | 340 | ||||
| -rw-r--r-- | src/game/client/gc_console.h | 3 | ||||
| -rw-r--r-- | src/game/client/gc_hooks.cpp | 39 | ||||
| -rw-r--r-- | src/game/client/gc_menu.cpp | 35 |
6 files changed, 278 insertions, 176 deletions
diff --git a/src/game/client/gc_client.cpp b/src/game/client/gc_client.cpp index fae66cf0..eae9f52f 100644 --- a/src/game/client/gc_client.cpp +++ b/src/game/client/gc_client.cpp @@ -793,22 +793,15 @@ void render_game() // send message if(chat_input_len) { - if(chat_mode == CHATMODE_CONSOLE) - config_set(chat_input); - else if(chat_mode == CHATMODE_REMOTECONSOLE) - client_rcon(chat_input); + // send chat message + msg_pack_start(MSG_SAY, MSGFLAG_VITAL); + if(chat_mode == CHATMODE_ALL) + msg_pack_int(0); else - { - // send chat message - msg_pack_start(MSG_SAY, MSGFLAG_VITAL); - if(chat_mode == CHATMODE_ALL) - msg_pack_int(0); - else - msg_pack_int(1); - msg_pack_string(chat_input, 512); - msg_pack_end(); - client_send_msg(); - } + msg_pack_int(1); + msg_pack_string(chat_input, 512); + msg_pack_end(); + client_send_msg(); } chat_mode = CHATMODE_NONE; @@ -847,13 +840,7 @@ void render_game() if(inp_key_down(config.key_teamchat)) chat_mode = CHATMODE_TEAM; - - if(inp_key_down(config.key_console)) - chat_mode = CHATMODE_CONSOLE; - if(inp_key_down(config.key_remoteconsole)) - chat_mode = CHATMODE_REMOTECONSOLE; - if(chat_mode != CHATMODE_NONE) { mem_zero(chat_input, sizeof(chat_input)); @@ -1252,10 +1239,6 @@ void render_game() str_format(buf, sizeof(buf), "All: %s_", chat_input); else if(chat_mode == CHATMODE_TEAM) str_format(buf, sizeof(buf), "Team: %s_", chat_input); - else if(chat_mode == CHATMODE_CONSOLE) - str_format(buf, sizeof(buf), "Console: %s_", chat_input); - else if(chat_mode == CHATMODE_REMOTECONSOLE) - str_format(buf, sizeof(buf), "Rcon: %s_", chat_input); else str_format(buf, sizeof(buf), "Chat: %s_", chat_input); gfx_text(0, x, y, 8.0f, buf, 380); diff --git a/src/game/client/gc_client.h b/src/game/client/gc_client.h index 93a90a86..0b76e38c 100644 --- a/src/game/client/gc_client.h +++ b/src/game/client/gc_client.h @@ -74,8 +74,8 @@ enum CHATMODE_NONE=0, CHATMODE_ALL, CHATMODE_TEAM, - CHATMODE_CONSOLE, - CHATMODE_REMOTECONSOLE, + //CHATMODE_CONSOLE, + //CHATMODE_REMOTECONSOLE, }; extern int chat_mode; diff --git a/src/game/client/gc_console.cpp b/src/game/client/gc_console.cpp index 75c20e15..21e3bc34 100644 --- a/src/game/client/gc_console.cpp +++ b/src/game/client/gc_console.cpp @@ -26,14 +26,150 @@ enum CONSOLE_CLOSING, }; -static char console_history_data[65536]; -static RINGBUFFER *console_history; +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; + } + } -static char console_backlog_data[65536]; -static RINGBUFFER *console_backlog; + if(e.key == KEY_BACKSPACE) + { + if(input_len > 0) + { + input[input_len-1] = 0; + input_len--; -static unsigned int console_input_len = 0; -static char console_input[256] = {0}; + history_entry = 0x0; + } + } + else if(e.key == KEY_ENTER || e.key == KEY_KP_ENTER) + { + 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; + } + } + else if (e.key == KEY_UP) + { + if (history_entry) + { + char *test = (char *)ringbuf_prev(history, history_entry); + + if (test) + history_entry = test; + } + else + history_entry = (char *)ringbuf_last(history); + + if (history_entry) + { + unsigned int len = strlen(history_entry); + if (len < sizeof(input) - 1) + { + mem_copy(input, history_entry, len+1); + input_len = len; + } + } + + } + else if (e.key == KEY_DOWN) + { + if (history_entry) + history_entry = (char *)ringbuf_next(history, history_entry); + + if (history_entry) + { + unsigned int len = strlen(history_entry); + if (len < sizeof(input) - 1) + { + mem_copy(input, history_entry, len+1); + + input_len = len; + } + } + else + { + input[0] = 0; + input_len = 0; + } + } + } + + 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; static int console_state = CONSOLE_CLOSED; static float state_change_end = 0.0f; static const float state_change_duration = 0.1f; @@ -44,17 +180,22 @@ static float time_now() return float(time_get()-time_start)/float(time_freq()); } -static void client_console_print(const char *str) +static CONSOLE *current_console() { - int len = strlen(str); - - if (len > 255) - len = 255; + if(console_type != 0) + return &remote_console; + return &local_console; +} - char *entry = (char *)ringbuf_allocate(console_backlog, len+1); - mem_copy(entry, str, len+1); +static void client_console_print(const char *str) +{ + local_console.print_line(str); } +void console_rcon_print(const char *line) +{ + remote_console.print_line(line); +} static void con_team(void *result, void *user_data) { @@ -63,7 +204,8 @@ static void con_team(void *result, void *user_data) send_switch_team(new_team); } -static void command_history(void *result, void *user_data) +/* +static void con_history(void *result, void *user_data) { char *entry = (char *)ringbuf_first(console_history); @@ -73,28 +215,23 @@ static void command_history(void *result, void *user_data) entry = (char *)ringbuf_next(console_history, entry); } -} +}*/ void send_kill(int client_id); -static void command_kill(void *result, void *user_data) +static void con_kill(void *result, void *user_data) { send_kill(-1); } void client_console_init() { - console_history = ringbuf_init(console_history_data, sizeof(console_history_data)); - console_backlog = ringbuf_init(console_backlog_data, sizeof(console_backlog_data)); - console_register_print_callback(client_console_print); MACRO_REGISTER_COMMAND("team", "i", con_team, 0x0); - MACRO_REGISTER_COMMAND("history", "", command_history, 0x0); - MACRO_REGISTER_COMMAND("kill", "", command_kill, 0x0); + //MACRO_REGISTER_COMMAND("history", "", con_history, 0x0); + MACRO_REGISTER_COMMAND("kill", "", con_kill, 0x0); } -static char *console_history_entry = 0x0; - void console_handle_input() { int was_active = console_active(); @@ -103,95 +240,12 @@ void console_handle_input() { INPUT_EVENT e = inp_get_event(i); - if (e.key == KEY_F3) - { - console_toggle(); - } - - if (console_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++; - - console_history_entry = 0x0; - } - } - - if(e.key == KEY_BACKSPACE) - { - if(console_input_len > 0) - { - console_input[console_input_len-1] = 0; - console_input_len--; - - console_history_entry = 0x0; - } - } - else if(e.key == KEY_ENTER || e.key == KEY_KP_ENTER) - { - if (console_input_len) - { - char *entry = (char *)ringbuf_allocate(console_history, console_input_len+1); - mem_copy(entry, console_input, console_input_len+1); - - console_execute(console_input); - console_input[0] = 0; - console_input_len = 0; - - console_history_entry = 0x0; - } - } - else if (e.key == KEY_UP) - { - if (console_history_entry) - { - char *test = (char *)ringbuf_prev(console_history, console_history_entry); - - if (test) - console_history_entry = test; - } - else - console_history_entry = (char *)ringbuf_last(console_history); - - if (console_history_entry) - { - unsigned int len = strlen(console_history_entry); - if (len < sizeof(console_input) - 1) - { - mem_copy(console_input, console_history_entry, len+1); - - console_input_len = len; - } - } - - } - else if (e.key == KEY_DOWN) - { - if (console_history_entry) - console_history_entry = (char *)ringbuf_next(console_history, console_history_entry); - - if (console_history_entry) - { - unsigned int len = strlen(console_history_entry); - if (len < sizeof(console_input) - 1) - { - mem_copy(console_input, console_history_entry, len+1); - - console_input_len = len; - } - } - else - { - console_input[0] = 0; - console_input_len = 0; - } - } - } + if (e.key == config.key_toggleconsole) + console_toggle(0); + else if (e.key == config.key_toggleconsole+1) + console_toggle(1); + else if(console_active()) + current_console()->handle_event(e); } if (was_active || console_active()) @@ -201,24 +255,33 @@ void console_handle_input() } } -void console_toggle() +void console_toggle(int type) { - if (console_state == CONSOLE_CLOSED || console_state == CONSOLE_OPEN) + if(console_type != type && (console_state == CONSOLE_OPEN || console_state == CONSOLE_OPENING)) { - state_change_end = time_now()+state_change_duration; + // don't toggle console, just switch what console to use } else - { - float progress = state_change_end-time_now(); - float reversed_progress = state_change_duration-progress; + { + 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; + } - state_change_end = time_now()+reversed_progress; + if (console_state == CONSOLE_CLOSED || console_state == CONSOLE_CLOSING) + console_state = CONSOLE_OPENING; + else + console_state = CONSOLE_CLOSING; } - if (console_state == CONSOLE_CLOSED || console_state == CONSOLE_CLOSING) - console_state = CONSOLE_OPENING; - else - console_state = CONSOLE_CLOSING; + console_type = type; } // only defined for 0<=t<=1 @@ -276,6 +339,8 @@ void console_render() gfx_texture_set(data->images[IMAGE_CONSOLE_BG].id); gfx_quads_begin(); gfx_setcolor(0.2f, 0.2f, 0.2f,0.9f); + if(console_type != 0) + gfx_setcolor(0.4f, 0.2f, 0.2f,0.9f); gfx_quads_setsubset(0,-console_height*0.075f,screen.w*0.075f*0.5f,0); gfx_quads_drawTL(0,0,screen.w,console_height); gfx_quads_end(); @@ -287,36 +352,45 @@ void console_render() 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; + + CONSOLE *console = current_console(); { float font_size = 10.0f; float row_height = font_size*1.25f; - float width = gfx_text_width(0, font_size, console_input, -1); + float width = gfx_text_width(0, font_size, console->input, -1); float x = 3, y = console_height - row_height - 2; - float prompt_width = gfx_text_width(0, font_size, ">", -1)+2; + 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; - gfx_text(0, x, y, font_size, ">", -1); - gfx_text(0, x+prompt_width, y, font_size, console_input, -1); + gfx_text(0, x, y, font_size, prompt, -1); + gfx_text(0, x+prompt_width, y, font_size, console->input, -1); gfx_text(0, x+prompt_width+width+1, y, font_size, "_", -1); - char buf[64]; - str_format(buf, sizeof(buf), "Teewars v%s", TEEWARS_VERSION); + char buf[128]; + str_format(buf, sizeof(buf), "Teewars v%s %s", TEEWARS_VERSION); float version_width = gfx_text_width(0, font_size, buf, -1); gfx_text(0, screen.w-version_width-5, y, font_size, buf, -1); y -= row_height; - char *entry = (char *)ringbuf_last(console_backlog); + char *entry = (char *)ringbuf_last(console->backlog); while (y > 0.0f && entry) { gfx_text(0, x, y, font_size, entry, -1); y -= row_height; - entry = (char *)ringbuf_prev(console_backlog, entry); + entry = (char *)ringbuf_prev(console->backlog, entry); } } } diff --git a/src/game/client/gc_console.h b/src/game/client/gc_console.h index 87628a2a..0d516820 100644 --- a/src/game/client/gc_console.h +++ b/src/game/client/gc_console.h @@ -2,9 +2,10 @@ #define _GC_CONSOLE_H void console_handle_input(); -void console_toggle(); +void console_toggle(int tpye); void console_render(); int console_active(); void client_console_init(); +void console_rcon_print(const char *line); #endif diff --git a/src/game/client/gc_hooks.cpp b/src/game/client/gc_hooks.cpp index 9292d08c..d8863be7 100644 --- a/src/game/client/gc_hooks.cpp +++ b/src/game/client/gc_hooks.cpp @@ -31,9 +31,25 @@ extern "C" void modc_console_init() client_console_init(); } +static void load_sounds_thread(void *) +{ + // load sounds + for(int s = 0; s < data->num_sounds; s++) + { + //render_loading(current/total); + for(int i = 0; i < data->sounds[s].num_sounds; i++) + { + int id = snd_load_wv(data->sounds[s].sounds[i].filename); + data->sounds[s].sounds[i].id = id; + } + } +} + extern "C" void modc_init() { static FONT_SET default_font; + + int64 start = time_get(); int before = gfx_memory_usage(); font_set_load(&default_font, "data/fonts/default_font%d.tfnt", "data/fonts/default_font%d.png", "data/fonts/default_font%d_b.png", 14, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 36); @@ -56,9 +72,9 @@ extern "C" void modc_init() // TODO: should be removed snd_set_listener_pos(0.0f, 0.0f); - float total = data->num_sounds+data->num_images; + float total = data->num_images; float current = 0; - + // load textures for(int i = 0; i < data->num_images; i++) { @@ -66,8 +82,14 @@ extern "C" void modc_init() data->images[i].id = gfx_load_texture(data->images[i].filename, IMG_AUTO); current++; } + + skin_init(); + //load_sounds_thread(0); + thread_create(load_sounds_thread, 0); + // load sounds + /* for(int s = 0; s < data->num_sounds; s++) { render_loading(current/total); @@ -83,9 +105,11 @@ extern "C" void modc_init() } current++; - } - - skin_init(); + }*/ + + + int64 end = time_get(); + dbg_msg("", "%f.2ms", ((end-start)*1000)/(float)time_freq()); } extern "C" void modc_entergame() @@ -324,6 +348,11 @@ extern "C" void modc_render() console_render(); } +extern "C" void modc_rcon_line(const char *line) +{ + console_rcon_print(line); +} + extern "C" int modc_snap_input(int *data) { picked_up_weapon = -1; diff --git a/src/game/client/gc_menu.cpp b/src/game/client/gc_menu.cpp index ec2cc2fe..96b4a9f1 100644 --- a/src/game/client/gc_menu.cpp +++ b/src/game/client/gc_menu.cpp @@ -90,16 +90,24 @@ static void ui_draw_browse_icon(int what, const RECT *r) gfx_quads_end(); } +static vec4 button_color_mul(const void *id) +{ + if(ui_active_item() == id) + return vec4(1,1,1,0.5f); + else if(ui_hot_item() == id) + return vec4(1,1,1,1.5f); + return vec4(1,1,1,1); +} + static void ui_draw_menu_button(const void *id, const char *text, int checked, const RECT *r, const void *extra) { - ui_draw_rect(r, vec4(1,1,1,0.5f), CORNER_ALL, 5.0f); + ui_draw_rect(r, vec4(1,1,1,0.5f)*button_color_mul(id), CORNER_ALL, 5.0f); ui_do_label(r, text, 18.0f, 0); } - static void ui_draw_keyselect_button(const void *id, const char *text, int checked, const RECT *r, const void *extra) { - ui_draw_rect(r, vec4(1,1,1,0.5f), CORNER_ALL, 5.0f); + ui_draw_rect(r, vec4(1,1,1,0.5f)*button_color_mul(id), CORNER_ALL, 5.0f); ui_do_label(r, text, 14.0f, 0); } @@ -152,7 +160,7 @@ static void ui_draw_checkbox_common(const void *id, const char *text, const char ui_vsplit_l(&t, 5.0f, 0, &t); ui_margin(&c, 2.0f, &c); - ui_draw_rect(&c, vec4(1,1,1,0.25f), CORNER_ALL, 3.0f); + ui_draw_rect(&c, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 3.0f); c.y += 2; ui_do_label(&c, boxtext, 12.0f, 0); ui_do_label(&t, text, 14.0f, -1); @@ -337,7 +345,7 @@ float ui_do_scrollbar_v(const void *id, const RECT *rect, float current) slider = handle; ui_margin(&slider, 5.0f, &slider); - ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_ALL, 2.5f); + ui_draw_rect(&slider, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 2.5f); return ret; } @@ -393,7 +401,7 @@ float ui_do_scrollbar_h(const void *id, const RECT *rect, float current) slider = handle; ui_margin(&slider, 5.0f, &slider); - ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_ALL, 2.5f); + ui_draw_rect(&slider, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 2.5f); return ret; } @@ -761,6 +769,13 @@ static void menu2_render_serverbrowser(RECT main_view) int new_selected = -1; int selected_index = -1; + int num_players = 0; + + for (int i = 0; i < num_servers; i++) + { + SERVER_INFO *item = client_serverbrowse_sorted_get(i); + num_players += item->num_players; + } for (int i = 0; i < num_servers; i++) { @@ -1069,7 +1084,7 @@ static void menu2_render_serverbrowser(RECT main_view) ui_draw_rect(&status, vec4(1,1,1,0.25f), CORNER_B, 5.0f); ui_vmargin(&status, 50.0f, &status); char buf[128]; - str_format(buf, sizeof(buf), "%d of %d servers", client_serverbrowse_sorted_num(), client_serverbrowse_num()); + str_format(buf, sizeof(buf), "%d of %d servers, %d players", client_serverbrowse_sorted_num(), client_serverbrowse_num(), num_players); ui_do_label(&status, buf, 14.0f, -1); // render toolbox @@ -1302,8 +1317,7 @@ static void menu2_render_settings_controls(RECT main_view) { "Emoticon:", &config.key_emoticon }, { "Chat:", &config.key_chat }, { "Team Chat:", &config.key_teamchat }, - { "Console:", &config.key_console }, - { "Remote Console:", &config.key_remoteconsole }, + { "Toggle Console:", &config.key_toggleconsole }, { "Screenshot:", &config.key_screenshot }, }; @@ -1530,6 +1544,7 @@ static void menu2_render_settings_sound(RECT main_view) static void menu2_render_settings_network(RECT main_view) { + /* RECT button; ui_vsplit_l(&main_view, 300.0f, &main_view, 0); @@ -1539,7 +1554,7 @@ static void menu2_render_settings_network(RECT main_view) ui_vsplit_l(&button, 110.0f, 0, &button); ui_vsplit_l(&button, 180.0f, &button, 0); ui_do_edit_box(&config.rcon_password, &button, config.rcon_password, sizeof(config.rcon_password), true); - } + }*/ } static void menu2_render_settings(RECT main_view) |