Skip to content

Commit

Permalink
Rename *_RIGHT to *_WIDTH and *_BOTTOM to *_HEIGHT in integer express…
Browse files Browse the repository at this point in the history
…ions for widgets

The terms "width" and "height" are clearer and they match what the values actually represent (window or parent width/height). The YAML changes are generated with the update rule.
  • Loading branch information
dragunoff authored and PunkPun committed Oct 7, 2024
1 parent bb17cfa commit 27252df
Show file tree
Hide file tree
Showing 125 changed files with 3,503 additions and 3,457 deletions.
8 changes: 4 additions & 4 deletions OpenRA.Game/Widgets/Widget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ public virtual void Initialize(WidgetArgs args)
new Dictionary<string, int>((Dictionary<string, int>)subs) :
new Dictionary<string, int>();

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_BOTTOM", parentBounds.Height);
substitutions.Add("WINDOW_WIDTH", Game.Renderer.Resolution.Width);
substitutions.Add("WINDOW_HEIGHT", Game.Renderer.Resolution.Height);
substitutions.Add("PARENT_WIDTH", parentBounds.Width);
substitutions.Add("PARENT_HEIGHT", parentBounds.Height);

var readOnlySubstitutions = new ReadOnlyDictionary<string, int>(substitutions);
var width = Width?.Evaluate(readOnlySubstitutions) ?? 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#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 RenameWidgetSubstitutions : UpdateRule
{
public override string Name => "Rename *_RIGHT to *_WIDTH and *_BOTTOM to *_HEIGHT in integer expressions for widgets.";

public override string Description =>
"PARENT_RIGHT -> PARENT_WIDTH, PARENT_BOTTOM -> PARENT_HEIGHT, " +
"WINDOW_RIGHT -> WINDOW_WIDTH, WINDOW_BOTTOM -> WINDOW_HEIGHT " +
"in integer expressions for width, height and position.";

public override IEnumerable<string> 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)
{
field.ReplaceValue(field.Value.Value.Replace("PARENT_RIGHT", "PARENT_WIDTH"));
field.ReplaceValue(field.Value.Value.Replace("PARENT_BOTTOM", "PARENT_HEIGHT"));
field.ReplaceValue(field.Value.Value.Replace("WINDOW_RIGHT", "WINDOW_WIDTH"));
field.ReplaceValue(field.Value.Value.Replace("WINDOW_BOTTOM", "WINDOW_HEIGHT"));
}

yield break;
}
}
}
1 change: 1 addition & 0 deletions OpenRA.Mods.Common/UpdateRules/UpdatePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public sealed class UpdatePath
new MovePreviewFacing(),
new RenameOnDeath(),
new RemoveParentTopParentLeftSubstitutions(),
new RenameWidgetSubstitutions(),

