Reimplement connecting / connection failed dialogs.

This commit is contained in:
Paul Chote
2011-05-08 16:12:24 +12:00
parent a607a60b8f
commit 5c59f7703d
10 changed files with 270 additions and 147 deletions

View File

@@ -356,9 +356,14 @@ namespace OpenRA
return modData.ObjectCreator.CreateObject<T>( name );
}
public static void CreateAndJoinServer(Settings settings, string map)
public static void CreateServer(Settings settings, string map)
{
server = new Server.Server(modData, settings, map);
}
public static void CreateAndJoinServer(Settings settings, string map)
{
CreateServer(settings, map);
JoinServer(IPAddress.Loopback.ToString(), settings.Server.ListenPort);
}

View File

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

View File

@@ -0,0 +1,103 @@
#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 OpenRA.Network;
using OpenRA.Widgets;
using System;
using System.Collections.Generic;
namespace OpenRA.Mods.Cnc.Widgets
{
public class CncConnectingLogic : IWidgetDelegate
{
static bool staticSetup;
Action onConnect, onRetry, onAbort;
static void ConnectionStateChangedStub(OrderManager om)
{
var panel = Widget.RootWidget.GetWidget("CONNECTING_PANEL");
if (panel == null)
return;
var handler = panel.DelegateObject as CncConnectingLogic;
if (handler == null)
return;
handler.ConnectionStateChanged(om);
}
void ConnectionStateChanged(OrderManager om)
{
if (om.Connection.ConnectionState == ConnectionState.Connected)
{
Widget.CloseWindow();
onConnect();
}
else if (om.Connection.ConnectionState == ConnectionState.NotConnected)
{
// Show connection failed dialog
Widget.CloseWindow();
Widget.OpenWindow("CONNECTIONFAILED_PANEL", new Dictionary<string, object>()
{
{ "onAbort", onAbort },
{ "onRetry", onRetry }
});
}
}
[ObjectCreator.UseCtor]
public CncConnectingLogic([ObjectCreator.Param] Widget widget,
[ObjectCreator.Param] Action onConnect,
[ObjectCreator.Param] Action onRetry,
[ObjectCreator.Param] Action onAbort)
{
this.onConnect = onConnect;
this.onRetry = onRetry;
this.onAbort = onAbort;
if (!staticSetup)
{
staticSetup = true;
Game.ConnectionStateChanged += ConnectionStateChangedStub;
}
var panel = widget.GetWidget("CONNECTING_PANEL");
panel.GetWidget<CncMenuButtonWidget>("ABORT_BUTTON").OnClick = onAbort;
//widget.GetWidget<LabelWidget>("CONNECTING_DESC").GetText = () =>
// "Connecting to {0}:{1}...".F(host, port);
}
public static void Connect(string host, int port, Action onConnect, Action onAbort)
{
Game.JoinServer(host, port);
Widget.OpenWindow("CONNECTING_PANEL", new Dictionary<string, object>()
{
{ "onConnect", onConnect },
{ "onAbort", onAbort },
{ "onRetry", new Action(() => { Widget.CloseWindow(); Connect(host, port, onConnect, onAbort); }) }
});
}
}
public class CncConnectionFailedLogic : IWidgetDelegate
{
[ObjectCreator.UseCtor]
public CncConnectionFailedLogic([ObjectCreator.Param] Widget widget,
[ObjectCreator.Param] Action onRetry,
[ObjectCreator.Param] Action onAbort)
{
var panel = widget.GetWidget("CONNECTIONFAILED_PANEL");
panel.GetWidget<CncMenuButtonWidget>("ABORT_BUTTON").OnClick = onAbort;
panel.GetWidget<CncMenuButtonWidget>("RETRY_BUTTON").OnClick = onRetry;
//widget.GetWidget<LabelWidget>("CONNECTING_DESC").GetText = () =>
// "Connecting to {0}:{1}...".F(host, port);
}
}}

View File

