Introduce actor previews for PBOG and the editor.
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -545,6 +545,8 @@
|
|||||||
<Compile Include="Widgets\LabelWithTooltipWidget.cs" />
|
<Compile Include="Widgets\LabelWithTooltipWidget.cs" />
|
||||||
<Compile Include="ProductionQueueFromSelection.cs" />
|
<Compile Include="ProductionQueueFromSelection.cs" />
|
||||||
<Compile Include="Scripting\Global\MediaGlobal.cs" />
|
<Compile Include="Scripting\Global\MediaGlobal.cs" />
|
||||||
|
<Compile Include="Graphics\ActorPreview.cs" />
|
||||||
|
<Compile Include="Graphics\SpriteActorPreview.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">
|
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">
|
||||||
|
|||||||
@@ -13,8 +13,10 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Mods.RA.Buildings;
|
using OpenRA.Mods.RA.Buildings;
|
||||||
|
using OpenRA.Mods.RA.Graphics;
|
||||||
using OpenRA.Mods.RA.Render;
|
using OpenRA.Mods.RA.Render;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
using OpenRA.Primitives;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Orders
|
namespace OpenRA.Mods.RA.Orders
|
||||||
{
|
{
|
||||||
@@ -23,8 +25,8 @@ namespace OpenRA.Mods.RA.Orders
|
|||||||
readonly Actor Producer;
|
readonly Actor Producer;
|
||||||
readonly string Building;
|
readonly string Building;
|
||||||
readonly BuildingInfo BuildingInfo;
|
readonly BuildingInfo BuildingInfo;
|
||||||
|
IActorPreview[] preview;
|
||||||
|
|
||||||
IEnumerable<IRenderable> preview;
|
|
||||||
Sprite buildOk, buildBlocked;
|
Sprite buildOk, buildBlocked;
|
||||||
bool initialized = false;
|
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> Render(WorldRenderer wr, World world) { yield break; }
|
||||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world)
|
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world)
|
||||||
{
|
{
|
||||||
@@ -108,23 +118,22 @@ namespace OpenRA.Mods.RA.Orders
|
|||||||
{
|
{
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
{
|
||||||
var rbi = rules.Actors[Building].Traits.GetOrDefault<RenderBuildingInfo>();
|
var init = new ActorPreviewInitializer(rules.Actors[Building], Producer.Owner, wr, new TypeDictionary());
|
||||||
if (rbi == null)
|
preview = rules.Actors[Building].Traits.WithInterface<IRenderActorPreviewInfo>()
|
||||||
preview = new IRenderable[0];
|
.SelectMany(rpi => rpi.RenderPreview(init))
|
||||||
else
|
.ToArray();
|
||||||
{
|
|
||||||
var palette = rbi.Palette ?? (Producer.Owner != null ?
|
|
||||||
rbi.PlayerPalette + Producer.Owner.InternalName : null);
|
|
||||||
|
|
||||||
preview = rbi.RenderPreview(world, rules.Actors[Building], wr.Palette(palette));
|
|
||||||
}
|
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var offset = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, BuildingInfo) - WPos.Zero;
|
var comparer = new RenderableComparer(wr);
|
||||||
foreach (var r in preview)
|
var offset = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, BuildingInfo);
|
||||||
yield return r.OffsetBy(offset);
|
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 res = world.WorldActor.Trait<ResourceLayer>();
|
||||||
var isCloseEnough = BuildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, Building, topLeft);
|
var isCloseEnough = BuildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, Building, topLeft);
|
||||||
|
|||||||
@@ -12,27 +12,27 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Mods.RA.Buildings;
|
using OpenRA.Mods.RA.Buildings;
|
||||||
|
using OpenRA.Mods.RA.Graphics;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Render
|
namespace OpenRA.Mods.RA.Render
|
||||||
{
|
{
|
||||||
class RenderBuildingWarFactoryInfo : RenderBuildingInfo
|
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 */
|
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||||
IEnumerable<IRenderable> BaseBuildingPreview(World world, ActorInfo building, PaletteReference pr)
|
|
||||||
{
|
{
|
||||||
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)
|
// Show additional roof overlay
|
||||||
{
|
var anim = new Animation(init.World, image, () => 0);
|
||||||
var p = BaseBuildingPreview(world, building, pr);
|
|
||||||
var anim = new Animation(world, RenderSprites.GetImage(building), () => 0);
|
|
||||||
anim.PlayRepeating("idle-top");
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,20 +11,23 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Mods.RA.Graphics;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Render
|
namespace OpenRA.Mods.RA.Render
|
||||||
{
|
{
|
||||||
public class RenderSimpleInfo : RenderSpritesInfo, IQuantizeBodyOrientationInfo, ILegacyEditorRenderInfo, Requires<IBodyOrientationInfo>
|
public class RenderSimpleInfo : RenderSpritesInfo, IRenderActorPreviewSpritesInfo, IQuantizeBodyOrientationInfo, ILegacyEditorRenderInfo, Requires<IBodyOrientationInfo>
|
||||||
{
|
{
|
||||||
public override object Create(ActorInitializer init) { return new RenderSimple(init.self); }
|
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);
|
var ifacing = init.Actor.Traits.GetOrDefault<IFacingInfo>();
|
||||||
anim.PlayRepeating("idle");
|
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)
|
public virtual int QuantizedBodyFacings(SequenceProvider sequenceProvider, ActorInfo ai)
|
||||||
|
|||||||
@@ -12,12 +12,15 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Mods.RA.Graphics;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Render
|
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.")]
|
[Desc("Defaults to the actor name.")]
|
||||||
public readonly string Image = null;
|
public readonly string Image = null;
|
||||||
@@ -30,6 +33,23 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
public readonly float Scale = 1f;
|
public readonly float Scale = 1f;
|
||||||
|
|
||||||
public virtual object Create(ActorInitializer init) { return new RenderSprites(init.self); }
|
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
|
public class RenderSprites : IRender, ITick, INotifyOwnerChanged, INotifyEffectiveOwnerChanged
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenRA.Mods.RA.Activities;
|
using OpenRA.Mods.RA.Activities;
|
||||||
|
using OpenRA.Mods.RA.Graphics;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
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 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 INotifyAttack { void Attacking(Actor self, Target target, Armament a, Barrel barrel); }
|
||||||
public interface INotifyChat { bool OnChat(string from, string message); }
|
public interface INotifyChat { bool OnChat(string from, string message); }
|
||||||
|
public interface IRenderActorPreviewInfo { IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init); }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user