Move some Render traits to Mods.Common

This commit is contained in:
reaperrr
2014-12-09 22:37:49 +01:00
parent 88c119ebba
commit 9a1e110481
6 changed files with 8 additions and 11 deletions

View File

@@ -139,13 +139,17 @@
<Compile Include="Traits\RallyPoint.cs" />
<Compile Include="Traits\Render\RenderEditorOnly.cs" />
<Compile Include="Traits\Render\RenderFlare.cs" />
<Compile Include="Traits\Render\RenderNameTag.cs" />
<Compile Include="Traits\Render\RenderSimple.cs" />
<Compile Include="Traits\Render\RenderSprites.cs" />
<Compile Include="Traits\Render\RenderUnit.cs" />
<Compile Include="Traits\Render\WithBuildingPlacedAnimation.cs" />
<Compile Include="Traits\Render\WithDeathAnimation.cs" />
<Compile Include="Traits\Render\WithResources.cs" />
<Compile Include="Traits\Render\WithShadow.cs" />
<Compile Include="Traits\Render\WithSmoke.cs" />
<Compile Include="Traits\ShakeOnDeath.cs" />
<Compile Include="Traits\SmokeTrailWhenDamaged.cs" />
<Compile Include="Traits\Sound\ActorLostNotification.cs" />
<Compile Include="Traits\Sound\AnnounceOnBuild.cs" />
<Compile Include="Traits\Sound\AnnounceOnKill.cs" />

View File

@@ -0,0 +1,57 @@
#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.Collections.Generic;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Displays the player name above the unit")]
class RenderNameTagInfo : ITraitInfo
{
public readonly int MaxLength = 10;
public readonly string Font = "TinyBold";
public object Create(ActorInitializer init) { return new RenderNameTag(init.self, this); }
}
class RenderNameTag : IRender
{
readonly SpriteFont font;
readonly Color color;
readonly string name;
public RenderNameTag(Actor self, RenderNameTagInfo info)
{
font = Game.Renderer.Fonts[info.Font];
color = self.Owner.Color.RGB;
if (self.Owner.PlayerName.Length > info.MaxLength)
name = self.Owner.PlayerName.Substring(0, info.MaxLength);
else
name = self.Owner.PlayerName;
}
public IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr)
{
var pos = wr.ScreenPxPosition(self.CenterPosition);
var bounds = self.Bounds;
bounds.Offset(pos.X, pos.Y);
var spaceBuffer = (int)(10 / wr.Viewport.Zoom);
var effectPos = wr.Position(new int2(pos.X, bounds.Y - spaceBuffer));
yield return new TextRenderable(font, effectPos, 0, color, name);
}
}
}

View File

@@ -0,0 +1,48 @@
#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 System.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Clones the aircraft sprite with another palette below it.")]
class WithShadowInfo : ITraitInfo
{
public readonly string Palette = "shadow";
public object Create(ActorInitializer init) { return new WithShadow(this); }
}
class WithShadow : IRenderModifier
{
WithShadowInfo info;
public WithShadow(WithShadowInfo info)
{
this.info = info;
}
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)
{
// Contrails shouldn't cast shadows
var shadowSprites = r.Where(s => !s.IsDecoration)
.Select(a => a.WithPalette(wr.Palette(info.Palette))
.OffsetBy(new WVec(0, 0, -a.Pos.Z))
.WithZOffset(a.ZOffset + a.Pos.Z)
.AsDecoration());
return shadowSprites.Concat(r);
}
}
}

View File

@@ -0,0 +1,51 @@
#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.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Renders an overlay when the actor is taking heavy damage.")]
public class WithSmokeInfo : ITraitInfo, Requires<RenderSpritesInfo>
{
[Desc("Needs to define \"idle\", \"loop\" and \"end\" sub-sequences.")]
public readonly string Sequence = "smoke_m";
public object Create(ActorInitializer init) { return new WithSmoke(init.self, this); }
}
public class WithSmoke : INotifyDamage
{
bool isSmoking;
Animation anim;
public WithSmoke(Actor self, WithSmokeInfo info)
{
var rs = self.Trait<RenderSprites>();
anim = new Animation(self.World, info.Sequence);
rs.Add("smoke", new AnimationWithOffset(anim, null, () => !isSmoking));
}
public void Damaged(Actor self, AttackInfo e)
{
if (isSmoking) return;
if (e.Damage < 0) return; /* getting healed */
if (e.DamageState < DamageState.Heavy) return;
isSmoking = true;
anim.PlayThen("idle",
() => anim.PlayThen("loop",
() => anim.PlayBackwardsThen("end",
() => isSmoking = false)));
}
}
}

View File

@@ -0,0 +1,55 @@
#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.Mods.Common.Effects;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
class SmokeTrailWhenDamagedInfo : ITraitInfo, Requires<IBodyOrientationInfo>
{
[Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero;
public readonly int Interval = 3;
public readonly string Sprite = "smokey";
public readonly DamageState MinDamage = DamageState.Heavy;
public object Create(ActorInitializer init) { return new SmokeTrailWhenDamaged(init.self, this); }
}
class SmokeTrailWhenDamaged : ITick
{
IBodyOrientation body;
SmokeTrailWhenDamagedInfo info;
int ticks;
public SmokeTrailWhenDamaged(Actor self, SmokeTrailWhenDamagedInfo info)
{
this.info = info;
body = self.Trait<IBodyOrientation>();
}
public void Tick(Actor self)
{
if (--ticks <= 0)
{
var position = self.CenterPosition;
if (position.Z > 0 && self.GetDamageState() >= info.MinDamage && !self.World.FogObscures(self))
{
var offset = info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation));
var pos = position + body.LocalToWorld(offset);
self.World.AddFrameEndTask(w => w.Add(new Smoke(w, pos, info.Sprite)));
}
ticks = info.Interval;
}
}
}
}