TableTower/ui/sheet_detail_panel.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

176 lines
5.8 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class_name SheetDetailPanel
extends PanelContainer
## The side panel that opens when you click a list entry's ⓘ or a chip: the
## box's name as a caps label, the entry's name, its other columns as small
## tags, and its full details text (editable). A Lore Entry link in a text box
## opens a Lore Entry here instead (open_lore): its name, tags, text and
## details, to read (they are edited in the Lore Index). A row from a Lore
## Entry also gets "Read the Lore Entry" and "Open its sheet" buttons.
## An in-app panel, not a window.
const WIDTH := 340.0
var ed: SheetEditor
var box_id := ""
var index := -1
## The Lore Entry shown (SheetLoreLinks), or "" for a list entry.
var lore_id := ""
var _col: VBoxContainer
func setup(p_editor: SheetEditor) -> void:
ed = p_editor
custom_minimum_size.x = WIDTH
var sb := Style.box(Style.CARD_SOFT, 0, [18, 18, 18, 18])
sb.border_color = Style.DASH
sb.border_width_left = 1
add_theme_stylebox_override("panel", sb)
_col = VBoxContainer.new()
_col.add_theme_constant_override("separation", 12)
add_child(_col)
visible = false
func open(p_box_id: String, p_index: int) -> void:
box_id = p_box_id
index = p_index
lore_id = ""
rebuild()
## Shows the Lore Entry `id` in full.
func open_lore(id: String) -> void:
box_id = ""
index = -1
lore_id = id
rebuild()
func close() -> void:
box_id = ""
index = -1
lore_id = ""
visible = false
func rebuild() -> void:
for c in _col.get_children():
_col.remove_child(c)
c.queue_free()
if lore_id != "":
_show_lore()
return
var box := ed.doc.find_box(box_id) if ed.doc and box_id != "" else null
var rows: Array = box.value if box and box.value is Array else []
if box == null or index < 0 or index >= rows.size():
visible = false
return
visible = true
var entry: Dictionary = rows[index]
var cols := SheetFieldsList.columns(box)
_add_head(box.title, str(entry.get(str(cols[0]["name"]), "")))
var tags := HFlowContainer.new()
tags.add_theme_constant_override("h_separation", 6)
for k in range(1, cols.size()):
var key := str(cols[k]["name"])
if str(entry.get(key, "")) != "":
tags.add_child(_tag("%s %s" % [key, SheetValues.show(entry[key])]))
if tags.get_child_count() > 0:
_col.add_child(tags)
_add_item_links(entry)
_col.add_child(Style.make_label("Details", Style.body_bold(), 14, Style.INK))
var text := TextEdit.new()
text.name = "DetailsText"
text.text = str(entry.get("details", ""))
text.placeholder_text = "What it does, in full. Hovering the entry shows the start of this."
text.wrap_mode = TextEdit.LINE_WRAPPING_BOUNDARY
text.custom_minimum_size.y = 220
text.size_flags_vertical = SIZE_EXPAND_FILL
ModalCard.style_text_edit(text)
var key_box := box
var at := index
text.text_changed.connect(func() -> void:
var next := SheetFieldsList.entries(key_box)
if at < next.size():
next[at]["details"] = text.text
ed.edit_value(key_box, next, ""))
_col.add_child(text)
## A Lore Entry row's ways on: its entry (here) and its item sheet.
func _add_item_links(entry: Dictionary) -> void:
var row := HFlowContainer.new()
row.add_theme_constant_override("h_separation", 6)
if entry.has("lore"):
var read := ModalCard.make_button("Read the Lore Entry", "plain")
read.name = "ReadLore"
read.pressed.connect(open_lore.bind(str(entry["lore"])))
row.add_child(read)
if str(entry.get("sheet", "")) != "":
var sheet := ModalCard.make_button("Open its sheet", "plain")
sheet.name = "OpenSheet"
sheet.pressed.connect(ed.nav.open.bind(str(entry["sheet"])))
row.add_child(sheet)
if row.get_child_count() > 0:
_col.add_child(row)
## The caps label over the name, and the × button.
func _add_head(caption: String, title_text: String) -> void:
var head := HBoxContainer.new()
var names := VBoxContainer.new()
names.size_flags_horizontal = SIZE_EXPAND_FILL
names.add_theme_constant_override("separation", 2)
names.add_child(Style.make_label(caption.to_upper(), Style.caps(), 11, Style.TRIM))
var title := Style.make_label(title_text, Style.display(), 26, Style.INK)
title.name = "Title"
title.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
names.add_child(title)
head.add_child(names)
var close_button := ModalCard.make_button("×", "plain")
close_button.name = "Close"
close_button.tooltip_text = "Close the details"
close_button.pressed.connect(close)
head.add_child(close_button)
_col.add_child(head)
func _show_lore() -> void:
visible = true
var page := SheetLoreLinks.find(ed.m, lore_id)
if page == null:
_add_head("Lore Entry", "A missing Lore Entry")
_col.add_child(_note("This Lore Entry was deleted, or it is in another spread's Lore Index."))
return
_add_head("Lore Entry", page.label())
if page.sheet != "":
var sheet := ModalCard.make_button("Open its sheet", "plain")
sheet.name = "OpenSheet"
sheet.pressed.connect(ed.nav.open.bind(page.sheet))
_col.add_child(sheet)
if not page.tags.is_empty():
var tags := HFlowContainer.new()
tags.add_theme_constant_override("h_separation", 6)
for tag in page.tags:
tags.add_child(_tag(tag))
_col.add_child(tags)
for part: Array in [["LoreText", page.text], ["LoreDetails", page.details]]:
if str(part[1]).strip_edges() == "" or (part[0] == "LoreText" and Formatter.strip_tags(part[1]).strip_edges() == page.label()):
continue
var text := RichText.label(RichText.preview(str(part[1]), ed.m.data), 15, Style.INK, false)
text.name = str(part[0])
_col.add_child(text)
_col.add_child(_note("Edit it in the Lore Index (top bar)."))
func _note(text: String) -> Label:
var label := Style.make_label(text, Style.body(), 13, Style.MUTED)
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
return label
func _tag(text: String) -> PanelContainer:
var p := PanelContainer.new()
p.add_theme_stylebox_override("panel", Style.box(Style.VALUE_BG, 5, [8, 2, 8, 2]))
p.add_child(Style.make_label(text, Style.body_bold(), 13, Style.VALUE_INK))
return p