Let panels handle closing themselves

This commit is contained in:
Paul Chote
2011-05-12 20:14:23 +12:00
parent 5fffc9d816
commit 61facc7bb1
11 changed files with 34 additions and 42 deletions

View File

@@ -76,7 +76,7 @@ namespace OpenRA.Mods.Cnc.Widgets
} }
var panel = widget.GetWidget("CONNECTING_PANEL"); var panel = widget.GetWidget("CONNECTING_PANEL");
panel.GetWidget<CncMenuButtonWidget>("ABORT_BUTTON").OnClick = onAbort; panel.GetWidget<CncMenuButtonWidget>("ABORT_BUTTON").OnClick = () => { Widget.CloseWindow(); onAbort(); };
widget.GetWidget<LabelWidget>("CONNECTING_DESC").GetText = () => widget.GetWidget<LabelWidget>("CONNECTING_DESC").GetText = () =>
"Connecting to {0}:{1}...".F(host, port); "Connecting to {0}:{1}...".F(host, port);
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{ "port", port }, { "port", port },
{ "onConnect", onConnect }, { "onConnect", onConnect },
{ "onAbort", onAbort }, { "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) [ObjectCreator.Param] Action onAbort)
{ {
var panel = widget.GetWidget("CONNECTIONFAILED_PANEL"); var panel = widget.GetWidget("CONNECTIONFAILED_PANEL");
panel.GetWidget<CncMenuButtonWidget>("ABORT_BUTTON").OnClick = onAbort; panel.GetWidget<CncMenuButtonWidget>("ABORT_BUTTON").OnClick = () => { Widget.CloseWindow(); onAbort(); };
panel.GetWidget<CncMenuButtonWidget>("RETRY_BUTTON").OnClick = onRetry; panel.GetWidget<CncMenuButtonWidget>("RETRY_BUTTON").OnClick = () => { Widget.CloseWindow(); onRetry(); };
widget.GetWidget<LabelWidget>("CONNECTING_DESC").GetText = () => widget.GetWidget<LabelWidget>("CONNECTING_DESC").GetText = () =>
"Could not connect to {0}:{1}".F(host, port); "Could not connect to {0}:{1}".F(host, port);

View File

@@ -116,7 +116,7 @@ namespace OpenRA.Mods.Cnc.Widgets
hideButtons = true; hideButtons = true;
Widget.OpenWindow("MUSIC_PANEL", new Dictionary<string, object>() Widget.OpenWindow("MUSIC_PANEL", new Dictionary<string, object>()
{ {
{ "onExit", new Action(() => { hideButtons = false; Widget.CloseWindow(); }) }, { "onExit", new Action(() => hideButtons = false) },
}); });
}; };

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Cnc.Widgets
var panel = widget.GetWidget("INSTALL_PANEL"); var panel = widget.GetWidget("INSTALL_PANEL");
var args = new Dictionary<string, object>() var args = new Dictionary<string, object>()
{ {
{ "continueLoading", continueLoading }, { "continueLoading", new Action(() => { Widget.CloseWindow(); continueLoading(); }) },
{ "installData", installData } { "installData", installData }
}; };
@@ -48,7 +48,8 @@ namespace OpenRA.Mods.Cnc.Widgets
{ {
Widget.OpenWindow("MODS_PANEL", new Dictionary<string, object>() Widget.OpenWindow("MODS_PANEL", new Dictionary<string, object>()
{ {
{ "onExit", new Action(Widget.CloseWindow) }, { "onExit", new Action(() => {}) },
// Close this panel
{ "onSwitch", new Action(Widget.CloseWindow) }, { "onSwitch", new Action(Widget.CloseWindow) },
}); });
}; };
@@ -137,8 +138,7 @@ namespace OpenRA.Mods.Cnc.Widgets
Game.RunAfterTick(() => Game.RunAfterTick(() =>
{ {
Widget.CloseWindow(); // Progress panel Widget.CloseWindow();
Widget.CloseWindow(); // Install choice panel
continueLoading(); continueLoading();
}); });
}) { IsBackground = true }; }) { IsBackground = true };
@@ -237,8 +237,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{ {
Game.RunAfterTick(() => Game.RunAfterTick(() =>
{ {
Widget.CloseWindow(); // Progress panel Widget.CloseWindow();
Widget.CloseWindow(); // Install choice panel
continueLoading(); continueLoading();
}); });
} }

View File

