Split chat lines into pools
- Add a common class for passing around chat lines - Add wrapper methods for adding chat lines - Combine repeated chat lines in the display widget
This commit is contained in:
committed by
Paul Chote
parent
0a02bd524a
commit
6af354ff99
@@ -121,7 +121,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
services = modData.Manifest.Get<WebServices>();
|
||||
|
||||
orderManager.AddChatLine += AddChatLine;
|
||||
orderManager.AddTextNotification += AddChatLine;
|
||||
Game.LobbyInfoChanged += UpdateCurrentMap;
|
||||
Game.LobbyInfoChanged += UpdatePlayerList;
|
||||
Game.LobbyInfoChanged += UpdateDiscordStatus;
|
||||
@@ -466,7 +466,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (disposing && !disposed)
|
||||
{
|
||||
disposed = true;
|
||||
orderManager.AddChatLine -= AddChatLine;
|
||||
orderManager.AddTextNotification -= AddChatLine;
|
||||
Game.LobbyInfoChanged -= UpdateCurrentMap;
|
||||
Game.LobbyInfoChanged -= UpdatePlayerList;
|
||||
Game.LobbyInfoChanged -= UpdateDiscordStatus;
|
||||
@@ -489,10 +489,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
panel = PanelType.Players;
|
||||
}
|
||||
|
||||
void AddChatLine(string name, Color nameColor, string text, Color textColor)
|
||||
void AddChatLine(TextNotification chatLine)
|
||||
{
|
||||
var template = (ContainerWidget)chatTemplate.Clone();
|
||||
LobbyUtils.SetupChatLine(template, DateTime.Now, name, nameColor, text, textColor);
|
||||
LobbyUtils.SetupChatLine(template, DateTime.Now, chatLine);
|
||||
|
||||
var scrolledToBottom = lobbyChatPanel.ScrolledToBottom;
|
||||
lobbyChatPanel.AddChild(template);
|
||||
|
||||
@@ -651,28 +651,28 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
HideChildWidget(parent, "STATUS_IMAGE");
|
||||
}
|
||||
|
||||
public static void SetupChatLine(ContainerWidget template, DateTime time, string name, Color nameColor, string text, Color textColor)
|
||||
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 = name + ":";
|
||||
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 = () => nameColor;
|
||||
nameLabel.GetColor = () => chatLine.PrefixColor;
|
||||
nameLabel.GetText = () => nameText;
|
||||
nameLabel.Bounds.Width = nameSize.X;
|
||||
|
||||
textLabel.GetColor = () => textColor;
|
||||
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
|
||||
text = WidgetUtils.WrapText(text, textLabel.Bounds.Width, font);
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user