2026-11-10 19:02:46 -06:00
|
|
|
class_name PageEditor
|
|
|
|
|
extends VBoxContainer
|
|
|
|
|
## The Book's editor for one Page: its name in the list, the result text (with
|
|
|
|
|
## BBCode and a live preview), the details tooltip and tags. Every change goes
|
|
|
|
|
## to all results linked to the page at once (TowerBoard.sync_page).
|
|
|
|
|
|
|
|
|
|
var m: Main
|
|
|
|
|
var page: BookPage
|
|
|
|
|
var _preview: RichTextLabel
|
|
|
|
|
var _uses: Label
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _init(p_main: Main) -> void:
|
|
|
|
|
m = p_main
|
|
|
|
|
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:
|
2026-11-15 12:46:05 -06:00
|
|
|
add_child(_note("Pick a Lore Entry to edit it, or press + Lore Entry."))
|
2026-11-10 19:02:46 -06:00
|
|
|
return
|
|
|
|
|
var name_edit := _line(p.name, p.label(), func(s: String) -> void: p.name = s.strip_edges())
|
2026-11-15 12:46:05 -06:00
|
|
|
add_child(_field("Name in the Lore Index", name_edit))
|
2026-11-10 19:02:46 -06:00
|
|
|
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))
|
|
|
|
|
_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)
|
|
|
|
|
det.text_changed.connect(func() -> void:
|
|
|
|
|
p.details = det.text
|
|
|
|
|
_changed())
|
|
|
|
|
add_child(_field("Details", det))
|
Pictures on results and Book pages; export/import keeps everything new
A result or page can have a picture (TableEntry.image, BookPage.image),
chosen from a file, shrunk to 512 px and kept in the spread file as WebP
under "images" (BoardImages; only used pictures are saved). It shows as
a thumbnail on the card row and in the details pop-up, and comes with a
page. Imported BBCode still can't point at files.
Fix: the Table Tarot JSON export and import (JsonIO.canonical) dropped
every key it didn't know, losing the Book, pictures, card colours and
sizes, limits, nesting, costs and thread options. They now pass through;
a round-trip test covers them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 19:21:05 -06:00
|
|
|
add_child(_field("Picture", ImageField.new(m, p.image, func(id: String) -> void:
|
|
|
|
|
p.image = id
|
|
|
|
|
_changed())))
|
2026-11-10 19:02:46 -06:00
|
|
|
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()
|
2026-11-15 12:46:05 -06:00
|
|
|
var del := Style.bar_button("Delete Lore Entry")
|
|
|
|
|
del.tooltip_text = "Results using it keep their text and stop following the Lore Entry"
|
2026-11-10 19:02:46 -06:00
|
|
|
del.size_flags_horizontal = SIZE_SHRINK_BEGIN
|
|
|
|
|
del.pressed.connect(func() -> void:
|
|
|
|
|
m.undo_redo._begin_edit()
|
|
|
|
|
m.data.remove_page(p.id)
|
|
|
|
|
m.mark_dirty()
|
|
|
|
|
m.undo_redo._end_edit()
|
|
|
|
|
show_page(null))
|
|
|
|
|
add_child(del)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Copies the page onto its results and redraws their cards.
|
|
|
|
|
func _changed() -> void:
|
|
|
|
|
for tid in m.data.sync_page(page.id):
|
|
|
|
|
m.inspector_edited(tid)
|
|
|
|
|
m.mark_dirty()
|
|
|
|
|
_refresh_uses()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _refresh_uses() -> void:
|
|
|
|
|
var n := m.data.page_uses(page.id)
|
2026-11-15 12:46:05 -06:00
|
|
|
_uses.text = "Used by %d %s. Drag the Lore Entry from the list onto a result to use it there." % [n, "result" if n == 1 else "results"]
|
2026-11-10 19:02:46 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|