Add IBlocksProjectiles interface to avoid using BlocksProjectiles directly

This commit is contained in:
teees
2015-11-28 21:34:12 +01:00
parent 7f2feb29cd
commit 3d597c7880
2 changed files with 27 additions and 10 deletions

View File

@@ -9,7 +9,9 @@
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Effects;
using OpenRA.Traits;
@@ -22,19 +24,18 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new CombatDebugOverlay(init.Self); }
}
public class CombatDebugOverlay : IPostRender, INotifyDamage
public class CombatDebugOverlay : IPostRender, INotifyDamage, INotifyCreated
{
readonly DeveloperMode devMode;
readonly HealthInfo healthInfo;
readonly BlocksProjectilesInfo blockInfo;
IBlocksProjectiles[] allBlockers;
Lazy<AttackBase> attack;
Lazy<BodyOrientation> coords;
public CombatDebugOverlay(Actor self)
{
healthInfo = self.Info.TraitInfoOrDefault<HealthInfo>();
blockInfo = self.Info.TraitInfoOrDefault<BlocksProjectilesInfo>();
attack = Exts.Lazy(() => self.TraitOrDefault<AttackBase>());
coords = Exts.Lazy(() => self.Trait<BodyOrientation>());
@@ -42,6 +43,11 @@ namespace OpenRA.Mods.Common.Traits
devMode = localPlayer != null ? localPlayer.PlayerActor.Trait<DeveloperMode>() : null;
}
public void Created(Actor self)
{
allBlockers = self.TraitsImplementing<IBlocksProjectiles>().ToArray();
}
public void RenderAfterWorld(WorldRenderer wr, Actor self)
{
if (devMode == null || !devMode.ShowCombatGeometry)
@@ -53,10 +59,11 @@ namespace OpenRA.Mods.Common.Traits
if (healthInfo != null)
healthInfo.Shape.DrawCombatOverlay(wr, wcr, self);
if (blockInfo != null)
var blockers = allBlockers.Where(Exts.IsTraitEnabled).ToList();
if (blockers.Count > 0)
{
var hc = Color.Orange;
var height = new WVec(0, 0, blockInfo.Height.Length);
var height = new WVec(0, 0, blockers.Max(b => b.BlockingHeight.Length));
var ha = wr.ScreenPosition(self.CenterPosition);
var hb = wr.ScreenPosition(self.CenterPosition + height);
wcr.DrawLine(ha, hb, iz, hc);