Aligns the naming conventions defined in editorconfig (dotnet_naming_style, dotnet_naming_symbols, dotnet_naming_rule) which are reported under the IDE1006 rule with the existing StyleCop rules from the SA13XX range. This ensures the two rulesets agree when rejecting and accepting naming conventions within the IDE, with a few edges cases where only one ruleset can enforce the convention. IDE1006 allows use to specify a naming convention for type parameters, const locals and protected readonly fields which SA13XX cannot enforce. Some StyleCop SA13XX rules such as SA1309 'Field names should not begin with underscore' are not possible to enforce with the naming rules of IDE1006. Therefore we enable the IDE1006 as a build time warning to enforce conventions and extend them. We disable SA13XX rules that can now be covered by IDE1006 to avoid double-reporting but leave the remaining SA13XX rules that cover additional cases enabled. We also re-enable the SA1311 rule convention but enforce it via IDE1006, requiring some violations to be fixed or duplication of existing suppressions. Most violations fixes are trivial renames with the following exception. In ActorInitializer.cs, we prefer to make the fields private instead. ValueActorInit provides a publicly accessible property for access and OwnerInit provides a publicly accessible method. Health.cs is adjusted to access the property base instead when overriding. The reflection calls must be adjusted to target the base class specifically, as searching for a private field from the derived class will fail to locate it on the base class. Unused suppressions were removed.
135 lines
5.1 KiB
C#
135 lines
5.1 KiB
C#
#region Copyright & License Information
|
|
/*
|
|
* Copyright 2007-2021 The OpenRA Developers (see AUTHORS)
|
|
* 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;
|
|
using OpenRA.Graphics;
|
|
using OpenRA.Mods.Common.Orders;
|
|
using OpenRA.Primitives;
|
|
using OpenRA.Traits;
|
|
|
|
namespace OpenRA.Mods.Common.Traits
|
|
{
|
|
[Desc("Creates a building placement preview showing only the building footprint.")]
|
|
public class FootprintPlaceBuildingPreviewInfo : TraitInfo<FootprintPlaceBuildingPreview>, IPlaceBuildingPreviewGeneratorInfo
|
|
{
|
|
[PaletteReference]
|
|
[Desc("Palette to use for rendering the placement sprite.")]
|
|
public readonly string Palette = TileSet.TerrainPaletteInternalName;
|
|
|
|
[Desc("Custom opacity to apply to the placement sprite.")]
|
|
public readonly float FootprintAlpha = 1f;
|
|
|
|
[Desc("Custom opacity to apply to the line-build placement sprite.")]
|
|
public readonly float LineBuildFootprintAlpha = 1f;
|
|
|
|
protected virtual IPlaceBuildingPreview CreatePreview(WorldRenderer wr, ActorInfo ai, TypeDictionary init)
|
|
{
|
|
return new FootprintPlaceBuildingPreviewPreview(wr, ai, this, init);
|
|
}
|
|
|
|
IPlaceBuildingPreview IPlaceBuildingPreviewGeneratorInfo.CreatePreview(WorldRenderer wr, ActorInfo ai, TypeDictionary init)
|
|
{
|
|
return CreatePreview(wr, ai, init);
|
|
}
|
|
}
|
|
|
|
public class FootprintPlaceBuildingPreview { }
|
|
|
|
public class FootprintPlaceBuildingPreviewPreview : IPlaceBuildingPreview
|
|
{
|
|
protected readonly ActorInfo ActorInfo;
|
|
protected readonly WVec CenterOffset;
|
|
readonly FootprintPlaceBuildingPreviewInfo info;
|
|
readonly IPlaceBuildingDecorationInfo[] decorations;
|
|
readonly int2 topLeftScreenOffset;
|
|
readonly Sprite validTile, blockedTile;
|
|
readonly float validAlpha, blockedAlpha;
|
|
|
|
public FootprintPlaceBuildingPreviewPreview(WorldRenderer wr, ActorInfo ai, FootprintPlaceBuildingPreviewInfo info, TypeDictionary init)
|
|
{
|
|
ActorInfo = ai;
|
|
this.info = info;
|
|
decorations = ActorInfo.TraitInfos<IPlaceBuildingDecorationInfo>().ToArray();
|
|
|
|
var world = wr.World;
|
|
CenterOffset = ActorInfo.TraitInfo<BuildingInfo>().CenterOffset(world);
|
|
topLeftScreenOffset = -wr.ScreenPxOffset(CenterOffset);
|
|
|
|
var tileset = world.Map.Tileset.ToLowerInvariant();
|
|
if (world.Map.Rules.Sequences.HasSequence("overlay", $"build-valid-{tileset}"))
|
|
{
|
|
var validSequence = world.Map.Rules.Sequences.GetSequence("overlay", $"build-valid-{tileset}");
|
|
validTile = validSequence.GetSprite(0);
|
|
validAlpha = validSequence.GetAlpha(0);
|
|
}
|
|
else
|
|
{
|
|
var validSequence = world.Map.Rules.Sequences.GetSequence("overlay", "build-valid");
|
|
validTile = validSequence.GetSprite(0);
|
|
validAlpha = validSequence.GetAlpha(0);
|
|
}
|
|
|
|
var blockedSequence = world.Map.Rules.Sequences.GetSequence("overlay", "build-invalid");
|
|
blockedTile = blockedSequence.GetSprite(0);
|
|
blockedAlpha = blockedSequence.GetAlpha(0);
|
|
}
|
|
|
|
protected virtual void TickInner() { }
|
|
|
|
protected virtual IEnumerable<IRenderable> RenderFootprint(WorldRenderer wr, CPos topLeft, Dictionary<CPos, PlaceBuildingCellType> footprint,
|
|
PlaceBuildingCellType filter = PlaceBuildingCellType.Invalid | PlaceBuildingCellType.Valid | PlaceBuildingCellType.LineBuild)
|
|
{
|
|
var palette = wr.Palette(info.Palette);
|
|
var topLeftPos = wr.World.Map.CenterOfCell(topLeft);
|
|
foreach (var c in footprint)
|
|
{
|
|
if ((c.Value & filter) == 0)
|
|
continue;
|
|
|
|
var tile = (c.Value & PlaceBuildingCellType.Invalid) != 0 ? blockedTile : validTile;
|
|
var sequenceAlpha = (c.Value & PlaceBuildingCellType.Invalid) != 0 ? blockedAlpha : validAlpha;
|
|
var pos = wr.World.Map.CenterOfCell(c.Key);
|
|
var offset = new WVec(0, 0, topLeftPos.Z - pos.Z);
|
|
var traitAlpha = (c.Value & PlaceBuildingCellType.LineBuild) != 0 ? info.LineBuildFootprintAlpha : info.FootprintAlpha;
|
|
yield return new SpriteRenderable(tile, pos, offset, -511, palette, 1f, sequenceAlpha * traitAlpha, float3.Ones, TintModifiers.IgnoreWorldTint, true);
|
|
}
|
|
}
|
|
|
|
protected virtual IEnumerable<IRenderable> RenderAnnotations(WorldRenderer wr, CPos topLeft)
|
|
{
|
|
var centerPosition = wr.World.Map.CenterOfCell(topLeft) + CenterOffset;
|
|
foreach (var d in decorations)
|
|
foreach (var r in d.RenderAnnotations(wr, wr.World, ActorInfo, centerPosition))
|
|
yield return r;
|
|
}
|
|
|
|
protected virtual IEnumerable<IRenderable> RenderInner(WorldRenderer wr, CPos topLeft, Dictionary<CPos, PlaceBuildingCellType> footprint)
|
|
{
|
|
return RenderFootprint(wr, topLeft, footprint);
|
|
}
|
|
|
|
IEnumerable<IRenderable> IPlaceBuildingPreview.Render(WorldRenderer wr, CPos topLeft, Dictionary<CPos, PlaceBuildingCellType> footprint)
|
|
{
|
|
return RenderInner(wr, topLeft, footprint);
|
|
}
|
|
|
|
IEnumerable<IRenderable> IPlaceBuildingPreview.RenderAnnotations(WorldRenderer wr, CPos topLeft)
|
|
{
|
|
return RenderAnnotations(wr, topLeft);
|
|
}
|
|
|
|
void IPlaceBuildingPreview.Tick() { TickInner(); }
|
|
|
|
int2 IPlaceBuildingPreview.TopLeftScreenOffset => topLeftScreenOffset;
|
|
}
|
|
}
|