Merge pull request #13175 from rob-v/GlobalChat

Enhance - unify global chat (with lobby chat)
This commit is contained in:
Taryn Hill
2017-04-29 09:28:34 -05:00
committed by GitHub
8 changed files with 143 additions and 58 deletions

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
class GlobalChatLogic : ChromeLogic class GlobalChatLogic : ChromeLogic
{ {
readonly ScrollPanelWidget historyPanel; readonly ScrollPanelWidget historyPanel;
readonly LabelWidget historyTemplate; readonly ContainerWidget chatTemplate;
readonly ScrollPanelWidget nicknamePanel; readonly ScrollPanelWidget nicknamePanel;
readonly Widget nicknameTemplate; readonly Widget nicknameTemplate;
readonly TextFieldWidget inputBox; readonly TextFieldWidget inputBox;
@@ -27,10 +27,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public GlobalChatLogic(Widget widget) public GlobalChatLogic(Widget widget)
{ {
historyPanel = widget.Get<ScrollPanelWidget>("HISTORY_PANEL"); historyPanel = widget.Get<ScrollPanelWidget>("HISTORY_PANEL");
historyTemplate = historyPanel.Get<LabelWidget>("HISTORY_TEMPLATE"); chatTemplate = historyPanel.Get<ContainerWidget>("CHAT_TEMPLATE");
nicknamePanel = widget.Get<ScrollPanelWidget>("NICKNAME_PANEL"); nicknamePanel = widget.Get<ScrollPanelWidget>("NICKNAME_PANEL");
nicknameTemplate = nicknamePanel.Get("NICKNAME_TEMPLATE"); nicknameTemplate = nicknamePanel.Get("NICKNAME_TEMPLATE");
var textColor = ChromeMetrics.Get<Color>("GlobalChatTextColor");
var textLabel = chatTemplate.Get<LabelWidget>("TEXT");
textLabel.GetColor = () => textColor;
historyPanel.Bind(Game.GlobalChat.History, MakeHistoryWidget, HistoryWidgetEquals, true); historyPanel.Bind(Game.GlobalChat.History, MakeHistoryWidget, HistoryWidgetEquals, true);
nicknamePanel.Bind(Game.GlobalChat.Users, MakeUserWidget, UserWidgetEquals, false); nicknamePanel.Bind(Game.GlobalChat.Users, MakeUserWidget, UserWidgetEquals, false);
@@ -80,19 +84,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Widget MakeHistoryWidget(object o) Widget MakeHistoryWidget(object o)
{ {
var message = (ChatMessage)o; var message = (ChatMessage)o;
var widget = (LabelWidget)historyTemplate.Clone(); var from = message.Type == ChatMessageType.Notification ? "Battlefield Control" : message.Nick;
var font = Game.Renderer.Fonts[widget.Font]; var color = message.Type == ChatMessageType.Notification ? ChromeMetrics.Get<Color>("GlobalChatNotificationColor")
: ChromeMetrics.Get<Color>("GlobalChatPlayerNameColor");
var template = (ContainerWidget)chatTemplate.Clone();
LobbyUtils.SetupChatLine(template, color, from, message.Message);
var color = message.Type == ChatMessageType.Notification ? template.Id = message.UID;
ChromeMetrics.Get<Color>("GlobalChatNotificationColor") : return template;
ChromeMetrics.Get<Color>("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;
} }
bool HistoryWidgetEquals(Widget widget, object o) bool HistoryWidgetEquals(Widget widget, object o)

View File

@@ -565,33 +565,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
lobbyChatUnreadMessages += 1; lobbyChatUnreadMessages += 1;
var template = chatTemplate.Clone(); var template = (ContainerWidget)chatTemplate.Clone();
var nameLabel = template.Get<LabelWidget>("NAME"); LobbyUtils.SetupChatLine(template, c, from, text);
var timeLabel = template.Get<LabelWidget>("TIME");
var textLabel = template.Get<LabelWidget>("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 scrolledToBottom = lobbyChatPanel.ScrolledToBottom; var scrolledToBottom = lobbyChatPanel.ScrolledToBottom;
lobbyChatPanel.AddChild(template); lobbyChatPanel.AddChild(template);

View File

@@ -517,5 +517,35 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return address; return address;
} }
public static void SetupChatLine(ContainerWidget template, Color c, string from, string text)
{
var nameLabel = template.Get<LabelWidget>("NAME");
var timeLabel = template.Get<LabelWidget>("TIME");
var textLabel = template.Get<LabelWidget>("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;
}
}
} }
} }

View File

@@ -26,10 +26,30 @@ Container@LOBBY_GLOBALCHAT_PANEL:
TopBottomSpacing: 4 TopBottomSpacing: 4
ItemSpacing: 4 ItemSpacing: 4
Children: Children:
Label@HISTORY_TEMPLATE: Container@CHAT_TEMPLATE:
X: 5 X: 2
Width: 530 Width: PARENT_RIGHT-27
WordWrap: True 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: TextField@CHAT_TEXTFIELD:
X: 200 X: 200
Y: PARENT_BOTTOM + 5 Y: PARENT_BOTTOM + 5

View File

@@ -26,10 +26,30 @@ Container@GLOBALCHAT_PANEL:
TopBottomSpacing: 4 TopBottomSpacing: 4
ItemSpacing: 4 ItemSpacing: 4
Children: Children:
Label@HISTORY_TEMPLATE: Container@CHAT_TEMPLATE:
X: 5 X: 2
Width: 530 Width: PARENT_RIGHT-27
WordWrap: True 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: TextField@CHAT_TEXTFIELD:
Y: PARENT_BOTTOM - 25 Y: PARENT_BOTTOM - 25
Width: 582 Width: 582

View File

@@ -26,10 +26,30 @@ Container@LOBBY_GLOBALCHAT_PANEL:
TopBottomSpacing: 4 TopBottomSpacing: 4
ItemSpacing: 4 ItemSpacing: 4
Children: Children:
Label@HISTORY_TEMPLATE: Container@CHAT_TEMPLATE:
X: 5 X: 2
Width: 530 Width: PARENT_RIGHT-27
WordWrap: True 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: TextField@CHAT_TEXTFIELD:
X: 205 X: 205
Y: PARENT_BOTTOM - 25 Y: PARENT_BOTTOM - 25

View File

@@ -26,10 +26,30 @@ Container@GLOBALCHAT_PANEL:
TopBottomSpacing: 4 TopBottomSpacing: 4
ItemSpacing: 4 ItemSpacing: 4
Children: Children:
Label@HISTORY_TEMPLATE: Container@CHAT_TEMPLATE:
X: 5 X: 2
Width: 530 Width: PARENT_RIGHT-27
WordWrap: True 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: TextField@CHAT_TEXTFIELD:
Y: PARENT_BOTTOM - 25 Y: PARENT_BOTTOM - 25
Width: 582 Width: 582

View File

@@ -10,8 +10,9 @@ Metrics:
ButtonTextShadow: false ButtonTextShadow: false
CheckboxPressedState: false CheckboxPressedState: false
GameStartedColor: FFA500 GameStartedColor: FFA500
GlobalChatNotificationColor: D3D3D3 GlobalChatNotificationColor: FFA500
GlobalChatTextColor: FFFFFF GlobalChatTextColor: FFFFFF
GlobalChatPlayerNameColor: 00FF00
HotkeyColor: FFFFFF HotkeyColor: FFFFFF
HotkeyColorDisabled: 808080 HotkeyColorDisabled: 808080
HotkeyFont: Regular HotkeyFont: Regular