about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/engine/client/gfx.c18
-rw-r--r--src/engine/interface.h2
-rw-r--r--src/game/client/game_client.cpp87
-rw-r--r--src/game/game_variables.h4
-rw-r--r--src/game/server/game_server.cpp33
5 files changed, 113 insertions, 31 deletions
diff --git a/src/engine/client/gfx.c b/src/engine/client/gfx.c
index e2aa1c81..05ebcb1c 100644
--- a/src/engine/client/gfx.c
+++ b/src/engine/client/gfx.c
@@ -807,12 +807,28 @@ static int word_length(const char *text)
 	}
 }
 
+
+
+static float pretty_r=1;
+static float pretty_g=1;
+static float pretty_b=1;
+static float pretty_a=1;
+
+void gfx_pretty_text_color(float r, float g, float b, float a)
+{
+	pretty_r = r;
+	pretty_g = g;
+	pretty_b = b;
+	pretty_a = a;
+}
+
 float gfx_pretty_text_raw(float x, float y, float size, const char *text_, int length)
 {
 	const unsigned char *text = (unsigned char *)text_;
 	const float spacing = 0.05f;
 	gfx_texture_set(current_font->font_texture);
 	gfx_quads_begin();
+	gfx_setcolor(pretty_r, pretty_g, pretty_b, pretty_a);
 	
 	if(length < 0)
 		length = strlen(text_);
@@ -847,6 +863,8 @@ float gfx_pretty_text_raw(float x, float y, float size, const char *text_, int l
 	return x;
 }
 
+
+
 void gfx_pretty_text(float x, float y, float size, const char *text, int max_width)
 {
 	if(max_width == -1)
diff --git a/src/engine/interface.h b/src/engine/interface.h
index 8c272000..abe447c4 100644
--- a/src/engine/interface.h
+++ b/src/engine/interface.h
@@ -813,6 +813,8 @@ int client_serverbrowse_num_requests();
 void client_serverbrowse_update();
 
 /* undocumented graphics stuff */
+
+void gfx_pretty_text_color(float r, float g, float b, float a);
 void gfx_pretty_text(float x, float y, float size, const char *text, int max_width);
 float gfx_pretty_text_width(float size, const char *text, int length);
 
diff --git a/src/game/client/game_client.cpp b/src/game/client/game_client.cpp
index 2c9307eb..dfb8e698 100644
--- a/src/game/client/game_client.cpp
+++ b/src/game/client/game_client.cpp
@@ -25,7 +25,14 @@ static int skinseed = 0;
 static int music_menu = -1;
 static int music_menu_id = -1;
 
-static bool chat_active = false;
+enum
+{
+	CHATMODE_NONE=0,
+	CHATMODE_ALL,
+	CHATMODE_TEAM,
+};
+
+static int chat_mode = CHATMODE_NONE;
 static bool menu_active = false;
 static bool emoticon_selector_active = false;
 
@@ -370,6 +377,7 @@ struct chatline
 {
 	int tick;
 	int client_id;
+	int team;
 	char text[512+64];
 };
 
@@ -383,16 +391,19 @@ void chat_reset()
 	chat_current_line = 0;
 }
 
-void chat_add_line(int client_id, const char *line)
+void chat_add_line(int client_id, int team, const char *line)
 {
 	chat_current_line = (chat_current_line+1)%chat_max_lines;
 	chat_lines[chat_current_line].tick = client_tick();
 	chat_lines[chat_current_line].client_id = client_id;
+	chat_lines[chat_current_line].team = team;
 
 	if(client_id == -1) // server message
 		sprintf(chat_lines[chat_current_line].text, "*** %s", line);
 	else
-		sprintf(chat_lines[chat_current_line].text, "%s: %s", client_datas[client_id].name, line); // TODO: abit nasty
+	{
+		sprintf(chat_lines[chat_current_line].text, "%s: %s", client_datas[client_id].name, line);
+	}
 }
 
 struct killmsg
@@ -453,7 +464,7 @@ extern "C" void modc_init()
 	data = load_data_from_memory(internal_data);
 
 	// TODO: should be removed
-	music_menu = snd_load_wav("data/audio/music_menu.wav");
+	music_menu = snd_load_wv("data/audio/music_menu.wv");
 	snd_set_listener_pos(0.0f, 0.0f);
 
 	float total = data->num_sounds+data->num_images;
@@ -1666,17 +1677,17 @@ void render_game()
 
 	if (inp_key_down(KEY_ESC))
 	{
-		if (chat_active)
-			chat_active = false;
+		if (chat_mode)
+			chat_mode = CHATMODE_NONE;
 		else
 			menu_active = !menu_active;
 	}
 	
 	if (!menu_active)
 	{
-		if(inp_key_down(KEY_ENTER))
+		if(chat_mode != CHATMODE_NONE)
 		{
-			if(chat_active)
+			if(inp_key_down(KEY_ENTER))
 			{
 				// send message
 				if(chat_input_len)
@@ -1690,24 +1701,20 @@ void render_game()
 						else
 						{
 							msg_pack_start(MSG_SAY, MSGFLAG_VITAL);
-							msg_pack_int(-1);
+							if(chat_mode == CHATMODE_ALL)
+								msg_pack_int(0);
+							else
+								msg_pack_int(1);
 							msg_pack_string(chat_input, 512);
 							msg_pack_end();
 							client_send_msg();
 						}
 					}
 				}
+				
+				chat_mode = CHATMODE_NONE;
 			}
-			else
-			{
-				mem_zero(chat_input, sizeof(chat_input));
-				chat_input_len = 0;
-			}
-			chat_active = !chat_active;
-		}
-		
-		if(chat_active)
-		{
+			
 			int c = inp_last_char();
 			int k = inp_last_key();
 		
@@ -1731,6 +1738,23 @@ void render_game()
 			}
 			
 		}
