From 9843d10dbd3a03cb78b3464f637322744f893d04 Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Sat, 31 Oct 2015 00:00:08 +0100 Subject: [PATCH 1/2] Fix production bars not being visible on captured factories --- .../Traits/Render/ProductionBar.cs | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Render/ProductionBar.cs b/OpenRA.Mods.Common/Traits/Render/ProductionBar.cs index 9375ea7954..fd47ab9f93 100644 --- a/OpenRA.Mods.Common/Traits/Render/ProductionBar.cs +++ b/OpenRA.Mods.Common/Traits/Render/ProductionBar.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits 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 Actor self; @@ -39,28 +39,33 @@ namespace OpenRA.Mods.Common.Traits this.info = info; } - public void Tick(Actor self) + void FindQueue() { + var type = info.ProductionType ?? self.Info.TraitInfo().Produces.First(); + + // Per-actor queue + // Note: this includes disabled queues, as each bar must bind to exactly one queue. + queue = self.TraitsImplementing() + .FirstOrDefault(q => type == null || type == q.Info.Type); + if (queue == null) { - var type = info.ProductionType ?? self.Info.TraitInfo().Produces.First(); - - // Per-actor queue - // Note: this includes disabled queues, as each bar must bind to exactly one queue. - queue = self.TraitsImplementing() + // No queues available - check for classic production queues + queue = self.Owner.PlayerActor.TraitsImplementing() .FirstOrDefault(q => type == null || type == q.Info.Type); - - if (queue == null) - { - // No queues available - check for classic production queues - queue = self.Owner.PlayerActor.TraitsImplementing() - .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(); 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 void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) + { + FindQueue(); + } } } From b1e69168382f78386713f96db136f3e3d2c62645 Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Sat, 31 Oct 2015 00:24:41 +0100 Subject: [PATCH 2/2] Add missing Requires<> to ProductionBar --- OpenRA.Mods.Common/Traits/Render/ProductionBar.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/Render/ProductionBar.cs b/OpenRA.Mods.Common/Traits/Render/ProductionBar.cs index fd47ab9f93..7e4ecea686 100644 --- a/OpenRA.Mods.Common/Traits/Render/ProductionBar.cs +++ b/OpenRA.Mods.Common/Traits/Render/ProductionBar.cs @@ -16,7 +16,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { [Desc("Visualizes the remaining build time of actor produced here.")] - class ProductionBarInfo : ITraitInfo + class ProductionBarInfo : ITraitInfo, Requires { [Desc("Production queue type, for actors with multiple queues.")] public readonly string ProductionType = null;