Move lobby event unbinding to Dispose.

This commit is contained in:
Paul Chote
2016-05-28 18:21:44 +01:00
parent fba509b363
commit ec2d883e9e

View File

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