TableTower/ui/inspector_scale.gd
RobinFiredrake 03bc168756 UI for scales: make, show and edit ordered-step values
- Making one: Scale (ordered steps) in + Card, the inspector's Type switch
  and the settings dialog; steps one per line and a starting step dropdown
  (InspectorScale); new scales get Low, Medium, High.
- Showing one: the variable card shows the current step and the steps in a
  row with the current one marked; the Variables tab stores a typed step
  number or name as the step.
- Plain words: Builder ops step_up, step_down, toward, at_least, at_most
  (BuilderScales; step_up/down need the board), DescribeScales phrases,
  scale effect rows (EffectsScaleRow) and step dropdowns in conditions.
- Help: a Scales topic after Values and changes.
- Tests: test_ui_scales, plus builder and describe cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:25:55 -06:00

35 lines
1.5 KiB
GDScript

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)