Refer to editor marker tiles by their color.

This commit is contained in:
Paul Chote
2025-09-12 12:33:25 +01:00
committed by Gustas Kažukauskas
parent 994eddd46f
commit 831cce2f9c
6 changed files with 89 additions and 25 deletions

View File

@@ -163,9 +163,13 @@ namespace OpenRA.Mods.Common.Widgets
this.paintTiles = paintTiles; this.paintTiles = paintTiles;
this.markerLayerOverlay = markerLayerOverlay; this.markerLayerOverlay = markerLayerOverlay;
Text = type != null if (type != null)
? FluentProvider.GetMessage(AddedMarkerTiles, "count", paintTiles.Length, "type", type) {
: FluentProvider.GetMessage(RemovedMarkerTiles, "count", paintTiles.Length); var typeLabel = FluentProvider.GetMessage(markerLayerOverlay.Info.Colors.ElementAt(type.Value).Key);
Text = FluentProvider.GetMessage(AddedMarkerTiles, "count", paintTiles.Length, "type", typeLabel);
}
else
Text = FluentProvider.GetMessage(RemovedMarkerTiles, "count", paintTiles.Length);
} }
public void Execute() { } public void Execute() { }
@@ -202,7 +206,8 @@ namespace OpenRA.Mods.Common.Widgets
this.markerLayerOverlay = markerLayerOverlay; this.markerLayerOverlay = markerLayerOverlay;
tiles = markerLayerOverlay.Tiles[tile].ToImmutableArray(); tiles = markerLayerOverlay.Tiles[tile].ToImmutableArray();
Text = FluentProvider.GetMessage(ClearedSelectedMarkerTiles, "count", tiles.Length, "type", tile); var typeLabel = FluentProvider.GetMessage(markerLayerOverlay.Info.Colors.ElementAt(tile).Key);
Text = FluentProvider.GetMessage(ClearedSelectedMarkerTiles, "count", tiles.Length, "type", typeLabel);
} }
public void Execute() public void Execute()

View File

@@ -31,18 +31,19 @@ namespace OpenRA.Mods.Common.Traits
[Desc("The widget tree to open when the tool is selected.")] [Desc("The widget tree to open when the tool is selected.")]
public readonly string PanelWidget = "MARKER_TOOL_PANEL"; public readonly string PanelWidget = "MARKER_TOOL_PANEL";
[FluentReference(LintDictionaryReference.Keys)]
[Desc("A list of colors to be used for drawing.")] [Desc("A list of colors to be used for drawing.")]
public readonly Color[] Colors = public readonly Dictionary<string, Color> Colors = new()
[ {
Color.FromArgb(255, 0, 0), { "notification-added-marker-tiles-markers.red", Color.FromArgb(255, 0, 0) },
Color.FromArgb(255, 127, 0), { "notification-added-marker-tiles-markers.orange", Color.FromArgb(255, 127, 0) },
Color.FromArgb(255, 238, 70), { "notification-added-marker-tiles-markers.yellow", Color.FromArgb(255, 238, 70) },
Color.FromArgb(0, 255, 33), { "notification-added-marker-tiles-markers.green", Color.FromArgb(0, 255, 33) },
Color.FromArgb(0, 255, 255), { "notification-added-marker-tiles-markers.cyan", Color.FromArgb(0, 255, 255) },
Color.FromArgb(0, 42, 255), { "notification-added-marker-tiles-markers.blue", Color.FromArgb(0, 42, 255) },
Color.FromArgb(165, 0, 255), { "notification-added-marker-tiles-markers.purple", Color.FromArgb(165, 0, 255) },
Color.FromArgb(255, 0, 220), { "notification-added-marker-tiles-markers.magenta", Color.FromArgb(255, 0, 220) }
]; };
[Desc("Default alpha blend.")] [Desc("Default alpha blend.")]
public readonly int Alpha = 85; public readonly int Alpha = 85;
@@ -139,7 +140,7 @@ namespace OpenRA.Mods.Common.Traits
PanelWidget = info.PanelWidget; PanelWidget = info.PanelWidget;
tileAlpha = info.Alpha; tileAlpha = info.Alpha;
alphaBlendColors = new Color[info.Colors.Length]; alphaBlendColors = new Color[info.Colors.Count];
UpdateTileAlpha(); UpdateTileAlpha();
CellLayer = new CellLayer<int?>(map); CellLayer = new CellLayer<int?>(map);
@@ -184,8 +185,8 @@ namespace OpenRA.Mods.Common.Traits
void UpdateTileAlpha() void UpdateTileAlpha()
{ {
for (var i = 0; i < Info.Colors.Length; i++) for (var i = 0; i < Info.Colors.Count; i++)
alphaBlendColors[i] = Color.FromArgb(tileAlpha, Info.Colors[i]); alphaBlendColors[i] = Color.FromArgb(tileAlpha, Info.Colors.ElementAt(i).Value);
} }
public void ClearSelected(int tileType) public void ClearSelected(int tileType)

