Fix production bars not being visible on captured factories
This commit is contained in:
@@ -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,9 +39,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
this.info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(Actor self)
|
void FindQueue()
|
||||||
{
|
|
||||||
if (queue == null)
|
|
||||||
{
|
{
|
||||||
var type = info.ProductionType ?? self.Info.TraitInfo<ProductionInfo>().Produces.First();
|
var type = info.ProductionType ?? self.Info.TraitInfo<ProductionInfo>().Produces.First();
|
||||||
|
|
||||||
@@ -61,6 +59,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
throw new InvalidOperationException("No queues available for production type '{0}'".F(type));
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user