about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game/client/components/menus.cpp19
-rw-r--r--src/game/client/components/menus.hpp14
-rw-r--r--src/game/client/components/menus_settings.cpp24
-rw-r--r--src/game/client/gameclient.cpp1
4 files changed, 48 insertions, 10 deletions
diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp
index 86b794ef..a3ee6762 100644
--- a/src/game/client/components/menus.cpp
+++ b/src/game/client/components/menus.cpp
@@ -444,23 +444,22 @@ int MENUS::ui_do_key_reader(void *id, const RECT *rect, int key)
 
 	if(ui_active_item() == id)
 	{
-		for(int i = 0; i < num_inputevents; i++)
+		if(binder.got_key)
 		{
-			INPUT_EVENT e = inputevents[i];
-			if(e.flags&INPFLAG_PRESS && e.key && e.key != KEY_ESC)
-			{
-				new_key = e.key;
-				ui_set_active_item(0);
-				mouse_released = false;
-				num_inputevents = 0;
-				break;
-			}
+			new_key = binder.key.key;
+			binder.got_key = false;
+			ui_set_active_item(0);
+			mouse_released = false;
 		}
 	}
 	else if(ui_hot_item() == id)
 	{
 		if(ui_mouse_button(0) && mouse_released)
+		{
+			binder.take_key = true;
+			binder.got_key = false;
 			ui_set_active_item(id);
+		}
 	}
 	
 	if(inside)
diff --git a/src/game/client/components/menus.hpp b/src/game/client/components/menus.hpp
index 6332698f..bc733fb6 100644
--- a/src/game/client/components/menus.hpp
+++ b/src/game/client/components/menus.hpp
@@ -3,6 +3,18 @@
 #include <game/client/component.hpp>
 #include <game/client/ui.hpp>
 
+
+// compnent to fetch keypresses, override all other input
+class MENUS_KEYBINDER : public COMPONENT
+{
+public:
+	bool take_key;
+	bool got_key;
+	INPUT_EVENT key;
+	MENUS_KEYBINDER();
+	virtual bool on_input(INPUT_EVENT e);
+};
+
 class MENUS : public COMPONENT
 {	
 	static vec4 gui_color;
@@ -150,6 +162,8 @@ class MENUS : public COMPONENT
 	void render_settings(RECT main_view);
 	
 public:
+	static MENUS_KEYBINDER binder;
+	
 	MENUS();
 
 	void render_loading(float percent);
diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp
index 3db02aa4..2e7a6912 100644
--- a/src/game/client/components/menus_settings.cpp
+++ b/src/game/client/components/menus_settings.cpp
@@ -18,6 +18,30 @@
 #include "menus.hpp"
 #include "skins.hpp"
 
+MENUS_KEYBINDER MENUS::binder;
+
+MENUS_KEYBINDER::MENUS_KEYBINDER()
+{
+	take_key = false;
+	got_key = false;
+}
+
+bool MENUS_KEYBINDER::on_input(INPUT_EVENT e)
+{
+	if(take_key)
+	{
+		if(e.flags&INPFLAG_PRESS && e.key != KEY_ESC)
+		{
+			key = e;
+			got_key = true;
+			take_key = false;
+		}
+		return true;
+	}
+	
+	return false;
+}
+
 void MENUS::render_settings_player(RECT main_view)
 {
 	RECT button;
diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp
index 45e4aecd..1b50a081 100644
--- a/src/game/client/gameclient.cpp
+++ b/src/game/client/gameclient.cpp
@@ -146,6 +146,7 @@ void GAMECLIENT::on_console_init()
 	all.add(console);
 	
 	// build the input stack
+	input.add(&menus->binder); // this will take over all input when we want to bind a key
 	input.add(&binds->special_binds);
 	input.add(console);
 	input.add(chat); // chat has higher prio due to tha you can quit it by pressing esc