Pass WidgetArgs to Widget.Initialize. Use this to allow for custom substitutions.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace OpenRA
|
||||
if (child.Key != "Children")
|
||||
FieldLoader.LoadField(widget, child.Key, child.Value.Value);
|
||||
|
||||
widget.Initialize();
|
||||
widget.Initialize(args);
|
||||
|
||||
foreach (var child in node.Value.Nodes)
|
||||
if (child.Key == "Children")
|
||||
|
||||
@@ -219,9 +219,14 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
|
||||
void ShowGroupModifierDropdown(CncDropDownButtonWidget dropdown)
|
||||
{
|
||||
var panel = Game.LoadWidget(world, "LABEL_DROPDOWN_TEMPLATE", null, new WidgetArgs()) as ScrollPanelWidget;
|
||||
var itemTemplate = panel.GetWidget<ScrollItemWidget>("TEMPLATE");
|
||||
var substitutions = new Dictionary<string,int>() {{ "DROPDOWN_WIDTH", dropdown.Bounds.Width }};
|
||||
|
||||
var panel = (ScrollPanelWidget)Game.LoadWidget(world, "LABEL_DROPDOWN_TEMPLATE", null, new WidgetArgs()
|
||||
{
|
||||
{ "substitutions", substitutions }
|
||||
});
|
||||
|
||||
var itemTemplate = panel.GetWidget<ScrollItemWidget>("TEMPLATE");
|
||||
var options = new List<Pair<string, Modifiers>>()
|
||||
{
|
||||
Pair.New("Ctrl", Modifiers.Ctrl),
|
||||
|
||||
@@ -42,9 +42,9 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
public override void Initialize(WidgetArgs args)
|
||||
{
|
||||
base.Initialize();
|
||||
base.Initialize(args);
|
||||
|
||||
var size = Math.Max(world.Map.Bounds.Width, world.Map.Bounds.Height);
|
||||
previewScale = Math.Min(RenderBounds.Width * 1f / world.Map.Bounds.Width, RenderBounds.Height * 1f / world.Map.Bounds.Height);
|
||||
|
||||
@@ -34,9 +34,9 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
this.worldRenderer = worldRenderer;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
public override void Initialize(WidgetArgs args)
|
||||
{
|
||||
base.Initialize();
|
||||
base.Initialize(args);
|
||||
|
||||
spsprites = Rules.Info.Values.SelectMany( u => u.Traits.WithInterface<SupportPowerInfo>() )
|
||||
.Select(u => u.Image).Distinct()
|
||||
|
||||
@@ -74,7 +74,7 @@ Background@COLOR_CHOOSER:
|
||||
|
||||
ScrollPanel@LABEL_DROPDOWN_TEMPLATE:
|
||||
Id:LABEL_DROPDOWN_TEMPLATE
|
||||
Width:100
|
||||
Width:DROPDOWN_WIDTH
|
||||
Children:
|
||||
ScrollItem@TEMPLATE:
|
||||
Id:TEMPLATE
|
||||
|
||||
Reference in New Issue
Block a user