Add TextRenderable for CashTick. Make ticks consistent.

This commit is contained in:
Paul Chote
2013-06-16 19:10:38 +12:00
parent 52335a37bf
commit 1eb04a70a5
10 changed files with 81 additions and 36 deletions

View File

@@ -27,15 +27,15 @@ namespace OpenRA.Mods.RA.Activities
public override Activity Tick(Actor self)
{
if (IsCanceled || !target.IsValid)
if (IsCanceled || !target.IsValid || !target.IsActor)
return NextActivity;
var targetPlayer = target.Actor.Owner;
targetPlayer.PlayerActor.Trait<PlayerResources>().GiveCash(payload);
var targetActor = target.Actor;
targetActor.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(payload);
self.Destroy();
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
self.World.AddFrameEndTask(w => w.Add(new CashTick(payload, 30, 2, target.CenterLocation, targetPlayer.Color.RGB)));
self.World.AddFrameEndTask(w => w.Add(new CashTick(targetActor.CenterPosition, targetActor.Owner.Color.RGB, payload)));
return this;
}

View File

@@ -32,7 +32,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(refund, 30, 2, self.CenterLocation, self.Owner.Color.RGB)));
self.World.AddFrameEndTask(w => w.Add(new CashTick(self.CenterPosition, self.Owner.Color.RGB, refund)));
self.Destroy();
return this;

View File

@@ -23,10 +23,6 @@ namespace OpenRA.Mods.RA
public readonly int Amount = 15;
[Desc("Whether to show the cash tick indicators (+$15 rising from actor).")]
public readonly bool ShowTicks = true;
[Desc("How long the cash tick indicator should be shown for.")]
public readonly int TickLifetime = 30;
[Desc("Pixels/tick upward movement of the cash tick indicator.")]
public readonly int TickVelocity = 1;
[Desc("Amount of money awarded for capturing the actor.")]
public readonly int CaptureAmount = 0;
@@ -64,7 +60,7 @@ namespace OpenRA.Mods.RA
void MaybeAddCashTick(Actor self, int amount)
{
if (Info.ShowTicks)
self.World.AddFrameEndTask(w => w.Add(new CashTick(amount, Info.TickLifetime, Info.TickVelocity, self.CenterLocation, self.Owner.Color.RGB)));
self.World.AddFrameEndTask(w => w.Add(new CashTick(self.CenterPosition, self.Owner.Color.RGB, amount)));
}
}
}

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
collector.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(amount);
if ((info as GiveCashCrateActionInfo).UseCashTick)
w.Add(new CashTick(amount, 20, 1, collector.CenterLocation, collector.Owner.Color.RGB));
w.Add(new CashTick(collector.CenterPosition, collector.Owner.Color.RGB, amount));
});
base.Activate(collector);

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Effects;
@@ -18,41 +19,32 @@ namespace OpenRA.Mods.RA.Effects
{
class CashTick : IEffect
{
readonly string s;
int remaining;
readonly int velocity;
PPos pos;
readonly float2 offset;
readonly Color color;
readonly SpriteFont font;
readonly string text;
Color color;
int remaining = 30;
WPos pos;
static string FormatCashAmount(int x) { return "{0}${1}".F(x < 0 ? "-" : "+", x); }
public CashTick(int value, int lifetime, int velocity, PPos pos, Color color)
: this(FormatCashAmount(value), lifetime, velocity, pos, color) { }
public CashTick(string value, int lifetime, int velocity, PPos pos, Color color)
public CashTick(WPos pos, Color color, int value)
{
this.color = color;
this.velocity = velocity;
this.font = Game.Renderer.Fonts["TinyBold"];
this.pos = pos;
s = value;
font = Game.Renderer.Fonts["TinyBold"];
offset = 0.5f*font.Measure(s).ToFloat2();
remaining = lifetime;
this.color = color;
this.text = "{0}${1}".F(value < 0 ? "-" : "+", Math.Abs(value));
}
static readonly WVec velocity = new WVec(0,0,86);
public void Tick(World world)
{
if (--remaining <= 0)
world.AddFrameEndTask(w => w.Remove(this));
pos -= new PVecInt(0, velocity);
pos += velocity;
}
public IEnumerable<IRenderable> Render(WorldRenderer wr)
{
font.DrawTextWithContrast(s, Game.viewport.Zoom*(pos.ToFloat2() - Game.viewport.Location) - offset, color, Color.Black,1);
yield break;
yield return new TextRenderable(font, pos, 0, color, text);
}
}
}

View File

@@ -54,7 +54,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(bounty, 20, 1, self.CenterLocation, e.Attacker.Owner.Color.RGB)));
e.Attacker.World.AddFrameEndTask(w => w.Add(new CashTick(self.CenterPosition, e.Attacker.Owner.Color.RGB, bounty)));
e.Attacker.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(bounty);
}

View File

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

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(temp, Info.TickLifetime, Info.TickVelocity, self.CenterLocation, self.Owner.Color.RGB)));
self.World.AddFrameEndTask(w => w.Add(new CashTick(self.CenterPosition, self.Owner.Color.RGB, temp)));
currentDisplayTick = Info.TickRate;
currentDisplayValue = 0;
}