Updated ChatDisplayWidget to use the new vertical alignment
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Primitives;
|
||||
@@ -25,6 +24,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
public readonly Color BackgroundColorDark = ChromeMetrics.Get<Color>("TextContrastColorDark");
|
||||
public readonly Color BackgroundColorLight = ChromeMetrics.Get<Color>("TextContrastColorLight");
|
||||
public string Notification = "";
|
||||
public readonly int TextLineBoxHeight = 16;
|
||||
public readonly int Space = 4;
|
||||
|
||||
const int LogLength = 9;
|
||||
List<ChatLine> recentLines = new List<ChatLine>();
|
||||
@@ -35,13 +36,14 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
var pos = RenderOrigin;
|
||||
var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
||||
var chatpos = new int2(chatLogArea.X + 5, chatLogArea.Bottom - 5);
|
||||
var chatPos = new int2(chatLogArea.X + 5, chatLogArea.Bottom - 8);
|
||||
|
||||
var font = Game.Renderer.Fonts["Regular"];
|
||||
Game.Renderer.EnableScissor(chatLogArea);
|
||||
|
||||
foreach (var line in recentLines.AsEnumerable().Reverse())
|
||||
{
|
||||
var lineHeight = TextLineBoxHeight;
|
||||
var inset = 0;
|
||||
string name = null;
|
||||
|
||||
@@ -52,31 +54,46 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
}
|
||||
|
||||
var text = WidgetUtils.WrapText(line.Text, chatLogArea.Width - inset - 6, font);
|
||||
chatpos = chatpos.WithY(chatpos.Y - (Math.Max(15, font.Measure(text).Y) + 5));
|
||||
var textSize = font.Measure(text).Y;
|
||||
var offset = font.TopOffset;
|
||||
|
||||
if (chatpos.Y < pos.Y)
|
||||
if (chatPos.Y < pos.Y)
|
||||
break;
|
||||
|
||||
var textLineHeight = lineHeight;
|
||||
|
||||
var dh = textSize - textLineHeight;
|
||||
if (dh > 0)
|
||||
textLineHeight += dh;
|
||||
|
||||
var textOffset = textLineHeight - (textLineHeight - textSize - offset) / 2;
|
||||
var textPos = new int2(chatPos.X + inset, chatPos.Y - textOffset);
|
||||
|
||||
if (name != null)
|
||||
{
|
||||
var nameSize = font.Measure(name).Y;
|
||||
var namePos = chatPos.WithY(chatPos.Y - (textLineHeight - (lineHeight - nameSize - offset) / 2));
|
||||
|
||||
if (UseContrast)
|
||||
font.DrawTextWithContrast(name, chatpos,
|
||||
font.DrawTextWithContrast(name, namePos,
|
||||
line.NameColor, BackgroundColorDark, BackgroundColorLight, 1);
|
||||
else if (UseShadow)
|
||||
font.DrawTextWithShadow(name, chatpos,
|
||||
font.DrawTextWithShadow(name, namePos,
|
||||
line.NameColor, BackgroundColorDark, BackgroundColorLight, 1);
|
||||
else
|
||||
font.DrawText(name, chatpos, line.NameColor);
|
||||
font.DrawText(name, namePos, line.NameColor);
|
||||
}
|
||||
|
||||
if (UseContrast)
|
||||
font.DrawTextWithContrast(text, chatpos + new int2(inset, 0),
|
||||
font.DrawTextWithContrast(text, textPos,
|
||||
line.TextColor, Color.Black, 1);
|
||||
else if (UseShadow)
|
||||
font.DrawTextWithShadow(text, chatpos + new int2(inset, 0),
|
||||
font.DrawTextWithShadow(text, textPos,
|
||||
line.TextColor, Color.Black, 1);
|
||||
else
|
||||
font.DrawText(text, chatpos + new int2(inset, 0), Color.White);
|
||||
font.DrawText(text, textPos, Color.White);
|
||||
|
||||
chatPos = chatPos.WithY(chatPos.Y - Space - textLineHeight);
|
||||
}
|
||||
|
||||
Game.Renderer.DisableScissor();
|
||||
|
||||
Reference in New Issue
Block a user