From e545865599a06123240104de0b4e2c997bf9b93a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 15 Apr 2013 05:45:41 +1200 Subject: [PATCH] Add Selectable field to Selectable. There are a bunch of bogus assumptions about targetable actors being selectable. These aren't easily fixed, so this add a Selectable field that can be diabled for things we want to target, but not select. --- OpenRA.Game/Orders/UnitOrderGenerator.cs | 7 +++++-- OpenRA.Game/Traits/Selectable.cs | 16 ++++++++++++++-- .../Widgets/WorldInteractionControllerWidget.cs | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index f24de9b9c3..75d5fe3391 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -54,9 +54,12 @@ namespace OpenRA.Orders .OrderByDescending(a => a.SelectionPriority()) .FirstOrDefault(); - if (mi.Modifiers.HasModifier(Modifiers.Shift) || !world.Selection.Actors.Any()) - if (underCursor != null && underCursor.HasTrait()) + if (underCursor != null && (mi.Modifiers.HasModifier(Modifiers.Shift) || !world.Selection.Actors.Any())) + { + var selectable = underCursor.TraitOrDefault(); + if (selectable != null && selectable.Info.Selectable) useSelect = true; + } var orders = world.Selection.Actors .Select(a => OrderForUnit(a, xy, mi, underCursor)) diff --git a/OpenRA.Game/Traits/Selectable.cs b/OpenRA.Game/Traits/Selectable.cs index 22562f6382..9fbaf02b4d 100644 --- a/OpenRA.Game/Traits/Selectable.cs +++ b/OpenRA.Game/Traits/Selectable.cs @@ -16,21 +16,30 @@ namespace OpenRA.Traits { public class SelectableInfo : ITraitInfo { + public readonly bool Selectable = true; public readonly int Priority = 10; public readonly int[] Bounds = null; [VoiceReference] public readonly string Voice = null; - public object Create(ActorInitializer init) { return new Selectable(init.self); } + public object Create(ActorInitializer init) { return new Selectable(init.self, this); } } public class Selectable : IPostRenderSelection { + public SelectableInfo Info; Actor self; - public Selectable(Actor self) { this.self = self; } + public Selectable(Actor self, SelectableInfo info) + { + this.self = self; + Info = info; + } public void RenderAfterWorld(WorldRenderer wr) { + if (!Info.Selectable) + return; + var bounds = self.Bounds.Value; var xy = new float2(bounds.Left, bounds.Top); @@ -44,6 +53,9 @@ namespace OpenRA.Traits public void DrawRollover(WorldRenderer wr, Actor self) { + if (!Info.Selectable) + return; + var bounds = self.Bounds.Value; var xy = new float2(bounds.Left, bounds.Top); diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index b58609031b..4debabcfa1 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -184,7 +184,7 @@ namespace OpenRA.Widgets IEnumerable SelectActorsInBox(World world, PPos a, PPos b, Func cond) { return world.FindUnits(a, b) - .Where(x => x.HasTrait() && !world.FogObscures(x) && cond(x)) + .Where(x => x.HasTrait() && x.Trait().Info.Selectable && !world.FogObscures(x) && cond(x)) .GroupBy(x => x.GetSelectionPriority()) .OrderByDescending(g => g.Key) .Select(g => g.AsEnumerable())