From 68557329548b14bae4e4058c3bad42b7683fec62 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 16 Mar 2010 19:55:43 +1300 Subject: [PATCH] remove some ugly hacks --- OpenRA.Game/Chrome.cs | 4 +- OpenRA.Game/Chrome/WidgetLoader.cs | 91 +++++++++++++----------------- 2 files changed, 41 insertions(+), 54 deletions(-) diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index 9900c2e83f..352d9058ea 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -131,9 +131,7 @@ namespace OpenRA var widgetYaml = m.ChromeLayout.Select(a => MiniYaml.FromFile(a)).Aggregate(MiniYaml.Merge); - // Hack around a bug in MiniYaml - widgetYaml.Values.FirstOrDefault().Value = widgetYaml.Keys.FirstOrDefault(); - WidgetLoader.rootWidget = WidgetLoader.LoadWidget(widgetYaml.Values.FirstOrDefault()); + WidgetLoader.rootWidget = WidgetLoader.LoadWidget( widgetYaml.FirstOrDefault() ); WidgetLoader.rootWidget.Initialize(); } diff --git a/OpenRA.Game/Chrome/WidgetLoader.cs b/OpenRA.Game/Chrome/WidgetLoader.cs index 47e181d4f1..209d05e42e 100644 --- a/OpenRA.Game/Chrome/WidgetLoader.cs +++ b/OpenRA.Game/Chrome/WidgetLoader.cs @@ -1,53 +1,42 @@ -using OpenRA.FileFormats; -using OpenRA.Graphics; -using OpenRA.Widgets; -using System; -using System.Collections.Generic; -using System.Drawing; -using System.IO; -using System.Reflection; -using System.Linq; - -namespace OpenRA -{ - class WidgetLoader - { - public static Widget rootWidget; - public static Widget LoadWidget( MiniYaml node ) - { - var widget = NewWidget( node.Value ); - foreach( var child in node.Nodes ) - { - if( child.Key == "Children" ) - { - foreach( var c in child.Value.Nodes ) - { - // Hack around a bug in MiniYaml - c.Value.Value = c.Key; - widget.AddChild( LoadWidget( c.Value ) ); - } - } - else - FieldLoader.LoadField( widget, child.Key, child.Value ); - } - return widget; - } - - static Widget NewWidget( string widgetType ) +using System; +using OpenRA.FileFormats; +using OpenRA.Widgets; +using System.Collections.Generic; + +namespace OpenRA +{ + class WidgetLoader + { + public static Widget rootWidget; + public static Widget LoadWidget(KeyValuePair node) { - widgetType = widgetType.Split('@')[0]; - - foreach (var mod in Game.ModAssemblies) - { - var fullTypeName = mod.Second + "." + widgetType + "Widget"; - var widget = (Widget)mod.First.CreateInstance(fullTypeName); - if (widget == null) continue; - - Log.Write("Creating Widget of type {0}",widgetType); - return widget; - } - - throw new InvalidOperationException("Cannot locate widget: {0}".F(widgetType)); - } - } + var widget = NewWidget(node.Key); + foreach (var child in node.Value.Nodes) + { + if (child.Key == "Children") + foreach (var c in child.Value.Nodes) + widget.AddChild(LoadWidget(c)); + else + FieldLoader.LoadField(widget, child.Key, child.Value); + } + return widget; + } + + static Widget NewWidget(string widgetType) + { + widgetType = widgetType.Split('@')[0]; + + foreach (var mod in Game.ModAssemblies) + { + var fullTypeName = mod.Second + "." + widgetType + "Widget"; + var widget = (Widget)mod.First.CreateInstance(fullTypeName); + if (widget == null) continue; + + Log.Write("Creating Widget of type {0}", widgetType); + return widget; + } + + throw new InvalidOperationException("Cannot locate widget: {0}".F(widgetType)); + } + } } \ No newline at end of file