Tweak lobby chat panel

This commit is contained in:
Paul Chote
2011-07-09 17:15:06 +12:00
parent 3f468353fc
commit f724da5628
2 changed files with 38 additions and 34 deletions

View File

@@ -219,6 +219,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
chatPanel = lobby.GetWidget<ScrollPanelWidget>("CHAT_DISPLAY");
chatTemplate = chatPanel.GetWidget("CHAT_TEMPLATE");
chatPanel.RemoveChildren();
lobby.GetWidget<ButtonWidget>("MUSIC_BUTTON").OnClick = () =>
{
@@ -241,31 +242,32 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
public void AddChatLine(Color c, string from, string text)
{
var template = chatTemplate.Clone() as ContainerWidget;
var nameLabel = template.GetWidget<LabelWidget>("NAME");
var timeLabel = template.GetWidget<LabelWidget>("TIME");
var textLabel = template.GetWidget<LabelWidget>("TEXT");
var name = from+":";
var font = Game.Renderer.Fonts["Regular"];
var font = Game.Renderer.Fonts[nameLabel.Font];
var nameSize = font.Measure(from);
var template = chatTemplate.Clone() as ContainerWidget;
template.IsVisible = () => true;
var time = System.DateTime.Now;
template.GetWidget<LabelWidget>("TIME").GetText = () => "[{0:D2}:{1:D2}]".F(time.Hour, time.Minute);
timeLabel.GetText = () => "{0:D2}:{1:D2}".F(time.Hour, time.Minute);
var p = template.GetWidget<LabelWidget>("NAME");
p.GetColor = () => c;
p.GetText = () => name;
p.Bounds.Width = nameSize.X;
var t = template.GetWidget<LabelWidget>("TEXT");
t.Bounds.X += nameSize.X;
t.Bounds.Width -= nameSize.X;
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();

View File

@@ -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