diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index d0b08c5c20..dc5d5df41d 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -75,6 +75,7 @@ + diff --git a/OpenRA.Mods.Cnc/Widgets/CncMenuLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncMenuLogic.cs index 88589acc8f..8390345699 100755 --- a/OpenRA.Mods.Cnc/Widgets/CncMenuLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncMenuLogic.cs @@ -64,7 +64,18 @@ namespace OpenRA.Mods.Cnc.Widgets Menu = MenuType.None; Widget.OpenWindow("SERVERBROWSER_PANEL", new Dictionary() { - {"onExit", new Action(() => { Menu = MenuType.Multiplayer; Widget.CloseWindow(); })} + {"onExit", new Action(ReturnToMultiplayerMenu)}, + { "openLobby", new Action(() => OpenLobbyPanel(MenuType.Main)) } + }); + }; + + multiplayerMenu.GetWidget("CREATE_BUTTON").OnClick = () => + { + Menu = MenuType.None; + Widget.OpenWindow("CREATESERVER_PANEL", new Dictionary() + { + { "onExit", new Action(ReturnToMultiplayerMenu) }, + { "openLobby", new Action(() => OpenLobbyPanel(MenuType.Multiplayer)) } }); }; @@ -73,8 +84,8 @@ namespace OpenRA.Mods.Cnc.Widgets Menu = MenuType.None; Widget.OpenWindow("DIRECTCONNECT_PANEL", new Dictionary() { - { "onExit", new Action(() => { Menu = MenuType.Multiplayer; Widget.CloseWindow(); }) }, - { "openLobby", new Action(OpenLobbyPanel) } + { "onExit", new Action(ReturnToMultiplayerMenu) }, + { "openLobby", new Action(() => OpenLobbyPanel(MenuType.Multiplayer)) } }); }; @@ -85,19 +96,25 @@ namespace OpenRA.Mods.Cnc.Widgets settingsMenu.GetWidget("BACK_BUTTON").OnClick = () => Menu = MenuType.Main; } + void ReturnToMultiplayerMenu() + { + Menu = MenuType.Multiplayer; + Widget.CloseWindow(); + } + void RemoveShellmapUI() { Widget.CloseWindow(); Widget.RootWidget.RemoveChild(Widget.RootWidget.GetWidget("MENU_BACKGROUND")); } - void OpenLobbyPanel() + void OpenLobbyPanel(MenuType menu) { // Quit the lobby: disconnect and restore menu Action onLobbyClose = () => { Game.DisconnectOnly(); - Menu = MenuType.Main; + Menu = menu; Widget.CloseWindow(); }; @@ -120,7 +137,7 @@ namespace OpenRA.Mods.Cnc.Widgets settings.Server.ExternalPort = 1234; Game.CreateAndJoinServer(settings, map); - OpenLobbyPanel(); + OpenLobbyPanel(MenuType.Main); } } } diff --git a/OpenRA.Mods.Cnc/Widgets/CncServerCreationLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncServerCreationLogic.cs new file mode 100644 index 0000000000..fa722b6483 --- /dev/null +++ b/OpenRA.Mods.Cnc/Widgets/CncServerCreationLogic.cs @@ -0,0 +1,57 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 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.Linq; +using System.Net; +using OpenRA.Widgets; +using System; + +namespace OpenRA.Mods.Cnc.Widgets +{ + public class CncServerCreationLogic : IWidgetDelegate + { + Widget panel; + Action onCreate; + [ObjectCreator.UseCtor] + public CncServerCreationLogic([ObjectCreator.Param] Widget widget, + [ObjectCreator.Param] Action onExit, + [ObjectCreator.Param] Action openLobby) + { + panel = widget.GetWidget("CREATESERVER_PANEL"); + onCreate = openLobby; + + var settings = Game.Settings; + panel.GetWidget("BACK_BUTTON").OnClick = onExit; + panel.GetWidget("CREATE_BUTTON").OnClick = CreateAndJoin; + + panel.GetWidget("MAP_BUTTON").IsDisabled = () => true; + + panel.GetWidget("GAME_TITLE").Text = settings.Server.Name ?? ""; + panel.GetWidget("LISTEN_PORT").Text = settings.Server.ListenPort.ToString(); + panel.GetWidget("EXTERNAL_PORT").Text = settings.Server.ExternalPort.ToString(); + panel.GetWidget("CHECKBOX_ONLINE").Bind(settings.Server, "AdvertiseOnline"); + panel.GetWidget("CHECKBOX_ONLINE").OnChange += _ => settings.Save(); + } + + void CreateAndJoin() + { + var map = Game.modData.AvailableMaps.FirstOrDefault(m => m.Value.Selectable).Key; + + Game.Settings.Server.Name = panel.GetWidget("GAME_TITLE").Text; + Game.Settings.Server.ListenPort = int.Parse(panel.GetWidget("LISTEN_PORT").Text); + Game.Settings.Server.ExternalPort = int.Parse(panel.GetWidget("EXTERNAL_PORT").Text); + Game.Settings.Save(); + + Game.CreateAndJoinServer(Game.Settings, map); + Widget.CloseWindow(); + onCreate(); + } + } +} diff --git a/mods/cnc/chrome/createserver.yaml b/mods/cnc/chrome/createserver.yaml new file mode 100644 index 0000000000..294675572d --- /dev/null +++ b/mods/cnc/chrome/createserver.yaml @@ -0,0 +1,95 @@ +Container@CREATESERVER_PANEL: + Id:CREATESERVER_PANEL + Delegate:CncServerCreationLogic + X:(WINDOW_RIGHT - WIDTH)/2 + Y:(WINDOW_BOTTOM - 500)/2 + Width:740 + Height:535 + Children: + Label@TITLE: + Text:Create Server + Width:740 + Y:0-25 + Font:BigBold + Contrast:true + Align:Center + Background@bg: + Width:740 + Height:500 + Background:panel-black + Children: + Label@GAME_TITLE_LABEL: + Id:GAME_TITLE_LABEL + X:50 + Y:59 + Width:95 + Height:25 + Align: Right + Text:Game Title: + TextField@GAME_TITLE: + Id:GAME_TITLE + X:150 + Y:60 + Width:210 + MaxLength:50 + Height:25 + Text:OpenRA Game + Label@EXTERNAL_PORT_LABEL: + Id:EXTERNAL_PORT_LABEL + X:50 + Y:94 + Width:95 + Height:25 + Align: Right + Text:External Port: + TextField@EXTERNAL_PORT: + Id:EXTERNAL_PORT + X:150 + Y:95 + Width:50 + MaxLength:5 + Height:25 + Text:OpenRA Game + Label@LISTEN_PORT_LABEL: + Id:LISTEN_PORT_LABEL + X:210 + Y:94 + Width:95 + Height:25 + Align: Right + Text:Listen Port: + TextField@LISTEN_PORT: + Id:LISTEN_PORT + X:310 + Y:95 + Width:50 + MaxLength:5 + Height:25 + Checkbox@CHECKBOX_ONLINE: + Id:CHECKBOX_ONLINE + X:165 + Y:130 + Width:300 + Height:20 + Text:Advertise game Online + CncMenuButton@BACK_BUTTON: + Id:BACK_BUTTON + X:0 + Y:499 + Width:140 + Height:35 + Text:Back + CncMenuButton@MAP_BUTTON: + Id:MAP_BUTTON + X:450 + Y:499 + Width:140 + Height:35 + Text:Change Map + CncMenuButton@CREATE_BUTTON: + Id:CREATE_BUTTON + X:600 + Y:499 + Width:140 + Height:35 + Text:Create \ No newline at end of file diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index 4df3099a0c..8500f01988 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -62,6 +62,7 @@ ChromeLayout: mods/cnc/chrome/gameinit.yaml mods/cnc/chrome/mainmenu.yaml mods/cnc/chrome/serverbrowser.yaml + mods/cnc/chrome/createserver.yaml mods/cnc/chrome/directconnect.yaml mods/cnc/chrome/lobby.yaml mods/cnc/chrome/mapchooser.yaml