From 900335b08ca5e5aadc44278a4af9af5ea51e2c16 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 11 Jul 2010 00:34:54 +1200 Subject: [PATCH] Direct Connect dialog & saves last server --- OpenRA.Game/GameRules/UserSettings.cs | 20 ++++---- .../Delegates/ServerBrowserDelegate.cs | 47 +++++++++++++----- OpenRA.Game/Widgets/TextFieldWidget.cs | 1 - mods/cnc/menus.yaml | 49 +++++++++++++++++++ 4 files changed, 93 insertions(+), 24 deletions(-) diff --git a/OpenRA.Game/GameRules/UserSettings.cs b/OpenRA.Game/GameRules/UserSettings.cs index 6ff7ce9a33..3c07436099 100644 --- a/OpenRA.Game/GameRules/UserSettings.cs +++ b/OpenRA.Game/GameRules/UserSettings.cs @@ -44,20 +44,20 @@ namespace OpenRA.GameRules public bool MusicPlayer = true; // Internal game settings - public readonly int Timestep = 40; - public readonly int SheetSize = 2048; + public int Timestep = 40; + public int SheetSize = 2048; // External game settings - public readonly string NetworkHost = null; - public readonly int NetworkPort = 0; - public readonly string Replay = null; + public string LastServer = "localhost:1234"; + public string Replay = null; public string PlayerName = null; - public readonly string[] InitialMods = { "ra" }; + public string[] InitialMods = { "ra" }; - public readonly int ListenPort = 1234; - public readonly int ExternalPort = 1234; - public readonly bool InternetServer = true; - public readonly string MasterServer = "http://open-ra.org/master/"; + // Server settings + public int ListenPort = 1234; + public int ExternalPort = 1234; + public bool InternetServer = true; + public string MasterServer = "http://open-ra.org/master/"; string SettingsFile; UserSettings defaults; diff --git a/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs b/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs index 77a008a8a5..4574708c4a 100644 --- a/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs @@ -33,12 +33,12 @@ namespace OpenRA.Widgets.Delegates public ServerBrowserDelegate() { - var r = Chrome.rootWidget; - + var r = Chrome.rootWidget; + var bg = r.GetWidget("JOINSERVER_BG"); + var dc = r.GetWidget("DIRECTCONNECT_BG"); + MasterServerQuery.OnComplete += games => { - var bg = r.GetWidget("JOINSERVER_BG"); - if (games == null) { r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true; @@ -76,6 +76,10 @@ namespace OpenRA.Widgets.Delegates OnMouseUp = nmi => { r.GetWidget("JOINSERVER_BG").Visible = false; + + Game.Settings.LastServer = g.Address; + Game.Settings.Save(); + Game.JoinServer(g.Address.Split(':')[0], int.Parse(g.Address.Split(':')[1])); Game.SetGameId(g.Id); return true; @@ -92,7 +96,7 @@ namespace OpenRA.Widgets.Delegates r.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp = mi => { - var bg = r.OpenWindow("JOINSERVER_BG"); + r.OpenWindow("JOINSERVER_BG"); r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true; r.GetWidget("JOINSERVER_PROGRESS_TITLE").Text = "Fetching game list..."; @@ -105,10 +109,8 @@ namespace OpenRA.Widgets.Delegates return true; }; - r.GetWidget("JOINSERVER_BUTTON_REFRESH").OnMouseUp = mi => + bg.GetWidget("JOINSERVER_BUTTON_REFRESH").OnMouseUp = mi => { - var bg = r.GetWidget("JOINSERVER_BG"); - r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true; r.GetWidget("JOINSERVER_PROGRESS_TITLE").Text = "Fetching game list..."; @@ -120,20 +122,39 @@ namespace OpenRA.Widgets.Delegates return true; }; - r.GetWidget("JOINSERVER_BUTTON_CANCEL").OnMouseUp = mi => + bg.GetWidget("JOINSERVER_BUTTON_CANCEL").OnMouseUp = mi => { r.CloseWindow(); return true; }; - r.GetWidget("JOINSERVER_BUTTON_DIRECTCONNECT").OnMouseUp = mi => - { /* rude hack. Should prompt the user once we have textfield widgets */ + bg.GetWidget("JOINSERVER_BUTTON_DIRECTCONNECT").OnMouseUp = mi => { r.CloseWindow(); - if (Game.Settings.NetworkHost != null) - Game.JoinServer(Game.Settings.NetworkHost, Game.Settings.NetworkPort); + dc.GetWidget("SERVER_ADDRESS").Text = Game.Settings.LastServer; + r.OpenWindow("DIRECTCONNECT_BG"); return true; }; + + dc.GetWidget("BUTTON_START").OnMouseUp = mi => { + + var address = dc.GetWidget("SERVER_ADDRESS").Text; + var cpts = address.Split(':').ToArray(); + if (cpts.Length != 2) + return true; + + Game.Settings.LastServer = address; + Game.Settings.Save(); + + r.CloseWindow(); + Game.JoinServer(cpts[0], int.Parse(cpts[1])); + return true; + }; + + r.GetWidget("BUTTON_CANCEL").OnMouseUp = mi => { + r.CloseWindow(); + return r.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp(mi); + }; } } } diff --git a/OpenRA.Game/Widgets/TextFieldWidget.cs b/OpenRA.Game/Widgets/TextFieldWidget.cs index 4ca5a403e2..6e21a33cff 100644 --- a/OpenRA.Game/Widgets/TextFieldWidget.cs +++ b/OpenRA.Game/Widgets/TextFieldWidget.cs @@ -108,7 +108,6 @@ namespace OpenRA.Widgets } else if (!char.IsControl(c)) { - Console.WriteLine("{0} {1}",MaxLength, Text.Length); if (MaxLength > 0 && Text.Length >= MaxLength) return; diff --git a/mods/cnc/menus.yaml b/mods/cnc/menus.yaml index 371d8812d2..e356d63576 100644 --- a/mods/cnc/menus.yaml +++ b/mods/cnc/menus.yaml @@ -249,6 +249,55 @@ Container: Height:25 Text:Cancel Bold:True + Background@DIRECTCONNECT_BG: + Id:DIRECTCONNECT_BG + Delegate:ServerBrowserDelegate + X:(WINDOW_RIGHT - WIDTH)/2 + Y:(WINDOW_BOTTOM - HEIGHT)/2 + Width:400 + Height:155 + Visible:false + Children: + Label@DIRECTCONNECT_LABEL_TITLE: + Id:DIRECTCONNECT_LABEL_TITLE + X:0 + Y:20 + Width:400 + Height:25 + Text:Direct Connect + Align:Center + Bold:True + Label@ADDRESS_LABEL: + Id:ADDRESS_LABEL + X:50 + Y:59 + Width:95 + Height:25 + Align:Right + Text:Server Address: + TextField@SERVER_ADDRESS: + Id:SERVER_ADDRESS + X:150 + Y:60 + Width:200 + MaxLength:50 + Height:25 + Button@BUTTON_START: + Id:BUTTON_START + X:130 + Y:PARENT_BOTTOM - 45 + Width:120 + Height:25 + Text:Join + Bold:True + Button@BUTTON_CANCEL: + Id:BUTTON_CANCEL + X:260 + Y:PARENT_BOTTOM - 45 + Width:120 + Height:25 + Text:Cancel + Bold:True Background@CONNECTION_FAILED_BG: Id:CONNECTION_FAILED_BG Delegate:ConnectionDialogsDelegate