View File

@@ -0,0 +1,44 @@
#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 OpenRA.Primitives;
namespace OpenRA.Mods.Common.UpdateRules.Rules
{
/// <summary>
/// Adds color names to the editor history list.
/// </summary>
public class EditorMarkerTileLabels : UpdateRule, IBeforeUpdateActors
{
public override string Name => "Add labels to MarkerLayerOverlay colors.";
public override string Description => "Adds color names to the editor history list.";
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNodeBuilder actorNode)
{
foreach (var layerNode in actorNode.ChildrenMatching("MarkerLayerOverlay"))
{
foreach (var colorsNode in layerNode.ChildrenMatching("Colors"))
{
var colors = FieldLoader.GetValue<Color[]>("Colors", colorsNode.Value.Value);
colorsNode.Value.Value = null;
foreach (var color in colors)
{
var c = FieldSaver.FormatValue(color);
colorsNode.AddNode("notification-added-marker-tiles-markers." + c, c);
}
}
}
yield break;
}
}
}

View File

@@ -71,6 +71,7 @@ namespace OpenRA.Mods.Common.UpdateRules
// bleed only changes here. // bleed only changes here.
new ReplaceBaseAttackNotifier(), new ReplaceBaseAttackNotifier(),
new RemoveBuildingInfoAllowPlacementOnResources(), new RemoveBuildingInfoAllowPlacementOnResources(),
new EditorMarkerTileLabels(),
]), ]),
]; ];

View File

@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
tileColorPanel.RemoveChildren(); tileColorPanel.RemoveChildren();
var colors = markerLayerTrait.Info.Colors; var colors = markerLayerTrait.Info.Colors;
for (var colorIndex = 0; colorIndex < colors.Length; colorIndex++) for (var colorIndex = 0; colorIndex < colors.Count; colorIndex++)
{ {
var scrollItem = SetupColorSwatchItem(colorIndex, colorSwatchTemplate); var scrollItem = SetupColorSwatchItem(colorIndex, colorSwatchTemplate);
tileColorPanel.AddChild(scrollItem); tileColorPanel.AddChild(scrollItem);
@@ -92,8 +92,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
editor.SetBrush(new EditorMarkerLayerBrush(editor, index, worldRenderer)); editor.SetBrush(new EditorMarkerLayerBrush(editor, index, worldRenderer));
}); });
var colorWidget = item.Get<ColorBlockWidget>("TILE_PREVIEW"); var color = colors.ElementAt(index).Value;
colorWidget.GetColor = () => colors[index]; item.Get<ColorBlockWidget>("TILE_PREVIEW").GetColor = () => color;
return item; return item;
} }

View File

@@ -809,17 +809,30 @@ notification-added-tile = Added tile { $id }
notification-filled-tile = Filled with tile { $id } notification-filled-tile = Filled with tile { $id }
## EditorMarkerLayerBrush ## EditorMarkerLayerBrush
notification-added-marker-tiles-markers =
.red = red
.orange = orange
.yellow = yellow
.green = green
.cyan = cyan
.blue = blue
.purple = purple
.magenta = magenta
notification-added-marker-tiles = notification-added-marker-tiles =
{ $count -> { $count ->
[one] Added one marker tile of type { $type } [one] Added { $type } marker tile
*[other] Added { $count } marker tiles of type { $type } *[other] Added { $count } { $type } marker tiles
} }
notification-removed-marker-tiles = notification-removed-marker-tiles =
{ $count -> { $count ->
[one] Removed one marker tile [one] Removed marker tile
*[other] Removed { $count } marker tiles *[other] Removed { $count } marker tiles
} }
notification-cleared-selected-marker-tiles = Cleared { $count } marker tiles of type { $type } notification-cleared-selected-marker-tiles =
{ $count ->
[one] Cleared { $type } marker tile
*[other] Cleared { $count } { $type } marker tiles
}
notification-cleared-all-marker-tiles = Cleared { $count } marker tiles notification-cleared-all-marker-tiles = Cleared { $count } marker tiles
## EditorActionManager ## EditorActionManager