TableTower/ui/field_palette.gd
RobinFiredrake dd0323c53f Sheets phase C: every field kind, details panel, canvas panning
- 25 palette items over 23 kinds: basics, trackers (bars, ticks, clocks,
  dots, step/usage dice, ladders), formulas and dice buttons (rule
  language with sheet @names), lists (rows, mini table, chips, point pool
  that may go negative, bonds), slots, conditions, spell slots, XP,
  currency, heading, divider, picture.
- Per-kind settings in the inspector; hover excerpts and an in-app
  details panel for list entries; live redraw of dependent boxes.
- Canvas: the page stays put after edits (boxes can go anywhere), a
  screen of room past the boxes, drag-to-pan and edge scrolling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 16:28:04 -06:00

55 lines
1.7 KiB
GDScript

class_name FieldPalette
extends VBoxContainer
## The sheet editor's field palette: every kind of box (SheetKinds) in a
## PaletteList, like the spread's card palette. Click adds a box in the middle
## of the canvas; drag drops it where you let go. Greyed in Play under a
## notice with Switch to Build.
const MESSAGE := "Fields are added in Build mode."
var ed: SheetEditor
var list: PaletteList
var notice: PanelContainer
func setup(p_editor: SheetEditor) -> void:
ed = p_editor
add_theme_constant_override("separation", 8)
notice = BuildModeHint.make_notice(ed.m, func() -> void: ed.set_mode(Main.Mode.BUILD), MESSAGE)
add_child(notice)
list = PaletteList.new()
list.setup("Search fields", "Drag onto the sheet, or click to add", "Add a field", "“number”, “text” or “title”")
list.size_flags_vertical = SIZE_EXPAND_FILL
list.sections_for = _sections
list.can_use = ed.building
list.on_blocked = func() -> void: ed.m.toast(MESSAGE)
list.drop_at = drop_at
add_child(list)
list.rebuild()
func _process(_delta: float) -> void:
notice.visible = ed.doc != null and not ed.building()
func _sections(query: String) -> Array:
var out: Array = []
for group in SheetKinds.groups():
var entries: Array = []
for item: Dictionary in SheetKinds.ITEMS:
if item["group"] == group and PaletteList.matches(item, query):
entries.append([item, _add.bind(str(item["id"]))])
out.append([group, entries])
return out
func drop_at(on_add: Callable, screen_point: Vector2) -> bool:
var at := ed.canvas.drop_point(screen_point)
if at == Vector2.INF:
return false
list.use(on_add, at)
return true
func _add(at: Vector2, kind: String) -> void:
ed.add_box(kind, at)