Add TextRenderable for CashTick. Make ticks consistent.
This commit is contained in:
57
OpenRA.Game/Graphics/TextRenderable.cs
Normal file
57
OpenRA.Game/Graphics/TextRenderable.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2013 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;
|
||||
|
||||
namespace OpenRA.Graphics
|
||||
{
|
||||
public struct TextRenderable : IRenderable
|
||||
{
|
||||
readonly SpriteFont font;
|
||||
readonly WPos pos;
|
||||
readonly int zOffset;
|
||||
readonly Color color;
|
||||
readonly string text;
|
||||
|
||||
public TextRenderable(SpriteFont font, WPos pos, int zOffset, Color color, string text)
|
||||
{
|
||||
this.font = font;
|
||||
this.pos = pos;
|
||||
this.zOffset = zOffset;
|
||||
this.color = color;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public WPos Pos { get { return pos; } }
|
||||
public float Scale { get { return 1f; } }
|
||||
public PaletteReference Palette { get { return null; } }
|
||||
public int ZOffset { get { return zOffset; } }
|
||||
|
||||
public IRenderable WithScale(float newScale) { return new TextRenderable(font, pos, zOffset, color, text); }
|
||||
public IRenderable WithPalette(PaletteReference newPalette) { return new TextRenderable(font, pos, zOffset, color, text); }
|
||||
public IRenderable WithZOffset(int newOffset) { return new TextRenderable(font, pos, zOffset, color, text); }
|
||||
public IRenderable WithPos(WPos pos) { return new TextRenderable(font, pos, zOffset, color, text); }
|
||||
|
||||
public void BeforeRender(WorldRenderer wr) {}
|
||||
public void Render(WorldRenderer wr)
|
||||
{
|
||||
var screenPos = Game.viewport.Zoom*(wr.ScreenPxPosition(pos) - Game.viewport.Location) - 0.5f*font.Measure(text).ToFloat2();
|
||||
font.DrawTextWithContrast(text, screenPos, color, Color.Black, 1);
|
||||
}
|
||||
|
||||
public void RenderDebugGeometry(WorldRenderer wr)
|
||||
{
|
||||
var size = font.Measure(text).ToFloat2();
|
||||
var offset = wr.ScreenPxPosition(pos) - 0.5f*size;
|
||||
Game.Renderer.WorldLineRenderer.DrawRect(offset, offset + size, Color.Red);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -233,6 +233,7 @@
|
||||
<Compile Include="Traits\BodyOrientation.cs" />
|
||||
<Compile Include="Graphics\VoxelAnimation.cs" />
|
||||
<Compile Include="Graphics\VoxelRenderable.cs" />
|
||||
<Compile Include="Graphics\TextRenderable.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user