Add a WidgetArgs type to work around gmcs not understanding lambda -> Action -> object.

This commit is contained in:
Paul Chote
2011-05-13 09:41:21 +12:00
parent 603379aa96
commit f4ea4c5daa
17 changed files with 85 additions and 79 deletions

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{
// Show connection failed dialog
Widget.CloseWindow();
Widget.OpenWindow("CONNECTIONFAILED_PANEL", new Dictionary<string, object>()
Widget.OpenWindow("CONNECTIONFAILED_PANEL", new WidgetArgs()
{
{ "onAbort", onAbort },
{ "onRetry", onRetry },
@@ -85,13 +85,13 @@ namespace OpenRA.Mods.Cnc.Widgets
public static void Connect(string host, int port, Action onConnect, Action onAbort)
{
Game.JoinServer(host, port);
Widget.OpenWindow("CONNECTING_PANEL", new Dictionary<string, object>()
Widget.OpenWindow("CONNECTING_PANEL", new WidgetArgs()
{
{ "host", host },
{ "port", port },
{ "onConnect", onConnect },
{ "onAbort", onAbort },
{ "onRetry", new Action(() => Connect(host, port, onConnect, onAbort)) }
{ "onRetry", () => Connect(host, port, onConnect, onAbort) }
});
}
}

View File

@@ -59,8 +59,7 @@ namespace OpenRA.Mods.Cnc.Widgets
ingameRoot.GetWidget<CncMenuButtonWidget>("OPTIONS_BUTTON").OnClick = () =>
{
ingameRoot.IsVisible = () => false;
var onExit = new Action(() => {ingameRoot.IsVisible = () => true;});
Widget.LoadWidget("INGAME_MENU", new Dictionary<string, object>() {{ "world", world }, { "onExit", onExit }});
Widget.LoadWidget("INGAME_MENU", new WidgetArgs() {{ "world", world }, { "onExit", () => ingameRoot.IsVisible = () => true }});
};
var postgameBG = ingameRoot.GetWidget("POSTGAME_BG");
@@ -93,19 +92,19 @@ namespace OpenRA.Mods.Cnc.Widgets
bool hideButtons = false;
menu.GetWidget("MENU_BUTTONS").IsVisible = () => !hideButtons;
var onQuit = (Action)(() =>
Action onQuit = () =>
{
Game.DisconnectOnly();
Widget.RootWidget.RemoveChildren();
Game.LoadShellMap();
});
};
var doNothing = (Action)(() => {});
Action doNothing = () => {};
menu.GetWidget<CncMenuButtonWidget>("QUIT_BUTTON").OnClick = () =>
PromptConfirmAction("Quit", "Are you sure you want to quit?", onQuit, doNothing);
var onSurrender = (Action)(() => world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false)));
Action onSurrender = () => world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false));
var surrenderButton = menu.GetWidget<CncMenuButtonWidget>("SURRENDER_BUTTON");
surrenderButton.IsDisabled = () => (world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Undefined);
surrenderButton.OnClick = () =>
@@ -114,18 +113,18 @@ namespace OpenRA.Mods.Cnc.Widgets
menu.GetWidget<CncMenuButtonWidget>("MUSIC_BUTTON").OnClick = () =>
{
hideButtons = true;
Widget.OpenWindow("MUSIC_PANEL", new Dictionary<string, object>()
Widget.OpenWindow("MUSIC_PANEL", new WidgetArgs()
{
{ "onExit", new Action(() => hideButtons = false) },
{ "onExit", () => hideButtons = false },
});
};
menu.GetWidget<CncMenuButtonWidget>("PREFERENCES_BUTTON").OnClick = () =>
{
hideButtons = true;
Widget.OpenWindow("SETTINGS_PANEL", new Dictionary<string, object>()
Widget.OpenWindow("SETTINGS_PANEL", new WidgetArgs()
{
{ "onExit", new Action(() => hideButtons = false) },
{ "onExit", () => hideButtons = false },
});
};

View File

@@ -29,9 +29,9 @@ namespace OpenRA.Mods.Cnc.Widgets
[ObjectCreator.Param] Action continueLoading)
{
var panel = widget.GetWidget("INSTALL_PANEL");
var args = new Dictionary<string, object>()
var args = new WidgetArgs()
{
{ "continueLoading", new Action(() => { Widget.CloseWindow(); continueLoading(); }) },
{ "continueLoading", () => { Widget.CloseWindow(); continueLoading(); } },
{ "installData", installData }
};
@@ -46,11 +46,11 @@ namespace OpenRA.Mods.Cnc.Widgets
// TODO:
panel.GetWidget<CncMenuButtonWidget>("MODS_BUTTON").OnClick = () =>
{
Widget.OpenWindow("MODS_PANEL", new Dictionary<string, object>()
Widget.OpenWindow("MODS_PANEL", new WidgetArgs()
{
{ "onExit", new Action(() => {}) },
{ "onExit", () => {} },
// Close this panel
{ "onSwitch", new Action(Widget.CloseWindow) },
{ "onSwitch", Widget.CloseWindow },
});
};
}

View File

@@ -92,22 +92,22 @@ namespace OpenRA.Mods.Cnc.Widgets
// Show connection failed dialog
Widget.CloseWindow();
Action onConnect = new Action(() =>
Action onConnect = () =>
{
Game.OpenWindow("SERVER_LOBBY", new Dictionary<string, object>()
Game.OpenWindow("SERVER_LOBBY", new WidgetArgs()
{
{ "onExit", onExit },
{ "onStart", OnGameStart }
});
});
};
Action onRetry = new Action(() =>
Action onRetry = () =>
{
Widget.CloseWindow();
CncConnectingLogic.Connect(om.Host, om.Port, onConnect, onExit);
});
};
Widget.OpenWindow("CONNECTIONFAILED_PANEL", new Dictionary<string, object>()
Widget.OpenWindow("CONNECTIONFAILED_PANEL", new WidgetArgs()
{
{ "onAbort", onExit },
{ "onRetry", onRetry },
@@ -197,10 +197,10 @@ namespace OpenRA.Mods.Cnc.Widgets
Game.Settings.Save();
});
Widget.OpenWindow( "MAPCHOOSER_PANEL", new Dictionary<string, object>
Widget.OpenWindow( "MAPCHOOSER_PANEL", new WidgetArgs()
{
{ "initialMap", Map.Uid },
{ "onExit", new Action(() => {}) },
{ "onExit", () => {} },
{ "onSelect", onSelect }
});
};
@@ -406,7 +406,7 @@ namespace OpenRA.Mods.Cnc.Widgets
if (Map.Players[s.MapPlayer].LockColor)
return false;
var colorChooser = Game.modData.WidgetLoader.LoadWidget( new Dictionary<string,object>() { {"worldRenderer", worldRenderer} }, null, "COLOR_CHOOSER" );
var colorChooser = Game.modData.WidgetLoader.LoadWidget( new WidgetArgs() { {"worldRenderer", worldRenderer} }, null, "COLOR_CHOOSER" );
var hueSlider = colorChooser.GetWidget<SliderWidget>("HUE_SLIDER");
hueSlider.SetOffset(orderManager.LocalClient.ColorRamp.H / 255f);

View File

@@ -50,10 +50,10 @@ namespace OpenRA.Mods.Cnc.Widgets
mainMenu.GetWidget<CncMenuButtonWidget>("REPLAYS_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
Widget.OpenWindow("REPLAYBROWSER_PANEL", new Dictionary<string, object>()
Widget.OpenWindow("REPLAYBROWSER_PANEL", new WidgetArgs()
{
{ "onExit", new Action(() => Menu = MenuType.Main) },
{ "onStart", new Action(RemoveShellmapUI) }
{ "onExit", () => Menu = MenuType.Main },
{ "onStart", RemoveShellmapUI }
});
};
@@ -68,30 +68,30 @@ namespace OpenRA.Mods.Cnc.Widgets
multiplayerMenu.GetWidget<CncMenuButtonWidget>("JOIN_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
Widget.OpenWindow("SERVERBROWSER_PANEL", new Dictionary<string, object>()
Widget.OpenWindow("SERVERBROWSER_PANEL", new WidgetArgs()
{
{ "onExit", new Action(() => Menu = MenuType.Multiplayer) },
{ "openLobby", new Action(() => OpenLobbyPanel(MenuType.Multiplayer)) }
{ "onExit", () => Menu = MenuType.Multiplayer },
{ "openLobby", () => OpenLobbyPanel(MenuType.Multiplayer) }
});
};
multiplayerMenu.GetWidget<CncMenuButtonWidget>("CREATE_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
Widget.OpenWindow("CREATESERVER_PANEL", new Dictionary<string, object>()
Widget.OpenWindow("CREATESERVER_PANEL", new WidgetArgs()
{
{ "onExit", new Action(() => Menu = MenuType.Multiplayer) },
{ "openLobby", new Action(() => OpenLobbyPanel(MenuType.Multiplayer)) }
{ "onExit", () => Menu = MenuType.Multiplayer },
{ "openLobby", () => OpenLobbyPanel(MenuType.Multiplayer) }
});
};
multiplayerMenu.GetWidget<CncMenuButtonWidget>("DIRECTCONNECT_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
Widget.OpenWindow("DIRECTCONNECT_PANEL", new Dictionary<string, object>()
Widget.OpenWindow("DIRECTCONNECT_PANEL", new WidgetArgs()
{
{ "onExit", new Action(() => Menu = MenuType.Multiplayer) },
{ "openLobby", new Action(() => OpenLobbyPanel(MenuType.Multiplayer)) }
{ "onExit", () => Menu = MenuType.Multiplayer },
{ "openLobby", () => OpenLobbyPanel(MenuType.Multiplayer) }
});
};
@@ -102,28 +102,28 @@ namespace OpenRA.Mods.Cnc.Widgets
settingsMenu.GetWidget<CncMenuButtonWidget>("MODS_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
Widget.OpenWindow("MODS_PANEL", new Dictionary<string, object>()
Widget.OpenWindow("MODS_PANEL", new WidgetArgs()
{
{ "onExit", new Action(() => Menu = MenuType.Settings) },
{ "onSwitch", new Action(RemoveShellmapUI) }
{ "onExit", () => Menu = MenuType.Settings },
{ "onSwitch", RemoveShellmapUI }
});
};
settingsMenu.GetWidget<CncMenuButtonWidget>("MUSIC_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
Widget.OpenWindow("MUSIC_PANEL", new Dictionary<string, object>()
Widget.OpenWindow("MUSIC_PANEL", new WidgetArgs()
{
{ "onExit", new Action(() => Menu = MenuType.Settings) },
{ "onExit", () => Menu = MenuType.Settings },
});
};
settingsMenu.GetWidget<CncMenuButtonWidget>("PREFERENCES_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
Widget.OpenWindow("SETTINGS_PANEL", new Dictionary<string, object>()
Widget.OpenWindow("SETTINGS_PANEL", new WidgetArgs()
{
{ "onExit", new Action(() => Menu = MenuType.Settings) },
{ "onExit", () => Menu = MenuType.Settings },
});
};
settingsMenu.GetWidget<CncMenuButtonWidget>("BACK_BUTTON").OnClick = () => Menu = MenuType.Main;
@@ -138,10 +138,10 @@ namespace OpenRA.Mods.Cnc.Widgets
void OpenLobbyPanel(MenuType menu)
{
Menu = MenuType.None;
Game.OpenWindow("SERVER_LOBBY", new Dictionary<string, object>()
Game.OpenWindow("SERVER_LOBBY", new WidgetArgs()
{
{ "onExit", new Action(() => { Game.DisconnectOnly(); Menu = menu; }) },
{ "onStart", new Action(RemoveShellmapUI) }
{ "onExit", () => { Game.DisconnectOnly(); Menu = menu; } },
{ "onStart", RemoveShellmapUI }
});
}
@@ -152,8 +152,8 @@ namespace OpenRA.Mods.Cnc.Widgets
Game.CreateLocalServer(map);
CncConnectingLogic.Connect(IPAddress.Loopback.ToString(),
Game.Settings.Server.LoopbackPort,
new Action(() => OpenLobbyPanel(MenuType.Main)),
new Action(() => { Game.CloseServer(); Menu = MenuType.Main; }));
() => OpenLobbyPanel(MenuType.Main),
() => { Game.CloseServer(); Menu = MenuType.Main; });
}
}
}

View File

@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Cnc.Widgets
var installButton = panel.GetWidget<CncMenuButtonWidget>("INSTALL_BUTTON");
installButton.OnClick = () =>
Widget.OpenWindow("INSTALL_MUSIC_PANEL", new Dictionary<string, object>() {{ "afterInstall", afterInstall }});
Widget.OpenWindow("INSTALL_MUSIC_PANEL", new WidgetArgs() {{ "afterInstall", afterInstall }});
installButton.IsVisible = () => music.Length < 2; // Hack around ra shipping (only) hellmarch by default
panel.GetWidget("NO_MUSIC_LABEL").IsVisible = noMusic;

View File

@@ -38,10 +38,10 @@ namespace OpenRA.Mods.Cnc.Widgets
panel.GetWidget<CncMenuButtonWidget>("MAP_BUTTON").OnClick = () =>
{
Widget.OpenWindow( "MAPCHOOSER_PANEL", new Dictionary<string, object>
Widget.OpenWindow( "MAPCHOOSER_PANEL", new WidgetArgs()
{
{ "initialMap", map.Uid },
{ "onExit", new Action(() => {}) },
{ "onExit", () => {} },
{ "onSelect", new Action<Map>(m => map = m) }
});
};