Remove RenderBuilding

This commit is contained in:
reaperrr
2015-07-15 07:29:45 +02:00
parent bf51e0600d
commit 9da56f51e2
42 changed files with 196 additions and 248 deletions

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Activities
continue;
// HACK to check if we are on the helipad/airfield/etc.
var hostBuilding = self.World.ActorMap.GetUnitsAt(self.Location).FirstOrDefault(a => a.HasTrait<RenderBuilding>());
var hostBuilding = self.World.ActorMap.GetUnitsAt(self.Location).FirstOrDefault(a => a.HasTrait<Building>());
if (hostBuilding == null || !hostBuilding.IsInWorld)
return NextActivity;
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Activities
if (!pool.GiveAmmo())
continue;
hostBuilding.Trait<RenderBuilding>().PlayCustomAnim(hostBuilding, "active");
hostBuilding.Trait<WithSpriteBody>().PlayCustomAnimation(hostBuilding, "active");
var sound = pool.Info.RearmSound;
if (sound != null)

View File

@@ -405,7 +405,6 @@
<Compile Include="Traits\Render\AutoSelectionSize.cs" />
<Compile Include="Traits\Render\Hovers.cs" />
<Compile Include="Traits\Render\LeavesTrails.cs" />
<Compile Include="Traits\Render\RenderBuilding.cs" />
<Compile Include="Traits\Render\RenderSpritesEditorOnly.cs" />
<Compile Include="Traits\Render\WithTurretedSpriteBody.cs" />
<Compile Include="Traits\Render\RenderNameTag.cs" />

View File

@@ -105,7 +105,8 @@ namespace OpenRA.Mods.Common.Traits
// Harvester was killed while unloading
if (dockedHarv != null && dockedHarv.IsDead)
{
self.Trait<RenderBuilding>().CancelCustomAnim(self);
var wsb = self.Trait<WithSpriteBody>();
wsb.PlayCustomAnimation(self, wsb.Info.Sequence);
dockedHarv = null;
}

View File

