- A Sheet card can show a sheet file (sheet, prefix): first-tab preview, Open sheet with a way back, the spread's Play/Build in the editor. - Rolls read and write "Use in tables" boxes as @name or @prefix_name; locked boxes and formulas/lists keep their values; changed boxes glow. - A roll reaching the card shows the sheet's text (SheetText) in the tray; text boxes also show spread values when on the spread. - Old template Sheet cards migrate to a sheet with one text box (not in Help demos). Card palette lists your sheets. - Sheet canvas: tiled grid (smooth panning); boxes no longer overlap (nearest free spot, drags stop short; Alt places freely). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
111 lines
4.2 KiB
GDScript
111 lines
4.2 KiB
GDScript
class_name CardPalette
|
|
extends VBoxContainer
|
|
## The Cards tab of the left dock: every kind of card (CardCatalog) and your
|
|
## templates in a PaletteList. Click an item to add it in the middle of the
|
|
## view; drag it to place it on the spread.
|
|
## In Play the items are greyed under a notice with "Switch to Build"
|
|
## (BuildModeHint), so players learn where cards are added.
|
|
|
|
## Palette-only items that aren't card kinds.
|
|
const GROUP_ITEM := {"label": "Empty group", "group": CardCatalog.GROUP_OTHER,
|
|
"tip": "A new, empty group. Drag cards onto it.", "words": "group frame folder"}
|
|
const ALL_TEMPLATES := {"label": "All templates…", "group": CardCatalog.GROUP_TEMPLATES,
|
|
"tip": "Search, import, rename and delete templates", "words": "import manage"}
|
|
|
|
var m: Main
|
|
var list: PaletteList
|
|
var search: LineEdit
|
|
var notice: PanelContainer
|
|
var _templates: Array[Dictionary] = []
|
|
var _sheets: Array[Dictionary] = []
|
|
|
|
|
|
func setup(p_main: Main) -> void:
|
|
m = p_main
|
|
add_theme_constant_override("separation", 8)
|
|
notice = BuildModeHint.make_notice(m, func() -> void: m.set_mode(Main.Mode.BUILD))
|
|
add_child(notice)
|
|
list = PaletteList.new()
|
|
list.setup("Search cards and templates", "Drag onto the spread, or click to add", "Add a card", "“dice”, “choice” or “if”")
|
|
list.size_flags_vertical = SIZE_EXPAND_FILL
|
|
list.sections_for = _sections
|
|
list.can_use = func() -> bool: return m.mode == Main.Mode.BUILD
|
|
list.on_blocked = BuildModeHint.explain.bind(m)
|
|
list.drop_at = drop_at
|
|
list.after_use = func() -> void:
|
|
if m.mobile:
|
|
m.mobile.show_list(false)
|
|
add_child(list)
|
|
search = list.search
|
|
list.rebuild()
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
notice.visible = m.mode != Main.Mode.BUILD
|
|
|
|
|
|
## Reads the template list again (it lives in files, so not on every keystroke).
|
|
func refresh_templates() -> void:
|
|
_templates = m.templating.templates().list() if m.templating else []
|
|
_sheets.clear()
|
|
if m.screens:
|
|
_sheets = m.screens.sheets.store.list()
|
|
list.rebuild()
|
|
|
|
|
|
func _sections(query: String) -> Array:
|
|
var out: Array = []
|
|
for group in CardCatalog.groups():
|
|
var entries: Array = []
|
|
for item: Dictionary in CardCatalog.ITEMS:
|
|
if item["group"] == group and PaletteList.matches(item, query):
|
|
entries.append([item, _add_card.bind(item)])
|
|
if group == CardCatalog.GROUP_SHEETS:
|
|
entries.append_array(_sheet_entries(query))
|
|
out.append([group, entries])
|
|
var templates: Array = []
|
|
for row: Dictionary in _templates:
|
|
var item := {"label": row["name"], "group": CardCatalog.GROUP_TEMPLATES, "tip": row.get("description", ""), "words": "template"}
|
|
if PaletteList.matches(item, query):
|
|
templates.append([item, _add_template.bind(str(row["id"]))])
|
|
if PaletteList.matches(ALL_TEMPLATES, query):
|
|
templates.append([ALL_TEMPLATES, func(_at: Vector2) -> void: m.templating.open_template_picker()])
|
|
out.append([CardCatalog.GROUP_TEMPLATES, templates])
|
|
out.append([CardCatalog.GROUP_OTHER, [[GROUP_ITEM, _add_group_card]] if PaletteList.matches(GROUP_ITEM, query) else []])
|
|
return out
|
|
|
|
|
|
## Your sheets, to place on the spread as Sheet cards.
|
|
func _sheet_entries(query: String) -> Array:
|
|
var out: Array = []
|
|
for row: Dictionary in _sheets:
|
|
var item := {"label": row["name"], "group": CardCatalog.GROUP_SHEETS, "tip": "Place this sheet on the spread; tables can then use its boxes", "words": "sheet character"}
|
|
if PaletteList.matches(item, query):
|
|
out.append([item, func(at: Vector2) -> void: m.sheet_links.add_card(str(row["id"]), at)])
|
|
return out
|
|
|
|
|
|
## Adds through `on_add` with its top-left corner under a screen point on the spread.
|
|
func drop_at(on_add: Callable, screen_point: Vector2) -> bool:
|
|
var board := m.board
|
|
if not board.is_visible_in_tree() or not board.get_global_rect().has_point(screen_point):
|
|
return false
|
|
var world := board.screen_to_world(screen_point - board.global_position)
|
|
list.use(on_add, (world - Vector2(128, 20)).round())
|
|
return true
|
|
|
|
|
|
func _add_card(at: Vector2, item: Dictionary) -> void:
|
|
m.editing.add_table(str(item["kind"]), str(item["sub"]), at, str(item["variant"]))
|
|
|
|
|
|
func _add_template(at: Vector2, id: String) -> void:
|
|
var tpl := m.templating.templates().get_template(id)
|
|
if tpl.is_empty():
|
|
m.toast("Couldn't read that template")
|
|
return
|
|
m.templating.begin_template_insert(tpl, at)
|
|
|
|
|
|
func _add_group_card(at: Vector2) -> void:
|
|
m.list_view.new_group(at)
|