Add CashTricklerBar

This commit is contained in:
Mustafa Alperen Seki
2017-09-21 21:01:19 +03:00
committed by reaperrr
parent a4b0bf5c52
commit 2102fad2b5
3 changed files with 62 additions and 5 deletions

View File

@@ -413,6 +413,7 @@
<Compile Include="Traits\BodyOrientation.cs" /> <Compile Include="Traits\BodyOrientation.cs" />
<Compile Include="Traits\QuantizeFacingsFromSequence.cs" /> <Compile Include="Traits\QuantizeFacingsFromSequence.cs" />
<Compile Include="Traits\Render\AutoSelectionSize.cs" /> <Compile Include="Traits\Render\AutoSelectionSize.cs" />
<Compile Include="Traits\Render\CashTricklerBar.cs" />
<Compile Include="Traits\Render\CustomTerrainDebugOverlay.cs" /> <Compile Include="Traits\Render\CustomTerrainDebugOverlay.cs" />
<Compile Include="Traits\Render\Hovers.cs" /> <Compile Include="Traits\Render\Hovers.cs" />
<Compile Include="Traits\Render\LeavesTrails.cs" /> <Compile Include="Traits\Render\LeavesTrails.cs" />

View File

@@ -40,13 +40,13 @@ namespace OpenRA.Mods.Common.Traits
{ {
readonly CashTricklerInfo info; readonly CashTricklerInfo info;
PlayerResources resources; PlayerResources resources;
[Sync] int ticks; [Sync] public int Ticks { get; private set; }
public CashTrickler(CashTricklerInfo info) public CashTrickler(CashTricklerInfo info)
: base(info) : base(info)
{ {
this.info = info; this.info = info;
ticks = info.InitialDelay; Ticks = info.InitialDelay;
} }
protected override void Created(Actor self) protected override void Created(Actor self)
@@ -64,14 +64,14 @@ namespace OpenRA.Mods.Common.Traits
void ITick.Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (IsTraitDisabled) if (IsTraitDisabled)
ticks = info.Interval; Ticks = info.Interval;
if (IsTraitPaused || IsTraitDisabled) if (IsTraitPaused || IsTraitDisabled)
return; return;
if (--ticks < 0) if (--Ticks < 0)
{ {
ticks = info.Interval; Ticks = info.Interval;
ModifyCash(self, self.Owner, info.Amount); ModifyCash(self, self.Owner, info.Amount);
} }
} }

View File

@@ -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<CashTricklerInfo>
{
[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<CashTrickler> cashTricklers;
public CashTricklerBar(Actor self, CashTricklerBarInfo info)
{
this.self = self;
this.info = info;
cashTricklers = self.TraitsImplementing<CashTrickler>().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; } }
}
}