From 6b1adbacc41e72728a73d6806899371210a72848 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Sat, 18 Jun 2016 22:39:39 +0200 Subject: [PATCH 1/3] Make WithShadow public and upgradable --- OpenRA.Mods.Common/Traits/Render/WithShadow.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Render/WithShadow.cs b/OpenRA.Mods.Common/Traits/Render/WithShadow.cs index ce750760b4..adc123b775 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithShadow.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithShadow.cs @@ -16,25 +16,32 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Render { - [Desc("Clones the aircraft sprite with another palette below it.")] - class WithShadowInfo : ITraitInfo + [Desc("Clones the actor sprite with another palette below it.")] + public class WithShadowInfo : UpgradableTraitInfo { [PaletteReference] public readonly string Palette = "shadow"; - public object Create(ActorInitializer init) { return new WithShadow(this); } + public override object Create(ActorInitializer init) { return new WithShadow(this); } } - class WithShadow : IRenderModifier + public class WithShadow : UpgradableTrait, IRenderModifier { - WithShadowInfo info; + readonly WithShadowInfo info; public WithShadow(WithShadowInfo info) + : base(info) { this.info = info; } public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { + if (IsTraitDisabled) + return Enumerable.Empty(); + + if (self.IsDead || !self.IsInWorld) + return Enumerable.Empty(); + // Contrails shouldn't cast shadows var height = self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length; var shadowSprites = r.Where(s => !s.IsDecoration) From cc9b24d93289c707e0662bf67e691f11797d5be9 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Sat, 18 Jun 2016 22:41:00 +0200 Subject: [PATCH 2/3] Make WithShadow Offset and ZOffset customizable --- OpenRA.Mods.Common/Traits/Render/WithShadow.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Render/WithShadow.cs b/OpenRA.Mods.Common/Traits/Render/WithShadow.cs index adc123b775..1cd25cdd60 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithShadow.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithShadow.cs @@ -21,6 +21,12 @@ namespace OpenRA.Mods.Common.Traits.Render { [PaletteReference] public readonly string Palette = "shadow"; + [Desc("Shadow position offset relative to actor position (ground level).")] + public readonly WVec Offset = WVec.Zero; + + [Desc("Shadow Z offset relative to actor sprite.")] + public readonly int ZOffset = -5; + public override object Create(ActorInitializer init) { return new WithShadow(this); } } @@ -46,8 +52,8 @@ namespace OpenRA.Mods.Common.Traits.Render var height = self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length; var shadowSprites = r.Where(s => !s.IsDecoration) .Select(a => a.WithPalette(wr.Palette(info.Palette)) - .OffsetBy(new WVec(0, 0, -height)) - .WithZOffset(a.ZOffset + height) + .OffsetBy(info.Offset - new WVec(0, 0, height)) + .WithZOffset(a.ZOffset + (height + info.ZOffset)) .AsDecoration()); return shadowSprites.Concat(r); From 906bbc5439ed3a20c80d6c48136a7f4023ca4f22 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Sat, 18 Jun 2016 23:14:54 +0200 Subject: [PATCH 3/3] Give TD/RA aircraft custom shadow offsets To a) match 'light direction' of other actor art, and b) make the shadow still a little visible for landed aircraft. --- mods/cnc/rules/defaults.yaml | 6 ++++++ mods/ra/rules/defaults.yaml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/mods/cnc/rules/defaults.yaml b/mods/cnc/rules/defaults.yaml index 10a23a9828..8096acdb46 100644 --- a/mods/cnc/rules/defaults.yaml +++ b/mods/cnc/rules/defaults.yaml @@ -153,6 +153,8 @@ GenericName: Helicopter WithFacingSpriteBody: WithShadow: + Offset: 43, 128, 0 + ZOffset: -129 Hovers@CRUISING: UpgradeTypes: cruising UpgradeMinEnabledLevel: 1 @@ -427,6 +429,8 @@ ActorLostNotification: AttackMove: WithShadow: + Offset: 43, 128, 0 + ZOffset: -129 WithFacingSpriteBody: FlyAwayOnIdle: RejectsOrders: @@ -746,6 +750,8 @@ ^HelicopterHusk: Inherits: ^CommonHuskDefaults WithShadow: + Offset: 43, 128, 0 + ZOffset: -129 Aircraft: AirborneUpgrades: airborne CanHover: True diff --git a/mods/ra/rules/defaults.yaml b/mods/ra/rules/defaults.yaml index bca4783423..2b23090d49 100644 --- a/mods/ra/rules/defaults.yaml +++ b/mods/ra/rules/defaults.yaml @@ -386,6 +386,8 @@ Tooltip: GenericName: Plane WithShadow: + Offset: 43, 128, 0 + ZOffset: -129 WithFacingSpriteBody: MustBeDestroyed: Voiced: @@ -690,6 +692,8 @@ ^PlaneHusk: Inherits: ^BasicHusk WithShadow: + Offset: 43, 128, 0 + ZOffset: -129 Tooltip: GenericName: Destroyed Plane Aircraft: @@ -703,6 +707,8 @@ ^HelicopterHusk: Inherits: ^BasicHusk WithShadow: + Offset: 43, 128, 0 + ZOffset: -129 Tooltip: GenericName: Destroyed Helicopter Aircraft: