From ffac0221cf4b3f941daa93d3b8cd6da0eda9d93c Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 16 Mar 2011 21:00:39 +1300 Subject: [PATCH] CashTick IEffect for Oil Derricks. --- OpenRA.Mods.RA/CashTrickler.cs | 22 +++++++++--- OpenRA.Mods.RA/Effects/CashTick.cs | 51 ++++++++++++++++++++++++++++ OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 3 +- 3 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 OpenRA.Mods.RA/Effects/CashTick.cs diff --git a/OpenRA.Mods.RA/CashTrickler.cs b/OpenRA.Mods.RA/CashTrickler.cs index 6036887334..889f998e06 100644 --- a/OpenRA.Mods.RA/CashTrickler.cs +++ b/OpenRA.Mods.RA/CashTrickler.cs @@ -9,27 +9,39 @@ #endregion using OpenRA.Traits; +using OpenRA.Mods.RA.Effects; namespace OpenRA.Mods.RA { - class CashTricklerInfo : TraitInfo + class CashTricklerInfo : ITraitInfo { public readonly int Period = 10; public readonly int Amount = 3; + public readonly bool ShowTicks = true; + public readonly int TickLifetime = 30; + public readonly int TickVelocity = 2; + + public object Create (ActorInitializer init) { return new CashTrickler(this); } } class CashTrickler : ITick, ISync { [Sync] int ticks; - + CashTricklerInfo Info; + public CashTrickler(CashTricklerInfo info) + { + Info = info; + } + public void Tick(Actor self) { if (--ticks < 0) { - var info = self.Info.Traits.Get(); - self.Owner.PlayerActor.Trait().GiveCash(info.Amount); - ticks = info.Period; + self.Owner.PlayerActor.Trait().GiveCash(Info.Amount); + ticks = Info.Period; + if (Info.ShowTicks) + self.World.AddFrameEndTask(w => w.Add(new CashTick(Info.Amount, Info.TickLifetime, Info.TickVelocity, self.CenterLocation, self.Owner.ColorRamp.GetColor(0)))); } } } diff --git a/OpenRA.Mods.RA/Effects/CashTick.cs b/OpenRA.Mods.RA/Effects/CashTick.cs new file mode 100644 index 0000000000..28fa8f24d7 --- /dev/null +++ b/OpenRA.Mods.RA/Effects/CashTick.cs @@ -0,0 +1,51 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 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; +using OpenRA.Effects; +using OpenRA.GameRules; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA.Effects +{ + class CashTick : IEffect + { + string s; + int lifetime = 50; + int remaining; + int velocity; + float2 pos; + Color color; + + public CashTick(int value, int lifetime, int velocity, float2 pos, Color color) + { + this.color = color; + this.lifetime = lifetime; + this.velocity = velocity; + s = "${0}".F(value); + this.pos = pos - 0.5f*Game.Renderer.BoldFont.Measure(s).ToFloat2(); + remaining = lifetime; + } + + public void Tick(World world) + { + if (--remaining <= 0) + world.AddFrameEndTask(w => w.Remove(this)); + pos.Y -= velocity; + } + + public IEnumerable Render() + { + Game.Renderer.BoldFont.DrawTextWithContrast(s, pos - Game.viewport.Location, color, Color.Black,1); + yield break; + } + } +} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index b54c28ccbf..07c9ea77b4 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -330,7 +330,8 @@ - + +