From 507cdf125653b4e0d1d3260ef80ddd123bfb47a8 Mon Sep 17 00:00:00 2001 From: michaeldgg2 <119738087+michaeldgg2@users.noreply.github.com> Date: Sat, 28 Oct 2023 11:23:05 +0200 Subject: [PATCH] Fix ProductionTabsWidget not picking up ProductionQueue getting enabled/disabled during its lifetime --- .../Widgets/ProductionTabsWidget.cs | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs b/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs index e81758f76c..867f5f515b 100644 --- a/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Widgets public void Update(IEnumerable allQueues) { - var queues = allQueues.Where(q => q.Info.Group == Group).ToList(); + var queues = allQueues.Where(q => q.Enabled && q.Info.Group == Group).ToList(); var tabs = new List(); var largestUsedName = 0; @@ -105,6 +105,8 @@ namespace OpenRA.Mods.Common.Widgets readonly Lazy paletteWidget; string queueGroup; + readonly List<(ProductionQueue Queue, bool Enabled)> cachedProductionQueueEnabledStates = new(); + [ObjectCreator.UseCtor] public ProductionTabsWidget(World world) { @@ -243,12 +245,16 @@ namespace OpenRA.Mods.Common.Widgets { if (a.Info.HasTraitInfo()) { - var allQueues = a.World.ActorsWithTrait() - .Where(p => p.Actor.Owner == p.Actor.World.LocalPlayer && p.Actor.IsInWorld && p.Trait.Enabled) - .Select(p => p.Trait).ToList(); + var queues = a.World.ActorsWithTrait() + .Where(p => p.Actor.Owner == p.Actor.World.LocalPlayer && p.Actor.IsInWorld) + .Select(p => p.Trait); + + cachedProductionQueueEnabledStates.Clear(); + foreach (var queue in queues) + cachedProductionQueueEnabledStates.Add((queue, queue.Enabled)); foreach (var g in Groups.Values) - g.Update(allQueues); + g.Update(cachedProductionQueueEnabledStates.Select(t => t.Queue)); if (queueGroup == null) return; @@ -268,6 +274,22 @@ namespace OpenRA.Mods.Common.Widgets { if (leftPressed) Scroll(1); if (rightPressed) Scroll(-1); + + // It is possible that production queues get enabled/disabled during their lifetime. + // This makes sure every enabled production queue always has its tab associated with it. + var shouldUpdateQueues = false; + foreach (var (queue, enabled) in cachedProductionQueueEnabledStates) + { + if (queue.Enabled != enabled) + { + shouldUpdateQueues = true; + break; + } + } + + if (shouldUpdateQueues) + foreach (var g in Groups.Values) + g.Update(cachedProductionQueueEnabledStates.Select(t => t.Queue)); } public override bool YieldMouseFocus(MouseInput mi)