Choice
namespace Griff.Scenes;
public sealed class Choice : ComponentTurns 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.
Properties
Section titled “Properties”Format
Section titled “Format”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.
Options
Section titled “Options”public IReadOnlyList<string> Options { get; set; }What can be picked, one per row.
SaveAs
Section titled “SaveAs”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.
Setting
Section titled “Setting”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).
Methods
Section titled “Methods”Display
Section titled “Display”public string? Display()What the label says for the option picked; null leaves it alone.
ReadsAs
Section titled “ReadsAs”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.
Events
Section titled “Events”Changed
Section titled “Changed”public event Action<Choice>? ChangedRaised when the player changes it.