diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index e6b3c196a6..0e669f5c74 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -197,7 +197,7 @@ namespace OpenRA CreateAndStartLocalServer(lobbyInfo.GlobalSettings.Map, orders); } - public static void CreateAndStartLocalServer(string mapUID, IEnumerable setupOrders, Action onStart = null) + public static void CreateAndStartLocalServer(string mapUID, IEnumerable setupOrders) { OrderManager om = null; @@ -207,10 +207,8 @@ namespace OpenRA LobbyInfoChanged -= lobbyReady; foreach (var o in setupOrders) om.IssueOrder(o); - - if (onStart != null) - onStart(); }; + LobbyInfoChanged += lobbyReady; om = JoinServer(IPAddress.Loopback.ToString(), CreateLocalServer(mapUID), ""); diff --git a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs index f084c991a8..4acc95caa6 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs @@ -55,6 +55,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { this.modData = modData; this.onStart = onStart; + Game.BeforeGameStart += OnGameStart; missionList = widget.Get("MISSION_LIST"); @@ -151,6 +152,24 @@ namespace OpenRA.Mods.Common.Widgets.Logic }; } + void OnGameStart() + { + Ui.CloseWindow(); + onStart(); + } + + bool disposed; + protected override void Dispose(bool disposing) + { + if (disposing && !disposed) + { + disposed = true; + Game.BeforeGameStart -= OnGameStart; + } + + base.Dispose(disposing); + } + void CreateMissionGroup(string title, IEnumerable previews) { var header = ScrollItemWidget.Setup(headerTemplate, () => true, () => { }); @@ -344,11 +363,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic PlayVideo(fsPlayer, missionData.StartVideo, PlayingVideo.GameStart, () => { StopVideo(fsPlayer); - Game.CreateAndStartLocalServer(selectedMap.Uid, orders, onStart); + Game.CreateAndStartLocalServer(selectedMap.Uid, orders); }); } else - Game.CreateAndStartLocalServer(selectedMap.Uid, orders, onStart); + Game.CreateAndStartLocalServer(selectedMap.Uid, orders); } class DropDownOption