UI words only: Book -> Lore Index, Page -> Lore Entry (code keeps book and BookPage). In Build the Inspector and the Lore Index share the dock as two tabs (SideTabs); selecting on the spread goes back to the Inspector. In Play the Lore Index opens alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
113 lines
3.6 KiB
GDScript
113 lines
3.6 KiB
GDScript
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:
|
|
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))
|
|
_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))
|
|
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()
|
|
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:
|
|
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)
|
|
_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"]
|
|
|
|
|
|
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
|