SelectionState
namespace Griff.Scenes;
public sealed class SelectionStateWhat’s selected, the way real-time strategy games select, and the rules for changing it: a click picks one (adding it or taking it out with AddToSelection held, and a double-click picking every one of its kind on screen), a box picks what’s inside, and control groups are kept and picked again by number. It knows nothing of the mouse, keys or what can be selected: an ISelectionRules says what’s where. SelectionControls keeps one, and so does the Strategy module’s Commander, so both select alike; a script’s own selecting can keep one too.
Properties
Section titled “Properties”DoubleClickSeconds
Section titled “DoubleClickSeconds”public double DoubleClickSeconds { get; set; }How close in seconds two clicks on the same thing make a double-click (no more apart than this).
DoubleTapSeconds
Section titled “DoubleTapSeconds”public double DoubleTapSeconds { get; set; }How close in seconds two picks of a control group make a double-tap (less apart than this).
DragFrom
Section titled “DragFrom”public Vector2? DragFrom { get; set; }Where a box being dragged out started (in the world), or null.
LastClickTime
Section titled “LastClickTime”public double LastClickTime { get; }When the last click was, in the clock’s seconds.
LastClicked
Section titled “LastClicked”public Entity? LastClicked { get; }The last thing clicked (or null for nothing), for telling a double-click.
LastGroup
Section titled “LastGroup”public int LastGroup { get; }The control group last picked, or -1.
LastGroupTime
Section titled “LastGroupTime”public double LastGroupTime { get; }When the last control group was picked, in the clock’s seconds.
Selected
Section titled “Selected”public IReadOnlyList<Entity> Selected { get; }What’s selected, first picked first.
Methods
Section titled “Methods”public void Box(ISelectionRules rules, Vector2 from, Vector2 to, bool add)A box dragged from from to to: what’s inside; with add, added to what’s kept.
public void Click(ISelectionRules rules, Vector2 point, bool add, double now)A click at point at now: what’s there alone; with add, added to the selection or taken out of it, where the rules allow; a second click on it soon enough, every one of its kind. A click on nothing clears the selection (unless adding).
public IReadOnlyList<Entity> Group(int number)Control group number; empty if it hasn’t been kept.
KeepGroup
Section titled “KeepGroup”public IReadOnlyList<Entity> KeepGroup(ISelectionRules rules, int number)Keeps what’s selected (what the rules keep of it) as control group number, and returns it.
PickGroup
Section titled “PickGroup”public bool PickGroup(ISelectionRules rules, int number, bool add, double now, out Vector2? center)Picks control group number again (adding it to the selection with add), dropping what’s gone from it. Picked twice quickly, center is the middle of the group, to move the camera to. False if no such group was kept.
Release
Section titled “Release”public void Release(ISelectionRules rules, Vector2 at, float clickDistance, bool add, double now)Ends the box being dragged out (from DragFrom) with the mouse let go at at: a click where it started if it moved less than clickDistance, otherwise a box. Nothing if none was.
public bool Set(IEnumerable<Entity> entities)Selects entities (each once), dropping the rest; true if that changed anything.
SetGroup
Section titled “SetGroup”public void SetGroup(int number, IEnumerable<Entity> entities)Keeps entities as control group number.