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

@@ -98,14 +98,14 @@ namespace OpenRA
// Hacky workaround for orderManager visibility
public static Widget OpenWindow(World world, string widget)
{
return Widget.OpenWindow(widget, new Dictionary<string,object>{{ "world", world }, { "orderManager", orderManager }, { "worldRenderer", worldRenderer }});
return Widget.OpenWindow(widget, new WidgetArgs() {{ "world", world }, { "orderManager", orderManager }, { "worldRenderer", worldRenderer }});
}
// Who came up with the great idea of making these things
// impossible for the things that want them to access them directly?
public static Widget OpenWindow(string widget, Dictionary<string, object> args)
public static Widget OpenWindow(string widget, WidgetArgs args)
{
return Widget.OpenWindow(widget, new Dictionary<string,object>(args)
return Widget.OpenWindow(widget, new WidgetArgs(args)
{
{ "world", worldRenderer.world },
{ "orderManager", orderManager },
@@ -113,9 +113,9 @@ namespace OpenRA
});
}
public static Widget LoadWidget(World world, string widget, Dictionary<string, object> args)
public static Widget LoadWidget(World world, string widget, WidgetArgs args)
{
return Widget.LoadWidget(widget, new Dictionary<string,object>(args)
return Widget.LoadWidget(widget, new WidgetArgs(args)
{
{ "world", world },
{ "orderManager", orderManager },

View File

@@ -121,7 +121,7 @@ namespace OpenRA.Widgets
height);
}
public void PostInit(Dictionary<string, object> args)
public void PostInit(WidgetArgs args)
{
if (Delegate == null)
return;
@@ -322,10 +322,10 @@ namespace OpenRA.Widgets
public static Widget OpenWindow(string id)
{
return OpenWindow(id, new Dictionary<string, object>());
return OpenWindow(id, new WidgetArgs());
}
public static Widget OpenWindow(string id, Dictionary<string, object> args)
public static Widget OpenWindow(string id, WidgetArgs args)
{
var window = Game.modData.WidgetLoader.LoadWidget(args, rootWidget, id);
if (WindowList.Count > 0)
@@ -334,7 +334,7 @@ namespace OpenRA.Widgets
return window;
}
public static Widget LoadWidget(string id, Dictionary<string, object> args)
public static Widget LoadWidget(string id, WidgetArgs args)
{
return Game.modData.WidgetLoader.LoadWidget(args, rootWidget, id);
}
@@ -378,7 +378,14 @@ namespace OpenRA.Widgets
public override string GetCursor(int2 pos) { return null; }
public override Widget Clone() { return new ContainerWidget(this); }
}
public class WidgetArgs : Dictionary<string, object>
{
public WidgetArgs() : base() { }
public WidgetArgs(Dictionary<string, object> args) : base(args) { }
public void Add(string key, Action val) { base.Add(key, val); }
}
public interface IWidgetDelegate { }
// TODO: This can die once ra init is sane

View File

@@ -32,7 +32,7 @@ namespace OpenRA
}
}
public Widget LoadWidget( Dictionary<string, object> args, Widget parent, string w )
public Widget LoadWidget( WidgetArgs args, Widget parent, string w )
{
MiniYamlNode ret;
if (!widgets.TryGetValue(w, out ret))
@@ -41,7 +41,7 @@ namespace OpenRA
return LoadWidget( args, parent, ret );
}
public Widget LoadWidget( Dictionary<string, object> args, Widget parent, MiniYamlNode node)
public Widget LoadWidget( WidgetArgs args, Widget parent, MiniYamlNode node)
{
var widget = NewWidget(node.Key, args);
@@ -63,7 +63,7 @@ namespace OpenRA
return widget;
}
Widget NewWidget(string widgetType, Dictionary<string, object> args)
Widget NewWidget(string widgetType, WidgetArgs args)
{
widgetType = widgetType.Split('@')[0];
return Game.modData.ObjectCreator.CreateObject<Widget>(widgetType + "Widget", args);