From 2722fc5434e59c3afaec013f0d22097d57b8ac1f Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Sun, 17 Mar 2013 21:14:49 +1300 Subject: [PATCH] Pause the game when users navigate to the options menu in SP mode --- OpenRA.Game/Network/Session.cs | 5 +++++ .../Widgets/Logic/CncIngameChromeLogic.cs | 10 +++++++++- OpenRA.Mods.RA/Missions/Allies01Script.cs | 2 +- OpenRA.Mods.RA/Missions/MissionUtils.cs | 5 ----- .../Missions/Soviet01ClassicScript.cs | 2 +- .../Widgets/Logic/IngameChromeLogic.cs | 11 ++++++++++- .../Widgets/Logic/IngameObserverChromeLogic.cs | 17 +++++++++++------ 7 files changed, 37 insertions(+), 15 deletions(-) diff --git a/OpenRA.Game/Network/Session.cs b/OpenRA.Game/Network/Session.cs index 7e63d9ba4a..c2e995b140 100644 --- a/OpenRA.Game/Network/Session.cs +++ b/OpenRA.Game/Network/Session.cs @@ -37,6 +37,11 @@ namespace OpenRA.Network 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 class Client diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs index 5a97160f96..b961612561 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs @@ -92,9 +92,17 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic } ingameRoot.IsVisible = () => false; + if (world.LobbyInfo.IsSinglePlayer) + world.IssueOrder(Order.PauseGame()); 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()); + } + } }); } diff --git a/OpenRA.Mods.RA/Missions/Allies01Script.cs b/OpenRA.Mods.RA/Missions/Allies01Script.cs index 46c574a5e6..03865672c4 100644 --- a/OpenRA.Mods.RA/Missions/Allies01Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies01Script.cs @@ -306,7 +306,7 @@ namespace OpenRA.Mods.RA.Missions Game.MoveViewport(insertionLZ.Location.ToFloat2()); - if (MissionUtils.IsSingleClient(world)) + if (w.LobbyInfo.IsSinglePlayer) Media.PlayFMVFullscreen(w, "ally1.vqa", () => Media.PlayFMVFullscreen(w, "landing.vqa", () => { diff --git a/OpenRA.Mods.RA/Missions/MissionUtils.cs b/OpenRA.Mods.RA/Missions/MissionUtils.cs index 7b8e743a49..e37df7ca6c 100644 --- a/OpenRA.Mods.RA/Missions/MissionUtils.cs +++ b/OpenRA.Mods.RA/Missions/MissionUtils.cs @@ -121,11 +121,6 @@ namespace OpenRA.Mods.RA.Missions return world.Actors.FirstOrDefault(a => a.HasTrait() && a.Trait().Passengers.Contains(actor)); } - public static bool IsSingleClient(World world) - { - return world.LobbyInfo.Clients.Count() == 1; - } - public static void PlayMissionMusic() { if (!Rules.InstalledMusic.Any()) return; diff --git a/OpenRA.Mods.RA/Missions/Soviet01ClassicScript.cs b/OpenRA.Mods.RA/Missions/Soviet01ClassicScript.cs index 53ae5305c6..284816840a 100644 --- a/OpenRA.Mods.RA/Missions/Soviet01ClassicScript.cs +++ b/OpenRA.Mods.RA/Missions/Soviet01ClassicScript.cs @@ -160,7 +160,7 @@ namespace OpenRA.Mods.RA.Missions Game.MoveViewport(startJeep.Location.ToFloat2()); - if (MissionUtils.IsSingleClient(world)) + if (w.LobbyInfo.IsSinglePlayer) { Media.PlayFMVFullscreen(w, "soviet1.vqa", () => { diff --git a/OpenRA.Mods.RA/Widgets/Logic/IngameChromeLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/IngameChromeLogic.cs index 4f1cd7a0c2..a7356190e2 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/IngameChromeLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/IngameChromeLogic.cs @@ -30,7 +30,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic var optionsBG = gameRoot.Get("INGAME_OPTIONS_BG"); r.Get("INGAME_OPTIONS_BUTTON").OnClick = () => + { optionsBG.Visible = !optionsBG.Visible; + if (world.LobbyInfo.IsSinglePlayer) + world.IssueOrder(Order.PauseGame()); + }; var cheatsButton = gameRoot.Get("CHEATS_BUTTON"); cheatsButton.OnClick = () => @@ -53,7 +57,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic optionsBG.Get("SETTINGS").OnClick = () => Ui.OpenWindow("SETTINGS_MENU"); optionsBG.Get("MUSIC").OnClick = () => Ui.OpenWindow("MUSIC_MENU"); - optionsBG.Get("RESUME").OnClick = () => optionsBG.Visible = false; + optionsBG.Get("RESUME").OnClick = () => + { + optionsBG.Visible = false; + if (world.LobbyInfo.IsSinglePlayer) + world.IssueOrder(Order.PauseGame()); + }; optionsBG.Get("SURRENDER").OnClick = () => { diff --git a/OpenRA.Mods.RA/Widgets/Logic/IngameObserverChromeLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/IngameObserverChromeLogic.cs index 888404372b..9d4c65d743 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/IngameObserverChromeLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/IngameObserverChromeLogic.cs @@ -30,7 +30,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic var optionsBG = gameRoot.Get("INGAME_OPTIONS_BG"); r.Get("INGAME_OPTIONS_BUTTON").OnClick = () => + { optionsBG.Visible = !optionsBG.Visible; + if (world.LobbyInfo.IsSinglePlayer) + world.IssueOrder(Order.PauseGame()); + }; optionsBG.Get("DISCONNECT").OnClick = () => { @@ -43,14 +47,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic optionsBG.Get("SETTINGS").OnClick = () => Ui.OpenWindow("SETTINGS_MENU"); optionsBG.Get("MUSIC").OnClick = () => Ui.OpenWindow("MUSIC_MENU"); - optionsBG.Get("RESUME").OnClick = () => optionsBG.Visible = false; + optionsBG.Get("RESUME").OnClick = () => + { + optionsBG.Visible = false; + if (world.LobbyInfo.IsSinglePlayer) + world.IssueOrder(Order.PauseGame()); + }; optionsBG.Get("SURRENDER").IsVisible = () => false; - Ui.Root.Get("INGAME_STATS_BUTTON").OnClick = () => - { - var stats = gameRoot.Get("OBSERVER_STATS"); - stats.Visible = !stats.Visible; - }; + Ui.Root.Get("INGAME_STATS_BUTTON").OnClick = () => gameRoot.Get("OBSERVER_STATS").Visible ^= true; } void UnregisterEvents()