Restore separated direct connect dialog.
This commit is contained in:
56
OpenRA.Mods.Common/Widgets/Logic/DirectConnectLogic.cs
Normal file
56
OpenRA.Mods.Common/Widgets/Logic/DirectConnectLogic.cs
Normal file
@@ -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<TextFieldWidget>("IP");
|
||||
var portField = panel.Get<TextFieldWidget>("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<ButtonWidget>("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<ButtonWidget>("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;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Color>("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<ButtonWidget>("DIRECTCONNECT_TAB");
|
||||
directConnectTab.IsHighlighted = () => panel == PanelType.DirectConnect;
|
||||
directConnectTab.OnClick = () => panel = PanelType.DirectConnect;
|
||||
var directConnectButton = widget.Get<ButtonWidget>("DIRECTCONNECT_BUTTON");
|
||||
directConnectButton.OnClick = () =>
|
||||
{
|
||||
Ui.OpenWindow("DIRECTCONNECT_PANEL", new WidgetArgs
|
||||
{
|
||||
{ "openLobby", OpenLobby },
|
||||
{ "onExit", DoNothing },
|
||||
{ "directConnectHost", null },
|
||||
{ "directConnectPort", 0 },
|
||||
});
|
||||
};
|
||||
|
||||
var createServerTab = widget.Get<ButtonWidget>("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<TextFieldWidget>("IP");
|
||||
var portField = directConnectPanel.Get<TextFieldWidget>("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<ButtonWidget>("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",
|
||||
|
||||
Reference in New Issue
Block a user