From a288c5df1537b12d0408a3a9a9c07901da200fbb Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 23 May 2011 18:14:01 +1200 Subject: [PATCH] Use static ctors for static setup. --- .../Widgets/Logic/CncConnectionLogic.cs | 11 +++++----- .../Widgets/Logic/CncIngameChromeLogic.cs | 11 +++++----- .../Widgets/Logic/CncLobbyLogic.cs | 20 +++++++++---------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncConnectionLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncConnectionLogic.cs index f74b50ad5e..a05645e62f 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncConnectionLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncConnectionLogic.cs @@ -16,11 +16,15 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic { public class CncConnectingLogic { - static bool staticSetup; Action onConnect, onRetry, onAbort; string host; int port; + static CncConnectingLogic() + { + Game.ConnectionStateChanged += ConnectionStateChangedStub; + } + static void ConnectionStateChangedStub(OrderManager om) { var panel = Widget.RootWidget.GetWidget("CONNECTING_PANEL"); @@ -68,11 +72,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic this.onConnect = onConnect; this.onRetry = onRetry; this.onAbort = onAbort; - if (!staticSetup) - { - staticSetup = true; - Game.ConnectionStateChanged += ConnectionStateChangedStub; - } var panel = widget.GetWidget("CONNECTING_PANEL"); panel.GetWidget("ABORT_BUTTON").OnClick = () => { Widget.CloseWindow(); onAbort(); }; diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs index a02ca22234..c3c34d9538 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs @@ -19,8 +19,12 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic enum MenuType { None, Diplomacy, Cheats } MenuType menu = MenuType.None; - static bool staticSetup; Widget ingameRoot; + + static CncIngameChromeLogic() + { + Game.AddChatLine += AddChatLineStub; + } static void AddChatLineStub(Color c, string from, string text) { @@ -49,11 +53,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic .Fade(CncMenuPaletteEffect.EffectType.None); ingameRoot = widget.GetWidget("INGAME_ROOT"); - if (!staticSetup) - { - staticSetup = true; - Game.AddChatLine += AddChatLineStub; - } if (world.LocalPlayer != null) widget.GetWidget("PLAYER_WIDGETS").IsVisible = () => true; diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs index 5ecfa3a8a7..967c207179 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs @@ -37,7 +37,14 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic readonly Action onExit; readonly OrderManager orderManager; - static bool staticSetup; + static CncLobbyLogic() + { + Game.LobbyInfoChanged += LobbyInfoChangedStub; + Game.BeforeGameStart += BeforeGameStartStub; + Game.AddChatLine += AddChatLineStub; + Game.ConnectionStateChanged += ConnectionStateChangedStub; + } + public static CncLobbyLogic GetHandler() { var panel = Widget.RootWidget.GetWidget("SERVER_LOBBY"); @@ -127,16 +134,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic this.orderManager = orderManager; this.OnGameStart = () => { Widget.CloseWindow(); onStart(); }; this.onExit = onExit; - - if (!staticSetup) - { - staticSetup = true; - Game.LobbyInfoChanged += LobbyInfoChangedStub; - Game.BeforeGameStart += BeforeGameStartStub; - Game.AddChatLine += AddChatLineStub; - Game.ConnectionStateChanged += ConnectionStateChangedStub; - } - + UpdateCurrentMap(); PlayerPalettePreview = world.WorldActor.Trait(); PlayerPalettePreview.Ramp = Game.Settings.Player.ColorRamp;