hacky chat line wrapping
This commit is contained in:
@@ -22,6 +22,7 @@ using System.Collections.Generic;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
@@ -69,12 +70,34 @@ namespace OpenRA
|
|||||||
|
|
||||||
public void AddLine(Color c, string from, string text)
|
public void AddLine(Color c, string from, string 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 });
|
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>();
|
var eva = Rules.Info["world"].Traits.Get<EvaAlertsInfo>();
|
||||||
Sound.Play(eva.ChatBeep);
|
Sound.Play(eva.ChatBeep);
|
||||||
while (recentLines.Count > logLength) recentLines.RemoveAt(0);
|
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; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
class Chrome : IHandleInput
|
class Chrome : IHandleInput
|
||||||
{
|
{
|
||||||
|
//todo: remove when have a real chat widget
|
||||||
|
public static int ChatWidth = 760;
|
||||||
|
|
||||||
public readonly Renderer renderer;
|
public readonly Renderer renderer;
|
||||||
public readonly LineRenderer lineRenderer;
|
public readonly LineRenderer lineRenderer;
|
||||||
|
|
||||||
@@ -187,7 +190,9 @@ namespace OpenRA
|
|||||||
|
|
||||||
void DrawChat(Rectangle typingArea, Rectangle chatLogArea)
|
void DrawChat(Rectangle typingArea, Rectangle chatLogArea)
|
||||||
{
|
{
|
||||||
|
|
||||||
var chatpos = new int2(chatLogArea.X + 10, chatLogArea.Bottom - 6);
|
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);
|
renderer.Device.EnableScissor(typingArea.Left, typingArea.Top, typingArea.Width, typingArea.Height);
|
||||||
if (Game.chat.isChatting)
|
if (Game.chat.isChatting)
|
||||||
|
|||||||
Reference in New Issue
Block a user