From 4e84545b5540b2023f0b5a724b495f88a1d4129f Mon Sep 17 00:00:00 2001 From: teinarss Date: Mon, 27 May 2019 20:42:21 +0200 Subject: [PATCH] Updated ChatDisplayWidget to use the new vertical alignment --- .../Widgets/ChatDisplayWidget.cs | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/ChatDisplayWidget.cs b/OpenRA.Mods.Common/Widgets/ChatDisplayWidget.cs index 5354f68b10..4309fb9ea3 100644 --- a/OpenRA.Mods.Common/Widgets/ChatDisplayWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ChatDisplayWidget.cs @@ -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("TextContrastColorDark"); public readonly Color BackgroundColorLight = ChromeMetrics.Get("TextContrastColorLight"); public string Notification = ""; + public readonly int TextLineBoxHeight = 16; + public readonly int Space = 4; const int LogLength = 9; List recentLines = new List(); @@ -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();