Pass WidgetArgs to Widget.Initialize. Use this to allow for custom substitutions.

This commit is contained in:
Paul Chote
2011-05-17 18:57:41 +12:00
parent b417118429
commit 5bc0ef69ad
6 changed files with 18 additions and 10 deletions

View File

@@ -95,14 +95,17 @@ namespace OpenRA.Widgets
public virtual int2 ChildOrigin { get { return RenderOrigin; } }
public virtual Rectangle RenderBounds { get { return new Rectangle(RenderOrigin.X, RenderOrigin.Y, Bounds.Width, Bounds.Height); } }
public virtual void Initialize()
public virtual void Initialize(WidgetArgs args)
{
// Parse the YAML equations to find the widget bounds
var parentBounds = (Parent == null)
? new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height)
: Parent.Bounds;
var substitutions = new Dictionary<string, int>();
var substitutions = args.ContainsKey("substitutions") ?
new Dictionary<string, int>((Dictionary<string, int>)args["substitutions"]) :
new Dictionary<string, int>();
substitutions.Add("WINDOW_RIGHT", Game.viewport.Width);
substitutions.Add("WINDOW_BOTTOM", Game.viewport.Height);
substitutions.Add("PARENT_RIGHT", parentBounds.Width);