Spawn a server process from ingame

This commit is contained in:
Paul Chote
2010-03-09 19:57:34 +13:00
parent cddefb3919
commit 9d139d43a8
3 changed files with 50 additions and 9 deletions

View File

@@ -231,14 +231,30 @@ namespace OpenRA
public void DrawDialog(string text)
{
var w = renderer.BoldFont.Measure(text).X + 120;
var h = 100;
DrawDialog(text, null, _ => { }, null, _ => { });
}
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);
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
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
@@ -421,16 +437,16 @@ namespace OpenRA
DrawDialogBackground(r, "dialog");
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);
});
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",

View File

@@ -32,6 +32,7 @@ using OpenRA.Traits;
using Timer = OpenRA.Support.Timer;
using System.Runtime.InteropServices;
using System.IO;
using System.Diagnostics;
namespace OpenRA
{
@@ -54,6 +55,8 @@ namespace OpenRA
static string mapName;
internal static Session LobbyInfo = new Session();
static bool changePending;
internal static Process Server;
public static void LoadModPackages(Manifest manifest)
{
@@ -132,7 +135,7 @@ namespace OpenRA
throw new NotImplementedException();
else
{
orderManager = new OrderManager(new EchoConnection());
JoinLocal();
}
}
@@ -140,7 +143,25 @@ namespace OpenRA
{
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;
public static void ResetTimer()
@@ -420,6 +441,9 @@ namespace OpenRA
public static void Exit()
{
if (Server != null)
CloseServer();
quit = true;
}
}

View File

@@ -92,7 +92,8 @@ namespace OpenRA.Graphics
Game.chrome.DrawDialog("Connecting to {0}:{1}...".F( Game.Settings.NetworkHost, Game.Settings.NetworkPort ));
break;
case ConnectionState.NotConnected:
Game.chrome.DrawDialog("Connection failed.");
// Todo: Hook these up
Game.chrome.DrawDialog("Connection failed.", "Retry", _ => {}, "Cancel",_ => {});
break;
case ConnectionState.Connected:
Game.chrome.DrawLobby( world );