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.
This commit is contained in:
@@ -54,9 +54,12 @@ namespace OpenRA.Orders
|
|||||||
.OrderByDescending(a => a.SelectionPriority())
|
.OrderByDescending(a => a.SelectionPriority())
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
if (mi.Modifiers.HasModifier(Modifiers.Shift) || !world.Selection.Actors.Any())
|
if (underCursor != null && (mi.Modifiers.HasModifier(Modifiers.Shift) || !world.Selection.Actors.Any()))
|
||||||
if (underCursor != null && underCursor.HasTrait<Selectable>())
|
{
|
||||||
|
var selectable = underCursor.TraitOrDefault<Selectable>();
|
||||||
|
if (selectable != null && selectable.Info.Selectable)
|
||||||
useSelect = true;
|
useSelect = true;
|
||||||
|
}
|
||||||
|
|
||||||
var orders = world.Selection.Actors
|
var orders = world.Selection.Actors
|
||||||
.Select(a => OrderForUnit(a, xy, mi, underCursor))
|
.Select(a => OrderForUnit(a, xy, mi, underCursor))
|
||||||
|
|||||||
@@ -16,21 +16,30 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
public class SelectableInfo : ITraitInfo
|
public class SelectableInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
|
public readonly bool Selectable = true;
|
||||||
public readonly int Priority = 10;
|
public readonly int Priority = 10;
|
||||||
public readonly int[] Bounds = null;
|
public readonly int[] Bounds = null;
|
||||||
[VoiceReference] public readonly string Voice = 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 class Selectable : IPostRenderSelection
|
||||||
{
|
{
|
||||||
|
public SelectableInfo Info;
|
||||||
Actor self;
|
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)
|
public void RenderAfterWorld(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
|
if (!Info.Selectable)
|
||||||
|
return;
|
||||||
|
|
||||||
var bounds = self.Bounds.Value;
|
var bounds = self.Bounds.Value;
|
||||||
|
|
||||||
var xy = new float2(bounds.Left, bounds.Top);
|
var xy = new float2(bounds.Left, bounds.Top);
|
||||||
@@ -44,6 +53,9 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public void DrawRollover(WorldRenderer wr, Actor self)
|
public void DrawRollover(WorldRenderer wr, Actor self)
|
||||||
{
|
{
|
||||||
|
if (!Info.Selectable)
|
||||||
|
return;
|
||||||
|
|
||||||
var bounds = self.Bounds.Value;
|
var bounds = self.Bounds.Value;
|
||||||
|
|
||||||
var xy = new float2(bounds.Left, bounds.Top);
|
var xy = new float2(bounds.Left, bounds.Top);
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ namespace OpenRA.Widgets
|
|||||||
IEnumerable<Actor> SelectActorsInBox(World world, PPos a, PPos b, Func<Actor, bool> cond)
|
IEnumerable<Actor> SelectActorsInBox(World world, PPos a, PPos b, Func<Actor, bool> cond)
|
||||||
{
|
{
|
||||||
return world.FindUnits(a, b)
|
return world.FindUnits(a, b)
|
||||||
.Where(x => x.HasTrait<Selectable>() && !world.FogObscures(x) && cond(x))
|
.Where(x => x.HasTrait<Selectable>() && x.Trait<Selectable>().Info.Selectable && !world.FogObscures(x) && cond(x))
|
||||||
.GroupBy(x => x.GetSelectionPriority())
|
.GroupBy(x => x.GetSelectionPriority())
|
||||||
.OrderByDescending(g => g.Key)
|
.OrderByDescending(g => g.Key)
|
||||||
.Select(g => g.AsEnumerable())
|
.Select(g => g.AsEnumerable())
|
||||||
|
|||||||
Reference in New Issue
Block a user