@@ -1,81 +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;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Render trait for stationary objects that can be placed from the build palette.")]
public class RenderBuildingInfo : RenderSimpleInfo, Requires<BuildingInfo>
{
public readonly bool PauseOnLowPower = false;
public override object Create(ActorInitializer init) { return new RenderBuilding(init, this); }
}
public class RenderBuilding : RenderSimple, INotifyDamageStateChanged, INotifyBuildComplete
{
RenderBuildingInfo info;
public RenderBuilding(ActorInitializer init, RenderBuildingInfo info)
: this(init, info, () => 0) { }
public RenderBuilding(ActorInitializer init, RenderBuildingInfo info, Func<int> baseFacing)
: base(init, info, baseFacing)
{
var self = init.Self;
this.info = info;
DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence));
}
public virtual void BuildingComplete(Actor self)
{
DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence));
if (info.PauseOnLowPower)
DefaultAnimation.Paused = () =>
self.IsDisabled() && DefaultAnimation.CurrentSequence.Name == NormalizeSequence(self, info.Sequence);
}
public void PlayCustomAnimThen(Actor self, string name, Action a)
{
DefaultAnimation.PlayThen(NormalizeSequence(self, name),
() => { DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence)); a(); });
}
public void PlayCustomAnimRepeating(Actor self, string name)
{
DefaultAnimation.PlayThen(NormalizeSequence(self, name),
() => PlayCustomAnimRepeating(self, name));
}
public void PlayCustomAnimBackwards(Actor self, string name, Action a)
{
DefaultAnimation.PlayBackwardsThen(NormalizeSequence(self, name),
() => { DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence)); a(); });
}
public void CancelCustomAnim(Actor self)
{
DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence));
}
public virtual void DamageStateChanged(Actor self, AttackInfo e)
{
if (DefaultAnimation.CurrentSequence != null)
DefaultAnimation.ReplaceAnim(NormalizeSequence(self, DefaultAnimation.CurrentSequence.Name));
}
}
}

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Replaces the idle animation of a building.")]
public class WithActiveAnimationInfo : ITraitInfo, Requires<RenderBuildingInfo>
public class WithActiveAnimationInfo : ITraitInfo, Requires<WithSpriteBodyInfo>
{
[Desc("Sequence name to use")]
[SequenceReference] public readonly string Sequence = "active";
@@ -31,11 +31,11 @@ namespace OpenRA.Mods.Common.Traits
public class WithActiveAnimation : ITick, INotifyBuildComplete, INotifySold
{
readonly WithActiveAnimationInfo info;
readonly RenderBuilding renderBuilding;
readonly WithSpriteBody wsb;
public WithActiveAnimation(Actor self, WithActiveAnimationInfo info)
{
renderBuilding = self.Trait<RenderBuilding>();
wsb = self.Trait<WithSpriteBody>();
this.info = info;
}
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits
if (--ticks <= 0)
{
if (!(info.PauseOnLowPower && self.IsDisabled()))
renderBuilding.PlayCustomAnim(self, info.Sequence);
wsb.PlayCustomAnimation(self, info.Sequence);
ticks = info.Interval;
}
}

View File

@@ -13,10 +13,10 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Changes the animation when the actor constructed a building.")]
public class WithBuildingPlacedAnimationInfo : ITraitInfo, Requires<RenderSimpleInfo>
public class WithBuildingPlacedAnimationInfo : ITraitInfo, Requires<WithSpriteBodyInfo>
{
[Desc("Sequence name to use")]
[SequenceReference] public readonly string Sequence = "build";
[Desc("Sequence name to use"), SequenceReference]
public readonly string Sequence = "build";
public object Create(ActorInitializer init) { return new WithBuildingPlacedAnimation(init.Self, this); }
}
@@ -24,13 +24,13 @@ namespace OpenRA.Mods.Common.Traits
public class WithBuildingPlacedAnimation : INotifyBuildingPlaced, INotifyBuildComplete
{
readonly WithBuildingPlacedAnimationInfo info;
readonly RenderSimple renderSimple;
readonly WithSpriteBody wsb;
bool buildComplete;
public WithBuildingPlacedAnimation(Actor self, WithBuildingPlacedAnimationInfo info)
{
this.info = info;
renderSimple = self.Trait<RenderSimple>();
wsb = self.Trait<WithSpriteBody>();
buildComplete = !self.HasTrait<Building>();
}
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
public void BuildingPlaced(Actor self)
{
if (buildComplete)
renderSimple.PlayCustomAnim(self, info.Sequence);
wsb.PlayCustomAnimation(self, info.Sequence, () => wsb.CancelCustomAnimation(self));
}
}
}

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Replaces the sprite during construction.")]
public class WithMakeAnimationInfo : ITraitInfo, Requires<BuildingInfo>, Requires<RenderBuildingInfo>
public class WithMakeAnimationInfo : ITraitInfo, Requires<WithSpriteBodyInfo>
{
[Desc("Sequence name to use")]
[SequenceReference] public readonly string Sequence = "make";
@@ -29,18 +29,18 @@ namespace OpenRA.Mods.Common.Traits
public class WithMakeAnimation
{
readonly WithMakeAnimationInfo info;
readonly RenderBuilding renderBuilding;
readonly WithSpriteBody wsb;
public WithMakeAnimation(ActorInitializer init, WithMakeAnimationInfo info)
{
this.info = info;
var self = init.Self;
renderBuilding = self.Trait<RenderBuilding>();
wsb = self.Trait<WithSpriteBody>();
var building = self.Trait<Building>();
if (!building.SkipMakeAnimation)
var building = self.TraitOrDefault<Building>();
if (building != null && !building.SkipMakeAnimation)
{
renderBuilding.PlayCustomAnimThen(self, info.Sequence, () =>
wsb.PlayCustomAnimation(self, info.Sequence, () =>
{
building.NotifyBuildingComplete(self);
});
@@ -49,10 +49,10 @@ namespace OpenRA.Mods.Common.Traits
public void Reverse(Actor self, Activity activity, bool queued = true)
{
renderBuilding.PlayCustomAnimBackwards(self, info.Sequence, () =>
wsb.PlayCustomAnimationBackwards(self, info.Sequence, () =>
{
// avoids visual glitches as we wait for the actor to get destroyed
renderBuilding.DefaultAnimation.PlayFetchIndex(info.Sequence, () => 0);
wsb.DefaultAnimation.PlayFetchIndex(info.Sequence, () => 0);
self.QueueActivity(queued, activity);
});
}

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Replaces the building animation when it repairs a unit.")]
public class WithRepairAnimationInfo : ITraitInfo, Requires<RenderBuildingInfo>
public class WithRepairAnimationInfo : ITraitInfo, Requires<WithSpriteBodyInfo>
{
[Desc("Sequence name to use")]
[SequenceReference] public readonly string Sequence = "active";
@@ -36,9 +36,9 @@ namespace OpenRA.Mods.Common.Traits
public void Repairing(Actor self, Actor host)
{
var building = host.TraitOrDefault<RenderBuilding>();
if (building != null && !(info.PauseOnLowPower && self.IsDisabled()))
building.PlayCustomAnim(host, info.Sequence);
var spriteBody = host.TraitOrDefault<WithSpriteBody>();
if (spriteBody != null && !(info.PauseOnLowPower && self.IsDisabled()))
spriteBody.PlayCustomAnimation(host, info.Sequence);
}
}
}

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Displays the fill status of PlayerResources with an extra sprite overlay on the actor.")]
class WithResourcesInfo : ITraitInfo, Requires<RenderSimpleInfo>
class WithResourcesInfo : ITraitInfo, Requires<WithSpriteBodyInfo>, Requires<RenderSpritesInfo>
{
[Desc("Sequence name to use")]
[SequenceReference] public readonly string Sequence = "resources";
@@ -26,7 +26,8 @@ namespace OpenRA.Mods.Common.Traits
{
readonly WithResourcesInfo info;
readonly AnimationWithOffset anim;
readonly RenderSimple rs;
readonly RenderSprites rs;
readonly WithSpriteBody wsb;
PlayerResources playerResources;
bool buildComplete;
@@ -34,7 +35,8 @@ namespace OpenRA.Mods.Common.Traits
public WithResources(Actor self, WithResourcesInfo info)
{
this.info = info;
rs = self.Trait<RenderSimple>();
rs = self.Trait<RenderSprites>();
wsb = self.Trait<WithSpriteBody>();
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
var a = new Animation(self.World, rs.GetImage(self));
@@ -55,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits
public void DamageStateChanged(Actor self, AttackInfo e)
{
if (anim.Animation.CurrentSequence != null)
anim.Animation.ReplaceAnim(rs.NormalizeSequence(self, info.Sequence));
anim.Animation.ReplaceAnim(wsb.NormalizeSequence(self, info.Sequence));
}
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)

View File

@@ -19,11 +19,11 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Default trait for rendering sprite-based actors.")]
public class WithSpriteBodyInfo : UpgradableTraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>
{
[Desc("Animation to play when the actor is created.")]
[SequenceReference] public readonly string StartSequence = null;
[Desc("Animation to play when the actor is created."), SequenceReference]
public readonly string StartSequence = null;
[Desc("Animation to play when the actor is idle.")]
[SequenceReference] public readonly string Sequence = "idle";
[Desc("Animation to play when the actor is idle."), SequenceReference]
public readonly string Sequence = "idle";
[Desc("Pause animation when actor is disabled.")]
public readonly bool PauseAnimationWhenDisabled = false;

View File

@@ -30,6 +30,9 @@ namespace OpenRA.Mods.Common.Traits
public readonly int Range = 1;
public readonly string GrantUpgradeSound = "ironcur9.aud";
[Desc("Sequence to play for granting actor when activated."), SequenceReference]
public readonly string GrantUpgradeSequence = "active";
public override object Create(ActorInitializer init) { return new GrantUpgradePower(init.Self, this); }
}
@@ -53,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits
{
base.Activate(self, order, manager);
self.Trait<RenderBuilding>().PlayCustomAnim(self, "active");
self.Trait<WithSpriteBody>().PlayCustomAnimation(self, info.GrantUpgradeSequence);
Sound.Play(info.GrantUpgradeSound, self.World.Map.CenterOfCell(order.TargetLocation));

View File

@@ -47,6 +47,10 @@ namespace OpenRA.Mods.Common.Traits
public readonly string FlashType = null;
[SequenceReference]
[Desc("Sequence the launching actor should play when activating this power.")]
public readonly string ActivationSequence = "active";
public override object Create(ActorInitializer init) { return new NukePower(init.Self, this); }
}
@@ -71,8 +75,8 @@ namespace OpenRA.Mods.Common.Traits
else
Sound.Play(Info.IncomingSound);
var rb = self.Trait<RenderSimple>();
rb.PlayCustomAnim(self, "active");
var wsb = self.Trait<WithSpriteBody>();
wsb.PlayCustomAnimation(self, info.ActivationSequence);
var targetPosition = self.World.Map.CenterOfCell(order.TargetLocation);
var missile = new NukeLaunch(self.Owner, info.MissileWeapon,

View File

@@ -1931,6 +1931,40 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
}
if (engineVersion < 20150828)
{
// Replaced RenderBuilding with RenderSprites + WithSpriteBody (+AutoSelectionSize)
if (depth == 0)
{
var childKeysExcludeFromRS = new[] { "Sequence", "PauseOnLowPower" };
var rb = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("RenderBuilding"));
if (rb != null)
{
rb.Key = "WithSpriteBody";
var rsNodes = rb.Value.Nodes.Where(n => !childKeysExcludeFromRS.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", ""));
node.Value.Nodes.Add(new MiniYamlNode("AutoSelectionSize", ""));
rb.Value.Nodes.RemoveAll(n => rsNodes.Contains(n));
}
var rrb = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("-RenderBuilding"));
if (rrb != null)
rrb.Key = "-WithSpriteBody";
if (depth == 2 && node.Key == "PauseOnLowPower" && (parentKey == "WithSpriteBody"
|| parentKey == "WithTurretedSpriteBody" || parentKey == "WithWallSpriteBody"))
node.Key = "PauseAnimationWhenDisabled";
}
}
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
}
}