about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-08-30 21:01:57 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-08-30 21:01:57 +0000
commit8949d77fc4b84869c3b2212afa28930ee2d6cfdd (patch)
tree7988e2212d40326801158e74c52e2fcbd3f1eff9 /src
parent2b53f91a1f24dfba2837b458177042efd48260cd (diff)
downloadzcatch-8949d77fc4b84869c3b2212afa28930ee2d6cfdd.tar.gz
zcatch-8949d77fc4b84869c3b2212afa28930ee2d6cfdd.zip
added the binding commands to the console again
Diffstat (limited to 'src')
-rw-r--r--src/game/client/components/binds.cpp80
-rw-r--r--src/game/client/components/binds.hpp8
2 files changed, 55 insertions, 33 deletions
diff --git a/src/game/client/components/binds.cpp b/src/game/client/components/binds.cpp
index 18b0ae1e..7fd318ab 100644
--- a/src/game/client/components/binds.cpp
+++ b/src/game/client/components/binds.cpp
@@ -1,3 +1,5 @@
+#include <stdlib.h> // atoi
+#include <string.h> // strcmp
 #include <engine/e_client_interface.h>
 #include "binds.hpp"
 
@@ -63,9 +65,8 @@ const char *BINDS::get(int keyid)
 
 void BINDS::set_defaults()
 {
-	unbindall();
-
 	// set default key bindings
+	unbindall();
 	bind(KEY_F1, "toggle_local_console");
 	bind(KEY_F2, "toggle_remote_console");
 	bind(KEY_TAB, "+scoreboard");
@@ -93,34 +94,23 @@ void BINDS::set_defaults()
 
 void BINDS::on_init()
 {
+	// bindings
+	MACRO_REGISTER_COMMAND("bind", "sr", con_bind, this);
+	MACRO_REGISTER_COMMAND("unbind", "s", con_unbind, this);
+	MACRO_REGISTER_COMMAND("unbindall", "", con_unbindall, this);
+	MACRO_REGISTER_COMMAND("dump_binds", "", con_dump_binds, this);
+	
+	// default bindings
 	set_defaults();
 }
 
-/*
-static int get_key_id(const char *key_name)
-{
-	// check for numeric
-	if(key_name[0] == '#')
-	{
-		int i = atoi(key_name+1);
-		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_bind(void *result, void *user_data)
+
+void BINDS::con_bind(void *result, void *user_data)
 {
+	BINDS *binds = (BINDS *)user_data;
 	const char *key_name = console_arg_string(result, 0);
-	int id = get_key_id(key_name);
+	int id = binds->get_key_id(key_name);
 	
 	if(!id)
 	{
@@ -128,14 +118,15 @@ static void con_bind(void *result, void *user_data)
 		return;
 	}
 	
-	binds_set(id, console_arg_string(result, 1));
+	binds->bind(id, console_arg_string(result, 1));
 }
 
 
-static void con_unbind(void *result, void *user_data)
+void BINDS::con_unbind(void *result, void *user_data)
 {
+	BINDS *binds = (BINDS *)user_data;
 	const char *key_name = console_arg_string(result, 0);
-	int id = get_key_id(key_name);
+	int id = binds->get_key_id(key_name);
 	
 	if(!id)
 	{
@@ -143,26 +134,49 @@ static void con_unbind(void *result, void *user_data)
 		return;
 	}
 	
-	binds_set(id, "");
+	binds->bind(id, "");
 }
 
 
-static void con_unbindall(void *result, void *user_data)
+void BINDS::con_unbindall(void *result, void *user_data)
 {
-	binds_unbindall();
+	BINDS *binds = (BINDS *)user_data;
+	binds->unbindall();
 }
 
 
-static void con_dump_binds(void *result, void *user_data)
+void BINDS::con_dump_binds(void *result, void *user_data)
 {
+	BINDS *binds = (BINDS *)user_data;
 	for(int i = 0; i < KEY_LAST; i++)
 	{
-		if(keybindings[i][0] == 0)
+		if(binds->keybindings[i][0] == 0)
 			continue;
-		dbg_msg("binds", "%s (%d) = %s", inp_key_name(i), i, keybindings[i]);
+		dbg_msg("binds", "%s (%d) = %s", inp_key_name(i), i, binds->keybindings[i]);
+	}
+}
+
+int BINDS::get_key_id(const char *key_name)
+{
+	// check for numeric
+	if(key_name[0] == '#')
+	{
+		int i = atoi(key_name+1);
+		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;
 }
 
+/*
 void binds_save()
 {
 	char buffer[256];
diff --git a/src/game/client/components/binds.hpp b/src/game/client/components/binds.hpp
index e9232484..5b53b194 100644
--- a/src/game/client/components/binds.hpp
+++ b/src/game/client/components/binds.hpp
@@ -3,6 +3,14 @@
 class BINDS : public COMPONENT
 {
 	char keybindings[KEY_LAST][128];
+
+	int get_key_id(const char *key_name);
+
+	static void con_bind(void *result, void *user_data);
+	static void con_unbind(void *result, void *user_data);
+	static void con_unbindall(void *result, void *user_data);
+	static void con_dump_binds(void *result, void *user_data);
+	
 public:
 	BINDS();