+		else
+		{
+			if(chat_mode == CHATMODE_NONE)
+			{
+				if(inp_key_down(config.key_chat))
+					chat_mode = CHATMODE_ALL;
+
+				if(inp_key_down(config.key_teamchat))
+					chat_mode = CHATMODE_TEAM;
+				
+				if(chat_mode != CHATMODE_NONE)
+				{
+					mem_zero(chat_input, sizeof(chat_input));
+					chat_input_len = 0;
+				}
+			}
+		}
 	}
 	
 	if (!menu_active)
@@ -1758,7 +1782,7 @@ void render_game()
 		input.target_y = (int)mouse_pos.y;
 		input.activeweapon = -1;
 	
-		if(chat_active)
+		if(chat_mode != CHATMODE_NONE)
 			input.state = STATE_CHATTING;
 		else if(menu_active)
 			input.state = STATE_IN_MENU;
@@ -1841,7 +1865,7 @@ void render_game()
 	
 	if(config.debug)
 	{
-		if(!chat_active && inp_key_pressed(KEY_F8))
+		if(chat_mode != CHATMODE_NONE && inp_key_pressed(KEY_F8))
 			zoom = 1.0f;
 	}
 	
@@ -2071,11 +2095,16 @@ void render_game()
 		float x = 10.0f;
 		float y = 300.0f-50.0f;
 		float starty = -1;
-		if(chat_active)
+		if(chat_mode != CHATMODE_NONE)
 		{
 			// render chat input
 			char buf[sizeof(chat_input)+16];
-			sprintf(buf, "Chat: %s_", chat_input);
+			if(chat_mode == CHATMODE_ALL)
+				sprintf(buf, "All: %s_", chat_input);
+			else if(chat_mode == CHATMODE_TEAM)
+				sprintf(buf, "Team: %s_", chat_input);
+			else
+				sprintf(buf, "Chat: %s_", chat_input);
 			gfx_pretty_text(x, y, 10.0f, buf, 380);
 			starty = y;
 		}
@@ -2091,9 +2120,17 @@ void render_game()
 
 			int lines = int(gfx_pretty_text_width(10, chat_lines[r].text, -1)) / 380 + 1;
 			
