From ec7bbd6c18d88a79a181c1d10085842e259f02fc Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 29 Jun 2013 13:20:04 +1200 Subject: [PATCH] Add Ui.LoadWidget overload. --- OpenRA.Game/Widgets/Widget.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index e3c06dd1f1..6e3264adf8 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -48,6 +48,15 @@ namespace OpenRA.Widgets return window; } + public static T LoadWidget(string id, Widget parent, WidgetArgs args) where T : Widget + { + var widget = LoadWidget(id, parent, args) as T; + if (widget == null) + throw new InvalidOperationException( + "Widget {0} is not of type {1}".F(id, typeof(T).Name)); + return widget; + } + public static Widget LoadWidget(string id, Widget parent, WidgetArgs args) { return Game.modData.WidgetLoader.LoadWidget(args, parent, id);