diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs index c75252840b..267192fef6 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs @@ -219,7 +219,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic chatPanel = lobby.GetWidget("CHAT_DISPLAY"); chatTemplate = chatPanel.GetWidget("CHAT_TEMPLATE"); - + chatPanel.RemoveChildren(); + lobby.GetWidget("MUSIC_BUTTON").OnClick = () => { Widget.OpenWindow("MUSIC_PANEL", new WidgetArgs() @@ -241,32 +242,33 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic public void AddChatLine(Color c, string from, string text) { - var name = from+":"; - var font = Game.Renderer.Fonts["Regular"]; - var nameSize = font.Measure(from); - var template = chatTemplate.Clone() as ContainerWidget; - template.IsVisible = () => true; - + var nameLabel = template.GetWidget("NAME"); + var timeLabel = template.GetWidget("TIME"); + var textLabel = template.GetWidget("TEXT"); + + var name = from+":"; + var font = Game.Renderer.Fonts[nameLabel.Font]; + var nameSize = font.Measure(from); + var time = System.DateTime.Now; - template.GetWidget("TIME").GetText = () => "[{0:D2}:{1:D2}]".F(time.Hour, time.Minute); - - var p = template.GetWidget("NAME"); - p.GetColor = () => c; - p.GetText = () => name; - p.Bounds.Width = nameSize.X; - - var t = template.GetWidget("TEXT"); - t.Bounds.X += nameSize.X; - t.Bounds.Width -= nameSize.X; - + timeLabel.GetText = () => "{0:D2}:{1:D2}".F(time.Hour, time.Minute); + + nameLabel.GetColor = () => c; + nameLabel.GetText = () => name; + nameLabel.Bounds.Width = nameSize.X; + 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, t.Bounds.Width, font); - t.GetText = () => text; - var oldHeight = t.Bounds.Height; - t.Bounds.Height = font.Measure(text).Y; - template.Bounds.Height += (t.Bounds.Height - oldHeight); - + text = WidgetUtils.WrapText(text, textLabel.Bounds.Width, font); + textLabel.GetText = () => text; + var oldHeight = textLabel.Bounds.Height; + textLabel.Bounds.Height = font.Measure(text).Y; + var dh = textLabel.Bounds.Height - oldHeight; + if (dh > 0) + template.Bounds.Height += dh; + chatPanel.AddChild(template); chatPanel.ScrollToBottom(); } diff --git a/mods/cnc/chrome/lobby.yaml b/mods/cnc/chrome/lobby.yaml index 01b500c536..2802882a79 100644 --- a/mods/cnc/chrome/lobby.yaml +++ b/mods/cnc/chrome/lobby.yaml @@ -397,32 +397,34 @@ Container@SERVER_LOBBY: Y:285 Width:PARENT_RIGHT - 30 Height:PARENT_BOTTOM - 324 - ItemSpacing:2 + ItemSpacing:1 Children: Container@CHAT_TEMPLATE: Id:CHAT_TEMPLATE Width:PARENT_RIGHT-27 - Height:14 + Height:16 X:2 Y:0 - Visible:false Children: Label@TIME: Id:TIME - X:5 + X:3 Width:50 - Height:14 + Height:15 + VAlign:Top Label@NAME: Id:NAME - X:55 + X:45 Width:50 - Height:14 + Height:15 + VAlign:Top Label@TEXT: Id:TEXT - X:65 - Height:14 - Width:PARENT_RIGHT - 100 - 10 + X:55 + Width:PARENT_RIGHT - 60 + Height:15 WordWrap:true + VAlign:Top TextField@CHAT_TEXTFIELD: Id:CHAT_TEXTFIELD X:15