Skip to content

Commit

Permalink
Merge pull request OpenRA#8553 from reaperrr/rem-renderunit
Browse files Browse the repository at this point in the history
Removed RenderHarvester, RenderLandingCraft and RenderUnit
  • Loading branch information
penev92 committed Jul 4, 2015
2 parents a871a28 + 2be06e6 commit 8ee2673
Show file tree
Hide file tree
Showing 24 changed files with 377 additions and 234 deletions.
20 changes: 16 additions & 4 deletions OpenRA.Mods.Common/Activities/SpriteHarvesterDockSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,37 @@ namespace OpenRA.Mods.Common.Activities
{
public class SpriteHarvesterDockSequence : HarvesterDockSequence
{
readonly RenderUnit ru;
readonly WithSpriteBody wsb;
readonly WithDockingAnimation wda;

public SpriteHarvesterDockSequence(Actor self, Actor refinery, int dockAngle, bool isDragRequired, WVec dragOffset, int dragLength)
: base(self, refinery, dockAngle, isDragRequired, dragOffset, dragLength)
{
ru = self.Trait<RenderUnit>();
wsb = self.Trait<WithSpriteBody>();
wda = self.Trait<WithDockingAnimation>();
}

public override Activity OnStateDock(Actor self)
{
ru.PlayCustomAnimation(self, "dock", () => ru.PlayCustomAnimationRepeating(self, "dock-loop"));
foreach (var trait in self.TraitsImplementing<INotifyHarvesterAction>())
trait.Docked();

wsb.PlayCustomAnimation(self, wda.Info.DockSequence, () => wsb.PlayCustomAnimationRepeating(self, wda.Info.DockLoopSequence));
dockingState = State.Loop;
return this;
}

public override Activity OnStateUndock(Actor self)
{
ru.PlayCustomAnimationBackwards(self, "dock", () => dockingState = State.Complete);
wsb.PlayCustomAnimationBackwards(self, wda.Info.DockSequence,
() =>
{
dockingState = State.Complete;
foreach (var trait in self.TraitsImplementing<INotifyHarvesterAction>())
trait.Undocked();
});
dockingState = State.Wait;

return this;
}
}
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/OpenRA.Mods.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,9 @@
<Compile Include="Traits\Render\RenderBuildingCharge.cs" />
<Compile Include="Traits\Render\RenderBuildingTurreted.cs" />
<Compile Include="Traits\Render\RenderEditorOnly.cs" />
<Compile Include="Traits\Render\RenderHarvester.cs" />
<Compile Include="Traits\Render\RenderNameTag.cs" />
<Compile Include="Traits\Render\RenderSimple.cs" />
<Compile Include="Traits\Render\RenderSprites.cs" />
<Compile Include="Traits\Render\RenderUnit.cs" />
<Compile Include="Traits\Render\RenderBuildingSilo.cs" />
<Compile Include="Traits\Render\RenderBuildingWall.cs" />
<Compile Include="Traits\Render\RenderDetectionCircle.cs" />
Expand All @@ -421,8 +419,10 @@
<Compile Include="Traits\Render\WithCrateBody.cs" />
<Compile Include="Traits\Render\WithDeathAnimation.cs" />
<Compile Include="Traits\Render\WithDecoration.cs" />
<Compile Include="Traits\Render\WithDockingAnimation.cs" />
<Compile Include="Traits\Render\WithDockingOverlay.cs" />
<Compile Include="Traits\Render\WithHarvestAnimation.cs" />
<Compile Include="Traits\Render\WithHarvestOverlay.cs" />
<Compile Include="Traits\Render\WithIdleOverlay.cs" />
<Compile Include="Traits\Render\WithMuzzleFlash.cs" />
<Compile Include="Traits\Render\WithRangeCircle.cs" />
Expand Down
63 changes: 0 additions & 63 deletions OpenRA.Mods.Common/Traits/Render/RenderHarvester.cs

This file was deleted.

50 changes: 0 additions & 50 deletions OpenRA.Mods.Common/Traits/Render/RenderUnit.cs

This file was deleted.

3 changes: 1 addition & 2 deletions OpenRA.Mods.Common/Traits/Render/WithAttackAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
#endregion

using System.Linq;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;

namespace OpenRA.Mods.RA.Traits
namespace OpenRA.Mods.Common.Traits
{
public class WithAttackAnimationInfo : ITraitInfo, Requires<WithFacingSpriteBodyInfo>, Requires<ArmamentInfo>, Requires<AttackBaseInfo>
{
Expand Down
35 changes: 35 additions & 0 deletions OpenRA.Mods.Common/Traits/Render/WithDockingAnimation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#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 OpenRA.Traits;

namespace OpenRA.Mods.Common.Traits
{
public class WithDockingAnimationInfo : ITraitInfo, Requires<WithSpriteBodyInfo>, Requires<HarvesterInfo>
{
[Desc("Displayed when docking to refinery.")]
[SequenceReference] public readonly string DockSequence = "dock";

[Desc("Looped while unloading at refinery.")]
[SequenceReference] public readonly string DockLoopSequence = "dock-loop";

public object Create(ActorInitializer init) { return new WithDockingAnimation(init, this); }
}

public class WithDockingAnimation
{
public readonly WithDockingAnimationInfo Info;

public WithDockingAnimation(ActorInitializer init, WithDockingAnimationInfo info)
{
Info = info;
}
}
}
87 changes: 51 additions & 36 deletions OpenRA.Mods.Common/Traits/Render/WithHarvestAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,79 @@
#endregion

using OpenRA.Activities;
using OpenRA.Graphics;
using OpenRA.Traits;

namespace OpenRA.Mods.Common.Traits
{
[Desc("Displays an overlay whenever resources are harvested by the actor.")]
class WithHarvestAnimationInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
public class WithHarvestAnimationInfo : ITraitInfo, Requires<WithSpriteBodyInfo>, Requires<HarvesterInfo>
{
[Desc("Sequence name to use")]
[SequenceReference] public readonly string Sequence = "harvest";
[Desc("Prefix added to idle and harvest sequences depending on fullness of harvester.")]
[SequenceReference(null, true)] public readonly string[] PrefixByFullness = { "" };

[Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero;
[Desc("Displayed while harvesting.")]
[SequenceReference] public readonly string HarvestSequence = "harvest";

public readonly string Palette = "effect";

public object Create(ActorInitializer init) { return new WithHarvestAnimation(init.Self, this); }
public object Create(ActorInitializer init) { return new WithHarvestAnimation(init, this); }
}

class WithHarvestAnimation : INotifyHarvesterAction
public class WithHarvestAnimation : ITick, INotifyHarvesterAction
{
WithHarvestAnimationInfo info;
Animation anim;
bool visible;
public readonly WithHarvestAnimationInfo Info;
readonly WithSpriteBody wsb;
readonly Harvester harv;

public bool IsModifying;

public WithHarvestAnimation(ActorInitializer init, WithHarvestAnimationInfo info)
{
Info = info;
harv = init.Self.Trait<Harvester>();
wsb = init.Self.Trait<WithSpriteBody>();
}

public WithHarvestAnimation(Actor self, WithHarvestAnimationInfo info)
protected virtual string NormalizeHarvesterSequence(Actor self, string baseSequence)
{
this.info = info;
var rs = self.Trait<RenderSprites>();
var body = self.Trait<IBodyOrientation>();
var desiredState = harv.Fullness * (Info.PrefixByFullness.Length - 1) / 100;
var desiredPrefix = Info.PrefixByFullness[desiredState];

if (wsb.DefaultAnimation.HasSequence(desiredPrefix + baseSequence))
return desiredPrefix + baseSequence;
else
return baseSequence;
}

anim = new Animation(self.World, rs.GetImage(self), RenderSprites.MakeFacingFunc(self));
anim.IsDecoration = true;
anim.Play(info.Sequence);
rs.Add(new AnimationWithOffset(anim,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !visible,
() => false,
p => ZOffsetFromCenter(self, p, 0)), info.Palette);
public void Tick(Actor self)
{
if (!IsModifying && !string.IsNullOrEmpty(wsb.Info.Sequence) && wsb.DefaultAnimation.HasSequence(NormalizeHarvesterSequence(self, wsb.Info.Sequence)))
{
if (wsb.DefaultAnimation.CurrentSequence.Name != NormalizeHarvesterSequence(self, wsb.Info.Sequence))
wsb.DefaultAnimation.ReplaceAnim(NormalizeHarvesterSequence(self, wsb.Info.Sequence));
}
}

public void Harvested(Actor self, ResourceType resource)
{
if (visible)
return;
if (!IsModifying && !string.IsNullOrEmpty(Info.HarvestSequence) && wsb.DefaultAnimation.HasSequence(NormalizeHarvesterSequence(self, Info.HarvestSequence)))
{
IsModifying = true;
wsb.PlayCustomAnimation(self, NormalizeHarvesterSequence(self, Info.HarvestSequence), () => IsModifying = false);
}
}

// If IsModifying isn't set to true, the docking animation
// will be overridden by the WithHarvestAnimation fullness modifier.
public void Docked()
{
IsModifying = true;
}

visible = true;
anim.PlayThen(info.Sequence, () => visible = false);
public void Undocked()
{
IsModifying = false;
}

public void MovingToResources(Actor self, CPos targetCell, Activity next) { }
public void MovingToRefinery(Actor self, CPos targetCell, Activity next) { }
public void MovementCancelled(Actor self) { }

public static int ZOffsetFromCenter(Actor self, WPos pos, int offset)
{
var delta = self.CenterPosition - pos;
return delta.Y + delta.Z + offset;
}
}
}
Loading

0 comments on commit 8ee2673

Please sign in to comment.