TableTower/ui/sheet_item_nav.gd
RobinFiredrake 317cac7a78 Sheets phase E: export/import, text toolbar and Lore links, Lore library and items, phone view
- 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>
2026-11-29 17:25:09 -06:00

65 lines
1.8 KiB
GDScript

class_name SheetItemNav
extends RefCounted
## Going into an item sheet and back: opening a row's or a Lore Entry's sheet
## from the sheet editor remembers the sheet you were on; the top bar's
## back button ("← Brin Hollowmere") returns there, and past the first
## sheet to the spread it was opened from.
var ed: SheetEditor
## The sheets to go back to, last on top: {id, name, spread}.
var _stack: Array[Dictionary] = []
func _init(p_editor: SheetEditor) -> void:
ed = p_editor
func clear() -> void:
_stack.clear()
func can_go_back() -> bool:
return not _stack.is_empty()
## The back button's words, or "" when there is nowhere to go back to.
func back_label() -> String:
if can_go_back():
return "← %s" % str(_stack.back()["name"])
return "← %s" % ed.from_spread if ed.from_spread != "" else ""
## Opens sheet `id`, keeping the open one to come back to.
func open(id: String) -> void:
var doc := ed.screen.store.load_sheet(id) if id != "" else null
if doc == null:
ed.m.toast("That sheet is gone.")
return
var stack := _stack.duplicate()
stack.append({"id": ed.doc.id, "name": ed.doc.name, "spread": ed.from_spread})
_show(doc, stack, ed.from_spread)
## Back to the sheet before, or to the spread past the first one.
func back() -> void:
if not can_go_back():
ed.back_to_spread()
return
var stack := _stack.duplicate()
var last: Dictionary = stack.pop_back()
var doc := ed.screen.store.load_sheet(str(last["id"]))
if doc == null:
ed.m.toast("That sheet is gone.")
_stack = stack
ed.top_bar.sync()
return
_show(doc, stack, str(last["spread"]))
func _show(doc: SheetDoc, stack: Array[Dictionary], spread: String) -> void:
var keep_mode := ed.mode
ed.save_now()
ed.open(doc)
_stack = stack
ed.from_spread = spread
ed.set_mode(keep_mode)