TableTower/ui/inspector_scale.gd

36 lines
1.5 KiB
GDScript3
Raw Normal View History

class_name InspectorScale
extends RefCounted
## A scale variable card's fields in the inspector (Scales): its steps, one
## per line, lowest first, and a starting value picked from them. Writes go
## through Inspector.apply_settings (TableSettingsRules keeps the starting
## value one of the steps).
static func build(insp: Inspector, box: VBoxContainer, t: RollTable, err: Label) -> void:
var te := InspectorKit.text_box("\n".join(t.steps), "Low\nMedium\nHigh", 96.0)
InspectorKit.tag(te, "card.steps")
insp.fields["steps"] = te
box.add_child(InspectorKit.field("Steps, one per line, lowest first", te))
var start := HBoxContainer.new()
box.add_child(InspectorKit.field("Starting value", start))
_fill_start(insp, start, t, err)
te.text_changed.connect(func() -> void:
var msg := insp.apply_settings({"steps": te.text})
InspectorKit.mark(te, msg == "")
InspectorKit.show_error(err, msg)
if msg == "":
_fill_start(insp, start, t, err)
)
## The starting value's step dropdown in `holder` (refilled when the steps change).
static func _fill_start(insp: Inspector, holder: Container, t: RollTable, err: Label) -> void:
InspectorKit.clear(holder)
var dd := ScaleFields.step_dropdown(t.steps, Builder.unquote(t.initial), func(step: String) -> void:
InspectorKit.show_error(err, insp.apply_settings({"initial": ScaleFields.initial_text(step)}))
)
dd.tooltip_text = "The step it starts at, and goes back to on Reset"
InspectorKit.tag(dd, "card.initial")
insp.fields["initial"] = dd
holder.add_child(dd)