Skip to content

Commit 6bcbae7

Browse files
committed
Remove PARENT_TOP and PARENT_LEFT from integer expressions for widgets
PARENT_TOP and PARENT_LEFT should be 0 so they are not very useful substitutions. They are replaced with 0 or removed if that was the whole value for a field.
1 parent 806f0fd commit 6bcbae7

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

OpenRA.Game/Widgets/Widget.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,6 @@ public virtual void Initialize(WidgetArgs args)
293293
substitutions.Add("WINDOW_RIGHT", Game.Renderer.Resolution.Width);
294294
substitutions.Add("WINDOW_BOTTOM", Game.Renderer.Resolution.Height);
295295
substitutions.Add("PARENT_RIGHT", parentBounds.Width);
296-
substitutions.Add("PARENT_LEFT", parentBounds.Left);
297-
substitutions.Add("PARENT_TOP", parentBounds.Top);
298296
substitutions.Add("PARENT_BOTTOM", parentBounds.Height);
299297

300298
var readOnlySubstitutions = new ReadOnlyDictionary<string, int>(substitutions);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#region Copyright & License Information
2+
/*
3+
* Copyright (c) The OpenRA Developers and Contributors
4+
* This file is part of OpenRA, which is free software. It is made
5+
* available to you under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation, either version 3 of
7+
* the License, or (at your option) any later version. For more
8+
* information, see COPYING.
9+
*/
10+
#endregion
11+
12+
using System.Collections.Generic;
13+
using System.Linq;
14+
15+
namespace OpenRA.Mods.Common.UpdateRules.Rules
16+
{
17+
public class RemoveParentTopParentLeftSubstitutions : UpdateRule
18+
{
19+
public override string Name => "Remove PARENT_TOP and PARENT_LEFT from integer expressions for widgets.";
20+
21+
public override string Description =>
22+
"PARENT_TOP is replaced with 0 and PARENT_LEFT is replaced with 0 in integer expressions for width, hegiht and position.";
23+
24+
public override IEnumerable<string> UpdateChromeNode(ModData modData, MiniYamlNodeBuilder chromeNode)
25+
{
26+
var dimensionFields =
27+
chromeNode.ChildrenMatching("Width")
28+
.Concat(chromeNode.ChildrenMatching("Height"))
29+
.Concat(chromeNode.ChildrenMatching("X"))
30+
.Concat(chromeNode.ChildrenMatching("Y")).ToArray();
31+
32+
foreach (var field in dimensionFields)
33+
{
34+
if (field.Value.Value == "PARENT_TOP" || field.Value.Value == "PARENT_LEFT")
35+
{
36+
chromeNode.RemoveNode(field);
37+
}
38+
else if (field.Value.Value.Contains("PARENT_TOP"))
39+
{
40+
field.ReplaceValue(field.Value.Value.Replace("PARENT_TOP", "0"));
41+
}
42+
else if (field.Value.Value.Contains("PARENT_LEFT"))
43+
{
44+
field.ReplaceValue(field.Value.Value.Replace("PARENT_LEFT", "0"));
45+
}
46+
}
47+
48+
yield break;
49+
}
50+
}
51+
}

OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,6 @@ static void RecalculateWidgetLayout(Widget w, bool insideScrollPanel = false)
520520
{ "WINDOW_RIGHT", Game.Renderer.Resolution.Width },
521521
{ "WINDOW_BOTTOM", Game.Renderer.Resolution.Height },
522522
{ "PARENT_RIGHT", parentBounds.Width },
523-
{ "PARENT_LEFT", parentBounds.Left },
524-
{ "PARENT_TOP", parentBounds.Top },
525523
{ "PARENT_BOTTOM", parentBounds.Height }
526524
};
527525

mods/common/chrome/ingame-debug-hpf.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ Container@HPF_OVERLAY:
44
Height: 60
55
Children:
66
DropDownButton@HPF_OVERLAY_LOCOMOTOR:
7-
Y: PARENT_TOP
87
Width: PARENT_RIGHT
98
Height: 25
109
Text: dropdownbutton-hpf-overlay-locomotor
1110
Font: Regular
1211
DropDownButton@HPF_OVERLAY_CHECK:
13-
Y: PARENT_TOP + 35
12+
Y: 35
1413
Width: PARENT_RIGHT
1514
Height: 25
1615
Text: dropdownbutton-hpf-overlay-check

0 commit comments

Comments
 (0)