diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 0cc9844663..20bde1192b 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -835,6 +835,7 @@ + diff --git a/OpenRA.Mods.Common/Widgets/Logic/DirectConnectLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/DirectConnectLogic.cs new file mode 100644 index 0000000000..1d8f041543 --- /dev/null +++ b/OpenRA.Mods.Common/Widgets/Logic/DirectConnectLogic.cs @@ -0,0 +1,56 @@ +#region Copyright & License Information +/* + * Copyright 2007-2017 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using OpenRA.Widgets; + +namespace OpenRA.Mods.Common.Widgets.Logic +{ + public class DirectConnectLogic : ChromeLogic + { + static readonly Action DoNothing = () => { }; + + [ObjectCreator.UseCtor] + public DirectConnectLogic(Widget widget, Action onExit, Action openLobby, string directConnectHost, int directConnectPort) + { + var panel = widget; + var ipField = panel.Get("IP"); + var portField = panel.Get("PORT"); + + var last = Game.Settings.Player.LastServer.Split(':'); + ipField.Text = last.Length > 1 ? last[0] : "localhost"; + portField.Text = last.Length == 2 ? last[1] : "1234"; + + panel.Get("JOIN_BUTTON").OnClick = () => + { + var port = Exts.WithDefault(1234, () => Exts.ParseIntegerInvariant(portField.Text)); + + Game.Settings.Player.LastServer = "{0}:{1}".F(ipField.Text, port); + Game.Settings.Save(); + + ConnectionLogic.Connect(ipField.Text, port, "", () => { Ui.CloseWindow(); openLobby(); }, DoNothing); + }; + + panel.Get("BACK_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); }; + + if (directConnectHost != null) + { + // The connection window must be opened at the end of the tick for the widget hierarchy to + // work out, but we also want to prevent the server browser from flashing visible for one tick. + widget.Visible = false; + Game.RunAfterTick(() => + { + ConnectionLogic.Connect(directConnectHost, directConnectPort, "", () => { Ui.CloseWindow(); openLobby(); }, DoNothing); + widget.Visible = true; + }); + } + } + } +} diff --git a/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs index 66dcf1ca01..3c8424f04b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { static readonly Action DoNothing = () => { }; - enum PanelType { Browser, DirectConnect, CreateServer } + enum PanelType { Browser, CreateServer } PanelType panel = PanelType.Browser; readonly Color incompatibleVersionColor; @@ -85,7 +85,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic incompatibleGameStartedColor = ChromeMetrics.Get("IncompatibleGameStartedColor"); LoadBrowserPanel(widget); - LoadDirectConnectPanel(widget); LoadCreateServerPanel(widget); // Filter and refresh buttons act on the browser panel, @@ -100,9 +99,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic browserTab.IsHighlighted = () => panel == PanelType.Browser; browserTab.OnClick = () => panel = PanelType.Browser; - var directConnectTab = widget.Get("DIRECTCONNECT_TAB"); - directConnectTab.IsHighlighted = () => panel == PanelType.DirectConnect; - directConnectTab.OnClick = () => panel = PanelType.DirectConnect; + var directConnectButton = widget.Get("DIRECTCONNECT_BUTTON"); + directConnectButton.OnClick = () => + { + Ui.OpenWindow("DIRECTCONNECT_PANEL", new WidgetArgs + { + { "openLobby", OpenLobby }, + { "onExit", DoNothing }, + { "directConnectHost", null }, + { "directConnectPort", 0 }, + }); + }; var createServerTab = widget.Get("CREATE_TAB"); createServerTab.IsHighlighted = () => panel == PanelType.CreateServer; @@ -131,7 +138,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic widget.Visible = false; Game.RunAfterTick(() => { - ConnectionLogic.Connect(directConnectHost, directConnectPort, "", OpenLobby, DoNothing); + Ui.OpenWindow("DIRECTCONNECT_PANEL", new WidgetArgs + { + { "openLobby", OpenLobby }, + { "onExit", DoNothing }, + { "directConnectHost", directConnectHost }, + { "directConnectPort", directConnectPort }, + }); + widget.Visible = true; }); } @@ -261,30 +275,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic } } - void LoadDirectConnectPanel(Widget widget) - { - var directConnectPanel = Game.LoadWidget(null, "MULTIPLAYER_DIRECTCONNECT_PANEL", - widget.Get("TOP_PANELS_ROOT"), new WidgetArgs()); - directConnectPanel.IsVisible = () => panel == PanelType.DirectConnect; - - var ipField = directConnectPanel.Get("IP"); - var portField = directConnectPanel.Get("PORT"); - - var last = Game.Settings.Player.LastServer.Split(':'); - ipField.Text = last.Length > 1 ? last[0] : "localhost"; - portField.Text = last.Length == 2 ? last[1] : "1234"; - - directConnectPanel.Get("JOIN_BUTTON").OnClick = () => - { - var port = Exts.WithDefault(1234, () => Exts.ParseIntegerInvariant(portField.Text)); - - Game.Settings.Player.LastServer = "{0}:{1}".F(ipField.Text, port); - Game.Settings.Save(); - - ConnectionLogic.Connect(ipField.Text, port, "", OpenLobby, DoNothing); - }; - } - void LoadCreateServerPanel(Widget widget) { var createServerPanel = Game.LoadWidget(null, "MULTIPLAYER_CREATESERVER_PANEL", diff --git a/mods/cnc/chrome/multiplayer-directconnect.yaml b/mods/cnc/chrome/multiplayer-directconnect.yaml index 31b7a30759..b453ef6cf6 100644 --- a/mods/cnc/chrome/multiplayer-directconnect.yaml +++ b/mods/cnc/chrome/multiplayer-directconnect.yaml @@ -1,95 +1,58 @@ -Container@MULTIPLAYER_DIRECTCONNECT_PANEL: - Width: PARENT_RIGHT - Height: PARENT_BOTTOM +Container@DIRECTCONNECT_PANEL: + Logic: DirectConnectLogic + X: (WINDOW_RIGHT - WIDTH)/2 + Y: (WINDOW_BOTTOM - 90)/2 + Width: 370 + Height: 125 Children: Label@TITLE: - Y: 5 - Width: 582 - Height: 25 - Text: Connect to Server + Width: PARENT_RIGHT + Y: 0-25 + Font: BigBold + Contrast: true Align: Center - Font: Bold - ScrollPanel: - Y: 30 - Width: 582 - Height: 249 + Text: Connect to Server + Background@bg: + Width: 370 + Height: 90 + Background: panel-black Children: - Container: - X: 185 - Y: 60 - Children: - Label@ADDRESS_LABEL: - Y: 14 - Width: 95 - Height: 25 - Align: Right - Text: Address: - TextField@IP: - X: 100 - Y: 15 - Width: 215 - Height: 25 - Label@PORT_LABEL: - Y: 49 - Width: 95 - Height: 25 - Align: Right - Text: Port: - TextField@PORT: - X: 100 - Y: 50 - Width: 50 - Height: 25 - MaxLength: 5 - Container@SIDEBAR: - X: PARENT_RIGHT - WIDTH - Y: 30 - Width: 174 - Height: 280 - Children: - Background@MAP_BG: - Width: PARENT_RIGHT - Height: 174 - Background: panel-gray - Label@TITLE: - Y: 172 - Width: PARENT_RIGHT + Label@ADDRESS_LABEL: + X: 50 + Y: 14 + Width: 95 Height: 25 - Font: Bold - Align: Center - Text: Direct Connect - Label@DESCA: - Y: 190 - Width: PARENT_RIGHT + Align: Right + Text: Address: + TextField@IP: + X: 150 + Y: 15 + Width: 200 Height: 25 - Font: Tiny - Align: Center - Text: Enter the server IP and port in the - Label@DESCB: - Y: 203 - Width: PARENT_RIGHT + Label@PORT_LABEL: + X: 50 + Y: 49 + Width: 95 Height: 25 - Font: Tiny - Align: Center - Text: fields to the left, and then press Join. - Label@DESCC: - Y: 216 - Width: PARENT_RIGHT + Align: Right + Text: Port: + TextField@PORT: + X: 150 + Y: 50 + Width: 200 Height: 25 - Font: Tiny - Align: Center - Text: The mod and game version will be - Label@DESCD: - Y: 229 - Width: PARENT_RIGHT - Height: 25 - Font: Tiny - Align: Center - Text: verified when connecting. + Button@BACK_BUTTON: + Key: escape + X: 0 + Y: 89 + Width: 140 + Height: 35 + Text: Back Button@JOIN_BUTTON: Key: return - X: PARENT_RIGHT - WIDTH - Y: 284 - Width: 174 - Height: 25 + X: 230 + Y: 89 + Width: 140 + Height: 35 Text: Join + diff --git a/mods/cnc/chrome/multiplayer.yaml b/mods/cnc/chrome/multiplayer.yaml index 9e5571626b..8cd2519b56 100644 --- a/mods/cnc/chrome/multiplayer.yaml +++ b/mods/cnc/chrome/multiplayer.yaml @@ -20,27 +20,27 @@ Container@MULTIPLAYER_PANEL: DropDownButton@FILTERS_DROPDOWNBUTTON: X: 15 Y: 284 - Width: 147 + Width: 152 Height: 25 Text: Filter Games Button@REFRESH_BUTTON: - X: 167 + X: 172 Y: 284 Width: 100 Height: 25 Text: Refresh + Button@DIRECTCONNECT_BUTTON: + X: 277 + Y: 284 + Width: 100 + Height: 25 + Text: Direct IP Button@BROWSER_TAB: - X: 272 - Y: 278 - Width: 105 - Height: 31 - Text: Browse - Button@DIRECTCONNECT_TAB: X: 382 Y: 278 Width: 105 Height: 31 - Text: Direct IP + Text: Browse Button@CREATE_TAB: X: 492 Y: 278 diff --git a/mods/common/chrome/connection.yaml b/mods/common/chrome/connection.yaml index 693b74b7b9..ed314d5bd3 100644 --- a/mods/common/chrome/connection.yaml +++ b/mods/common/chrome/connection.yaml @@ -63,7 +63,7 @@ Background@CONNECTING_PANEL: X: (WINDOW_RIGHT - WIDTH) / 2 Y: (WINDOW_BOTTOM - HEIGHT) / 2 Width: 450 - Height: 150 + Height: 160 Children: Label@CONNECTING_TITLE: X: 0 diff --git a/mods/common/chrome/multiplayer-directconnect.yaml b/mods/common/chrome/multiplayer-directconnect.yaml index 4777c7e9d1..b96f28d55f 100644 --- a/mods/common/chrome/multiplayer-directconnect.yaml +++ b/mods/common/chrome/multiplayer-directconnect.yaml @@ -1,96 +1,57 @@ -Container@MULTIPLAYER_DIRECTCONNECT_PANEL: - Width: PARENT_RIGHT - Height: PARENT_BOTTOM +Background@DIRECTCONNECT_PANEL: + Logic: DirectConnectLogic + X: (WINDOW_RIGHT - WIDTH)/2 + Y: (WINDOW_BOTTOM - HEIGHT)/2 + Width: 450 + Height: 160 Children: - Label@TITLE: - Y: 5 - Width: 583 + Label@DIRECTCONNECT_LABEL_TITLE: + X: 0 + Y: 20 + Width: 450 Height: 25 Text: Connect to Server Align: Center Font: Bold - ScrollPanel: - Y: 30 - Width: 583 - Height: 279 - Children: - Container: - X: 185 - Y: 85 - Children: - Label@ADDRESS_LABEL: - Y: 14 - Width: 95 - Height: 25 - Align: Right - Text: Address: - TextField@IP: - X: 100 - Y: 15 - Width: 215 - Height: 25 - Label@PORT_LABEL: - Y: 49 - Width: 95 - Height: 25 - Align: Right - Text: Port: - TextField@PORT: - X: 100 - Y: 50 - Width: 50 - Height: 25 - MaxLength: 5 - Container@SIDEBAR: - X: PARENT_RIGHT - WIDTH - Y: 30 - Width: 174 - Height: 280 - Children: - Background@MAP_BG: - Width: PARENT_RIGHT - Height: 174 - Background: dialog3 - Label@TITLE: - Y: 172 - Width: PARENT_RIGHT - Height: 25 - Font: Bold - Align: Center - Text: Direct Connect - Label@DESCA: - Y: 190 - Width: PARENT_RIGHT - Height: 25 - Font: Tiny - Align: Center - Text: Enter the server IP and port in the - Label@DESCB: - Y: 203 - Width: PARENT_RIGHT - Height: 25 - Font: Tiny - Align: Center - Text: fields to the left, and then press Join. - Label@DESCC: - Y: 216 - Width: PARENT_RIGHT - Height: 25 - Font: Tiny - Align: Center - Text: The mod and game version will be - Label@DESCD: - Y: 229 - Width: PARENT_RIGHT - Height: 25 - Font: Tiny - Align: Center - Text: verified when connecting. + Label@ADDRESS_LABEL: + X: 50 + Y: 59 + Width: 95 + Height: 25 + Align: Right + Text: Server Address: + TextField@IP: + X: 150 + Y: 60 + Width: 210 + MaxLength: 50 + Height: 25 + Label@PORT_LABEL: + X: 360 + Y: 59 + Width: 10 + Height: 25 + Align: Center + Text: : + TextField@PORT: + X: 370 + Y: 60 + Width: 60 + MaxLength: 5 + Height: 25 Button@JOIN_BUTTON: - Key: return - X: PARENT_RIGHT - WIDTH - Y: 284 - Width: 174 + X: PARENT_RIGHT - 430 + Y: PARENT_BOTTOM - 45 + Width: 160 Height: 25 Text: Join Font: Bold + Key: return + Button@BACK_BUTTON: + X: PARENT_RIGHT - 180 + Y: PARENT_BOTTOM - 45 + Width: 160 + Height: 25 + Text: Cancel + Font: Bold + Key: escape \ No newline at end of file diff --git a/mods/common/chrome/multiplayer.yaml b/mods/common/chrome/multiplayer.yaml index 578abb031b..c0615fe696 100644 --- a/mods/common/chrome/multiplayer.yaml +++ b/mods/common/chrome/multiplayer.yaml @@ -20,25 +20,25 @@ Background@MULTIPLAYER_PANEL: Text: Filter Games Font: Bold Button@REFRESH_BUTTON: - X: 183 + X: 182 Y: PARENT_BOTTOM - HEIGHT - 20 Width: 100 Height: 25 Text: Refresh Font: Bold - Button@BROWSER_TAB: + Button@DIRECTCONNECT_BUTTON: X: 288 Y: PARENT_BOTTOM - HEIGHT - 20 - Width: 105 - Height: 31 - Text: Browse + Width: 100 + Height: 25 + Text: Direct IP Font: Bold - Button@DIRECTCONNECT_TAB: + Button@BROWSER_TAB: X: 393 Y: PARENT_BOTTOM - HEIGHT - 20 Width: 105 Height: 31 - Text: Direct IP + Text: Browse Font: Bold Button@CREATE_TAB: X: 498