SelectionControls
namespace Griff.Scenes;
public sealed class SelectionControls : ComponentSelecting as in a real-time strategy game, with no code: put it on the camera, and Selectable on what can be selected. A click picks one, a left-drag draws a box that picks those inside it, AddToSelection (Shift) held adds to the selection (or takes one out of it), a double-click picks every one of that kind on screen, and AssignGroup (Ctrl) with a number keeps the selection as that control group, the number alone picks it again and pressing it twice quickly moves the camera to it. Esc clears it. A right-click with something selected is a command the game carries out itself: Commanded says what was under the mouse and what’s selected.
Its keys are the input actions Select (left click), Command (right click), AddToSelection (Shift), AssignGroup (Ctrl) and Group1 to Group9 (the number keys), so Game > Controls and the player’s Rebind buttons change them. Clicks on buttons and the HUD don’t select, and while it’s Busy (a tool in hand) it leaves the mouse alone. Esc closes an open window first, and with something selected it clears the selection rather than opening the game menu. The selection is this machine’s own; in a network game, the game sends the orders a command gives.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”BoxColor
Section titled “BoxColor”public Color BoxColor { get; set; }The color of the box drawn while dragging one out, or what tints its BoxImage.
BoxImage
Section titled “BoxImage”public string? BoxImage { get; set; }A picture stretched over the box while dragging one out. Empty draws a faint fill and an outline in BoxColor.
BoxSlice
Section titled “BoxSlice”public float BoxSlice { get; set; }For a BoxImage that stretches (nine-slice): how much of it is border at each edge, from 0 to 0.5.
BoxSliceSize
Section titled “BoxSliceSize”public float BoxSliceSize { get; set; }With BoxSlice: how big the box’s border is drawn, in world units.
public bool Busy { get; set; }True while the mouse is busy with something else (a building tool in hand, a road being painted): it neither selects, commands nor clears, so the game’s left-drag can paint. Set by scripts; see also BusyFlag. A LineTool in hand (its Controllable ticked) makes it busy too.
BusyFlag
Section titled “BusyFlag”public string? BusyFlag { get; set; }A flag that makes it busy while it’s set, as Busy does, e.g. “Building” (set by a trigger’s Set Flag or a script’s Game.SetFlag), or “not Ready” for while it isn’t. Empty for none.
Controllable
Section titled “Controllable”public bool Controllable { get; set; }Untick it to have it ignore the mouse and keys while the game plays on: another part of the scene has the player’s input. Its Focus action ticks it and unticks it on everything else the player plays.
DoubleClickSeconds
Section titled “DoubleClickSeconds”public float DoubleClickSeconds { get; set; }How quickly, in seconds, a second click on the same thing makes a double-click (picking all of its kind on screen), and a second press of a group’s number moves the camera to the group.
IsDragging
Section titled “IsDragging”public bool IsDragging { get; }True while a box is being dragged out.
MarkerColor
Section titled “MarkerColor”public Color MarkerColor { get; set; }The color of the marker round each thing selected, or what tints its MarkerImage.
MarkerImage
Section titled “MarkerImage”public string? MarkerImage { get; set; }A picture drawn round each thing selected, stretched to its area plus MarkerPadding, e.g. a bracket frame. Empty draws an outline in MarkerColor.
MarkerPadding
Section titled “MarkerPadding”public float MarkerPadding { get; set; }How far the marker stands out from each thing’s area, in world units.
MarkerSlice
Section titled “MarkerSlice”public float MarkerSlice { get; set; }For a MarkerImage that stretches (nine-slice): how much of it, from 0 to 0.5 of its width and height, is border at each edge, as a sprite’s Slice. 0 stretches the whole picture.
MarkerSliceSize
Section titled “MarkerSliceSize”public float MarkerSliceSize { get; set; }With MarkerSlice: how big the marker’s border is drawn, in world units.
Selected
Section titled “Selected”public IReadOnlyList<Entity> Selected { get; }What’s selected, first picked first.
SelectedCount
Section titled “SelectedCount”public int SelectedCount { get; }How many things are selected.
Methods
Section titled “Methods”public void Add(Entity entity)Adds entity to what’s selected.
public void Clear()Selects nothing, as Esc does.
public IReadOnlyList<Entity> Group(int number)The things kept as control group number (1 to 9); empty if it hasn’t been kept.
Remove
Section titled “Remove”public void Remove(Entity entity)Takes entity out of what’s selected.
Select
Section titled “Select”public void Select(Entity entity)Selects entity alone, as a click on it does.
Select
Section titled “Select”public void Select(IEnumerable<Entity> entities)Selects entities, dropping anything already selected.
SetGroup
Section titled “SetGroup”public void SetGroup(int number, IEnumerable<Entity> entities)Keeps entities as control group number (1 to 9), as Ctrl and the number does with the selection.
Events
Section titled “Events”Commanded
Section titled “Commanded”public event Action<Entity, Vector2, IReadOnlyList<Entity>>? CommandedRaised by a right-click (the Command action) with something selected: the target under the mouse (the Selectable on top, or a button in the world, or null for the ground), the point in the world, and what’s selected. The game carries the command out: walk there, work the machine, unload the truck.
SelectionChanged
Section titled “SelectionChanged”public event Action<IReadOnlyList<Entity>>? SelectionChangedRaised whenever what’s selected changes, with what’s selected now.