diff --git a/OpenRA.Game/Graphics/TextRenderable.cs b/OpenRA.Game/Graphics/TextRenderable.cs new file mode 100644 index 0000000000..cbebceb6cd --- /dev/null +++ b/OpenRA.Game/Graphics/TextRenderable.cs @@ -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); + } + } +} diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index e16d1f3b80..36357505a1 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -233,6 +233,7 @@ + diff --git a/OpenRA.Mods.RA/Activities/DonateSupplies.cs b/OpenRA.Mods.RA/Activities/DonateSupplies.cs index c140c3f89e..5d82168c76 100644 --- a/OpenRA.Mods.RA/Activities/DonateSupplies.cs +++ b/OpenRA.Mods.RA/Activities/DonateSupplies.cs @@ -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().GiveCash(payload); + var targetActor = target.Actor; + targetActor.Owner.PlayerActor.Trait().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; } diff --git a/OpenRA.Mods.RA/Activities/Sell.cs b/OpenRA.Mods.RA/Activities/Sell.cs index ddc2f78652..2222cedacf 100755 --- a/OpenRA.Mods.RA/Activities/Sell.cs +++ b/OpenRA.Mods.RA/Activities/Sell.cs @@ -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; diff --git a/OpenRA.Mods.RA/CashTrickler.cs b/OpenRA.Mods.RA/CashTrickler.cs index ca4130736b..290403c389 100644 --- a/OpenRA.Mods.RA/CashTrickler.cs +++ b/OpenRA.Mods.RA/CashTrickler.cs @@ -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))); } } } diff --git a/OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs b/OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs index 43ecd9770e..4d2c0c848a 100644 --- a/OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA collector.Owner.PlayerActor.Trait().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); diff --git a/OpenRA.Mods.RA/Effects/CashTick.cs b/OpenRA.Mods.RA/Effects/CashTick.cs index ef84230ec2..a1b5998211 100644 --- a/OpenRA.Mods.RA/Effects/CashTick.cs +++ b/OpenRA.Mods.RA/Effects/CashTick.cs @@ -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 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); } } } diff --git a/OpenRA.Mods.RA/GivesBounty.cs b/OpenRA.Mods.RA/GivesBounty.cs index 0a3064308d..d4cf88cbc0 100644 --- a/OpenRA.Mods.RA/GivesBounty.cs +++ b/OpenRA.Mods.RA/GivesBounty.cs @@ -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().GiveCash(bounty); } diff --git a/OpenRA.Mods.RA/InfiltrateForCash.cs b/OpenRA.Mods.RA/InfiltrateForCash.cs index 1e7ba1c929..b0f27fa33c 100644 --- a/OpenRA.Mods.RA/InfiltrateForCash.cs +++ b/OpenRA.Mods.RA/InfiltrateForCash.cs @@ -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))); } } } diff --git a/OpenRA.Mods.RA/OreRefinery.cs b/OpenRA.Mods.RA/OreRefinery.cs index a1069c7b9f..a398b98dd8 100644 --- a/OpenRA.Mods.RA/OreRefinery.cs +++ b/OpenRA.Mods.RA/OreRefinery.cs @@ -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; }