TableTower/ui/sheet_fields_smart.gd
RobinFiredrake 317cac7a78 Sheets phase E: export/import, text toolbar and Lore links, Lore library and items, phone view
- E1: Export ▾ (share file with embedded pictures, print/PDF web page,
  PNG of the tab); Import a sheet file from Sheets and New sheet.
- E2: formatting toolbar (FormatMenu) in sheet text boxes; Lore links
  ([url=lore:ID]) with hover excerpt and the details panel.
- E3: Lore Index in Play and in sheets (shared LoreList); This spread |
  My library; item sheets on Lore Entries; drag entries into lists,
  slots and notes (copy, Shift keeps linked).
- E4: phone stacked view in phone order, Stacked | Canvas switch, 44 px
  touch sizes, bottom panels; sheet CLI flags split out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 17:25:09 -06:00

58 lines
2.4 KiB
GDScript

class_name SheetFieldsSmart
extends RefCounted
## Smart boxes: a formula worked out from other boxes (the rule language with
## the sheet's values as @names, SheetValues), and a dice button that rolls
## its dice with them and shows the result.
static func make(ed: SheetEditor, box: SheetBox, look: Dictionary) -> Control:
var ink: Color = look["ink"]
if box.kind == SheetKinds.FORMULA:
return _formula(ed, box, ink)
return _dice(ed, box, ink)
static func _formula(ed: SheetEditor, box: SheetBox, ink: Color) -> Control:
var result := SheetValues.formula(ed.doc, box)
var col := VBoxContainer.new()
col.alignment = BoxContainer.ALIGNMENT_CENTER
var value := Style.make_label(SheetValues.show(result["value"]) if result["error"] == "" else "?", Style.display(), 26, ink)
value.name = "Value"
value.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
col.add_child(value)
var expr := str(box.config.get("expr", ""))
var line := SheetFieldViews.note(str(result["error"]) if result["error"] != "" else "ƒ " + expr, ink, 12)
line.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
line.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
line.autowrap_mode = TextServer.AUTOWRAP_OFF
col.add_child(line)
col.tooltip_text = "Worked out from: %s" % expr
return col
## [Roll], then the dice and the last result under it.
static func _dice(ed: SheetEditor, box: SheetBox, ink: Color) -> Control:
var col := VBoxContainer.new()
col.alignment = BoxContainer.ALIGNMENT_CENTER
col.add_theme_constant_override("separation", 4)
var dice := str(box.config.get("dice", "1d20"))
var b := SheetFieldViews.step_button("Roll", ink)
b.tooltip_text = "Roll %s" % dice
b.name = "Roll"
b.custom_minimum_size.y = maxf(32, b.custom_minimum_size.y)
b.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
col.add_child(b)
var last := SheetFieldViews.note("%s · %s" % [dice, str(box.value) if box.value != null else "not rolled yet"], ink, 12)
last.name = "Last"
last.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
col.add_child(last)
b.pressed.connect(func() -> void:
var r := SheetValues.evaluate(ed.doc, dice, 0, ed.m.rng)
if r["error"] != "":
ed.m.toast("%s: %s" % [box.title, r["error"]])
return
var text := "Rolled %s" % SheetValues.show(r["value"])
last.text = "%s · %s" % [dice, text]
ed.m.toast("%s: %s (%s)" % [box.title, SheetValues.show(r["value"]), dice])
ed.edit_value(box, text))
return col