From d3d949176d47ec322f6ff99dc4c70bfd6a0c0b9f Mon Sep 17 00:00:00 2001 From: michaeldgg2 <119738087+michaeldgg2@users.noreply.github.com> Date: Thu, 17 Apr 2025 11:49:22 +0200 Subject: [PATCH] ProductionTabsWidget: fix updating tabs when new production building is built --- .../Widgets/ProductionTabsWidget.cs | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs b/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs index 85f40a2408..cd11558f32 100644 --- a/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs @@ -243,31 +243,32 @@ namespace OpenRA.Mods.Common.Widgets // Is added to world.ActorAdded by the SidebarLogic handler public void ActorChanged(Actor a) { - if (a.Info.HasTraitInfo()) - { - var queues = a.World.ActorsWithTrait() - .Where(p => p.Actor.Owner == p.Actor.World.LocalPlayer && p.Actor.IsInWorld) - .Select(p => p.Trait); + // Ignore non-production actors and actors owned by non-local player + if (!a.Info.HasTraitInfo() || a.Owner != a.World.LocalPlayer) + return; - cachedProductionQueueEnabledStates.Clear(); - foreach (var queue in queues) - cachedProductionQueueEnabledStates.Add((queue, queue.Enabled)); + var queues = a.World.ActorsWithTrait() + .Where(p => p.Actor.Owner == p.Actor.World.LocalPlayer && p.Actor.IsInWorld) + .Select(p => p.Trait); - foreach (var g in Groups.Values) - g.Update(cachedProductionQueueEnabledStates.Select(t => t.Queue)); + cachedProductionQueueEnabledStates.Clear(); + foreach (var queue in queues) + cachedProductionQueueEnabledStates.Add((queue, queue.Enabled)); - if (queueGroup == null) - return; + foreach (var g in Groups.Values) + g.Update(cachedProductionQueueEnabledStates.Select(t => t.Queue)); - // Queue destroyed, was last of type: switch to a new group - if (Groups[queueGroup].Tabs.Count == 0) - QueueGroup = Groups.Where(g => g.Value.Tabs.Count > 0) - .Select(g => g.Key).FirstOrDefault(); + if (queueGroup == null) + return; - // Queue destroyed, others of same type: switch to another tab - else if (!Groups[queueGroup].Tabs.Select(t => t.Queue).Contains(CurrentQueue)) - SelectNextTab(false); - } + // Queue destroyed, was last of type: switch to a new group + if (Groups[queueGroup].Tabs.Count == 0) + QueueGroup = Groups.Where(g => g.Value.Tabs.Count > 0) + .Select(g => g.Key).FirstOrDefault(); + + // Queue destroyed, others of same type: switch to another tab + else if (!Groups[queueGroup].Tabs.Select(t => t.Queue).Contains(CurrentQueue)) + SelectNextTab(false); } public override void Tick()