Correctly handle Production traits disabled by condition.
This commit is contained in:
@@ -142,7 +142,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
// so we must query other player traits from self, knowing that
|
// so we must query other player traits from self, knowing that
|
||||||
// it refers to the same actor as self.Owner.PlayerActor
|
// it refers to the same actor as self.Owner.PlayerActor
|
||||||
playerPower = (self.Info.Name == "player" ? self : self.Owner.PlayerActor).TraitOrDefault<PowerManager>();
|
playerPower = (self.Info.Name == "player" ? self : self.Owner.PlayerActor).TraitOrDefault<PowerManager>();
|
||||||
productionTraits = self.TraitsImplementing<Production>().ToArray();
|
productionTraits = self.TraitsImplementing<Production>().Where(p => p.Info.Produces.Contains(Info.Type)).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ClearQueue()
|
protected void ClearQueue()
|
||||||
@@ -239,6 +239,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public virtual IEnumerable<ActorInfo> AllItems()
|
public virtual IEnumerable<ActorInfo> AllItems()
|
||||||
{
|
{
|
||||||
|
if (productionTraits.Any() && productionTraits.All(p => p.IsTraitDisabled))
|
||||||
|
return Enumerable.Empty<ActorInfo>();
|
||||||
if (developerMode.AllTech)
|
if (developerMode.AllTech)
|
||||||
return Producible.Keys;
|
return Producible.Keys;
|
||||||
|
|
||||||
@@ -247,6 +249,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public virtual IEnumerable<ActorInfo> BuildableItems()
|
public virtual IEnumerable<ActorInfo> BuildableItems()
|
||||||
{
|
{
|
||||||
|
if (productionTraits.Any() && productionTraits.All(p => p.IsTraitDisabled))
|
||||||
|
return Enumerable.Empty<ActorInfo>();
|
||||||
if (!Enabled)
|
if (!Enabled)
|
||||||
return Enumerable.Empty<ActorInfo>();
|
return Enumerable.Empty<ActorInfo>();
|
||||||
if (developerMode.AllTech)
|
if (developerMode.AllTech)
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
.FirstOrDefault(q => q.Enabled && types.Contains(q.Info.Type));
|
.FirstOrDefault(q => q.Enabled && types.Contains(q.Info.Type));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queue == null)
|
if (queue == null || !queue.BuildableItems().Any())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (tabsWidget.Value != null)
|
if (tabsWidget.Value != null)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||||
@@ -34,7 +35,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
tabs.PickUpCompletedBuilding();
|
tabs.PickUpCompletedBuilding();
|
||||||
};
|
};
|
||||||
|
|
||||||
button.IsDisabled = () => tabs.Groups[button.ProductionGroup].Tabs.Count == 0;
|
button.IsDisabled = () => !tabs.Groups[button.ProductionGroup].Tabs.Any(t => t.Queue.BuildableItems().Any());
|
||||||
button.OnMouseUp = mi => selectTab(mi.Modifiers.HasModifier(Modifiers.Shift));
|
button.OnMouseUp = mi => selectTab(mi.Modifiers.HasModifier(Modifiers.Shift));
|
||||||
button.OnKeyPress = e => selectTab(e.Modifiers.HasModifier(Modifiers.Shift));
|
button.OnKeyPress = e => selectTab(e.Modifiers.HasModifier(Modifiers.Shift));
|
||||||
button.IsHighlighted = () => tabs.QueueGroup == button.ProductionGroup;
|
button.IsHighlighted = () => tabs.QueueGroup == button.ProductionGroup;
|
||||||
|
|||||||
@@ -161,6 +161,11 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
|
var tabs = Groups[queueGroup].Tabs.Where(t => t.Queue.BuildableItems().Any());
|
||||||
|
|
||||||
|
if (!tabs.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
var rb = RenderBounds;
|
var rb = RenderBounds;
|
||||||
leftButtonRect = new Rectangle(rb.X, rb.Y, ArrowWidth, rb.Height);
|
leftButtonRect = new Rectangle(rb.X, rb.Y, ArrowWidth, rb.Height);
|
||||||
rightButtonRect = new Rectangle(rb.Right - ArrowWidth, rb.Y, ArrowWidth, rb.Height);
|
rightButtonRect = new Rectangle(rb.Right - ArrowWidth, rb.Y, ArrowWidth, rb.Height);
|
||||||
@@ -185,7 +190,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
var font = Game.Renderer.Fonts["TinyBold"];
|
var font = Game.Renderer.Fonts["TinyBold"];
|
||||||
contentWidth = 0;
|
contentWidth = 0;
|
||||||
|
|
||||||
foreach (var tab in Groups[queueGroup].Tabs)
|
foreach (var tab in tabs)
|
||||||
{
|
{
|
||||||
var rect = new Rectangle(origin.X + contentWidth, origin.Y, TabWidth, rb.Height);
|
var rect = new Rectangle(origin.X + contentWidth, origin.Y, TabWidth, rb.Height);
|
||||||
var hover = !leftHover && !rightHover && Ui.MouseOverWidget == this && rect.Contains(Viewport.LastMousePos);
|
var hover = !leftHover && !rightHover && Ui.MouseOverWidget == this && rect.Contains(Viewport.LastMousePos);
|
||||||
|
|||||||
Reference in New Issue
Block a user