diff --git a/OpenRA.Mods.Cnc/Widgets/CncConnectionLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncConnectionLogic.cs index 8729d7c09d..b53ccb6713 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncConnectionLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncConnectionLogic.cs @@ -76,7 +76,7 @@ namespace OpenRA.Mods.Cnc.Widgets } var panel = widget.GetWidget("CONNECTING_PANEL"); - panel.GetWidget("ABORT_BUTTON").OnClick = onAbort; + panel.GetWidget("ABORT_BUTTON").OnClick = () => { Widget.CloseWindow(); onAbort(); }; widget.GetWidget("CONNECTING_DESC").GetText = () => "Connecting to {0}:{1}...".F(host, port); @@ -91,7 +91,7 @@ namespace OpenRA.Mods.Cnc.Widgets { "port", port }, { "onConnect", onConnect }, { "onAbort", onAbort }, - { "onRetry", new Action(() => { Widget.CloseWindow(); Connect(host, port, onConnect, onAbort); }) } + { "onRetry", new Action(() => Connect(host, port, onConnect, onAbort)) } }); } } @@ -106,8 +106,8 @@ namespace OpenRA.Mods.Cnc.Widgets [ObjectCreator.Param] Action onAbort) { var panel = widget.GetWidget("CONNECTIONFAILED_PANEL"); - panel.GetWidget("ABORT_BUTTON").OnClick = onAbort; - panel.GetWidget("RETRY_BUTTON").OnClick = onRetry; + panel.GetWidget("ABORT_BUTTON").OnClick = () => { Widget.CloseWindow(); onAbort(); }; + panel.GetWidget("RETRY_BUTTON").OnClick = () => { Widget.CloseWindow(); onRetry(); }; widget.GetWidget("CONNECTING_DESC").GetText = () => "Could not connect to {0}:{1}".F(host, port); diff --git a/OpenRA.Mods.Cnc/Widgets/CncIngameChromeLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncIngameChromeLogic.cs index 9ddea0750a..d9e001655a 100755 --- a/OpenRA.Mods.Cnc/Widgets/CncIngameChromeLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncIngameChromeLogic.cs @@ -116,7 +116,7 @@ namespace OpenRA.Mods.Cnc.Widgets hideButtons = true; Widget.OpenWindow("MUSIC_PANEL", new Dictionary() { - { "onExit", new Action(() => { hideButtons = false; Widget.CloseWindow(); }) }, + { "onExit", new Action(() => hideButtons = false) }, }); }; diff --git a/OpenRA.Mods.Cnc/Widgets/CncInstallLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncInstallLogic.cs index aeb45e82a1..e76c76facf 100755 --- a/OpenRA.Mods.Cnc/Widgets/CncInstallLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncInstallLogic.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Cnc.Widgets var panel = widget.GetWidget("INSTALL_PANEL"); var args = new Dictionary() { - { "continueLoading", continueLoading }, + { "continueLoading", new Action(() => { Widget.CloseWindow(); continueLoading(); }) }, { "installData", installData } }; @@ -48,7 +48,8 @@ namespace OpenRA.Mods.Cnc.Widgets { Widget.OpenWindow("MODS_PANEL", new Dictionary() { - { "onExit", new Action(Widget.CloseWindow) }, + { "onExit", new Action(() => {}) }, + // Close this panel { "onSwitch", new Action(Widget.CloseWindow) }, }); }; @@ -137,8 +138,7 @@ namespace OpenRA.Mods.Cnc.Widgets Game.RunAfterTick(() => { - Widget.CloseWindow(); // Progress panel - Widget.CloseWindow(); // Install choice panel + Widget.CloseWindow(); continueLoading(); }); }) { IsBackground = true }; @@ -237,8 +237,7 @@ namespace OpenRA.Mods.Cnc.Widgets { Game.RunAfterTick(() => { - Widget.CloseWindow(); // Progress panel - Widget.CloseWindow(); // Install choice panel + Widget.CloseWindow(); continueLoading(); }); } diff --git a/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs index d8b186356d..47145a3b88 100755 --- a/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs @@ -126,7 +126,7 @@ namespace OpenRA.Mods.Cnc.Widgets { this.orderManager = orderManager; this.worldRenderer = worldRenderer; - this.OnGameStart = onStart; + this.OnGameStart = () => { Widget.CloseWindow(); onStart(); }; this.onExit = onExit; if (!staticSetup) @@ -195,20 +195,19 @@ namespace OpenRA.Mods.Cnc.Widgets orderManager.IssueOrder(Order.Command("map " + m.Uid)); Game.Settings.Server.LastMap = m.Uid; Game.Settings.Save(); - Widget.CloseWindow(); }); Widget.OpenWindow( "MAPCHOOSER_PANEL", new Dictionary { { "initialMap", Map.Uid }, - { "onExit", new Action(() => Widget.CloseWindow()) }, + { "onExit", new Action(() => {}) }, { "onSelect", onSelect } }); }; mapButton.IsVisible = () => mapButton.Visible && Game.IsHost; var disconnectButton = lobby.GetWidget("DISCONNECT_BUTTON"); - disconnectButton.OnClick = onExit; + disconnectButton.OnClick = () => { Widget.CloseWindow(); onExit(); }; var gameStarting = false; var lockTeamsCheckbox = lobby.GetWidget("LOCKTEAMS_CHECKBOX"); diff --git a/OpenRA.Mods.Cnc/Widgets/CncMapChooserLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncMapChooserLogic.cs index 083fabb678..8da2891f4d 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncMapChooserLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncMapChooserLogic.cs @@ -45,8 +45,8 @@ namespace OpenRA.Mods.Cnc.Widgets panel.GetWidget("CURMAP_THEATER").GetText = () => Rules.TileSets[map.Tileset].Name; panel.GetWidget("CURMAP_PLAYERS").GetText = () => map.PlayerCount.ToString(); - panel.GetWidget("BUTTON_OK").OnClick = () => onSelect(map); - panel.GetWidget("BUTTON_CANCEL").OnClick = onExit; + panel.GetWidget("BUTTON_OK").OnClick = () => { Widget.CloseWindow(); onSelect(map); }; + panel.GetWidget("BUTTON_CANCEL").OnClick = () => { Widget.CloseWindow(); onExit(); }; panel.GetWidget("BUTTON_INSTALL").IsDisabled = () => true; panel.GetWidget("BUTTON_INSTALL").OnClick = () => InstallMap(); diff --git a/OpenRA.Mods.Cnc/Widgets/CncMenuLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncMenuLogic.cs index 2d1d0d1a07..c13092e223 100755 --- a/OpenRA.Mods.Cnc/Widgets/CncMenuLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncMenuLogic.cs @@ -52,7 +52,7 @@ namespace OpenRA.Mods.Cnc.Widgets Menu = MenuType.None; Widget.OpenWindow("REPLAYBROWSER_PANEL", new Dictionary() { - { "onExit", new Action(() => { Menu = MenuType.Main; Widget.CloseWindow(); }) }, + { "onExit", new Action(() => Menu = MenuType.Main) }, { "onStart", new Action(RemoveShellmapUI) } }); }; @@ -70,7 +70,7 @@ namespace OpenRA.Mods.Cnc.Widgets Menu = MenuType.None; Widget.OpenWindow("SERVERBROWSER_PANEL", new Dictionary() { - { "onExit", new Action(() => ReturnToMenu(MenuType.Multiplayer)) }, + { "onExit", new Action(() => Menu = MenuType.Multiplayer) }, { "openLobby", new Action(() => OpenLobbyPanel(MenuType.Multiplayer)) } }); }; @@ -80,7 +80,7 @@ namespace OpenRA.Mods.Cnc.Widgets Menu = MenuType.None; Widget.OpenWindow("CREATESERVER_PANEL", new Dictionary() { - { "onExit", new Action(() => ReturnToMenu(MenuType.Multiplayer)) }, + { "onExit", new Action(() => Menu = MenuType.Multiplayer) }, { "openLobby", new Action(() => OpenLobbyPanel(MenuType.Multiplayer)) } }); }; @@ -90,7 +90,7 @@ namespace OpenRA.Mods.Cnc.Widgets Menu = MenuType.None; Widget.OpenWindow("DIRECTCONNECT_PANEL", new Dictionary() { - { "onExit", new Action(() => ReturnToMenu(MenuType.Multiplayer)) }, + { "onExit", new Action(() => Menu = MenuType.Multiplayer) }, { "openLobby", new Action(() => OpenLobbyPanel(MenuType.Multiplayer)) } }); }; @@ -104,7 +104,7 @@ namespace OpenRA.Mods.Cnc.Widgets Menu = MenuType.None; Widget.OpenWindow("MODS_PANEL", new Dictionary() { - { "onExit", new Action(() => ReturnToMenu(MenuType.Settings)) }, + { "onExit", new Action(() => Menu = MenuType.Settings) }, { "onSwitch", new Action(RemoveShellmapUI) } }); }; @@ -114,7 +114,7 @@ namespace OpenRA.Mods.Cnc.Widgets Menu = MenuType.None; Widget.OpenWindow("MUSIC_PANEL", new Dictionary() { - { "onExit", new Action(() => ReturnToMenu(MenuType.Settings)) }, + { "onExit", new Action(() => Menu = MenuType.Settings) }, }); }; @@ -123,21 +123,14 @@ namespace OpenRA.Mods.Cnc.Widgets Menu = MenuType.None; Widget.OpenWindow("SETTINGS_PANEL", new Dictionary() { - { "onExit", new Action(() => ReturnToMenu(MenuType.Settings)) }, + { "onExit", new Action(() => Menu = MenuType.Settings) }, }); }; settingsMenu.GetWidget("BACK_BUTTON").OnClick = () => Menu = MenuType.Main; } - void ReturnToMenu(MenuType menu) - { - Menu = menu; - Widget.CloseWindow(); - } - void RemoveShellmapUI() { - Widget.CloseWindow(); var root = Widget.RootWidget.GetWidget("MENU_BACKGROUND"); root.Parent.RemoveChild(root); } @@ -147,7 +140,7 @@ namespace OpenRA.Mods.Cnc.Widgets Menu = MenuType.None; Game.OpenWindow("SERVER_LOBBY", new Dictionary() { - { "onExit", new Action(() => { Game.DisconnectOnly(); ReturnToMenu(menu); }) }, + { "onExit", new Action(() => { Game.DisconnectOnly(); Menu = menu; }) }, { "onStart", new Action(RemoveShellmapUI) } }); } @@ -160,7 +153,7 @@ namespace OpenRA.Mods.Cnc.Widgets CncConnectingLogic.Connect(IPAddress.Loopback.ToString(), Game.Settings.Server.LoopbackPort, new Action(() => OpenLobbyPanel(MenuType.Main)), - new Action(() => { Game.CloseServer(); ReturnToMenu(MenuType.Main); })); + new Action(() => { Game.CloseServer(); Menu = MenuType.Main; })); } } } diff --git a/OpenRA.Mods.Cnc/Widgets/CncModBrowserLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncModBrowserLogic.cs index b2d5633963..098e781723 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncModBrowserLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncModBrowserLogic.cs @@ -54,7 +54,7 @@ namespace OpenRA.Mods.Cnc.Widgets }; loadButton.IsDisabled = () => currentMod.Id == Game.CurrentMods.Keys.First(); - panel.GetWidget("BACK_BUTTON").OnClick = onExit; + panel.GetWidget("BACK_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); }; currentMod = Mod.AllMods[Game.modData.Manifest.Mods[0]]; // Mod list diff --git a/OpenRA.Mods.Cnc/Widgets/CncMusicPlayerLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncMusicPlayerLogic.cs index f1846e01b0..526ec65eb3 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncMusicPlayerLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncMusicPlayerLogic.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.Cnc.Widgets installed = Rules.Music.Where(m => m.Value.Exists).Any(); Func noMusic = () => !installed; - panel.GetWidget("BACK_BUTTON").OnClick = onExit; + panel.GetWidget("BACK_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); }; Action afterInstall = path => { @@ -254,7 +254,7 @@ namespace OpenRA.Mods.Cnc.Widgets { File.Copy(path, destPath, true); } - catch (Exception) + catch { onError("File copy failed"); } @@ -267,7 +267,7 @@ namespace OpenRA.Mods.Cnc.Widgets }) { IsBackground = true }; t.Start(); } - catch (Exception) + catch { onError("Invalid mix file"); } diff --git a/OpenRA.Mods.Cnc/Widgets/CncReplayBrowserLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncReplayBrowserLogic.cs index 5e35c9e50e..3a8fa15988 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncReplayBrowserLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncReplayBrowserLogic.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Cnc.Widgets { panel = widget.GetWidget("REPLAYBROWSER_PANEL"); - panel.GetWidget("CANCEL_BUTTON").OnClick = onExit; + panel.GetWidget("CANCEL_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); }; var rl = panel.GetWidget("REPLAY_LIST"); var replayDir = Path.Combine(Platform.SupportDir, "Replays"); @@ -55,6 +55,7 @@ namespace OpenRA.Mods.Cnc.Widgets if (currentSummary != null) { Game.JoinReplay(currentSummary.Filename); + Widget.CloseWindow(); onStart(); } }; diff --git a/OpenRA.Mods.Cnc/Widgets/CncServerBrowserLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncServerBrowserLogic.cs index 63488e218f..a7014ce334 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncServerBrowserLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncServerBrowserLogic.cs @@ -240,7 +240,7 @@ namespace OpenRA.Mods.Cnc.Widgets CncConnectingLogic.Connect(ipField.Text, port, openLobby, onExit); }; - panel.GetWidget("BACK_BUTTON").OnClick = onExit; + panel.GetWidget("BACK_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); }; } } } diff --git a/OpenRA.Mods.Cnc/Widgets/CncServerCreationLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncServerCreationLogic.cs index 73443e3799..f3e4cb1d46 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncServerCreationLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncServerCreationLogic.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.Cnc.Widgets this.onExit = onExit; var settings = Game.Settings; - panel.GetWidget("BACK_BUTTON").OnClick = onExit; + panel.GetWidget("BACK_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); }; panel.GetWidget("CREATE_BUTTON").OnClick = CreateAndJoin; panel.GetWidget("MAP_BUTTON").OnClick = () => @@ -41,8 +41,8 @@ namespace OpenRA.Mods.Cnc.Widgets Widget.OpenWindow( "MAPCHOOSER_PANEL", new Dictionary { { "initialMap", map.Uid }, - { "onExit", new Action(() => Widget.CloseWindow()) }, - { "onSelect", new Action(m => { map = m; Widget.CloseWindow(); }) } + { "onExit", new Action(() => {}) }, + { "onSelect", new Action(m => map = m) } }); };