Merge pull request #7937 from pchote/some-editor-prereqs
A collection of ActorPreview improvements.
This commit is contained in:
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
// Show a static frame instead of animating all of the fullness states
|
||||
var anim = new Animation(init.World, image, () => 0);
|
||||
anim.PlayFetchIndex(Sequence, () => 0);
|
||||
anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => 0);
|
||||
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
// Show the correct turret facing
|
||||
var anim = new Animation(init.World, image, () => t.InitialFacing);
|
||||
anim.PlayRepeating(Sequence);
|
||||
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
||||
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||
}
|
||||
|
||||
@@ -24,9 +24,44 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
// Show a static frame instead of animating all of the wall states
|
||||
var adjacent = 0;
|
||||
|
||||
if (init.Contains<RuntimeNeighbourInit>())
|
||||
{
|
||||
var location = CPos.Zero;
|
||||
if (init.Contains<LocationInit>())
|
||||
location = init.Get<LocationInit, CPos>();
|
||||
|
||||
var neighbours = init.Get<RuntimeNeighbourInit, Dictionary<CPos, string[]>>();
|
||||
foreach (var kv in neighbours)
|
||||
{
|
||||
var haveNeighbour = false;
|
||||
foreach (var n in kv.Value)
|
||||
{
|
||||
var rb = init.World.Map.Rules.Actors[n].Traits.GetOrDefault<RenderBuildingWallInfo>();
|
||||
if (rb != null && rb.Type == Type)
|
||||
{
|
||||
haveNeighbour = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!haveNeighbour)
|
||||
continue;
|
||||
|
||||
if (kv.Key == location + new CVec(0, -1))
|
||||
adjacent |= 1;
|
||||
else if (kv.Key == location + new CVec(+1, 0))
|
||||
adjacent |= 2;
|
||||
else if (kv.Key == location + new CVec(0, +1))
|
||||
adjacent |= 4;
|
||||
else if (kv.Key == location + new CVec(-1, 0))
|
||||
adjacent |= 8;
|
||||
}
|
||||
}
|
||||
|
||||
var anim = new Animation(init.World, image, () => 0);
|
||||
anim.PlayFetchIndex(Sequence, () => 0);
|
||||
anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => adjacent);
|
||||
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||
}
|
||||
@@ -110,4 +145,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
UpdateNeighbours(self);
|
||||
}
|
||||
}
|
||||
|
||||
public class RuntimeNeighbourInit : IActorInit<Dictionary<CPos, string[]>>, ISuppressInitExport
|
||||
{
|
||||
[FieldFromYamlKey] readonly Dictionary<CPos, string[]> value = null;
|
||||
public RuntimeNeighbourInit() { }
|
||||
public RuntimeNeighbourInit(Dictionary<CPos, string[]> init) { value = init; }
|
||||
public Dictionary<CPos, string[]> Value(World world) { return value; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var facing = ifacing != null ? init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : ifacing.GetInitialFacing() : 0;
|
||||
|
||||
var anim = new Animation(init.World, image, () => facing);
|
||||
anim.PlayRepeating(Sequence);
|
||||
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
||||
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
.First(tt => tt.Turret == armament.Turret);
|
||||
|
||||
var anim = new Animation(init.World, image, () => t.InitialFacing);
|
||||
anim.Play(Sequence);
|
||||
anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
||||
|
||||
var turretOrientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(t.InitialFacing)), facings);
|
||||
var turretOffset = body.LocalToWorld(t.Offset.Rotate(turretOrientation));
|
||||
|
||||
@@ -9,14 +9,16 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Renders crates with both water and land variants.")]
|
||||
class WithCrateBodyInfo : ITraitInfo, Requires<RenderSpritesInfo>
|
||||
class WithCrateBodyInfo : ITraitInfo, Requires<RenderSpritesInfo>, IQuantizeBodyOrientationInfo, IRenderActorPreviewSpritesInfo
|
||||
{
|
||||
public readonly string[] Images = { "crate" };
|
||||
|
||||
@@ -24,6 +26,15 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public readonly string[] XmasImages = { };
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithCrateBody(init.Self, this); }
|
||||
|
||||
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
var anim = new Animation(init.World, Images.First(), () => 0);
|
||||
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), "idle"));
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||
}
|
||||
|
||||
public int QuantizedBodyFacings(ActorInfo ai, SequenceProvider sequenceProvider, string race) { return 1; }
|
||||
}
|
||||
|
||||
class WithCrateBody : INotifyParachuteLanded
|
||||
|
||||
@@ -40,10 +40,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (UpgradeMinEnabledLevel > 0)
|
||||
yield break;
|
||||
|
||||
if (Palette != null)
|
||||
p = init.WorldRenderer.Palette(Palette);
|
||||
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 0;
|
||||
var anim = new Animation(init.World, image, () => facing);
|
||||
anim.PlayRepeating(Sequence);
|
||||
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
||||
|
||||
var orientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)), facings);
|
||||
var offset = body.LocalToWorld(Offset.Rotate(orientation));
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : ifacing.GetInitialFacing();
|
||||
|
||||
var anim = new Animation(init.World, image, () => facing);
|
||||
anim.PlayRepeating(StandSequences.First());
|
||||
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), StandSequences.First()));
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.TS.Traits
|
||||
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
var anim = new Animation(init.World, image, () => 0);
|
||||
anim.PlayFetchIndex(Sequence, () => 0);
|
||||
anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => 0);
|
||||
|
||||
var bi = init.Actor.Traits.Get<BuildingInfo>();
|
||||
var offset = FootprintUtils.CenterOffset(init.World, bi).Y + 512; // Additional 512 units move from center -> top of cell
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 0;
|
||||
var anim = new Animation(init.World, image, () => facing);
|
||||
anim.PlayRepeating(Sequence);
|
||||
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
||||
|
||||
var orientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)), facings);
|
||||
var offset = body.LocalToWorld(Offset.Rotate(orientation));
|
||||
|
||||
@@ -48,11 +48,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var turretFacing = init.Contains<TurretFacingInit>() ? init.Get<TurretFacingInit, int>() : t.InitialFacing;
|
||||
|
||||
var anim = new Animation(init.World, image, () => turretFacing);
|
||||
anim.Play(Sequence);
|
||||
anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
||||
|
||||
var orientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(bodyFacing)), facings);
|
||||
var offset = body.LocalToWorld(t.Offset.Rotate(orientation));
|
||||
yield return new SpriteActorPreview(anim, offset, offset.Y + offset.Z + 1, p, rs.Scale);
|
||||
yield return new SpriteActorPreview(anim, offset, -(offset.Y + offset.Z) + 1, p, rs.Scale);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user