diff options
| -rw-r--r-- | src/game/client/components/binds.cpp | 16 | ||||
| -rw-r--r-- | src/game/client/components/binds.hpp | 12 | ||||
| -rw-r--r-- | src/game/client/gameclient.cpp | 1 |
3 files changed, 26 insertions, 3 deletions
diff --git a/src/game/client/components/binds.cpp b/src/game/client/components/binds.cpp index 05165e5e..18b0ae1e 100644 --- a/src/game/client/components/binds.cpp +++ b/src/game/client/components/binds.cpp @@ -1,9 +1,25 @@ #include <engine/e_client_interface.h> #include "binds.hpp" +bool BINDS::BINDS_SPECIAL::on_input(INPUT_EVENT e) +{ + // don't handle invalid events and keys that arn't set to anything + if(e.key >= KEY_F1 && e.key <= KEY_F25 && binds->keybindings[e.key][0] != 0) + { + int stroke = 0; + if(e.flags&INPFLAG_PRESS) + stroke = 1; + console_execute_line_stroked(stroke, binds->keybindings[e.key]); + return true; + } + + return false; +} + BINDS::BINDS() { mem_zero(keybindings, sizeof(keybindings)); + special_binds.binds = this; } void BINDS::bind(int keyid, const char *str) diff --git a/src/game/client/components/binds.hpp b/src/game/client/components/binds.hpp index 304b4a8d..e9232484 100644 --- a/src/game/client/components/binds.hpp +++ b/src/game/client/components/binds.hpp @@ -6,14 +6,20 @@ class BINDS : public COMPONENT public: BINDS(); + class BINDS_SPECIAL : public COMPONENT + { + public: + BINDS *binds; + virtual bool on_input(INPUT_EVENT e); + }; + + BINDS_SPECIAL special_binds; + void bind(int keyid, const char *str); void set_defaults(); void unbindall(); const char *get(int keyid); - /*virtual void on_reset(); - virtual void on_render(); - virtual void on_message(int msgtype, void *rawmsg);*/ virtual void on_init(); virtual bool on_input(INPUT_EVENT e); }; diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index a88e7d3c..a6c531dd 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -101,6 +101,7 @@ void GAMECLIENT::on_init() all.add(console); // build the input stack + 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 input.add(motd); // for pressing esc to remove it |