@@ -35,38 +35,72 @@ namespace OpenRA.Mods.Cnc.Widgets
// Must be set only once on game start
// TODO: This is stupid
static bool staticSetup;
enum StaticCrap { LobbyInfo, BeforeGameStart, AddChatLine }
static void StaticCrapChanged(StaticCrap type, Color a, string b, string c)
static bool staticSetup;
public static CncLobbyLogic GetHandler()
{
var panel = Widget.RootWidget.GetWidget("SERVER_LOBBY");
// The panel may not be open anymore
if (panel == null)
return;
return null;
var lobbyLogic = panel.DelegateObject as CncLobbyLogic;
if (lobbyLogic == null)
return panel.DelegateObject as CncLobbyLogic;
}
static void LobbyInfoChangedStub()
{
var handler = GetHandler();
if (handler == null)
return;
switch (type)
{
case StaticCrap.LobbyInfo:
lobbyLogic.UpdateCurrentMap();
lobbyLogic.UpdatePlayerList();
break;
case StaticCrap.BeforeGameStart:
lobbyLogic.onGameStart();
break;
case StaticCrap.AddChatLine:
lobbyLogic.AddChatLine(a,b,c);
break;
}
handler.UpdateCurrentMap();
handler.UpdatePlayerList();
}
static void BeforeGameStartStub()
{
var handler = GetHandler();
if (handler == null)
return;
handler.onGameStart();
}
static void AddChatLineStub(Color c, string from, string text)
{
var handler = GetHandler();
if (handler == null)
return;
handler.AddChatLine(c, from, text);
}
static void ConnectionStateChangedStub(OrderManager om)
{
var handler = GetHandler();
if (handler == null)
return;
handler.ConnectionStateChanged(om);
}
// Listen for connection failures
void ConnectionStateChanged(OrderManager om)
{
// TODO: Show a connection failed dialog
if (om.Connection.ConnectionState == ConnectionState.NotConnected)
onExit();
//Widget.CloseWindow();
//Widget.OpenWindow("CONNECTION_FAILED_BG", new Dictionary<string, object> { { "orderManager", orderManager } });
}
readonly Action onGameStart;
readonly Action onExit;
readonly OrderManager orderManager;
readonly WorldRenderer worldRenderer;
[ObjectCreator.UseCtor]
internal CncLobbyLogic([ObjectCreator.Param( "widget" )] Widget lobby,
[ObjectCreator.Param] OrderManager orderManager,
@@ -77,13 +111,15 @@ namespace OpenRA.Mods.Cnc.Widgets
this.orderManager = orderManager;
this.worldRenderer = worldRenderer;
this.onGameStart = onStart;
this.onExit = onExit;
if (!staticSetup)
{
staticSetup = true;
Game.LobbyInfoChanged += () => StaticCrapChanged(StaticCrap.LobbyInfo, Color.Beige, null, null);
Game.BeforeGameStart += () => StaticCrapChanged(StaticCrap.BeforeGameStart, Color.PapayaWhip, null, null);
Game.AddChatLine += (a,b,c) => StaticCrapChanged(StaticCrap.AddChatLine, a, b, c);
Game.LobbyInfoChanged += LobbyInfoChangedStub;
Game.BeforeGameStart += BeforeGameStartStub;
Game.AddChatLine += AddChatLineStub;
Game.ConnectionStateChanged += ConnectionStateChangedStub;
}
UpdateCurrentMap();

View File

@@ -49,9 +49,10 @@ namespace OpenRA.Mods.Cnc.Widgets
return "";
}
}
[ObjectCreator.UseCtor]
public CncServerBrowserLogic([ObjectCreator.Param] Widget widget,
[ObjectCreator.Param] Action openLobby,
[ObjectCreator.Param] Action onExit)
{
var panel = widget.GetWidget("SERVERBROWSER_PANEL");
@@ -74,8 +75,10 @@ namespace OpenRA.Mods.Cnc.Widgets
if (currentServer == null)
return;
Widget.CloseWindow();
Game.JoinServer(currentServer.Address.Split(':')[0], int.Parse(currentServer.Address.Split(':')[1]));
string host = currentServer.Address.Split(':')[0];
int port = int.Parse(currentServer.Address.Split(':')[1]);
CncConnectingLogic.Connect(host, port, openLobby, onExit);
};
panel.GetWidget<CncMenuButtonWidget>("BACK_BUTTON").OnClick = onExit;
@@ -189,7 +192,7 @@ namespace OpenRA.Mods.Cnc.Widgets
browserLogic.RefreshServerList(games);
}
}
public class CncDirectConnectLogic : IWidgetDelegate
{
[ObjectCreator.UseCtor]
@@ -198,24 +201,24 @@ namespace OpenRA.Mods.Cnc.Widgets
[ObjectCreator.Param] Action openLobby)
{
var panel = widget.GetWidget("DIRECTCONNECT_PANEL");
var ip = panel.GetWidget<TextFieldWidget>("IP");
var port = panel.GetWidget<TextFieldWidget>("PORT");
var ipField = panel.GetWidget<TextFieldWidget>("IP");
var portField = panel.GetWidget<TextFieldWidget>("PORT");
var last = Game.Settings.Player.LastServer.Split(':').ToArray();
ip.Text = last.Length > 1 ? last[0] : "localhost";
port.Text = last.Length > 2 ? last[1] : "1234";
ipField.Text = last.Length > 1 ? last[0] : "localhost";
portField.Text = last.Length > 2 ? last[1] : "1234";
panel.GetWidget<CncMenuButtonWidget>("JOIN_BUTTON").OnClick = () =>
{
int p;
if (!int.TryParse(port.Text, out p))
p = 1234;
int port;
if (!int.TryParse(portField.Text, out port))
port = 1234;
Game.Settings.Player.LastServer = "{0}:{1}".F(ip.Text, p);
Game.Settings.Player.LastServer = "{0}:{1}".F(ipField.Text, port);
Game.Settings.Save();
Game.JoinServer(ip.Text,p);
openLobby();
Widget.CloseWindow();
CncConnectingLogic.Connect(ipField.Text, port, openLobby, onExit);
};
panel.GetWidget<CncMenuButtonWidget>("BACK_BUTTON").OnClick = onExit;

View File

@@ -20,6 +20,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{
Widget panel;
Action onCreate;
Action onExit;
Map map;
bool advertiseOnline;
[ObjectCreator.UseCtor]
@@ -29,6 +30,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{
panel = widget.GetWidget("CREATESERVER_PANEL");
onCreate = openLobby;
this.onExit = onExit;
var settings = Game.Settings;
panel.GetWidget<CncMenuButtonWidget>("BACK_BUTTON").OnClick = onExit;
@@ -68,9 +70,9 @@ namespace OpenRA.Mods.Cnc.Widgets
Game.Settings.Server.AdvertiseOnline = advertiseOnline;
Game.Settings.Save();
Game.CreateAndJoinServer(Game.Settings, map.Uid);
Game.CreateServer(Game.Settings, map.Uid);
Widget.CloseWindow();
onCreate();
CncConnectingLogic.Connect(IPAddress.Loopback.ToString(), Game.Settings.Server.ListenPort, onCreate, onExit);
}
}
}

