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(); }