Fix ProductionOverlay crash.
This commit is contained in:
@@ -39,12 +39,12 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
{
|
{
|
||||||
readonly Animation overlay;
|
readonly Animation overlay;
|
||||||
readonly ProductionInfo production;
|
readonly ProductionInfo production;
|
||||||
ProductionQueue queue;
|
ProductionQueue[] queues;
|
||||||
bool buildComplete;
|
bool buildComplete;
|
||||||
|
|
||||||
bool IsProducing
|
bool IsProducing
|
||||||
{
|
{
|
||||||
get { return queue != null && queue.CurrentItem() != null && !queue.CurrentPaused; }
|
get { return queues != null && queues.Any(q => q.Enabled && q.CurrentItem() != null && !q.CurrentPaused); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public WithProductionOverlay(Actor self, WithProductionOverlayInfo info)
|
public WithProductionOverlay(Actor self, WithProductionOverlayInfo info)
|
||||||
@@ -65,36 +65,37 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
rs.Add(anim, info.Palette, info.IsPlayerPalette);
|
rs.Add(anim, info.Palette, info.IsPlayerPalette);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectQueue(Actor self)
|
void CacheQueues(Actor self)
|
||||||
{
|
{
|
||||||
var perBuildingQueues = self.TraitsImplementing<ProductionQueue>();
|
// Per-actor production
|
||||||
queue = perBuildingQueues.FirstOrDefault(q => q.Enabled && production.Produces.Contains(q.Info.Type));
|
queues = self.TraitsImplementing<ProductionQueue>()
|
||||||
|
.Where(q => production.Produces.Contains(q.Info.Type))
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
if (queue == null)
|
if (!queues.Any())
|
||||||
{
|
{
|
||||||
var perPlayerQueues = self.Owner.PlayerActor.TraitsImplementing<ProductionQueue>();
|
// Player-wide production
|
||||||
queue = perPlayerQueues.FirstOrDefault(q => q.Enabled && production.Produces.Contains(q.Info.Type));
|
queues = self.Owner.PlayerActor.TraitsImplementing<ProductionQueue>()
|
||||||
|
.Where(q => production.Produces.Contains(q.Info.Type))
|
||||||
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queue == null)
|
|
||||||
throw new InvalidOperationException("Can't find production queues.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyCreated.Created(Actor self)
|
void INotifyCreated.Created(Actor self)
|
||||||
{
|
{
|
||||||
if (buildComplete)
|
if (buildComplete)
|
||||||
SelectQueue(self);
|
CacheQueues(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyBuildComplete.BuildingComplete(Actor self)
|
void INotifyBuildComplete.BuildingComplete(Actor self)
|
||||||
{
|
{
|
||||||
buildComplete = true;
|
buildComplete = true;
|
||||||
SelectQueue(self);
|
CacheQueues(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||||
{
|
{
|
||||||
self.World.AddFrameEndTask(w => SelectQueue(self));
|
self.World.AddFrameEndTask(w => CacheQueues(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifySold.Sold(Actor self) { }
|
void INotifySold.Sold(Actor self) { }
|
||||||
|
|||||||
Reference in New Issue
Block a user