Spawn a server process from ingame
This commit is contained in:
@@ -231,14 +231,30 @@ namespace OpenRA
|
|||||||
|
|
||||||
public void DrawDialog(string text)
|
public void DrawDialog(string text)
|
||||||
{
|
{
|
||||||
var w = renderer.BoldFont.Measure(text).X + 120;
|
DrawDialog(text, null, _ => { }, null, _ => { });
|
||||||
var h = 100;
|
}
|
||||||
|
|
||||||
|
public void DrawDialog(string text, string button1String, Action<bool> button1Action, string button2String, Action<bool> button2Action)
|
||||||
|
{
|
||||||
|
var w = Math.Max(renderer.BoldFont.Measure(text).X + 120, 400);
|
||||||
|
var h = (button1String == null) ? 100 : 140;
|
||||||
var r = new Rectangle((Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h);
|
var r = new Rectangle((Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h);
|
||||||
DrawDialogBackground(r, "dialog");
|
DrawDialogBackground(r, "dialog");
|
||||||
DrawCentered(text, new int2(Game.viewport.Width / 2, Game.viewport.Height / 2 - 8), Color.White);
|
DrawCentered(text, new int2(Game.viewport.Width / 2, Game.viewport.Height / 2 - ((button1String == null) ? 8 : 28)), Color.White);
|
||||||
|
|
||||||
// don't allow clicks through the dialog
|
// don't allow clicks through the dialog
|
||||||
AddButton(r, _ => { });
|
AddButton(r, _ => { });
|
||||||
|
|
||||||
|
if (button1String != null)
|
||||||
|
{
|
||||||
|
AddUiButton(new int2(r.Right - 300, r.Bottom - 40),button1String, button1Action);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button2String != null)
|
||||||
|
{
|
||||||
|
AddUiButton(new int2(r.Right - 100, r.Bottom - 40),button2String, button2Action);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MapInfo
|
class MapInfo
|
||||||
@@ -421,16 +437,16 @@ namespace OpenRA
|
|||||||
DrawDialogBackground(r, "dialog");
|
DrawDialogBackground(r, "dialog");
|
||||||
DrawCentered("OpenRA Main Menu", new int2(r.Left + w / 2, r.Top + 20), Color.White);
|
DrawCentered("OpenRA Main Menu", new int2(r.Left + w / 2, r.Top + 20), Color.White);
|
||||||
|
|
||||||
AddUiButton(new int2(r.Left + w/2, r.Top + 70), "Join Server",
|
AddUiButton(new int2(r.Left + w/2, r.Top + 70), "Join Game",
|
||||||
_ =>
|
_ =>
|
||||||
{
|
{
|
||||||
Game.JoinServer("localhost", 1234);
|
Game.JoinServer("localhost", 1234);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddUiButton(new int2(r.Left + w/2, r.Top + 105), "Create Server",
|
AddUiButton(new int2(r.Left + w/2, r.Top + 105), "Create Game",
|
||||||
_ =>
|
_ =>
|
||||||
{
|
{
|
||||||
|
Game.CreateServer();
|
||||||
});
|
});
|
||||||
|
|
||||||
AddUiButton(new int2(r.Left + w/2, r.Top + 140), "Quit",
|
AddUiButton(new int2(r.Left + w/2, r.Top + 140), "Quit",
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ using OpenRA.Traits;
|
|||||||
using Timer = OpenRA.Support.Timer;
|
using Timer = OpenRA.Support.Timer;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
@@ -54,6 +55,8 @@ namespace OpenRA
|
|||||||
static string mapName;
|
static string mapName;
|
||||||
internal static Session LobbyInfo = new Session();
|
internal static Session LobbyInfo = new Session();
|
||||||
static bool changePending;
|
static bool changePending;
|
||||||
|
|
||||||
|
internal static Process Server;
|
||||||
|
|
||||||
public static void LoadModPackages(Manifest manifest)
|
public static void LoadModPackages(Manifest manifest)
|
||||||
{
|
{
|
||||||
@@ -132,7 +135,7 @@ namespace OpenRA
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
orderManager = new OrderManager(new EchoConnection());
|
JoinLocal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +143,25 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
orderManager = new OrderManager(new NetworkConnection( host, port ), "replay.rep");
|
orderManager = new OrderManager(new NetworkConnection( host, port ), "replay.rep");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void JoinLocal()
|
||||||
|
{
|
||||||
|
orderManager = new OrderManager(new EchoConnection());
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void CreateServer()
|
||||||
|
{
|
||||||
|
Server = new Process();
|
||||||
|
Server.StartInfo.FileName = "OpenRA.Server.exe";
|
||||||
|
Server.StartInfo.Arguments = string.Join(" ",Game.LobbyInfo.GlobalSettings.Mods);
|
||||||
|
Server.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void CloseServer()
|
||||||
|
{
|
||||||
|
Server.Kill();
|
||||||
|
}
|
||||||
|
|
||||||
static int lastTime = Environment.TickCount;
|
static int lastTime = Environment.TickCount;
|
||||||
|
|
||||||
public static void ResetTimer()
|
public static void ResetTimer()
|
||||||
@@ -420,6 +441,9 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static void Exit()
|
public static void Exit()
|
||||||
{
|
{
|
||||||
|
if (Server != null)
|
||||||
|
CloseServer();
|
||||||
|
|
||||||
quit = true;
|
quit = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,8 @@ namespace OpenRA.Graphics
|
|||||||
Game.chrome.DrawDialog("Connecting to {0}:{1}...".F( Game.Settings.NetworkHost, Game.Settings.NetworkPort ));
|
Game.chrome.DrawDialog("Connecting to {0}:{1}...".F( Game.Settings.NetworkHost, Game.Settings.NetworkPort ));
|
||||||
break;
|
break;
|
||||||
case ConnectionState.NotConnected:
|
case ConnectionState.NotConnected:
|
||||||
Game.chrome.DrawDialog("Connection failed.");
|
// Todo: Hook these up
|
||||||
|
Game.chrome.DrawDialog("Connection failed.", "Retry", _ => {}, "Cancel",_ => {});
|
||||||
break;
|
break;
|
||||||
case ConnectionState.Connected:
|
case ConnectionState.Connected:
|
||||||
Game.chrome.DrawLobby( world );
|
Game.chrome.DrawLobby( world );
|
||||||
|
|||||||
Reference in New Issue
Block a user