@@ -126,7 +126,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{ {
this.orderManager = orderManager; this.orderManager = orderManager;
this.worldRenderer = worldRenderer; this.worldRenderer = worldRenderer;
this.OnGameStart = onStart; this.OnGameStart = () => { Widget.CloseWindow(); onStart(); };
this.onExit = onExit; this.onExit = onExit;
if (!staticSetup) if (!staticSetup)
@@ -195,20 +195,19 @@ namespace OpenRA.Mods.Cnc.Widgets
orderManager.IssueOrder(Order.Command("map " + m.Uid)); orderManager.IssueOrder(Order.Command("map " + m.Uid));
Game.Settings.Server.LastMap = m.Uid; Game.Settings.Server.LastMap = m.Uid;
Game.Settings.Save(); Game.Settings.Save();
Widget.CloseWindow();
}); });
Widget.OpenWindow( "MAPCHOOSER_PANEL", new Dictionary<string, object> Widget.OpenWindow( "MAPCHOOSER_PANEL", new Dictionary<string, object>
{ {
{ "initialMap", Map.Uid }, { "initialMap", Map.Uid },
{ "onExit", new Action(() => Widget.CloseWindow()) }, { "onExit", new Action(() => {}) },
{ "onSelect", onSelect } { "onSelect", onSelect }
}); });
}; };
mapButton.IsVisible = () => mapButton.Visible && Game.IsHost; mapButton.IsVisible = () => mapButton.Visible && Game.IsHost;
var disconnectButton = lobby.GetWidget<CncMenuButtonWidget>("DISCONNECT_BUTTON"); var disconnectButton = lobby.GetWidget<CncMenuButtonWidget>("DISCONNECT_BUTTON");
disconnectButton.OnClick = onExit; disconnectButton.OnClick = () => { Widget.CloseWindow(); onExit(); };
var gameStarting = false; var gameStarting = false;
var lockTeamsCheckbox = lobby.GetWidget<CncCheckboxWidget>("LOCKTEAMS_CHECKBOX"); var lockTeamsCheckbox = lobby.GetWidget<CncCheckboxWidget>("LOCKTEAMS_CHECKBOX");

View File