View File

@@ -34,38 +34,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
public void Init()
{
if (Info.InstallMode == "cnc")
{
/*
Game.ConnectionStateChanged += orderManager =>
{
Widget.CloseWindow();
switch (orderManager.Connection.ConnectionState)
{
case ConnectionState.PreConnecting:
Widget.LoadWidget("MENU_BACKGROUND");
break;
case ConnectionState.Connecting:
Widget.OpenWindow("CONNECTING_BG",
new Dictionary<string, object> { { "host", orderManager.Host }, { "port", orderManager.Port } });
break;
case ConnectionState.NotConnected:
Widget.OpenWindow("CONNECTION_FAILED_BG",
new Dictionary<string, object> { { "orderManager", orderManager } });
break;
case ConnectionState.Connected:
var lobby = Game.OpenWindow(orderManager.world, "SERVER_LOBBY");
lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true;
lobby.GetWidget("LOCKTEAMS_CHECKBOX").Visible = true;
lobby.GetWidget("ALLOWCHEATS_CHECKBOX").Visible = true;
lobby.GetWidget("DISCONNECT_BUTTON").Visible = true;
break;
}
};
*/
}
else
if (Info.InstallMode != "cnc")
{
Game.ConnectionStateChanged += orderManager =>
{

View File

@@ -0,0 +1,77 @@
Container@CONNECTING_PANEL:
Id:CONNECTING_PANEL
Delegate:CncConnectingLogic
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - 90)/2
Width:370
Height:125
Children:
Label@TITLE:
Width:PARENT_RIGHT
Y:0-25
Font:BigBold
Contrast:true
Align:Center
Text:Connecting
Background@bg:
Width:370
Height:90
Background:panel-black
Children:
Label@CONNECTING_DESC:
Id:CONNECTING_DESC
Y:(PARENT_BOTTOM-HEIGHT)/2
Width:PARENT_RIGHT
Height:25
Text:Connecting...
Font:Bold
Align:Center
CncMenuButton@ABORT_BUTTON:
Id:ABORT_BUTTON
X:230
Y:89
Width:140
Height:35
Text:Abort
Container@CONNECTIONFAILED_PANEL:
Id:CONNECTIONFAILED_PANEL
Delegate:CncConnectionFailedLogic
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - 90)/2
Width:370
Height:125
Children:
Label@TITLE:
Width:PARENT_RIGHT
Y:0-25
Font:BigBold
Contrast:true
Align:Center
Text:Connection Failed
Background@bg:
Width:370
Height:90
Background:panel-black
Children:
Label@CONNECTING_DESC:
Id:CONNECTING_DESC
Y:(PARENT_BOTTOM-HEIGHT)/2
Width:PARENT_RIGHT
Height:25
Text:Failed to connect
Font:Bold
Align:Center
CncMenuButton@RETRY_BUTTON:
Id:RETRY_BUTTON
Y:89
Width:140
Height:35
Text:Retry
CncMenuButton@ABORT_BUTTON:
Id:ABORT_BUTTON
X:230
Y:89
Width:140
Height:35
Text:Abort

View File

@@ -1,74 +0,0 @@
Background@CONNECTION_FAILED_BG:
Id:CONNECTION_FAILED_BG
Delegate:ConnectionFailedDelegate
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:450
Height:150
Children:
Label@CONNECTION_FAILED_TITLE:
Id:CONNECTION_FAILED_TITLE
X:0
Y:20
Width:450
Height:25
Text:Connection Failed
Align:Center
Bold:True
Label@CONNECTION_FAILED_DESC:
Id:CONNECTION_FAILED_DESC
X:0
Y:60
Width:PARENT_RIGHT
Height:25
Text:Could not connect to AAA.BBB.CCC.DDD:EEEE
Align:Center
Button@CONNECTION_BUTTON_RETRY:
Id:CONNECTION_BUTTON_RETRY
X:PARENT_RIGHT - 360
Y:PARENT_BOTTOM - 45
Width:160
Height:25
Text:Retry
Bold:True
Button@CONNECTION_BUTTON_CANCEL:
Id:CONNECTION_BUTTON_CANCEL
X:PARENT_RIGHT - 180
Y:PARENT_BOTTOM - 45
Width:160
Height:25
Text:Cancel
Bold:True
Background@CONNECTING_BG:
Id:CONNECTING_BG
Delegate:ConnectionDialogsDelegate
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:450
Height:150
Children:
Label@CONNECTING_TITLE:
Id:CONNECTING_TITLE
X:0
Y:20
Width:450
Height:25
Text:Connecting
Align:Center
Bold:True
Label@CONNECTING_DESC:
Id:CONNECTING_DESC
X:0
Y:60
Width:PARENT_RIGHT
Height:25
Text:Connecting to AAA.BBB.CCC.DDD:EEEE...
Align:Center
Button@CONNECTION_BUTTON_ABORT:
Id:CONNECTION_BUTTON_ABORT
X:PARENT_RIGHT - 180
Y:PARENT_BOTTOM - 45
Width:160
Height:25
Text:Abort
Bold:True

View File

@@ -65,6 +65,7 @@ ChromeLayout:
mods/cnc/chrome/createserver.yaml
mods/cnc/chrome/directconnect.yaml
mods/cnc/chrome/lobby.yaml
mods/cnc/chrome/connection.yaml
mods/cnc/chrome/mapchooser.yaml
mods/cnc/chrome/replaybrowser.yaml
mods/cnc/chrome/ingame.yaml