about summary refs log tree commit diff
path: root/src/game/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/client')
-rw-r--r--src/game/client/gc_client.cpp2
-rw-r--r--src/game/client/gc_console.cpp54
-rw-r--r--src/game/client/gc_hooks.cpp32
3 files changed, 66 insertions, 22 deletions
diff --git a/src/game/client/gc_client.cpp b/src/game/client/gc_client.cpp
index d72efe8e..bbb00c27 100644
--- a/src/game/client/gc_client.cpp
+++ b/src/game/client/gc_client.cpp
@@ -1183,7 +1183,7 @@ void render_game()
 	{
 		if(chat_mode != CHATMODE_NONE)
 		{
-			if(inp_key_down(KEY_ENTER))
+			if(inp_key_down(KEY_ENTER) || inp_key_down(KEY_KP_ENTER))
 			{
 				// send message
 				if(chat_input_len)
diff --git a/src/game/client/gc_console.cpp b/src/game/client/gc_console.cpp
index 595560b6..ddfb4b48 100644
--- a/src/game/client/gc_console.cpp
+++ b/src/game/client/gc_console.cpp
@@ -40,13 +40,35 @@ static void client_console_print(const char *str)
 	//dbg_msg("console", "FROM CLIENT!! %s", str);
 }
 
+static void connect_command(struct lexer_result *result, void *user_data)
+{
+	const char *address;
+	extract_result_string(result, 1, &address);
+	client_connect(address);
+}
+
+static void disconnect_command(struct lexer_result *result, void *user_data)
+{
+	client_disconnect();
+}
+
+static void quit_command(struct lexer_result *result, void *user_data)
+{
+	client_quit();
+}
+
 void client_console_init()
 {
 	console_register_print_callback(client_console_print);
+	MACRO_REGISTER_COMMAND("quit", "", quit_command, 0x0);
+	MACRO_REGISTER_COMMAND("connect", "s", connect_command, 0x0);
+	MACRO_REGISTER_COMMAND("disconnect", "", disconnect_command, 0x0);
 }
 
 void console_handle_input()
 {
+	int was_active = active;
+
 	for(int i = 0; i < inp_num_events(); i++)
 	{
 		INPUTEVENT e = inp_get_event(i);
@@ -76,17 +98,23 @@ void console_handle_input()
 					console_input_len--;
 				}
 			}
-			else if(e.key == KEY_ENTER)
+			else if(e.key == KEY_ENTER || e.key == KEY_KP_ENTER)
 			{
-				console_execute(console_input);
-				console_input[0] = 0;
-				console_input_len = 0;
+				if (console_input_len)
+				{
+					console_execute(console_input);
+					console_input[0] = 0;
+					console_input_len = 0;
+				}
 			}
 		}
 	}
 
-	if (active)
+	if (was_active || active)
+	{
 		inp_clear_events();
+		inp_clear_key_states();
+	}
 }
 
 void console_toggle()
@@ -108,15 +136,17 @@ void console_render()
 
 	{
 		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;
+		float row_height = font_size*1.4f;
+		float width = gfx_text_width(0, font_size, console_input, -1);
+		float x = 3, y = console_height - row_height - 2;
 		int backlog_index = backlog_len-1;
+		float prompt_width = gfx_text_width(0, font_size, ">", -1)+2;
 
-		gfx_text(0, x, y, font_size, console_input, -1);
-		gfx_text(0, x+width+1, y, font_size, "_", -1);
+		gfx_text(0, x, y, font_size, ">", -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);
 
-		y -= row_spacing;
+		y -= row_height;
 
 		while (y > 0.0f && backlog_index >= 0)
 		{
@@ -124,7 +154,7 @@ void console_render()
 			gfx_text(0, x, y, font_size, line, -1);
 
 			backlog_index--;
-			y -= row_spacing;
+			y -= row_height;
 		}
 	}
 }
diff --git a/src/game/client/gc_hooks.cpp b/src/game/client/gc_hooks.cpp
index d70e84a5..34196eaa 100644
--- a/src/game/client/gc_hooks.cpp
+++ b/src/game/client/gc_hooks.cpp
@@ -25,6 +25,10 @@ extern void menu_init();
 extern bool menu_active;
 extern bool menu_game_active;
 
+extern "C" void modc_preinit()
+{
+	client_console_init();
+}
 
 extern "C" void modc_init()
 {
@@ -37,8 +41,6 @@ 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);
@@ -299,6 +301,8 @@ extern "C" void modc_render()
 	if(client_state() == CLIENTSTATE_ONLINE)
 	{
 		render_game();
+		if (console_active())
+			console_render();
 
 		// handle team switching
 		// TODO: FUGLY!!!
@@ -314,10 +318,8 @@ extern "C" void modc_render()
 	{
 		menu_render();
 		if (console_active())
-		{
 			console_render();
-			return;
-		}
+		return;
 	}
 
 	//
@@ -346,10 +348,22 @@ extern "C" int modc_snap_input(int *data)
 	else
 	{
 		input_data.state = STATE_PLAYING;
-		input_data.left = inp_key_state(config.key_move_left);
-		input_data.right = inp_key_state(config.key_move_right);
-		input_data.hook = inp_key_state(config.key_hook);
-		input_data.jump  = inp_key_state(config.key_jump);
+
+		// TODO: this doesn't feel too pretty... look into it?
+		if (console_active())
+		{
+			input_data.left = 0;
+			input_data.right = 0;
+			input_data.hook = 0;
+			input_data.jump = 0;
+		}
+		else
+		{
+			input_data.left = inp_key_state(config.key_move_left);
+			input_data.right = inp_key_state(config.key_move_right);
+			input_data.hook = inp_key_state(config.key_hook);
+			input_data.jump  = inp_key_state(config.key_jump);
+		}
 	}
 
 	// stress testing