Reimplement connecting / connection failed dialogs.
This commit is contained in:
103
OpenRA.Mods.Cnc/Widgets/CncConnectionLogic.cs
Normal file
103
OpenRA.Mods.Cnc/Widgets/CncConnectionLogic.cs
Normal 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);
|
||||
}
|
||||
}}
|
||||
Reference in New Issue
Block a user