- E1: Export ▾ (share file with embedded pictures, print/PDF web page, PNG of the tab); Import a sheet file from Sheets and New sheet. - E2: formatting toolbar (FormatMenu) in sheet text boxes; Lore links ([url=lore:ID]) with hover excerpt and the details panel. - E3: Lore Index in Play and in sheets (shared LoreList); This spread | My library; item sheets on Lore Entries; drag entries into lists, slots and notes (copy, Shift keeps linked). - E4: phone stacked view in phone order, Stacked | Canvas switch, 44 px touch sizes, bottom panels; sheet CLI flags split out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
132 lines
4.1 KiB
GDScript
132 lines
4.1 KiB
GDScript
class_name BookPanel
|
||
extends PanelContainer
|
||
## The Lore Index (Book in code) docked beside the spread: its Lore Entries
|
||
## (BookPage) on two levels, This spread and My library (LoreList). In Build
|
||
## it is a tab beside the inspector (SideTabs); in Play it opens on its own.
|
||
## Drag an entry onto a result to link it there, or onto a card to add it as
|
||
## a new result (a My library entry is copied into the spread first).
|
||
## Open from View ▾, ☰ or right-clicking the spread; × closes it.
|
||
|
||
const WIDTH := 340.0
|
||
const SETTING := "book"
|
||
|
||
var m: Main
|
||
## The shared list, search and editor.
|
||
var lore: LoreList
|
||
var list: ItemList
|
||
var editor: PageEditor
|
||
var splitter: PanelSplitter
|
||
var _search: LineEdit
|
||
var _tabs: Control
|
||
|
||
|
||
func setup(p_main: Main) -> void:
|
||
m = p_main
|
||
add_theme_stylebox_override("panel", Style.panel_box([10, 10, 10, 10]))
|
||
var col := VBoxContainer.new()
|
||
col.add_theme_constant_override("separation", 8)
|
||
add_child(col)
|
||
_tabs = SideTabs.make_row(m, SideTabs.LORE)
|
||
col.add_child(_tabs)
|
||
lore = LoreList.new()
|
||
lore.size_flags_vertical = SIZE_EXPAND_FILL
|
||
lore.setup(m, func() -> void: set_shown(false))
|
||
lore.dropped.connect(func(page: BookPage, level: LoreLevel, at: Vector2) -> void: drop_page(page.id, at, level))
|
||
lore.open_sheet = func(id: String) -> void: m.sheet_links.open_sheet(id)
|
||
col.add_child(lore)
|
||
list = lore.list
|
||
editor = lore.editor
|
||
_search = lore.search
|
||
|
||
|
||
## Refills the list (search applied), keeping the selection.
|
||
func refresh() -> void:
|
||
lore.refresh()
|
||
|
||
|
||
## After undo or redo: shows the entry in the editor again.
|
||
func reload_page() -> void:
|
||
lore.reload_page()
|
||
|
||
|
||
func set_width(px: float) -> void:
|
||
custom_minimum_size.x = px
|
||
|
||
|
||
func set_shown(on: bool) -> void:
|
||
visible = on
|
||
if splitter:
|
||
splitter.visible = on
|
||
if m.state:
|
||
m.state.set_setting(SETTING, on)
|
||
m.state.save()
|
||
SideTabs.sync(m)
|
||
|
||
|
||
func toggle() -> void:
|
||
SideTabs.show_tab(m, SideTabs.INSPECTOR if visible else SideTabs.LORE)
|
||
|
||
|
||
## Build shows the Inspector | Lore Index tabs in place of the title.
|
||
func show_tabs(on: bool) -> void:
|
||
_tabs.visible = on
|
||
lore.title.visible = not on
|
||
|
||
|
||
func new_page() -> BookPage:
|
||
if not visible:
|
||
set_shown(true)
|
||
return lore.new_page()
|
||
|
||
|
||
## Adds a result's text and details to the spread's Lore Index and links the result to it.
|
||
func save_result(t: RollTable, e: TableEntry) -> BookPage:
|
||
# Lambdas copy local variables, so the page comes back in an Array.
|
||
var made: Array[BookPage] = []
|
||
lore.levels[LoreLevel.SPREAD].edit(func() -> void:
|
||
var added := m.data.add_page(e.text, e.details)
|
||
added.image = e.image
|
||
e.page = added.id
|
||
m.inspector_edited(t.id)
|
||
made.append(added))
|
||
var p := made[0]
|
||
set_shown(true)
|
||
lore.set_level(LoreLevel.SPREAD)
|
||
select_page(p.id)
|
||
m.toast("Saved “%s” to the Lore Index" % p.label())
|
||
return p
|
||
|
||
|
||
func select_page(pid: String) -> void:
|
||
if lore.level.key != LoreLevel.SPREAD and m.data.get_page(pid):
|
||
lore.set_level(LoreLevel.SPREAD)
|
||
lore.select_page(pid)
|
||
|
||
|
||
## Drops an entry at a screen point: onto a result links it there; onto a card
|
||
## (not a result) adds it as a new result. An entry from `from_level` My
|
||
## library is copied into the spread first (one undo step). True when it landed.
|
||
func drop_page(pid: String, at: Vector2, from_level: LoreLevel = null) -> bool:
|
||
for c: TableCard in m.cards.values():
|
||
if not c.is_visible_in_tree() or not c.get_global_rect().has_point(at) or c.table.kind == RollTable.KIND_VARIABLE:
|
||
continue
|
||
var linked := pid
|
||
m.undo_redo._begin_edit()
|
||
if from_level and from_level.key == LoreLevel.LIBRARY:
|
||
linked = lore.levels[LoreLevel.SPREAD].copy_raw(from_level.get_page(pid)).id
|
||
var target: TableEntry = null
|
||
for eid: String in c.rows:
|
||
var row: Control = c.rows[eid]
|
||
if is_instance_valid(row) and row.get_global_rect().has_point(at):
|
||
target = c.table.find_entry(eid)
|
||
if target == null:
|
||
m.editing.add_entry(c.table.id)
|
||
target = c.table.entries[c.table.entries.size() - 1]
|
||
m.data.link_page(target, linked)
|
||
m.inspector_edited(c.table.id)
|
||
m.mark_dirty()
|
||
m.undo_redo._end_edit()
|
||
m.toast("“%s” now shows on %s" % [m.data.get_page(linked).label(), Formatter.strip_tags(c.table.name)])
|
||
return true
|
||
return false
|
||
|