Merge pull request #6084 from pchote/renderpreview
Improve actor preview rendering
This commit is contained in:
45
OpenRA.Mods.RA/Graphics/ActorPreview.cs
Normal file
45
OpenRA.Mods.RA/Graphics/ActorPreview.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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 OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Mods.RA.Graphics
|
||||
{
|
||||
public interface IActorPreview
|
||||
{
|
||||
void Tick();
|
||||
IEnumerable<IRenderable> Render(WorldRenderer wr, WPos pos);
|
||||
}
|
||||
|
||||
public class ActorPreviewInitializer
|
||||
{
|
||||
public readonly ActorInfo Actor;
|
||||
public readonly Player Owner;
|
||||
public readonly WorldRenderer WorldRenderer;
|
||||
public World World { get { return WorldRenderer.world; } }
|
||||
|
||||
readonly TypeDictionary dict;
|
||||
|
||||
public ActorPreviewInitializer(ActorInfo actor, Player owner, WorldRenderer worldRenderer, TypeDictionary dict)
|
||||
{
|
||||
Actor = actor;
|
||||
Owner = owner;
|
||||
WorldRenderer = worldRenderer;
|
||||
this.dict = dict;
|
||||
}
|
||||
|
||||
public T Get<T>() where T : IActorInit { return dict.Get<T>(); }
|
||||
public U Get<T, U>() where T : IActorInit<U> { return dict.Get<T>().Value(World); }
|
||||
public bool Contains<T>() where T : IActorInit { return dict.Contains<T>(); }
|
||||
}
|
||||
}
|
||||
42
OpenRA.Mods.RA/Graphics/SpriteActorPreview.cs
Normal file
42
OpenRA.Mods.RA/Graphics/SpriteActorPreview.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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 OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Mods.RA.Graphics
|
||||
{
|
||||
public class SpriteActorPreview : IActorPreview
|
||||
{
|
||||
readonly Animation animation;
|
||||
readonly WVec offset;
|
||||
readonly int zOffset;
|
||||
readonly PaletteReference pr;
|
||||
readonly float scale;
|
||||
|
||||
public SpriteActorPreview(Animation animation, WVec offset, int zOffset, PaletteReference pr, float scale)
|
||||
{
|
||||
this.animation = animation;
|
||||
this.offset = offset;
|
||||
this.zOffset = zOffset;
|
||||
this.pr = pr;
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public void Tick() { animation.Tick(); }
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, WPos pos)
|
||||
{
|
||||
return animation.Render(pos, offset, zOffset, pr, scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
58
OpenRA.Mods.RA/Graphics/VoxelActorPreview.cs
Normal file
58
OpenRA.Mods.RA/Graphics/VoxelActorPreview.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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 OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Mods.RA.Graphics
|
||||
{
|
||||
public class VoxelPreview : IActorPreview
|
||||
{
|
||||
readonly VoxelAnimation[] components;
|
||||
readonly RenderVoxelsInfo rvi;
|
||||
readonly WRot lightSource;
|
||||
readonly WRot camera;
|
||||
|
||||
readonly PaletteReference colorPalette;
|
||||
readonly PaletteReference normalsPalette;
|
||||
readonly PaletteReference shadowPalette;
|
||||
|
||||
readonly WVec offset;
|
||||
readonly int zOffset;
|
||||
|
||||
public VoxelPreview(VoxelAnimation[] components, WVec offset, int zOffset, RenderVoxelsInfo rvi, WAngle cameraPitch,
|
||||
PaletteReference colorPalette, PaletteReference normalsPalette, PaletteReference shadowPalette)
|
||||
{
|
||||
this.components = components;
|
||||
this.rvi = rvi;
|
||||
lightSource = new WRot(WAngle.Zero,new WAngle(256) - rvi.LightPitch, rvi.LightYaw);
|
||||
camera = new WRot(WAngle.Zero, cameraPitch - new WAngle(256), new WAngle(256));
|
||||
|
||||
this.colorPalette = colorPalette;
|
||||
this.normalsPalette = normalsPalette;
|
||||
this.shadowPalette = shadowPalette;
|
||||
|
||||
this.offset = offset;
|
||||
this.zOffset = zOffset;
|
||||
}
|
||||
|
||||
public void Tick() { /* not supported */ }
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, WPos pos)
|
||||
{
|
||||
yield return new VoxelRenderable(components, pos + offset, zOffset, camera, rvi.Scale,
|
||||
lightSource, rvi.LightAmbientColor, rvi.LightDiffuseColor,
|
||||
colorPalette, normalsPalette, shadowPalette);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -545,6 +545,9 @@
|
||||
<Compile Include="Widgets\LabelWithTooltipWidget.cs" />
|
||||
<Compile Include="ProductionQueueFromSelection.cs" />
|
||||
<Compile Include="Scripting\Global\MediaGlobal.cs" />
|
||||
<Compile Include="Graphics\ActorPreview.cs" />
|
||||
<Compile Include="Graphics\SpriteActorPreview.cs" />
|
||||
<Compile Include="Graphics\VoxelActorPreview.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">
|
||||
|
||||
@@ -13,8 +13,10 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Graphics;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Mods.RA.Orders
|
||||
{
|
||||
@@ -23,8 +25,8 @@ namespace OpenRA.Mods.RA.Orders
|
||||
readonly Actor Producer;
|
||||
readonly string Building;
|
||||
readonly BuildingInfo BuildingInfo;
|
||||
IActorPreview[] preview;
|
||||
|
||||
IEnumerable<IRenderable> preview;
|
||||
Sprite buildOk, buildBlocked;
|
||||
bool initialized = false;
|
||||
|
||||
@@ -79,7 +81,15 @@ namespace OpenRA.Mods.RA.Orders
|
||||
}
|
||||
}
|
||||
|
||||
public void Tick(World world) {}
|
||||
public void Tick(World world)
|
||||
{
|
||||
if (preview == null)
|
||||
return;
|
||||
|
||||
foreach (var p in preview)
|
||||
p.Tick();
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world)
|
||||
{
|
||||
@@ -108,23 +118,22 @@ namespace OpenRA.Mods.RA.Orders
|
||||
{
|
||||
if (!initialized)
|
||||
{
|
||||
var rbi = rules.Actors[Building].Traits.GetOrDefault<RenderBuildingInfo>();
|
||||
if (rbi == null)
|
||||
preview = new IRenderable[0];
|
||||
else
|
||||
{
|
||||
var palette = rbi.Palette ?? (Producer.Owner != null ?
|
||||
rbi.PlayerPalette + Producer.Owner.InternalName : null);
|
||||
|
||||
preview = rbi.RenderPreview(world, rules.Actors[Building], wr.Palette(palette));
|
||||
}
|
||||
var init = new ActorPreviewInitializer(rules.Actors[Building], Producer.Owner, wr, new TypeDictionary());
|
||||
preview = rules.Actors[Building].Traits.WithInterface<IRenderActorPreviewInfo>()
|
||||
.SelectMany(rpi => rpi.RenderPreview(init))
|
||||
.ToArray();
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
var offset = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, BuildingInfo) - WPos.Zero;
|
||||
foreach (var r in preview)
|
||||
yield return r.OffsetBy(offset);
|
||||
var comparer = new RenderableComparer(wr);
|
||||
var offset = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, BuildingInfo);
|
||||
var previewRenderables = preview
|
||||
.SelectMany(p => p.Render(wr, offset))
|
||||
.OrderBy(r => r, comparer);
|
||||
|
||||
foreach (var r in previewRenderables)
|
||||
yield return r;
|
||||
|
||||
var res = world.WorldActor.Trait<ResourceLayer>();
|
||||
var isCloseEnough = BuildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, Building, topLeft);
|
||||
|
||||
@@ -49,8 +49,6 @@ namespace OpenRA.Mods.RA.Render
|
||||
this.info = info;
|
||||
|
||||
DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));
|
||||
|
||||
self.Trait<IBodyOrientation>().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings);
|
||||
}
|
||||
|
||||
public virtual void BuildingComplete(Actor self)
|
||||
|
||||
@@ -9,14 +9,29 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
class RenderBuildingTurretedInfo : RenderBuildingInfo, Requires<TurretedInfo>
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new RenderBuildingTurreted( init, this ); }
|
||||
public override object Create(ActorInitializer init) { return new RenderBuildingTurreted(init, this); }
|
||||
|
||||
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
|
||||
.FirstOrDefault();
|
||||
|
||||
// Show the correct turret facing
|
||||
var anim = new Animation(init.World, image, () => t.InitialFacing);
|
||||
anim.PlayRepeating("idle");
|
||||
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||
}
|
||||
}
|
||||
|
||||
class RenderBuildingTurreted : RenderBuilding
|
||||
|
||||
@@ -8,7 +8,10 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
@@ -19,6 +22,15 @@ namespace OpenRA.Mods.RA.Render
|
||||
public readonly string Sequence = "idle";
|
||||
|
||||
public override object Create(ActorInitializer init) { return new RenderBuildingWall(init, this); }
|
||||
|
||||
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 anim = new Animation(init.World, image, () => 0);
|
||||
anim.PlayFetchIndex("idle", () => 0);
|
||||
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||
}
|
||||
}
|
||||
|
||||
class RenderBuildingWall : RenderBuilding, INotifyAddedToWorld, INotifyRemovedFromWorld
|
||||
|
||||
@@ -12,27 +12,27 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
class RenderBuildingWarFactoryInfo : RenderBuildingInfo
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new RenderBuildingWarFactory( init, this ); }
|
||||
public override object Create(ActorInitializer init) { return new RenderBuildingWarFactory(init, this); }
|
||||
|
||||
/* get around unverifiability */
|
||||
IEnumerable<IRenderable> BaseBuildingPreview(World world, ActorInfo building, PaletteReference pr)
|
||||
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
return base.RenderPreview(world, building, pr);
|
||||
}
|
||||
foreach (var orig in base.RenderPreviewSprites(init, rs, image, facings, p))
|
||||
yield return orig;
|
||||
|
||||
public override IEnumerable<IRenderable> RenderPreview(World world, ActorInfo building, PaletteReference pr)
|
||||
{
|
||||
var p = BaseBuildingPreview(world, building, pr);
|
||||
var anim = new Animation(world, RenderSprites.GetImage(building), () => 0);
|
||||
// Show additional roof overlay
|
||||
var anim = new Animation(init.World, image, () => 0);
|
||||
anim.PlayRepeating("idle-top");
|
||||
|
||||
return p.Concat(anim.Render(WPos.Zero, WVec.Zero, 0, pr, Scale));
|
||||
var bi = init.Actor.Traits.Get<BuildingInfo>();
|
||||
var offset = FootprintUtils.CenterOffset(init.World, bi).Y + 512;
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, offset, p, rs.Scale);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,11 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Effects;
|
||||
using OpenRA.Mods.RA.Graphics;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
@@ -25,6 +29,23 @@ namespace OpenRA.Mods.RA.Render
|
||||
public readonly string[] StandAnimations = { "stand" };
|
||||
|
||||
public override object Create(ActorInitializer init) { return new RenderInfantry(init.self, this); }
|
||||
|
||||
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
var facing = 0;
|
||||
var ifacing = init.Actor.Traits.GetOrDefault<IFacingInfo>();
|
||||
if (ifacing != null)
|
||||
facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : ifacing.GetInitialFacing();
|
||||
|
||||
var anim = new Animation(init.World, image, () => facing);
|
||||
anim.PlayRepeating(StandAnimations.First());
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||
}
|
||||
|
||||
public override int QuantizedBodyFacings(SequenceProvider sequenceProvider, ActorInfo ai)
|
||||
{
|
||||
return sequenceProvider.GetSequence(RenderSprites.GetImage(ai), StandAnimations.First()).Facings;
|
||||
}
|
||||
}
|
||||
|
||||
public class RenderInfantry : RenderSimple, INotifyAttack, INotifyKilled, INotifyIdle
|
||||
@@ -64,8 +85,6 @@ namespace OpenRA.Mods.RA.Render
|
||||
DefaultAnimation.PlayFetchIndex(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom)), () => 0);
|
||||
State = AnimationState.Waiting;
|
||||
move = self.Trait<IMove>();
|
||||
|
||||
self.Trait<IBodyOrientation>().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings);
|
||||
}
|
||||
|
||||
public void Attacking(Actor self, Target target)
|
||||
|
||||
@@ -11,20 +11,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
public class RenderSimpleInfo : RenderSpritesInfo, ILegacyEditorRenderInfo, Requires<IBodyOrientationInfo>
|
||||
public class RenderSimpleInfo : RenderSpritesInfo, IRenderActorPreviewSpritesInfo, IQuantizeBodyOrientationInfo, ILegacyEditorRenderInfo, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new RenderSimple(init.self); }
|
||||
|
||||
public virtual IEnumerable<IRenderable> RenderPreview(World world, ActorInfo ai, PaletteReference pr)
|
||||
public virtual IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
var anim = new Animation(world, RenderSimple.GetImage(ai), () => 0);
|
||||
anim.PlayRepeating("idle");
|
||||
var ifacing = init.Actor.Traits.GetOrDefault<IFacingInfo>();
|
||||
var facing = ifacing != null ? init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : ifacing.GetInitialFacing() : 0;
|
||||
|
||||
return anim.Render(WPos.Zero, WVec.Zero, 0, pr, Scale);
|
||||
var anim = new Animation(init.World, image, () => facing);
|
||||
anim.PlayRepeating("idle");
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||
}
|
||||
|
||||
public virtual int QuantizedBodyFacings(SequenceProvider sequenceProvider, ActorInfo ai)
|
||||
{
|
||||
return sequenceProvider.GetSequence(RenderSprites.GetImage(ai), "idle").Facings;
|
||||
}
|
||||
|
||||
public string EditorPalette { get { return Palette; } }
|
||||
@@ -46,7 +54,6 @@ namespace OpenRA.Mods.RA.Render
|
||||
: this(self, MakeFacingFunc(self))
|
||||
{
|
||||
DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));
|
||||
self.Trait<IBodyOrientation>().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings);
|
||||
}
|
||||
|
||||
public int2 SelectionSize(Actor self) { return AutoSelectionSize(self); }
|
||||
|
||||
@@ -12,12 +12,15 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
public class RenderSpritesInfo : ITraitInfo
|
||||
public interface IRenderActorPreviewSpritesInfo { IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p); }
|
||||
|
||||
public class RenderSpritesInfo : IRenderActorPreviewInfo, ITraitInfo
|
||||
{
|
||||
[Desc("Defaults to the actor name.")]
|
||||
public readonly string Image = null;
|
||||
@@ -30,6 +33,23 @@ namespace OpenRA.Mods.RA.Render
|
||||
public readonly float Scale = 1f;
|
||||
|
||||
public virtual object Create(ActorInitializer init) { return new RenderSprites(init.self); }
|
||||
|
||||
public IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init)
|
||||
{
|
||||
var sequenceProvider = init.World.Map.SequenceProvider;
|
||||
var image = RenderSprites.GetImage(init.Actor);
|
||||
var palette = init.WorldRenderer.Palette(Palette ?? (init.Owner != null ? PlayerPalette + init.Owner.InternalName : null));
|
||||
|
||||
var facings = 0;
|
||||
var body = init.Actor.Traits.GetOrDefault<BodyOrientationInfo>();
|
||||
if (body != null)
|
||||
facings = body.QuantizedFacings == -1 ? init.Actor.Traits.Get<IQuantizeBodyOrientationInfo>().QuantizedBodyFacings(sequenceProvider, init.Actor) : body.QuantizedFacings;
|
||||
|
||||
foreach (var spi in init.Actor.Traits.WithInterface<IRenderActorPreviewSpritesInfo>())
|
||||
foreach (var preview in spi.RenderPreviewSprites(init, this, image, facings, palette))
|
||||
yield return preview;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class RenderSprites : IRender, ITick, INotifyOwnerChanged, INotifyEffectiveOwnerChanged
|
||||
@@ -89,7 +109,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
public static string GetImage(ActorInfo actor)
|
||||
{
|
||||
var Info = actor.Traits.Get<RenderSpritesInfo>();
|
||||
return Info.Image ?? actor.Name;
|
||||
return (Info.Image ?? actor.Name).ToLowerInvariant();
|
||||
}
|
||||
|
||||
public string GetImage(Actor self)
|
||||
|
||||
@@ -9,13 +9,16 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Mods.RA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
public class RenderVoxelsInfo : ITraitInfo, Requires<IBodyOrientationInfo>
|
||||
public interface IRenderActorPreviewVoxelsInfo { IEnumerable<VoxelAnimation> RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p); }
|
||||
|
||||
public class RenderVoxelsInfo : ITraitInfo, IRenderActorPreviewInfo, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
[Desc("Defaults to the actor name.")]
|
||||
public readonly string Image = null;
|
||||
@@ -34,7 +37,27 @@ namespace OpenRA.Mods.RA.Render
|
||||
public readonly WAngle LightYaw = WAngle.FromDegrees(240);
|
||||
public readonly float[] LightAmbientColor = new float[] {0.6f, 0.6f, 0.6f};
|
||||
public readonly float[] LightDiffuseColor = new float[] {0.4f, 0.4f, 0.4f};
|
||||
|
||||
public virtual object Create(ActorInitializer init) { return new RenderVoxels(init.self, this); }
|
||||
|
||||
public virtual IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init)
|
||||
{
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var sequenceProvider = init.World.Map.SequenceProvider;
|
||||
var image = Image ?? init.Actor.Name;
|
||||
var facings = body.QuantizedFacings == -1 ? init.Actor.Traits.Get<IQuantizeBodyOrientationInfo>().QuantizedBodyFacings(sequenceProvider, init.Actor) : body.QuantizedFacings;
|
||||
var palette = init.WorldRenderer.Palette(Palette ?? (init.Owner != null ? PlayerPalette + init.Owner.InternalName : null));
|
||||
|
||||
var facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 0;
|
||||
var orientation = WRot.FromFacing(facing);
|
||||
var components = init.Actor.Traits.WithInterface<IRenderActorPreviewVoxelsInfo>()
|
||||
.SelectMany(rvpi => rvpi.RenderPreviewVoxels(init, this, image, orientation, facings, palette))
|
||||
.ToArray();
|
||||
|
||||
yield return new VoxelPreview(components, WVec.Zero, 0, this, body.CameraPitch, palette,
|
||||
init.WorldRenderer.Palette(NormalsPalette), init.WorldRenderer.Palette("shadow"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class RenderVoxels : IRender, INotifyOwnerChanged
|
||||
|
||||
@@ -8,15 +8,17 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
[Desc("Renders a decorative animation on units and buildings.")]
|
||||
public class WithIdleOverlayInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
|
||||
public class WithIdleOverlayInfo : ITraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
[Desc("Sequence name to use")]
|
||||
public readonly string Sequence = "idle-overlay";
|
||||
@@ -33,6 +35,18 @@ namespace OpenRA.Mods.RA.Render
|
||||
public readonly bool PauseOnLowPower = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithIdleOverlay(init.self, this); }
|
||||
|
||||
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
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);
|
||||
|
||||
var orientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)), facings);
|
||||
var offset = body.LocalToWorld(Offset.Rotate(orientation));
|
||||
yield return new SpriteActorPreview(anim, offset, offset.Y + offset.Z + 1, p, rs.Scale);
|
||||
}
|
||||
}
|
||||
|
||||
public class WithIdleOverlay : INotifyDamageStateChanged, INotifyBuildComplete, INotifySold
|
||||
|
||||
@@ -8,13 +8,16 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
[Desc("Displays a helicopter rotor overlay.")]
|
||||
public class WithRotorInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
|
||||
public class WithRotorInfo : ITraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
[Desc("Sequence name to use when flying")]
|
||||
public readonly string Sequence = "rotor";
|
||||
@@ -29,6 +32,18 @@ namespace OpenRA.Mods.RA.Render
|
||||
public readonly string Id = "rotor";
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithRotor(init.self, this); }
|
||||
|
||||
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
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);
|
||||
|
||||
var orientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)), facings);
|
||||
var offset = body.LocalToWorld(Offset.Rotate(orientation));
|
||||
yield return new SpriteActorPreview(anim, offset, offset.Y + offset.Z + 1, p, rs.Scale);
|
||||
}
|
||||
}
|
||||
|
||||
public class WithRotor : ITick
|
||||
|
||||
@@ -11,12 +11,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
[Desc("Renders barrels for units with the Turreted trait.")]
|
||||
class WithTurretInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<TurretedInfo>, Requires<IBodyOrientationInfo>
|
||||
class WithTurretInfo : ITraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>, Requires<TurretedInfo>, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
[Desc("Sequence name to use")]
|
||||
public readonly string Sequence = "turret";
|
||||
@@ -31,6 +32,20 @@ namespace OpenRA.Mods.RA.Render
|
||||
public readonly bool Recoils = true;
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithTurret(init.self, this); }
|
||||
|
||||
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
|
||||
.First(tt => tt.Turret == Turret);
|
||||
|
||||
var anim = new Animation(init.World, image, () => t.InitialFacing);
|
||||
anim.Play(Sequence);
|
||||
|
||||
var orientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(t.InitialFacing)), facings);
|
||||
var offset = body.LocalToWorld(t.Offset.Rotate(orientation));
|
||||
yield return new SpriteActorPreview(anim, offset, offset.Y + offset.Z + 1, p, rs.Scale);
|
||||
}
|
||||
}
|
||||
|
||||
class WithTurret : ITick
|
||||
|
||||
@@ -11,11 +11,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
public class WithVoxelBarrelInfo : ITraitInfo, Requires<RenderVoxelsInfo>
|
||||
public class WithVoxelBarrelInfo : ITraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>
|
||||
{
|
||||
[Desc("Voxel sequence name to use")]
|
||||
public readonly string Sequence = "barrel";
|
||||
@@ -25,6 +26,22 @@ namespace OpenRA.Mods.RA.Render
|
||||
public readonly WVec LocalOffset = WVec.Zero;
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithVoxelBarrel(init.self, this); }
|
||||
|
||||
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p)
|
||||
{
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var armament = init.Actor.Traits.WithInterface<ArmamentInfo>()
|
||||
.First(a => a.Name == Armament);
|
||||
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
|
||||
.First(tt => tt.Turret == armament.Turret);
|
||||
|
||||
var voxel = VoxelProvider.GetVoxel(image, Sequence);
|
||||
var turretOrientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(t.InitialFacing) - orientation.Yaw), facings);
|
||||
var turretOffset = body.LocalToWorld(t.Offset.Rotate(orientation));
|
||||
|
||||
yield return new VoxelAnimation(voxel, () => turretOffset, () => new [] { turretOrientation, orientation },
|
||||
() => false, () => 0);
|
||||
}
|
||||
}
|
||||
|
||||
public class WithVoxelBarrel
|
||||
|
||||
16
OpenRA.Mods.RA/Render/WithVoxelBody.cs
Executable file → Normal file
16
OpenRA.Mods.RA/Render/WithVoxelBody.cs
Executable file → Normal file
@@ -9,18 +9,32 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
[Desc("Also returns a default selection size that is calculated automatically from the voxel dimensions.")]
|
||||
public class WithVoxelBodyInfo : ITraitInfo, Requires<RenderVoxelsInfo>
|
||||
public class WithVoxelBodyInfo : ITraitInfo, IQuantizeBodyOrientationInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>
|
||||
{
|
||||
public readonly string Sequence = "idle";
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithVoxelBody(init.self, this); }
|
||||
|
||||
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p)
|
||||
{
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var voxel = VoxelProvider.GetVoxel(image, "idle");
|
||||
var bodyOrientation = new[] { body.QuantizeOrientation(orientation, facings) };
|
||||
yield return new VoxelAnimation(voxel, () => WVec.Zero,
|
||||
() => bodyOrientation,
|
||||
() => false, () => 0);
|
||||
}
|
||||
|
||||
public int QuantizedBodyFacings(SequenceProvider sequenceProvider, ActorInfo ai) { return 0; }
|
||||
}
|
||||
|
||||
public class WithVoxelBody : IAutoSelectionSize
|
||||
|
||||
@@ -11,11 +11,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
public class WithVoxelTurretInfo : ITraitInfo, Requires<RenderVoxelsInfo>
|
||||
public class WithVoxelTurretInfo : ITraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>, Requires<TurretedInfo>
|
||||
{
|
||||
[Desc("Voxel sequence name to use")]
|
||||
public readonly string Sequence = "turret";
|
||||
@@ -24,6 +25,20 @@ namespace OpenRA.Mods.RA.Render
|
||||
public readonly string Turret = "primary";
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithVoxelTurret(init.self, this); }
|
||||
|
||||
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p)
|
||||
{
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
|
||||
.First(tt => tt.Turret == Turret);
|
||||
|
||||
var voxel = VoxelProvider.GetVoxel(image, Sequence);
|
||||
var turretOffset = body.LocalToWorld(t.Offset.Rotate(orientation));
|
||||
|
||||
var turretBodyOrientation = new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(t.InitialFacing) - orientation.Yaw);
|
||||
var turretOrientation = new[] { turretBodyOrientation, body.QuantizeOrientation(orientation, facings) };
|
||||
yield return new VoxelAnimation(voxel, () => turretOffset, () => turretOrientation, () => false, () => 0);
|
||||
}
|
||||
}
|
||||
|
||||
public class WithVoxelTurret
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
@@ -50,4 +51,5 @@ namespace OpenRA.Mods.RA
|
||||
public interface INotifyTransform { void BeforeTransform(Actor self); void OnTransform(Actor self); void AfterTransform(Actor toActor); }
|
||||
public interface INotifyAttack { void Attacking(Actor self, Target target, Armament a, Barrel barrel); }
|
||||
public interface INotifyChat { bool OnChat(string from, string message); }
|
||||
public interface IRenderActorPreviewInfo { IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user