diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 2c66eb7845..b18376aa1e 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -411,7 +411,6 @@ - @@ -424,6 +423,7 @@ + diff --git a/OpenRA.Mods.Common/Traits/Render/RenderBuildingSilo.cs b/OpenRA.Mods.Common/Traits/Render/RenderBuildingSilo.cs deleted file mode 100644 index 0652818378..0000000000 --- a/OpenRA.Mods.Common/Traits/Render/RenderBuildingSilo.cs +++ /dev/null @@ -1,61 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2015 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. For more information, - * see COPYING. - */ -#endregion - -using System.Collections.Generic; -using OpenRA.Graphics; -using OpenRA.Mods.Common.Graphics; -using OpenRA.Traits; - -namespace OpenRA.Mods.Common.Traits -{ - [Desc("Render trait for buildings that change the sprite according to the remaining resource storage capacity across all depots.")] - class RenderBuildingSiloInfo : RenderBuildingInfo - { - public override object Create(ActorInitializer init) { return new RenderBuildingSilo(init, this); } - - public override IEnumerable RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p) - { - // Show a static frame instead of animating all of the fullness states - var anim = new Animation(init.World, image, () => 0); - anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => 0); - - yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale); - } - } - - class RenderBuildingSilo : RenderBuilding, INotifyBuildComplete, INotifyOwnerChanged - { - readonly RenderBuildingSiloInfo info; - PlayerResources playerResources; - - public RenderBuildingSilo(ActorInitializer init, RenderBuildingSiloInfo info) - : base(init, info) - { - this.info = info; - playerResources = init.Self.Owner.PlayerActor.Trait(); - } - - public override void BuildingComplete(Actor self) - { - var animation = RenderSprites.NormalizeSequence(DefaultAnimation, self.GetDamageState(), info.Sequence); - - DefaultAnimation.PlayFetchIndex(animation, - () => playerResources.ResourceCapacity != 0 - ? ((10 * DefaultAnimation.CurrentSequence.Length - 1) * playerResources.Resources) / (10 * playerResources.ResourceCapacity) - : 0); - } - - public override void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) - { - playerResources = newOwner.PlayerActor.Trait(); - base.OnOwnerChanged(self, oldOwner, newOwner); - } - } -} diff --git a/OpenRA.Mods.Common/Traits/Render/WithSiloAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithSiloAnimation.cs new file mode 100644 index 0000000000..91eb2ea3aa --- /dev/null +++ b/OpenRA.Mods.Common/Traits/Render/WithSiloAnimation.cs @@ -0,0 +1,55 @@ +#region Copyright & License Information +/* + * Copyright 2007-2015 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. For more information, + * see COPYING. + */ +#endregion + +using System.Collections.Generic; +using OpenRA.Graphics; +using OpenRA.Mods.Common.Graphics; +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits +{ + [Desc("Render trait for buildings that change the sprite according to the remaining resource storage capacity across all depots.")] + class WithSiloAnimationInfo : ITraitInfo, Requires, Requires + { + public readonly int Stages = 10; + + public object Create(ActorInitializer init) { return new WithSiloAnimation(init, this); } + } + + class WithSiloAnimation : INotifyBuildComplete, INotifyOwnerChanged + { + readonly WithSiloAnimationInfo info; + readonly WithSpriteBody wsb; + PlayerResources playerResources; + + public WithSiloAnimation(ActorInitializer init, WithSiloAnimationInfo info) + { + this.info = info; + wsb = init.Self.Trait(); + playerResources = init.Self.Owner.PlayerActor.Trait(); + } + + public void BuildingComplete(Actor self) + { + var animation = wsb.NormalizeSequence(self, wsb.Info.Sequence); + + wsb.DefaultAnimation.PlayFetchIndex(animation, + () => playerResources.ResourceCapacity != 0 + ? ((info.Stages * wsb.DefaultAnimation.CurrentSequence.Length - 1) * playerResources.Resources) / (info.Stages * playerResources.ResourceCapacity) + : 0); + } + + public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) + { + playerResources = newOwner.PlayerActor.Trait(); + OnOwnerChanged(self, oldOwner, newOwner); + } + } +} diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs index c78ed091fd..979287a349 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs @@ -1841,6 +1841,40 @@ namespace OpenRA.Mods.Common.UtilityCommands if (rrb != null) rrb.Key = "-WithChargeAnimation"; } + + // Replaced RenderBuildingSilo with RenderSprites + WithSpriteBody + WithSiloAnimation (+AutoSelectionSize) + if (depth == 0) + { + var childKeySequence = new[] { "Sequence", "PauseOnLowPower" }; + + var rb = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("RenderBuildingSilo")); + if (rb != null) + { + rb.Key = "WithSiloAnimation"; + + var rsNodes = rb.Value.Nodes.Where(n => !childKeySequence.Contains(n.Key)).ToList(); + var wsbNodes = rb.Value.Nodes.Where(n => childKeySequence.Contains(n.Key)).ToList(); + + if (rsNodes.Any()) + node.Value.Nodes.Add(new MiniYamlNode("RenderSprites", new MiniYaml("", rsNodes))); + else + node.Value.Nodes.Add(new MiniYamlNode("RenderSprites", "")); + + if (wsbNodes.Any()) + node.Value.Nodes.Add(new MiniYamlNode("WithSpriteBody", new MiniYaml("", wsbNodes))); + else + node.Value.Nodes.Add(new MiniYamlNode("WithSpriteBody", "")); + + node.Value.Nodes.Add(new MiniYamlNode("AutoSelectionSize", "")); + + rb.Value.Nodes.RemoveAll(n => rsNodes.Contains(n)); + rb.Value.Nodes.RemoveAll(n => wsbNodes.Contains(n)); + } + + var rrb = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("-RenderBuildingSilo")); + if (rrb != null) + rrb.Key = "-WithSiloAnimation"; + } } UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); diff --git a/mods/cnc/rules/structures.yaml b/mods/cnc/rules/structures.yaml index 4f311e3596..b8ef1febf4 100644 --- a/mods/cnc/rules/structures.yaml +++ b/mods/cnc/rules/structures.yaml @@ -210,7 +210,10 @@ SILO: Range: 4c0 Bib: HasMinibib: Yes - RenderBuildingSilo: + RenderSprites: + WithSpriteBody: + AutoSelectionSize: + WithSiloAnimation: StoresResources: PipCount: 10 PipColor: Green @@ -223,6 +226,7 @@ SILO: RequiredForShortGame: false SelectionDecorations: VisualBounds: 49,30 + -WithMakeAnimation: PYLE: Inherits: ^BaseBuilding diff --git a/mods/d2k/rules/structures.yaml b/mods/d2k/rules/structures.yaml index ff1979c926..69de28c6ca 100644 --- a/mods/d2k/rules/structures.yaml +++ b/mods/d2k/rules/structures.yaml @@ -242,11 +242,13 @@ silo: RevealsShroud: Range: 4c0 -RenderBuilding: - RenderBuildingSilo: + RenderSprites: Image: silo.harkonnen FactionImages: atreides: silo.atreides ordos: silo.ordos + WithSpriteBody: + WithSiloAnimation: StoresResources: PipColor: green PipCount: 5 @@ -256,6 +258,7 @@ silo: Amount: -5 MustBeDestroyed: RequiredForShortGame: false + -WithMakeAnimation: light: Inherits: ^Building diff --git a/mods/ra/rules/structures.yaml b/mods/ra/rules/structures.yaml index 2922c4f633..46bdc3802c 100644 --- a/mods/ra/rules/structures.yaml +++ b/mods/ra/rules/structures.yaml @@ -982,7 +982,9 @@ SILO: Range: 4c0 Bib: HasMinibib: Yes - RenderBuildingSilo: + RenderSprites: + WithSpriteBody: + WithSiloAnimation: StoresResources: PipCount: 5 Capacity: 1500 @@ -990,6 +992,7 @@ SILO: -EmitInfantryOnSell: Power: Amount: -10 + -WithMakeAnimation: HPAD: Inherits: ^Building diff --git a/mods/ts/rules/shared-structures.yaml b/mods/ts/rules/shared-structures.yaml index ff6b9f2d33..e75941b725 100644 --- a/mods/ts/rules/shared-structures.yaml +++ b/mods/ts/rules/shared-structures.yaml @@ -127,11 +127,13 @@ GASILO: RevealsShroud: Range: 4c0 -RenderBuilding: - RenderBuildingSilo: + RenderSprites: Image: gasilo.gdi FactionImages: gdi: gasilo.gdi nod: gasilo.nod + WithSpriteBody: + WithSiloAnimation: WithIdleOverlay@UNDERLAY: Sequence: idle-underlay WithIdleOverlay@LIGHTS: @@ -143,6 +145,7 @@ GASILO: Amount: -10 SelectionDecorations: VisualBounds: 80, 48, -5, 0 + -WithMakeAnimation: ANYPOWER: AlwaysVisible: