make ProductionBar actually work for all RA stuff

This commit is contained in:
Chris Forbes
2011-03-02 22:35:44 +13:00
parent c62e025c45
commit 89a96a9fe7
3 changed files with 41 additions and 6 deletions

View File

@@ -9,16 +9,37 @@
#endregion
using System.Drawing;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class ProductionBarInfo : TraitInfo<ProductionBar> { }
class ProductionBarInfo : ITraitInfo
{
public object Create(ActorInitializer init) { return new ProductionBar( init.self ); }
}
class ProductionBar : ISelectionBar
{
public float GetValue() { return .5f; }
Actor self;
public ProductionBar(Actor self) { this.self = self; }
public Color GetColor() { return Color.CadetBlue; }
public float GetValue()
{
var queue = self.TraitOrDefault<ProductionQueue>();
if (queue == null)
{
var produces = self.Trait<Production>().Info.Produces;
queue = self.Owner.PlayerActor.TraitsImplementing<ProductionQueue>()
.First(q => produces.Contains(q.Info.Type));
}
if (queue == null || queue.CurrentItem() == null)
return 0f;
return 1 - (float)queue.CurrentItem().RemainingCost / queue.CurrentItem().TotalCost;
}
public Color GetColor() { return Color.SkyBlue; }
}
}