diff --git a/OpenRA.Mods.Common/Widgets/Logic/GlobalChatLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/GlobalChatLogic.cs index cd5eb1aae5..9bb59da8a6 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/GlobalChatLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/GlobalChatLogic.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic class GlobalChatLogic : ChromeLogic { readonly ScrollPanelWidget historyPanel; - readonly LabelWidget historyTemplate; + readonly ContainerWidget chatTemplate; readonly ScrollPanelWidget nicknamePanel; readonly Widget nicknameTemplate; readonly TextFieldWidget inputBox; @@ -27,10 +27,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic public GlobalChatLogic(Widget widget) { historyPanel = widget.Get("HISTORY_PANEL"); - historyTemplate = historyPanel.Get("HISTORY_TEMPLATE"); + chatTemplate = historyPanel.Get("CHAT_TEMPLATE"); nicknamePanel = widget.Get("NICKNAME_PANEL"); nicknameTemplate = nicknamePanel.Get("NICKNAME_TEMPLATE"); + var textColor = ChromeMetrics.Get("GlobalChatTextColor"); + var textLabel = chatTemplate.Get("TEXT"); + textLabel.GetColor = () => textColor; + historyPanel.Bind(Game.GlobalChat.History, MakeHistoryWidget, HistoryWidgetEquals, true); nicknamePanel.Bind(Game.GlobalChat.Users, MakeUserWidget, UserWidgetEquals, false); @@ -80,19 +84,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic Widget MakeHistoryWidget(object o) { var message = (ChatMessage)o; - var widget = (LabelWidget)historyTemplate.Clone(); - var font = Game.Renderer.Fonts[widget.Font]; + var from = message.Type == ChatMessageType.Notification ? "Battlefield Control" : message.Nick; + var color = message.Type == ChatMessageType.Notification ? ChromeMetrics.Get("GlobalChatNotificationColor") + : ChromeMetrics.Get("GlobalChatPlayerNameColor"); + var template = (ContainerWidget)chatTemplate.Clone(); + LobbyUtils.SetupChatLine(template, color, from, message.Message); - var color = message.Type == ChatMessageType.Notification ? - ChromeMetrics.Get("GlobalChatNotificationColor") : - ChromeMetrics.Get("GlobalChatTextColor"); - - var display = WidgetUtils.WrapText(message.ToString(), widget.Bounds.Width, font); - widget.Bounds.Height = font.Measure(display).Y; - widget.GetText = () => display; - widget.GetColor = () => color; - widget.Id = message.UID; - return widget; + template.Id = message.UID; + return template; } bool HistoryWidgetEquals(Widget widget, object o) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index 30c70e0c58..4f08c69905 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -565,33 +565,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic { lobbyChatUnreadMessages += 1; - var template = chatTemplate.Clone(); - var nameLabel = template.Get("NAME"); - var timeLabel = template.Get("TIME"); - var textLabel = template.Get("TEXT"); - - var name = from + ":"; - var font = Game.Renderer.Fonts[nameLabel.Font]; - var nameSize = font.Measure(from); - - var time = DateTime.Now; - 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, 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; - } + var template = (ContainerWidget)chatTemplate.Clone(); + LobbyUtils.SetupChatLine(template, c, from, text); var scrolledToBottom = lobbyChatPanel.ScrolledToBottom; lobbyChatPanel.AddChild(template); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index d9c664c3e2..755dd2d15f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -517,5 +517,35 @@ namespace OpenRA.Mods.Common.Widgets.Logic return address; } + + public static void SetupChatLine(ContainerWidget template, Color c, string from, string text) + { + var nameLabel = template.Get("NAME"); + var timeLabel = template.Get("TIME"); + var textLabel = template.Get("TEXT"); + + var name = from + ":"; + var font = Game.Renderer.Fonts[nameLabel.Font]; + var nameSize = font.Measure(from); + + var time = DateTime.Now; + 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, 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; + } + } } } diff --git a/mods/cnc/chrome/lobby-globalchat.yaml b/mods/cnc/chrome/lobby-globalchat.yaml index bf5e065708..abc1e086d0 100644 --- a/mods/cnc/chrome/lobby-globalchat.yaml +++ b/mods/cnc/chrome/lobby-globalchat.yaml @@ -26,10 +26,30 @@ Container@LOBBY_GLOBALCHAT_PANEL: TopBottomSpacing: 4 ItemSpacing: 4 Children: - Label@HISTORY_TEMPLATE: - X: 5 - Width: 530 - WordWrap: True + Container@CHAT_TEMPLATE: + X: 2 + Width: PARENT_RIGHT-27 + Height: 16 + Children: + Label@TIME: + X: 3 + Width: 50 + Height: 15 + VAlign: Top + Shadow: True + Label@NAME: + X: 45 + Width: 50 + Height: 15 + VAlign: Top + Shadow: True + Label@TEXT: + X: 55 + Width: PARENT_RIGHT - 60 + Height: 15 + WordWrap: true + VAlign: Top + Shadow: True TextField@CHAT_TEXTFIELD: X: 200 Y: PARENT_BOTTOM + 5 diff --git a/mods/cnc/chrome/multiplayer-globalchat.yaml b/mods/cnc/chrome/multiplayer-globalchat.yaml index 950914aa79..c6350d2f01 100644 --- a/mods/cnc/chrome/multiplayer-globalchat.yaml +++ b/mods/cnc/chrome/multiplayer-globalchat.yaml @@ -26,10 +26,30 @@ Container@GLOBALCHAT_PANEL: TopBottomSpacing: 4 ItemSpacing: 4 Children: - Label@HISTORY_TEMPLATE: - X: 5 - Width: 530 - WordWrap: True + Container@CHAT_TEMPLATE: + X: 2 + Width: PARENT_RIGHT-27 + Height: 16 + Children: + Label@TIME: + X: 3 + Width: 50 + Height: 15 + VAlign: Top + Shadow: True + Label@NAME: + X: 45 + Width: 50 + Height: 15 + VAlign: Top + Shadow: True + Label@TEXT: + X: 55 + Width: PARENT_RIGHT - 60 + Height: 15 + WordWrap: true + VAlign: Top + Shadow: True TextField@CHAT_TEXTFIELD: Y: PARENT_BOTTOM - 25 Width: 582 diff --git a/mods/common/chrome/lobby-globalchat.yaml b/mods/common/chrome/lobby-globalchat.yaml index 98349effae..fabffc1fe6 100644 --- a/mods/common/chrome/lobby-globalchat.yaml +++ b/mods/common/chrome/lobby-globalchat.yaml @@ -26,10 +26,30 @@ Container@LOBBY_GLOBALCHAT_PANEL: TopBottomSpacing: 4 ItemSpacing: 4 Children: - Label@HISTORY_TEMPLATE: - X: 5 - Width: 530 - WordWrap: True + Container@CHAT_TEMPLATE: + X: 2 + Width: PARENT_RIGHT-27 + Height: 16 + Children: + Label@TIME: + X: 3 + Width: 50 + Height: 15 + VAlign: Top + Shadow: True + Label@NAME: + X: 45 + Width: 50 + Height: 15 + VAlign: Top + Shadow: True + Label@TEXT: + X: 55 + Width: PARENT_RIGHT - 60 + Height: 15 + WordWrap: true + VAlign: Top + Shadow: True TextField@CHAT_TEXTFIELD: X: 205 Y: PARENT_BOTTOM - 25 diff --git a/mods/common/chrome/multiplayer-globalchat.yaml b/mods/common/chrome/multiplayer-globalchat.yaml index 2c6aa3df45..4cb404482c 100644 --- a/mods/common/chrome/multiplayer-globalchat.yaml +++ b/mods/common/chrome/multiplayer-globalchat.yaml @@ -26,10 +26,30 @@ Container@GLOBALCHAT_PANEL: TopBottomSpacing: 4 ItemSpacing: 4 Children: - Label@HISTORY_TEMPLATE: - X: 5 - Width: 530 - WordWrap: True + Container@CHAT_TEMPLATE: + X: 2 + Width: PARENT_RIGHT-27 + Height: 16 + Children: + Label@TIME: + X: 3 + Width: 50 + Height: 15 + VAlign: Top + Shadow: True + Label@NAME: + X: 45 + Width: 50 + Height: 15 + VAlign: Top + Shadow: True + Label@TEXT: + X: 55 + Width: PARENT_RIGHT - 60 + Height: 15 + WordWrap: true + VAlign: Top + Shadow: True TextField@CHAT_TEXTFIELD: Y: PARENT_BOTTOM - 25 Width: 582 diff --git a/mods/common/metrics.yaml b/mods/common/metrics.yaml index 41436c54e2..97d47ccd94 100644 --- a/mods/common/metrics.yaml +++ b/mods/common/metrics.yaml @@ -10,8 +10,9 @@ Metrics: ButtonTextShadow: false CheckboxPressedState: false GameStartedColor: FFA500 - GlobalChatNotificationColor: D3D3D3 + GlobalChatNotificationColor: FFA500 GlobalChatTextColor: FFFFFF + GlobalChatPlayerNameColor: 00FF00 HotkeyColor: FFFFFF HotkeyColorDisabled: 808080 HotkeyFont: Regular