Merge pull request #4393 from cjshmyr/nametag
Added RenderNameTag trait for actors
This commit is contained in:
@@ -84,6 +84,7 @@ NEW:
|
|||||||
Added a new Launch.Replay=$FILEPATH parameter for OpenRA.Game.exe to instantly start watching a *.rep file.
|
Added a new Launch.Replay=$FILEPATH parameter for OpenRA.Game.exe to instantly start watching a *.rep file.
|
||||||
Added HackyAI settings: ExcessPowerFactor, MinimumExcessPower, IdleBaseUnitsMaximum, RushAttackScanRadius, ProtectUnitScanRadius, RallyPointScanRadius. See the traits documentation for more information.
|
Added HackyAI settings: ExcessPowerFactor, MinimumExcessPower, IdleBaseUnitsMaximum, RushAttackScanRadius, ProtectUnitScanRadius, RallyPointScanRadius. See the traits documentation for more information.
|
||||||
Added HitAnimPalette trait for LaserZap projectiles. Laser hit animations can now specify individual palettes. Defaults to effect palette.
|
Added HitAnimPalette trait for LaserZap projectiles. Laser hit animations can now specify individual palettes. Defaults to effect palette.
|
||||||
|
Added RenderNameTag trait to show the player's name above an actor.
|
||||||
Fixed performance issues with units pathing to naval transports.
|
Fixed performance issues with units pathing to naval transports.
|
||||||
Fixed unit moving to transports that have moved.
|
Fixed unit moving to transports that have moved.
|
||||||
Server:
|
Server:
|
||||||
|
|||||||
@@ -341,6 +341,7 @@
|
|||||||
<Compile Include="Render\RenderUnitReload.cs" />
|
<Compile Include="Render\RenderUnitReload.cs" />
|
||||||
<Compile Include="Render\WithBuildingExplosion.cs" />
|
<Compile Include="Render\WithBuildingExplosion.cs" />
|
||||||
<Compile Include="Render\WithMuzzleFlash.cs" />
|
<Compile Include="Render\WithMuzzleFlash.cs" />
|
||||||
|
<Compile Include="Render\RenderNameTag.cs" />
|
||||||
<Compile Include="Render\WithRotor.cs" />
|
<Compile Include="Render\WithRotor.cs" />
|
||||||
<Compile Include="Render\WithShadow.cs" />
|
<Compile Include="Render\WithShadow.cs" />
|
||||||
<Compile Include="Render\WithSmoke.cs" />
|
<Compile Include="Render\WithSmoke.cs" />
|
||||||
|
|||||||
52
OpenRA.Mods.RA/Render/RenderNameTag.cs
Normal file
52
OpenRA.Mods.RA/Render/RenderNameTag.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#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.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA.Render
|
||||||
|
{
|
||||||
|
class RenderNameTagInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
public readonly int MaxLength = 10;
|
||||||
|
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["TinyBold"];
|
||||||
|
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.Value;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user