Fix production bars not being visible on captured factories

This commit is contained in:
Oliver Brakmann
2015-10-31 00:00:08 +01:00
parent 168dab9707
commit 9843d10dbd

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new ProductionBar(init.Self, this); } public object Create(ActorInitializer init) { return new ProductionBar(init.Self, this); }
} }
class ProductionBar : ISelectionBar, ITick class ProductionBar : ISelectionBar, ITick, INotifyCreated, INotifyOwnerChanged
{ {
readonly ProductionBarInfo info; readonly ProductionBarInfo info;
readonly Actor self; readonly Actor self;
@@ -39,28 +39,33 @@ namespace OpenRA.Mods.Common.Traits
this.info = info; this.info = info;
} }
public void Tick(Actor self) void FindQueue()
{ {
var type = info.ProductionType ?? self.Info.TraitInfo<ProductionInfo>().Produces.First();
// Per-actor queue
// Note: this includes disabled queues, as each bar must bind to exactly one queue.
queue = self.TraitsImplementing<ProductionQueue>()
.FirstOrDefault(q => type == null || type == q.Info.Type);
if (queue == null) if (queue == null)
{ {
var type = info.ProductionType ?? self.Info.TraitInfo<ProductionInfo>().Produces.First(); // No queues available - check for classic production queues
queue = self.Owner.PlayerActor.TraitsImplementing<ProductionQueue>()
// Per-actor queue
// Note: this includes disabled queues, as each bar must bind to exactly one queue.
queue = self.TraitsImplementing<ProductionQueue>()
.FirstOrDefault(q => type == null || type == q.Info.Type); .FirstOrDefault(q => type == null || type == q.Info.Type);
if (queue == null)
{
// No queues available - check for classic production queues
queue = self.Owner.PlayerActor.TraitsImplementing<ProductionQueue>()
.FirstOrDefault(q => type == null || type == q.Info.Type);
}
if (queue == null)
throw new InvalidOperationException("No queues available for production type '{0}'".F(type));
} }
if (queue == null)
throw new InvalidOperationException("No queues available for production type '{0}'".F(type));
}
public void Created(Actor self)
{
FindQueue();
}
public void Tick(Actor self)
{
var current = queue.CurrentItem(); var current = queue.CurrentItem();
value = current != null ? 1 - (float)current.RemainingCost / current.TotalCost : 0; value = current != null ? 1 - (float)current.RemainingCost / current.TotalCost : 0;
} }
@@ -75,5 +80,10 @@ namespace OpenRA.Mods.Common.Traits
} }
public Color GetColor() { return info.Color; } public Color GetColor() { return info.Color; }
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
{
FindQueue();
}
} }
} }