Pause the game when users navigate to the options menu in SP mode

This commit is contained in:
Scott_NZ
2013-03-17 21:14:49 +13:00
parent 86b55a6444
commit 2722fc5434
7 changed files with 37 additions and 15 deletions

View File

@@ -37,6 +37,11 @@ namespace OpenRA.Network
return Slots.FirstOrDefault(s => !s.Value.Closed && ClientInSlot(s.Key) == null).Key; return Slots.FirstOrDefault(s => !s.Value.Closed && ClientInSlot(s.Key) == null).Key;
} }
public bool IsSinglePlayer
{
get { return Clients.Count(c => c.Bot == null) == 1; }
}
public enum ClientState { NotReady, Ready, Disconnected = 1000 } public enum ClientState { NotReady, Ready, Disconnected = 1000 }
public class Client public class Client

View File

@@ -92,9 +92,17 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
} }
ingameRoot.IsVisible = () => false; ingameRoot.IsVisible = () => false;
if (world.LobbyInfo.IsSinglePlayer)
world.IssueOrder(Order.PauseGame());
Game.LoadWidget(world, "INGAME_MENU", Ui.Root, new WidgetArgs() Game.LoadWidget(world, "INGAME_MENU", Ui.Root, new WidgetArgs()
{ {
{ "onExit", () => ingameRoot.IsVisible = () => true } { "onExit", () =>
{
ingameRoot.IsVisible = () => true;
if (world.LobbyInfo.IsSinglePlayer)
world.IssueOrder(Order.PauseGame());
}
}
}); });
} }

View File

@@ -306,7 +306,7 @@ namespace OpenRA.Mods.RA.Missions
Game.MoveViewport(insertionLZ.Location.ToFloat2()); Game.MoveViewport(insertionLZ.Location.ToFloat2());
if (MissionUtils.IsSingleClient(world)) if (w.LobbyInfo.IsSinglePlayer)
Media.PlayFMVFullscreen(w, "ally1.vqa", () => Media.PlayFMVFullscreen(w, "ally1.vqa", () =>
Media.PlayFMVFullscreen(w, "landing.vqa", () => Media.PlayFMVFullscreen(w, "landing.vqa", () =>
{ {

View File

@@ -121,11 +121,6 @@ namespace OpenRA.Mods.RA.Missions
return world.Actors.FirstOrDefault(a => a.HasTrait<Cargo>() && a.Trait<Cargo>().Passengers.Contains(actor)); return world.Actors.FirstOrDefault(a => a.HasTrait<Cargo>() && a.Trait<Cargo>().Passengers.Contains(actor));
} }
public static bool IsSingleClient(World world)
{
return world.LobbyInfo.Clients.Count() == 1;
}
public static void PlayMissionMusic() public static void PlayMissionMusic()
{ {
if (!Rules.InstalledMusic.Any()) return; if (!Rules.InstalledMusic.Any()) return;

View File

@@ -160,7 +160,7 @@ namespace OpenRA.Mods.RA.Missions
Game.MoveViewport(startJeep.Location.ToFloat2()); Game.MoveViewport(startJeep.Location.ToFloat2());
if (MissionUtils.IsSingleClient(world)) if (w.LobbyInfo.IsSinglePlayer)
{ {
Media.PlayFMVFullscreen(w, "soviet1.vqa", () => Media.PlayFMVFullscreen(w, "soviet1.vqa", () =>
{ {

View File

@@ -30,7 +30,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var optionsBG = gameRoot.Get("INGAME_OPTIONS_BG"); var optionsBG = gameRoot.Get("INGAME_OPTIONS_BG");
r.Get<ButtonWidget>("INGAME_OPTIONS_BUTTON").OnClick = () => r.Get<ButtonWidget>("INGAME_OPTIONS_BUTTON").OnClick = () =>
{
optionsBG.Visible = !optionsBG.Visible; optionsBG.Visible = !optionsBG.Visible;
if (world.LobbyInfo.IsSinglePlayer)
world.IssueOrder(Order.PauseGame());
};
var cheatsButton = gameRoot.Get<ButtonWidget>("CHEATS_BUTTON"); var cheatsButton = gameRoot.Get<ButtonWidget>("CHEATS_BUTTON");
cheatsButton.OnClick = () => cheatsButton.OnClick = () =>
@@ -53,7 +57,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
optionsBG.Get<ButtonWidget>("SETTINGS").OnClick = () => Ui.OpenWindow("SETTINGS_MENU"); optionsBG.Get<ButtonWidget>("SETTINGS").OnClick = () => Ui.OpenWindow("SETTINGS_MENU");
optionsBG.Get<ButtonWidget>("MUSIC").OnClick = () => Ui.OpenWindow("MUSIC_MENU"); optionsBG.Get<ButtonWidget>("MUSIC").OnClick = () => Ui.OpenWindow("MUSIC_MENU");
optionsBG.Get<ButtonWidget>("RESUME").OnClick = () => optionsBG.Visible = false; optionsBG.Get<ButtonWidget>("RESUME").OnClick = () =>
{
optionsBG.Visible = false;
if (world.LobbyInfo.IsSinglePlayer)
world.IssueOrder(Order.PauseGame());
};
optionsBG.Get<ButtonWidget>("SURRENDER").OnClick = () => optionsBG.Get<ButtonWidget>("SURRENDER").OnClick = () =>
{ {

View File

@@ -30,7 +30,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var optionsBG = gameRoot.Get("INGAME_OPTIONS_BG"); var optionsBG = gameRoot.Get("INGAME_OPTIONS_BG");
r.Get<ButtonWidget>("INGAME_OPTIONS_BUTTON").OnClick = () => r.Get<ButtonWidget>("INGAME_OPTIONS_BUTTON").OnClick = () =>
{
optionsBG.Visible = !optionsBG.Visible; optionsBG.Visible = !optionsBG.Visible;
if (world.LobbyInfo.IsSinglePlayer)
world.IssueOrder(Order.PauseGame());
};
optionsBG.Get<ButtonWidget>("DISCONNECT").OnClick = () => optionsBG.Get<ButtonWidget>("DISCONNECT").OnClick = () =>
{ {
@@ -43,14 +47,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic
optionsBG.Get<ButtonWidget>("SETTINGS").OnClick = () => Ui.OpenWindow("SETTINGS_MENU"); optionsBG.Get<ButtonWidget>("SETTINGS").OnClick = () => Ui.OpenWindow("SETTINGS_MENU");
optionsBG.Get<ButtonWidget>("MUSIC").OnClick = () => Ui.OpenWindow("MUSIC_MENU"); optionsBG.Get<ButtonWidget>("MUSIC").OnClick = () => Ui.OpenWindow("MUSIC_MENU");
optionsBG.Get<ButtonWidget>("RESUME").OnClick = () => optionsBG.Visible = false; optionsBG.Get<ButtonWidget>("RESUME").OnClick = () =>
{
optionsBG.Visible = false;
if (world.LobbyInfo.IsSinglePlayer)
world.IssueOrder(Order.PauseGame());
};
optionsBG.Get<ButtonWidget>("SURRENDER").IsVisible = () => false; optionsBG.Get<ButtonWidget>("SURRENDER").IsVisible = () => false;
Ui.Root.Get<ButtonWidget>("INGAME_STATS_BUTTON").OnClick = () => Ui.Root.Get<ButtonWidget>("INGAME_STATS_BUTTON").OnClick = () => gameRoot.Get("OBSERVER_STATS").Visible ^= true;
{
var stats = gameRoot.Get("OBSERVER_STATS");
stats.Visible = !stats.Visible;
};
} }
void UnregisterEvents() void UnregisterEvents()