about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/engine/client/gfx.cpp8
-rw-r--r--src/engine/client/snd.cpp1
-rw-r--r--src/engine/client/ui.cpp1
-rw-r--r--src/engine/interface.h2
-rw-r--r--src/game/client/game_client.cpp79
5 files changed, 18 insertions, 73 deletions
diff --git a/src/engine/client/gfx.cpp b/src/engine/client/gfx.cpp
index 1c871e28..dafdfa06 100644
--- a/src/engine/client/gfx.cpp
+++ b/src/engine/client/gfx.cpp
@@ -790,7 +790,7 @@ double extra_kerning[256*256] = {0};
 
 pretty_font *current_font = &default_font;
 
-void gfx_pretty_text(float x, float y, float size, const char *text)
+void gfx_pretty_text(float x, float y, float size, const char *text, int max_width)
 {
 	const float spacing = 0.05f;
 	gfx_texture_set(current_font->font_texture);
@@ -826,6 +826,12 @@ void gfx_pretty_text(float x, float y, float size, const char *text)
 				x_nudge = extra_kerning[text[0] + text[1] * 256];
 
 			x += (width + current_font->m_CharStartTable[c] + spacing + x_nudge) * size;
+
+			if (max_width != -1 && x - startx > max_width)
+			{
+				x = startx;
+				y += size - 2;
+			}
 		}
 
 		text++;
diff --git a/src/engine/client/snd.cpp b/src/engine/client/snd.cpp
index 69cca0f5..c28efe05 100644
--- a/src/engine/client/snd.cpp
+++ b/src/engine/client/snd.cpp
@@ -269,7 +269,6 @@ int snd_load_wv(const char *filename)
 	{
 		int samples = WavpackGetNumSamples(context);
 		int bitspersample = WavpackGetBitsPerSample(context);
-		int bytespersample = WavpackGetBytesPerSample(context);
 		unsigned int samplerate = WavpackGetSampleRate(context);
 		int channels = WavpackGetNumChannels(context);
 
diff --git a/src/engine/client/ui.cpp b/src/engine/client/ui.cpp
index d7a0a4d8..7b309539 100644
--- a/src/engine/client/ui.cpp
+++ b/src/engine/client/ui.cpp
@@ -15,7 +15,6 @@ struct pretty_font
 };
 
 extern pretty_font *current_font;
-void gfx_pretty_text(float x, float y, float size, const char *text);
 
 static void *hot_item = 0;
 static void *active_item = 0;
diff --git a/src/engine/interface.h b/src/engine/interface.h
index 4d92e87f..f7a95c61 100644
--- a/src/engine/interface.h
+++ b/src/engine/interface.h
@@ -768,7 +768,7 @@ int client_tickspeed();
 int client_state();
 const char *client_error_string();
 
-void gfx_pretty_text(float x, float y, float size, const char *text);
+void gfx_pretty_text(float x, float y, float size, const char *text, int max_width = -1);
 float gfx_pretty_text_width(float size, const char *text, int length = -1);
 
 void gfx_getscreen(float *tl_x, float *tl_y, float *br_x, float *br_y);
diff --git a/src/game/client/game_client.cpp b/src/game/client/game_client.cpp
index 7b94261d..0fd1b1e2 100644
--- a/src/game/client/game_client.cpp
+++ b/src/game/client/game_client.cpp
@@ -413,75 +413,14 @@ void chat_reset()
 
 void chat_add_line(int client_id, 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;
+
 	if(client_id == -1) // server message
-	{
-		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;
 		sprintf(chat_lines[chat_current_line].text, "*** %s", line);
-	}
 	else
-	{
-		int len;
-		int loop_count = 0;
-		while ((len = strlen(line)) > 0)
-		{
-			const int max_line_len = 80;
-			const char *str;
-			int str_len;
-
-			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;
-			// check if we need to cut it
-			if (len > max_line_len)
-			{
-				int cutoff = max_line_len;
-
-				// find space
-				while (cutoff > 0)
-				{
-					if (line[cutoff] == ' ')
-						break;
-					else
-						cutoff--;
-				}
-
-				// if no space was found, force cut off
-				if (!cutoff)
-					cutoff = max_line_len;
-	
-				str = line;
-				str_len = cutoff;
-
-				line += cutoff;
-
-				// get rid of leading spaces
-				while (line[0] == ' ')
-					line++;
-			}
-			else
-			{
-				str = line;
-				str_len = len;
-
-				line += len;
-			}
-
-			if (loop_count == 0)
-			{
-				sprintf(chat_lines[chat_current_line].text, "%s: %s", client_datas[client_id].name, str); // TODO: abit nasty
-				chat_lines[chat_current_line].text[strlen(client_datas[client_id].name) + 2 + str_len] = '\0';
-			}
-			else
-			{
-				memcpy(chat_lines[chat_current_line].text, str, str_len);
-				chat_lines[chat_current_line].text[str_len] = '\0';
-			}
-
-			loop_count++;
-		}
-	}
+		sprintf(chat_lines[chat_current_line].text, "%s: %s", client_datas[client_id].name, line); // TODO: abit nasty
 }
 
 struct killmsg
@@ -1679,7 +1618,7 @@ void render_game()
 			// render chat input
 			char buf[sizeof(chat_input)+16];
 			sprintf(buf, "Chat: %s_", chat_input);
-			gfx_pretty_text(x, y, 10, buf);
+			gfx_pretty_text(x, y, 10, buf, 380);
 			starty = y;
 		}
 		
@@ -1691,9 +1630,11 @@ void render_game()
 			int r = ((chat_current_line-i)+chat_max_lines)%chat_max_lines;
 			if(client_tick() > chat_lines[r].tick+50*15)
 				break;
+
+			int lines = int(gfx_pretty_text_width(10, chat_lines[r].text)) / 380 + 1;
 			
-			gfx_pretty_text(x, y, 10, chat_lines[r].text);
-			y -= 8;
+			gfx_pretty_text(x, y - 8 * (lines - 1), 10, chat_lines[r].text, 380);
+			y -= 8 * lines;
 		}
 	}