Dissolve Render namespace

This commit is contained in:
reaperrr
2014-12-25 23:40:40 +01:00
parent 51fe951cd6
commit 2054e41552
42 changed files with 43 additions and 55 deletions

View File

@@ -170,7 +170,9 @@
<Compile Include="Traits\Render\RenderUnit.cs" />
<Compile Include="Traits\Render\TimedUpgradeBar.cs" />
<Compile Include="Traits\Render\WithBuildingPlacedAnimation.cs" />
<Compile Include="Traits\Render\WithCrateBody.cs" />
<Compile Include="Traits\Render\WithDeathAnimation.cs" />
<Compile Include="Traits\Render\WithHarvestAnimation.cs" />
<Compile Include="Traits\Render\WithResources.cs" />
<Compile Include="Traits\Render\WithRotor.cs" />
<Compile Include="Traits\Render\WithShadow.cs" />

View File

@@ -0,0 +1,50 @@
#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.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Renders crates with both water and land variants.")]
class WithCrateBodyInfo : ITraitInfo, Requires<RenderSpritesInfo>
{
public readonly string[] Images = { "crate" };
[Desc("Easteregg sequences to use in december.")]
public readonly string[] XmasImages = { };
public object Create(ActorInitializer init) { return new WithCrateBody(init.self, this); }
}
class WithCrateBody : INotifyParachuteLanded
{
readonly Actor self;
readonly Animation anim;
public WithCrateBody(Actor self, WithCrateBodyInfo info)
{
this.self = self;
var rs = self.Trait<RenderSprites>();
var images = info.XmasImages.Any() && DateTime.Today.Month == 12 ? info.XmasImages : info.Images;
anim = new Animation(self.World, images.Random(Game.CosmeticRandom));
anim.Play("idle");
rs.Add("crate", anim);
}
public void OnLanded()
{
var seq = self.World.Map.GetTerrainInfo(self.Location).IsWater ? "water" : "land";
anim.PlayRepeating(seq);
}
}
}

View File

@@ -0,0 +1,69 @@
#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 OpenRA.Graphics;
using OpenRA.Activities;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Displays an overlay whenever resources are harvested by the actor.")]
class WithHarvestAnimationInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
{
[Desc("Sequence name to use")]
public readonly string Sequence = "harvest";
[Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero;
public object Create(ActorInitializer init) { return new WithHarvestAnimation(init.self, this); }
}
class WithHarvestAnimation : INotifyHarvesterAction
{
WithHarvestAnimationInfo info;
Animation anim;
bool visible;
public WithHarvestAnimation(Actor self, WithHarvestAnimationInfo info)
{
this.info = info;
var rs = self.Trait<RenderSprites>();
var body = self.Trait<IBodyOrientation>();
anim = new Animation(self.World, rs.GetImage(self), RenderSimple.MakeFacingFunc(self));
anim.Play(info.Sequence);
rs.Add("harvest_{0}".F(info.Sequence), new AnimationWithOffset(anim,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !visible,
() => false,
p => ZOffsetFromCenter(self, p, 0)));
}
public void Harvested(Actor self, ResourceType resource)
{
if (visible)
return;
visible = true;
anim.PlayThen(info.Sequence, () => visible = false);
}
public void MovingToResources(Actor self, CPos targetCell, Activity next) { }
public void MovingToRefinery(Actor self, CPos targetCell, Activity next) { }
public void MovementCancelled(Actor self) { }
static public int ZOffsetFromCenter(Actor self, WPos pos, int offset)
{
var delta = self.CenterPosition - pos;
return delta.Y + delta.Z + offset;
}
}
}

View File

@@ -21,6 +21,7 @@ namespace OpenRA.Mods.Common.Traits
}
public interface INotifyChat { bool OnChat(string from, string message); }
public interface INotifyParachuteLanded { void OnLanded(); }
public interface IRenderActorPreviewInfo { IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init); }
public interface ICruiseAltitudeInfo { WRange GetCruiseAltitude(); }