class_name PageEditor extends VBoxContainer ## The Lore Index's editor for one Lore Entry (BookPage): its name in the ## list, the result text (with BBCode and a live preview), the details ## tooltip, picture (spread only) and tags, then LoreEntryActions (copy to the ## other level, item sheet). Changes go through the list's level (LoreLevel): ## for the spread, to all results linked to the entry at once (TowerBoard.sync_page). var m: Main var lore: LoreList var page: BookPage var _preview: RichTextLabel var _uses: Label func _init(p_lore: LoreList) -> void: lore = p_lore m = p_lore.m add_theme_constant_override("separation", 8) func show_page(p: BookPage) -> void: page = p for c in get_children(): c.queue_free() if p == null: add_child(_note("Pick a Lore Entry to edit it, or press + Lore Entry.")) return var name_edit := _line(p.name, p.label(), func(s: String) -> void: p.name = s.strip_edges()) add_child(_field("Name in the Lore Index", name_edit)) var text := TextEdit.new() text.text = p.text text.placeholder_text = "The result, e.g. [b][color=gold]The Sword of Holy Light[/color][/b]" text.wrap_mode = TextEdit.LINE_WRAPPING_BOUNDARY text.custom_minimum_size = Vector2(0, 70) ModalCard.style_text_edit(text) text.text_changed.connect(func() -> void: p.text = text.text _preview.text = RichText.decorate(p.text) _changed()) add_child(_field("Result text", text)) SpellUnderline.attach(text, m) _preview = RichText.label(RichText.decorate(p.text), 16, Style.INK, false, true) var pv := PanelContainer.new() pv.add_theme_stylebox_override("panel", Style.box(Style.CARD, 6, [10, 6, 10, 6])) pv.add_child(_preview) add_child(pv) var det := TextEdit.new() det.text = p.details det.placeholder_text = "Shown when the result is hovered (optional)" det.wrap_mode = TextEdit.LINE_WRAPPING_BOUNDARY det.custom_minimum_size = Vector2(0, 60) ModalCard.style_text_edit(det) SpellUnderline.attach(det, m) det.text_changed.connect(func() -> void: p.details = det.text _changed()) add_child(_field("Details", det)) if lore.level.key == LoreLevel.SPREAD: add_child(_field("Picture", ImageField.new(m, p.image, func(id: String) -> void: p.image = id _changed()))) var tags := _line(", ".join(p.tags), "e.g. weapon, holy", func(s: String) -> void: var list: Array[String] = [] for t in s.split(","): if t.strip_edges() != "": list.append(t.strip_edges()) p.tags = list) add_child(_field("Tags", tags)) _uses = _note("") add_child(_uses) _refresh_uses() add_child(LoreEntryActions.make(lore, p)) var del := Style.bar_button("Delete Lore Entry") del.tooltip_text = "Results using it keep their text and stop following the Lore Entry" del.size_flags_horizontal = SIZE_SHRINK_BEGIN del.pressed.connect(func() -> void: lore.level.remove_page(p.id) show_page(null) lore.refresh()) add_child(del) ## Keeps the change (for the spread: onto its results, redrawing their cards). func _changed() -> void: lore.level.changed(page) _refresh_uses() func _refresh_uses() -> void: _uses.text = lore.level.uses_note(page) func _line(text: String, placeholder: String, on_change: Callable) -> LineEdit: var le := LineEdit.new() le.text = text le.placeholder_text = placeholder ModalCard.style_line_edit(le) le.text_changed.connect(func(s: String) -> void: on_change.call(s) _changed()) return le static func _field(heading: String, c: Control) -> Control: var v := VBoxContainer.new() v.add_theme_constant_override("separation", 3) v.add_child(Style.make_label(heading.to_upper(), Style.caps(), 11, Style.ON_BG_MUTED)) v.add_child(c) return v static func _note(text: String) -> Label: var l := Style.make_label(text, Style.body(), 13, Style.ON_BG_MUTED) l.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART return l