hacky chat line wrapping

This commit is contained in:
alzeih
2010-06-26 12:56:30 +12:00
committed by Chris Forbes
parent 7070b04cc9
commit aa64803f84
2 changed files with 31 additions and 3 deletions

View File

@@ -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<EvaAlertsInfo>();
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; }
}

View File

@@ -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 },