Rework chat line templates and logic

- Extract chat line templates and logic so they can be reused across widgets
- Make text notification styling entirely template driven (by removing chat color configuration and making color optional for `TextNotification`)
- Add a new TextNotificationsDisplay widget (based on and replacing ChatDisplayWidget)
- Add timestamp support to text notifications
This commit is contained in:
Ivaylo Draganov
2021-06-15 17:32:21 +03:00
committed by Matthias Mailänder
parent 8416dc3f2d
commit 9e92340ea7
20 changed files with 330 additions and 363 deletions

View File

@@ -648,37 +648,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
HideChildWidget(parent, "STATUS_IMAGE");
}
public static void SetupChatLine(ContainerWidget template, DateTime time, TextNotification chatLine)
{
var nameLabel = template.Get<LabelWidget>("NAME");
var timeLabel = template.Get<LabelWidget>("TIME");
var textLabel = template.Get<LabelWidget>("TEXT");
var nameText = chatLine.Prefix + ":";
var font = Game.Renderer.Fonts[nameLabel.Font];
var nameSize = font.Measure(nameText);
timeLabel.GetText = () => $"{time.Hour:D2}:{time.Minute:D2}";
nameLabel.GetColor = () => chatLine.PrefixColor;
nameLabel.GetText = () => nameText;
nameLabel.Bounds.Width = nameSize.X;
textLabel.GetColor = () => chatLine.TextColor;
textLabel.Bounds.X += nameSize.X;
textLabel.Bounds.Width -= nameSize.X;
// Hack around our hacky wordwrap behavior: need to resize the widget to fit the text
var text = WidgetUtils.WrapText(chatLine.Text, textLabel.Bounds.Width, font);
textLabel.GetText = () => text;
var dh = font.Measure(text).Y - textLabel.Bounds.Height;
if (dh > 0)
{
textLabel.Bounds.Height += dh;
template.Bounds.Height += dh;
}
}
static void HideChildWidget(Widget parent, string widgetId)
{
var widget = parent.GetOrNull(widgetId);