Merge pull request #11426 from pchote/actorpreview-dynamic-facing

Support dynamic ActorPreview facings and creating previews from live actors.
This commit is contained in:
reaperrr
2016-06-20 14:38:11 +02:00
committed by GitHub
39 changed files with 382 additions and 150 deletions

View File

@@ -30,12 +30,13 @@ namespace OpenRA.Mods.TS.Traits.Render
public object Create(ActorInitializer init) { return new WithVoxelUnloadBody(init.Self, this); }
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p)
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(
ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func<WRot> orientation, int facings, PaletteReference p)
{
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
var voxel = VoxelProvider.GetVoxel(image, "idle");
yield return new VoxelAnimation(voxel, () => WVec.Zero,
() => new[] { body.QuantizeOrientation(orientation, facings) },
() => new[] { body.QuantizeOrientation(orientation(), facings) },
() => false, () => 0);
}
}

View File

@@ -10,21 +10,37 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.Common.Traits.Render;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.TS.Traits.Render
{
public class WithVoxelWalkerBodyInfo : ITraitInfo, Requires<RenderVoxelsInfo>, Requires<IMoveInfo>, Requires<IFacingInfo>
public class WithVoxelWalkerBodyInfo : ITraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>, Requires<IMoveInfo>, Requires<IFacingInfo>
{
public readonly int TickRate = 5;
public object Create(ActorInitializer init) { return new WithVoxelWalkerBody(init.Self, this); }
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(
ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func<WRot> orientation, int facings, PaletteReference p)
{
var voxel = VoxelProvider.GetVoxel(image, "idle");
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
var frame = init.Contains<BodyAnimationFrameInit>() ? init.Get<BodyAnimationFrameInit, uint>() : 0;
yield return new VoxelAnimation(voxel, () => WVec.Zero,
() => new[] { body.QuantizeOrientation(orientation(), facings) },
() => false, () => frame);
}
}
public class WithVoxelWalkerBody : IAutoSelectionSize, ITick
public class WithVoxelWalkerBody : IAutoSelectionSize, ITick, IActorPreviewInitModifier
{
WithVoxelWalkerBodyInfo info;
IMove movement;
@@ -69,5 +85,18 @@ namespace OpenRA.Mods.TS.Traits.Render
if (++frame == frames)
frame = 0;
}
void IActorPreviewInitModifier.ModifyActorPreviewInit(Actor self, TypeDictionary inits)
{
inits.Add(new BodyAnimationFrameInit(frame));
}
}
public class BodyAnimationFrameInit : IActorInit<uint>
{
[FieldFromYamlKey] readonly uint value = 0;
public BodyAnimationFrameInit() { }
public BodyAnimationFrameInit(uint init) { value = init; }
public uint Value(World world) { return value; }
}
}

View File

@@ -15,9 +15,9 @@ using System.Drawing;
using System.IO;
using System.Linq;
using OpenRA.FileSystem;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.FileFormats;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.TS.UtilityCommands
{