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>
This commit is contained in:
parent
5941733af1
commit
317cac7a78
72 changed files with 2305 additions and 309 deletions
|
|
@ -13,6 +13,9 @@ var details: String = ""
|
|||
var tags: Array[String] = []
|
||||
## A picture (BoardImages id). "" = none.
|
||||
var image: String = ""
|
||||
## Its item sheet (a SheetStore sheet id, e.g. a sword's Damage and Charges).
|
||||
## "" = none. Saved as "sheet".
|
||||
var sheet: String = ""
|
||||
|
||||
|
||||
func label() -> String:
|
||||
|
|
@ -29,6 +32,8 @@ func to_dict() -> Dictionary:
|
|||
d["tags"] = tags.duplicate()
|
||||
if image != "":
|
||||
d["image"] = image
|
||||
if sheet != "":
|
||||
d["sheet"] = sheet
|
||||
return d
|
||||
|
||||
|
||||
|
|
@ -39,6 +44,12 @@ static func from_dict(d: Dictionary) -> BookPage:
|
|||
p.text = str(d.get("text", ""))
|
||||
p.details = str(d.get("details", ""))
|
||||
p.image = str(d.get("image", ""))
|
||||
p.sheet = str(d.get("sheet", ""))
|
||||
for t: Variant in d.get("tags", []):
|
||||
p.tags.append(str(t))
|
||||
return p
|
||||
|
||||
|
||||
## A copy with the same fields (the caller gives it a new id).
|
||||
func copy() -> BookPage:
|
||||
return BookPage.from_dict(to_dict())
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ const IMPORT_ALLOWED_TAGS: Array[String] = [
|
|||
]
|
||||
|
||||
## url parameters with these prefixes are TextExpander's internal markers.
|
||||
const INTERNAL_META_PREFIXES: Array[String] = ["table:", "var:", "missing:", "unset:", "deep:", "error:"]
|
||||
## "lore:" is a link to a Lore Entry (SheetLoreLinks): it means nothing outside the app.
|
||||
const INTERNAL_META_PREFIXES: Array[String] = ["table:", "var:", "missing:", "unset:", "deep:", "error:", "lore:"]
|
||||
|
||||
## Matches one tag: [name], [/name], [name=param] or [name key=value ...].
|
||||
## Parameters may contain quoted strings, so [url={"a":1}] is one tag.
|
||||
|
|
|
|||
77
core/lore_library.gd
Normal file
77
core/lore_library.gd
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
class_name LoreLibrary
|
||||
extends RefCounted
|
||||
## "My library": the shared Lore Index level, kept outside every spread in
|
||||
## <root>/lore_library.json ({"book": [BookPage dicts]}). Any spread and any
|
||||
## sheet can use its Lore Entries. Links to it in sheet text say so:
|
||||
## [url=lore:lib:ID] (SheetLoreLinks). There is no undo here; every change is
|
||||
## saved at once (save()).
|
||||
|
||||
const FILE := "lore_library.json"
|
||||
|
||||
var root := "user://"
|
||||
var pages: Array[BookPage] = []
|
||||
## Goes up on every change, so open lists know to refresh.
|
||||
var revision := 0
|
||||
|
||||
|
||||
func _init(p_root: String = "user://") -> void:
|
||||
root = p_root
|
||||
load_file()
|
||||
|
||||
|
||||
func path() -> String:
|
||||
return root.path_join(FILE)
|
||||
|
||||
|
||||
func load_file() -> void:
|
||||
pages.clear()
|
||||
if not FileAccess.file_exists(path()):
|
||||
return
|
||||
var parsed: Variant = JSON.parse_string(FileAccess.get_file_as_string(path()))
|
||||
if parsed is Dictionary and parsed.get("book") is Array:
|
||||
for v: Variant in parsed["book"]:
|
||||
if v is Dictionary:
|
||||
var page := BookPage.from_dict(v)
|
||||
if page.id == "":
|
||||
page.id = TowerBoard.new_id("lib")
|
||||
pages.append(page)
|
||||
|
||||
|
||||
func save() -> Error:
|
||||
revision += 1
|
||||
DirAccess.make_dir_recursive_absolute(root)
|
||||
var list: Array = []
|
||||
for page in pages:
|
||||
list.append(page.to_dict())
|
||||
return BoardFileIO.write_text_atomic(path(), JSON.stringify({"book": list}, "\t"))
|
||||
|
||||
|
||||
func get_page(id: String) -> BookPage:
|
||||
for page in pages:
|
||||
if page.id == id:
|
||||
return page
|
||||
return null
|
||||
|
||||
|
||||
func add_page(text: String, details: String = "") -> BookPage:
|
||||
var page := BookPage.new()
|
||||
page.id = TowerBoard.new_id("lib")
|
||||
page.text = text
|
||||
page.details = details
|
||||
pages.append(page)
|
||||
save()
|
||||
return page
|
||||
|
||||
|
||||
## Adds a copy of `page` (a new id) and returns it.
|
||||
func add_copy(page: BookPage) -> BookPage:
|
||||
var added := page.copy()
|
||||
added.id = TowerBoard.new_id("lib")
|
||||
pages.append(added)
|
||||
save()
|
||||
return added
|
||||
|
||||
|
||||
func remove_page(id: String) -> void:
|
||||
pages = pages.filter(func(page: BookPage) -> bool: return page.id != id)
|
||||
save()
|
||||
1
core/lore_library.gd.uid
Normal file
1
core/lore_library.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cftrxlns3sxb5
|
||||
|
|
@ -58,9 +58,4 @@ static func create(id: String = "demo-brin") -> SheetDoc:
|
|||
|
||||
|
||||
static func _add(doc: SheetDoc, boxes: Array, item_id: String, title: String, gx: int, gy: int, gw: int, gh: int) -> SheetBox:
|
||||
var b := SheetKinds.make_box(item_id, doc.new_box_id(), Vector2(gx, gy) * SheetKinds.GRID)
|
||||
b.title = title
|
||||
b.w = gw * SheetKinds.GRID
|
||||
b.h = gh * SheetKinds.GRID
|
||||
boxes.append(b)
|
||||
return b
|
||||
return SheetKinds.place(doc, boxes, item_id, title, Rect2i(gx, gy, gw, gh))
|
||||
|
|
|
|||
71
core/sheet_file.gd
Normal file
71
core/sheet_file.gd
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
class_name SheetFile
|
||||
extends RefCounted
|
||||
## A share file: one sheet as JSON that someone else can import into their
|
||||
## app. Pictures in picture boxes travel inside it (base64 under "pictures",
|
||||
## keyed by file name), so the receiver sees them too.
|
||||
## Form: {"tabletarot_sheet": 1, "sheet": SheetDoc.to_dict(), "pictures": {name: base64}}.
|
||||
|
||||
const FORMAT_KEY := "tabletarot_sheet"
|
||||
const FORMAT_VERSION := 1
|
||||
const EXTENSION := "sheet.json"
|
||||
const FILTER := "*.sheet.json, *.json ; Sheet file"
|
||||
|
||||
|
||||
## The share file's text for `doc`.
|
||||
static func share_text(doc: SheetDoc) -> String:
|
||||
var pictures := {}
|
||||
for tab in doc.tabs:
|
||||
for box: SheetBox in tab["boxes"]:
|
||||
var path := _picture_path(box)
|
||||
if path == "" or pictures.has(path.get_file()):
|
||||
continue
|
||||
var bytes := FileAccess.get_file_as_bytes(path)
|
||||
if not bytes.is_empty():
|
||||
pictures[path.get_file()] = Marshalls.raw_to_base64(bytes)
|
||||
var sheet := doc.to_dict()
|
||||
sheet.erase("from_template") # the receiver doesn't have our templates
|
||||
return JSON.stringify({FORMAT_KEY: FORMAT_VERSION, "sheet": sheet, "pictures": pictures}, "\t")
|
||||
|
||||
|
||||
## Reads share-file `text` into `store` as a new sheet (or a template) with a
|
||||
## fresh id, saved, with its pictures written back. Null if it isn't one.
|
||||
static func import_text(store: SheetStore, text: String, templates: bool = false) -> SheetDoc:
|
||||
var parsed: Variant = JSON.parse_string(text)
|
||||
if not parsed is Dictionary or not (parsed as Dictionary).get("sheet") is Dictionary:
|
||||
return null
|
||||
var data: Dictionary = parsed
|
||||
var doc := SheetDoc.from_dict(data["sheet"])
|
||||
doc.from_template = ""
|
||||
var pictures: Variant = data.get("pictures", {})
|
||||
var kept := {} # file name in the share file -> path in this store
|
||||
if pictures is Dictionary:
|
||||
for file_name: String in pictures:
|
||||
var bytes := Marshalls.base64_to_raw(str(pictures[file_name]))
|
||||
kept[file_name] = store.keep_picture_bytes(bytes, file_name.get_extension())
|
||||
for tab in doc.tabs:
|
||||
for box: SheetBox in tab["boxes"]:
|
||||
var path := _picture_path(box)
|
||||
if path != "":
|
||||
box.value = str(kept.get(path.get_file(), ""))
|
||||
doc.id = store.free_id(doc.name, templates)
|
||||
if store.save(doc, templates) != OK:
|
||||
return null
|
||||
return doc
|
||||
|
||||
|
||||
static func import_path(store: SheetStore, path: String, templates: bool = false) -> SheetDoc:
|
||||
if not FileAccess.file_exists(path):
|
||||
return null
|
||||
return import_text(store, FileAccess.get_file_as_string(path), templates)
|
||||
|
||||
|
||||
## A file name for sharing `doc` ("brin-hollowmere.sheet.json").
|
||||
static func file_name(doc: SheetDoc) -> String:
|
||||
var slug := LibraryStore.slugify(doc.name)
|
||||
return "%s.%s" % [slug if slug != "" else "sheet", EXTENSION]
|
||||
|
||||
|
||||
static func _picture_path(box: SheetBox) -> String:
|
||||
if box.kind != SheetKinds.PICTURE or not box.value is String:
|
||||
return ""
|
||||
return str(box.value)
|
||||
1
core/sheet_file.gd.uid
Normal file
1
core/sheet_file.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://djngvnq5jin4i
|
||||
60
core/sheet_items.gd
Normal file
60
core/sheet_items.gd
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
class_name SheetItems
|
||||
extends RefCounted
|
||||
## Item sheets: a Lore Entry (BookPage) can carry a small sheet of its own,
|
||||
## e.g. the Ashen Blade with Damage, Charges and Notes (BookPage.sheet holds
|
||||
## its SheetStore id). Dropped into a sheet box, an entry becomes a row or an
|
||||
## item; a copy gets its own copy of the item sheet (copy_sheet), a linked one
|
||||
## (Shift) points at the entry's sheet. The rows' keys: "lore" (a link ref,
|
||||
## SheetLoreLinks) and "sheet" (a sheet id).
|
||||
|
||||
|
||||
## A new item sheet for `page`, saved in `store`; the page now links to it.
|
||||
static func make_sheet(store: SheetStore, page: BookPage) -> SheetDoc:
|
||||
var name := Formatter.strip_tags(page.label()).strip_edges()
|
||||
var doc := SheetDoc.new("", name if name != "" else "Item")
|
||||
var boxes: Array = doc.tabs[0]["boxes"]
|
||||
SheetKinds.place(doc, boxes, SheetKinds.HEADING, doc.name, Rect2i(1, 1, 24, 3)).frameless = true
|
||||
SheetKinds.place(doc, boxes, SheetKinds.SHORT_TEXT, "Damage", Rect2i(1, 5, 11, 4))
|
||||
SheetKinds.place(doc, boxes, SheetKinds.NUMBER, "Charges", Rect2i(13, 5, 8, 5))
|
||||
var notes := SheetKinds.place(doc, boxes, SheetKinds.TEXT, "Notes", Rect2i(1, 11, 24, 8))
|
||||
notes.value = (page.text + "\n\n" + page.details).strip_edges()
|
||||
doc.id = store.free_id(doc.name)
|
||||
store.save(doc)
|
||||
page.sheet = doc.id
|
||||
return doc
|
||||
|
||||
|
||||
## Saves a copy of sheet `id` under a new id; returns it ("" when `id` is gone).
|
||||
static func copy_sheet(store: SheetStore, id: String) -> String:
|
||||
var doc := store.load_sheet(id) if id != "" else null
|
||||
if doc == null:
|
||||
return ""
|
||||
var copied := doc.copy()
|
||||
copied.id = store.free_id(doc.name)
|
||||
store.save(copied)
|
||||
return copied.id
|
||||
|
||||
|
||||
## The row or item a dropped entry becomes. `fields` holds the box's own
|
||||
## keys (name, details or size); "lore" and "sheet" are added here.
|
||||
static func with_links(fields: Dictionary, page: BookPage, ref: String, linked: bool, store: SheetStore) -> Dictionary:
|
||||
var out := fields.duplicate()
|
||||
if linked:
|
||||
out["lore"] = ref
|
||||
if page.sheet != "":
|
||||
out["sheet"] = page.sheet
|
||||
elif page.sheet != "":
|
||||
var copied := copy_sheet(store, page.sheet)
|
||||
if copied != "":
|
||||
out["sheet"] = copied
|
||||
return out
|
||||
|
||||
|
||||
## The entry's text and details without formatting, for a row's details.
|
||||
static func plain_text(page: BookPage) -> String:
|
||||
var parts := PackedStringArray()
|
||||
for part in [page.text, page.details]:
|
||||
var plain := Formatter.strip_tags(part).strip_edges()
|
||||
if plain != "" and plain != Formatter.strip_tags(page.label()).strip_edges():
|
||||
parts.append(plain)
|
||||
return "\n\n".join(parts)
|
||||
1
core/sheet_items.gd.uid
Normal file
1
core/sheet_items.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cnh0colx35f3s
|
||||
|
|
@ -170,6 +170,17 @@ static func make_box(item_id: String, id: String, at: Vector2) -> SheetBox:
|
|||
return box
|
||||
|
||||
|
||||
## Adds a box from palette item `item_id` to `boxes` of `doc`, placed on the
|
||||
## grid by `cells` (x, y, width, height in grid steps), and returns it.
|
||||
static func place(doc: SheetDoc, boxes: Array, item_id: String, title: String, cells: Rect2i) -> SheetBox:
|
||||
var box := make_box(item_id, doc.new_box_id(), Vector2(cells.position) * GRID)
|
||||
box.title = title
|
||||
box.w = cells.size.x * GRID
|
||||
box.h = cells.size.y * GRID
|
||||
boxes.append(box)
|
||||
return box
|
||||
|
||||
|
||||
## Rounds to the nearest grid step.
|
||||
static func snap(v: float) -> float:
|
||||
return roundf(v / GRID) * GRID
|
||||
|
|
|
|||
|
|
@ -81,19 +81,27 @@ func free_id(name: String, templates: bool = false) -> String:
|
|||
## Copies a picture into the sheets' pictures folder (so the sheet keeps it
|
||||
## if the original moves) and returns the copy's path ("" if unreadable).
|
||||
func keep_picture(path: String) -> String:
|
||||
var bytes := FileAccess.get_file_as_bytes(path)
|
||||
return keep_picture_bytes(FileAccess.get_file_as_bytes(path), path.get_extension())
|
||||
|
||||
|
||||
## Saves picture `bytes` in the pictures folder, named by their hash (the
|
||||
## same picture is kept once); returns its path ("" if it can't).
|
||||
func keep_picture_bytes(bytes: PackedByteArray, extension: String) -> String:
|
||||
if bytes.is_empty():
|
||||
return ""
|
||||
var dir := dir_for(false).path_join("pictures")
|
||||
DirAccess.make_dir_recursive_absolute(dir)
|
||||
var kept := dir.path_join("%s.%s" % [str(hash(bytes)).replace("-", "n"), path.get_extension().to_lower()])
|
||||
var f := FileAccess.open(kept, FileAccess.WRITE)
|
||||
if f == null:
|
||||
DirAccess.make_dir_recursive_absolute(pictures_dir())
|
||||
var kept := pictures_dir().path_join("%s.%s" % [str(hash(bytes)).replace("-", "n"), extension.to_lower()])
|
||||
var file := FileAccess.open(kept, FileAccess.WRITE)
|
||||
if file == null:
|
||||
return ""
|
||||
f.store_buffer(bytes)
|
||||
file.store_buffer(bytes)
|
||||
return kept
|
||||
|
||||
|
||||
func pictures_dir() -> String:
|
||||
return dir_for(false).path_join("pictures")
|
||||
|
||||
|
||||
## A new sheet, blank or copied from a template, saved and returned.
|
||||
func create(name: String, template_id: String = "") -> SheetDoc:
|
||||
var doc: SheetDoc = null
|
||||
|
|
|
|||
|
|
@ -10,16 +10,27 @@ extends RefCounted
|
|||
static func summary(doc: SheetDoc, prefix: String = "") -> String:
|
||||
var lines: Array[String] = []
|
||||
for tab in doc.tabs:
|
||||
var boxes: Array = (tab["boxes"] as Array).duplicate()
|
||||
boxes.sort_custom(func(a: SheetBox, b: SheetBox) -> bool: return a.y < b.y or (a.y == b.y and a.x < b.x))
|
||||
for box: SheetBox in boxes:
|
||||
var line := _line(doc, box, prefix)
|
||||
if line != "":
|
||||
lines.append(line)
|
||||
var text := tab_text(doc, tab, prefix)
|
||||
if text != "":
|
||||
lines.append(text)
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
static func _line(doc: SheetDoc, box: SheetBox, prefix: String) -> String:
|
||||
## One tab's boxes in reading order (top-down, then left-right). With
|
||||
## `placeholders` off, boxes used in tables show their values instead of
|
||||
## {@name} (the sheet's own print-out).
|
||||
static func tab_text(doc: SheetDoc, tab: Dictionary, prefix: String = "", placeholders: bool = true) -> String:
|
||||
var lines: Array[String] = []
|
||||
var boxes: Array = (tab["boxes"] as Array).duplicate()
|
||||
boxes.sort_custom(func(a: SheetBox, b: SheetBox) -> bool: return a.y < b.y or (a.y == b.y and a.x < b.x))
|
||||
for box: SheetBox in boxes:
|
||||
var line := _line(doc, box, prefix, placeholders)
|
||||
if line != "":
|
||||
lines.append(line)
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
static func _line(doc: SheetDoc, box: SheetBox, prefix: String, placeholders: bool) -> String:
|
||||
match box.kind:
|
||||
SheetKinds.HEADING:
|
||||
return "[b]%s[/b]" % box.title
|
||||
|
|
@ -31,7 +42,7 @@ static func _line(doc: SheetDoc, box: SheetBox, prefix: String) -> String:
|
|||
return ""
|
||||
return text if box.title == "" else "[b]%s:[/b] %s" % [box.title, text]
|
||||
var shown := ""
|
||||
if box.var_name != "" and SheetLinks.WRITABLE.has(box.kind):
|
||||
if placeholders and box.var_name != "" and SheetLinks.WRITABLE.has(box.kind):
|
||||
shown = "{@%s}" % (box.var_name if prefix == "" else "%s_%s" % [prefix, box.var_name])
|
||||
else:
|
||||
shown = _value(doc, box)
|
||||
|
|
|
|||
|
|
@ -159,7 +159,8 @@ templates/ built-in templates · examples/logic_demo.json (original demo board)
|
|||
`ui/card_catalog.gd` (every card kind: one list for the palette, right-click › New card and
|
||||
new-card names; variants "dice" and "deck"). `SideTabs.tab_row` is the shared dock tab style.
|
||||
- **Lists and phones:** `ui/list_view.gd`, `ui/list_tree.gd`, `ui/list_order.gd`,
|
||||
`ui/mobile_layout.gd`, `ui/touch_input.gd`.
|
||||
`ui/mobile_layout.gd`, `ui/touch_input.gd`; sheets on phones: `ui/sheet_phone_layout.gd`,
|
||||
`ui/sheet_stack_view.gd` (SHEETS.md E4).
|
||||
- **Book and pictures:** `core/book_page.gd`, `core/board_images.gd`, `ui/book_panel.gd`,
|
||||
`ui/page_editor.gd`, `ui/image_field.gd`. `TowerBoard` has `book`, `images`, nesting helpers
|
||||
(`tables_in`, `groups_in`, `hidden_by`, `set_group_parent`).
|
||||
|
|
@ -246,6 +247,9 @@ Each original file keeps one-line delegators, so callers are unchanged.
|
|||
open ones build; `activate` points `selection`/`fields`/`effects` at the section clicked in),
|
||||
`ui/inspector_range.gd` (a result's weight, range and position).
|
||||
- **Dock tabs:** `ui/side_tabs.gd` (Build: Inspector | Lore Index; `BookPanel` is the Lore Index).
|
||||
- **Lore Index (2026-11-29, E3):** `ui/lore_list.gd` (the shared list + `PageEditor`, used by `BookPanel` on the
|
||||
spread and `SheetLoreDock` in the sheet editor), levels `ui/lore_level.gd` (+ `_spread`, `_library`),
|
||||
`core/lore_library.gd` (My library file), `ui/lore_entry_actions.gd` (Copy to…, item sheet).
|
||||
- **Rolling:** `ui/skip_animations.gd` (View ▾ setting); `ModalCard.animate_in` (pop-up entrance).
|
||||
- **Look:** `ui/card_move_handle.gd` (Build grip on the header; `CardGrip` is the resize corner);
|
||||
theme tokens `SELECTED` and `CARD_HEAD` (derived from CARD/CARD_SHADE when a theme omits it).
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ an old sheet card becomes a sheet with one text box.
|
|||
(rule language with sheet @names; loops are errors). Views: `ui/sheet_field_views.gd` (basics,
|
||||
dispatch), `sheet_fields_trackers/smart/list/niche.gd`; settings: `ui/sheet_kind_settings.gd`;
|
||||
details side panel: `ui/sheet_detail_panel.gd`. Pictures are copied to `sheets/pictures/`.
|
||||
Not yet: per-entry variables in lists (phase D), BBCode buttons and Lore links in text (E).
|
||||
Not yet: per-entry variables in lists (phase D), BBCode buttons and Lore links in text (done in E2).
|
||||
- **D. Sheets on spreads** — built 2026-11-29: a sheet on a spread is a **Sheet card** linked to a
|
||||
sheet file (`RollTable.sheet_id`, `sheet_prefix`; JSON `sheet`, `prefix`), so threads, groups, undo,
|
||||
List view and the tray headline work as for any card. The card shows `SheetPreview` (first tab,
|
||||
|
|
@ -76,6 +76,57 @@ an old sheet card becomes a sheet with one text box.
|
|||
Card palette › Sheets: "New sheet" + your sheets. Sheet canvas: grid is one tiled texture (smooth
|
||||
panning); boxes don't overlap (new ones take the nearest free spot, drags stop short; Alt = free).
|
||||
- **E. Lore Index library + items, export (PDF, PNG, share file), phone stacked view.**
|
||||
- **E1. Export and import** — built 2026-11-29: sheet top bar **Export ▾** (Play and Build):
|
||||
"Share file…" (`*.sheet.json`: `{"tabletarot_sheet": 1, "sheet", "pictures"}`, picture boxes'
|
||||
files inside as base64; no template link), "Print / PDF (web page)…" (Godot has no PDF writer:
|
||||
an HTML page, one `<section>` per tab printed on its own page, boxes as "Title: value" lines
|
||||
from `SheetText.tab_text` with values, through the tray's `SheetExport.to_html`), "Image
|
||||
(PNG)…" (the window's pixels under the canvas: this tab as you see it). **Import…** on the
|
||||
Sheets list and "Import a sheet file…" in the New sheet dialog: a new id, pictures written to
|
||||
`sheets/pictures/`, saved and opened (from the card palette: placed on the spread).
|
||||
- **E2. Text tools and Lore links** — built 2026-11-29: editing a Long notes box (Play) shows
|
||||
`SheetTextToolbar` above it: B I U S, Colour ▾ / Size ▾ / Effect ▾ (the tags of `FormatMenu`,
|
||||
which the TextEdit also gets as its right-click menu), {@} ▾ (the sheet's @names as live
|
||||
values) and "§ Link…" (Link a Lore Entry…, `LoreLinkPicker` with search). **Link syntax:**
|
||||
plain BBCode `[url=lore:ENTRY_ID]words[/url]` (no selection: the entry's name is added).
|
||||
`RichText.decorate` draws it in REF_INK on REF_BG; hover (`DetailsPopup` "lore:") shows the
|
||||
name and an excerpt cut with "…"; a click opens it in the side panel
|
||||
(`SheetDetailPanel.open_lore`, read only). "lore:" is an internal meta (Copy as BBCode drops
|
||||
the link, keeps the words). Which Lore Index: the open spread's, even for a sheet not on a
|
||||
spread; the one lookup is `SheetLoreLinks.entries` (E3 adds "My library" there).
|
||||
- **E3. Lore Index everywhere, My library, sheet items** — built 2026-11-29: the Lore Index
|
||||
panel is `LoreList` (title, + Lore Entry, ×, **This spread | My library** tabs, search, list,
|
||||
`PageEditor`), shown by `BookPanel` (spread, Play and Build) and `SheetLoreDock` (sheet editor:
|
||||
the inspector's Lore tab in Build, top bar **Lore Index** toggle in both modes). Levels are
|
||||
`LoreLevel` objects (`SpreadLoreLevel`: spread undo, `sync_page`; `LibraryLoreLevel`: saved at
|
||||
once, no undo). **My library** is `LoreLibrary`, `<store root>/lore_library.json`
|
||||
(`{"book": [BookPage dicts]}`; user:// when saving, the sheets' scratch folder otherwise).
|
||||
**Link refs:** `lore:ID` = this spread, `lore:lib:ID` = My library (`SheetLoreLinks.ref/find`).
|
||||
Under an entry: "Copy to My library / This spread" (a new id; its item sheet copied; pictures only
|
||||
stay in the spread) and "Make a sheet for this entry" / "Open its sheet": `BookPage.sheet` (JSON
|
||||
`sheet`, a SheetStore id) → `SheetItems.make_sheet` (Heading, Damage, Charges, Notes). A library
|
||||
entry dropped on a spread card is copied into the spread first. **Drops into a sheet**
|
||||
(`SheetLoreDrop`, one `set_value` undo step): list box → a row (first column = name, `details` =
|
||||
plain text), Slots → an item `{name, size: 1}`, Long notes → a link appended. A drop copies (the
|
||||
item sheet too, `SheetItems.copy_sheet`); Shift links: `lore` = ref and `sheet` = the entry's own
|
||||
sheet. Marks: § before a linked row/item, ▤ opens a row's sheet (Slots: the item's menu); ⓘ on such
|
||||
a row has "Read the Lore Entry" / "Open its sheet". Opening a sheet from a sheet uses `SheetItemNav`
|
||||
("← previous sheet", then back to the spread). A linked row keeps its own copy of the text (it
|
||||
doesn't follow later edits of the entry); deleting an entry leaves its item sheet in Sheets.
|
||||
- **E4. Phones and tablets** — built 2026-11-29: in the phone layout (`MobileLayout`, also
|
||||
`--mobile`) the sheet editor uses `SheetPhoneLayout`. Play shows the **stacked view**
|
||||
(`SheetStackView`): the open tab's boxes in one full-width column, each the same `SheetBoxView`
|
||||
at its own height or taller if its content needs it. **Phone order rule** (`SheetStackView.order_of`):
|
||||
boxes with a Phone order number (> 0) come first, smallest first; then the automatic ones (0) in
|
||||
reading order (y, then x); equal numbers also fall back to reading order. Touch size: while the
|
||||
stack builds a box, `SheetFieldViews.touch` is on and `tap_size` grows step buttons, ticks, dots and
|
||||
slot cells to 44 px (no second set of views). A **bottom bar** replaces the status strip: Undo,
|
||||
**Stacked | Canvas** (Play; Canvas is the real layout, drag to pan, no pinch zoom yet), and
|
||||
"+ Field" (Build, which always uses the canvas) that opens the field palette full screen; a pick
|
||||
goes back to the canvas. The inspector (only while a box is selected), the Lore Index and the
|
||||
details panel open as **bottom panels**. The top bar drops the brand words, hint, Lore Index and
|
||||
Export ▾ (both move into ☰). Not done: narrow desktop windows keep the desktop layout; a stats
|
||||
list in Rows style stays rows (no big tiles); Lore drops onto stacked boxes don't land.
|
||||
|
||||
## 5. Code map (phase B)
|
||||
- Data: `core/sheet_doc.gd` (tabs of boxes), `core/sheet_box.gd`, `core/sheet_kinds.gd` (the
|
||||
|
|
@ -90,4 +141,15 @@ an old sheet card becomes a sheet with one text box.
|
|||
(shared brand), `SheetBoxView.look` (tinted card, band, border), canvas and menu draw the
|
||||
theme's spread background (`BoardBackdrop`). Sheets in Play keep the greyed palette (user's rule).
|
||||
- Keys: `MainLayout._shortcut_input` sends keys to the screen that shows.
|
||||
- CLI: `--menu`, `--sheets`, `--sheet-demo` (+ `--sheet-build`), `--new-sheet`. Suites: `test_sheets`, `test_sheet_editor`.
|
||||
- Export/import (E1): `core/sheet_file.gd` (share file), `ui/sheet_export_menu.gd` (Export ▾,
|
||||
PNG capture), `SheetExport.sheet_html`, `SheetStore.keep_picture_bytes`, `SheetsScreen.import_sheet`.
|
||||
- Text tools and Lore links (E2): `ui/sheet_text_box.gd` (the Long notes view), `ui/sheet_text_toolbar.gd`,
|
||||
`ui/sheet_lore_links.gd` (lookup, excerpt, hover), `ui/lore_link_picker.gd`; `FormatMenu.colours/selection`.
|
||||
- Lore Index everywhere (E3): `ui/lore_list.gd`, `ui/lore_level*.gd`, `core/lore_library.gd`,
|
||||
`ui/lore_entry_actions.gd`, `ui/sheet_lore_dock.gd`, `ui/sheet_lore_drop.gd`, `ui/sheet_item_nav.gd`,
|
||||
`core/sheet_items.gd`; `SheetKinds.place` (a box on the grid; `SheetDemo` uses it too).
|
||||
- Phones (E4): `ui/sheet_phone_layout.gd` (bottom bar, bottom panels, full-screen palette),
|
||||
`ui/sheet_stack_view.gd` (stacked view, `order_of`); `SheetFieldViews.touch/tap_size`. Suite: `test_mobile`.
|
||||
- CLI (`ui/main_cli_sheets.gd`): `--menu`, `--sheets`, `--sheet-demo` (+ `--sheet-build`, `--sheet-lore` (a linked Lore Entry
|
||||
in the panel), `--sheet-edit=TITLE` (that text box open with its toolbar), `--sheet-lore-index` (the Lore
|
||||
Index beside it, with a My library item dropped in)), `--new-sheet`. Suites: `test_sheets`, `test_sheet_editor`.
|
||||
|
|
|
|||
|
|
@ -238,6 +238,9 @@ The [b]Lore Index[/b] holds [b]Lore Entries[/b]: results you want to use on more
|
|||
- Open it from View ▾, ☰ or right-click the spread. In Build it is a tab beside the inspector. [b]+ Lore Entry[/b] adds one; in Build, a result's inspector has [b]Save to the Lore Index[/b].
|
||||
- Drag a Lore Entry onto a result to use it there, or onto a card to add it as a new result. Results using a Lore Entry show a small §.
|
||||
- Edit a Lore Entry and every result using it changes. Change a result's own text and it stops following the Lore Entry ([b]Unlink[/b] does the same).
|
||||
- At the top, [b]This spread | My library[/b] switches levels. This spread's entries are saved with the spread. [b]My library[/b] is shared by every spread and sheet. [b]Copy to My library[/b] (or [b]Copy to This spread[/b]) under an entry adds a copy to the other level. Drag a My library entry onto a result and the spread gets its own copy.
|
||||
- [b]Make a sheet for this entry[/b] gives it a small item sheet, such as a sword's Damage, Charges and Notes. Entries with a sheet show ▤; [b]Open its sheet[/b] opens it.
|
||||
- The Lore Index opens in Play too, and inside sheets (see Sheets).
|
||||
[demo]book[/demo]
|
||||
|
||||
# Rolling more than once
|
||||
|
|
@ -271,6 +274,10 @@ A result or a Lore Entry can have a picture: [b]Picture → Choose…[/b] in its
|
|||
- The list fills the screen; [b]Spread[/b] and [b]List[/b] swap between them.
|
||||
- Press and hold for the right-click menu. Two fingers move and zoom the spread.
|
||||
- View, Help and Play/Build are in the [b]☰[/b] menu.
|
||||
- A sheet in Play shows its boxes one under the other, full width. A box's [b]Phone order[/b] (in Build, on the right) puts it first; boxes left at 0 follow from top to bottom, then left to right.
|
||||
- [b]Stacked[/b] and [b]Canvas[/b] at the bottom swap between that list and the real layout. Drag to move around the canvas.
|
||||
- In Build, [b]+ Field[/b] at the bottom opens the fields. Tap a box to change its settings in the panel below.
|
||||
- On a sheet, [b]Lore Index[/b] and [b]Export[/b] are in the [b]☰[/b] menu.
|
||||
|
||||
# The main menu and Sheets
|
||||
The app opens on the [b]main menu[/b]: Spreads, Sheets, Settings and Quit. To come back to it, click the logo at the top left, or use [b]☰ → Main menu[/b].
|
||||
|
|
@ -283,8 +290,14 @@ The app opens on the [b]main menu[/b]: Spreads, Sheets, Settings and Quit. To co
|
|||
- Field kinds: [b]Basics[/b] (number, short text, long notes, checkbox, dropdown), [b]Trackers[/b] (current / max bars, tick boxes, clocks, dot ratings, step dice, usage dice, word ladders), [b]Smart[/b] (formulas and dice buttons), [b]Lists[/b] (rows, mini tables, chips, point pools, bonds, slot inventory, conditions, spell slots, XP, currency) and [b]Layout[/b] (heading, divider, picture). Click a box in Build to change its settings on the right, such as a dropdown's options or a list's columns.
|
||||
- Turn on [b]Use in tables[/b] and give the box a name, such as str. Formulas and dice buttons use it as @str, like [b]floor((@str - 10) / 2)[/b] or [b]1d20 + @str[/b], and a text box shows it with {@str}.
|
||||
- A list with a [b]point pool[/b] takes each entry's cost off the pool. You can go over; the pool turns red.
|
||||
- Click a [b]Long notes[/b] box in Play to write in it. The buttons above the text add the common formatting: [b]B[/b], [i]I[/i], [u]U[/u], [s]S[/s], [b]Colour[/b], [b]Size[/b] and [b]Effect[/b] wrap the selected words; [b]{@}[/b] adds a live value. Right-click the text for the same formatting. Any BBCode works.
|
||||
- [b]§ Link…[/b] links the selected words to a Lore Entry from the spread's Lore Index or My library. Hover the link to see the start of the entry; click it to read it all in the side panel.
|
||||
- [b]Lore Index[/b] at the top shows the Lore Index beside the sheet, in Play and Build (in Build it is a tab beside the inspector). Drag a Lore Entry onto a box: onto a list or Slots box it adds an entry or item, with the entry's text as its details; onto a Long notes box it adds a link. A drop is a copy, and the entry's item sheet is copied with it. Hold [b]Shift[/b] while you drop to keep it linked: it shows §, and it uses the entry's own sheet. Undo takes it out again.
|
||||
- An item with a sheet shows ▤ (in Slots: click the item). That opens its sheet; [b]←[/b] at the top goes back to the sheet you came from. ⓘ on a linked entry has [b]Read the Lore Entry[/b].
|
||||
- Hover a list entry to see the start of its details; click its ⓘ (or a chip) to read and edit them in full in the side panel.
|
||||
- [b]Sheet ▾ → Save as template…[/b] keeps the layout to start new sheets from.
|
||||
- In Build, [b]Save as template…[/b] at the top (also in [b]☰[/b]) keeps the layout to start new sheets from.
|
||||
- [b]Export ▾[/b] at the top right saves the sheet as a file: [b]Share file…[/b] for others to import (pictures go with it), [b]Print / PDF (web page)…[/b] to open in a browser and print or save as PDF (one page per tab), or [b]Image (PNG)…[/b] of the tab as you see it.
|
||||
- To add a sheet someone sent you, press [b]Import…[/b] on the Sheets page, or [b]Import a sheet file…[/b] in the New sheet window. It becomes a new sheet of your own.
|
||||
|
||||
## Sheets on a spread
|
||||
- In Build, drag one of your sheets from the card palette's [b]Sheets[/b] group onto the spread (or pick [b]New sheet[/b]). It becomes a Sheet card showing a small picture of its first tab. Threads can lead into it: a roll that reaches it shows the sheet in the tray, ready to copy or save.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
extends AppTestBase
|
||||
## The Book: pages saved from results, linked results following a page's edits,
|
||||
## dropping a page onto a result or a card, unlinking, saving and undo.
|
||||
## dropping a page onto a result or a card, unlinking, saving and undo; the
|
||||
## two levels (This spread | My library) and Lore Entries in sheets (items).
|
||||
## Run: tools/run_tests.sh book
|
||||
|
||||
|
||||
|
|
@ -11,6 +12,8 @@ func run() -> void:
|
|||
await _frames()
|
||||
await _test_book()
|
||||
_test_pictures()
|
||||
await _test_levels()
|
||||
await _test_sheet_items()
|
||||
finish()
|
||||
|
||||
|
||||
|
|
@ -119,3 +122,67 @@ func _test_pictures() -> void:
|
|||
_check(e3.combine_for("loot") == "max" and e3.pipe_pause.has("loot") and e3.pipe_color.get("loot") == "#c04a86", "thread options import")
|
||||
_check(b2.get_group(g2.id).parent == g.id and b2.book.size() == main.data.book.size() and b2.images.has(r["id"]), "nesting, the Book and pictures import")
|
||||
|
||||
|
||||
|
||||
## My library beside This spread: new entries go to the level shown, Copy to
|
||||
## moves a copy across, and a library entry dropped on a card is copied in.
|
||||
func _test_levels() -> void:
|
||||
var lore := main.book.lore
|
||||
var library := SheetLoreLinks.library(main)
|
||||
var before := library.pages.size()
|
||||
lore.set_level(LoreLevel.LIBRARY)
|
||||
var shared := lore.new_page()
|
||||
_eq(library.pages.size(), before + 1, "+ Lore Entry in My library adds it there")
|
||||
_eq(lore.list.item_count, library.pages.size(), "the list shows My library")
|
||||
lore.set_level(LoreLevel.SPREAD)
|
||||
_eq(lore.list.item_count, main.data.book.size(), "This spread shows the spread's entries again")
|
||||
var spread_count := main.data.book.size()
|
||||
var copied := LoreEntryActions.copy_to(lore, shared, lore.levels[LoreLevel.SPREAD])
|
||||
_check(main.data.book.size() == spread_count + 1 and copied.id != shared.id, "Copy to This spread adds a copy")
|
||||
_check(SheetLoreLinks.find(main, "lib:" + shared.id) == shared and SheetLoreLinks.find(main, copied.id) == copied, "links name their level: lore:lib:ID or lore:ID")
|
||||
await _frames()
|
||||
var card := main.card_for("loot")
|
||||
_check(main.book.drop_page(shared.id, card.get_global_rect().position + Vector2(20, 12), lore.levels[LoreLevel.LIBRARY]), "a My library entry drops onto a card")
|
||||
_eq(main.data.book.size(), spread_count + 2, "and is copied into the spread first")
|
||||
library.remove_page(shared.id)
|
||||
|
||||
|
||||
## The Lore Index in a sheet: an entry with an item sheet dropped on a Slots
|
||||
## box (a copy with its own sheet) and on a list box with Shift (linked), one
|
||||
## undo step each; its sheet opens with a way back.
|
||||
func _test_sheet_items() -> void:
|
||||
var sheets := main.screens.sheets
|
||||
var doc := SheetDemo.create("lore-items")
|
||||
sheets.store.save(doc)
|
||||
main.screens.show(MainScreens.SHEETS)
|
||||
sheets.open_doc(doc)
|
||||
var ed := sheets.editor
|
||||
ed.set_mode(Main.Mode.PLAY)
|
||||
ed.set_lore_shown(true)
|
||||
_check(ed.lore_dock.visible and not ed.inspector.visible, "Play: the Lore Index opens beside the sheet")
|
||||
var level: LoreLevel = ed.lore_dock.lore.levels[LoreLevel.LIBRARY]
|
||||
var blade := level.add_page("Ashen Blade", "Burns what it cuts.")
|
||||
LoreEntryActions.open_or_make_sheet(ed.lore_dock.lore, blade)
|
||||
_check(blade.sheet != "" and ed.doc.id == blade.sheet, "Make a sheet for this entry opens its new sheet")
|
||||
_eq(ed.top_bar.back_button.text, "← Brin Hollowmere", "with a way back")
|
||||
ed.nav.back()
|
||||
_eq(ed.doc.id, doc.id, "back returns to the character")
|
||||
await _frames()
|
||||
var inventory := MainCliSheets.box_titled(ed.doc, "Inventory")
|
||||
var at: Vector2 = ed.canvas.views[inventory.id].get_global_rect().get_center()
|
||||
_check(SheetLoreDrop.drop(ed, blade, level, at, false), "an entry drops onto a Slots box")
|
||||
var item: Dictionary = (MainCliSheets.box_titled(ed.doc, "Inventory").value as Array).back()
|
||||
_check(item["name"] == "Ashen Blade" and str(item.get("sheet", "")) not in ["", blade.sheet] and not item.has("lore"), "as an item with its own copy of the sheet")
|
||||
await _frames()
|
||||
var talents := MainCliSheets.box_titled(ed.doc, "Talents")
|
||||
var rows := (talents.value as Array).size()
|
||||
SheetLoreDrop.drop(ed, blade, level, ed.canvas.views[talents.id].get_global_rect().get_center(), true)
|
||||
var row: Dictionary = (MainCliSheets.box_titled(ed.doc, "Talents").value as Array).back()
|
||||
_check(row["Name"] == "Ashen Blade" and row["details"] == "Burns what it cuts." and row["lore"] == "lib:" + blade.id and row["sheet"] == blade.sheet, "Shift: a list row stays linked")
|
||||
_check(ed.canvas.views[talents.id].find_child("LoreMark", true, false) != null, "and shows §")
|
||||
ed.undo()
|
||||
_eq((MainCliSheets.box_titled(ed.doc, "Talents").value as Array).size(), rows, "undo takes the row out again")
|
||||
ed.set_lore_shown(false)
|
||||
level.remove_page(blade.id)
|
||||
sheets.show_list()
|
||||
main.screens.show(MainScreens.SPREAD)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
extends AppTestBase
|
||||
## The phone layout (List fills the screen, Spread/List swap, slim bar and
|
||||
## tray, View/Help/Play-Build in ☰) and touch gestures (pinch zoom, a long
|
||||
## press timing out into a right-click).
|
||||
## press timing out into a right-click), and sheets on a phone (the stacked
|
||||
## view in phone order, the Stacked | Canvas switch, Build's "+ Field").
|
||||
## Run: tools/run_tests.sh mobile
|
||||
|
||||
|
||||
|
|
@ -10,6 +11,7 @@ func run() -> void:
|
|||
return
|
||||
await _test_layout()
|
||||
await _test_touch()
|
||||
await _test_sheet()
|
||||
finish()
|
||||
|
||||
|
||||
|
|
@ -55,6 +57,50 @@ func _test_touch() -> void:
|
|||
touch._input(_tap(0, Vector2(120, 320), false))
|
||||
|
||||
|
||||
func _test_sheet() -> void:
|
||||
var a := SheetBox.new("a")
|
||||
var b := SheetBox.new("b")
|
||||
var c := SheetBox.new("c")
|
||||
var d := SheetBox.new("d")
|
||||
a.set_rect(Rect2(200, 0, 10, 10))
|
||||
b.set_rect(Rect2(0, 0, 10, 10))
|
||||
c.set_rect(Rect2(0, 50, 10, 10))
|
||||
d.set_rect(Rect2(0, 90, 10, 10))
|
||||
d.phone_order = 1
|
||||
var ids: Array = SheetStackView.order_of([a, b, c, d]).map(func(box: SheetBox) -> String: return box.id)
|
||||
_eq(ids, ["d", "b", "a", "c"], "phone order: numbers first, then top-down, left-right")
|
||||
main.screens.show(MainScreens.SHEETS)
|
||||
var ed := main.screens.sheets.editor
|
||||
main.screens.sheets.open_doc(SheetDemo.create())
|
||||
await _frames()
|
||||
var phone := ed.phone
|
||||
_check(phone != null and phone.stack.visible and not ed.canvas.visible and not ed.palette_dock.visible, "Play on a phone shows the stacked view")
|
||||
_eq(phone.stack.views.size(), (ed.current_tab()["boxes"] as Array).size(), "every box of the tab is in the stack")
|
||||
var number: SheetBox = null
|
||||
for box: SheetBox in ed.current_tab()["boxes"]:
|
||||
if box.kind == SheetKinds.NUMBER and number == null:
|
||||
number = box
|
||||
var plus: Button = phone.stack.views[number.id].find_child("Plus", true, false)
|
||||
_check(plus.custom_minimum_size.y >= SheetFieldViews.TOUCH, "step buttons are touch size")
|
||||
_check(not SheetFieldViews.touch, "the touch flag is off again")
|
||||
var before: Variant = number.value
|
||||
plus.pressed.emit()
|
||||
_eq(number.value, int(before) + 1, "+ in the stack changes the value")
|
||||
phone.undo_button.pressed.emit()
|
||||
_eq(ed.doc.find_box(number.id).value, before, "Undo in the bottom bar takes it back")
|
||||
phone.canvas_button.pressed.emit()
|
||||
_check(ed.canvas.visible and not phone.stack.visible, "Canvas shows the real layout")
|
||||
ed.set_mode(Main.Mode.BUILD)
|
||||
_check(ed.canvas.visible and not phone.canvas_button.visible and phone.add_button.visible, "Build uses the canvas, with + Field")
|
||||
phone.add_button.pressed.emit()
|
||||
_check(ed.palette_dock.visible and not ed.canvas.visible, "+ Field opens the palette full screen")
|
||||
ed.palette._add(Vector2.INF, SheetKinds.NUMBER)
|
||||
_check(ed.canvas.visible and not ed.palette_dock.visible and ed.inspector.visible, "a pick goes back to the canvas, inspector below")
|
||||
ed.set_mode(Main.Mode.PLAY)
|
||||
phone.stacked_button.pressed.emit()
|
||||
main.screens.show(MainScreens.SPREAD)
|
||||
|
||||
|
||||
func _tap(i: int, at: Vector2, down: bool) -> InputEventScreenTouch:
|
||||
var t := InputEventScreenTouch.new()
|
||||
t.index = i
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ func run() -> void:
|
|||
await _test_kinds()
|
||||
await _test_links()
|
||||
await _test_overlap()
|
||||
await _test_export()
|
||||
await _test_text_tools()
|
||||
finish()
|
||||
|
||||
|
||||
|
|
@ -292,3 +294,75 @@ func _click() -> InputEventMouseButton:
|
|||
mb.button_index = MOUSE_BUTTON_LEFT
|
||||
mb.pressed = true
|
||||
return mb
|
||||
|
||||
|
||||
func _test_export() -> void:
|
||||
var sheets := main.screens.sheets
|
||||
var doc := SheetDemo.create("export-demo")
|
||||
sheets.store.save(doc)
|
||||
sheets.open_doc(doc)
|
||||
var ed := sheets.editor
|
||||
ed.set_mode(Main.Mode.PLAY)
|
||||
var bar: SheetTopBar = ed.top_bar
|
||||
_check(bar.export_button.is_visible_in_tree(), "Export ▾ shows in Play")
|
||||
var popup := bar.export_button.get_popup()
|
||||
popup.about_to_popup.emit()
|
||||
_eq(range(popup.item_count).map(func(i: int) -> String: return popup.get_item_text(i)), SheetExportMenu.ITEMS, "Export ▾ offers share file, print page and PNG")
|
||||
var page := SheetExportMenu.page_html(ed)
|
||||
_check(page.contains(doc.name) and page.count("<section>") == doc.tabs.size(), "the print page has the sheet, one section per tab")
|
||||
_check(SheetExportMenu.capture(ed.canvas) == null, "headless runs have no picture to take")
|
||||
sheets.show_list()
|
||||
_check(sheets.list_page.find_child("ImportSheet", true, false) != null, "the Sheets list can import a sheet file")
|
||||
sheets.open_new_sheet()
|
||||
await _frames()
|
||||
for c in main.get_children():
|
||||
if c is NewSheetDialog:
|
||||
_check(c.footer.find_child("Import", false, false) != null, "the New sheet dialog can import too")
|
||||
c.close()
|
||||
|
||||
|
||||
## A text box being edited shows the formatting toolbar; B wraps the
|
||||
## selection; "Link a Lore Entry…" links it; the link shows as a reference,
|
||||
## hovers an excerpt and opens the entry in the side panel.
|
||||
func _test_text_tools() -> void:
|
||||
var sheets := main.screens.sheets
|
||||
var page := main.data.add_page("Abbey of Vel", "Ruined. The monks left in a hurry, and something stayed behind in the crypt. The bell still rings at night, though no rope hangs from it and no one climbs the tower.")
|
||||
var doc := sheets.store.create("Notes")
|
||||
var note := SheetKinds.make_box(SheetKinds.TEXT, doc.new_box_id(), Vector2(0, 0))
|
||||
note.value = "Go to the abbey"
|
||||
doc.tabs[0]["boxes"].append(note)
|
||||
sheets.store.save(doc)
|
||||
sheets.open_doc(doc)
|
||||
var ed := sheets.editor
|
||||
ed.set_mode(Main.Mode.PLAY)
|
||||
var view: SheetBoxView = ed.canvas.views[note.id]
|
||||
var shown: RichTextLabel = view.find_child("Shown", true, false)
|
||||
shown.gui_input.emit(_click())
|
||||
var toolbar: SheetTextToolbar = view.find_child("Toolbar", true, false)
|
||||
_check(toolbar.is_visible_in_tree(), "editing a text box shows the toolbar")
|
||||
var edit: TextEdit = view.find_child("Edit", true, false)
|
||||
edit.select(0, 0, 0, 2)
|
||||
(toolbar.find_child("Bold", false, false) as Button).pressed.emit()
|
||||
_eq(str(note.value), "[b]Go[/b] to the abbey", "B wraps the selection in [b]")
|
||||
edit.select(0, 17, 0, 22)
|
||||
toolbar.pick_lore()
|
||||
var picker: LoreLinkPicker = null
|
||||
for child in main.get_children():
|
||||
if child is LoreLinkPicker:
|
||||
picker = child
|
||||
_check(picker != null, "Link a Lore Entry… opens the picker")
|
||||
picker.search.text = "abbey"
|
||||
picker.fill()
|
||||
(picker.find_child(page.id.validate_node_name(), true, false) as Button).pressed.emit()
|
||||
note = ed.doc.find_box(note.id)
|
||||
_eq(str(note.value), "[b]Go[/b] to the [url=lore:%s]abbey[/url]" % page.id, "picking an entry links the selected words")
|
||||
shown = ed.canvas.views[note.id].find_child("Shown", true, false)
|
||||
_check(shown.text.contains("[bgcolor=#%s]" % Style.REF_BG.to_html(false)), "the link shows in the reference colours")
|
||||
_check(SheetLoreLinks.excerpt(page).ends_with("…"), "the hover excerpt is cut with …")
|
||||
shown.meta_clicked.emit("lore:" + page.id)
|
||||
_check(ed.details.visible and ed.details.lore_id == page.id, "clicking the link opens the side panel")
|
||||
var title: Label = ed.details.find_child("Title", true, false)
|
||||
_eq(title.text, "Abbey of Vel", "with the Lore Entry")
|
||||
ed.details.close()
|
||||
main.data.remove_page(page.id)
|
||||
sheets.show_list()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
extends TestBase
|
||||
## Headless checks for sheets (no UI): the file format round trip, boxes and
|
||||
## tabs, the store (save, list, templates, new from template) and snapshot undo.
|
||||
## tabs, the store (save, list, templates, new from template) and snapshot undo;
|
||||
## My library (LoreLibrary) and item sheets of Lore Entries (SheetItems).
|
||||
## Run: tools/run_tests.sh sheets
|
||||
|
||||
const ROOT := "user://test_sheets/"
|
||||
|
|
@ -14,6 +15,8 @@ func run() -> void:
|
|||
_test_history()
|
||||
_test_values()
|
||||
_test_links()
|
||||
_test_share_file()
|
||||
_test_lore_items()
|
||||
_wipe(ROOT)
|
||||
finish()
|
||||
|
||||
|
|
@ -156,3 +159,55 @@ func _test_links() -> void:
|
|||
_check(SheetDoc.overlaps(tab, first.rect()), "a box's own place overlaps it")
|
||||
var spot := SheetDoc.free_spot(tab, first.rect(), SheetKinds.GRID)
|
||||
_check(not SheetDoc.overlaps(tab, Rect2(spot, first.rect().size)), "free_spot finds a place that covers nothing")
|
||||
|
||||
|
||||
func _test_share_file() -> void:
|
||||
var store := SheetStore.new(ROOT.path_join("mine"))
|
||||
var doc := store.create("Brin")
|
||||
doc.from_template = "fighter"
|
||||
var source := ROOT.path_join("portrait.png")
|
||||
Image.create(4, 4, false, Image.FORMAT_RGB8).save_png(source)
|
||||
var portrait := SheetKinds.make_box(SheetKinds.PICTURE, doc.new_box_id(), Vector2.ZERO)
|
||||
portrait.value = store.keep_picture(source)
|
||||
doc.tabs[0]["boxes"].append(portrait)
|
||||
var heading := SheetKinds.make_box(SheetKinds.HEADING, doc.new_box_id(), Vector2(0, 200))
|
||||
heading.title = "Gear"
|
||||
doc.add_tab("Spells")["boxes"].append(heading)
|
||||
var text := SheetFile.share_text(doc)
|
||||
_check(text.contains("\"pictures\"") and not text.contains("fighter"), "a share file carries its pictures, not our template")
|
||||
var theirs := SheetStore.new(ROOT.path_join("theirs"))
|
||||
var got := SheetFile.import_text(theirs, text)
|
||||
_check(got != null and got.name == "Brin" and got.tabs.size() == 2 and got.from_template == "", "a share file imports with its tabs")
|
||||
var picture := str(got.find_box(portrait.id).value)
|
||||
_check(picture.begins_with(theirs.pictures_dir()), "the picture is written into the receiver's pictures")
|
||||
_eq(FileAccess.get_file_as_bytes(picture), FileAccess.get_file_as_bytes(source), "the picture arrives whole")
|
||||
_check(theirs.load_sheet(got.id) != null, "the imported sheet is saved")
|
||||
_eq(SheetFile.import_text(store, text).id, "brin-2", "importing beside the original gets a new id")
|
||||
_check(SheetFile.import_text(store, "{\"name\": 1}") == null, "other files are refused")
|
||||
var page := SheetExport.sheet_html(got, func(_doc: SheetDoc, line: String) -> String: return line)
|
||||
_eq(page.count("<section>"), 2, "the print page has one section per tab")
|
||||
_check(page.contains("<h2>Spells</h2>") and page.contains("<b>Gear</b>"), "it shows the tab names and boxes")
|
||||
|
||||
|
||||
## My library survives a reload; a Lore Entry keeps its item sheet link in the
|
||||
## spread file; a dropped copy gets its own copy of the sheet, a linked one doesn't.
|
||||
func _test_lore_items() -> void:
|
||||
var store := SheetStore.new(ROOT.path_join("lore"))
|
||||
var library := LoreLibrary.new(store.root)
|
||||
var blade := library.add_page("[b]Ashen Blade[/b]", "Burns what it cuts.")
|
||||
blade.tags.assign(["weapon"])
|
||||
var doc := SheetItems.make_sheet(store, blade)
|
||||
library.save()
|
||||
_check(store.load_sheet(blade.sheet) != null and (doc.tabs[0]["boxes"][2] as SheetBox).title == "Charges", "an entry gets an item sheet with Damage, Charges and Notes")
|
||||
var back := LoreLibrary.new(store.root).get_page(blade.id)
|
||||
_check(back != null and back.sheet == doc.id and back.tags == blade.tags, "My library comes back from its file, with the sheet link")
|
||||
var board := TowerBoard.new()
|
||||
var page := board.add_page("Ashen Blade")
|
||||
page.sheet = doc.id
|
||||
var again := TowerBoard.new()
|
||||
again.load_dict(JsonIO.canonical(JSON.parse_string(board.to_json())))
|
||||
_eq(again.get_page(page.id).sheet, doc.id, "a spread's Lore Entry saves its sheet link")
|
||||
var copied := SheetItems.with_links({"name": "Ashen Blade"}, blade, "lib:" + blade.id, false, store)
|
||||
_check(str(copied.get("sheet", "")) not in ["", doc.id] and not copied.has("lore"), "a copy gets its own item sheet")
|
||||
var linked := SheetItems.with_links({"name": "Ashen Blade"}, blade, "lib:" + blade.id, true, store)
|
||||
_check(linked["sheet"] == doc.id and linked["lore"] == "lib:" + blade.id, "a linked item keeps the entry and its sheet")
|
||||
|
|
|
|||
168
ui/book_panel.gd
168
ui/book_panel.gd
|
|
@ -1,25 +1,23 @@
|
|||
class_name BookPanel
|
||||
extends PanelContainer
|
||||
## The Lore Index (Book in code): the spread's reusable results, its Lore
|
||||
## Entries (BookPage), docked beside the spread; in Build it is a tab beside
|
||||
## the inspector (SideTabs).
|
||||
## A searchable list (name, text and tags) above the page editor. Drag a page
|
||||
## onto a result to link it there, or onto a card to add it as a new result.
|
||||
## 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 _ids: Array[String] = []
|
||||
var _rev := -1
|
||||
var _dragging := ""
|
||||
var _tabs: Control
|
||||
var _title: Label
|
||||
|
||||
|
||||
func setup(p_main: Main) -> void:
|
||||
|
|
@ -30,78 +28,25 @@ func setup(p_main: Main) -> void:
|
|||
add_child(col)
|
||||
_tabs = SideTabs.make_row(m, SideTabs.LORE)
|
||||
col.add_child(_tabs)
|
||||
var head := HBoxContainer.new()
|
||||
head.add_theme_constant_override("separation", 6)
|
||||
col.add_child(head)
|
||||
_title = Style.make_label("Lore Index", Style.display(), 20, Style.ON_BG)
|
||||
_title.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
head.add_child(_title)
|
||||
var add := Style.bar_button("+ Lore Entry")
|
||||
add.tooltip_text = "A new Lore Entry: a result you can reuse on any table"
|
||||
add.pressed.connect(new_page)
|
||||
head.add_child(add)
|
||||
var close := Style.bar_button("×")
|
||||
close.tooltip_text = "Close the Lore Index"
|
||||
close.pressed.connect(func() -> void: set_shown(false))
|
||||
head.add_child(close)
|
||||
_search = LineEdit.new()
|
||||
_search.placeholder_text = "Search Lore Entries and tags"
|
||||
_search.clear_button_enabled = true
|
||||
ModalCard.style_line_edit(_search)
|
||||
_search.text_changed.connect(func(_s: String) -> void: refresh())
|
||||
col.add_child(_search)
|
||||
list = ItemList.new()
|
||||
list.custom_minimum_size = Vector2(0, 170)
|
||||
list.add_theme_stylebox_override("panel", Style.box(Style.CARD, 6, [6, 6, 6, 6]))
|
||||
list.add_theme_color_override("font_color", Style.INK)
|
||||
list.add_theme_color_override("font_selected_color", Style.INK)
|
||||
list.add_theme_stylebox_override("selected", Style.box(Style.LIT, 4))
|
||||
list.add_theme_stylebox_override("selected_focus", Style.box(Style.LIT, 4))
|
||||
list.item_selected.connect(func(i: int) -> void: editor.show_page(m.data.get_page(_ids[i])))
|
||||
list.set_drag_forwarding(_drag, Callable(), Callable())
|
||||
col.add_child(list)
|
||||
var scroll := ScrollContainer.new()
|
||||
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
scroll.size_flags_vertical = SIZE_EXPAND_FILL
|
||||
col.add_child(scroll)
|
||||
editor = PageEditor.new(m)
|
||||
editor.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
scroll.add_child(editor)
|
||||
editor.show_page(null)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if visible and m.data and m.edit_rev != _rev:
|
||||
_rev = m.edit_rev
|
||||
refresh()
|
||||
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:
|
||||
var keep := editor.page.id if editor.page else ""
|
||||
var q := _search.text.strip_edges().to_lower()
|
||||
list.clear()
|
||||
_ids.clear()
|
||||
for p in m.data.book:
|
||||
var hay := (p.label() + " " + Formatter.strip_tags(p.text) + " " + " ".join(p.tags)).to_lower()
|
||||
if q != "" and not hay.contains(q):
|
||||
continue
|
||||
var i := list.add_item(p.label())
|
||||
list.set_item_tooltip(i, ("Tags: " + ", ".join(p.tags) + "\n" if not p.tags.is_empty() else "") + "Drag onto a result to use it")
|
||||
_ids.append(p.id)
|
||||
if p.id == keep:
|
||||
list.select(i)
|
||||
if keep != "" and m.data.get_page(keep) == null:
|
||||
editor.show_page(null)
|
||||
lore.refresh()
|
||||
|
||||
|
||||
## After undo or redo: the page in the editor is shown again from the
|
||||
## restored spread, so its fields show the undone text at once.
|
||||
## After undo or redo: shows the entry in the editor again.
|
||||
func reload_page() -> void:
|
||||
if editor == null or editor.page == null:
|
||||
return
|
||||
editor.show_page(m.data.get_page(editor.page.id))
|
||||
refresh()
|
||||
lore.reload_page()
|
||||
|
||||
|
||||
func set_width(px: float) -> void:
|
||||
|
|
@ -112,7 +57,6 @@ func set_shown(on: bool) -> void:
|
|||
visible = on
|
||||
if splitter:
|
||||
splitter.visible = on
|
||||
_rev = -1
|
||||
if m.state:
|
||||
m.state.set_setting(SETTING, on)
|
||||
m.state.save()
|
||||
|
|
@ -126,73 +70,50 @@ func toggle() -> void:
|
|||
## Build shows the Inspector | Lore Index tabs in place of the title.
|
||||
func show_tabs(on: bool) -> void:
|
||||
_tabs.visible = on
|
||||
_title.visible = not on
|
||||
lore.title.visible = not on
|
||||
|
||||
|
||||
func new_page() -> BookPage:
|
||||
m.undo_redo._begin_edit()
|
||||
var p := m.data.add_page("New Lore Entry")
|
||||
m.mark_dirty()
|
||||
m.undo_redo._end_edit()
|
||||
if not visible:
|
||||
set_shown(true)
|
||||
refresh()
|
||||
select_page(p.id)
|
||||
return p
|
||||
return lore.new_page()
|
||||
|
||||
|
||||
## Adds a result's text and details to the Book and links the result to it.
|
||||
## 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:
|
||||
m.undo_redo._begin_edit()
|
||||
var p := m.data.add_page(e.text, e.details)
|
||||
p.image = e.image
|
||||
e.page = p.id
|
||||
m.inspector_edited(t.id)
|
||||
m.mark_dirty()
|
||||
m.undo_redo._end_edit()
|
||||
# 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)
|
||||
refresh()
|
||||
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:
|
||||
var i := _ids.find(pid)
|
||||
if i >= 0:
|
||||
list.select(i)
|
||||
editor.show_page(m.data.get_page(pid))
|
||||
if lore.level.key != LoreLevel.SPREAD and m.data.get_page(pid):
|
||||
lore.set_level(LoreLevel.SPREAD)
|
||||
lore.select_page(pid)
|
||||
|
||||
|
||||
func _drag(at: Vector2) -> Variant:
|
||||
var i := list.get_item_at_position(at, true)
|
||||
if i < 0:
|
||||
return null
|
||||
_dragging = _ids[i]
|
||||
var l := Style.make_label(list.get_item_text(i), Style.body_bold(), 15, Style.INK)
|
||||
var pc := PanelContainer.new()
|
||||
pc.add_theme_stylebox_override("panel", Style.box(Style.LIT, 6, [8, 4, 8, 4]))
|
||||
pc.add_child(l)
|
||||
list.set_drag_preview(pc)
|
||||
return {"book_page": _dragging}
|
||||
|
||||
|
||||
## Nothing took the drop (cards' text fields don't), so the Book places it.
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_DRAG_END and _dragging != "":
|
||||
var pid := _dragging
|
||||
_dragging = ""
|
||||
if not get_viewport().gui_is_drag_successful():
|
||||
drop_page(pid, get_global_mouse_position())
|
||||
|
||||
|
||||
## Drops a page at a screen point: onto a result links it there; onto a card
|
||||
## (not a result) adds it as a new result. True when it landed somewhere.
|
||||
func drop_page(pid: String, at: Vector2) -> bool:
|
||||
## 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]
|
||||
|
|
@ -201,10 +122,11 @@ func drop_page(pid: String, at: Vector2) -> bool:
|
|||
if target == null:
|
||||
m.editing.add_entry(c.table.id)
|
||||
target = c.table.entries[c.table.entries.size() - 1]
|
||||
m.data.link_page(target, pid)
|
||||
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(pid).label(), Formatter.strip_tags(c.table.name)])
|
||||
m.toast("“%s” now shows on %s" % [m.data.get_page(linked).label(), Formatter.strip_tags(c.table.name)])
|
||||
return true
|
||||
return false
|
||||
|
||||
|
|
|
|||
|
|
@ -257,6 +257,8 @@ func show_meta(owner: Control, meta: String) -> void:
|
|||
show_table(owner, arg)
|
||||
"var":
|
||||
_show_var(owner, arg)
|
||||
"lore":
|
||||
SheetLoreLinks.show_hover(main, owner, arg)
|
||||
"missing":
|
||||
show_for(owner, "Missing table", "There's no table called [b]%s[/b]. Check the spelling, or add a table with that name." % RichText.plain(arg))
|
||||
"unset":
|
||||
|
|
|
|||
|
|
@ -52,4 +52,6 @@ func drop_at(on_add: Callable, screen_point: Vector2) -> bool:
|
|||
|
||||
|
||||
func _add(at: Vector2, kind: String) -> void:
|
||||
if ed.phone:
|
||||
ed.phone.palette_open = false
|
||||
ed.add_box(kind, at)
|
||||
|
|
|
|||
|
|
@ -51,14 +51,19 @@ static func _add_to(field: Control) -> void:
|
|||
menu.set_meta("format_menu", true)
|
||||
menu.add_separator("Format")
|
||||
_add_items(menu, STYLES, FIRST_ID, field)
|
||||
var colours: Array = []
|
||||
for preset: Array in ColorChoice.PRESETS:
|
||||
colours.append([preset[0], "[color=%s]" % preset[1], "[/color]"])
|
||||
_submenu(menu, "Colour", colours, FIRST_ID + 100, field)
|
||||
_submenu(menu, "Colour", colours(), FIRST_ID + 100, field)
|
||||
_submenu(menu, "Size", SIZES, FIRST_ID + 200, field)
|
||||
_submenu(menu, "Effect", EFFECTS, FIRST_ID + 300, field)
|
||||
|
||||
|
||||
## The colour presets as [label, open tag, close tag], like STYLES.
|
||||
static func colours() -> Array:
|
||||
var out: Array = []
|
||||
for preset: Array in ColorChoice.PRESETS:
|
||||
out.append([preset[0], "[color=%s]" % preset[1], "[/color]"])
|
||||
return out
|
||||
|
||||
|
||||
static func _submenu(menu: PopupMenu, label: String, items: Array, first_id: int, field: Control) -> void:
|
||||
var sub := PopupMenu.new()
|
||||
ModalCard.style_popup(sub)
|
||||
|
|
@ -88,16 +93,21 @@ static func wrap_selection(field: Control, open: String, close_tag: String) -> v
|
|||
line.text_changed.emit(line.text)
|
||||
elif field is TextEdit:
|
||||
var edit := field as TextEdit
|
||||
var sel := Vector2i(_offset(edit, edit.get_caret_line(), edit.get_caret_column()), 0)
|
||||
sel.y = sel.x
|
||||
if edit.has_selection():
|
||||
sel = Vector2i(_offset(edit, edit.get_selection_from_line(), edit.get_selection_from_column()),
|
||||
_offset(edit, edit.get_selection_to_line(), edit.get_selection_to_column()))
|
||||
var result := TableSettingsRules.wrap_text(edit.text, sel, open, close_tag)
|
||||
var result := TableSettingsRules.wrap_text(edit.text, selection(edit), open, close_tag)
|
||||
edit.text = str(result["text"])
|
||||
edit.text_changed.emit()
|
||||
|
||||
|
||||
## A TextEdit's selection as character offsets (from, to); both are the caret
|
||||
## when nothing is selected.
|
||||
static func selection(edit: TextEdit) -> Vector2i:
|
||||
if edit.has_selection():
|
||||
return Vector2i(_offset(edit, edit.get_selection_from_line(), edit.get_selection_from_column()),
|
||||
_offset(edit, edit.get_selection_to_line(), edit.get_selection_to_column()))
|
||||
var caret := _offset(edit, edit.get_caret_line(), edit.get_caret_column())
|
||||
return Vector2i(caret, caret)
|
||||
|
||||
|
||||
## The character offset of a line and column in a TextEdit.
|
||||
static func _offset(edit: TextEdit, line: int, column: int) -> int:
|
||||
var offset := 0
|
||||
|
|
|
|||
39
ui/lore_entry_actions.gd
Normal file
39
ui/lore_entry_actions.gd
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
class_name LoreEntryActions
|
||||
extends RefCounted
|
||||
## The buttons under a Lore Entry in the page editor: copy it to the other
|
||||
## Lore Index level (This spread ↔ My library), and its item sheet: "Make a
|
||||
## sheet for this entry" (SheetItems.make_sheet) or "Open its sheet".
|
||||
|
||||
|
||||
static func make(lore: LoreList, page: BookPage) -> Control:
|
||||
var row := HFlowContainer.new()
|
||||
row.add_theme_constant_override("h_separation", 6)
|
||||
row.add_theme_constant_override("v_separation", 6)
|
||||
var other_key := LoreLevel.LIBRARY if lore.level.key == LoreLevel.SPREAD else LoreLevel.SPREAD
|
||||
var other: LoreLevel = lore.levels[other_key]
|
||||
var copy := Style.bar_button("Copy to %s" % other.title())
|
||||
copy.name = "CopyToLevel"
|
||||
copy.tooltip_text = "My library is shared by every spread and sheet" if other_key == LoreLevel.LIBRARY else "Add a copy to this spread's Lore Index"
|
||||
copy.pressed.connect(func() -> void: copy_to(lore, page, other))
|
||||
row.add_child(copy)
|
||||
var sheet := Style.bar_button("Open its sheet" if page.sheet != "" else "Make a sheet for this entry")
|
||||
sheet.name = "ItemSheet"
|
||||
sheet.tooltip_text = "Its item sheet, e.g. Damage, Charges and Notes. Drag the entry into a character's inventory to take it along."
|
||||
sheet.pressed.connect(func() -> void: open_or_make_sheet(lore, page))
|
||||
row.add_child(sheet)
|
||||
return row
|
||||
|
||||
|
||||
static func copy_to(lore: LoreList, page: BookPage, other: LoreLevel) -> BookPage:
|
||||
var added := other.add_copy(page)
|
||||
lore.m.toast("Copied “%s” to %s" % [page.label(), other.title()])
|
||||
return added
|
||||
|
||||
|
||||
## Opens the entry's item sheet, making one first when it has none.
|
||||
static func open_or_make_sheet(lore: LoreList, page: BookPage) -> void:
|
||||
if page.sheet == "" or lore.m.screens.sheets.store.load_sheet(page.sheet) == null:
|
||||
lore.level.edit(func() -> void: SheetItems.make_sheet(lore.m.screens.sheets.store, page))
|
||||
lore.refresh()
|
||||
if lore.open_sheet.is_valid():
|
||||
lore.open_sheet.call(page.sheet)
|
||||
1
ui/lore_entry_actions.gd.uid
Normal file
1
ui/lore_entry_actions.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c3q4uuqo4thag
|
||||
91
ui/lore_level.gd
Normal file
91
ui/lore_level.gd
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
class_name LoreLevel
|
||||
extends RefCounted
|
||||
## One level of the Lore Index, as the Lore Index panels (LoreList,
|
||||
## PageEditor) see it: "This spread" (SpreadLoreLevel) or the shared
|
||||
## "My library" (LibraryLoreLevel). The panels call these and never touch
|
||||
## the spread or the library file themselves.
|
||||
|
||||
const SPREAD := "spread"
|
||||
const LIBRARY := "library"
|
||||
|
||||
var m: Main
|
||||
## SPREAD or LIBRARY.
|
||||
var key := SPREAD
|
||||
|
||||
|
||||
func _init(p_main: Main) -> void:
|
||||
m = p_main
|
||||
|
||||
|
||||
## The level's name on its tab and in buttons.
|
||||
func title() -> String:
|
||||
return "This spread"
|
||||
|
||||
|
||||
func pages() -> Array[BookPage]:
|
||||
return []
|
||||
|
||||
|
||||
func get_page(_id: String) -> BookPage:
|
||||
return null
|
||||
|
||||
|
||||
## Runs `change` as one step (one undo step for the spread) and keeps it.
|
||||
func edit(change: Callable) -> void:
|
||||
change.call()
|
||||
|
||||
|
||||
## After the page editor changed `page`: keep it and update what shows it.
|
||||
func changed(_page: BookPage) -> void:
|
||||
pass
|
||||
|
||||
|
||||
## A new entry in this level, as one step.
|
||||
func add_page(text: String, details: String = "") -> BookPage:
|
||||
# Lambdas copy local variables, so the result comes back in an Array.
|
||||
var made: Array[BookPage] = []
|
||||
edit(func() -> void: made.append(_add_raw(text, details)))
|
||||
return made[0]
|
||||
|
||||
|
||||
## Adds an entry without making a step (add_page and add_copy wrap it).
|
||||
func _add_raw(_text: String, _details: String) -> BookPage:
|
||||
return null
|
||||
|
||||
|
||||
func remove_page(_id: String) -> void:
|
||||
pass
|
||||
|
||||
|
||||
## Goes up when the entries change, so an open list knows to refresh.
|
||||
func revision() -> int:
|
||||
return 0
|
||||
|
||||
|
||||
## The line under the editor: where the entry is used.
|
||||
func uses_note(_page: BookPage) -> String:
|
||||
return ""
|
||||
|
||||
|
||||
## What a sheet link to `page` holds after "lore:" (SheetLoreLinks).
|
||||
func ref(page: BookPage) -> String:
|
||||
return page.id
|
||||
|
||||
|
||||
## Adds a copy of `page` (from another level) here and returns it. Its item
|
||||
## sheet is copied too, so the two don't share one. Pictures belong to a
|
||||
## spread, so only a copy into the spread keeps one.
|
||||
func add_copy(page: BookPage) -> BookPage:
|
||||
var made: Array[BookPage] = []
|
||||
edit(func() -> void: made.append(copy_raw(page)))
|
||||
return made[0]
|
||||
|
||||
|
||||
## add_copy without making a step, for a caller that already has one open.
|
||||
func copy_raw(page: BookPage) -> BookPage:
|
||||
var added := _add_raw(page.text, page.details)
|
||||
added.name = page.name
|
||||
added.tags = page.tags.duplicate()
|
||||
added.image = page.image if key == SPREAD else ""
|
||||
added.sheet = SheetItems.copy_sheet(m.screens.sheets.store, page.sheet)
|
||||
return added
|
||||
1
ui/lore_level.gd.uid
Normal file
1
ui/lore_level.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ct5ild7jamk7t
|
||||
54
ui/lore_level_library.gd
Normal file
54
ui/lore_level_library.gd
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
class_name LibraryLoreLevel
|
||||
extends LoreLevel
|
||||
## "My library": the shared Lore Entries (LoreLibrary), the same in every
|
||||
## spread and sheet. Saved at once; there is no undo for it.
|
||||
|
||||
|
||||
func _init(p_main: Main) -> void:
|
||||
super(p_main)
|
||||
key = LIBRARY
|
||||
|
||||
|
||||
func title() -> String:
|
||||
return "My library"
|
||||
|
||||
|
||||
func library() -> LoreLibrary:
|
||||
return SheetLoreLinks.library(m)
|
||||
|
||||
|
||||
func pages() -> Array[BookPage]:
|
||||
return library().pages if library() else ([] as Array[BookPage])
|
||||
|
||||
|
||||
func get_page(id: String) -> BookPage:
|
||||
return library().get_page(id) if library() else null
|
||||
|
||||
|
||||
func edit(change: Callable) -> void:
|
||||
change.call()
|
||||
library().save()
|
||||
|
||||
|
||||
func changed(_page: BookPage) -> void:
|
||||
library().save()
|
||||
|
||||
|
||||
func _add_raw(text: String, details: String) -> BookPage:
|
||||
return library().add_page(text, details)
|
||||
|
||||
|
||||
func remove_page(id: String) -> void:
|
||||
library().remove_page(id)
|
||||
|
||||
|
||||
func revision() -> int:
|
||||
return library().revision if library() else 0
|
||||
|
||||
|
||||
func uses_note(_page: BookPage) -> String:
|
||||
return "In My library: every spread and sheet can use it. Drag it onto a result to copy it into this spread."
|
||||
|
||||
|
||||
func ref(page: BookPage) -> String:
|
||||
return SheetLoreLinks.LIBRARY + page.id
|
||||
1
ui/lore_level_library.gd.uid
Normal file
1
ui/lore_level_library.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://oep0hvvp2j83
|
||||
48
ui/lore_level_spread.gd
Normal file
48
ui/lore_level_spread.gd
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
class_name SpreadLoreLevel
|
||||
extends LoreLevel
|
||||
## "This spread": the open spread's Lore Entries (TowerBoard.book). Changes
|
||||
## go through the spread's undo, and linked results follow (TowerBoard.sync_page).
|
||||
|
||||
|
||||
func _init(p_main: Main) -> void:
|
||||
super(p_main)
|
||||
key = SPREAD
|
||||
|
||||
|
||||
func pages() -> Array[BookPage]:
|
||||
return m.data.book if m.data else ([] as Array[BookPage])
|
||||
|
||||
|
||||
func get_page(id: String) -> BookPage:
|
||||
return m.data.get_page(id) if m.data else null
|
||||
|
||||
|
||||
func edit(change: Callable) -> void:
|
||||
m.undo_redo._begin_edit()
|
||||
change.call()
|
||||
m.mark_dirty()
|
||||
m.undo_redo._end_edit()
|
||||
|
||||
|
||||
func changed(page: BookPage) -> void:
|
||||
for table_id in m.data.sync_page(page.id):
|
||||
m.inspector_edited(table_id)
|
||||
m.mark_dirty()
|
||||
|
||||
|
||||
func _add_raw(text: String, details: String) -> BookPage:
|
||||
return m.data.add_page(text, details)
|
||||
|
||||
|
||||
func remove_page(id: String) -> void:
|
||||
edit(func() -> void: m.data.remove_page(id))
|
||||
|
||||
|
||||
func revision() -> int:
|
||||
return m.edit_rev
|
||||
|
||||
|
||||
func uses_note(page: BookPage) -> String:
|
||||
var n := m.data.page_uses(page.id)
|
||||
return "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"]
|
||||
|
||||
1
ui/lore_level_spread.gd.uid
Normal file
1
ui/lore_level_spread.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bifofg6rfhmum
|
||||
63
ui/lore_link_picker.gd
Normal file
63
ui/lore_link_picker.gd
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
class_name LoreLinkPicker
|
||||
extends ModalCard
|
||||
## "Link a Lore Entry": a search box over the Lore Entries a sheet can link to
|
||||
## (SheetLoreLinks.entries), each with the start of its text. Clicking one
|
||||
## calls on_pick(page) and closes; Enter picks the first one shown.
|
||||
|
||||
var main: Main
|
||||
var search: LineEdit
|
||||
var _on_pick: Callable
|
||||
var _list: VBoxContainer
|
||||
var _first: BookPage
|
||||
|
||||
|
||||
func _init(p_main: Main, on_pick: Callable) -> void:
|
||||
super("Link a Lore Entry", 460.0)
|
||||
main = p_main
|
||||
_on_pick = on_pick
|
||||
search = LineEdit.new()
|
||||
search.name = "Search"
|
||||
search.placeholder_text = "Search Lore Entries and tags"
|
||||
search.clear_button_enabled = true
|
||||
search.text_changed.connect(func(_text: String) -> void: fill())
|
||||
search.text_submitted.connect(func(_text: String) -> void:
|
||||
if _first:
|
||||
choose(_first))
|
||||
body.add_child(search)
|
||||
_list = VBoxContainer.new()
|
||||
_list.name = "Entries"
|
||||
_list.add_theme_constant_override("separation", 4)
|
||||
body.add_child(_list)
|
||||
body.add_child(ModalCard.note("From this spread's Lore Index. The selected words become the link; with none, the entry's name is added."))
|
||||
add_button("Cancel", "plain", close)
|
||||
fill()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super()
|
||||
search.grab_focus()
|
||||
|
||||
|
||||
## Lists the entries matching the search.
|
||||
func fill() -> void:
|
||||
for child in _list.get_children():
|
||||
_list.remove_child(child)
|
||||
child.queue_free()
|
||||
var found := SheetLoreLinks.search(main, search.text)
|
||||
_first = found[0] if not found.is_empty() else null
|
||||
if found.is_empty():
|
||||
var empty := "No Lore Entries yet. Add some in the spread's Lore Index." if SheetLoreLinks.entries(main).is_empty() else "Nothing matches “%s”." % search.text.strip_edges()
|
||||
_list.add_child(ModalCard.note(empty))
|
||||
for page in found:
|
||||
var button := ModalCard.make_button(page.label(), "plain")
|
||||
button.name = page.id.validate_node_name()
|
||||
button.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||||
button.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
||||
button.tooltip_text = SheetLoreLinks.excerpt(page)
|
||||
button.pressed.connect(choose.bind(page))
|
||||
_list.add_child(button)
|
||||
|
||||
|
||||
func choose(page: BookPage) -> void:
|
||||
_on_pick.call(page)
|
||||
close()
|
||||
1
ui/lore_link_picker.gd.uid
Normal file
1
ui/lore_link_picker.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://d0injuj4i7wnx
|
||||
156
ui/lore_list.gd
Normal file
156
ui/lore_list.gd
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
class_name LoreList
|
||||
extends VBoxContainer
|
||||
## The Lore Index's shared part: the title with "+ Lore Entry" and ×, the
|
||||
## "This spread | My library" switch (LoreLevel), a search box (name, text
|
||||
## and tags), the list and the page editor (PageEditor). The spread's dock
|
||||
## (BookPanel) and the sheet editor's (SheetLoreDock) both show one.
|
||||
## Dragging an entry that nothing takes ends in `dropped`: the host places it
|
||||
## (on a spread card, or into a sheet box).
|
||||
|
||||
## A drag from the list ended where no control took it.
|
||||
signal dropped(page: BookPage, level: LoreLevel, at: Vector2)
|
||||
|
||||
var m: Main
|
||||
var level: LoreLevel
|
||||
var levels := {}
|
||||
var title: Label
|
||||
var level_tabs: HBoxContainer
|
||||
var search: LineEdit
|
||||
var list: ItemList
|
||||
var editor: PageEditor
|
||||
## Opens an entry's item sheet (sheet id); set by the host.
|
||||
var open_sheet: Callable
|
||||
var _ids: Array[String] = []
|
||||
var _rev := -1
|
||||
var _dragging := ""
|
||||
|
||||
|
||||
## `on_close` runs when × is pressed.
|
||||
func setup(p_main: Main, on_close: Callable) -> void:
|
||||
m = p_main
|
||||
levels = {LoreLevel.SPREAD: SpreadLoreLevel.new(m), LoreLevel.LIBRARY: LibraryLoreLevel.new(m)}
|
||||
level = levels[LoreLevel.SPREAD]
|
||||
add_theme_constant_override("separation", 8)
|
||||
var head := HBoxContainer.new()
|
||||
head.add_theme_constant_override("separation", 6)
|
||||
add_child(head)
|
||||
title = Style.make_label("Lore Index", Style.display(), 20, Style.ON_BG)
|
||||
title.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
head.add_child(title)
|
||||
var add := Style.bar_button("+ Lore Entry")
|
||||
add.name = "NewEntry"
|
||||
add.tooltip_text = "A new Lore Entry: a result you can reuse on any table"
|
||||
add.pressed.connect(new_page)
|
||||
head.add_child(add)
|
||||
var close := Style.bar_button("×")
|
||||
close.tooltip_text = "Close the Lore Index"
|
||||
close.pressed.connect(on_close)
|
||||
head.add_child(close)
|
||||
level_tabs = SideTabs.tab_row([[LoreLevel.SPREAD, "This spread"], [LoreLevel.LIBRARY, "My library"]], level.key, set_level)
|
||||
level_tabs.name = "LoreLevels"
|
||||
level_tabs.tooltip_text = "This spread's Lore Entries, or My library: shared by every spread and sheet"
|
||||
add_child(level_tabs)
|
||||
search = LineEdit.new()
|
||||
search.placeholder_text = "Search Lore Entries and tags"
|
||||
search.clear_button_enabled = true
|
||||
ModalCard.style_line_edit(search)
|
||||
search.text_changed.connect(func(_s: String) -> void: refresh())
|
||||
add_child(search)
|
||||
list = ItemList.new()
|
||||
list.custom_minimum_size = Vector2(0, 170)
|
||||
list.add_theme_stylebox_override("panel", Style.box(Style.CARD, 6, [6, 6, 6, 6]))
|
||||
list.add_theme_color_override("font_color", Style.INK)
|
||||
list.add_theme_color_override("font_selected_color", Style.INK)
|
||||
list.add_theme_stylebox_override("selected", Style.box(Style.LIT, 4))
|
||||
list.add_theme_stylebox_override("selected_focus", Style.box(Style.LIT, 4))
|
||||
list.item_selected.connect(func(i: int) -> void: editor.show_page(level.get_page(_ids[i])))
|
||||
list.set_drag_forwarding(_drag, Callable(), Callable())
|
||||
add_child(list)
|
||||
var scroll := ScrollContainer.new()
|
||||
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
scroll.size_flags_vertical = SIZE_EXPAND_FILL
|
||||
add_child(scroll)
|
||||
editor = PageEditor.new(self)
|
||||
editor.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
scroll.add_child(editor)
|
||||
editor.show_page(null)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if is_visible_in_tree() and m.data and level.revision() != _rev:
|
||||
_rev = level.revision()
|
||||
refresh()
|
||||
|
||||
|
||||
## Shows level `key` (LoreLevel.SPREAD or LIBRARY).
|
||||
func set_level(key: String) -> void:
|
||||
level = levels[key]
|
||||
SideTabs.press(level_tabs, key)
|
||||
editor.show_page(null)
|
||||
refresh()
|
||||
|
||||
|
||||
## Refills the list (search applied), keeping the selection.
|
||||
func refresh() -> void:
|
||||
_rev = level.revision()
|
||||
var keep := editor.page.id if editor.page else ""
|
||||
var query := search.text.strip_edges().to_lower()
|
||||
list.clear()
|
||||
_ids.clear()
|
||||
for page in level.pages():
|
||||
var hay := (page.label() + " " + Formatter.strip_tags(page.text) + " " + " ".join(page.tags)).to_lower()
|
||||
if query != "" and not hay.contains(query):
|
||||
continue
|
||||
var i := list.add_item(page.label() + (" ▤" if page.sheet != "" else ""))
|
||||
list.set_item_tooltip(i, ("Tags: " + ", ".join(page.tags) + "\n" if not page.tags.is_empty() else "") + ("Has an item sheet\n" if page.sheet != "" else "") + "Drag onto a result or a sheet box to use it")
|
||||
_ids.append(page.id)
|
||||
if page.id == keep:
|
||||
list.select(i)
|
||||
if keep != "" and level.get_page(keep) == null:
|
||||
editor.show_page(null)
|
||||
|
||||
|
||||
## After undo or redo: the entry in the editor is shown again from the
|
||||
## restored spread, so its fields show the undone text at once.
|
||||
func reload_page() -> void:
|
||||
if editor.page == null:
|
||||
return
|
||||
editor.show_page(level.get_page(editor.page.id))
|
||||
refresh()
|
||||
|
||||
|
||||
func new_page() -> BookPage:
|
||||
var page := level.add_page("New Lore Entry")
|
||||
refresh()
|
||||
select_page(page.id)
|
||||
return page
|
||||
|
||||
|
||||
func select_page(id: String) -> void:
|
||||
var i := _ids.find(id)
|
||||
if i >= 0:
|
||||
list.select(i)
|
||||
editor.show_page(level.get_page(id))
|
||||
|
||||
|
||||
func _drag(at: Vector2) -> Variant:
|
||||
var i := list.get_item_at_position(at, true)
|
||||
if i < 0:
|
||||
return null
|
||||
_dragging = _ids[i]
|
||||
var label := Style.make_label(list.get_item_text(i), Style.body_bold(), 15, Style.INK)
|
||||
var chip := PanelContainer.new()
|
||||
chip.add_theme_stylebox_override("panel", Style.box(Style.LIT, 6, [8, 4, 8, 4]))
|
||||
chip.add_child(label)
|
||||
list.set_drag_preview(chip)
|
||||
return {"book_page": _dragging, "lore_level": level.key}
|
||||
|
||||
|
||||
## Nothing took the drop (cards' and boxes' fields don't), so the host places it.
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_DRAG_END and _dragging != "":
|
||||
var id := _dragging
|
||||
_dragging = ""
|
||||
var page := level.get_page(id)
|
||||
if page and not get_viewport().gui_is_drag_successful():
|
||||
dropped.emit(page, level, get_global_mouse_position())
|
||||
1
ui/lore_list.gd.uid
Normal file
1
ui/lore_list.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bmwxcnge60bo6
|
||||
|
|
@ -8,12 +8,15 @@ var m: Main
|
|||
var _build: MainCliBuild
|
||||
## The --perf timings (MainCliPerf).
|
||||
var _perf: MainCliPerf
|
||||
## The sheet and Lore flags (MainCliSheets).
|
||||
var _sheets: MainCliSheets
|
||||
|
||||
|
||||
func _init(p_main: Main) -> void:
|
||||
m = p_main
|
||||
_build = MainCliBuild.new(p_main)
|
||||
_perf = MainCliPerf.new(p_main)
|
||||
_sheets = MainCliSheets.new(p_main)
|
||||
|
||||
|
||||
# ---------- Command line (used for screenshots and checks) ----------
|
||||
|
|
@ -258,32 +261,7 @@ func _run_nav_cli(args: PackedStringArray) -> void:
|
|||
m.demo.open(demo)
|
||||
if args.has("--book"):
|
||||
m.book.set_shown(true)
|
||||
if args.has("--sheet-demo"):
|
||||
# The example sheet in the Sheets screen; --sheet-build opens it in Build.
|
||||
m.screens.show(MainScreens.SHEETS)
|
||||
var sheet := SheetDemo.create()
|
||||
m.screens.sheets.store.save(sheet)
|
||||
m.screens.sheets.open_doc(sheet)
|
||||
if args.has("--sheet-build"):
|
||||
m.screens.sheets.editor.set_mode(Main.Mode.BUILD)
|
||||
var sheet_tab := _arg_value(args, "--sheet-tab")
|
||||
if sheet_tab != "":
|
||||
m.screens.sheets.editor.show_tab(str(sheet.tabs[clampi(sheet_tab.to_int(), 0, sheet.tabs.size() - 1)]["id"]))
|
||||
var select := _arg_value(args, "--sheet-select")
|
||||
for tab in sheet.tabs:
|
||||
for b: SheetBox in tab["boxes"]:
|
||||
if select != "" and b.title == select:
|
||||
m.screens.sheets.editor.select(b.id) if args.has("--sheet-build") else m.screens.sheets.editor.show_details(b.id, 0)
|
||||
if args.has("--sheet-node"):
|
||||
# The example sheet placed on the spread, as a Sheet card.
|
||||
var placed := SheetDemo.create()
|
||||
m.screens.sheets.store.save(placed)
|
||||
m.sheet_links.add_card(placed.id, m.board.screen_to_world(m.board.size * Vector2(0.62, 0.3)))
|
||||
if args.has("--new-sheet"):
|
||||
m.screens.show(MainScreens.SHEETS)
|
||||
m.screens.sheets.store.save_as_template(SheetDemo.create(), "OSR Character")
|
||||
m.screens.sheets.refresh()
|
||||
m.screens.sheets.open_new_sheet()
|
||||
_sheets.run(args)
|
||||
if args.has("--list"):
|
||||
m.list_view.set_shown(true)
|
||||
if args.has("--pack"):
|
||||
|
|
@ -328,3 +306,4 @@ func _run_undo_cli(args: PackedStringArray) -> void:
|
|||
ev.global_position = ev.position
|
||||
m.get_viewport().push_input(ev)
|
||||
await m.get_tree().process_frame
|
||||
|
||||
|
|
|
|||
85
ui/main_cli_sheets.gd
Normal file
85
ui/main_cli_sheets.gd
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
class_name MainCliSheets
|
||||
extends RefCounted
|
||||
## The sheet command-line flags, for screenshots and checks (see
|
||||
## docs/DESIGN.md §5). MainCli uses it; only automation needs this file.
|
||||
# --sheet-demo the example sheet in the Sheets screen
|
||||
# [--sheet-build] [--sheet-tab=N] [--sheet-select=TITLE] [--sheet-lore]
|
||||
# [--sheet-edit=TITLE] [--sheet-lore-index] (the Lore Index beside the sheet)
|
||||
# --sheet-node the example sheet placed on the spread
|
||||
# --new-sheet the New sheet dialog, with a template
|
||||
|
||||
var m: Main
|
||||
|
||||
|
||||
func _init(p_main: Main) -> void:
|
||||
m = p_main
|
||||
|
||||
|
||||
func run(args: PackedStringArray) -> void:
|
||||
if args.has("--sheet-demo"):
|
||||
# The example sheet in the Sheets screen; --sheet-build opens it in Build.
|
||||
m.screens.show(MainScreens.SHEETS)
|
||||
var sheet := SheetDemo.create()
|
||||
m.screens.sheets.store.save(sheet)
|
||||
m.screens.sheets.open_doc(sheet)
|
||||
if args.has("--sheet-build"):
|
||||
m.screens.sheets.editor.set_mode(Main.Mode.BUILD)
|
||||
var sheet_tab := MainCli._arg_value(args, "--sheet-tab")
|
||||
if sheet_tab != "":
|
||||
m.screens.sheets.editor.show_tab(str(sheet.tabs[clampi(sheet_tab.to_int(), 0, sheet.tabs.size() - 1)]["id"]))
|
||||
var select := MainCli._arg_value(args, "--sheet-select")
|
||||
for tab in sheet.tabs:
|
||||
for b: SheetBox in tab["boxes"]:
|
||||
if select != "" and b.title == select:
|
||||
m.screens.sheets.editor.select(b.id) if args.has("--sheet-build") else m.screens.sheets.editor.show_details(b.id, 0)
|
||||
if args.has("--sheet-lore"):
|
||||
# A Lore Entry linked from the Oath box, open in the side panel.
|
||||
var page := m.data.add_page("Abbey of Vel", "A ruined abbey on the moor. The monks left in a hurry; the bell still rings at night.")
|
||||
var oath := box_titled(m.screens.sheets.editor.doc, "Oath")
|
||||
oath.value = str(oath.value).replace("the abbey", "the [url=lore:%s]abbey[/url]" % page.id)
|
||||
m.screens.sheets.editor.refresh()
|
||||
m.screens.sheets.editor.details.open_lore(page.id)
|
||||
if args.has("--sheet-lore-index"):
|
||||
show_lore_items(m.screens.sheets.editor)
|
||||
var edit_title := MainCli._arg_value(args, "--sheet-edit")
|
||||
if edit_title != "":
|
||||
# Opens that text box for editing, with its toolbar.
|
||||
var view: SheetBoxView = m.screens.sheets.editor.canvas.views.get(box_titled(m.screens.sheets.editor.doc, edit_title).id)
|
||||
var click := InputEventMouseButton.new()
|
||||
click.button_index = MOUSE_BUTTON_LEFT
|
||||
click.pressed = true
|
||||
(view.find_child("Shown", true, false) as Control).gui_input.emit(click)
|
||||
if args.has("--sheet-node"):
|
||||
# The example sheet placed on the spread, as a Sheet card.
|
||||
var placed := SheetDemo.create()
|
||||
m.screens.sheets.store.save(placed)
|
||||
m.sheet_links.add_card(placed.id, m.board.screen_to_world(m.board.size * Vector2(0.62, 0.3)))
|
||||
if args.has("--new-sheet"):
|
||||
m.screens.show(MainScreens.SHEETS)
|
||||
m.screens.sheets.store.save_as_template(SheetDemo.create(), "OSR Character")
|
||||
m.screens.sheets.refresh()
|
||||
m.screens.sheets.open_new_sheet()
|
||||
|
||||
|
||||
## The box called `title` on any tab of `doc` (CLI flags name boxes by title).
|
||||
static func box_titled(doc: SheetDoc, title: String) -> SheetBox:
|
||||
for tab in doc.tabs:
|
||||
for box: SheetBox in tab["boxes"]:
|
||||
if box.title == title:
|
||||
return box
|
||||
return null
|
||||
|
||||
|
||||
## --sheet-lore-index: the Lore Index beside the sheet on My library, with an
|
||||
## entry that has an item sheet, dropped linked into the Inventory and copied into Talents.
|
||||
func show_lore_items(ed: SheetEditor) -> void:
|
||||
ed.set_lore_shown(true)
|
||||
var lore := ed.lore_dock.lore
|
||||
lore.set_level(LoreLevel.LIBRARY)
|
||||
var blade := lore.level.add_page("[b]Ashen Blade[/b]", "Burns what it cuts. Three charges; a spent charge returns at dawn.")
|
||||
blade.name = "Ashen Blade"
|
||||
lore.level.edit(func() -> void: SheetItems.make_sheet(ed.screen.store, blade))
|
||||
SheetLoreDrop.add(ed, box_titled(ed.doc, "Inventory"), blade, lore.level.ref(blade), true)
|
||||
SheetLoreDrop.add(ed, box_titled(ed.doc, "Talents"), blade, lore.level.ref(blade), false)
|
||||
lore.refresh()
|
||||
lore.select_page(blade.id)
|
||||
1
ui/main_cli_sheets.gd.uid
Normal file
1
ui/main_cli_sheets.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://rcuoo7x8ofv1
|
||||
|
|
@ -129,9 +129,14 @@ func set_prefix(card_id: String, prefix: String) -> void:
|
|||
## way back to the spread.
|
||||
func open(card_id: String) -> void:
|
||||
var t := m.data.get_table(card_id)
|
||||
var doc := load_doc(t.sheet_id if t else "")
|
||||
open_sheet(t.sheet_id if t else "", "That sheet is gone. Delete the card, or link another sheet.")
|
||||
|
||||
|
||||
## Opens sheet `id` (a card's, or a Lore Entry's item sheet) with a way back to the spread.
|
||||
func open_sheet(id: String, gone: String = "That sheet is gone.") -> void:
|
||||
var doc := load_doc(id)
|
||||
if doc == null:
|
||||
m.toast("That sheet is gone. Delete the card, or link another sheet.")
|
||||
m.toast(gone)
|
||||
return
|
||||
m.screens.show(MainScreens.SHEETS)
|
||||
m.screens.sheets.open_doc(doc)
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ func apply() -> void:
|
|||
bar.actions_menu.get_parent().add_child(add_button)
|
||||
bar.actions_menu.get_parent().move_child(add_button, swap.get_index())
|
||||
show_list(true)
|
||||
m.screens.sheets.editor.use_phone_layout()
|
||||
|
||||
|
||||
## The list or the spread fills the screen.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ extends ModalCard
|
|||
## "+ New sheet", like the mockup: a name, then a grid of starts drawn as small
|
||||
## pictures: a blank canvas (a grid) or one of your sheet templates (its tint
|
||||
## and a few boxes). The Create button names the pick. Calls
|
||||
## on_create(name, template_id) ("" = blank).
|
||||
## on_create(name, template_id) ("" = blank). "Import a sheet file…" in the
|
||||
## footer closes it and calls on_import (when given).
|
||||
|
||||
var store: SheetStore
|
||||
var name_edit: LineEdit
|
||||
|
|
@ -14,7 +15,7 @@ var _names: Dictionary = {} # template id -> name
|
|||
var _on_create: Callable
|
||||
|
||||
|
||||
func _init(p_store: SheetStore, template_id: String, on_create: Callable) -> void:
|
||||
func _init(p_store: SheetStore, template_id: String, on_create: Callable, on_import: Callable = Callable()) -> void:
|
||||
super._init("New sheet", 720.0)
|
||||
store = p_store
|
||||
_on_create = on_create
|
||||
|
|
@ -40,6 +41,11 @@ func _init(p_store: SheetStore, template_id: String, on_create: Callable) -> voi
|
|||
_names[tpl.id] = tpl.name
|
||||
var n := tpl.tabs.size()
|
||||
grid.add_child(_option(group, tpl.id, tpl.name, "Your template · %d %s" % [n, "tab" if n == 1 else "tabs"], tpl.tint))
|
||||
if on_import.is_valid():
|
||||
var import_button := add_button("Import a sheet file…", "plain", func() -> void:
|
||||
close()
|
||||
on_import.call())
|
||||
import_button.name = "Import"
|
||||
var hint := Style.make_label("Templates: in a sheet, Save as template…", Style.body(), 13, Style.MUTED)
|
||||
hint.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
hint.size_flags_vertical = SIZE_SHRINK_CENTER
|
||||
|
|
|
|||
|
|
@ -1,17 +1,21 @@
|
|||
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).
|
||||
## The Lore Index's editor for one Lore Entry (BookPage): its name in the
|
||||
## list, the result text (with BBCode and a live preview), the details
|
||||
## tooltip, picture (spread only) and tags, then LoreEntryActions (copy to the
|
||||
## other level, item sheet). Changes go through the list's level (LoreLevel):
|
||||
## for the spread, to all results linked to the entry at once (TowerBoard.sync_page).
|
||||
|
||||
var m: Main
|
||||
var lore: LoreList
|
||||
var page: BookPage
|
||||
var _preview: RichTextLabel
|
||||
var _uses: Label
|
||||
|
||||
|
||||
func _init(p_main: Main) -> void:
|
||||
m = p_main
|
||||
func _init(p_lore: LoreList) -> void:
|
||||
lore = p_lore
|
||||
m = p_lore.m
|
||||
add_theme_constant_override("separation", 8)
|
||||
|
||||
|
||||
|
|
@ -52,9 +56,10 @@ func show_page(p: BookPage) -> 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())))
|
||||
if lore.level.key == LoreLevel.SPREAD:
|
||||
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(","):
|
||||
|
|
@ -65,29 +70,25 @@ func show_page(p: BookPage) -> void:
|
|||
_uses = _note("")
|
||||
add_child(_uses)
|
||||
_refresh_uses()
|
||||
add_child(LoreEntryActions.make(lore, p))
|
||||
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))
|
||||
lore.level.remove_page(p.id)
|
||||
show_page(null)
|
||||
lore.refresh())
|
||||
add_child(del)
|
||||
|
||||
|
||||
## Copies the page onto its results and redraws their cards.
|
||||
## Keeps the change (for the spread: onto its results, redrawing their cards).
|
||||
func _changed() -> void:
|
||||
for tid in m.data.sync_page(page.id):
|
||||
m.inspector_edited(tid)
|
||||
m.mark_dirty()
|
||||
lore.level.changed(page)
|
||||
_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"]
|
||||
_uses.text = lore.level.uses_note(page)
|
||||
|
||||
|
||||
func _line(text: String, placeholder: String, on_change: Callable) -> LineEdit:
|
||||
|
|
|
|||
|
|
@ -183,12 +183,13 @@ static func _ref_chip(body: String, board: TowerBoard) -> String:
|
|||
return "[url=table:%s][bgcolor=#%s][color=#%s] %s [/color][/bgcolor][/url]" % [id, Style.REF_BG.to_html(false), Style.REF_INK.to_html(false), label_text]
|
||||
|
||||
|
||||
## Colours the internal markers of rolled text: table rolls in teal, variables in
|
||||
## brass, and missing / unset / too-deep markers in red, so they're visible.
|
||||
## Colours the internal markers of rolled text: table rolls and Lore Entry
|
||||
## links (SheetLoreLinks) in teal, variables in brass, and missing / unset / too-deep markers in red, so they're visible.
|
||||
static func decorate(bbcode: String, on_felt: bool = false) -> String:
|
||||
if not bbcode.contains("[url="):
|
||||
return bbcode
|
||||
var out := ""
|
||||
# The closing tags each open [url] needs before its [/url].
|
||||
var open: Array[String] = []
|
||||
for t: Dictionary in Formatter.tokenize(bbcode):
|
||||
if t["name"] == "url":
|
||||
|
|
@ -196,19 +197,24 @@ static func decorate(bbcode: String, on_felt: bool = false) -> String:
|
|||
var meta := (t["param"] as String).trim_prefix("=").strip_edges().trim_prefix("\"").trim_suffix("\"")
|
||||
var color := _marker_color(meta, on_felt)
|
||||
out += t["raw"]
|
||||
var closing := ""
|
||||
if meta.begins_with(SheetLoreLinks.META) and not on_felt:
|
||||
# A Lore Entry link: a reference chip, like [[Table]] in preview().
|
||||
out += "[bgcolor=#%s]" % Style.REF_BG.to_html(false)
|
||||
closing = "[/bgcolor]"
|
||||
if color != "":
|
||||
out += "[color=#%s]" % color
|
||||
open.append(color)
|
||||
closing = "[/color]" + closing
|
||||
open.append(closing)
|
||||
continue
|
||||
elif not open.is_empty():
|
||||
if open.pop_back() != "":
|
||||
out += "[/color]"
|
||||
out += open.pop_back()
|
||||
out += t["raw"]
|
||||
return out
|
||||
|
||||
|
||||
static func _marker_color(meta: String, on_felt: bool) -> String:
|
||||
if meta.begins_with("table:"):
|
||||
if meta.begins_with("table:") or meta.begins_with(SheetLoreLinks.META):
|
||||
return (Style.REF_INK_ON_BG if on_felt else Style.REF_INK).to_html(false)
|
||||
if meta.begins_with("var:"):
|
||||
return (Style.VALUE_INK_ON_BG if on_felt else Style.VALUE_INK).to_html(false)
|
||||
|
|
|
|||
|
|
@ -2,13 +2,19 @@ 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). An in-app panel, not a window.
|
||||
## 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
|
||||
|
||||
|
||||
|
|
@ -28,12 +34,22 @@ func setup(p_editor: SheetEditor) -> void:
|
|||
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
|
||||
|
||||
|
||||
|
|
@ -41,6 +57,9 @@ 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():
|
||||
|
|
@ -49,21 +68,7 @@ func rebuild() -> void:
|
|||
visible = true
|
||||
var entry: Dictionary = rows[index]
|
||||
var cols := SheetFieldsList.columns(box)
|
||||
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(box.title.to_upper(), Style.caps(), 11, Style.TRIM))
|
||||
var title := Style.make_label(str(entry.get(str(cols[0]["name"]), "")), Style.display(), 26, Style.INK)
|
||||
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)
|
||||
_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()):
|
||||
|
|
@ -72,6 +77,7 @@ func rebuild() -> void:
|
|||
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"
|
||||
|
|
@ -91,6 +97,78 @@ func rebuild() -> void:
|
|||
_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]))
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ class_name SheetEditor
|
|||
extends VBoxContainer
|
||||
## One open sheet: the sheet top bar (SheetTopBar), the field palette on the
|
||||
## left (FieldPalette), the tab row (SheetTabsBar) over the canvas
|
||||
## (SheetCanvas) and, in Build, the inspector on the right (SheetInspector).
|
||||
## (SheetCanvas) and, in Build, the inspector on the right (SheetInspector);
|
||||
## the Lore Index (SheetLoreDock) shares that dock and also opens in Play.
|
||||
## It owns the sheet's Play/Build mode, the open tab, the selected box, undo
|
||||
## (SnapshotHistory) and saving. Every change goes through edit() or
|
||||
## edit_value(), so it can be undone and is saved soon after.
|
||||
|
|
@ -26,6 +27,13 @@ var canvas: SheetCanvas
|
|||
var inspector: SheetInspector
|
||||
## The side panel for a list entry's full details.
|
||||
var details: SheetDetailPanel
|
||||
## The Lore Index beside the sheet (shown when lore_shown).
|
||||
var lore_dock: SheetLoreDock
|
||||
var lore_shown := false
|
||||
## Item sheets opened from this one, and the way back.
|
||||
var nav := SheetItemNav.new(self)
|
||||
## The phone layout (stacked view, bottom bar), or null on a desktop.
|
||||
var phone: SheetPhoneLayout
|
||||
var status_label: Label
|
||||
var undo_label: Label
|
||||
var _save_timer: Timer
|
||||
|
|
@ -59,6 +67,9 @@ func setup(p_main: Main, p_screen: SheetsScreen) -> void:
|
|||
inspector = SheetInspector.new()
|
||||
inspector.setup(self)
|
||||
middle.add_child(inspector)
|
||||
lore_dock = SheetLoreDock.new()
|
||||
lore_dock.setup(self)
|
||||
middle.add_child(lore_dock)
|
||||
details = SheetDetailPanel.new()
|
||||
details.setup(self)
|
||||
middle.add_child(details)
|
||||
|
|
@ -99,6 +110,13 @@ func _make_status_strip() -> PanelContainer:
|
|||
return strip
|
||||
|
||||
|
||||
## Switches to the phone layout (MobileLayout calls it once).
|
||||
func use_phone_layout() -> void:
|
||||
phone = SheetPhoneLayout.new(self)
|
||||
phone.apply()
|
||||
refresh()
|
||||
|
||||
|
||||
func update_status() -> void:
|
||||
if doc == null:
|
||||
return
|
||||
|
|
@ -115,6 +133,7 @@ func update_status() -> void:
|
|||
|
||||
func open(p_doc: SheetDoc) -> void:
|
||||
from_spread = ""
|
||||
nav.clear()
|
||||
doc = p_doc
|
||||
history.clear()
|
||||
_merge_key = ""
|
||||
|
|
@ -173,10 +192,19 @@ func set_mode(new_mode: Main.Mode) -> void:
|
|||
|
||||
|
||||
func set_palette_shown(on: bool) -> void:
|
||||
if phone:
|
||||
phone.show_palette(on)
|
||||
return
|
||||
palette_dock.visible = on
|
||||
top_bar.sync()
|
||||
|
||||
|
||||
## Shows or hides the Lore Index; in Build it takes the inspector's place.
|
||||
func set_lore_shown(on: bool) -> void:
|
||||
lore_shown = on
|
||||
refresh()
|
||||
|
||||
|
||||
func show_tab(id: String) -> void:
|
||||
if id != tab_id:
|
||||
canvas.recentre()
|
||||
|
|
@ -189,6 +217,8 @@ func select(box_id: String) -> void:
|
|||
selected = box_id
|
||||
canvas.paint_selection()
|
||||
inspector.rebuild()
|
||||
if phone:
|
||||
phone.sync()
|
||||
update_status()
|
||||
|
||||
|
||||
|
|
@ -203,10 +233,14 @@ func refresh() -> void:
|
|||
top_bar.sync()
|
||||
tabs_bar.rebuild()
|
||||
canvas.rebuild()
|
||||
inspector.visible = building()
|
||||
inspector.visible = building() and not lore_shown
|
||||
inspector.rebuild()
|
||||
if details.box_id != "":
|
||||
lore_dock.visible = lore_shown
|
||||
lore_dock.sync()
|
||||
if details.box_id != "" or details.lore_id != "":
|
||||
details.rebuild()
|
||||
if phone:
|
||||
phone.sync(true)
|
||||
update_status()
|
||||
|
||||
|
||||
|
|
@ -233,7 +267,7 @@ func edit(label: String, change: Callable, merge_key: String = "", redraw: bool
|
|||
## elsewhere (the details panel) passes keep_id "" so the box redraws too.
|
||||
func edit_value(box: SheetBox, value: Variant, keep_id: String = "-") -> void:
|
||||
edit("Change %s" % (box.title if box.title != "" else "a value"), func() -> void: box.value = value, "value:" + box.id, false)
|
||||
canvas.rebuild_except(box.id if keep_id == "-" else keep_id)
|
||||
_redraw_except(box.id if keep_id == "-" else keep_id)
|
||||
|
||||
|
||||
## The note a roll left on a box ("from Background table"), or "".
|
||||
|
|
@ -250,7 +284,14 @@ func set_value(box: SheetBox, value: Variant) -> void:
|
|||
## typing; the boxes are redrawn but the inspector keeps focus.
|
||||
func edit_config(box: SheetBox, label: String, change: Callable) -> void:
|
||||
edit(label, change, "config:%s:%s" % [box.id, label], false)
|
||||
canvas.rebuild_except("")
|
||||
_redraw_except("")
|
||||
|
||||
|
||||
## Redraws the boxes but `keep_id` on the canvas and the stacked view.
|
||||
func _redraw_except(keep_id: String) -> void:
|
||||
canvas.rebuild_except(keep_id)
|
||||
if phone and phone.stack.visible:
|
||||
phone.stack.rebuild_except(keep_id)
|
||||
|
||||
|
||||
## Opens a list entry's details in the side panel.
|
||||
|
|
|
|||
|
|
@ -72,11 +72,23 @@ static func _esc(s: String) -> String:
|
|||
|
||||
const HTML_HEAD := """<!doctype html><html><head><meta charset="utf-8"><title>%s</title>
|
||||
<style>body{font-family:Georgia,serif;max-width:42em;margin:2em auto;padding:0 1em;line-height:1.5;color:#1c0329}
|
||||
h1{font-size:1.6em;border-bottom:2px solid #823d08;padding-bottom:.2em}</style></head><body>
|
||||
h1{font-size:1.6em;border-bottom:2px solid #823d08;padding-bottom:.2em}
|
||||
h2{font-size:1.25em;color:#823d08}section+section{break-before:page}</style></head><body>
|
||||
<h1>%s</h1>
|
||||
"""
|
||||
|
||||
|
||||
## A whole sheet as a web page to print to PDF: one section per tab (each
|
||||
## printed on its own page), boxes as "Title: value" lines (SheetText).
|
||||
## `expand` fills in {@name} in text boxes (MainSheetLinks.expand).
|
||||
static func sheet_html(doc: SheetDoc, expand: Callable) -> String:
|
||||
var out := HTML_HEAD % [_esc(doc.name), _esc(doc.name)]
|
||||
for tab in doc.tabs:
|
||||
var text := str(expand.call(doc, SheetText.tab_text(doc, tab, "", false)))
|
||||
out += "<section>\n<h2>%s</h2>\n%s\n</section>\n" % [_esc(str(tab["name"])), to_html(Formatter.to_export_bbcode(text))]
|
||||
return out + "</body></html>\n"
|
||||
|
||||
|
||||
## The tray's "Save as…" submenu entry: asks where, then writes the file.
|
||||
static func save(m: Main, format_index: int) -> void:
|
||||
if m.current.is_empty():
|
||||
|
|
|
|||
69
ui/sheet_export_menu.gd
Normal file
69
ui/sheet_export_menu.gd
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
class_name SheetExportMenu
|
||||
extends RefCounted
|
||||
## The sheet editor's "Export ▾" menu (Play and Build): a share file others
|
||||
## can import (SheetFile), a web page to print or save as PDF (one page per
|
||||
## tab, SheetExport.sheet_html), and a PNG of the tab as you see it.
|
||||
|
||||
const ITEMS := ["Share file…", "Print / PDF (web page)…", "Image (PNG)…"]
|
||||
|
||||
|
||||
static func make_button(ed: SheetEditor) -> MenuButton:
|
||||
var button := Style.menu_button("Export ▾")
|
||||
button.name = "Export"
|
||||
button.tooltip_text = "Save this sheet as a file to share, print or show"
|
||||
button.get_popup().about_to_popup.connect(func() -> void: Actions.fill(button.get_popup(), actions(ed)))
|
||||
return button
|
||||
|
||||
|
||||
static func actions(ed: SheetEditor) -> Array:
|
||||
return [
|
||||
{"text": ITEMS[0], "do": share.bind(ed), "tip": "A file others can import into their Sheets"},
|
||||
{"text": ITEMS[1], "do": print_page.bind(ed), "tip": "Open it in a browser and print it, or save it as PDF. One page per tab."},
|
||||
{"text": ITEMS[2], "do": image.bind(ed), "tip": "This tab, as you see it"},
|
||||
]
|
||||
|
||||
|
||||
static func share(ed: SheetEditor) -> void:
|
||||
ed.save_now()
|
||||
ed.m.layout.export_dialog("Share sheet", SheetFile.FILTER, SheetFile.file_name(ed.doc),
|
||||
func() -> String: return SheetFile.share_text(ed.doc))
|
||||
|
||||
|
||||
static func print_page(ed: SheetEditor) -> void:
|
||||
ed.m.layout.export_dialog("Save a page to print", "*.html ; Web page", LibraryStore.slugify(ed.doc.name) + ".html",
|
||||
func() -> String: return page_html(ed))
|
||||
|
||||
|
||||
static func page_html(ed: SheetEditor) -> String:
|
||||
return SheetExport.sheet_html(ed.doc, ed.m.sheet_links.expand)
|
||||
|
||||
|
||||
## Waits for the menu to close and the canvas to draw, takes the picture,
|
||||
## then asks where to save it.
|
||||
static func image(ed: SheetEditor) -> void:
|
||||
await RenderingServer.frame_post_draw
|
||||
await RenderingServer.frame_post_draw
|
||||
var picture := capture(ed.canvas)
|
||||
if picture == null:
|
||||
ed.m.toast("Couldn't take a picture of the sheet")
|
||||
return
|
||||
var file_name := "%s-%s.png" % [LibraryStore.slugify(ed.doc.name), LibraryStore.slugify(str(ed.current_tab().get("name", "tab")))]
|
||||
ed.m.layout.file_dialog("Save a picture of this tab", ["*.png ; PNG picture"], FileDialog.FILE_MODE_SAVE_FILE, func(path: String) -> void:
|
||||
var err := picture.save_png(path)
|
||||
ed.m.toast("Exported to %s" % path.get_file() if err == OK else "Couldn't write %s" % path.get_file())
|
||||
, file_name)
|
||||
|
||||
|
||||
## The part of the window that shows `canvas`, as an Image (null when
|
||||
## nothing is drawn, as in headless runs).
|
||||
static func capture(canvas: Control) -> Image:
|
||||
if DisplayServer.get_name() == "headless":
|
||||
return null
|
||||
var shown := canvas.get_viewport().get_texture().get_image()
|
||||
if shown == null or shown.is_empty():
|
||||
return null
|
||||
var to_pixels := canvas.get_viewport().get_final_transform() * canvas.get_global_transform_with_canvas()
|
||||
var region := Rect2i(to_pixels * Rect2(Vector2.ZERO, canvas.size)).intersection(Rect2i(Vector2i.ZERO, shown.get_size()))
|
||||
if region.size.x <= 0 or region.size.y <= 0:
|
||||
return null
|
||||
return shown.get_region(region)
|
||||
1
ui/sheet_export_menu.gd.uid
Normal file
1
ui/sheet_export_menu.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cwi0dep1m2yxc
|
||||
|
|
@ -6,6 +6,18 @@ extends RefCounted
|
|||
## SheetFieldsNiche. Changes go through SheetEditor.edit_value (typing) or
|
||||
## set_value (clicks), so they can be undone.
|
||||
|
||||
## Touch targets at least this big (px) while `touch` is on.
|
||||
const TOUCH := 44.0
|
||||
|
||||
## True while the stacked phone view (SheetStackView) builds a box: buttons
|
||||
## and ticks get touch size (tap_size). Set and cleared around one build.
|
||||
static var touch := false
|
||||
|
||||
|
||||
## `normal` grown to touch size while `touch` is on.
|
||||
static func tap_size(normal: Vector2) -> Vector2:
|
||||
return normal.max(Vector2(TOUCH, TOUCH)) if touch else normal
|
||||
|
||||
|
||||
static func make(ed: SheetEditor, box: SheetBox, look: Dictionary) -> Control:
|
||||
var ink: Color = look["ink"]
|
||||
|
|
@ -168,39 +180,9 @@ static func pick_picture(ed: SheetEditor, box: SheetBox) -> void:
|
|||
ed.set_value(box, kept))
|
||||
|
||||
|
||||
## Shows the formatted text; click (Play) to edit it as BBCode, click away to see it again.
|
||||
## Long notes: formatted text, edited with a toolbar (SheetTextBox).
|
||||
static func _text(ed: SheetEditor, box: SheetBox, ink: Color) -> Control:
|
||||
var stack := Control.new()
|
||||
var shown := RichTextLabel.new()
|
||||
shown.bbcode_enabled = true
|
||||
shown.scroll_active = true
|
||||
shown.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
shown.add_theme_color_override("default_color", ink)
|
||||
shown.add_theme_font_override("normal_font", Style.body())
|
||||
shown.text = expand(ed, str(box.value if box.value != null else ""))
|
||||
if shown.text == "" and not ed.building():
|
||||
shown.text = "[i]Click to write…[/i]"
|
||||
stack.add_child(shown)
|
||||
var edit := TextEdit.new()
|
||||
edit.name = "Edit"
|
||||
edit.text = str(box.value if box.value != null else "")
|
||||
edit.wrap_mode = TextEdit.LINE_WRAPPING_BOUNDARY
|
||||
edit.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
edit.visible = false
|
||||
ModalCard.style_text_edit(edit)
|
||||
stack.add_child(edit)
|
||||
shown.gui_input.connect(func(ev: InputEvent) -> void:
|
||||
var mb := ev as InputEventMouseButton
|
||||
if mb and mb.pressed and mb.button_index == MOUSE_BUTTON_LEFT and not ed.building():
|
||||
shown.visible = false
|
||||
edit.visible = true
|
||||
edit.grab_focus())
|
||||
edit.text_changed.connect(func() -> void: ed.edit_value(box, edit.text))
|
||||
edit.focus_exited.connect(func() -> void:
|
||||
edit.visible = false
|
||||
shown.text = expand(ed, edit.text)
|
||||
shown.visible = true)
|
||||
return stack
|
||||
return SheetTextBox.make(ed, box, ink)
|
||||
|
||||
|
||||
## Live values: {@name} shows the value of the box used in tables as @name.
|
||||
|
|
@ -217,19 +199,21 @@ static func parse_number(text: String, fallback: Variant) -> Variant:
|
|||
return SheetValues.number(fallback)
|
||||
|
||||
|
||||
## A small button drawn in the box's own ink colour.
|
||||
static func step_button(text: String, ink: Color) -> Button:
|
||||
var b := Button.new()
|
||||
b.text = text
|
||||
b.custom_minimum_size = Vector2(26, 26)
|
||||
b.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.add_theme_font_override("font", Style.body_bold())
|
||||
b.add_theme_font_size_override("font_size", 15)
|
||||
## A small button drawn in the box's own ink colour. Pass `button` to skin another
|
||||
## kind of button (a MenuButton).
|
||||
static func step_button(text: String, ink: Color, button: Button = null) -> Button:
|
||||
if button == null:
|
||||
button = Button.new()
|
||||
button.text = text
|
||||
button.custom_minimum_size = tap_size(Vector2(26, 26))
|
||||
button.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
button.focus_mode = Control.FOCUS_NONE
|
||||
button.add_theme_font_override("font", Style.body_bold())
|
||||
button.add_theme_font_size_override("font_size", 15)
|
||||
var normal := Style.bordered(Style.box(Color(ink, 0.04), 6, [6, 0, 6, 0]), 1, Color(ink, 0.35))
|
||||
var hover := Style.bordered(Style.box(Color(ink, 0.12), 6, [6, 0, 6, 0]), 1, Color(ink, 0.6))
|
||||
Style.skin_button(b, normal, hover, hover, ink, ink, ink)
|
||||
return b
|
||||
Style.skin_button(button, normal, hover, hover, ink, ink, ink)
|
||||
return button
|
||||
|
||||
|
||||
## A muted label in the box's ink.
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ extends RefCounted
|
|||
## Hovering an entry shows a short excerpt of its details; ⓘ opens them in
|
||||
## the side panel (SheetDetailPanel). With a point pool (config "pool") the
|
||||
## cost column's total comes off the pool; going over is allowed and shows red.
|
||||
## A row from a Lore Entry (SheetLoreDrop) may hold "lore" (linked: shown with
|
||||
## §) and "sheet" (its item sheet: ▤ opens it).
|
||||
|
||||
const EXCERPT := 110
|
||||
|
||||
|
|
@ -90,6 +92,12 @@ static func _row(ed: SheetEditor, box: SheetBox, ink: Color, cols: Array, rows:
|
|||
var entry: Dictionary = rows[i]
|
||||
row.tooltip_text = excerpt(entry, cols)
|
||||
row.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
if entry.has("lore"):
|
||||
var mark := Style.make_label("§", Style.body_bold(), 14, Style.REF_INK)
|
||||
mark.name = "LoreMark"
|
||||
mark.tooltip_text = "Linked to a Lore Entry: ⓘ to read it"
|
||||
mark.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
row.add_child(mark)
|
||||
for k in cols.size():
|
||||
var c: Dictionary = cols[k]
|
||||
var key := str(c["name"])
|
||||
|
|
@ -119,6 +127,8 @@ static func _row(ed: SheetEditor, box: SheetBox, ink: Color, cols: Array, rows:
|
|||
_show_pool(box, pool_label, ink))
|
||||
row.add_child(cell)
|
||||
row.add_child(_info_button(ed, box, i, ink))
|
||||
if str(entry.get("sheet", "")) != "":
|
||||
row.add_child(sheet_button(ed, str(entry["sheet"]), ink))
|
||||
if not ed.building():
|
||||
var remove := SheetFieldViews.step_button("×", ink)
|
||||
remove.name = "Remove"
|
||||
|
|
@ -140,6 +150,20 @@ static func _info_button(ed: SheetEditor, box: SheetBox, i: int, ink: Color) ->
|
|||
return b
|
||||
|
||||
|
||||
## ▤: opens an item's sheet (SheetItemNav, with a way back).
|
||||
static func sheet_button(ed: SheetEditor, sheet_id: String, ink: Color) -> Button:
|
||||
var b := SheetFieldViews.step_button("▤", ink)
|
||||
b.name = "OpenSheet"
|
||||
b.tooltip_text = "Open its sheet"
|
||||
b.pressed.connect(func() -> void: ed.nav.open(sheet_id))
|
||||
return b
|
||||
|
||||
|
||||
## "§ " before a linked entry's name, else "".
|
||||
static func link_mark(entry: Dictionary) -> String:
|
||||
return "§ " if entry.has("lore") else ""
|
||||
|
||||
|
||||
static func _size_cell(c: Control, col: Dictionary) -> void:
|
||||
if col.get("type", "text") == "number":
|
||||
c.custom_minimum_size.x = 44
|
||||
|
|
@ -168,7 +192,7 @@ static func _chips(ed: SheetEditor, box: SheetBox, ink: Color) -> HFlowContainer
|
|||
var parts: Array = []
|
||||
for c: Dictionary in cols:
|
||||
parts.append(SheetValues.show(entry.get(c["name"], "")) if c.get("type", "text") == "number" else str(entry.get(c["name"], "")))
|
||||
var chip := SheetFieldViews.step_button(" ".join(parts).strip_edges(), ink)
|
||||
var chip := SheetFieldViews.step_button(link_mark(entry) + " ".join(parts).strip_edges(), ink)
|
||||
chip.name = "Chip%d" % i
|
||||
chip.tooltip_text = excerpt(entry, cols) + "\nClick for details · right-click to remove"
|
||||
var index := i
|
||||
|
|
|
|||
|
|
@ -47,9 +47,9 @@ static func _slots(ed: SheetEditor, box: SheetBox, ink: Color) -> Control:
|
|||
var it: Dictionary = items[i]
|
||||
var size := maxi(1, int(SheetValues.number(it.get("size", 1))))
|
||||
for k in size:
|
||||
var b := SheetFieldViews.step_button(str(it.get("name", "")) if k == 0 else "↳", ink)
|
||||
var b := SheetFieldViews.step_button(SheetFieldsList.link_mark(it) + str(it.get("name", "")) if k == 0 else "↳", ink)
|
||||
b.name = "Item%d_%d" % [i, k]
|
||||
b.custom_minimum_size = Vector2(0, 26)
|
||||
b.custom_minimum_size = SheetFieldViews.tap_size(Vector2(0, 26))
|
||||
b.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
b.clip_text = true
|
||||
b.tooltip_text = "%s · %d %s · click to change" % [it.get("name", ""), size, "slot" if size == 1 else "slots"]
|
||||
|
|
@ -59,7 +59,7 @@ static func _slots(ed: SheetEditor, box: SheetBox, ink: Color) -> Control:
|
|||
cell += 1
|
||||
while cell < total:
|
||||
var empty := PanelContainer.new()
|
||||
empty.custom_minimum_size = Vector2(0, 26)
|
||||
empty.custom_minimum_size = SheetFieldViews.tap_size(Vector2(0, 26))
|
||||
empty.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
empty.add_theme_stylebox_override("panel", Style.bordered(Style.box(Color(0, 0, 0, 0), 6), 1, Color(ink, 0.25)))
|
||||
grid.add_child(empty)
|
||||
|
|
@ -88,7 +88,15 @@ static func _item_menu(ed: SheetEditor, box: SheetBox, index: int, at: Control)
|
|||
var next := _items(box)
|
||||
next[index]["size"] = maxi(1, int(SheetValues.number(next[index].get("size", 1))) + delta)
|
||||
ed.set_value(box, next)
|
||||
Actions.popup_at(ed.m, [
|
||||
var item: Dictionary = _items(box)[index]
|
||||
var extra: Array = []
|
||||
if str(item.get("sheet", "")) != "":
|
||||
extra.append({"text": "Open its sheet", "do": ed.nav.open.bind(str(item["sheet"]))})
|
||||
if item.has("lore"):
|
||||
extra.append({"text": "Read the Lore Entry", "do": ed.details.open_lore.bind(str(item["lore"]))})
|
||||
if not extra.is_empty():
|
||||
extra.append({"sep": ""})
|
||||
Actions.popup_at(ed.m, extra + [
|
||||
{"text": "Bigger (one more slot)", "do": change.bind(1)},
|
||||
{"text": "Smaller", "do": change.bind(-1)},
|
||||
{"text": "Remove", "do": func() -> void:
|
||||
|
|
@ -149,7 +157,7 @@ static func _spell_slots(ed: SheetEditor, box: SheetBox, ink: Color) -> Control:
|
|||
var b := Button.new()
|
||||
b.name = "Slot%d_%d" % [i, k + 1]
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.custom_minimum_size = Vector2(18, 18)
|
||||
b.custom_minimum_size = SheetFieldViews.tap_size(Vector2(18, 18))
|
||||
var on := k < marked
|
||||
var sb := Style.bordered(Style.box(ink if on else Color(0, 0, 0, 0), 9), 2, ink if on else Color(ink, 0.55))
|
||||
Style.skin_button(b, sb, sb, sb, ink)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ static func _dice(ed: SheetEditor, box: SheetBox, ink: Color) -> Control:
|
|||
var b := SheetFieldViews.step_button("Roll", ink)
|
||||
b.tooltip_text = "Roll %s" % dice
|
||||
b.name = "Roll"
|
||||
b.custom_minimum_size.y = 32
|
||||
b.custom_minimum_size.y = maxf(32, b.custom_minimum_size.y)
|
||||
b.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
|
||||
col.add_child(b)
|
||||
var last := SheetFieldViews.note("%s · %s" % [dice, str(box.value) if box.value != null else "not rolled yet"], ink, 12)
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ static func _marks(ed: SheetEditor, box: SheetBox, ink: Color, count: int, round
|
|||
var b := Button.new()
|
||||
b.name = "Mark%d" % (i + 1)
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.custom_minimum_size = Vector2(18, 18)
|
||||
b.custom_minimum_size = SheetFieldViews.tap_size(Vector2(18, 18))
|
||||
var on := i < marked
|
||||
var radius := 9 if round else 3
|
||||
var sb := Style.bordered(Style.box(ink if on else Color(0, 0, 0, 0), radius), 2, ink if on else Color(ink, 0.55))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
class_name SheetInspector
|
||||
extends PanelContainer
|
||||
## The sheet editor's right dock (Build only), laid out like the mockup and the
|
||||
## spread's: "Inspector | Lore Index" tabs, a caps kind label over the name,
|
||||
## spread's: "Inspector | Lore Index" tabs (the Lore tab shows SheetLoreDock in
|
||||
## its place), a caps kind label over the name,
|
||||
## then settings. With a box selected: its title, colour, frame, phone order,
|
||||
## "Use in tables" and "Lock against rolls". With nothing selected: the
|
||||
## sheet's name, tint and Save as template.
|
||||
|
|
@ -11,7 +12,6 @@ const INSPECTOR := "inspector"
|
|||
const LORE := "lore"
|
||||
|
||||
var ed: SheetEditor
|
||||
var tab := INSPECTOR
|
||||
var _col: VBoxContainer
|
||||
|
||||
|
||||
|
|
@ -34,12 +34,8 @@ func rebuild() -> void:
|
|||
c.queue_free()
|
||||
if ed.doc == null or not ed.building():
|
||||
return
|
||||
_col.add_child(SideTabs.tab_row([[INSPECTOR, "Inspector"], [LORE, "Lore Index"]], tab, func(which: String) -> void:
|
||||
tab = which
|
||||
rebuild()))
|
||||
if tab == LORE:
|
||||
_col.add_child(_note("Lore Entries on sheets come in a later step: hover links, and items such as a rolled sword you drag into an inventory."))
|
||||
return
|
||||
_col.add_child(SideTabs.tab_row([[INSPECTOR, "Inspector"], [LORE, "Lore Index"]], INSPECTOR, func(which: String) -> void:
|
||||
ed.set_lore_shown(which == LORE)))
|
||||
var box := ed.doc.find_box(ed.selected) if ed.selected != "" else null
|
||||
if box:
|
||||
_box_section(box)
|
||||
|
|
|
|||
65
ui/sheet_item_nav.gd
Normal file
65
ui/sheet_item_nav.gd
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
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)
|
||||
1
ui/sheet_item_nav.gd.uid
Normal file
1
ui/sheet_item_nav.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bjqn3iifp8s6v
|
||||
40
ui/sheet_lore_dock.gd
Normal file
40
ui/sheet_lore_dock.gd
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
class_name SheetLoreDock
|
||||
extends PanelContainer
|
||||
## The Lore Index inside the sheet editor (Play and Build): the shared
|
||||
## LoreList, with the "Inspector | Lore Index" tabs on top in Build (as on the
|
||||
## spread). Drag a Lore Entry onto a box: SheetLoreDrop adds it there.
|
||||
## Shown with SheetEditor.set_lore_shown (top bar "Lore Index", the tab).
|
||||
|
||||
const WIDTH := 340.0
|
||||
|
||||
var ed: SheetEditor
|
||||
var lore: LoreList
|
||||
var _tabs: HBoxContainer
|
||||
|
||||
|
||||
func setup(p_editor: SheetEditor) -> void:
|
||||
ed = p_editor
|
||||
custom_minimum_size.x = WIDTH
|
||||
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.tab_row([[SheetInspector.INSPECTOR, "Inspector"], [SheetInspector.LORE, "Lore Index"]], SheetInspector.LORE,
|
||||
func(which: String) -> void: ed.set_lore_shown(which == SheetInspector.LORE))
|
||||
col.add_child(_tabs)
|
||||
lore = LoreList.new()
|
||||
lore.name = "LoreList"
|
||||
lore.size_flags_vertical = SIZE_EXPAND_FILL
|
||||
lore.setup(ed.m, func() -> void: ed.set_lore_shown(false))
|
||||
lore.dropped.connect(func(page: BookPage, level: LoreLevel, at: Vector2) -> void:
|
||||
SheetLoreDrop.drop(ed, page, level, at, Input.is_key_pressed(KEY_SHIFT)))
|
||||
lore.open_sheet = func(id: String) -> void: ed.nav.open(id)
|
||||
col.add_child(lore)
|
||||
visible = false
|
||||
|
||||
|
||||
## Build shows the tabs in place of the title, as on the spread.
|
||||
func sync() -> void:
|
||||
_tabs.visible = ed.building()
|
||||
SideTabs.press(_tabs, SheetInspector.LORE)
|
||||
lore.title.visible = not ed.building()
|
||||
1
ui/sheet_lore_dock.gd.uid
Normal file
1
ui/sheet_lore_dock.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://oi6b5go0678j
|
||||
56
ui/sheet_lore_drop.gd
Normal file
56
ui/sheet_lore_drop.gd
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
class_name SheetLoreDrop
|
||||
extends RefCounted
|
||||
## A Lore Entry dropped on a sheet box (from SheetLoreDock), as one undo step:
|
||||
## onto a list box it adds a row (the entry's name, its text as "details");
|
||||
## onto a Slots box an item; onto a Long notes box a link (SheetLoreLinks).
|
||||
## A drop copies: its item sheet is copied too (SheetItems). With Shift held
|
||||
## the row stays linked: "lore" holds the link ref and "sheet" the entry's
|
||||
## own sheet. Linked rows show § (SheetFieldsList.link_mark).
|
||||
|
||||
const TAKES := [SheetKinds.LIST, SheetKinds.SLOTS, SheetKinds.TEXT]
|
||||
|
||||
|
||||
## Drops `page` at screen point `at`. True when a box took it.
|
||||
static func drop(ed: SheetEditor, page: BookPage, level: LoreLevel, at: Vector2, linked: bool) -> bool:
|
||||
var box := box_at(ed, at)
|
||||
if box == null:
|
||||
return false
|
||||
if not box.kind in TAKES:
|
||||
ed.m.toast("Drop a Lore Entry on a list, Slots or Long notes box")
|
||||
return false
|
||||
add(ed, box, page, level.ref(page), linked)
|
||||
return true
|
||||
|
||||
|
||||
## The box whose view is under screen point `at`, or null.
|
||||
static func box_at(ed: SheetEditor, at: Vector2) -> SheetBox:
|
||||
for view: SheetBoxView in ed.canvas.views.values():
|
||||
if is_instance_valid(view) and view.is_visible_in_tree() and view.get_global_rect().has_point(at):
|
||||
return view.box
|
||||
return null
|
||||
|
||||
|
||||
## Adds `page` to `box` (a list, Slots or Long notes box) as one undo step.
|
||||
static func add(ed: SheetEditor, box: SheetBox, page: BookPage, link_ref: String, linked: bool) -> void:
|
||||
var name := Formatter.strip_tags(page.label()).strip_edges()
|
||||
var value: Variant
|
||||
match box.kind:
|
||||
SheetKinds.TEXT:
|
||||
var text := str(box.value if box.value != null else "")
|
||||
value = text + (" " if text != "" and not text.ends_with("\n") else "") + SheetLoreLinks.tag_for(link_ref) + SheetLoreLinks.shown_name(page) + "[/url]"
|
||||
SheetKinds.SLOTS:
|
||||
value = SheetFieldsList.entries(box)
|
||||
value.append(SheetItems.with_links({"name": name, "size": 1}, page, link_ref, linked, ed.screen.store))
|
||||
_:
|
||||
var row := {}
|
||||
var cols := SheetFieldsList.columns(box)
|
||||
for col: Dictionary in cols:
|
||||
row[col["name"]] = 0 if col.get("type", "text") == "number" else ""
|
||||
row[str(cols[0]["name"])] = name
|
||||
var details := SheetItems.plain_text(page)
|
||||
if details != "":
|
||||
row["details"] = details
|
||||
value = SheetFieldsList.entries(box)
|
||||
value.append(SheetItems.with_links(row, page, link_ref, linked, ed.screen.store))
|
||||
ed.set_value(box, value)
|
||||
ed.m.toast("Added “%s” to %s%s" % [name, box.title if box.title != "" else "the box", " (linked)" if linked else ""])
|
||||
1
ui/sheet_lore_drop.gd.uid
Normal file
1
ui/sheet_lore_drop.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://sh44juvi7vdv
|
||||
92
ui/sheet_lore_links.gd
Normal file
92
ui/sheet_lore_links.gd
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
class_name SheetLoreLinks
|
||||
extends RefCounted
|
||||
## Links to Lore Entries (BookPage) in sheet text. The link is plain BBCode:
|
||||
## [url=lore:ENTRY_ID]shown words[/url]. RichText.decorate draws it in the
|
||||
## reference colours; hovering shows the entry's name and the start of its
|
||||
## text (DetailsPopup "lore:"); a click in a sheet opens it in the side panel
|
||||
## (SheetDetailPanel.open_lore).
|
||||
##
|
||||
## Which Lore Index: two levels. The open spread's (Main.data.book) and the
|
||||
## shared "My library" (LoreLibrary, kept by SheetsScreen). A link to a
|
||||
## library entry says so: [url=lore:lib:ID]; a plain lore:ID is the spread's.
|
||||
## entries() and find() are the one place that decides.
|
||||
|
||||
const META := "lore:"
|
||||
## The level mark in a link ref for a "My library" entry.
|
||||
const LIBRARY := "lib:"
|
||||
## Longest hover excerpt, in characters (as for list entries).
|
||||
const EXCERPT := 140
|
||||
|
||||
|
||||
## The shared "My library" level, or null before the screens are built.
|
||||
static func library(m: Main) -> LoreLibrary:
|
||||
if m == null or m.screens == null or m.screens.sheets == null:
|
||||
return null
|
||||
return m.screens.sheets.library
|
||||
|
||||
|
||||
## Every Lore Entry a sheet can link to: the spread's, then My library's.
|
||||
static func entries(m: Main) -> Array[BookPage]:
|
||||
var out: Array[BookPage] = []
|
||||
if m != null and m.data != null:
|
||||
out.assign(m.data.book)
|
||||
var shared := library(m)
|
||||
if shared:
|
||||
out.append_array(shared.pages)
|
||||
return out
|
||||
|
||||
|
||||
## What a link to `page` holds after "lore:": its id, or "lib:" + id for a
|
||||
## My library entry.
|
||||
static func ref(m: Main, page: BookPage) -> String:
|
||||
var shared := library(m)
|
||||
return LIBRARY + page.id if shared and shared.pages.has(page) else page.id
|
||||
|
||||
|
||||
## The Lore Entry a link ref points at, or null when it is gone.
|
||||
static func find(m: Main, link_ref: String) -> BookPage:
|
||||
if link_ref.begins_with(LIBRARY):
|
||||
var shared := library(m)
|
||||
return shared.get_page(link_ref.substr(LIBRARY.length())) if shared else null
|
||||
return m.data.get_page(link_ref) if m != null and m.data != null else null
|
||||
|
||||
|
||||
## The entries whose name, text or tags match every word of `query`.
|
||||
static func search(m: Main, query: String) -> Array[BookPage]:
|
||||
var out: Array[BookPage] = []
|
||||
var words := query.strip_edges().to_lower().split(" ", false)
|
||||
for page in entries(m):
|
||||
var hay := " ".join([page.label(), Formatter.strip_tags(page.text), " ".join(page.tags)]).to_lower()
|
||||
if Array(words).all(func(word: String) -> bool: return hay.contains(word)):
|
||||
out.append(page)
|
||||
return out
|
||||
|
||||
|
||||
## The opening tag of a link to `page`.
|
||||
static func open_tag(m: Main, page: BookPage) -> String:
|
||||
return tag_for(ref(m, page))
|
||||
|
||||
|
||||
## The opening tag of a link with ref `link_ref` ("ID" or "lib:ID").
|
||||
static func tag_for(link_ref: String) -> String:
|
||||
return "[url=%s%s]" % [META, link_ref]
|
||||
|
||||
|
||||
## The words a link shows when nothing was selected: the entry's name.
|
||||
static func shown_name(page: BookPage) -> String:
|
||||
return RichText.plain(Formatter.strip_tags(page.label()).strip_edges())
|
||||
|
||||
|
||||
## The entry's text and details without formatting, cut with "…".
|
||||
static func excerpt(page: BookPage) -> String:
|
||||
return RulesView.cut(SheetItems.plain_text(page).replace("\n", " "), EXCERPT)
|
||||
|
||||
|
||||
## Fills the hover pop-up for the link with ref `link_ref`.
|
||||
static func show_hover(m: Main, owner: Control, link_ref: String) -> void:
|
||||
var page := find(m, link_ref)
|
||||
if page == null:
|
||||
m.details().show_for(owner, "A missing Lore Entry", "This Lore Entry was deleted, or it is in another spread's Lore Index.")
|
||||
return
|
||||
var body := RichText.plain(excerpt(page))
|
||||
m.details().show_for(owner, page.label(), body if body != "" else "[i]No text yet[/i]", "Lore Entry · click to read it all")
|
||||
1
ui/sheet_lore_links.gd.uid
Normal file
1
ui/sheet_lore_links.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cfvht7q66drcp
|
||||
145
ui/sheet_phone_layout.gd
Normal file
145
ui/sheet_phone_layout.gd
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
class_name SheetPhoneLayout
|
||||
extends RefCounted
|
||||
## The sheet editor in the phone layout (MobileLayout). Play shows the
|
||||
## stacked view (SheetStackView) by default; the bottom bar has Undo and a
|
||||
## Stacked | Canvas switch (Play), or "+" for the field palette (Build, which
|
||||
## always uses the canvas). The palette opens full screen; picking a field
|
||||
## goes back to the canvas. The inspector (with a box selected), the Lore
|
||||
## Index and the details panel open as bottom panels, not side docks.
|
||||
|
||||
## Height of a bottom panel (inspector, Lore Index, details).
|
||||
const PANEL_HEIGHT := 360.0
|
||||
|
||||
var ed: SheetEditor
|
||||
var stack: SheetStackView
|
||||
## The player's choice in Play: the stacked view (true) or the real canvas.
|
||||
var stacked := true
|
||||
var palette_open := false
|
||||
var bar: PanelContainer
|
||||
var stacked_button: Button
|
||||
var canvas_button: Button
|
||||
var undo_button: Button
|
||||
var add_button: Button
|
||||
|
||||
|
||||
func _init(p_editor: SheetEditor) -> void:
|
||||
ed = p_editor
|
||||
|
||||
|
||||
func apply() -> void:
|
||||
var middle := ed.canvas.get_parent()
|
||||
stack = SheetStackView.new()
|
||||
stack.setup(ed)
|
||||
stack.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
middle.add_child(stack)
|
||||
middle.move_child(stack, ed.canvas.get_index() + 1)
|
||||
ed.palette_dock.visible = false
|
||||
ed.palette_dock.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
# The side docks become bottom panels under the canvas.
|
||||
for dock: Control in [ed.inspector, ed.lore_dock, ed.details]:
|
||||
middle.remove_child(dock)
|
||||
ed.add_child(dock)
|
||||
ed.move_child(dock, middle.get_index() + 1)
|
||||
dock.custom_minimum_size = Vector2(0, PANEL_HEIGHT)
|
||||
_style_bottom_sheet(ed.details)
|
||||
# The bottom bar takes the status strip's place.
|
||||
var strip := ed.status_label.get_parent().get_parent() as Control
|
||||
strip.visible = false
|
||||
bar = _make_bar()
|
||||
ed.add_child(bar)
|
||||
ed.move_child(bar, strip.get_index())
|
||||
var top := ed.top_bar
|
||||
for control: Control in [top._hint, top.export_button, top.brand_title, top.lore_button]:
|
||||
control.visible = false
|
||||
# The sheet's name takes the room the hint had, cut short when long.
|
||||
top.name_button.clip_text = true
|
||||
top.name_button.get_parent().size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
|
||||
|
||||
func _make_bar() -> PanelContainer:
|
||||
var panel := PanelContainer.new()
|
||||
panel.name = "PhoneBar"
|
||||
panel.add_theme_stylebox_override("panel", Style.box(Style.BG_DEEP.darkened(0.25), 0, [12, 6, 12, 6]))
|
||||
var row := HBoxContainer.new()
|
||||
row.add_theme_constant_override("separation", 8)
|
||||
panel.add_child(row)
|
||||
undo_button = _bar_button("↶ Undo")
|
||||
undo_button.pressed.connect(ed.undo)
|
||||
row.add_child(undo_button)
|
||||
var gap := Control.new()
|
||||
gap.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
row.add_child(gap)
|
||||
var group := ButtonGroup.new()
|
||||
stacked_button = MainTopBar.seg_button("Stacked", group)
|
||||
canvas_button = MainTopBar.seg_button("Canvas", group)
|
||||
stacked_button.name = "Stacked"
|
||||
canvas_button.name = "Canvas"
|
||||
for button: Button in [stacked_button, canvas_button]:
|
||||
button.custom_minimum_size.y = SheetFieldViews.TOUCH
|
||||
stacked_button.pressed.connect(show_stacked.bind(true))
|
||||
canvas_button.pressed.connect(show_stacked.bind(false))
|
||||
row.add_child(stacked_button)
|
||||
row.add_child(canvas_button)
|
||||
add_button = _bar_button("+ Field")
|
||||
add_button.tooltip_text = "Add a field"
|
||||
add_button.pressed.connect(show_palette.bind(true))
|
||||
row.add_child(add_button)
|
||||
return panel
|
||||
|
||||
|
||||
func _bar_button(text: String) -> Button:
|
||||
var button := Style.bar_button(text)
|
||||
button.custom_minimum_size = Vector2(SheetFieldViews.TOUCH, SheetFieldViews.TOUCH)
|
||||
return button
|
||||
|
||||
|
||||
## A panel from the bottom: rounded top corners and a line on top.
|
||||
static func _style_bottom_sheet(panel: PanelContainer) -> void:
|
||||
var sheet := Style.box(Style.CARD_SOFT, 14, [18, 14, 18, 14])
|
||||
sheet.corner_radius_bottom_left = 0
|
||||
sheet.corner_radius_bottom_right = 0
|
||||
sheet.border_color = Style.DASH
|
||||
sheet.border_width_top = 1
|
||||
panel.add_theme_stylebox_override("panel", sheet)
|
||||
|
||||
|
||||
## Play: the stacked view (true) or the real canvas (pan by dragging).
|
||||
func show_stacked(on: bool) -> void:
|
||||
stacked = on
|
||||
ed.refresh()
|
||||
|
||||
|
||||
func show_palette(on: bool) -> void:
|
||||
palette_open = on and ed.building()
|
||||
sync()
|
||||
|
||||
|
||||
## True when the stacked view shows in place of the canvas.
|
||||
func stack_shown() -> bool:
|
||||
return stacked and not ed.building()
|
||||
|
||||
|
||||
## Brings the views and the bar in line with the mode (SheetEditor.refresh
|
||||
## and select call it); rebuilds the stacked view when `redraw`.
|
||||
func sync(redraw: bool = false) -> void:
|
||||
if not ed.building():
|
||||
palette_open = false
|
||||
var on := stack_shown()
|
||||
stack.visible = on and not palette_open
|
||||
ed.canvas.visible = not on and not palette_open
|
||||
ed.palette_dock.visible = palette_open
|
||||
if on and redraw:
|
||||
stack.rebuild()
|
||||
# A small screen: the inspector only while a box is selected.
|
||||
ed.inspector.visible = ed.building() and not ed.lore_shown and ed.selected != "" and not palette_open
|
||||
stacked_button.visible = not ed.building()
|
||||
canvas_button.visible = not ed.building()
|
||||
stacked_button.set_pressed_no_signal(stacked)
|
||||
canvas_button.set_pressed_no_signal(not stacked)
|
||||
add_button.visible = ed.building() and not palette_open
|
||||
sync_undo()
|
||||
|
||||
|
||||
func sync_undo() -> void:
|
||||
undo_button.disabled = not ed.history.can_undo()
|
||||
undo_button.modulate.a = 1.0 if ed.history.can_undo() else 0.45
|
||||
1
ui/sheet_phone_layout.gd.uid
Normal file
1
ui/sheet_phone_layout.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://l1tiwr5ehyso
|
||||
95
ui/sheet_stack_view.gd
Normal file
95
ui/sheet_stack_view.gd
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
class_name SheetStackView
|
||||
extends ScrollContainer
|
||||
## The phone's Play view of a sheet tab (the "stacked view"): every box of
|
||||
## the open tab in one full-width column, in phone order (order_of). Each box
|
||||
## is the same SheetBoxView as on the canvas, built with touch-size buttons
|
||||
## and ticks (SheetFieldViews.touch). SheetPhoneLayout swaps it with the canvas.
|
||||
|
||||
const GAP := 10
|
||||
const PAD := 12
|
||||
|
||||
var ed: SheetEditor
|
||||
var column: VBoxContainer
|
||||
var views: Dictionary = {} # box id -> SheetBoxView
|
||||
var _backdrop: BoardBackdrop
|
||||
|
||||
|
||||
func setup(p_editor: SheetEditor) -> void:
|
||||
ed = p_editor
|
||||
name = "StackView"
|
||||
horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
add_theme_stylebox_override("panel", StyleBoxEmpty.new())
|
||||
_backdrop = BoardBackdrop.new(ThemeStore.current)
|
||||
draw.connect(func() -> void: _backdrop.draw(self, Rect2(Vector2.ZERO, size)))
|
||||
var pad := MarginContainer.new()
|
||||
pad.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
for side in ["left", "top", "right", "bottom"]:
|
||||
pad.add_theme_constant_override("margin_" + side, PAD)
|
||||
add_child(pad)
|
||||
column = VBoxContainer.new()
|
||||
column.add_theme_constant_override("separation", GAP)
|
||||
pad.add_child(column)
|
||||
|
||||
|
||||
## Phone order: boxes with a Phone order number come first, smallest first;
|
||||
## then the automatic ones (0) in reading order: top-down, then left-right.
|
||||
## Equal numbers also fall back to reading order.
|
||||
static func order_of(boxes: Array) -> Array:
|
||||
var sorted := boxes.duplicate()
|
||||
sorted.sort_custom(func(first: SheetBox, second: SheetBox) -> bool:
|
||||
var first_rank := first.phone_order if first.phone_order > 0 else 1 << 30
|
||||
var second_rank := second.phone_order if second.phone_order > 0 else 1 << 30
|
||||
if first_rank != second_rank:
|
||||
return first_rank < second_rank
|
||||
if first.y != second.y:
|
||||
return first.y < second.y
|
||||
return first.x < second.x)
|
||||
return sorted
|
||||
|
||||
|
||||
func rebuild() -> void:
|
||||
for child in column.get_children():
|
||||
column.remove_child(child)
|
||||
child.queue_free()
|
||||
views.clear()
|
||||
for box: SheetBox in order_of(ed.current_tab()["boxes"]):
|
||||
var view := _make_view(box)
|
||||
column.add_child(view)
|
||||
_fit_height(view)
|
||||
views[box.id] = view
|
||||
queue_redraw()
|
||||
|
||||
|
||||
## Redraws every box but `keep_id` (the one being typed in), as the canvas does.
|
||||
func rebuild_except(keep_id: String) -> void:
|
||||
for id: String in views.keys():
|
||||
if id == keep_id:
|
||||
continue
|
||||
var box := ed.doc.find_box(id)
|
||||
var old: SheetBoxView = views[id]
|
||||
if box == null:
|
||||
continue
|
||||
var view := _make_view(box)
|
||||
column.add_child(view)
|
||||
column.move_child(view, old.get_index())
|
||||
column.remove_child(old)
|
||||
old.queue_free()
|
||||
_fit_height(view)
|
||||
views[id] = view
|
||||
|
||||
|
||||
## A box view at full width, its buttons and ticks at touch size.
|
||||
func _make_view(box: SheetBox) -> SheetBoxView:
|
||||
var view := SheetBoxView.new()
|
||||
SheetFieldViews.touch = true
|
||||
view.setup(ed, box)
|
||||
SheetFieldViews.touch = false
|
||||
view.custom_minimum_size = Vector2(0, box.h)
|
||||
view.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
return view
|
||||
|
||||
|
||||
## The box's own height, or taller when its bigger buttons need it.
|
||||
func _fit_height(view: SheetBoxView) -> void:
|
||||
var content := view.get_child(0) as Control
|
||||
view.custom_minimum_size.y = maxf(view.box.h, content.get_combined_minimum_size().y)
|
||||
1
ui/sheet_stack_view.gd.uid
Normal file
1
ui/sheet_stack_view.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ctp0c75f48e6c
|
||||
76
ui/sheet_text_box.gd
Normal file
76
ui/sheet_text_box.gd
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
class_name SheetTextBox
|
||||
extends RefCounted
|
||||
## The Long notes box (SheetKinds.TEXT): formatted text with live {@values}
|
||||
## and Lore Entry links (SheetLoreLinks). In Play, click it to edit the BBCode
|
||||
## with a formatting toolbar above (SheetTextToolbar); click away to see the
|
||||
## text again. Hovering a Lore Entry link shows its start; clicking it opens
|
||||
## the entry in the side panel instead of editing.
|
||||
|
||||
|
||||
static func make(ed: SheetEditor, box: SheetBox, ink: Color) -> Control:
|
||||
var stack := Control.new()
|
||||
var shown := RichTextLabel.new()
|
||||
shown.name = "Shown"
|
||||
shown.bbcode_enabled = true
|
||||
shown.scroll_active = true
|
||||
shown.meta_underlined = false
|
||||
RichText.install_effects(shown)
|
||||
shown.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
shown.add_theme_color_override("default_color", ink)
|
||||
shown.add_theme_font_override("normal_font", Style.body())
|
||||
shown.text = render(ed, str(box.value if box.value != null else ""))
|
||||
if shown.text == "" and not ed.building():
|
||||
shown.text = "[i]Click to write…[/i]"
|
||||
stack.add_child(shown)
|
||||
var editing := VBoxContainer.new()
|
||||
editing.name = "Editing"
|
||||
editing.add_theme_constant_override("separation", 4)
|
||||
editing.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
editing.visible = false
|
||||
stack.add_child(editing)
|
||||
var edit := TextEdit.new()
|
||||
edit.name = "Edit"
|
||||
edit.text = str(box.value if box.value != null else "")
|
||||
edit.wrap_mode = TextEdit.LINE_WRAPPING_BOUNDARY
|
||||
edit.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
# Keep the selection while a toolbar menu is open.
|
||||
edit.deselect_on_focus_loss_enabled = false
|
||||
ModalCard.style_text_edit(edit)
|
||||
FormatMenu.attach(edit)
|
||||
var toolbar := SheetTextToolbar.new(ed, box, edit, ink)
|
||||
editing.add_child(toolbar)
|
||||
editing.add_child(edit)
|
||||
# The link under the mouse ("" = none): a click there opens it, not the editor.
|
||||
var hovered := {"meta": ""}
|
||||
shown.meta_hover_started.connect(func(meta: Variant) -> void:
|
||||
hovered["meta"] = str(meta)
|
||||
ed.m.details().show_meta(shown, str(meta)))
|
||||
shown.meta_hover_ended.connect(func(_meta: Variant) -> void:
|
||||
hovered["meta"] = ""
|
||||
ed.m.details().hide_for(shown))
|
||||
shown.meta_clicked.connect(func(meta: Variant) -> void: open_link(ed, str(meta)))
|
||||
shown.gui_input.connect(func(ev: InputEvent) -> void:
|
||||
var mb := ev as InputEventMouseButton
|
||||
if mb and mb.pressed and mb.button_index == MOUSE_BUTTON_LEFT and not ed.building() and hovered["meta"] == "":
|
||||
shown.visible = false
|
||||
editing.visible = true
|
||||
edit.grab_focus())
|
||||
edit.text_changed.connect(func() -> void: ed.edit_value(box, edit.text))
|
||||
toolbar.shown = shown
|
||||
# Deferred on the toolbar: a box redrawn meanwhile drops the call.
|
||||
edit.focus_exited.connect(func() -> void: toolbar.call_deferred("stop_editing"))
|
||||
toolbar.menu_closed.connect(func() -> void:
|
||||
if editing.visible:
|
||||
edit.grab_focus())
|
||||
return stack
|
||||
|
||||
|
||||
## The text as shown: live values filled in, links in the reference colours.
|
||||
static func render(ed: SheetEditor, text: String) -> String:
|
||||
return RichText.decorate(SheetFieldViews.expand(ed, text))
|
||||
|
||||
|
||||
## A click on a link: a Lore Entry opens in the side panel.
|
||||
static func open_link(ed: SheetEditor, meta: String) -> void:
|
||||
if meta.begins_with(SheetLoreLinks.META):
|
||||
ed.details.open_lore(meta.substr(SheetLoreLinks.META.length()))
|
||||
1
ui/sheet_text_box.gd.uid
Normal file
1
ui/sheet_text_box.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://p1627w4lv65d
|
||||
108
ui/sheet_text_toolbar.gd
Normal file
108
ui/sheet_text_toolbar.gd
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
class_name SheetTextToolbar
|
||||
extends HFlowContainer
|
||||
## The formatting buttons above a sheet text box while you edit it: bold,
|
||||
## italic, underline, strike-through, then Colour, Size and Effect menus,
|
||||
## live values ({@name}) and "Link a Lore Entry…". The tags come from
|
||||
## FormatMenu (the same as its right-click menu), which also wraps the
|
||||
## selection. Buttons take no focus, so the text keeps its selection.
|
||||
|
||||
## A toolbar menu closed: the text box takes the focus back.
|
||||
signal menu_closed
|
||||
|
||||
var ed: SheetEditor
|
||||
var box: SheetBox
|
||||
var edit: TextEdit
|
||||
## The formatted text shown when not editing (SheetTextBox).
|
||||
var shown: RichTextLabel
|
||||
var _menus: Array[PopupMenu] = []
|
||||
|
||||
|
||||
func _init(p_editor: SheetEditor, p_box: SheetBox, p_edit: TextEdit, ink: Color) -> void:
|
||||
ed = p_editor
|
||||
box = p_box
|
||||
edit = p_edit
|
||||
name = "Toolbar"
|
||||
add_theme_constant_override("h_separation", 3)
|
||||
add_theme_constant_override("v_separation", 3)
|
||||
var short := {"Bold": "B", "Italic": "I", "Underline": "U", "Strike-through": "S"}
|
||||
for style: Array in FormatMenu.STYLES:
|
||||
var button := _small(SheetFieldViews.step_button(short[style[0]], ink))
|
||||
button.name = str(style[0]).validate_node_name()
|
||||
button.tooltip_text = str(style[0])
|
||||
button.pressed.connect(FormatMenu.wrap_selection.bind(edit, style[1], style[2]))
|
||||
add_child(button)
|
||||
_menu("Colour", FormatMenu.colours(), ink)
|
||||
_menu("Size", FormatMenu.SIZES, ink)
|
||||
_menu("Effect", FormatMenu.EFFECTS, ink)
|
||||
var values := _menu("{@}", [], ink, "Values", "Show a live value: a box with Use in tables on")
|
||||
values.about_to_popup.connect(func() -> void: _fill_values(values))
|
||||
var link := _small(SheetFieldViews.step_button("§ Link…", ink))
|
||||
link.name = "LoreLink"
|
||||
link.tooltip_text = "Link a Lore Entry…"
|
||||
link.pressed.connect(pick_lore)
|
||||
add_child(link)
|
||||
|
||||
|
||||
## Shows the formatted text again once the text box lost the focus (not to
|
||||
## one of the toolbar's menus).
|
||||
func stop_editing() -> void:
|
||||
if edit.has_focus() or menu_open() or shown == null:
|
||||
return
|
||||
get_parent().visible = false
|
||||
shown.text = SheetTextBox.render(ed, edit.text)
|
||||
shown.visible = true
|
||||
|
||||
|
||||
## Smaller than the boxes' own buttons, so the text keeps the room.
|
||||
func _small(button: Button) -> Button:
|
||||
button.custom_minimum_size = Vector2(20, 20)
|
||||
button.add_theme_font_size_override("font_size", 12)
|
||||
return button
|
||||
|
||||
|
||||
## True while one of the toolbar's menus is open.
|
||||
func menu_open() -> bool:
|
||||
return _menus.any(func(menu: PopupMenu) -> bool: return menu.visible)
|
||||
|
||||
|
||||
## A menu button whose items wrap the selection in [label, open, close] tags.
|
||||
func _menu(label: String, items: Array, ink: Color, node_name: String = "", tip: String = "") -> PopupMenu:
|
||||
var button := _small(SheetFieldViews.step_button(label + " ▾", ink, MenuButton.new()))
|
||||
button.name = node_name if node_name != "" else label
|
||||
button.tooltip_text = tip if tip != "" else label
|
||||
add_child(button)
|
||||
var menu := (button as MenuButton).get_popup()
|
||||
ModalCard.style_popup(menu)
|
||||
for i in items.size():
|
||||
menu.add_item(str(items[i][0]), i)
|
||||
menu.id_pressed.connect(func(id: int) -> void:
|
||||
var current: Array = menu.get_meta("items", items)
|
||||
if id >= 0 and id < current.size():
|
||||
FormatMenu.wrap_selection(edit, str(current[id][1]), str(current[id][2])))
|
||||
menu.popup_hide.connect(func() -> void: menu_closed.emit())
|
||||
_menus.append(menu)
|
||||
return menu
|
||||
|
||||
|
||||
## The sheet's @names, each putting {@name} at the cursor.
|
||||
func _fill_values(menu: PopupMenu) -> void:
|
||||
menu.clear()
|
||||
var items: Array = []
|
||||
for value_name: String in SheetValues.vars(ed.doc):
|
||||
items.append(["@" + value_name, "{@%s}" % value_name, ""])
|
||||
menu.add_item("@" + value_name, items.size() - 1)
|
||||
if items.is_empty():
|
||||
menu.add_item("No values yet: turn on Use in tables in a box (Build)", 999)
|
||||
menu.set_item_disabled(0, true)
|
||||
menu.set_meta("items", items)
|
||||
|
||||
|
||||
## Asks for a Lore Entry, then links the selection to it (or adds its name).
|
||||
func pick_lore() -> void:
|
||||
var selected := FormatMenu.selection(edit)
|
||||
var text := edit.text
|
||||
var picker := LoreLinkPicker.new(ed.m, func(page: BookPage) -> void:
|
||||
var words := "" if selected.x != selected.y else SheetLoreLinks.shown_name(page)
|
||||
var result := TableSettingsRules.wrap_text(text, selected, SheetLoreLinks.open_tag(ed.m, page) + words, "[/url]")
|
||||
ed.set_value(box, str(result["text"])))
|
||||
ed.m._add_modal(picker)
|
||||
1
ui/sheet_text_toolbar.gd.uid
Normal file
1
ui/sheet_text_toolbar.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bpp5pjdx6rxsc
|
||||
|
|
@ -3,7 +3,9 @@ extends PanelContainer
|
|||
## The sheet editor's top bar, the same layout as the spread's (MainTopBar):
|
||||
## the brand (click: main menu), Play | Build, a SHEET caption over the sheet's
|
||||
## name (click: switch sheet, all sheets, rename), the mode hint, and in Build
|
||||
## Field palette, Undo, Redo and Save as template…; ☰ at the end.
|
||||
## Field palette, Undo, Redo and Save as template…; Lore Index and Export ▾
|
||||
## (both modes, SheetExportMenu) and ☰ at the end. The back button leads to
|
||||
## the sheet an item sheet was opened from, or to the spread (SheetItemNav).
|
||||
|
||||
const HINTS := {
|
||||
Main.Mode.PLAY: "Type in the boxes to change values.",
|
||||
|
|
@ -21,6 +23,10 @@ var _hint: Label
|
|||
var _tools: HBoxContainer
|
||||
## "← Spread name" when the sheet was opened from a spread.
|
||||
var back_button: Button
|
||||
var export_button: MenuButton
|
||||
var lore_button: Button
|
||||
## The "Table Tarot" words beside the logo (hidden on phones).
|
||||
var brand_title: Label
|
||||
|
||||
|
||||
func setup(p_editor: SheetEditor) -> void:
|
||||
|
|
@ -29,11 +35,13 @@ func setup(p_editor: SheetEditor) -> void:
|
|||
var h := HBoxContainer.new()
|
||||
h.add_theme_constant_override("separation", 10)
|
||||
add_child(h)
|
||||
h.add_child(MainTopBar.make_brand(func() -> void: ed.m.screens.show(MainScreens.MENU)))
|
||||
var brand := MainTopBar.make_brand(func() -> void: ed.m.screens.show(MainScreens.MENU))
|
||||
brand_title = brand.get_child(brand.get_child_count() - 1)
|
||||
h.add_child(brand)
|
||||
back_button = Style.bar_button("")
|
||||
back_button.name = "BackToSpread"
|
||||
back_button.tooltip_text = "Back to the spread this sheet sits on"
|
||||
back_button.pressed.connect(func() -> void: ed.back_to_spread())
|
||||
back_button.tooltip_text = "Back to where you opened this sheet from"
|
||||
back_button.pressed.connect(func() -> void: ed.nav.back())
|
||||
h.add_child(back_button)
|
||||
var seg := PanelContainer.new()
|
||||
seg.add_theme_stylebox_override("panel", Style.box(Color(0, 0, 0, 0.28), 9, [3, 3, 3, 3]))
|
||||
|
|
@ -85,6 +93,15 @@ func setup(p_editor: SheetEditor) -> void:
|
|||
var template := Style.bar_button("Save as template…")
|
||||
template.pressed.connect(save_as_template)
|
||||
_tools.add_child(template)
|
||||
lore_button = Style.bar_button("Lore Index")
|
||||
lore_button.name = "LoreIndex"
|
||||
lore_button.toggle_mode = true
|
||||
lore_button.focus_mode = Control.FOCUS_NONE
|
||||
lore_button.tooltip_text = "Show or hide the Lore Index: drag an entry onto a box to add it"
|
||||
lore_button.pressed.connect(func() -> void: ed.set_lore_shown(not ed.lore_shown))
|
||||
h.add_child(lore_button)
|
||||
export_button = SheetExportMenu.make_button(ed)
|
||||
h.add_child(export_button)
|
||||
var actions := Style.menu_button("☰")
|
||||
actions.tooltip_text = "Main menu, all sheets, theme…"
|
||||
actions.get_popup().about_to_popup.connect(func() -> void: Actions.fill(actions.get_popup(), _actions()))
|
||||
|
|
@ -92,7 +109,7 @@ func setup(p_editor: SheetEditor) -> void:
|
|||
|
||||
|
||||
func _actions() -> Array:
|
||||
return [
|
||||
var list: Array = [
|
||||
{"text": "Main menu", "do": ed.m.screens.show.bind(MainScreens.MENU)},
|
||||
{"text": "All sheets", "do": ed.screen.show_list},
|
||||
{"sep": ""},
|
||||
|
|
@ -101,6 +118,12 @@ func _actions() -> Array:
|
|||
{"sep": ""},
|
||||
{"text": "Theme…", "do": func() -> void: ed.m.add_child(ThemeDialog.new(ed.m))},
|
||||
]
|
||||
if ed.phone:
|
||||
# Phones have no room for Lore Index and Export ▾ on the bar.
|
||||
list.append({"sep": ""})
|
||||
list.append({"text": "Hide the Lore Index" if ed.lore_shown else "Lore Index", "do": func() -> void: ed.set_lore_shown(not ed.lore_shown)})
|
||||
list.append_array(SheetExportMenu.actions(ed))
|
||||
return list
|
||||
|
||||
|
||||
## The name button's menu: your other sheets, All sheets, Rename.
|
||||
|
|
@ -136,10 +159,12 @@ func sync() -> void:
|
|||
play_button.set_pressed_no_signal(not build)
|
||||
build_button.set_pressed_no_signal(build)
|
||||
name_button.text = "%s ▾" % ed.doc.name
|
||||
back_button.visible = ed.from_spread != ""
|
||||
back_button.text = "← %s" % ed.from_spread
|
||||
back_button.text = ed.nav.back_label()
|
||||
back_button.visible = back_button.text != ""
|
||||
lore_button.set_pressed_no_signal(ed.lore_shown)
|
||||
_hint.text = HINTS[ed.mode]
|
||||
_tools.visible = build
|
||||
# Phones have Undo and "+ Field" in the bottom bar (SheetPhoneLayout).
|
||||
_tools.visible = build and ed.phone == null
|
||||
palette_button.set_pressed_no_signal(ed.palette_dock.visible)
|
||||
undo_button.disabled = not ed.history.can_undo()
|
||||
redo_button.disabled = not ed.history.can_redo()
|
||||
|
|
@ -147,3 +172,5 @@ func sync() -> void:
|
|||
redo_button.modulate.a = 1.0 if ed.history.can_redo() else 0.45
|
||||
undo_button.tooltip_text = "Undo: %s (Ctrl+Z)" % ed.history.undo_label() if ed.history.can_undo() else "Nothing to undo"
|
||||
redo_button.tooltip_text = "Redo: %s (Ctrl+Shift+Z)" % ed.history.redo_label() if ed.history.can_redo() else "Nothing to redo"
|
||||
if ed.phone:
|
||||
ed.phone.sync_undo()
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ const SCRATCH := "user://scratch_sheets/"
|
|||
|
||||
var m: Main
|
||||
var store: SheetStore
|
||||
## "My library": the shared Lore Index level, beside the sheets (same root).
|
||||
var library: LoreLibrary
|
||||
var editor: SheetEditor
|
||||
var list_page: VBoxContainer
|
||||
var scratch := SCRATCH
|
||||
|
|
@ -27,6 +29,7 @@ func setup(p_main: Main) -> void:
|
|||
scratch = SCRATCH.path_join(str(OS.get_process_id()))
|
||||
_wipe_scratch()
|
||||
store = SheetStore.new(scratch)
|
||||
library = LoreLibrary.new(store.root)
|
||||
var stack := Control.new()
|
||||
add_child(stack)
|
||||
list_page = _make_list_page()
|
||||
|
|
@ -61,6 +64,11 @@ func _make_list_page() -> VBoxContainer:
|
|||
var where := Style.make_label("Sheets", Style.body(), 15, Style.ON_BG_MUTED)
|
||||
where.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
head.add_child(where)
|
||||
var import_button := Style.bar_button("Import…")
|
||||
import_button.name = "ImportSheet"
|
||||
import_button.tooltip_text = "Add a sheet from a share file someone sent you"
|
||||
import_button.pressed.connect(import_sheet)
|
||||
head.add_child(import_button)
|
||||
var add := Style.bar_button("+ New sheet", true)
|
||||
add.name = "NewSheet"
|
||||
add.pressed.connect(open_new_sheet)
|
||||
|
|
@ -166,14 +174,30 @@ func _empty_note(text: String) -> Label:
|
|||
|
||||
## "+ New sheet": asks for a name and a start (blank or a template).
|
||||
## `on_made` gets the new sheet instead of opening it (the card palette
|
||||
## places it on the spread).
|
||||
## places it on the spread). The dialog can also import a sheet file.
|
||||
func open_new_sheet(template_id: String = "", on_made: Callable = Callable()) -> void:
|
||||
m._add_modal(NewSheetDialog.new(store, template_id, func(name: String, tpl: String) -> void:
|
||||
var on_create := func(name: String, tpl: String) -> void:
|
||||
var doc := store.create(name, tpl)
|
||||
if on_made.is_valid():
|
||||
on_made.call(doc)
|
||||
else:
|
||||
open_doc(doc)))
|
||||
open_doc(doc)
|
||||
m._add_modal(NewSheetDialog.new(store, template_id, on_create, import_sheet.bind(on_made)))
|
||||
|
||||
|
||||
## "Import a sheet file…": asks for a share file (SheetFile), saves it as a
|
||||
## new sheet and opens it (or hands it to `on_made`, as above).
|
||||
func import_sheet(on_made: Callable = Callable()) -> void:
|
||||
m.layout.file_dialog("Import a sheet file", [SheetFile.FILTER], FileDialog.FILE_MODE_OPEN_FILE, func(path: String) -> void:
|
||||
var doc := SheetFile.import_path(store, path)
|
||||
if doc == null:
|
||||
m.toast("That isn't a sheet file")
|
||||
return
|
||||
m.toast("Imported “%s”" % doc.name)
|
||||
if on_made.is_valid():
|
||||
on_made.call(doc)
|
||||
else:
|
||||
open_doc(doc))
|
||||
|
||||
|
||||
func open_sheet(id: String) -> void:
|
||||
|
|
@ -207,6 +231,7 @@ func _delete(id: String, name: String, templates: bool) -> void:
|
|||
|
||||
|
||||
func _wipe_scratch() -> void:
|
||||
DirAccess.remove_absolute(scratch.path_join(LoreLibrary.FILE))
|
||||
for templates: bool in [false, true]:
|
||||
var dir := scratch.path_join(SheetStore.TEMPLATES if templates else SheetStore.SHEETS)
|
||||
if DirAccess.dir_exists_absolute(dir):
|
||||
|
|
|
|||
Loading…
Reference in a new issue