TableTower/ui/variables_panel.gd
RobinFiredrake 87e578b85a Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
  Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
  rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
  chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
  StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
  (edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
  button for table settings, pipe popover (count, save as, remove), range
  clamps use min_value(); Build cards are 300px wide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00

113 lines
4.6 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class_name VariablesPanel
extends VBoxContainer
## The Variables tab of the result tray: the collection's persistent variables
## ({@name}), each editable, re-rollable from the table that set it, or
## clearable, and below them the last roll's chain variables (read only).
const HEIGHT := 132.0
var main: Main
var _list: VBoxContainer
var _field: StyleBoxFlat
var _field_focus: StyleBoxFlat
func setup(p_main: Main) -> void:
main = p_main
add_theme_constant_override("separation", 0)
_field = Style.bordered(Style.box(Color(1, 1, 1, 0.05), 6, [8, 3, 8, 3]), 1, Color(1, 1, 1, 0.12))
_field_focus = Style.bordered(Style.box(Color(1, 1, 1, 0.1), 6, [8, 3, 8, 3]), 1, Style.BRASS)
var scroll := ScrollContainer.new()
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
scroll.custom_minimum_size = Vector2(0, HEIGHT)
add_child(scroll)
_list = VBoxContainer.new()
_list.add_theme_constant_override("separation", 5)
_list.size_flags_horizontal = SIZE_EXPAND_FILL
scroll.add_child(_list)
func render() -> void:
for c in _list.get_children():
_list.remove_child(c)
c.queue_free()
var names: Array = main.persistent_vars.keys()
names.sort_custom(func(a: Variant, b: Variant) -> bool: return str(a).naturalnocasecmp_to(str(b)) < 0)
if names.is_empty():
var empty := RichText.label("No saved variables yet. A pipe that saves as [color=#%s]@name[/color], or [lb][lb]Table -> @name]] in a result, keeps its value here." % Style.BRASS.to_html(false),
14, Style.ON_FELT_MUTED, false)
_list.add_child(empty)
for n in names:
_list.add_child(_var_row(str(n)))
var chain: Dictionary = main.current.get("chain_vars", {})
if not chain.is_empty():
var head := Style.make_label("THIS ROLL", Style.caps(), 11, Style.ON_FELT_MUTED)
head.add_theme_constant_override("line_spacing", 0)
var gap := Control.new()
gap.custom_minimum_size = Vector2(0, 4)
_list.add_child(gap)
_list.add_child(head)
var keys: Array = chain.keys()
keys.sort()
for k in keys:
var line := RichText.label("[color=#%s]{%s}[/color] %s" % [RichText.VAR_INK_FELT.to_html(false), k, str(chain[k])],
14, Style.ON_FELT, false)
_list.add_child(line)
func _var_row(name: String) -> Control:
var v: Dictionary = main.persistent_vars[name] if main.persistent_vars[name] is Dictionary else {"value": str(main.persistent_vars[name])}
var row := HBoxContainer.new()
row.add_theme_constant_override("separation", 6)
var label := Style.make_label("@" + name, Style.body_bold(), 14, RichText.VAR_INK_FELT)
label.custom_minimum_size = Vector2(84, 0)
label.clip_text = true
label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
label.tooltip_text = "{@%s}" % name
label.size_flags_vertical = SIZE_SHRINK_CENTER
row.add_child(label)
var edit := LineEdit.new()
edit.text = str(v.get("value", ""))
edit.size_flags_horizontal = SIZE_EXPAND_FILL
edit.custom_minimum_size = Vector2(60, 0)
edit.add_theme_font_size_override("font_size", 14)
edit.add_theme_color_override("font_color", Style.ON_FELT)
edit.add_theme_color_override("caret_color", Style.ON_FELT)
edit.add_theme_color_override("selection_color", Color(Style.BRASS, 0.4))
edit.add_theme_stylebox_override("normal", _field)
edit.add_theme_stylebox_override("focus", _field_focus)
edit.tooltip_text = "Edit the value (BBCode ok); Enter to save"
var commit := func() -> void:
if main.persistent_vars.has(name) and edit.text != str((main.persistent_vars[name] as Dictionary).get("value", "")):
main.set_variable(name, edit.text)
edit.text_submitted.connect(func(_t: String) -> void:
commit.call()
edit.release_focus())
edit.focus_exited.connect(commit)
row.add_child(edit)
var source := str(v.get("source", ""))
var st := main.data.get_table(source) if source != "" else null
var again := _icon_button("↻", "Re-roll from %s" % Formatter.strip_tags(st.name) if st else "No table to re-roll from")
again.disabled = st == null
again.pressed.connect(func() -> void: main.reroll_variable(name))
row.add_child(again)
var clear := _icon_button("×", "Clear {@%s}" % name)
clear.pressed.connect(func() -> void: main.clear_variable(name))
row.add_child(clear)
return row
func _icon_button(text: String, tip: String) -> Button:
var b := Button.new()
b.text = text
b.tooltip_text = tip
b.custom_minimum_size = Vector2(28, 26)
b.add_theme_font_size_override("font_size", 16)
var n := Style.bordered(Style.box(Color(1, 1, 1, 0.04), 6), 1, Color(1, 1, 1, 0.12))
var h := Style.bordered(Style.box(Color(1, 1, 1, 0.1), 6), 1, Color(1, 1, 1, 0.2))
Style.skin_button(b, n, h, h, Style.ON_FELT_MUTED, Style.ON_FELT)
b.add_theme_color_override("font_disabled_color", Color(Style.ON_FELT_MUTED, 0.35))
return b