Skip to content

Selectable

namespace Griff.Scenes;
public sealed class Selectable : Component

Something the player selects as in a strategy game, with a SelectionControls: a worker, a machine, a truck. A click picks it, a box dragged over it picks it (with InBox), a double-click picks every one of its Kind on screen, and right-clicking it while others are selected commands them, with it as the target. A marker is drawn round it while it’s selected.

Its area is Size if that’s set, else its Button’s, else its box collider’s or its sprite’s. Where several overlap under the mouse, the one drawn on top is picked.

This is a component: its saved properties are on its component page.

public bool Clickable { get; set; }

Whether a click picks it. Untick it for something that’s only a target: right-clicking it still commands what’s selected, with it as the target (a resource, an enemy).

public bool InBox { get; set; }

Whether a box dragged out over it picks it. Untick it for what’s picked one at a time (a machine, a storage stack) so a box picks only the workers among them.

public bool IsSelected { get; }

True while a SelectionControls has it selected.

public string? Kind { get; set; }

What kind of thing it is, e.g. “Worker” or “Smelter”: a double-click on it picks every one of this kind on screen. Empty goes by the entity’s name.

public string KindName { get; }

Its kind for a double-click: Kind, or else the entity’s name.

public Vector2 Offset { get; set; }

Where the middle of Size’s area is from the entity, e.g. (0, 0.5) for a character standing on its position.

public Vector2 Size { get; set; }

The area that picks it, in world units before the transform’s scale (and turned with it), centered on the entity plus Offset. (0, 0) takes its Button’s, box collider’s or sprite’s.

public Box Area()

The upright box in the world round Shape.

public TurnedBox Shape()

The area in the world that picks it as it is now (see Size): it turns and scales with the entity, so a truck turned a quarter is picked, boxed and marked as it lies.

public event Action? Deselected

Raised when it stops being selected.

public event Action? Selected

Raised when it’s selected.