// Execute these rules last to avoid premature yaml merge crashes.
new ReplaceCloakPalette(),
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void ToggleFilterFlag(MPGameFilters f)
{
// HACK: MULTIPLAYER_FILTER_PANEL doesn't follow our normal procedure for dropdown creation
// but we still need to be able to set the dropdown width based on the parent
// The yaml should use PARENT_RIGHT instead of DROPDOWN_WIDTH
// The yaml should use PARENT_WIDTH instead of DROPDOWN_WIDTH
var filtersPanel = Ui.LoadWidget("MULTIPLAYER_FILTER_PANEL", filtersButton, new WidgetArgs());
filtersButton.Children.Remove(filtersPanel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,10 @@ static void RecalculateWidgetLayout(Widget w, bool insideScrollPanel = false)

var substitutions = new Dictionary<string, int>
{
{ "WINDOW_RIGHT", Game.Renderer.Resolution.Width },
{ "WINDOW_BOTTOM", Game.Renderer.Resolution.Height },
{ "PARENT_RIGHT", parentBounds.Width },
{ "PARENT_BOTTOM", parentBounds.Height }
{ "WINDOW_WIDTH", Game.Renderer.Resolution.Width },
{ "WINDOW_HEIGHT", Game.Renderer.Resolution.Height },
{ "PARENT_WIDTH", parentBounds.Width },
{ "PARENT_HEIGHT", parentBounds.Height }
};

var readOnlySubstitutions = new ReadOnlyDictionary<string, int>(substitutions);
Expand Down
58 changes: 29 additions & 29 deletions mods/cnc/chrome/assetbrowser.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
Container@ASSETBROWSER_PANEL:
Logic: AssetBrowserLogic
X: (WINDOW_RIGHT - WIDTH) / 2
Y: (WINDOW_BOTTOM - HEIGHT) / 2
X: (WINDOW_WIDTH - WIDTH) / 2
Y: (WINDOW_HEIGHT - HEIGHT) / 2
Width: 900
Height: 540
Children:
LogicTicker@ANIMATION_TICKER:
Label@ASSETBROWSER_TITLE:
Width: PARENT_RIGHT
Width: PARENT_WIDTH
Height: 25
Y: 0 - 34
Font: BigBold
Contrast: true
Align: Center
Text: label-assetbrowser-panel-title
Background@bg:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Width: PARENT_WIDTH
Height: PARENT_HEIGHT
Background: panel-black
Children:
Label@SOURCE_SELECTOR_DESC:
Expand Down Expand Up @@ -59,86 +59,86 @@ Container@ASSETBROWSER_PANEL:
X: 15
Y: 155
Width: 195
Height: PARENT_BOTTOM - 205
Height: PARENT_HEIGHT - 205
CollapseHiddenChildren: True
Children:
ScrollItem@ASSET_TEMPLATE:
Width: PARENT_RIGHT - 27
Width: PARENT_WIDTH - 27
Height: 25
X: 2
Visible: false
EnableChildMouseOver: True
Children:
LabelWithTooltip@TITLE:
X: 10
Width: PARENT_RIGHT - 15
Width: PARENT_WIDTH - 15
Height: 25
TooltipContainer: TOOLTIP_CONTAINER
TooltipTemplate: SIMPLE_TOOLTIP
Label@SPRITE_SCALE:
X: PARENT_RIGHT - WIDTH - 440
X: PARENT_WIDTH - WIDTH - 440
Y: 31
Width: 50
Height: 25
Font: Bold
Align: Left
Text: label-bg-sprite-scale
Slider@SPRITE_SCALE_SLIDER:
X: PARENT_RIGHT - WIDTH - 330
X: PARENT_WIDTH - WIDTH - 330
Y: 35
Width: 100
Height: 20
MinimumValue: 0.5
MaximumValue: 4
Label@PALETTE_DESC:
X: PARENT_RIGHT - WIDTH - 270
X: PARENT_WIDTH - WIDTH - 270
Y: 31
Width: 150
Height: 25
Font: Bold
Align: Right
Text: label-bg-palette-desc
DropDownButton@PALETTE_SELECTOR:
X: PARENT_RIGHT - WIDTH - 110
X: PARENT_WIDTH - WIDTH - 110
Y: 30
Width: 150
Height: 25
Font: Bold
DropDownButton@COLOR:
X: PARENT_RIGHT - WIDTH - 15
X: PARENT_WIDTH - WIDTH - 15
Y: 30
Width: 80
Height: 25
Children:
ColorBlock@COLORBLOCK:
X: 5
Y: 6
Width: PARENT_RIGHT - 35
Height: PARENT_BOTTOM - 12
Width: PARENT_WIDTH - 35
Height: PARENT_HEIGHT - 12
Background@SPRITE_BG:
X: 225
Y: 65
Width: PARENT_RIGHT - 195 - 45
Height: PARENT_BOTTOM - 115
Width: PARENT_WIDTH - 195 - 45
Height: PARENT_HEIGHT - 115
Background: scrollpanel-bg
Children:
Sprite@SPRITE:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Width: PARENT_WIDTH
Height: PARENT_HEIGHT
VideoPlayer@PLAYER:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Width: PARENT_WIDTH
Height: PARENT_HEIGHT
AspectRatio: 1
Label@ERROR:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Width: PARENT_WIDTH
Height: PARENT_HEIGHT
Align: Center
Visible: false
Text: label-sprite-bg-error
Container@FRAME_SELECTOR:
X: 225
Y: PARENT_BOTTOM - 40
Width: PARENT_RIGHT - 225
Y: PARENT_HEIGHT - 40
Width: PARENT_WIDTH - 225
Children:
Button@BUTTON_PREV:
Width: 26
Expand Down Expand Up @@ -208,19 +208,19 @@ Container@ASSETBROWSER_PANEL:
Slider@FRAME_SLIDER:
X: 140
Y: 3
Width: PARENT_RIGHT - 140 - 85
Width: PARENT_WIDTH - 140 - 85
Height: 20
MinimumValue: 0
Label@FRAME_COUNT:
X: PARENT_RIGHT - WIDTH + 5
X: PARENT_WIDTH - WIDTH + 5
Y: 0
Width: 80
Height: 25
Font: TinyBold
Align: Left
Button@CLOSE_BUTTON:
Key: escape
Y: PARENT_BOTTOM - 1
Y: PARENT_HEIGHT - 1
Width: 140
Height: 35
Text: button-back
Expand All @@ -235,5 +235,5 @@ ScrollPanel@ASSET_TYPES_PANEL:
Checkbox@ASSET_TYPE_TEMPLATE:
X: 5
Y: 5
Width: PARENT_RIGHT - 29
Width: PARENT_WIDTH - 29
Height: 20
42 changes: 21 additions & 21 deletions mods/cnc/chrome/color-picker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,78 +29,78 @@ Background@COLOR_CHOOSER:
Animate: true
Button@MIXER_TAB_BUTTON:
X: 5
Y: PARENT_BOTTOM - 30
Y: PARENT_HEIGHT - 30
Height: 25
Width: 80
Text: button-color-chooser-mixer-tab
Font: Bold
Button@PALETTE_TAB_BUTTON:
X: 90
Y: PARENT_BOTTOM - 30
Y: PARENT_HEIGHT - 30
Height: 25
Width: 80
Text: button-color-chooser-palette-tab
Font: Bold
Container@MIXER_TAB:
X: 5
Y: 5
Width: PARENT_RIGHT - 91
Height: PARENT_BOTTOM - 34
Width: PARENT_WIDTH - 91
Height: PARENT_HEIGHT - 34
Children:
Background@HUEBG:
Background: panel-black
X: 0
Y: 0
Width: PARENT_RIGHT
Width: PARENT_WIDTH
Height: 17
Children:
HueSlider@HUE_SLIDER:
X: 2
Y: 2
Width: PARENT_RIGHT - 4
Height: PARENT_BOTTOM - 4
Width: PARENT_WIDTH - 4
Height: PARENT_HEIGHT - 4
Ticks: 5
Background@MIXERBG:
Background: panel-black
X: 0
Y: 21
Width: PARENT_RIGHT
Height: PARENT_BOTTOM - 21
Width: PARENT_WIDTH
Height: PARENT_HEIGHT - 21
Children:
ColorMixer@MIXER:
X: 2
Y: 2
Width: PARENT_RIGHT - 4
Height: PARENT_BOTTOM - 4
Width: PARENT_WIDTH - 4
Height: PARENT_HEIGHT - 4
Background@PALETTE_TAB:
Background: panel-black
X: 5
Y: 5
Width: PARENT_RIGHT - 91
Height: PARENT_BOTTOM - 34
Width: PARENT_WIDTH - 91
Height: PARENT_HEIGHT - 34
Visible: false
Children:
Container@PALETTE_TAB_PANEL:
X: 0
Y: 0
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Width: PARENT_WIDTH
Height: PARENT_HEIGHT
Children:
Background@PRESET_HEADER:
Background: panel-black
Width: PARENT_RIGHT - 4
Width: PARENT_WIDTH - 4
Height: 13
X: 2
Y: 2
Children:
Label@LABEL:
Font: TinyBold
Width: PARENT_RIGHT
Width: PARENT_WIDTH
Height: 13
Align: Center
Text: label-preset-header
Container@PRESET_AREA:
Width: PARENT_RIGHT - 4
Width: PARENT_WIDTH - 4
Height: 58
X: 2
Y: 16
Expand All @@ -114,19 +114,19 @@ Background@COLOR_CHOOSER:
ClickSound: ClickSound
Background@CUSTOM_HEADER:
Background: panel-black
Width: PARENT_RIGHT - 4
Width: PARENT_WIDTH - 4
Height: 13
X: 2
Y: 71
Children:
Label@LABEL:
Font: TinyBold
Width: PARENT_RIGHT
Width: PARENT_WIDTH
Height: 13
Align: Center
Text: label-custom-header
Container@CUSTOM_AREA:
Width: PARENT_RIGHT - 4
Width: PARENT_WIDTH - 4
Height: 31
X: 2
Y: 85
Expand Down
Loading

0 comments on commit 27252df

Please sign in to comment.