Split TableCard into header, rows, editing, value-body and text helpers
ui/table_card.gd keeps the card node (setup, rebuild, styling, selection,
highlights API, geometry, drag input) and delegates to RefCounted helpers
that own their own state: TableCardHeader, TableCardRows, TableCardEditing,
TableCardValue, plus static TableCardText. No behaviour change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:10:57 -06:00
|
|
|
class_name TableCardValue
|
|
|
|
|
extends RefCounted
|
|
|
|
|
## The body of a variable card (its live value, big) or a collection card (its
|
|
|
|
|
## members with live values), re-rendered by refresh() after rolls and edits.
|
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:30 -06:00
|
|
|
## A scale card also shows its steps in a row with the current one marked.
|
Split TableCard into header, rows, editing, value-body and text helpers
ui/table_card.gd keeps the card node (setup, rebuild, styling, selection,
highlights API, geometry, drag input) and delegates to RefCounted helpers
that own their own state: TableCardHeader, TableCardRows, TableCardEditing,
TableCardValue, plus static TableCardText. No behaviour change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:10:57 -06:00
|
|
|
|
|
|
|
|
var card: TableCard
|
|
|
|
|
var var_value: Label
|
|
|
|
|
var var_hint: Label
|
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:30 -06:00
|
|
|
## Scale cards: the steps in a row, refilled when the current step changes.
|
|
|
|
|
var steps_row: HFlowContainer
|
|
|
|
|
var steps_cache := ""
|
Split TableCard into header, rows, editing, value-body and text helpers
ui/table_card.gd keeps the card node (setup, rebuild, styling, selection,
highlights API, geometry, drag input) and delegates to RefCounted helpers
that own their own state: TableCardHeader, TableCardRows, TableCardEditing,
TableCardValue, plus static TableCardText. No behaviour change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:10:57 -06:00
|
|
|
## Collection cards: the member list, refilled by refresh().
|
|
|
|
|
var members_box: VBoxContainer
|
|
|
|
|
var members_cache := ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _init(p_card: TableCard) -> void:
|
|
|
|
|
card = p_card
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Drops the references to the previous build's labels.
|
|
|
|
|
func clear() -> void:
|
|
|
|
|
var_value = null
|
|
|
|
|
var_hint = null
|
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:30 -06:00
|
|
|
steps_row = null
|
|
|
|
|
steps_cache = ""
|
Split TableCard into header, rows, editing, value-body and text helpers
ui/table_card.gd keeps the card node (setup, rebuild, styling, selection,
highlights API, geometry, drag input) and delegates to RefCounted helpers
that own their own state: TableCardHeader, TableCardRows, TableCardEditing,
TableCardValue, plus static TableCardText. No behaviour change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:10:57 -06:00
|
|
|
members_box = null
|
|
|
|
|
members_cache = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## A variable card's body: its live value, big, and in Build its starting value
|
|
|
|
|
## and a reset button.
|
|
|
|
|
func make_variable_body(build: bool) -> Control:
|
|
|
|
|
var table := card.table
|
|
|
|
|
var main := card.main
|
|
|
|
|
var wrap := MarginContainer.new()
|
|
|
|
|
wrap.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
|
|
|
wrap.add_theme_constant_override("margin_left", 14)
|
|
|
|
|
wrap.add_theme_constant_override("margin_right", 12)
|
|
|
|
|
wrap.add_theme_constant_override("margin_top", 6)
|
|
|
|
|
wrap.add_theme_constant_override("margin_bottom", 10)
|
|
|
|
|
var v := TableCard.vbox(2)
|
|
|
|
|
wrap.add_child(v)
|
|
|
|
|
var_value = Style.make_label("", Style.display(true), 34, Style.INK)
|
|
|
|
|
var_value.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
|
|
|
var_value.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
|
|
|
v.add_child(var_value)
|
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:30 -06:00
|
|
|
if table.is_scale():
|
|
|
|
|
steps_row = HFlowContainer.new()
|
|
|
|
|
steps_row.add_theme_constant_override("h_separation", 3)
|
|
|
|
|
steps_row.add_theme_constant_override("v_separation", 3)
|
|
|
|
|
steps_row.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
|
|
|
v.add_child(steps_row)
|
Split TableCard into header, rows, editing, value-body and text helpers
ui/table_card.gd keeps the card node (setup, rebuild, styling, selection,
highlights API, geometry, drag input) and delegates to RefCounted helpers
that own their own state: TableCardHeader, TableCardRows, TableCardEditing,
TableCardValue, plus static TableCardText. No behaviour change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:10:57 -06:00
|
|
|
var_hint = Style.make_label("", Style.body(true), 12, Style.MUTED)
|
|
|
|
|
var_hint.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
|
|
|
var_hint.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
|
|
|
v.add_child(var_hint)
|
|
|
|
|
if build:
|
|
|
|
|
var h := TableCard.hbox(8)
|
|
|
|
|
var init := RulesView.dice(table.initial, main.data, card.plain) if table.initial.strip_edges() != "" else ""
|
|
|
|
|
var start := Style.make_label("Starts at %s" % (init if init != "" else ("0" if table.var_type == "number" else "nothing")),
|
|
|
|
|
Style.body(true), 12, Style.MUTED)
|
|
|
|
|
start.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
|
|
|
start.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
|
|
|
|
h.add_child(start)
|
|
|
|
|
var reset := Button.new()
|
|
|
|
|
reset.text = "↺ Reset"
|
|
|
|
|
reset.tooltip_text = "Set @%s back to its starting value" % table.var_name
|
|
|
|
|
reset.add_theme_font_override("font", Style.body(true))
|
|
|
|
|
reset.add_theme_font_size_override("font_size", 12)
|
|
|
|
|
var n := Style.box(Color(0, 0, 0, 0), 5, [5, 0, 5, 1])
|
Theme system: runtime colour tokens, theme sets and a Theme dialog
Style's colours become static vars named by role (BG, PANEL, CARD, THREAD,
ACCENT, TRIM, GLOW…) instead of materials (felt, copper, brass), so a theme
can replace them. Stray hard-coded colours moved into tokens.
ThemeStore applies built-in sets (Tarot, the new default: jewel-purple
cloth with a shine; Felt, the old look) and the user's own sets from
user://themes/. Fills for the background and panels can be gradients; the
background pattern (dots, stars, none) and logo are per set. View ▾ →
Theme… edits a set; changes to a built-in save as a new set. Using a theme
reloads the UI and keeps the open spread.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 18:10:16 -06:00
|
|
|
var hv := Style.box(Style.CARD_HOVER, 5, [5, 0, 5, 1])
|
|
|
|
|
Style.skin_button(reset, n, hv, hv, Style.TRIM, Style.INK)
|
Split TableCard into header, rows, editing, value-body and text helpers
ui/table_card.gd keeps the card node (setup, rebuild, styling, selection,
highlights API, geometry, drag input) and delegates to RefCounted helpers
that own their own state: TableCardHeader, TableCardRows, TableCardEditing,
TableCardValue, plus static TableCardText. No behaviour change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:10:57 -06:00
|
|
|
reset.pressed.connect(func() -> void: main.reset_variable(table.var_name))
|
|
|
|
|
h.add_child(reset)
|
|
|
|
|
v.add_child(h)
|
|
|
|
|
return wrap
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## A collection card's body: its members with their live values (refilled by
|
|
|
|
|
## refresh()), and in Build "+ Add …", which selects the card so the
|
|
|
|
|
## inspector can add a member.
|
|
|
|
|
func make_collection_body(build: bool) -> Control:
|
|
|
|
|
var table := card.table
|
|
|
|
|
var main := card.main
|
|
|
|
|
var wrap := MarginContainer.new()
|
|
|
|
|
wrap.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
|
|
|
wrap.add_theme_constant_override("margin_left", 12)
|
|
|
|
|
wrap.add_theme_constant_override("margin_right", 14)
|
|
|
|
|
wrap.add_theme_constant_override("margin_top", 6)
|
|
|
|
|
wrap.add_theme_constant_override("margin_bottom", 10)
|
|
|
|
|
var v := TableCard.vbox(6)
|
|
|
|
|
wrap.add_child(v)
|
|
|
|
|
members_box = TableCard.vbox(0)
|
|
|
|
|
v.add_child(members_box)
|
|
|
|
|
if build:
|
|
|
|
|
var add := TableCardEditing.footer_button("+ Add " + Describe._singular(Formatter.strip_tags(table.name).strip_edges().to_lower()), Style.INK)
|
|
|
|
|
add.size_flags_horizontal = Control.SIZE_FILL
|
|
|
|
|
add.tooltip_text = "Add a member in the inspector"
|
|
|
|
|
add.set_meta("collection_add", true)
|
|
|
|
|
add.pressed.connect(func() -> void:
|
|
|
|
|
if main.has_method("select_card"):
|
|
|
|
|
main.call("select_card", table.id)
|
|
|
|
|
else:
|
|
|
|
|
main.request_table_settings(table.id)
|
|
|
|
|
)
|
|
|
|
|
v.add_child(add)
|
|
|
|
|
return wrap
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## A collection's members: [{name ("@skill_pilot"), label ("Pilot"), value
|
|
|
|
|
## (Variant or null when not set)}], set members first, then members only
|
|
|
|
|
## named by the board's rules, each sorted by label.
|
|
|
|
|
static func collection_members(t: RollTable, board: TowerBoard, vars: Dictionary) -> Array[Dictionary]:
|
|
|
|
|
var out: Array[Dictionary] = []
|
|
|
|
|
if t == null or not t.is_collection() or t.var_name == "":
|
|
|
|
|
return out
|
|
|
|
|
var seen := {}
|
|
|
|
|
for v: Dictionary in RollContext.vars_with_prefix(vars, t.var_name + "_"):
|
|
|
|
|
var nm := "@" + str(v["name"])
|
|
|
|
|
seen[nm] = true
|
|
|
|
|
out.append({"name": nm, "label": Describe.label(nm, board), "value": v["value"]})
|
|
|
|
|
var named: Array[Dictionary] = []
|
|
|
|
|
for kv: Dictionary in Builder.known_values(board):
|
|
|
|
|
if str(kv.get("collection", "")) == "@%s_*" % t.var_name and not seen.has(str(kv["name"])):
|
|
|
|
|
seen[str(kv["name"])] = true
|
|
|
|
|
named.append({"name": str(kv["name"]), "label": str(kv["label"]), "value": null})
|
|
|
|
|
var by_label := func(a: Dictionary, b: Dictionary) -> bool: return str(a["label"]).naturalnocasecmp_to(str(b["label"])) < 0
|
|
|
|
|
out.sort_custom(by_label)
|
|
|
|
|
named.sort_custom(by_label)
|
|
|
|
|
out.append_array(named)
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _refresh_members() -> void:
|
|
|
|
|
var plain := card.plain
|
|
|
|
|
var list := collection_members(card.table, card.main.data, card.main.persistent_vars)
|
|
|
|
|
var key := var_to_str(list) + str(plain)
|
|
|
|
|
if key == members_cache:
|
|
|
|
|
return
|
|
|
|
|
members_cache = key
|
|
|
|
|
for c in members_box.get_children():
|
|
|
|
|
members_box.remove_child(c)
|
|
|
|
|
c.queue_free()
|
|
|
|
|
if list.is_empty():
|
|
|
|
|
var none := Style.make_label("No members yet", Style.body_italic(true), 14, Style.MUTED)
|
|
|
|
|
none.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
|
|
|
members_box.add_child(none)
|
|
|
|
|
return
|
|
|
|
|
for m: Dictionary in list:
|
|
|
|
|
var h := TableCard.hbox(8)
|
|
|
|
|
h.custom_minimum_size = Vector2(0, 28)
|
|
|
|
|
h.set_meta("member", str(m["name"]))
|
|
|
|
|
var nl := Style.make_label(str(m["label"]) if plain else str(m["name"]), Style.body(true), 15, Style.INK)
|
|
|
|
|
nl.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
|
|
|
nl.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
|
|
|
|
nl.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
|
|
|
h.add_child(nl)
|
|
|
|
|
var val: Variant = m["value"]
|
|
|
|
|
var vl := Style.make_label("—" if val == null else Expr.format_value(val), Style.display(true), 17, Style.INK if val != null else Style.MUTED)
|
|
|
|
|
vl.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
|
|
|
|
vl.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
|
|
|
h.add_child(vl)
|
|
|
|
|
members_box.add_child(h)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Re-renders the member list or the variable's value and hint, touching only
|
|
|
|
|
## what changed.
|
|
|
|
|
func refresh() -> void:
|
|
|
|
|
if is_instance_valid(members_box):
|
|
|
|
|
_refresh_members()
|
|
|
|
|
if is_instance_valid(var_value):
|
|
|
|
|
var d := Roller.variable_display(card.main.data, card.main.persistent_vars, card.table)
|
|
|
|
|
var shown := str(d["text"]) if str(d["text"]) != "" else "—"
|
|
|
|
|
if var_value.text != shown:
|
|
|
|
|
var_value.text = shown
|
|
|
|
|
var size_px := 34 if shown.length() <= 8 else (24 if shown.length() <= 18 else 17)
|
|
|
|
|
var_value.add_theme_font_size_override("font_size", size_px)
|
|
|
|
|
var_value.add_theme_color_override("font_color", Style.INK if d["set"] else Style.MUTED)
|
|
|
|
|
var hint := ""
|
|
|
|
|
if str(d["error"]) != "":
|
|
|
|
|
hint = "⚠ " + str(d["error"])
|
|
|
|
|
elif not d["set"]:
|
|
|
|
|
hint = "Not set yet · starts at this"
|
|
|
|
|
var_hint.text = hint
|
|
|
|
|
var_hint.add_theme_color_override("font_color", Style.DANGER_INK if str(d["error"]) != "" else Style.MUTED)
|
|
|
|
|
var_hint.visible = hint != ""
|
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:30 -06:00
|
|
|
if is_instance_valid(steps_row):
|
|
|
|
|
_refresh_steps(str(d["text"]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## The steps as small chips, the one named `current` filled in.
|
|
|
|
|
func _refresh_steps(current: String) -> void:
|
|
|
|
|
var steps := card.table.steps
|
|
|
|
|
var key := "%s|%s" % [current, "\n".join(steps)]
|
|
|
|
|
if key == steps_cache:
|
|
|
|
|
return
|
|
|
|
|
steps_cache = key
|
|
|
|
|
InspectorKit.clear(steps_row)
|
|
|
|
|
var at := Scales.position_of(steps, current) - 1
|
|
|
|
|
for k in steps.size():
|
|
|
|
|
var on := k == at
|
|
|
|
|
var chip := PanelContainer.new()
|
|
|
|
|
chip.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
|
|
|
var bg := Style.box(Style.VALUE_BG if on else Color(0, 0, 0, 0), 4, [5, 1, 5, 1])
|
|
|
|
|
chip.add_theme_stylebox_override("panel", Style.bordered(bg, 1, Style.VALUE_BORDER if on else Style.RULE))
|
|
|
|
|
var l := Style.make_label(str(steps[k]), Style.body_bold(true) if on else Style.body(true), 11, Style.VALUE_INK if on else Style.MUTED)
|
|
|
|
|
l.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
|
|
|
chip.add_child(l)
|
|
|
|
|
steps_row.add_child(chip)
|