Skip to content

TogglesList

namespace Griff.Scenes;
public sealed class TogglesList : Component, IDrawable

A screen of on/off switches with no hand-placed buttons: while the game runs it makes a row for each row of a data table, its label and a Toggle button, each remembered in the save data under its own name (SaveAs, e.g. “fire.{row}”) and starting as the table’s DefaultColumn says until the player flips it. Put it on an entity with a Layout (in an options Panel), which lines the rows up and scrolls them. Every row’s Toggle is a real one, read by scripts with Game.SaveData.GetBool like a hand-placed Toggle.

Its children that hold a Toggle are its rows: it takes them away and makes them again when the table or the list changes, and leaves its other children (a heading) alone. Each plain row is an entity named after its table row with a Text for the label and a Button with a Toggle; a Template gives rows of your own. The Scene view shows sample rows where they’ll go.

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

public Color ButtonColor { get; set; }

The color of the plain rows’ buttons.

public float ButtonWidth { get; set; }

How wide each plain row’s button is, in world units.

public Color Color { get; set; }

The color of the plain rows’ words.

public string? DefaultColumn { get; set; }

The column (yes or no) holding whether each row starts on, until the player flips it or the game has one saved. Empty starts every row on, as a Toggle does.

public string? Font { get; set; }

A font for the plain rows’ words, as a Text’s Font. Empty uses the built-in font.

public string? Hide { get; set; }

Rows to leave out, separated by commas, with * and ? for any letters and one, e.g. “Debug*, Test” (the names of the table’s rows).

public string? LabelColumn { get; set; }

The column holding the words to show for each row. Empty shows the row’s name.

public IReadOnlyList<string> Listed { get; }

The names of the table rows it lists now, in order. Kept up to date by the game.

public string OffText { get; set; }

What a plain row’s button says while it’s off.

public string OnText { get; set; }

What a plain row’s button says while it’s on.

public float RowHeight { get; set; }

How tall each plain row is, in world units; it’s as wide as the Layout has room for.

public IReadOnlyList<Entity> Rows { get; }

The rows it made, one for each of Listed, in the same order. Kept up to date by the game.

public string? SaveAs { get; set; }

The name each row’s switch is kept under in Game.SaveData, where “{row}” is the row’s name: “fire.{row}” keeps the Rain row’s as “fire.Rain” (read it with GetBool("fire.Rain", true)). Without “{row}” every row would share one name.

public string? Table { get; set; }

The table with a row for each switch, e.g. “Fires” (Assets/Tables/Fires.table).

public string? Template { get; set; }

An entity to copy for each row instead of the plain ones, by name, e.g. “Fire Row”: a disabled one in the scene styled as you like. In each copy, “{name}” in a Text becomes the row’s label and “{row}” its name, and a Toggle with no Save As is kept under SaveAs (starting as DefaultColumn says, if it names one).

public float TextSize { get; set; }

How tall the plain rows’ words are, in world units.

public bool DefaultOf(TableRow row)

Whether a row starts on: its DefaultColumn cell, or on when there’s no such column.

public string KeyOf(TableRow row)

The name a row’s switch is kept under in the save data: SaveAs with “{row}” as the row’s name.

public string LabelOf(TableRow row)

The words a row shows: its LabelColumn cell, or its name when that is empty or not there.

public List<TableRow> Pick(Table table)

The rows of table it lists, in the table’s order, without those Hide leaves out.