Restore separated direct connect dialog.

This commit is contained in:
Paul Chote
2017-12-17 18:36:15 +00:00
committed by abcdefg30
parent 205c45198c
commit 5256fb7bbd
8 changed files with 189 additions and 218 deletions

View File

@@ -835,6 +835,7 @@
<Compile Include="Lint\CheckConflictingMouseBounds.cs" />
<Compile Include="Widgets\Logic\Lobby\LobbyOptionsLogic.cs" />
<Compile Include="Traits\World\LobbyPrerequisiteCheckbox.cs" />
<Compile Include="Widgets\Logic\DirectConnectLogic.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">

View 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;
});
}
}
}
}

View File

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

View File

@@ -1,95 +1,58 @@
Container@MULTIPLAYER_DIRECTCONNECT_PANEL:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Container@DIRECTCONNECT_PANEL:
Logic: DirectConnectLogic
X: (WINDOW_RIGHT - WIDTH)/2
Y: (WINDOW_BOTTOM - 90)/2
Width: 370
Height: 125
Children:
Label@TITLE:
Y: 5
Width: 582
Height: 25
Text: Connect to Server
Width: PARENT_RIGHT
Y: 0-25
Font: BigBold
Contrast: true
Align: Center
Font: Bold
ScrollPanel:
Y: 30
Width: 582
Height: 249
Children:
Container:
X: 185
Y: 60
Text: Connect to Server
Background@bg:
Width: 370
Height: 90
Background: panel-black
Children:
Label@ADDRESS_LABEL:
X: 50
Y: 14
Width: 95
Height: 25
Align: Right
Text: Address:
TextField@IP:
X: 100
X: 150
Y: 15
Width: 215
Width: 200
Height: 25
Label@PORT_LABEL:
X: 50
Y: 49
Width: 95
Height: 25
Align: Right
Text: Port:
TextField@PORT:
X: 100
X: 150
Y: 50
Width: 50
Width: 200
Height: 25
MaxLength: 5
Container@SIDEBAR:
X: PARENT_RIGHT - WIDTH
Y: 30
Width: 174
Height: 280
Children:
Background@MAP_BG:
Width: PARENT_RIGHT
Height: 174
Background: panel-gray
Label@TITLE:
Y: 172
Width: PARENT_RIGHT
Height: 25
Font: Bold
Align: Center
Text: Direct Connect
Label@DESCA:
Y: 190
Width: PARENT_RIGHT
Height: 25
Font: Tiny
Align: Center
Text: Enter the server IP and port in the
Label@DESCB:
Y: 203
Width: PARENT_RIGHT
Height: 25
Font: Tiny
Align: Center
Text: fields to the left, and then press Join.
Label@DESCC:
Y: 216
Width: PARENT_RIGHT
Height: 25
Font: Tiny
Align: Center
Text: The mod and game version will be
Label@DESCD:
Y: 229
Width: PARENT_RIGHT
Height: 25
Font: Tiny
Align: Center
Text: verified when connecting.
Button@BACK_BUTTON:
Key: escape
X: 0
Y: 89
Width: 140
Height: 35
Text: Back
Button@JOIN_BUTTON:
Key: return
X: PARENT_RIGHT - WIDTH
Y: 284
Width: 174
Height: 25
X: 230
Y: 89
Width: 140
Height: 35
Text: Join

View File

@@ -20,27 +20,27 @@ Container@MULTIPLAYER_PANEL:
DropDownButton@FILTERS_DROPDOWNBUTTON:
X: 15
Y: 284
Width: 147
Width: 152
Height: 25
Text: Filter Games
Button@REFRESH_BUTTON:
X: 167
X: 172
Y: 284
Width: 100
Height: 25
Text: Refresh
Button@DIRECTCONNECT_BUTTON:
X: 277
Y: 284
Width: 100
Height: 25
Text: Direct IP
Button@BROWSER_TAB:
X: 272
Y: 278
Width: 105
Height: 31
Text: Browse
Button@DIRECTCONNECT_TAB:
X: 382
Y: 278
Width: 105
Height: 31
Text: Direct IP
Text: Browse
Button@CREATE_TAB:
X: 492
Y: 278

