diff --git a/OpenRA.Game/Chat.cs b/OpenRA.Game/Chat.cs index 9867004bdb..5e6b700a84 100644 --- a/OpenRA.Game/Chat.cs +++ b/OpenRA.Game/Chat.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.Drawing; using OpenRA.FileFormats; using OpenRA.Traits; +using System.Text; namespace OpenRA { @@ -69,12 +70,34 @@ namespace OpenRA public void AddLine(Color c, string from, string text) { - recentLines.Add(new ChatLine { Color = c, Owner = from, Text = text }); + var sizeOwner = Game.chrome.renderer.RegularFont.Measure(from); + var sizeText = Game.chrome.renderer.RegularFont.Measure(text); + + if (sizeOwner.X + sizeText.X + 10 <= Chrome.ChatWidth) + recentLines.Add(new ChatLine { Color = c, Owner = from, Text = text }); + else + { + StringBuilder sb = new StringBuilder(); + foreach (var w in text.Split(' ')) + { + if ( Game.chrome.renderer.RegularFont.Measure(sb.ToString() + ' ' + w).X > Chrome.ChatWidth ) + { + recentLines.Add(new ChatLine { Color = c, Owner = from, Text = sb.ToString() } ); + sb = new StringBuilder(); + sb.Append(w); + } + else + sb.Append( ' ' + w); + } + if (sb.Length != 0) + recentLines.Add(new ChatLine { Color = c, Owner = from, Text = sb.ToString() } ); + } + var eva = Rules.Info["world"].Traits.Get(); Sound.Play(eva.ChatBeep); while (recentLines.Count > logLength) recentLines.RemoveAt(0); } } - class ChatLine { public Color Color = Color.White; public string Owner, Text; } + class ChatLine { public Color Color = Color.White; public string Owner, Text; public bool wrapped = false; } } diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index 6ebdc111fd..c85b4c0949 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -31,6 +31,9 @@ namespace OpenRA { class Chrome : IHandleInput { + //todo: remove when have a real chat widget + public static int ChatWidth = 760; + public readonly Renderer renderer; public readonly LineRenderer lineRenderer; @@ -187,8 +190,10 @@ namespace OpenRA void DrawChat(Rectangle typingArea, Rectangle chatLogArea) { + var chatpos = new int2(chatLogArea.X + 10, chatLogArea.Bottom - 6); - + ChatWidth = chatLogArea.Width - 10; + renderer.Device.EnableScissor(typingArea.Left, typingArea.Top, typingArea.Width, typingArea.Height); if (Game.chat.isChatting) RenderChatLine(new ChatLine { Owner = Game.chat.isTeamChat ? "TeamChat:" : "Chat:", Text = Game.chat.typing },