@@ -45,8 +45,8 @@ namespace OpenRA.Mods.Cnc.Widgets
panel.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => Rules.TileSets[map.Tileset].Name; panel.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => Rules.TileSets[map.Tileset].Name;
panel.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => map.PlayerCount.ToString(); panel.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => map.PlayerCount.ToString();
panel.GetWidget<CncMenuButtonWidget>("BUTTON_OK").OnClick = () => onSelect(map); panel.GetWidget<CncMenuButtonWidget>("BUTTON_OK").OnClick = () => { Widget.CloseWindow(); onSelect(map); };
panel.GetWidget<CncMenuButtonWidget>("BUTTON_CANCEL").OnClick = onExit; panel.GetWidget<CncMenuButtonWidget>("BUTTON_CANCEL").OnClick = () => { Widget.CloseWindow(); onExit(); };
panel.GetWidget<CncMenuButtonWidget>("BUTTON_INSTALL").IsDisabled = () => true; panel.GetWidget<CncMenuButtonWidget>("BUTTON_INSTALL").IsDisabled = () => true;
panel.GetWidget<CncMenuButtonWidget>("BUTTON_INSTALL").OnClick = () => InstallMap(); panel.GetWidget<CncMenuButtonWidget>("BUTTON_INSTALL").OnClick = () => InstallMap();

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Cnc.Widgets
Menu = MenuType.None; Menu = MenuType.None;
Widget.OpenWindow("REPLAYBROWSER_PANEL", new Dictionary<string, object>() Widget.OpenWindow("REPLAYBROWSER_PANEL", new Dictionary<string, object>()
{ {
{ "onExit", new Action(() => { Menu = MenuType.Main; Widget.CloseWindow(); }) }, { "onExit", new Action(() => Menu = MenuType.Main) },
{ "onStart", new Action(RemoveShellmapUI) } { "onStart", new Action(RemoveShellmapUI) }
}); });
}; };
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Cnc.Widgets
Menu = MenuType.None; Menu = MenuType.None;
Widget.OpenWindow("SERVERBROWSER_PANEL", new Dictionary<string, object>() Widget.OpenWindow("SERVERBROWSER_PANEL", new Dictionary<string, object>()
{ {
{ "onExit", new Action(() => ReturnToMenu(MenuType.Multiplayer)) }, { "onExit", new Action(() => Menu = MenuType.Multiplayer) },
{ "openLobby", new Action(() => OpenLobbyPanel(MenuType.Multiplayer)) } { "openLobby", new Action(() => OpenLobbyPanel(MenuType.Multiplayer)) }
}); });
}; };
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Cnc.Widgets
Menu = MenuType.None; Menu = MenuType.None;
Widget.OpenWindow("CREATESERVER_PANEL", new Dictionary<string, object>() Widget.OpenWindow("CREATESERVER_PANEL", new Dictionary<string, object>()
{ {
{ "onExit", new Action(() => ReturnToMenu(MenuType.Multiplayer)) }, { "onExit", new Action(() => Menu = MenuType.Multiplayer) },
{ "openLobby", new Action(() => OpenLobbyPanel(MenuType.Multiplayer)) } { "openLobby", new Action(() => OpenLobbyPanel(MenuType.Multiplayer)) }
}); });
}; };
@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Cnc.Widgets
Menu = MenuType.None; Menu = MenuType.None;
Widget.OpenWindow("DIRECTCONNECT_PANEL", new Dictionary<string, object>() Widget.OpenWindow("DIRECTCONNECT_PANEL", new Dictionary<string, object>()
{ {
{ "onExit", new Action(() => ReturnToMenu(MenuType.Multiplayer)) }, { "onExit", new Action(() => Menu = MenuType.Multiplayer) },
{ "openLobby", new Action(() => OpenLobbyPanel(MenuType.Multiplayer)) } { "openLobby", new Action(() => OpenLobbyPanel(MenuType.Multiplayer)) }
}); });
}; };
@@ -104,7 +104,7 @@ namespace OpenRA.Mods.Cnc.Widgets
Menu = MenuType.None; Menu = MenuType.None;
Widget.OpenWindow("MODS_PANEL", new Dictionary<string, object>() Widget.OpenWindow("MODS_PANEL", new Dictionary<string, object>()
{ {
{ "onExit", new Action(() => ReturnToMenu(MenuType.Settings)) }, { "onExit", new Action(() => Menu = MenuType.Settings) },
{ "onSwitch", new Action(RemoveShellmapUI) } { "onSwitch", new Action(RemoveShellmapUI) }
}); });
}; };
@@ -114,7 +114,7 @@ namespace OpenRA.Mods.Cnc.Widgets
Menu = MenuType.None; Menu = MenuType.None;
Widget.OpenWindow("MUSIC_PANEL", new Dictionary<string, object>() Widget.OpenWindow("MUSIC_PANEL", new Dictionary<string, object>()
{ {
{ "onExit", new Action(() => ReturnToMenu(MenuType.Settings)) }, { "onExit", new Action(() => Menu = MenuType.Settings) },
}); });
}; };
@@ -123,21 +123,14 @@ namespace OpenRA.Mods.Cnc.Widgets
Menu = MenuType.None; Menu = MenuType.None;
Widget.OpenWindow("SETTINGS_PANEL", new Dictionary<string, object>() Widget.OpenWindow("SETTINGS_PANEL", new Dictionary<string, object>()
{ {
{ "onExit", new Action(() => ReturnToMenu(MenuType.Settings)) }, { "onExit", new Action(() => Menu = MenuType.Settings) },
}); });
}; };
settingsMenu.GetWidget<CncMenuButtonWidget>("BACK_BUTTON").OnClick = () => Menu = MenuType.Main; settingsMenu.GetWidget<CncMenuButtonWidget>("BACK_BUTTON").OnClick = () => Menu = MenuType.Main;
} }
void ReturnToMenu(MenuType menu)
{
Menu = menu;
Widget.CloseWindow();
}
void RemoveShellmapUI() void RemoveShellmapUI()
{ {
Widget.CloseWindow();
var root = Widget.RootWidget.GetWidget("MENU_BACKGROUND"); var root = Widget.RootWidget.GetWidget("MENU_BACKGROUND");
root.Parent.RemoveChild(root); root.Parent.RemoveChild(root);
} }
@@ -147,7 +140,7 @@ namespace OpenRA.Mods.Cnc.Widgets
Menu = MenuType.None; Menu = MenuType.None;
Game.OpenWindow("SERVER_LOBBY", new Dictionary<string, object>() Game.OpenWindow("SERVER_LOBBY", new Dictionary<string, object>()
{ {
{ "onExit", new Action(() => { Game.DisconnectOnly(); ReturnToMenu(menu); }) }, { "onExit", new Action(() => { Game.DisconnectOnly(); Menu = menu; }) },
{ "onStart", new Action(RemoveShellmapUI) } { "onStart", new Action(RemoveShellmapUI) }
}); });
} }
@@ -160,7 +153,7 @@ namespace OpenRA.Mods.Cnc.Widgets
CncConnectingLogic.Connect(IPAddress.Loopback.ToString(), CncConnectingLogic.Connect(IPAddress.Loopback.ToString(),
Game.Settings.Server.LoopbackPort, Game.Settings.Server.LoopbackPort,
new Action(() => OpenLobbyPanel(MenuType.Main)), new Action(() => OpenLobbyPanel(MenuType.Main)),
new Action(() => { Game.CloseServer(); ReturnToMenu(MenuType.Main); })); new Action(() => { Game.CloseServer(); Menu = MenuType.Main; }));
} }
} }
} }

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Cnc.Widgets
}; };
loadButton.IsDisabled = () => currentMod.Id == Game.CurrentMods.Keys.First(); loadButton.IsDisabled = () => currentMod.Id == Game.CurrentMods.Keys.First();
panel.GetWidget<CncMenuButtonWidget>("BACK_BUTTON").OnClick = onExit; panel.GetWidget<CncMenuButtonWidget>("BACK_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); };
currentMod = Mod.AllMods[Game.modData.Manifest.Mods[0]]; currentMod = Mod.AllMods[Game.modData.Manifest.Mods[0]];
// Mod list // Mod list

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Cnc.Widgets
installed = Rules.Music.Where(m => m.Value.Exists).Any(); installed = Rules.Music.Where(m => m.Value.Exists).Any();
Func<bool> noMusic = () => !installed; Func<bool> noMusic = () => !installed;
panel.GetWidget<CncMenuButtonWidget>("BACK_BUTTON").OnClick = onExit; panel.GetWidget<CncMenuButtonWidget>("BACK_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); };
Action<string> afterInstall = path => Action<string> afterInstall = path =>
{ {
@@ -254,7 +254,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{ {
File.Copy(path, destPath, true); File.Copy(path, destPath, true);
} }
catch (Exception) catch
{ {
onError("File copy failed"); onError("File copy failed");
} }
@@ -267,7 +267,7 @@ namespace OpenRA.Mods.Cnc.Widgets
}) { IsBackground = true }; }) { IsBackground = true };
t.Start(); t.Start();
} }
catch (Exception) catch
{ {
onError("Invalid mix file"); onError("Invalid mix file");
} }

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{ {
panel = widget.GetWidget("REPLAYBROWSER_PANEL"); panel = widget.GetWidget("REPLAYBROWSER_PANEL");
panel.GetWidget<CncMenuButtonWidget>("CANCEL_BUTTON").OnClick = onExit; panel.GetWidget<CncMenuButtonWidget>("CANCEL_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); };
var rl = panel.GetWidget<ScrollPanelWidget>("REPLAY_LIST"); var rl = panel.GetWidget<ScrollPanelWidget>("REPLAY_LIST");
var replayDir = Path.Combine(Platform.SupportDir, "Replays"); var replayDir = Path.Combine(Platform.SupportDir, "Replays");
@@ -55,6 +55,7 @@ namespace OpenRA.Mods.Cnc.Widgets
if (currentSummary != null) if (currentSummary != null)
{ {
Game.JoinReplay(currentSummary.Filename); Game.JoinReplay(currentSummary.Filename);
Widget.CloseWindow();
onStart(); onStart();
} }
}; };

View File

@@ -240,7 +240,7 @@ namespace OpenRA.Mods.Cnc.Widgets
CncConnectingLogic.Connect(ipField.Text, port, openLobby, onExit); CncConnectingLogic.Connect(ipField.Text, port, openLobby, onExit);
}; };
panel.GetWidget<CncMenuButtonWidget>("BACK_BUTTON").OnClick = onExit; panel.GetWidget<CncMenuButtonWidget>("BACK_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); };
} }
} }
} }

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Cnc.Widgets
this.onExit = onExit; this.onExit = onExit;
var settings = Game.Settings; var settings = Game.Settings;
panel.GetWidget<CncMenuButtonWidget>("BACK_BUTTON").OnClick = onExit; panel.GetWidget<CncMenuButtonWidget>("BACK_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); };
panel.GetWidget<CncMenuButtonWidget>("CREATE_BUTTON").OnClick = CreateAndJoin; panel.GetWidget<CncMenuButtonWidget>("CREATE_BUTTON").OnClick = CreateAndJoin;
panel.GetWidget<CncMenuButtonWidget>("MAP_BUTTON").OnClick = () => panel.GetWidget<CncMenuButtonWidget>("MAP_BUTTON").OnClick = () =>
@@ -41,8 +41,8 @@ namespace OpenRA.Mods.Cnc.Widgets
Widget.OpenWindow( "MAPCHOOSER_PANEL", new Dictionary<string, object> Widget.OpenWindow( "MAPCHOOSER_PANEL", new Dictionary<string, object>
{ {
{ "initialMap", map.Uid }, { "initialMap", map.Uid },
{ "onExit", new Action(() => Widget.CloseWindow()) }, { "onExit", new Action(() => {}) },
{ "onSelect", new Action<Map>(m => { map = m; Widget.CloseWindow(); }) } { "onSelect", new Action<Map>(m => map = m) }
}); });
}; };