Skip to content

Choice

namespace Griff.Scenes;
public sealed class Choice : Component

Turns a Button into a picker of one of several Options: “Difficulty: Normal”. Left and right change it while it’s picked, and clicking (or the mouse wheel) moves to the next. SaveAs keeps the choice for next time, for scripts to read with Game.SaveData.GetString("difficulty"). Needs a Button on the same entity.

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

public string? Format { get; set; }

What the entity’s Text says, with {0} for the option: “Difficulty: < {0} >”. Empty leaves the text alone.

public int Index { get; set; }

Which option is picked, from 0.

public IReadOnlyList<string> Options { get; set; }

What can be picked, one per row.

public string? SaveAs { get; set; }

A name to keep the option under in Game.SaveData, e.g. “difficulty”. It’s saved as the option’s text.

public GameSetting Setting { get; set; }

A setting of the game it picks, with no code: Window Size or Frame Cap. While set, its options are the setting’s own (the window sizes that fit the screen, or the frame caps) in place of Options, it always shows the setting, and the game remembers it next time.

public string? Sound { get; set; }

A sound played as it changes, e.g. “Sounds/blip.wav”.

public string? Value { get; }

The option picked, or null if there are none.

public bool Wrap { get; set; }

Whether going past the last option comes round to the first again (and back).

public string? Display()

What the label says for the option picked; null leaves it alone.

public string ReadsAs(string? format)

What its text says with format as its Format, with the option picked now.

public int Step(int steps)

The index steps along from the one picked (negative goes back), wrapping round or stopping at the ends as Wrap says.

public event Action<Choice>? Changed

Raised when the player changes it.