diff --git a/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs index 469a033f26..ca943faa1f 100755 --- a/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs @@ -23,6 +23,9 @@ namespace OpenRA.Mods.Cnc.Widgets public class CncLobbyLogic : IWidgetDelegate { Widget LocalPlayerTemplate, RemotePlayerTemplate, EmptySlotTemplate, EmptySlotTemplateHost; + ScrollPanelWidget chatPanel; + Widget chatTemplate; + ScrollPanelWidget Players; Dictionary CountryNames; string MapUid; @@ -56,7 +59,7 @@ namespace OpenRA.Mods.Cnc.Widgets lobbyLogic.onGameStart(); break; case StaticCrap.AddChatLine: - panel.GetWidget("CHAT_DISPLAY").AddLine(a,b,c); + lobbyLogic.AddChatLine(a,b,c); break; } } @@ -160,7 +163,7 @@ namespace OpenRA.Mods.Cnc.Widgets gameStarting = true; orderManager.IssueOrder(Order.Command("startgame")); }; - + bool teamChat = false; var chatLabel = lobby.GetWidget("LABEL_CHATTYPE"); var chatTextField = lobby.GetWidget("CHAT_TEXTFIELD"); @@ -181,6 +184,40 @@ namespace OpenRA.Mods.Cnc.Widgets chatLabel.Text = (teamChat) ? "Team:" : "Chat:"; return true; }; + + chatPanel = lobby.GetWidget("CHAT_DISPLAY"); + chatTemplate = chatPanel.GetWidget("CHAT_TEMPLATE"); + } + + public void AddChatLine(Color c, string from, string text) + { + var name = from+":"; + var font = Game.Renderer.RegularFont; + var nameSize = font.Measure(from); + + var template = chatTemplate.Clone() as ContainerWidget; + template.IsVisible = () => true; + + var time = System.DateTime.Now; + template.GetWidget("TIME").GetText = () => "[{0:D2}:{1:D2}]".F(time.Hour, time.Minute); + + var p = template.GetWidget("NAME"); + p.Color = c; + p.GetText = () => name; + p.Bounds.Width = nameSize.X; + + var t = template.GetWidget("TEXT"); + t.Bounds.X += nameSize.X; + t.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); + + chatPanel.AddChild(template); } void UpdatePlayerColor(float hf, float sf, float lf, float r) diff --git a/mods/cnc/chrome.yaml b/mods/cnc/chrome.yaml index ec1418d8ce..6235e2a372 100644 --- a/mods/cnc/chrome.yaml +++ b/mods/cnc/chrome.yaml @@ -185,7 +185,7 @@ button: uibuttons.png corner-bl: 0,126,2,2 corner-br: 62,126,2,2 -dialog3: uibuttons.png +dialog2: uibuttons.png background: 2,2,60,60 border-r: 62,2,2,60 border-l: 0,2,2,60 @@ -196,7 +196,7 @@ dialog3: uibuttons.png corner-bl: 0,62,2,2 corner-br: 62,62,2,2 -dialog2: uibuttons.png +dialog3: uibuttons.png background: 2,66,60,60 border-r: 62,66,2,60 border-l: 0,66,2,60 diff --git a/mods/cnc/chrome/lobby.yaml b/mods/cnc/chrome/lobby.yaml index d0e02d6867..54d87ee87d 100644 --- a/mods/cnc/chrome/lobby.yaml +++ b/mods/cnc/chrome/lobby.yaml @@ -307,20 +307,14 @@ Container@SERVER_LOBBY: Text:Ready Align:Left Bold:True - ChatDisplay@CHAT_DISPLAY: - Id:CHAT_DISPLAY - X:15 - Y:285 - Width:PARENT_RIGHT - 30 - Height:PARENT_BOTTOM - 55 - 275 - Notification: beepy2.aud TextField@CHAT_TEXTFIELD: Id:CHAT_TEXTFIELD X:15 - Y:PARENT_BOTTOM - 15 - HEIGHT - LeftMargin:50 + Y:PARENT_BOTTOM - HEIGHT - 15 Width:PARENT_RIGHT - 30 Height:25 + LeftMargin:50 + Background: panel-darkred Children: Label@LABEL_CHATTYPE: Id:LABEL_CHATTYPE @@ -329,6 +323,38 @@ Container@SERVER_LOBBY: Height:25 Align:Right Text:Chat: + ScrollPanel@CHAT_DISPLAY: + Id:CHAT_DISPLAY + X:15 + Y:285 + Width:PARENT_RIGHT - 30 + Height:PARENT_BOTTOM - 324 + ItemSpacing:2 + Children: + Container@CHAT_TEMPLATE: + Id:CHAT_TEMPLATE + Width:PARENT_RIGHT-28 + Height:14 + X:2 + Y:0 + Visible:false + Children: + Label@TIME: + Id:TIME + X:5 + Width:50 + Height:14 + Label@NAME: + Id:NAME + X:55 + Width:50 + Height:14 + Label@TEXT: + Id:TEXT + X:65 + Height:14 + Width:PARENT_RIGHT - 100 - 10 + WordWrap:true CncMenuButton@START_GAME_BUTTON: Id:START_GAME_BUTTON X:0