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/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index 14b6ead95e..3ed3a458c4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (om.Connection.ConnectionState == ConnectionState.NotConnected) { // Show connection failed dialog - CloseWindow(); + Ui.CloseWindow(); Action onConnect = () => { @@ -100,17 +100,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic } } - void CloseWindow() - { - orderManager.AddChatLine -= AddChatLine; - Game.LobbyInfoChanged -= UpdateCurrentMap; - Game.LobbyInfoChanged -= UpdatePlayerList; - Game.BeforeGameStart -= OnGameStart; - Game.ConnectionStateChanged -= ConnectionStateChanged; - - Ui.CloseWindow(); - } - [ObjectCreator.UseCtor] internal LobbyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, OrderManager orderManager, Action onExit, Action onStart, bool skirmishMode) @@ -618,7 +607,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } var disconnectButton = lobby.Get("DISCONNECT_BUTTON"); - disconnectButton.OnClick = () => { CloseWindow(); onExit(); }; + disconnectButton.OnClick = () => { Ui.CloseWindow(); onExit(); }; if (skirmishMode) disconnectButton.Text = "Back"; @@ -716,6 +705,22 @@ namespace OpenRA.Mods.Common.Widgets.Logic addBotOnMapLoad = true; } + bool disposed; + protected override void Dispose(bool disposing) + { + if (disposing && !disposed) + { + disposed = true; + orderManager.AddChatLine -= AddChatLine; + Game.LobbyInfoChanged -= UpdateCurrentMap; + Game.LobbyInfoChanged -= UpdatePlayerList; + Game.BeforeGameStart -= OnGameStart; + Game.ConnectionStateChanged -= ConnectionStateChanged; + } + + base.Dispose(disposing); + } + public override void Tick() { var newMessages = Game.GlobalChat.History.Count(m => m.Type == ChatMessageType.Message); @@ -985,7 +990,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic void OnGameStart() { - CloseWindow(); + Ui.CloseWindow(); onStart(); } 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 diff --git a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs index c3edd02114..8998ad6b55 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs @@ -47,6 +47,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic this.modData = modData; this.onStart = onStart; + Game.BeforeGameStart += OnGameStart; playerList = panel.Get("PLAYER_LIST"); playerHeader = playerList.Get("HEADER"); @@ -668,16 +669,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic void WatchReplay() { - Action startReplay = () => + if (selectedReplay != null && ReplayUtils.PromptConfirmReplayCompatibility(selectedReplay)) { cancelLoadingReplays = true; Game.JoinReplay(selectedReplay.FilePath); - Ui.CloseWindow(); - onStart(); - }; - - if (selectedReplay != null && ReplayUtils.PromptConfirmReplayCompatibility(selectedReplay)) - startReplay(); + } } void AddReplay(ReplayMetadata replay, ScrollItemWidget template) @@ -701,6 +697,24 @@ namespace OpenRA.Mods.Common.Widgets.Logic replayList.AddChild(item); } + void OnGameStart() + { + Ui.CloseWindow(); + onStart(); + } + + bool disposed; + protected override void Dispose(bool disposing) + { + if (disposing && !disposed) + { + disposed = true; + Game.BeforeGameStart -= OnGameStart; + } + + base.Dispose(disposing); + } + class ReplayState { public bool Visible;