Changes to allow restarting of skirmish match

This commit is contained in:
Whinis
2016-01-16 17:09:30 -05:00
parent 1df728adad
commit f2260174f0
4 changed files with 52 additions and 16 deletions

View File

@@ -179,8 +179,11 @@ namespace OpenRA
{ {
var replay = OrderManager.Connection as ReplayConnection; var replay = OrderManager.Connection as ReplayConnection;
var replayName = replay != null ? replay.Filename : null; var replayName = replay != null ? replay.Filename : null;
var uid = OrderManager.World.Map.Uid; var lobbyInfo = OrderManager.LobbyInfo;
var globalSettings = OrderManager.LobbyInfo.GlobalSettings; var orders = new[] {
Order.Command("sync_lobby {0}".F(lobbyInfo.Serialize())),
Order.Command("startgame")
};
// Disconnect from the current game // Disconnect from the current game
Disconnect(); Disconnect();
@@ -190,10 +193,10 @@ namespace OpenRA
if (replay != null) if (replay != null)
JoinReplay(replayName); JoinReplay(replayName);
else else
StartMission(uid, globalSettings.GameSpeedType, globalSettings.Difficulty); CreateAndStartLocalServer(lobbyInfo.GlobalSettings.Map, orders);
} }
public static void StartMission(string mapUID, string gameSpeed, string difficulty, Action onStart = null) public static void CreateAndStartLocalServer(string mapUID, IEnumerable<Order> setupOrders, Action onStart = null)
{ {
OrderManager om = null; OrderManager om = null;
@@ -201,9 +204,9 @@ namespace OpenRA
lobbyReady = () => lobbyReady = () =>
{ {
LobbyInfoChanged -= lobbyReady; LobbyInfoChanged -= lobbyReady;
om.IssueOrder(Order.Command("gamespeed {0}".F(gameSpeed))); foreach (var o in setupOrders)
om.IssueOrder(Order.Command("difficulty {0}".F(difficulty))); om.IssueOrder(o);
om.IssueOrder(Order.Command("state {0}".F(Session.ClientState.Ready)));
if (onStart != null) if (onStart != null)
onStart(); onStart();
}; };

View File

@@ -889,6 +889,28 @@ namespace OpenRA.Mods.Common.Server
return true; return true;
} }
},
{ "sync_lobby",
s =>
{
if (!client.IsAdmin)
{
server.SendOrderTo(conn, "Message", "Only the host can set lobby info");
return true;
}
var lobbyInfo = Session.Deserialize(s);
if (lobbyInfo == null)
{
server.SendOrderTo(conn, "Message", "Invalid Lobby Info Sent");
return true;
}
server.LobbyInfo = lobbyInfo;
server.SyncLobbyInfo();
return true;
}
} }
}; };

View File

@@ -90,14 +90,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
hideMenu = true; hideMenu = true;
if (world.LocalPlayer == null || (world.LocalPlayer.WinState != WinState.Won && if (world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Won)
(!world.IsGameOver || world.Map.Visibility == MapVisibility.MissionSelector)))
{ {
Action restartAction = null; Action restartAction = null;
if (world.IsReplay || world.Map.Visibility == MapVisibility.MissionSelector) var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
var exitDelay = iop != null ? iop.ExitDelay : 0;
if (world.LobbyInfo.IsSinglePlayer)
{ {
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
var exitDelay = iop != null ? iop.ExitDelay : 0;
restartAction = () => restartAction = () =>
{ {
Ui.CloseWindow(); Ui.CloseWindow();
@@ -145,7 +145,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}; };
var surrenderButton = menu.Get<ButtonWidget>("SURRENDER"); var surrenderButton = menu.Get<ButtonWidget>("SURRENDER");
surrenderButton.IsVisible = () => world.Type == WorldType.Regular; surrenderButton.IsVisible = () => world.Type == WorldType.Regular;
surrenderButton.IsDisabled = () => (world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Undefined) || hasError; surrenderButton.IsDisabled = () =>
world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Undefined ||
world.Map.Visibility.HasFlag(MapVisibility.MissionSelector) || hasError;
surrenderButton.OnClick = () => surrenderButton.OnClick = () =>
{ {
hideMenu = true; hideMenu = true;
@@ -153,7 +155,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
title: "Surrender", title: "Surrender",
text: "Are you sure you want to surrender?", text: "Are you sure you want to surrender?",
onConfirm: onSurrender, onConfirm: onSurrender,
onCancel: showMenu); onCancel: showMenu,
confirmText: "Surrender",
cancelText: "Stay");
}; };
var saveMapButton = menu.Get<ButtonWidget>("SAVE_MAP"); var saveMapButton = menu.Get<ButtonWidget>("SAVE_MAP");

View File

@@ -14,6 +14,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Network;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Widgets; using OpenRA.Widgets;
@@ -301,6 +302,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return; return;
var gameStartVideo = selectedMap.Videos.GameStart; var gameStartVideo = selectedMap.Videos.GameStart;
var orders = new[] {
Order.Command("gamespeed {0}".F(gameSpeed)),
Order.Command("difficulty {0}".F(difficulty)),
Order.Command("state {0}".F(Session.ClientState.Ready))
};
if (gameStartVideo != null && Game.ModData.ModFiles.Exists(gameStartVideo)) if (gameStartVideo != null && Game.ModData.ModFiles.Exists(gameStartVideo))
{ {
var fsPlayer = fullscreenVideoPlayer.Get<VqaPlayerWidget>("PLAYER"); var fsPlayer = fullscreenVideoPlayer.Get<VqaPlayerWidget>("PLAYER");
@@ -308,11 +315,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
PlayVideo(fsPlayer, gameStartVideo, PlayingVideo.GameStart, () => PlayVideo(fsPlayer, gameStartVideo, PlayingVideo.GameStart, () =>
{ {
StopVideo(fsPlayer); StopVideo(fsPlayer);
Game.StartMission(selectedMapPreview.Uid, gameSpeed, difficulty, onStart); Game.CreateAndStartLocalServer(selectedMapPreview.Uid, orders, onStart);
}); });
} }
else else
Game.StartMission(selectedMapPreview.Uid, gameSpeed, difficulty, onStart); Game.CreateAndStartLocalServer(selectedMapPreview.Uid, orders, onStart);
} }
class DropDownOption class DropDownOption