+			gfx_pretty_text_color(1,1,1,1);
+			if(chat_lines[r].client_id == -1)
+				gfx_pretty_text_color(1,1,0.5f,1); // system
+			else if(chat_lines[r].team)
+				gfx_pretty_text_color(0.5f,1,0.5f,1); // team message
+			
 			gfx_pretty_text(x, y - 8 * (lines - 1), 10, chat_lines[r].text, 380);
 			y -= 8 * lines;
 		}
+		
+		gfx_pretty_text_color(1,1,1,1);
 	}
 	
 	// render goals
@@ -2251,8 +2288,8 @@ extern "C" void modc_message(int msg)
 		int cid = msg_unpack_int();
 		int team = msg_unpack_int();
 		const char *message = msg_unpack_string();
-		dbg_msg("message", "chat cid=%d msg='%s'", cid, message);
-		chat_add_line(cid, message);
+		dbg_msg("message", "chat cid=%d team=%d msg='%s'", cid, team, message);
+		chat_add_line(cid, team, message);
 
 		if(cid >= 0)
 			snd_play(0, data->sounds[SOUND_CHAT_CLIENT].sounds[0].id, SND_PLAY_ONCE, 0, 0);
diff --git a/src/game/game_variables.h b/src/game/game_variables.h
index 429c18aa..464f30a9 100644
--- a/src/game/game_variables.h
+++ b/src/game/game_variables.h
@@ -8,6 +8,10 @@ MACRO_CONFIG_INT(key_weapon2, '2', 32, 512)
 MACRO_CONFIG_INT(key_weapon3, '3', 32, 512)
 MACRO_CONFIG_INT(key_weapon4, '4', 32, 512)
 MACRO_CONFIG_INT(key_emoticon, 'E', 32, 512)
+
+MACRO_CONFIG_INT(key_chat, 'T', 32, 512)
+MACRO_CONFIG_INT(key_teamchat, 'Y', 32, 512)
+
 MACRO_CONFIG_INT(scroll_weapon, 1, 0, 1)
 
 MACRO_CONFIG_INT(scorelimit, 20, 0, 1000)
diff --git a/src/game/server/game_server.cpp b/src/game/server/game_server.cpp
index 78b95de3..cf4be747 100644
--- a/src/game/server/game_server.cpp
+++ b/src/game/server/game_server.cpp
@@ -1446,12 +1446,29 @@ void send_chat(int cid, int team, const char *msg)
 	else
 		dbg_msg("chat", "*** %s", msg);
 	
-	msg_pack_start(MSG_CHAT, MSGFLAG_VITAL);
-	msg_pack_int(cid);
-	msg_pack_int(team);
-	msg_pack_string(msg, 512);
-	msg_pack_end();
-	server_send_msg(-1);
+	if(team == -1)
+	{
+		msg_pack_start(MSG_CHAT, MSGFLAG_VITAL);
+		msg_pack_int(cid);
+		msg_pack_int(0);
+		msg_pack_string(msg, 512);
+		msg_pack_end();
+		server_send_msg(-1);
+	}
+	else
+	{
+		msg_pack_start(MSG_CHAT, MSGFLAG_VITAL);
+		msg_pack_int(cid);
+		msg_pack_int(1);
+		msg_pack_string(msg, 512);
+		msg_pack_end();
+				
+		for(int i = 0; i < MAX_CLIENTS; i++)
+		{
+			if(players[i].client_id != -1 && players[i].team == team)
+				server_send_msg(i);
+		}
+	}
 }
 
 void send_set_name(int cid, const char *old_name, const char *new_name)
@@ -1542,6 +1559,10 @@ void mods_message(int msg, int client_id)
 	{
 		int team = msg_unpack_int();
 		const char *text = msg_unpack_string();
+		if(team)
+			team = players[client_id].team;
+		else
+			team = -1;
 		send_chat(client_id, team, text);
 	}
 	else if (msg == MSG_SWITCHTEAM)