- 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>
40 lines
1.6 KiB
GDScript
40 lines
1.6 KiB
GDScript
class_name ScaleFields
|
|
extends RefCounted
|
|
## Small shared pieces for scale values (Scales) in the inspector: a value's
|
|
## steps, a dropdown of steps, and a step written as a rule literal.
|
|
|
|
|
|
## The steps of board value `v` ("@climate") when a scale card declares it,
|
|
## else [].
|
|
static func steps_of(main: Main, v: String) -> Array[String]:
|
|
var card := BuilderScales.card_for(v, main.data if main else null)
|
|
return card.steps if card else ([] as Array[String])
|
|
|
|
|
|
## A dropdown of `steps` with `current` selected (matched without caring about
|
|
## capitals). A `current` that isn't one of the steps is listed last, marked,
|
|
## so nothing is lost. `on_pick` gets the chosen step's name.
|
|
static func step_dropdown(steps: Array, current: String, on_pick: Callable) -> OptionButton:
|
|
var items: Array = steps.duplicate()
|
|
var at := Scales.position_of(steps, current) - 1 if current != "" else -1
|
|
if at < 0 and current != "":
|
|
items.append("%s (not a step)" % current)
|
|
at = items.size() - 1
|
|
var dd := InspectorKit.dropdown(items, at)
|
|
dd.tooltip_text = "Pick a step"
|
|
dd.item_selected.connect(func(k: int) -> void:
|
|
if k < steps.size():
|
|
on_pick.call(str(steps[k]))
|
|
)
|
|
return dd
|
|
|
|
|
|
## The steps a new scale card gets (RollTable.create's).
|
|
static func default_steps() -> Array[String]:
|
|
return RollTable.create(RollTable.KIND_VARIABLE, "", "", RollTable.VAR_SCALE).steps
|
|
|
|
|
|
## A step as a starting value: the name as it is when it reads as plain words,
|
|
## else quoted ("Semi-arid" has a dash, so it is "\"Semi-arid\"").
|
|
static func initial_text(step: String) -> String:
|
|
return step if RollTable._looks_literal(step) else Builder.quote(step)
|