diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 5b20d1daed..15474ec6a7 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -413,6 +413,7 @@ + diff --git a/OpenRA.Mods.Common/Traits/CashTrickler.cs b/OpenRA.Mods.Common/Traits/CashTrickler.cs index 3db9178bc8..978c2b8893 100644 --- a/OpenRA.Mods.Common/Traits/CashTrickler.cs +++ b/OpenRA.Mods.Common/Traits/CashTrickler.cs @@ -40,13 +40,13 @@ namespace OpenRA.Mods.Common.Traits { readonly CashTricklerInfo info; PlayerResources resources; - [Sync] int ticks; + [Sync] public int Ticks { get; private set; } public CashTrickler(CashTricklerInfo info) : base(info) { this.info = info; - ticks = info.InitialDelay; + Ticks = info.InitialDelay; } protected override void Created(Actor self) @@ -64,14 +64,14 @@ namespace OpenRA.Mods.Common.Traits void ITick.Tick(Actor self) { if (IsTraitDisabled) - ticks = info.Interval; + Ticks = info.Interval; if (IsTraitPaused || IsTraitDisabled) return; - if (--ticks < 0) + if (--Ticks < 0) { - ticks = info.Interval; + Ticks = info.Interval; ModifyCash(self, self.Owner, info.Amount); } } diff --git a/OpenRA.Mods.Common/Traits/Render/CashTricklerBar.cs b/OpenRA.Mods.Common/Traits/Render/CashTricklerBar.cs new file mode 100644 index 0000000000..7bc5257da3 --- /dev/null +++ b/OpenRA.Mods.Common/Traits/Render/CashTricklerBar.cs @@ -0,0 +1,56 @@ +#region Copyright & License Information +/* + * Copyright 2007-2017 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, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits.Render +{ + [Desc("Display the time remaining until the next cash is given by actor's CashTrickler trait.")] + class CashTricklerBarInfo : ITraitInfo, Requires + { + [Desc("Defines to which players the bar is to be shown.")] + public readonly Stance DisplayStances = Stance.Ally; + + public readonly Color Color = Color.Magenta; + + public object Create(ActorInitializer init) { return new CashTricklerBar(init.Self, this); } + } + + class CashTricklerBar : ISelectionBar + { + readonly Actor self; + readonly CashTricklerBarInfo info; + readonly IEnumerable cashTricklers; + + public CashTricklerBar(Actor self, CashTricklerBarInfo info) + { + this.self = self; + this.info = info; + cashTricklers = self.TraitsImplementing().ToArray(); + } + + float ISelectionBar.GetValue() + { + var viewer = self.World.RenderPlayer ?? self.World.LocalPlayer; + if (viewer != null && !info.DisplayStances.HasStance(self.Owner.Stances[viewer])) + return 0; + + var complete = cashTricklers.Min(ct => (float)ct.Ticks / ct.Info.Interval); + return 1 - complete; + } + + Color ISelectionBar.GetColor() { return info.Color; } + bool ISelectionBar.DisplayWhenEmpty { get { return false; } } + } +}