View File

@@ -63,7 +63,7 @@ Background@CONNECTING_PANEL:
X: (WINDOW_RIGHT - WIDTH) / 2
Y: (WINDOW_BOTTOM - HEIGHT) / 2
Width: 450
Height: 150
Height: 160
Children:
Label@CONNECTING_TITLE:
X: 0

View File

@@ -1,96 +1,57 @@
Container@MULTIPLAYER_DIRECTCONNECT_PANEL:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Background@DIRECTCONNECT_PANEL:
Logic: DirectConnectLogic
X: (WINDOW_RIGHT - WIDTH)/2
Y: (WINDOW_BOTTOM - HEIGHT)/2
Width: 450
Height: 160
Children:
Label@TITLE:
Y: 5
Width: 583
Label@DIRECTCONNECT_LABEL_TITLE:
X: 0
Y: 20
Width: 450
Height: 25
Text: Connect to Server
Align: Center
Font: Bold
ScrollPanel:
Y: 30
Width: 583
Height: 279
Children:
Container:
X: 185
Y: 85
Children:
Label@ADDRESS_LABEL:
Y: 14
X: 50
Y: 59
Width: 95
Height: 25
Align: Right
Text: Address:
Text: Server Address:
TextField@IP:
X: 100
Y: 15
Width: 215
X: 150
Y: 60
Width: 210
MaxLength: 50
Height: 25
Label@PORT_LABEL:
Y: 49
Width: 95
X: 360
Y: 59
Width: 10
Height: 25
Align: Right
Text: Port:
Align: Center
Text: :
TextField@PORT:
X: 100
Y: 50
Width: 50
Height: 25
X: 370
Y: 60
Width: 60
MaxLength: 5
Container@SIDEBAR:
X: PARENT_RIGHT - WIDTH
Y: 30
Width: 174
Height: 280
Children:
Background@MAP_BG:
Width: PARENT_RIGHT
Height: 174
Background: dialog3
Label@TITLE:
Y: 172
Width: PARENT_RIGHT
Height: 25
Font: Bold
Align: Center
Text: Direct Connect
Label@DESCA:
Y: 190
Width: PARENT_RIGHT
Height: 25
Font: Tiny
Align: Center
Text: Enter the server IP and port in the
Label@DESCB:
Y: 203
Width: PARENT_RIGHT
Height: 25
Font: Tiny
Align: Center
Text: fields to the left, and then press Join.
Label@DESCC:
Y: 216
Width: PARENT_RIGHT
Height: 25
Font: Tiny
Align: Center
Text: The mod and game version will be
Label@DESCD:
Y: 229
Width: PARENT_RIGHT
Height: 25
Font: Tiny
Align: Center
Text: verified when connecting.
Button@JOIN_BUTTON:
Key: return
X: PARENT_RIGHT - WIDTH
Y: 284
Width: 174
X: PARENT_RIGHT - 430
Y: PARENT_BOTTOM - 45
Width: 160
Height: 25
Text: Join
Font: Bold
Key: return
Button@BACK_BUTTON:
X: PARENT_RIGHT - 180
Y: PARENT_BOTTOM - 45
Width: 160
Height: 25
Text: Cancel
Font: Bold
Key: escape

View File

@@ -20,25 +20,25 @@ Background@MULTIPLAYER_PANEL:
Text: Filter Games
Font: Bold
Button@REFRESH_BUTTON:
X: 183
X: 182
Y: PARENT_BOTTOM - HEIGHT - 20
Width: 100
Height: 25
Text: Refresh
Font: Bold
Button@BROWSER_TAB:
Button@DIRECTCONNECT_BUTTON:
X: 288
Y: PARENT_BOTTOM - HEIGHT - 20
Width: 105
Height: 31
Text: Browse
Width: 100
Height: 25
Text: Direct IP
Font: Bold
Button@DIRECTCONNECT_TAB:
Button@BROWSER_TAB:
X: 393
Y: PARENT_BOTTOM - HEIGHT - 20
Width: 105
Height: 31
Text: Direct IP
Text: Browse
Font: Bold
Button@CREATE_TAB:
X: 498