class_name SheetInspector extends PanelContainer ## The sheet editor's right dock (Build only), laid out like the mockup and the ## spread's: "Inspector | Lore Index" tabs, a caps kind label over the name, ## then settings. With a box selected: its title, colour, frame, phone order, ## "Use in tables" and "Lock against rolls". With nothing selected: the ## sheet's name, tint and Save as template. const WIDTH := 300.0 const INSPECTOR := "inspector" const LORE := "lore" var ed: SheetEditor var tab := INSPECTOR var _col: VBoxContainer func setup(p_editor: SheetEditor) -> void: ed = p_editor custom_minimum_size.x = WIDTH add_theme_stylebox_override("panel", Style.box(Style.CARD_SOFT, 0, [16, 14, 16, 14])) var scroll := ScrollContainer.new() scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED add_child(scroll) _col = VBoxContainer.new() _col.size_flags_horizontal = SIZE_EXPAND_FILL _col.add_theme_constant_override("separation", 14) scroll.add_child(_col) func rebuild() -> void: for c in _col.get_children(): _col.remove_child(c) c.queue_free() if ed.doc == null or not ed.building(): return _col.add_child(SideTabs.tab_row([[INSPECTOR, "Inspector"], [LORE, "Lore Index"]], tab, func(which: String) -> void: tab = which rebuild())) if tab == LORE: _col.add_child(_note("Lore Entries on sheets come in a later step: hover links, and items such as a rolled sword you drag into an inventory.")) return var box := ed.doc.find_box(ed.selected) if ed.selected != "" else null if box: _box_section(box) else: _sheet_section() func _head(kind: String, title: String, size: int = 22) -> void: var head := VBoxContainer.new() head.add_theme_constant_override("separation", 2) head.add_child(Style.make_label(kind.to_upper(), Style.caps(), 11, Style.TRIM)) var t := Style.make_label(title, Style.display(), size, Style.INK) t.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART head.add_child(t) _col.add_child(head) ## A bold label over its control(s), as one group. func _group(label: String, controls: Array) -> void: var g := VBoxContainer.new() g.add_theme_constant_override("separation", 6) g.add_child(Style.make_label(label, Style.body_bold(), 14, Style.INK)) for c: Control in controls: g.add_child(c) _col.add_child(g) func _box_section(box: SheetBox) -> void: _head("Box · %s" % SheetKinds.find(box.kind).get("label", box.kind), box.title if box.title != "" else "Untitled") _group("Title", [_line("Title", box.title, func(text: String) -> void: ed.edit("Rename box", func() -> void: box.title = text, "title:" + box.id, false) ed.canvas.rebuild())]) var frameless := _check("Frameless (no card, sits on the cloth)", box.frameless, func(on: bool) -> void: ed.edit("Box frame", func() -> void: box.frameless = on)) frameless.name = "Frameless" _group("Colour", [ColorChoice.new(box.color, func(hex: String) -> void: ed.edit("Box colour", func() -> void: box.color = hex)), frameless]) var order := SpinBox.new() order.name = "PhoneOrder" order.min_value = 0 order.max_value = 999 order.value = box.phone_order order.custom_minimum_size.x = 80 order.value_changed.connect(func(v: float) -> void: ed.edit("Phone order", func() -> void: box.phone_order = int(v), "order:" + box.id, false)) var order_row := HBoxContainer.new() order_row.add_theme_constant_override("separation", 8) order_row.add_child(order) order_row.add_child(_note("0 = auto: top to bottom, then left to right")) _group("Phone order", [order_row]) if box.kind == SheetKinds.HEADING: _delete_button() return _col.add_child(_divider()) var tables := _switch("Use in tables", "Tables can read and write it", box.var_name != "", func(on: bool) -> void: ed.edit("Use in tables", func() -> void: box.var_name = _var_from(box.title) if on else "")) tables.name = "UseInTables" _col.add_child(tables) if box.var_name != "": _col.add_child(_var_row(box)) var lock := _switch("Lock against rolls", "A table roll can't change it", box.locked, func(on: bool) -> void: ed.edit("Lock box", func() -> void: box.locked = on)) lock.name = "Lock" _col.add_child(lock) _delete_button() func _delete_button() -> void: var delete := ModalCard.make_button("Delete box", "danger") delete.pressed.connect(ed.delete_selected) _col.add_child(delete) ## "Name in tables @[str]" in the reference colours. func _var_row(box: SheetBox) -> HBoxContainer: var row := HBoxContainer.new() row.add_theme_constant_override("separation", 6) row.add_child(Style.make_label("Name in tables", Style.body(), 13, Style.MUTED)) var chip := PanelContainer.new() chip.add_theme_stylebox_override("panel", Style.bordered(Style.box(Style.REF_BG, 6, [6, 0, 2, 0]), 1, Style.REF_INK.lightened(0.4))) var inner := HBoxContainer.new() inner.add_theme_constant_override("separation", 0) chip.add_child(inner) inner.add_child(Style.make_label("@", Style.body_bold(), 14, Style.REF_INK)) var name_edit := LineEdit.new() name_edit.name = "VarName" name_edit.text = box.var_name name_edit.flat = true name_edit.custom_minimum_size.x = 90 name_edit.add_theme_color_override("font_color", Style.REF_INK) name_edit.add_theme_font_override("font", Style.body_bold()) name_edit.text_changed.connect(func(text: String) -> void: ed.edit("Variable name", func() -> void: box.var_name = _var_from(text), "var:" + box.id, false)) inner.add_child(name_edit) row.add_child(chip) return row static func _var_from(text: String) -> String: var name := LibraryStore.slugify(text).replace("-", "_") return name if name != "" else "value" func _sheet_section() -> void: _head("Sheet", ed.doc.name) _col.add_child(_note("Nothing selected. Click a box to edit it, or add one from the field palette.")) _group("Name", [_line("Sheet name", ed.doc.name, func(text: String) -> void: ed.edit("Rename sheet", func() -> void: ed.doc.name = text, "sheetname", false))]) _group("Sheet tint", [_note("Tell sheets apart at a glance, e.g. vehicles vs characters."), ColorChoice.new(ed.doc.tint, func(hex: String) -> void: ed.edit("Sheet tint", func() -> void: ed.doc.tint = hex))]) _group("Snap grid", [_note("%d px. Hold Alt while dragging to place a box freely." % int(SheetKinds.GRID))]) var tpl := ModalCard.make_button("Save as template…", "plain") tpl.pressed.connect(ed.top_bar.save_as_template) _col.add_child(tpl) ## A bold label with a muted line under it and a checkbox at the right. func _switch(title: String, sub: String, on: bool, on_toggle: Callable) -> HBoxContainer: var row := HBoxContainer.new() row.add_theme_constant_override("separation", 8) var text := VBoxContainer.new() text.size_flags_horizontal = SIZE_EXPAND_FILL text.add_theme_constant_override("separation", 0) text.add_child(Style.make_label(title, Style.body_bold(), 14, Style.INK)) text.add_child(Style.make_label(sub, Style.body(), 13, Style.MUTED)) row.add_child(text) var check := CheckBox.new() check.name = "Check" check.button_pressed = on check.toggled.connect(on_toggle) row.add_child(check) return row func _check(text: String, on: bool, on_toggle: Callable) -> CheckBox: var c := CheckBox.new() c.text = text c.button_pressed = on c.add_theme_color_override("font_color", Style.INK) c.add_theme_color_override("font_hover_color", Style.INK) c.add_theme_color_override("font_pressed_color", Style.INK) c.toggled.connect(on_toggle) return c func _note(text: String) -> Label: var l := Style.make_label(text, Style.body(), 13, Style.MUTED) l.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART l.size_flags_horizontal = SIZE_EXPAND_FILL return l func _divider() -> ColorRect: var line := ColorRect.new() line.color = Style.RULE line.custom_minimum_size.y = 1 return line func _line(placeholder: String, text: String, on_change: Callable) -> LineEdit: var e := LineEdit.new() e.placeholder_text = placeholder e.text = text ModalCard.style_line_edit(e) e.text_changed.connect(on_change) return e