Adds damage debug overlay

This commit is contained in:
DeadlySurprise
2014-09-03 14:17:50 +02:00
parent 8e4b5af352
commit 7183c52a2e
11 changed files with 38 additions and 16 deletions

View File

@@ -34,6 +34,7 @@ Also thanks to:
* D2k Sardaukar
* Daniel Derejvanik (Harisson)
* Danny Keary (Dan9550)
* DeadlySurprise
* Erasmus Schroder (rasco)
* Fahrradkette
* Frank Razenberg (zzattack)

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Activities
self.Destroy();
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
self.World.AddFrameEndTask(w => w.Add(new CashTick(targetActor.CenterPosition, targetActor.Owner.Color.RGB, payload)));
self.World.AddFrameEndTask(w => w.Add(new FloatingText(targetActor.CenterPosition, targetActor.Owner.Color.RGB, FloatingText.FormatCashTick(payload), 30)));
return this;
}

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Activities
ns.Sold(self);
if (refund > 0 && self.Owner.IsAlliedWith(self.World.RenderPlayer))
self.World.AddFrameEndTask(w => w.Add(new CashTick(self.CenterPosition, self.Owner.Color.RGB, refund)));
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(refund), 30)));
self.Destroy();
return this;

View File

@@ -59,7 +59,7 @@ namespace OpenRA.Mods.RA
void MaybeAddCashTick(Actor self, int amount)
{
if (Info.ShowTicks)
self.World.AddFrameEndTask(w => w.Add(new CashTick(self.CenterPosition, self.Owner.Color.RGB, amount)));
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(amount), 30)));
}
}
}

View File

@@ -12,6 +12,7 @@ using System;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Traits;
using OpenRA.Mods.RA.Effects;
namespace OpenRA.Mods.RA
{
@@ -20,7 +21,7 @@ namespace OpenRA.Mods.RA
public object Create(ActorInitializer init) { return new CombatDebugOverlay(init.self); }
}
public class CombatDebugOverlay : IPostRender
public class CombatDebugOverlay : IPostRender, INotifyDamage
{
Lazy<AttackBase> attack;
Lazy<IBodyOrientation> coords;
@@ -87,5 +88,19 @@ namespace OpenRA.Mods.RA
}
}
}
public void Damaged(Actor self, AttackInfo e)
{
if (devMode == null || !devMode.ShowCombatGeometry || e.Damage == 0)
return;
var health = self.TraitOrDefault<Health>();
if (health == null)
return;
var damageText = "{0} ({1}%)".F(-e.Damage, e.Damage * 100 / health.MaxHP);
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color.RGB, damageText, 30)));
}
}
}

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA
collector.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(amount);
if (crateInfo.UseCashTick)
w.Add(new CashTick(collector.CenterPosition, collector.Owner.Color.RGB, amount));
w.Add(new FloatingText(collector.CenterPosition, collector.Owner.Color.RGB, FloatingText.FormatCashTick(amount), 30));
});
base.Activate(collector);

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#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
@@ -17,23 +17,24 @@ using OpenRA.Mods.RA.Graphics;
namespace OpenRA.Mods.RA.Effects
{
class CashTick : IEffect
public class FloatingText : IEffect
{
readonly SpriteFont font;
readonly string text;
Color color;
int remaining = 30;
int remaining;
WPos pos;
public CashTick(WPos pos, Color color, int value)
public FloatingText(WPos pos, Color color, string text, int duration)
{
this.font = Game.Renderer.Fonts["TinyBold"];
this.pos = pos;
this.color = color;
this.text = "{0}${1}".F(value < 0 ? "-" : "+", Math.Abs(value));
this.text = text;
this.remaining = duration;
}
static readonly WVec velocity = new WVec(0,0,86);
static readonly WVec velocity = new WVec(0, 0, 86);
public void Tick(World world)
{
if (--remaining <= 0)
@@ -49,5 +50,10 @@ namespace OpenRA.Mods.RA.Effects
yield return new TextRenderable(font, pos, 0, color, text);
}
public static string FormatCashTick(int cashAmount)
{
return "{0}${1}".F(cashAmount < 0 ? "-" : "+", Math.Abs(cashAmount));
}
}
}

View File

@@ -53,7 +53,7 @@ namespace OpenRA.Mods.RA
var bounty = cost * GetMultiplier(self) * info.Percentage / 10000;
if (bounty > 0 && e.Attacker.Owner.IsAlliedWith(self.World.RenderPlayer))
e.Attacker.World.AddFrameEndTask(w => w.Add(new CashTick(self.CenterPosition, e.Attacker.Owner.Color.RGB, bounty)));
e.Attacker.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color.RGB, FloatingText.FormatCashTick(bounty), 30)));
e.Attacker.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(bounty);
}

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Infiltration
Sound.PlayToPlayer(self.Owner, info.SoundToVictim);
self.World.AddFrameEndTask(w => w.Add(new CashTick(self.CenterPosition, infiltrator.Owner.Color.RGB, toGive)));
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, infiltrator.Owner.Color.RGB, FloatingText.FormatCashTick(toGive), 30)));
}
}
}

View File

@@ -120,6 +120,8 @@
<Compile Include="Air\AttackPlane.cs" />
<Compile Include="AI\SupportPowerDecision.cs" />
<Compile Include="Crates\DuplicateUnitCrateAction.cs" />
<Compile Include="Effects\FloatingText.cs" />
<Compile Include="Graphics\TextRenderable.cs" />
<Compile Include="Infiltration\InfiltrateForPowerOutage.cs" />
<Compile Include="Power\AffectedByPowerOutage.cs" />
<Compile Include="Power\Power.cs" />
@@ -212,7 +214,6 @@
<Compile Include="DemoTruck.cs" />
<Compile Include="DetectCloaked.cs" />
<Compile Include="Effects\Bullet.cs" />
<Compile Include="Effects\CashTick.cs" />
<Compile Include="Effects\Contrail.cs" />
<Compile Include="Effects\Corpse.cs" />
<Compile Include="Effects\CrateEffect.cs" />
@@ -534,7 +535,6 @@
<Compile Include="Render\RenderSprites.cs" />
<Compile Include="Graphics\BeamRenderable.cs" />
<Compile Include="Graphics\ContrailRenderable.cs" />
<Compile Include="Graphics\TextRenderable.cs" />
<Compile Include="Graphics\VoxelRenderable.cs" />
<Compile Include="Air\FlyAwayOnIdle.cs" />
<Compile Include="Buildings\ClonesProducedUnits.cs" />

View File

@@ -93,7 +93,7 @@ namespace OpenRA.Mods.RA
{
var temp = currentDisplayValue;
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
self.World.AddFrameEndTask(w => w.Add(new CashTick(self.CenterPosition, self.Owner.Color.RGB, temp)));
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(temp), 30)));
currentDisplayTick = Info.TickRate;
currentDisplayValue = 0;
}