From a69ea79d839f8bfe1b004b42603d67eebd17cdb2 Mon Sep 17 00:00:00 2001 From: Ivaylo Draganov Date: Thu, 3 Oct 2024 17:43:16 +0300 Subject: [PATCH] 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. --- OpenRA.Game/Widgets/Widget.cs | 2 - .../RemoveParentTopParentLeftSubstitutions.cs | 51 +++++++++++++++++++ OpenRA.Mods.Common/UpdateRules/UpdatePath.cs | 1 + .../Logic/Settings/DisplaySettingsLogic.cs | 2 - mods/common/chrome/ingame-debug-hpf.yaml | 3 +- 5 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 OpenRA.Mods.Common/UpdateRules/Rules/20231010/RemoveParentTopParentLeftSubstitutions.cs diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index c57bf2b1be56..28973b8179c5 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -293,8 +293,6 @@ public virtual void Initialize(WidgetArgs args) substitutions.Add("WINDOW_RIGHT", Game.Renderer.Resolution.Width); substitutions.Add("WINDOW_BOTTOM", Game.Renderer.Resolution.Height); substitutions.Add("PARENT_RIGHT", parentBounds.Width); - substitutions.Add("PARENT_LEFT", parentBounds.Left); - substitutions.Add("PARENT_TOP", parentBounds.Top); substitutions.Add("PARENT_BOTTOM", parentBounds.Height); var readOnlySubstitutions = new ReadOnlyDictionary(substitutions); diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20231010/RemoveParentTopParentLeftSubstitutions.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20231010/RemoveParentTopParentLeftSubstitutions.cs new file mode 100644 index 000000000000..0e3b0c1bc53a --- /dev/null +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20231010/RemoveParentTopParentLeftSubstitutions.cs @@ -0,0 +1,51 @@ +#region Copyright & License Information +/* + * Copyright (c) The OpenRA Developers and Contributors + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; +using System.Linq; + +namespace OpenRA.Mods.Common.UpdateRules.Rules +{ + public class RemoveParentTopParentLeftSubstitutions : UpdateRule + { + public override string Name => "Remove PARENT_TOP and PARENT_LEFT from integer expressions for widgets."; + + public override string Description => + "PARENT_TOP is replaced with 0 and PARENT_LEFT is replaced with 0 in integer expressions for width, hegiht and position."; + + public override IEnumerable UpdateChromeNode(ModData modData, MiniYamlNodeBuilder chromeNode) + { + var dimensionFields = + chromeNode.ChildrenMatching("Width") + .Concat(chromeNode.ChildrenMatching("Height")) + .Concat(chromeNode.ChildrenMatching("X")) + .Concat(chromeNode.ChildrenMatching("Y")).ToArray(); + + foreach (var field in dimensionFields) + { + if (field.Value.Value == "PARENT_TOP" || field.Value.Value == "PARENT_LEFT") + { + chromeNode.RemoveNode(field); + } + else if (field.Value.Value.Contains("PARENT_TOP")) + { + field.ReplaceValue(field.Value.Value.Replace("PARENT_TOP", "0")); + } + else if (field.Value.Value.Contains("PARENT_LEFT")) + { + field.ReplaceValue(field.Value.Value.Replace("PARENT_LEFT", "0")); + } + } + + yield break; + } + } +} diff --git a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs index 8eac7063be2a..9432533ee273 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs @@ -90,6 +90,7 @@ public sealed class UpdatePath new AddSupportPowerBlockedCursor(), new MovePreviewFacing(), new RenameOnDeath(), + new RemoveParentTopParentLeftSubstitutions(), // Execute these rules last to avoid premature yaml merge crashes. new ReplaceCloakPalette(), diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs index 11989cb82830..ff614c8c64f9 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs @@ -520,8 +520,6 @@ static void RecalculateWidgetLayout(Widget w, bool insideScrollPanel = false) { "WINDOW_RIGHT", Game.Renderer.Resolution.Width }, { "WINDOW_BOTTOM", Game.Renderer.Resolution.Height }, { "PARENT_RIGHT", parentBounds.Width }, - { "PARENT_LEFT", parentBounds.Left }, - { "PARENT_TOP", parentBounds.Top }, { "PARENT_BOTTOM", parentBounds.Height } }; diff --git a/mods/common/chrome/ingame-debug-hpf.yaml b/mods/common/chrome/ingame-debug-hpf.yaml index ddc827fe6b13..af5a16cab3de 100644 --- a/mods/common/chrome/ingame-debug-hpf.yaml +++ b/mods/common/chrome/ingame-debug-hpf.yaml @@ -4,13 +4,12 @@ Container@HPF_OVERLAY: Height: 60 Children: DropDownButton@HPF_OVERLAY_LOCOMOTOR: - Y: PARENT_TOP Width: PARENT_RIGHT Height: 25 Text: dropdownbutton-hpf-overlay-locomotor Font: Regular DropDownButton@HPF_OVERLAY_CHECK: - Y: PARENT_TOP + 35 + Y: 35 Width: PARENT_RIGHT Height: 25 Text: dropdownbutton-hpf-overlay-check