Fix duplicated text notifications when sound device is not available.

This commit is contained in:
Paul Chote
2026-01-01 12:35:44 +00:00
committed by Gustas Kažukauskas
parent 9fccc35046
commit 9e1f7cad55

View File

@@ -492,21 +492,23 @@ namespace OpenRA.Mods.Common.Traits
{ {
if (Info.PayUpFront && cost > playerResources.GetCashAndResources()) if (Info.PayUpFront && cost > playerResources.GetCashAndResources())
return; return;
var hasPlayedSound = false;
var notified = false;
BeginProduction(new ProductionItem(this, order.TargetString, cost, playerPower, () => self.World.AddFrameEndTask(_ => BeginProduction(new ProductionItem(this, order.TargetString, cost, playerPower, () => self.World.AddFrameEndTask(_ =>
{ {
// Make sure the item hasn't been invalidated between the ProductionItem ticking and this FrameEndTask running // Make sure the item hasn't been invalidated between the ProductionItem ticking and this FrameEndTask running
if (!Queue.Any(i => i.Done && i.Item == unit.Name)) if (!Queue.Any(i => i.Done && i.Item == unit.Name))
{ {
hasPlayedSound = false; notified = false;
return; return;
} }
var isBuilding = unit.HasTraitInfo<BuildingInfo>(); var isBuilding = unit.HasTraitInfo<BuildingInfo>();
if (isBuilding && !hasPlayedSound) if (isBuilding && !notified)
{ {
hasPlayedSound = Game.Sound.PlayNotification(rules, self.Owner, "Speech", Info.ReadyAudio, self.Owner.Faction.InternalName); Game.Sound.PlayNotification(rules, self.Owner, "Speech", Info.ReadyAudio, self.Owner.Faction.InternalName);
TextNotificationsManager.AddTransientLine(self.Owner, Info.ReadyTextNotification); TextNotificationsManager.AddTransientLine(self.Owner, Info.ReadyTextNotification);
notified = true;
} }
else if (!isBuilding) else if (!isBuilding)
{ {
@@ -515,10 +517,11 @@ namespace OpenRA.Mods.Common.Traits
Game.Sound.PlayNotification(rules, self.Owner, "Speech", Info.ReadyAudio, self.Owner.Faction.InternalName); Game.Sound.PlayNotification(rules, self.Owner, "Speech", Info.ReadyAudio, self.Owner.Faction.InternalName);
TextNotificationsManager.AddTransientLine(self.Owner, Info.ReadyTextNotification); TextNotificationsManager.AddTransientLine(self.Owner, Info.ReadyTextNotification);
} }
else if (!hasPlayedSound && time > 0) else if (!notified && time > 0)
{ {
hasPlayedSound = Game.Sound.PlayNotification(rules, self.Owner, "Speech", Info.BlockedAudio, self.Owner.Faction.InternalName); Game.Sound.PlayNotification(rules, self.Owner, "Speech", Info.BlockedAudio, self.Owner.Faction.InternalName);
TextNotificationsManager.AddTransientLine(self.Owner, Info.BlockedTextNotification); TextNotificationsManager.AddTransientLine(self.Owner, Info.BlockedTextNotification);
notified = true;
} }
} }
})), !order.Queued); })), !order.Queued);