about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-08-27 16:23:15 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-08-27 16:23:15 +0000
commit68c52dd5efca7ed66b083b70439337b8f1205c15 (patch)
tree2690d39776899a8bdea18801cb6074c35d0a941e
parentdc67b341387f539f11f8964c299ce479e36cc142 (diff)
downloadzcatch-68c52dd5efca7ed66b083b70439337b8f1205c15.tar.gz
zcatch-68c52dd5efca7ed66b083b70439337b8f1205c15.zip
repaired the local console
-rw-r--r--src/engine/e_console.c8
-rw-r--r--src/engine/e_console.h2
-rw-r--r--src/engine/server/es_server.c4
-rw-r--r--src/game/client/components/console.cpp66
-rw-r--r--src/game/client/components/console.hpp8
-rw-r--r--src/game/client/components/hud.cpp11
-rw-r--r--src/game/client/gameclient.cpp1
7 files changed, 83 insertions, 17 deletions
diff --git a/src/engine/e_console.c b/src/engine/e_console.c
index 8dd9dbcd..822d770a 100644
--- a/src/engine/e_console.c
+++ b/src/engine/e_console.c
@@ -198,17 +198,19 @@ void console_register(COMMAND *cmd)
 	first_command = cmd;
 }
 
-static void (*print_callback)(const char *) = 0x0;
+static void (*print_callback)(const char *, void *) = 0x0;
+static void *print_callback_userdata;
 
-void console_register_print_callback(void (*callback)(const char *))
+void console_register_print_callback(void (*callback)(const char *, void *), void *user_data)
 {
 	print_callback = callback;
+	print_callback_userdata = user_data;
 }
 
 void console_print(const char *str)
 {
 	if (print_callback)
-		print_callback(str);
+		print_callback(str, print_callback_userdata);
 }
 
 void console_execute_line_stroked(int stroke, const char *str)
diff --git a/src/engine/e_console.h b/src/engine/e_console.h
index 2170e8d7..75325d7e 100644
--- a/src/engine/e_console.h
+++ b/src/engine/e_console.h
@@ -22,7 +22,7 @@ void console_execute_line(const char *str);
 void console_execute_line_stroked(int stroke, const char *str);
 void console_execute_file(const char *filename);
 void console_print(const char *str);
-void console_register_print_callback(void (*callback)(const char *));
+void console_register_print_callback(void (*callback)(const char *, void *user_data), void *user_data);
 
 /*int console_result_string(void *result, int index, const char **str);
 int console_result_int(void *result, int index, int *i);
diff --git a/src/engine/server/es_server.c b/src/engine/server/es_server.c
index 6e015dbe..905ee272 100644
--- a/src/engine/server/es_server.c
+++ b/src/engine/server/es_server.c
@@ -572,7 +572,7 @@ static void server_send_rcon_line(int cid, const char *line)
 	server_send_msg(cid);
 }
 
-static void server_send_rcon_line_authed(const char *line)
+static void server_send_rcon_line_authed(const char *line, void *user_data)
 {
 	static volatile int reentry_guard = 0;
 	int i;
@@ -913,7 +913,7 @@ static int server_run()
 	net_init();
 	
 	/* */
-	console_register_print_callback(server_send_rcon_line_authed);
+	console_register_print_callback(server_send_rcon_line_authed, 0);
 
 	/* load map */
 	if(!server_load_map(config.sv_map))
diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp
index 6437b718..a67a1138 100644
--- a/src/game/client/components/console.cpp
+++ b/src/game/client/components/console.cpp
@@ -162,7 +162,6 @@ static float console_scale_func(float t)
 
 void CONSOLE::on_render()
 {
-
     RECT screen = *ui_screen();
 	float console_max_height = screen.h*3/5.0f;
 	float console_height;
@@ -294,7 +293,70 @@ void CONSOLE::on_message(int msgtype, void *rawmsg)
 
 bool CONSOLE::on_input(INPUT_EVENT e)
 {
-	return false;
+	if(console_state == CONSOLE_CLOSED)
+		return false;
+	if(e.key >= KEY_F1 && e.key <= KEY_F25)
+		return false;
+
+	if(e.key == KEY_ESC && (e.flags&INPFLAG_PRESS))
+		toggle(console_type);
+	else
+		current_console()->on_input(e);
+		
+	return true;
+}
+
+void CONSOLE::toggle(int type)
+{
+	if(console_type != type && (console_state == CONSOLE_OPEN || console_state == CONSOLE_OPENING))
+	{
+		// don't toggle console, just switch what console to use
+	}
+	else
+	{	
+		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;
+		}
+
+		if (console_state == CONSOLE_CLOSED || console_state == CONSOLE_CLOSING)
+			console_state = CONSOLE_OPENING;
+		else
+			console_state = CONSOLE_CLOSING;
+	}
+
+	console_type = type;
+}
+
+void CONSOLE::con_toggle_local_console(void *result, void *user_data)
+{
+	((CONSOLE *)user_data)->toggle(0);
+}
+
+void CONSOLE::con_toggle_remote_console(void *result, void *user_data)
+{
+	((CONSOLE *)user_data)->toggle(1);
+}
+
+void CONSOLE::client_console_print_callback(const char *str, void *user_data)
+{
+	((CONSOLE *)user_data)->local_console.print_line(str);
+}
+
+void CONSOLE::on_init()
+{
+	//
+	console_register_print_callback(client_console_print_callback, this);
+	
+	MACRO_REGISTER_COMMAND("toggle_local_console", "", con_toggle_local_console, this);
+	MACRO_REGISTER_COMMAND("toggle_remote_console", "", con_toggle_remote_console, this);
 }
 
 
diff --git a/src/game/client/components/console.hpp b/src/game/client/components/console.hpp
index 988e4ea3..8c6a9c72 100644
--- a/src/game/client/components/console.hpp
+++ b/src/game/client/components/console.hpp
@@ -43,10 +43,18 @@ class CONSOLE : public COMPONENT
 	int console_state;
 	float state_change_end;
 	float state_change_duration;
+
+
+	void toggle(int type);
+
+	static void client_console_print_callback(const char *str, void *user_data);
+	static void con_toggle_local_console(void *result, void *user_data);
+	static void con_toggle_remote_console(void *result, void *user_data);
 	
 public:
 	CONSOLE();
 
+	virtual void on_init();
 	virtual void on_reset();
 	virtual void on_render();
 	virtual void on_message(int msgtype, void *rawmsg);
diff --git a/src/game/client/components/hud.cpp b/src/game/client/components/hud.cpp
index 0e8d371c..a73ed955 100644
--- a/src/game/client/components/hud.cpp
+++ b/src/game/client/components/hud.cpp
@@ -196,14 +196,9 @@ void HUD::render_cursor()
 	gfx_quads_begin();
 
 	// render cursor
-	// TODO: repair me
-	//if (!menu_active)
-	{
-		dbg_msg("", "%f %f", gameclient.controls->target_pos.x, gameclient.controls->target_pos.y);
-		select_sprite(data->weapons.id[gameclient.snap.local_character->weapon%NUM_WEAPONS].sprite_cursor);
-		float cursorsize = 64;
-		draw_sprite(gameclient.controls->target_pos.x, gameclient.controls->target_pos.y, cursorsize);
-	}
+	select_sprite(data->weapons.id[gameclient.snap.local_character->weapon%NUM_WEAPONS].sprite_cursor);
+	float cursorsize = 64;
+	draw_sprite(gameclient.controls->target_pos.x, gameclient.controls->target_pos.y, cursorsize);
 	gfx_quads_end();
 }
 
diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp
index 0fb6c61e..0222b6b9 100644
--- a/src/game/client/gameclient.cpp
+++ b/src/game/client/gameclient.cpp
@@ -47,7 +47,6 @@ static ITEMS items;
 static MAPLAYERS maplayers_background(MAPLAYERS::TYPE_BACKGROUND);
 static MAPLAYERS maplayers_foreground(MAPLAYERS::TYPE_FOREGROUND);
 
-
 GAMECLIENT::STACK::STACK() { num = 0; }
 void GAMECLIENT::STACK::add(class COMPONENT *component) { components[num++] = component; }