From 8f23204eef956177855ee8fb9c1cc21cd08560f4 Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Wed, 27 Aug 2008 19:41:02 +0000 Subject: [PATCH] fixed the chat --- src/game/client/components/chat.cpp | 51 ++++++++++++++++++++--------- src/game/client/components/chat.hpp | 8 ++++- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index ecd29ab8f..2e4812151 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -1,3 +1,9 @@ +#include // strcmp + +extern "C" { + #include +} + #include #include #include @@ -17,6 +23,35 @@ void CHAT::on_reset() } + +void CHAT::con_say(void *result, void *user_data) +{ + ((CHAT*)user_data)->say(0, console_arg_string(result, 0)); +} + +void CHAT::con_sayteam(void *result, void *user_data) +{ + ((CHAT*)user_data)->say(1, console_arg_string(result, 0)); +} + +void CHAT::con_chat(void *result, void *user_data) +{ + const char *mode = console_arg_string(result, 0); + if(strcmp(mode, "all") == 0) + ((CHAT*)user_data)->enable_mode(0); + else if(strcmp(mode, "team") == 0) + ((CHAT*)user_data)->enable_mode(1); + else + dbg_msg("console", "expected all or team as mode"); +} + +void CHAT::on_init() +{ + MACRO_REGISTER_COMMAND("say", "r", con_say, this); + MACRO_REGISTER_COMMAND("say_team", "r", con_sayteam, this); + MACRO_REGISTER_COMMAND("chat", "s", con_chat, this); +} + bool CHAT::on_input(INPUT_EVENT e) { if(mode == MODE_NONE) @@ -63,8 +98,6 @@ void CHAT::on_message(int msgtype, void *rawmsg) } } - - void CHAT::add_line(int client_id, int team, const char *line) { current_line = (current_line+1)%MAX_LINES; @@ -176,20 +209,6 @@ void CHAT::on_render() gfx_text_color(1,1,1,1); } -void con_chat(void *result, void *user_data) -{ - /* - const char *mode = console_arg_string(result, 0); - if(strcmp(mode, "all") == 0) - chat_enable_mode(0); - else if(strcmp(mode, "team") == 0) - chat_enable_mode(1); - else - dbg_msg("console", "expected all or team as mode"); - */ -} - - void CHAT::say(int team, const char *line) { // send chat message diff --git a/src/game/client/components/chat.hpp b/src/game/client/components/chat.hpp index caec18b2e..fc21ce1f5 100644 --- a/src/game/client/components/chat.hpp +++ b/src/game/client/components/chat.hpp @@ -3,7 +3,6 @@ class CHAT : public COMPONENT { -public: LINEINPUT input; enum @@ -34,6 +33,12 @@ public: int mode; + static void con_say(void *result, void *user_data); + static void con_sayteam(void *result, void *user_data); + static void con_chat(void *result, void *user_data); + +public: + void add_line(int client_id, int team, const char *line); //void chat_reset(); //bool chat_input_handle(INPUT_EVENT e, void *user_data); @@ -42,6 +47,7 @@ public: void say(int team, const char *line); + virtual void on_init(); virtual void on_reset(); virtual void on_render(); virtual void on_message(int msgtype, void *rawmsg);