ProductionTabsWidget: fix updating tabs when new production building is built

This commit is contained in:
michaeldgg2
2025-04-17 11:49:22 +02:00
committed by Gustas Kažukauskas
parent 89d906a613
commit d3d949176d

View File

@@ -243,31 +243,32 @@ namespace OpenRA.Mods.Common.Widgets
// Is added to world.ActorAdded by the SidebarLogic handler // Is added to world.ActorAdded by the SidebarLogic handler
public void ActorChanged(Actor a) public void ActorChanged(Actor a)
{ {
if (a.Info.HasTraitInfo<ProductionQueueInfo>()) // Ignore non-production actors and actors owned by non-local player
{ if (!a.Info.HasTraitInfo<ProductionQueueInfo>() || a.Owner != a.World.LocalPlayer)
var queues = a.World.ActorsWithTrait<ProductionQueue>() return;
.Where(p => p.Actor.Owner == p.Actor.World.LocalPlayer && p.Actor.IsInWorld)
.Select(p => p.Trait);
cachedProductionQueueEnabledStates.Clear(); var queues = a.World.ActorsWithTrait<ProductionQueue>()
foreach (var queue in queues) .Where(p => p.Actor.Owner == p.Actor.World.LocalPlayer && p.Actor.IsInWorld)
cachedProductionQueueEnabledStates.Add((queue, queue.Enabled)); .Select(p => p.Trait);
foreach (var g in Groups.Values) cachedProductionQueueEnabledStates.Clear();
g.Update(cachedProductionQueueEnabledStates.Select(t => t.Queue)); foreach (var queue in queues)
cachedProductionQueueEnabledStates.Add((queue, queue.Enabled));
if (queueGroup == null) foreach (var g in Groups.Values)
return; g.Update(cachedProductionQueueEnabledStates.Select(t => t.Queue));
// Queue destroyed, was last of type: switch to a new group if (queueGroup == null)
if (Groups[queueGroup].Tabs.Count == 0) return;
QueueGroup = Groups.Where(g => g.Value.Tabs.Count > 0)
.Select(g => g.Key).FirstOrDefault();
// Queue destroyed, others of same type: switch to another tab // Queue destroyed, was last of type: switch to a new group
else if (!Groups[queueGroup].Tabs.Select(t => t.Queue).Contains(CurrentQueue)) if (Groups[queueGroup].Tabs.Count == 0)
SelectNextTab(false); 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() public override void Tick()