Render building previews
This commit is contained in:
@@ -28,19 +28,24 @@ namespace OpenRA.Traits
|
||||
public Dictionary<string, AnimationWithOffset> anims = new Dictionary<string, AnimationWithOffset>();
|
||||
public Animation anim { get { return anims[""].Animation; } protected set { anims[""].Animation = value; } }
|
||||
|
||||
public static string GetImage(ActorInfo actor, string Tileset)
|
||||
{
|
||||
var Info = actor.Traits.Get<RenderSimpleInfo>();
|
||||
if (Info.OverrideTileset != null && Tileset != null)
|
||||
for (int i = 0; i < Info.OverrideTileset.Length; i++)
|
||||
if (Info.OverrideTileset[i] == Tileset)
|
||||
return Info.OverrideImage[i];
|
||||
|
||||
return Info.Image ?? actor.Name;
|
||||
}
|
||||
|
||||
string cachedImage = null;
|
||||
public string GetImage(Actor self)
|
||||
{
|
||||
if (cachedImage != null)
|
||||
return cachedImage;
|
||||
|
||||
var Info = self.Info.Traits.Get<RenderSimpleInfo>();
|
||||
if (Info.OverrideTileset != null)
|
||||
for (int i = 0; i < Info.OverrideTileset.Length; i++)
|
||||
if (Info.OverrideTileset[i] == self.World.Map.Tileset)
|
||||
return cachedImage = Info.OverrideImage[i];
|
||||
|
||||
return cachedImage = Info.Image ?? self.Info.Name;
|
||||
return cachedImage = GetImage(self.Info, self.World.Map.Tileset);
|
||||
}
|
||||
|
||||
public RenderSimple(Actor self, Func<int> baseFacing)
|
||||
|
||||
@@ -13,6 +13,7 @@ using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
|
||||
namespace OpenRA.Mods.RA.Orders
|
||||
{
|
||||
@@ -60,11 +61,14 @@ namespace OpenRA.Mods.RA.Orders
|
||||
}
|
||||
|
||||
public void Tick( World world ) {}
|
||||
|
||||
public void RenderAfterWorld( WorldRenderer wr, World world ) { }
|
||||
|
||||
public void RenderAfterWorld( WorldRenderer wr, World world ) {}
|
||||
public void RenderBeforeWorld( WorldRenderer wr, World world )
|
||||
{
|
||||
var topleft = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2() - FootprintUtils.AdjustForBuildingSize( BuildingInfo );
|
||||
var renderables = Rules.Info[Building].Traits.Get<RenderBuildingInfo>().BuildingPreview(Rules.Info[Building], world.Map.Tileset);
|
||||
foreach (var r in renderables)
|
||||
r.Sprite.DrawAt(wr,Game.CellSize*topleft + r.Pos, r.Palette ?? world.LocalPlayer.Palette);
|
||||
|
||||
BuildingInfo.DrawBuildingGrid( wr, world, Building );
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Effects;
|
||||
using OpenRA.Traits;
|
||||
@@ -22,6 +23,14 @@ namespace OpenRA.Mods.RA.Render
|
||||
public readonly bool HasMakeAnimation = true;
|
||||
public readonly float2 Origin = float2.Zero;
|
||||
public override object Create(ActorInitializer init) { return new RenderBuilding(init);}
|
||||
|
||||
public virtual IEnumerable<Renderable> BuildingPreview(ActorInfo building, string Tileset)
|
||||
{
|
||||
var anim = new Animation(RenderSimple.GetImage(building, Tileset), () => 0);
|
||||
anim.PlayRepeating("idle");
|
||||
var rb = building.Traits.Get<RenderBuildingInfo>();
|
||||
yield return new Renderable(anim.Image,rb.Origin,rb.Palette,0);
|
||||
}
|
||||
}
|
||||
|
||||
public class RenderBuilding : RenderSimple, INotifyDamage, INotifySold, IRenderModifier
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
@@ -17,6 +18,17 @@ namespace OpenRA.Mods.RA.Render
|
||||
class RenderWarFactoryInfo : RenderBuildingInfo
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new RenderWarFactory(init); }
|
||||
|
||||
public override IEnumerable<Renderable> BuildingPreview(ActorInfo building, string Tileset)
|
||||
{
|
||||
foreach (var r in base.BuildingPreview(building, Tileset))
|
||||
yield return r;
|
||||
|
||||
var anim = new Animation(RenderSimple.GetImage(building, Tileset), () => 0);
|
||||
anim.PlayRepeating("idle-top");
|
||||
var rb = building.Traits.Get<RenderBuildingInfo>();
|
||||
yield return new Renderable(anim.Image,rb.Origin,rb.Palette,0);
|
||||
}
|
||||
}
|
||||
|
||||
class RenderWarFactory : RenderBuilding, INotifyBuildComplete, INotifyDamage, ITick, INotifyProduction, INotifySold
|
||||
|
||||
Reference in New Issue
Block a user