Start reimplementing server creation

This commit is contained in:
Paul Chote
2011-05-08 12:19:40 +12:00
parent 9f4eba9003
commit 99eb6ab774
5 changed files with 177 additions and 6 deletions

View File

@@ -75,6 +75,7 @@
<Compile Include="Widgets\CncMenuButton.cs" />
<Compile Include="Widgets\CncLobbyLogic.cs" />
<Compile Include="Widgets\CncReplayBrowserLogic.cs" />
<Compile Include="Widgets\CncServerCreationLogic.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -64,7 +64,18 @@ namespace OpenRA.Mods.Cnc.Widgets
Menu = MenuType.None;
Widget.OpenWindow("SERVERBROWSER_PANEL", new Dictionary<string, object>()
{
{"onExit", new Action(() => { Menu = MenuType.Multiplayer; Widget.CloseWindow(); })}
{"onExit", new Action(ReturnToMultiplayerMenu)},
{ "openLobby", new Action(() => OpenLobbyPanel(MenuType.Main)) }
});
};
multiplayerMenu.GetWidget<CncMenuButtonWidget>("CREATE_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
Widget.OpenWindow("CREATESERVER_PANEL", new Dictionary<string, object>()
{
{ "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<string, object>()
{
{ "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<CncMenuButtonWidget>("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);
}
}
}

View File

@@ -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<CncMenuButtonWidget>("BACK_BUTTON").OnClick = onExit;
panel.GetWidget<CncMenuButtonWidget>("CREATE_BUTTON").OnClick = CreateAndJoin;
panel.GetWidget<CncMenuButtonWidget>("MAP_BUTTON").IsDisabled = () => true;
panel.GetWidget<TextFieldWidget>("GAME_TITLE").Text = settings.Server.Name ?? "";
panel.GetWidget<TextFieldWidget>("LISTEN_PORT").Text = settings.Server.ListenPort.ToString();
panel.GetWidget<TextFieldWidget>("EXTERNAL_PORT").Text = settings.Server.ExternalPort.ToString();
panel.GetWidget<CheckboxWidget>("CHECKBOX_ONLINE").Bind(settings.Server, "AdvertiseOnline");
panel.GetWidget<CheckboxWidget>("CHECKBOX_ONLINE").OnChange += _ => settings.Save();
}
void CreateAndJoin()
{
var map = Game.modData.AvailableMaps.FirstOrDefault(m => m.Value.Selectable).Key;
Game.Settings.Server.Name = panel.GetWidget<TextFieldWidget>("GAME_TITLE").Text;
Game.Settings.Server.ListenPort = int.Parse(panel.GetWidget<TextFieldWidget>("LISTEN_PORT").Text);
Game.Settings.Server.ExternalPort = int.Parse(panel.GetWidget<TextFieldWidget>("EXTERNAL_PORT").Text);
Game.Settings.Save();
Game.CreateAndJoinServer(Game.Settings, map);
Widget.CloseWindow();
onCreate();
}
}
}

View File

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

View File

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