Move Interactable and Selectable to Mods.Common.
This commit is contained in:
@@ -70,7 +70,7 @@ namespace OpenRA.Orders
|
||||
|
||||
bool useSelect;
|
||||
if (Game.Settings.Game.UseClassicMouseStyle && !InputOverridesSelection(world, worldPixel, mi))
|
||||
useSelect = target.Type == TargetType.Actor && target.Actor.Info.HasTraitInfo<SelectableInfo>();
|
||||
useSelect = target.Type == TargetType.Actor && target.Actor.Info.HasTraitInfo<ISelectableInfo>();
|
||||
else
|
||||
{
|
||||
var ordersWithCursor = world.Selection.Actors
|
||||
@@ -81,7 +81,7 @@ namespace OpenRA.Orders
|
||||
if (cursorOrder != null)
|
||||
return cursorOrder.Cursor;
|
||||
|
||||
useSelect = target.Type == TargetType.Actor && target.Actor.Info.HasTraitInfo<SelectableInfo>() &&
|
||||
useSelect = target.Type == TargetType.Actor && target.Actor.Info.HasTraitInfo<ISelectableInfo>() &&
|
||||
(mi.Modifiers.HasModifier(Modifiers.Shift) || !world.Selection.Actors.Any());
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace OpenRA.Traits
|
||||
{
|
||||
public static int SelectionPriority(this ActorInfo a, Modifiers modifiers)
|
||||
{
|
||||
var selectableInfo = a.TraitInfoOrDefault<SelectableInfo>();
|
||||
var selectableInfo = a.TraitInfoOrDefault<ISelectableInfo>();
|
||||
return selectableInfo != null ? BaseSelectionPriority(selectableInfo, modifiers) : int.MinValue;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public static int SelectionPriority(this Actor a, Modifiers modifiers)
|
||||
{
|
||||
var info = a.Info.TraitInfo<SelectableInfo>();
|
||||
var info = a.Info.TraitInfo<ISelectableInfo>();
|
||||
var basePriority = BaseSelectionPriority(info, modifiers);
|
||||
|
||||
var viewer = (a.World.LocalPlayer == null || a.World.LocalPlayer.Spectating) ? a.World.RenderPlayer : a.World.LocalPlayer;
|
||||
@@ -47,7 +47,7 @@ namespace OpenRA.Traits
|
||||
}
|
||||
}
|
||||
|
||||
static int BaseSelectionPriority(SelectableInfo info, Modifiers modifiers)
|
||||
static int BaseSelectionPriority(ISelectableInfo info, Modifiers modifiers)
|
||||
{
|
||||
var priority = info.Priority;
|
||||
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2020 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
[Desc("Used to enable mouse interaction on actors that are not Selectable.")]
|
||||
public class InteractableInfo : ITraitInfo, IMouseBoundsInfo, IDecorationBoundsInfo
|
||||
{
|
||||
[Desc("Defines a custom rectangle for mouse interaction with the actor.",
|
||||
"If null, the engine will guess an appropriate size based on the With*Body trait.",
|
||||
"The first two numbers define the width and height of the rectangle.",
|
||||
"The (optional) second two numbers define an x and y offset from the actor center.")]
|
||||
public readonly int[] Bounds = null;
|
||||
|
||||
[Desc("Defines a custom rectangle for Decorations (e.g. the selection box).",
|
||||
"If null, Bounds will be used instead")]
|
||||
public readonly int[] DecorationBounds = null;
|
||||
|
||||
public virtual object Create(ActorInitializer init) { return new Interactable(this); }
|
||||
}
|
||||
|
||||
public class Interactable : INotifyCreated, IMouseBounds, IDecorationBounds
|
||||
{
|
||||
readonly InteractableInfo info;
|
||||
IAutoMouseBounds[] autoBounds;
|
||||
|
||||
public Interactable(InteractableInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
autoBounds = self.TraitsImplementing<IAutoMouseBounds>().ToArray();
|
||||
}
|
||||
|
||||
Rectangle AutoBounds(Actor self, WorldRenderer wr)
|
||||
{
|
||||
return autoBounds.Select(s => s.AutoMouseoverBounds(self, wr)).FirstOrDefault(r => !r.IsEmpty);
|
||||
}
|
||||
|
||||
Rectangle Bounds(Actor self, WorldRenderer wr, int[] bounds)
|
||||
{
|
||||
if (bounds == null)
|
||||
return AutoBounds(self, wr);
|
||||
|
||||
var size = new int2(bounds[0], bounds[1]);
|
||||
|
||||
var offset = -size / 2;
|
||||
if (bounds.Length > 2)
|
||||
offset += new int2(bounds[2], bounds[3]);
|
||||
|
||||
var xy = wr.ScreenPxPosition(self.CenterPosition) + offset;
|
||||
return new Rectangle(xy.X, xy.Y, size.X, size.Y);
|
||||
}
|
||||
|
||||
Rectangle IMouseBounds.MouseoverBounds(Actor self, WorldRenderer wr)
|
||||
{
|
||||
return Bounds(self, wr, info.Bounds);
|
||||
}
|
||||
|
||||
Rectangle IDecorationBounds.DecorationBounds(Actor self, WorldRenderer wr)
|
||||
{
|
||||
return Bounds(self, wr, info.DecorationBounds ?? info.Bounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2020 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
[Flags]
|
||||
public enum SelectionPriorityModifiers
|
||||
{
|
||||
None = 0,
|
||||
Ctrl = 1,
|
||||
Alt = 2
|
||||
}
|
||||
|
||||
[Desc("This actor is selectable. Defines bounds of selectable area, selection class, selection priority and selection priority modifiers.")]
|
||||
public class SelectableInfo : InteractableInfo
|
||||
{
|
||||
public readonly int Priority = 10;
|
||||
|
||||
[Desc("Allow selection priority to be modified using a hotkey.",
|
||||
"Valid values are None (priority is not affected by modifiers)",
|
||||
"Ctrl (priority is raised when Ctrl pressed) and",
|
||||
"Alt (priority is raised when Alt pressed).")]
|
||||
public readonly SelectionPriorityModifiers PriorityModifiers = SelectionPriorityModifiers.None;
|
||||
|
||||
[Desc("All units having the same selection class specified will be selected with select-by-type commands (e.g. double-click). "
|
||||
+ "Defaults to the actor name when not defined or inherited.")]
|
||||
public readonly string Class = null;
|
||||
|
||||
[VoiceReference]
|
||||
public readonly string Voice = "Select";
|
||||
|
||||
public override object Create(ActorInitializer init) { return new Selectable(init.Self, this); }
|
||||
}
|
||||
|
||||
public class Selectable : Interactable
|
||||
{
|
||||
public readonly string Class = null;
|
||||
public readonly SelectableInfo Info;
|
||||
|
||||
public Selectable(Actor self, SelectableInfo info)
|
||||
: base(info)
|
||||
{
|
||||
Class = string.IsNullOrEmpty(info.Class) ? self.Info.Name : info.Class;
|
||||
Info = info;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -440,6 +440,22 @@ namespace OpenRA.Traits
|
||||
bool SpatiallyPartitionable { get; }
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum SelectionPriorityModifiers
|
||||
{
|
||||
None = 0,
|
||||
Ctrl = 1,
|
||||
Alt = 2
|
||||
}
|
||||
|
||||
[RequireExplicitImplementation]
|
||||
public interface ISelectableInfo : ITraitInfoInterface
|
||||
{
|
||||
int Priority { get; }
|
||||
SelectionPriorityModifiers PriorityModifiers { get; }
|
||||
string Voice { get; }
|
||||
}
|
||||
|
||||
public interface ISelection
|
||||
{
|
||||
int Hash { get; }
|
||||
|
||||
Reference in New Issue
Block a user