- 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>
149 lines
6.3 KiB
GDScript
149 lines
6.3 KiB
GDScript
class_name SheetTopBar
|
|
extends PanelContainer
|
|
## The sheet editor's top bar, the same layout as the spread's (MainTopBar):
|
|
## the brand (click: main menu), Play | Build, a SHEET caption over the sheet's
|
|
## name (click: switch sheet, all sheets, rename), the mode hint, and in Build
|
|
## Field palette, Undo, Redo and Save as template…; ☰ at the end.
|
|
|
|
const HINTS := {
|
|
Main.Mode.PLAY: "Type in the boxes to change values.",
|
|
Main.Mode.BUILD: "Drag a box to move it, its corner to resize it.",
|
|
}
|
|
|
|
var ed: SheetEditor
|
|
var play_button: Button
|
|
var build_button: Button
|
|
var name_button: MenuButton
|
|
var palette_button: Button
|
|
var undo_button: Button
|
|
var redo_button: Button
|
|
var _hint: Label
|
|
var _tools: HBoxContainer
|
|
## "← Spread name" when the sheet was opened from a spread.
|
|
var back_button: Button
|
|
|
|
|
|
func setup(p_editor: SheetEditor) -> void:
|
|
ed = p_editor
|
|
add_theme_stylebox_override("panel", Style.panel_box([16, 10, 16, 10]))
|
|
var h := HBoxContainer.new()
|
|
h.add_theme_constant_override("separation", 10)
|
|
add_child(h)
|
|
h.add_child(MainTopBar.make_brand(func() -> void: ed.m.screens.show(MainScreens.MENU)))
|
|
back_button = Style.bar_button("")
|
|
back_button.name = "BackToSpread"
|
|
back_button.tooltip_text = "Back to the spread this sheet sits on"
|
|
back_button.pressed.connect(func() -> void: ed.back_to_spread())
|
|
h.add_child(back_button)
|
|
var seg := PanelContainer.new()
|
|
seg.add_theme_stylebox_override("panel", Style.box(Color(0, 0, 0, 0.28), 9, [3, 3, 3, 3]))
|
|
seg.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
|
var seg_row := HBoxContainer.new()
|
|
seg_row.add_theme_constant_override("separation", 0)
|
|
seg.add_child(seg_row)
|
|
var group := ButtonGroup.new()
|
|
play_button = MainTopBar.seg_button("Play", group)
|
|
build_button = MainTopBar.seg_button("Build", group)
|
|
play_button.pressed.connect(func() -> void: ed.set_mode(Main.Mode.PLAY))
|
|
build_button.pressed.connect(func() -> void: ed.set_mode(Main.Mode.BUILD))
|
|
seg_row.add_child(play_button)
|
|
seg_row.add_child(build_button)
|
|
h.add_child(seg)
|
|
var name_box := VBoxContainer.new()
|
|
name_box.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
|
name_box.add_theme_constant_override("separation", 0)
|
|
var caption := Style.make_label("SHEET", Style.caps(), 10, Style.ON_BG_MUTED)
|
|
caption.tooltip_text = "A sheet keeps track of one thing: a character, a vehicle… Click its name to switch sheets."
|
|
caption.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
name_box.add_child(caption)
|
|
name_button = Style.menu_button("", false)
|
|
name_button.tooltip_text = "Switch sheets, see all sheets, or rename this one"
|
|
name_button.get_popup().about_to_popup.connect(_fill_name_menu)
|
|
name_box.add_child(name_button)
|
|
h.add_child(name_box)
|
|
_hint = Style.make_label("", Style.body(), 14, Style.ON_BG_MUTED)
|
|
_hint.size_flags_horizontal = SIZE_EXPAND_FILL
|
|
_hint.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
|
_hint.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
|
_hint.custom_minimum_size = Vector2(60, 0)
|
|
h.add_child(_hint)
|
|
_tools = HBoxContainer.new()
|
|
_tools.add_theme_constant_override("separation", 6)
|
|
h.add_child(_tools)
|
|
palette_button = Style.bar_button("Field palette")
|
|
palette_button.toggle_mode = true
|
|
palette_button.focus_mode = Control.FOCUS_NONE
|
|
palette_button.tooltip_text = "Show or hide the field palette"
|
|
palette_button.pressed.connect(func() -> void: ed.set_palette_shown(not ed.palette_dock.visible))
|
|
_tools.add_child(palette_button)
|
|
undo_button = Style.bar_button("↶ Undo")
|
|
undo_button.pressed.connect(ed.undo)
|
|
_tools.add_child(undo_button)
|
|
redo_button = Style.bar_button("↷ Redo")
|
|
redo_button.pressed.connect(ed.redo)
|
|
_tools.add_child(redo_button)
|
|
var template := Style.bar_button("Save as template…")
|
|
template.pressed.connect(save_as_template)
|
|
_tools.add_child(template)
|
|
var actions := Style.menu_button("☰")
|
|
actions.tooltip_text = "Main menu, all sheets, theme…"
|
|
actions.get_popup().about_to_popup.connect(func() -> void: Actions.fill(actions.get_popup(), _actions()))
|
|
h.add_child(actions)
|
|
|
|
|
|
func _actions() -> Array:
|
|
return [
|
|
{"text": "Main menu", "do": ed.m.screens.show.bind(MainScreens.MENU)},
|
|
{"text": "All sheets", "do": ed.screen.show_list},
|
|
{"sep": ""},
|
|
{"text": "Rename sheet…", "do": rename},
|
|
{"text": "Save as template…", "do": save_as_template},
|
|
{"sep": ""},
|
|
{"text": "Theme…", "do": func() -> void: ed.m.add_child(ThemeDialog.new(ed.m))},
|
|
]
|
|
|
|
|
|
## The name button's menu: your other sheets, All sheets, Rename.
|
|
func _fill_name_menu() -> void:
|
|
var list: Array = []
|
|
for row: Dictionary in ed.screen.store.list():
|
|
if str(row["id"]) != ed.doc.id:
|
|
list.append({"text": str(row["name"]), "do": ed.screen.open_sheet.bind(str(row["id"]))})
|
|
if not list.is_empty():
|
|
list.append({"sep": ""})
|
|
list.append({"text": "All sheets…", "do": ed.screen.show_list})
|
|
list.append({"text": "Rename…", "do": rename})
|
|
Actions.fill(name_button.get_popup(), list)
|
|
|
|
|
|
func rename() -> void:
|
|
ed.m._add_modal(ModalCard.ask_text("Rename sheet", "Name", ed.doc.name, "Rename", func(text: String) -> void:
|
|
ed.edit("Rename sheet", func() -> void: ed.doc.name = text.strip_edges())))
|
|
|
|
|
|
func save_as_template() -> void:
|
|
ed.m._add_modal(ModalCard.ask_text("Save as template", "Template name", ed.doc.name, "Save", func(text: String) -> void:
|
|
ed.save_now()
|
|
ed.screen.store.save_as_template(ed.doc, text.strip_edges())
|
|
ed.m.toast("Saved template “%s”. Pick it under + New sheet." % text.strip_edges())))
|
|
|
|
|
|
## Brings the bar in line with the editor: mode, name, undo state.
|
|
func sync() -> void:
|
|
if ed.doc == null:
|
|
return
|
|
var build := ed.building()
|
|
play_button.set_pressed_no_signal(not build)
|
|
build_button.set_pressed_no_signal(build)
|
|
name_button.text = "%s ▾" % ed.doc.name
|
|
back_button.visible = ed.from_spread != ""
|
|
back_button.text = "← %s" % ed.from_spread
|
|
_hint.text = HINTS[ed.mode]
|
|
_tools.visible = build
|
|
palette_button.set_pressed_no_signal(ed.palette_dock.visible)
|
|
undo_button.disabled = not ed.history.can_undo()
|
|
redo_button.disabled = not ed.history.can_redo()
|
|
undo_button.modulate.a = 1.0 if ed.history.can_undo() else 0.45
|
|
redo_button.modulate.a = 1.0 if ed.history.can_redo() else 0.45
|
|
undo_button.tooltip_text = "Undo: %s (Ctrl+Z)" % ed.history.undo_label() if ed.history.can_undo() else "Nothing to undo"
|
|
redo_button.tooltip_text = "Redo: %s (Ctrl+Shift+Z)" % ed.history.redo_label() if ed.history.can_redo() else "Nothing to redo"
|