Sheets phase B: main menu, Sheets list, sheet editor
- Main menu (Spreads, Sheets, Settings, Quit) on the theme background,
with recent spreads and sheets; logo or ☰ returns to it.
- Sheets: data model, store, templates, snapshot undo; New sheet dialog
(blank or a template); editor with folder tabs, snap-grid canvas on the
spread background, field palette, inspector, Play/Build, status strip.
- Field kinds: Number, Text box (BBCode, live {@name}), Heading.
- PaletteList shared by the card and field palettes; shared top bar brand.
- Keys go to the screen that shows; theme reloads keep the screen.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
16b34c40f6
commit
2661744b06
57 changed files with 2955 additions and 171 deletions
80
core/sheet_box.gd
Normal file
80
core/sheet_box.gd
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
class_name SheetBox
|
||||
extends RefCounted
|
||||
## One box on a sheet tab: a field (a number, a text box, a heading…) placed
|
||||
## freely on the tab's canvas. `kind` picks how it looks and behaves
|
||||
## (SheetKinds); `config` holds the kind's settings and `value` what the
|
||||
## player filled in, so new kinds need no new fields here.
|
||||
|
||||
var id: String = ""
|
||||
var kind: String = SheetKinds.TEXT
|
||||
var title: String = ""
|
||||
## Position and size on the tab, in canvas pixels (snapped to SheetKinds.GRID
|
||||
## unless placed freely with Alt).
|
||||
var x: float = 0.0
|
||||
var y: float = 0.0
|
||||
var w: float = 192.0
|
||||
var h: float = 96.0
|
||||
## Box colour as "#rrggbb", or "" for the theme's card colour.
|
||||
var color: String = ""
|
||||
var frameless: bool = false
|
||||
## Place in the stacked phone view (0 = automatic: reading order).
|
||||
var phone_order: int = 0
|
||||
## Tables can read and write the box as @var_name ("" = not used in tables).
|
||||
var var_name: String = ""
|
||||
## Locked boxes ignore values written by rolls.
|
||||
var locked: bool = false
|
||||
var config: Dictionary = {}
|
||||
var value: Variant = null
|
||||
|
||||
|
||||
func _init(p_id: String = "", p_kind: String = SheetKinds.TEXT) -> void:
|
||||
id = p_id
|
||||
kind = p_kind
|
||||
|
||||
|
||||
func rect() -> Rect2:
|
||||
return Rect2(x, y, w, h)
|
||||
|
||||
|
||||
func set_rect(r: Rect2) -> void:
|
||||
x = r.position.x
|
||||
y = r.position.y
|
||||
w = r.size.x
|
||||
h = r.size.y
|
||||
|
||||
|
||||
func to_dict() -> Dictionary:
|
||||
var d := {"id": id, "kind": kind, "title": title, "x": x, "y": y, "w": w, "h": h}
|
||||
if color != "":
|
||||
d["color"] = color
|
||||
if frameless:
|
||||
d["frameless"] = true
|
||||
if phone_order != 0:
|
||||
d["phone_order"] = phone_order
|
||||
if var_name != "":
|
||||
d["var"] = var_name
|
||||
if locked:
|
||||
d["locked"] = true
|
||||
if not config.is_empty():
|
||||
d["config"] = config.duplicate(true)
|
||||
if value != null:
|
||||
d["value"] = value.duplicate(true) if value is Array or value is Dictionary else value
|
||||
return d
|
||||
|
||||
|
||||
static func from_dict(d: Dictionary) -> SheetBox:
|
||||
var box := SheetBox.new(str(d.get("id", "")), str(d.get("kind", SheetKinds.TEXT)))
|
||||
box.title = str(d.get("title", ""))
|
||||
box.x = float(d.get("x", 0))
|
||||
box.y = float(d.get("y", 0))
|
||||
box.w = float(d.get("w", 192))
|
||||
box.h = float(d.get("h", 96))
|
||||
box.color = str(d.get("color", ""))
|
||||
box.frameless = bool(d.get("frameless", false))
|
||||
box.phone_order = int(d.get("phone_order", 0))
|
||||
box.var_name = str(d.get("var", ""))
|
||||
box.locked = bool(d.get("locked", false))
|
||||
var cfg: Variant = d.get("config", {})
|
||||
box.config = (cfg as Dictionary).duplicate(true) if cfg is Dictionary else {}
|
||||
box.value = d.get("value", null)
|
||||
return box
|
||||
1
core/sheet_box.gd.uid
Normal file
1
core/sheet_box.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ceappwewpq0oa
|
||||
35
core/sheet_demo.gd
Normal file
35
core/sheet_demo.gd
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
class_name SheetDemo
|
||||
extends RefCounted
|
||||
## A small example sheet (an OSR knight) for screenshots (--sheet-demo) and
|
||||
## tests. Uses only the kinds built so far.
|
||||
|
||||
|
||||
static func create(id: String = "demo-brin") -> SheetDoc:
|
||||
var doc := SheetDoc.new(id, "Brin Hollowmere")
|
||||
var boxes: Array = doc.tabs[0]["boxes"]
|
||||
var title := _add(doc, boxes, SheetKinds.HEADING, "Brin Hollowmere", Vector2(16, 16), Vector2(28, 3), null)
|
||||
title.frameless = true
|
||||
var col := 0
|
||||
for stat: Array in [["Strength", "str", 14], ["Dexterity", "dex", 9], ["Willpower", "wil", 12]]:
|
||||
var b := _add(doc, boxes, SheetKinds.NUMBER, stat[0], Vector2(16 + col * 144, 80), Vector2(8, 5), stat[2])
|
||||
b.var_name = stat[1]
|
||||
col += 1
|
||||
var hp := _add(doc, boxes, SheetKinds.NUMBER, "Hit points", Vector2(16, 176), Vector2(8, 5), 6)
|
||||
hp.color = "#b8382c"
|
||||
_add(doc, boxes, SheetKinds.TEXT, "Background", Vector2(464, 80), Vector2(18, 8),
|
||||
"[b]Hedge knight[/b] from the river marches. Strength {@str}.")
|
||||
_add(doc, boxes, SheetKinds.TEXT, "Notes", Vector2(160, 176), Vector2(18, 7),
|
||||
"Owes the ferryman two silver.")
|
||||
doc.add_tab("Spells")
|
||||
doc.add_tab("Notes")
|
||||
return doc
|
||||
|
||||
|
||||
static func _add(doc: SheetDoc, boxes: Array, kind: String, title: String, at: Vector2, grid_size: Vector2, value: Variant) -> SheetBox:
|
||||
var b := SheetKinds.make_box(kind, doc.new_box_id(), at)
|
||||
b.title = title
|
||||
b.w = grid_size.x * SheetKinds.GRID
|
||||
b.h = grid_size.y * SheetKinds.GRID
|
||||
b.value = value
|
||||
boxes.append(b)
|
||||
return b
|
||||
1
core/sheet_demo.gd.uid
Normal file
1
core/sheet_demo.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b0f2v0kle4b3b
|
||||
115
core/sheet_doc.gd
Normal file
115
core/sheet_doc.gd
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
class_name SheetDoc
|
||||
extends RefCounted
|
||||
## A sheet: a character, a vehicle, anything you keep track of. It has tabs
|
||||
## (Main, Spells, Notes…), each a free canvas of boxes (SheetBox). Saved as
|
||||
## JSON by SheetStore; a template is a sheet saved in the templates folder.
|
||||
## Spec: docs/SHEETS.md.
|
||||
|
||||
const FORMAT_VERSION := 1
|
||||
|
||||
var id: String = ""
|
||||
var name: String = "New sheet"
|
||||
## Sheet tint as "#rrggbb" ("" = the theme's), e.g. to tell vehicles apart.
|
||||
var tint: String = ""
|
||||
## The template this sheet was made from ("" = blank).
|
||||
var from_template: String = ""
|
||||
## Each tab: {"id", "name", "boxes": Array[SheetBox]}.
|
||||
var tabs: Array[Dictionary] = []
|
||||
|
||||
|
||||
func _init(p_id: String = "", p_name: String = "New sheet") -> void:
|
||||
id = p_id
|
||||
name = p_name
|
||||
if tabs.is_empty():
|
||||
add_tab("Main")
|
||||
|
||||
|
||||
func add_tab(tab_name: String) -> Dictionary:
|
||||
var boxes: Array[SheetBox] = []
|
||||
var tab := {"id": new_tab_id(), "name": tab_name, "boxes": boxes}
|
||||
tabs.append(tab)
|
||||
return tab
|
||||
|
||||
|
||||
func new_tab_id() -> String:
|
||||
var n := tabs.size() + 1
|
||||
while tabs.any(func(t: Dictionary) -> bool: return t["id"] == "tab%d" % n):
|
||||
n += 1
|
||||
return "tab%d" % n
|
||||
|
||||
|
||||
func get_tab(tab_id: String) -> Dictionary:
|
||||
for tab in tabs:
|
||||
if tab["id"] == tab_id:
|
||||
return tab
|
||||
return {}
|
||||
|
||||
|
||||
## The box with `box_id` on any tab, or null.
|
||||
func find_box(box_id: String) -> SheetBox:
|
||||
for tab in tabs:
|
||||
for box: SheetBox in tab["boxes"]:
|
||||
if box.id == box_id:
|
||||
return box
|
||||
return null
|
||||
|
||||
|
||||
## The tab that holds `box_id` ({} if none).
|
||||
func tab_of(box_id: String) -> Dictionary:
|
||||
for tab in tabs:
|
||||
for box: SheetBox in tab["boxes"]:
|
||||
if box.id == box_id:
|
||||
return tab
|
||||
return {}
|
||||
|
||||
|
||||
## A box id not used on this sheet.
|
||||
func new_box_id() -> String:
|
||||
var n := 1
|
||||
while find_box("b%d" % n) != null:
|
||||
n += 1
|
||||
return "b%d" % n
|
||||
|
||||
|
||||
func remove_box(box_id: String) -> void:
|
||||
var tab := tab_of(box_id)
|
||||
if not tab.is_empty():
|
||||
(tab["boxes"] as Array).assign((tab["boxes"] as Array).filter(func(b: SheetBox) -> bool: return b.id != box_id))
|
||||
|
||||
|
||||
func to_dict() -> Dictionary:
|
||||
var tab_list: Array = []
|
||||
for tab in tabs:
|
||||
var boxes: Array = []
|
||||
for box: SheetBox in tab["boxes"]:
|
||||
boxes.append(box.to_dict())
|
||||
tab_list.append({"id": tab["id"], "name": tab["name"], "boxes": boxes})
|
||||
var d := {"format_version": FORMAT_VERSION, "id": id, "name": name, "tabs": tab_list}
|
||||
if tint != "":
|
||||
d["tint"] = tint
|
||||
if from_template != "":
|
||||
d["from_template"] = from_template
|
||||
return d
|
||||
|
||||
|
||||
static func from_dict(d: Dictionary) -> SheetDoc:
|
||||
var doc := SheetDoc.new(str(d.get("id", "")), str(d.get("name", "New sheet")))
|
||||
doc.tint = str(d.get("tint", ""))
|
||||
doc.from_template = str(d.get("from_template", ""))
|
||||
var tab_list: Variant = d.get("tabs", [])
|
||||
if tab_list is Array and not (tab_list as Array).is_empty():
|
||||
doc.tabs.clear()
|
||||
for td: Variant in tab_list:
|
||||
if not td is Dictionary:
|
||||
continue
|
||||
var boxes: Array[SheetBox] = []
|
||||
for bd: Variant in (td as Dictionary).get("boxes", []):
|
||||
if bd is Dictionary:
|
||||
boxes.append(SheetBox.from_dict(bd))
|
||||
doc.tabs.append({"id": str(td.get("id", doc.new_tab_id())), "name": str(td.get("name", "Tab")), "boxes": boxes})
|
||||
return doc
|
||||
|
||||
|
||||
## A deep copy (through the saved form), e.g. a new sheet from a template.
|
||||
func copy() -> SheetDoc:
|
||||
return SheetDoc.from_dict(to_dict())
|
||||
1
core/sheet_doc.gd.uid
Normal file
1
core/sheet_doc.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dpnmmdfjlsfhb
|
||||
61
core/sheet_kinds.gd
Normal file
61
core/sheet_kinds.gd
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
class_name SheetKinds
|
||||
extends RefCounted
|
||||
## Every kind of box you can put on a sheet, in one list: the field palette,
|
||||
## new boxes' starting size, title and value, and search all read it (the
|
||||
## sheet's version of CardCatalog). More kinds come in later phases
|
||||
## (docs/SHEETS.md §4 C).
|
||||
|
||||
## The snap grid's step, in canvas pixels.
|
||||
const GRID := 16.0
|
||||
|
||||
const HEADING := "heading"
|
||||
const TEXT := "text"
|
||||
const NUMBER := "number"
|
||||
|
||||
const GROUP_BASICS := "Basics"
|
||||
const GROUP_LAYOUT := "Layout"
|
||||
|
||||
## Each item: kind, label, group, tip, search words, start size (w, h in grid
|
||||
## steps), title and value.
|
||||
const ITEMS := [
|
||||
{"kind": NUMBER, "label": "Number", "group": GROUP_BASICS, "tip": "A stat or count, like Strength 14 or Gold 30",
|
||||
"words": "stat score value count", "w": 8, "h": 4, "title": "Number", "value": 0},
|
||||
{"kind": TEXT, "label": "Text box", "group": GROUP_BASICS, "tip": "Notes or a description, with formatting and live values like {@str}",
|
||||
"words": "notes description bbcode long", "w": 14, "h": 8, "title": "Notes", "value": ""},
|
||||
{"kind": HEADING, "label": "Heading", "group": GROUP_LAYOUT, "tip": "A title to label part of the sheet",
|
||||
"words": "title label section", "w": 14, "h": 3, "title": "Heading", "value": null},
|
||||
]
|
||||
|
||||
|
||||
static func find(kind: String) -> Dictionary:
|
||||
for item: Dictionary in ITEMS:
|
||||
if item["kind"] == kind:
|
||||
return item
|
||||
return {}
|
||||
|
||||
|
||||
static func groups() -> Array[String]:
|
||||
var out: Array[String] = []
|
||||
for item: Dictionary in ITEMS:
|
||||
if not out.has(item["group"]):
|
||||
out.append(item["group"])
|
||||
return out
|
||||
|
||||
|
||||
## A new box of `kind` with its start size, title and value, top-left at `at`.
|
||||
static func make_box(kind: String, id: String, at: Vector2) -> SheetBox:
|
||||
var item := find(kind)
|
||||
var box := SheetBox.new(id, kind)
|
||||
box.title = str(item.get("title", ""))
|
||||
box.x = snap(at.x)
|
||||
box.y = snap(at.y)
|
||||
box.w = float(item.get("w", 12)) * GRID
|
||||
box.h = float(item.get("h", 6)) * GRID
|
||||
var start: Variant = item.get("value", null)
|
||||
box.value = start.duplicate(true) if start is Array or start is Dictionary else start
|
||||
return box
|
||||
|
||||
|
||||
## Rounds to the nearest grid step.
|
||||
static func snap(v: float) -> float:
|
||||
return roundf(v / GRID) * GRID
|
||||
1
core/sheet_kinds.gd.uid
Normal file
1
core/sheet_kinds.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ddb544613vx0g
|
||||
111
core/sheet_store.gd
Normal file
111
core/sheet_store.gd
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
class_name SheetStore
|
||||
extends RefCounted
|
||||
## Sheets and sheet templates as JSON files: user://sheets/<id>.json and
|
||||
## user://sheet_templates/<id>.json. `root` can point elsewhere for tests.
|
||||
|
||||
const SHEETS := "sheets"
|
||||
const TEMPLATES := "sheet_templates"
|
||||
|
||||
var root := "user://"
|
||||
|
||||
|
||||
func _init(p_root: String = "user://") -> void:
|
||||
root = p_root
|
||||
|
||||
|
||||
func dir_for(templates: bool) -> String:
|
||||
return root.path_join(TEMPLATES if templates else SHEETS)
|
||||
|
||||
|
||||
func path_for(id: String, templates: bool) -> String:
|
||||
return dir_for(templates).path_join(id + ".json")
|
||||
|
||||
|
||||
## Rows for the Sheets list, newest first: {id, name, modified, from_template}.
|
||||
func list(templates: bool = false) -> Array[Dictionary]:
|
||||
var out: Array[Dictionary] = []
|
||||
var dir := dir_for(templates)
|
||||
if not DirAccess.dir_exists_absolute(dir):
|
||||
return out
|
||||
for file in DirAccess.get_files_at(dir):
|
||||
if not file.ends_with(".json"):
|
||||
continue
|
||||
var path := dir.path_join(file)
|
||||
var d := _read(path)
|
||||
if d.is_empty():
|
||||
continue
|
||||
out.append({"id": file.get_basename(), "name": str(d.get("name", file.get_basename())),
|
||||
"modified": FileAccess.get_modified_time(path), "from_template": str(d.get("from_template", ""))})
|
||||
out.sort_custom(func(a: Dictionary, b: Dictionary) -> bool: return int(a["modified"]) > int(b["modified"]))
|
||||
return out
|
||||
|
||||
|
||||
## The sheet with `id`, or null.
|
||||
func load_sheet(id: String, templates: bool = false) -> SheetDoc:
|
||||
if not LibraryStore.is_valid_id(id):
|
||||
return null
|
||||
var d := _read(path_for(id, templates))
|
||||
if d.is_empty():
|
||||
return null
|
||||
var doc := SheetDoc.from_dict(d)
|
||||
doc.id = id
|
||||
return doc
|
||||
|
||||
|
||||
func save(doc: SheetDoc, templates: bool = false) -> Error:
|
||||
if not LibraryStore.is_valid_id(doc.id):
|
||||
return ERR_INVALID_PARAMETER
|
||||
DirAccess.make_dir_recursive_absolute(dir_for(templates))
|
||||
return BoardFileIO.write_text_atomic(path_for(doc.id, templates), JSON.stringify(doc.to_dict(), "\t"))
|
||||
|
||||
|
||||
func delete(id: String, templates: bool = false) -> Error:
|
||||
if not LibraryStore.is_valid_id(id):
|
||||
return ERR_INVALID_PARAMETER
|
||||
return DirAccess.remove_absolute(path_for(id, templates))
|
||||
|
||||
|
||||
## A file id from `name` not used yet in that folder ("brin", "brin-2"…).
|
||||
func free_id(name: String, templates: bool = false) -> String:
|
||||
var base := LibraryStore.slugify(name)
|
||||
if base == "":
|
||||
base = "sheet"
|
||||
var id := base
|
||||
var n := 2
|
||||
while FileAccess.file_exists(path_for(id, templates)):
|
||||
id = "%s-%d" % [base, n]
|
||||
n += 1
|
||||
return id
|
||||
|
||||
|
||||
## A new sheet, blank or copied from a template, saved and returned.
|
||||
func create(name: String, template_id: String = "") -> SheetDoc:
|
||||
var doc: SheetDoc = null
|
||||
if template_id != "":
|
||||
var tpl := load_sheet(template_id, true)
|
||||
if tpl:
|
||||
doc = tpl.copy()
|
||||
doc.from_template = template_id
|
||||
if doc == null:
|
||||
doc = SheetDoc.new()
|
||||
doc.name = name
|
||||
doc.id = free_id(name)
|
||||
save(doc)
|
||||
return doc
|
||||
|
||||
|
||||
## Saves a copy of `doc` as a template named `name`; returns its id.
|
||||
func save_as_template(doc: SheetDoc, name: String) -> String:
|
||||
var tpl := doc.copy()
|
||||
tpl.name = name
|
||||
tpl.from_template = ""
|
||||
tpl.id = free_id(name, true)
|
||||
save(tpl, true)
|
||||
return tpl.id
|
||||
|
||||
|
||||
func _read(path: String) -> Dictionary:
|
||||
if not FileAccess.file_exists(path):
|
||||
return {}
|
||||
var parsed: Variant = JSON.parse_string(FileAccess.get_file_as_string(path))
|
||||
return parsed if parsed is Dictionary else {}
|
||||
1
core/sheet_store.gd.uid
Normal file
1
core/sheet_store.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://f35bed3tfxiq
|
||||
57
core/snapshot_history.gd
Normal file
57
core/snapshot_history.gd
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
class_name SnapshotHistory
|
||||
extends RefCounted
|
||||
## Undo and redo by whole snapshots (Dictionaries), for small documents such
|
||||
## as a sheet. The caller records the state before each edit (record) and
|
||||
## gets back the state to show on undo or redo. Spreads use EditHistory, which
|
||||
## keeps per-card strings because spreads can be large.
|
||||
|
||||
const MAX_STEPS := 200
|
||||
|
||||
var _undo: Array = [] # [{"state", "label"}]
|
||||
var _redo: Array = []
|
||||
|
||||
|
||||
func can_undo() -> bool:
|
||||
return not _undo.is_empty()
|
||||
|
||||
|
||||
func can_redo() -> bool:
|
||||
return not _redo.is_empty()
|
||||
|
||||
|
||||
func undo_label() -> String:
|
||||
return str(_undo.back()["label"]) if can_undo() else ""
|
||||
|
||||
|
||||
func redo_label() -> String:
|
||||
return str(_redo.back()["label"]) if can_redo() else ""
|
||||
|
||||
|
||||
func clear() -> void:
|
||||
_undo.clear()
|
||||
_redo.clear()
|
||||
|
||||
|
||||
## Records `before`, the state just before an edit called `label`. Clears redo.
|
||||
func record(before: Dictionary, label: String) -> void:
|
||||
_undo.append({"state": before.duplicate(true), "label": label})
|
||||
if _undo.size() > MAX_STEPS:
|
||||
_undo.pop_front()
|
||||
_redo.clear()
|
||||
|
||||
|
||||
## Steps back: give the current state, get the one to show ({} if none).
|
||||
func undo(current: Dictionary) -> Dictionary:
|
||||
if not can_undo():
|
||||
return {}
|
||||
var step: Dictionary = _undo.pop_back()
|
||||
_redo.append({"state": current.duplicate(true), "label": step["label"]})
|
||||
return step["state"]
|
||||
|
||||
|
||||
func redo(current: Dictionary) -> Dictionary:
|
||||
if not can_redo():
|
||||
return {}
|
||||
var step: Dictionary = _redo.pop_back()
|
||||
_undo.append({"state": current.duplicate(true), "label": step["label"]})
|
||||
return step["state"]
|
||||
1
core/snapshot_history.gd.uid
Normal file
1
core/snapshot_history.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ot0yekk00psr
|
||||
|
|
@ -34,8 +34,8 @@ mascot, **Morgan Fortuna** ("Morgan"; they/them in any UI text, kept gender-neut
|
|||
Card, Result, Change, Reset, Dice wording rules: `docs/HISTORY.md` §6 "Terminology".
|
||||
|
||||
## 3a. Now: Sheets and the unified editor (2026-11-29)
|
||||
Spec, decisions and phases: `docs/SHEETS.md`. Phase A (card palette, branch `card-palette`) built,
|
||||
tests pass; not yet hand-tested or merged.
|
||||
Spec, decisions, phases and code map: `docs/SHEETS.md`. Phase A (card palette) committed on
|
||||
`card-palette`; phase B base (main menu, Sheets, sheet editor) on `sheets`. Not hand-tested or merged.
|
||||
|
||||
## 3. Where things stand (2026-11-11)
|
||||
- **Everything from the 2026-11-10 plan is built, tested and on `main`** (pushed): theme system,
|
||||
|
|
|
|||
|
|
@ -47,12 +47,30 @@ an old sheet card becomes a sheet with one text box.
|
|||
- Sheet editor uses the same palette (with search) for fields.
|
||||
|
||||
## 4. Phases
|
||||
- **A. Card palette** (branch `card-palette`): left dock Cards | List, search, drag/click to
|
||||
- **A. Card palette** — done 2026-11-29 (commit 16b34c4 on `card-palette`): left dock Cards | List, search, drag/click to
|
||||
add, Play-mode notice, remove "+ Card ▾", rename Board ▾ → Spread ▾. Phone: "+" opens a
|
||||
searchable list.
|
||||
- **B. Sheets core:** data model + storage (sheets and templates), main menu, Sheets list,
|
||||
- **B. Sheets core** — base built 2026-11-29 (branch `sheets`): main menu, Sheets list, New
|
||||
sheet dialog, sheet editor with tabs, snap canvas (Alt = free), field palette (shared
|
||||
`PaletteList`), inspector, Play/Build, snapshot undo, saving. Kinds so far: Number, Text box,
|
||||
Heading. Theme changes keep the screen (`MainScreens.resume`). Was planned as: data model + storage (sheets and templates), main menu, Sheets list,
|
||||
New sheet dialog, sheet editor (tabs, snap canvas, palette, inspector, Play/Build, undo).
|
||||
- **C. Field types:** basics → trackers → computed and dice → niche kinds.
|
||||
- **D. Spread integration:** sheet node (first-tab preview), variables read/write, locks,
|
||||
replace and migrate `KIND_SHEET`, document tabs.
|
||||
- **E. Lore Index library + items, export (PDF, PNG, share file), phone stacked view.**
|
||||
|
||||
## 5. Code map (phase B)
|
||||
- Data: `core/sheet_doc.gd` (tabs of boxes), `core/sheet_box.gd`, `core/sheet_kinds.gd` (the
|
||||
kinds list, grid step, `make_box`), `core/sheet_store.gd` (user://sheets, user://sheet_templates;
|
||||
a scratch folder when not saving), `core/snapshot_history.gd`, `core/sheet_demo.gd`.
|
||||
- Screens: `ui/main_screens.gd` (menu / spread / sheets; start screen; resume after a theme
|
||||
change), `ui/main_menu.gd`, `ui/sheets_screen.gd`, `ui/new_sheet_dialog.gd`.
|
||||
- Editor: `ui/sheet_editor.gd` (mode, tab, selection, edit/undo/save), `ui/sheet_top_bar.gd`,
|
||||
`ui/sheet_tabs_bar.gd`, `ui/sheet_canvas.gd`, `ui/sheet_box_view.gd`, `ui/sheet_field_views.gd`,
|
||||
`ui/sheet_inspector.gd`, `ui/field_palette.gd`; `ui/palette_list.gd` is shared with the card palette.
|
||||
- Look (2026-11-29, matched to the mockup): `ui/menu_icons.gd` (drawn icons), `MainTopBar.make_brand`
|
||||
(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`.
|
||||
|
|
|
|||
|
|
@ -272,6 +272,17 @@ A result or a Lore Entry can have a picture: [b]Picture → Choose…[/b] in its
|
|||
- 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.
|
||||
|
||||
# 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].
|
||||
[b]Sheets[/b] are pages for anything you keep track of: a character, a vehicle, a ship. They work on their own, without a spread.
|
||||
- [b]+ New sheet[/b] starts from a blank canvas or one of your templates.
|
||||
- In [b]Build[/b], add fields from the [b]Fields[/b] palette on the left: click to add one in the middle, or drag it where you want it. Drag a box to move it and its corner to resize it. Boxes snap to the grid; hold [b]Alt[/b] to place one freely.
|
||||
- Click a box to edit its title, colour and frame on the right. With nothing selected, the right side edits the whole sheet: its name and tint.
|
||||
- [b]+ Tab[/b] adds a tab, each with its own canvas. Right-click a tab to rename, move or delete it.
|
||||
- In [b]Play[/b], type in the boxes to change values. Undo and redo work for both values and layout (Ctrl+Z, Ctrl+Shift+Z).
|
||||
- Give a box a name under [b]Use in tables[/b] and a text box can show it with {@name}.
|
||||
- [b]Sheet ▾ → Save as template…[/b] keeps the layout to start new sheets from.
|
||||
|
||||
# Spreads, import and export
|
||||
A [b]spread[/b] is one layout of cards, saved under its own name. Use the switcher beside Play | Build (it shows the spread's name) to switch, or to make a new spread, rename, duplicate, delete one, or sort spreads into folders.
|
||||
- The spreads you opened last are at the top, under [b]Recent[/b]. Spreads with no folder come next, then each folder as a submenu.
|
||||
|
|
|
|||
|
|
@ -28,7 +28,11 @@ func _test_lists() -> void:
|
|||
_check(play.has("Roll") and not play.has("Delete table"), "Play: a card can be rolled, not deleted: %s" % str(play))
|
||||
var bg := _texts(Actions.background(main, Vector2.ZERO))
|
||||
_check(bg.has("Search… Ctrl+F") and bg.has("Shuffle all decks") and not bg.has("New card from template…"), "Play spread menu: %s" % str(bg))
|
||||
var new_card: Dictionary = Actions.background(main, Vector2.ZERO)[bg.find("New card")]
|
||||
var new_card: Dictionary = {}
|
||||
for item: Dictionary in Actions.background(main, Vector2.ZERO):
|
||||
if item.get("text", "") == "New card":
|
||||
new_card = item
|
||||
_check(bg.has("Main menu"), "the spread menu leads back to the main menu")
|
||||
_check(new_card.get("disabled", false), "Play: New card shows greyed, pointing to Build mode")
|
||||
main.set_mode(Main.Mode.BUILD)
|
||||
await _frames()
|
||||
|
|
|
|||
125
tests/test_sheet_editor.gd
Normal file
125
tests/test_sheet_editor.gd
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
extends AppTestBase
|
||||
## The main menu and the sheet editor in the app: switching screens, making a
|
||||
## sheet, adding boxes from the field palette, moving them on the snap grid,
|
||||
## undo, tabs, number fields, saving, and keys staying on their own screen.
|
||||
## Run: tools/run_tests.sh sheet_editor
|
||||
|
||||
|
||||
func run() -> void:
|
||||
if not await start_main(false):
|
||||
return
|
||||
await _test_menu()
|
||||
await _test_new_sheet()
|
||||
await _test_boxes()
|
||||
await _test_tabs()
|
||||
await _test_keys()
|
||||
finish()
|
||||
|
||||
|
||||
func _test_menu() -> void:
|
||||
var screens := main.screens
|
||||
_check(screens.showing(MainScreens.SPREAD), "tests start on the spread")
|
||||
main.top_bar.brand_title.get_parent().gui_input.emit(_click())
|
||||
_check(screens.menu.visible and not screens.spread_root.visible, "clicking the logo opens the main menu")
|
||||
var labels: Array = screens.menu.buttons.keys()
|
||||
_eq(labels, ["Spreads", "Sheets", "Settings", "Quit"], "the menu lists Spreads first, titles only")
|
||||
(screens.menu.buttons["Sheets"] as Button).pressed.emit()
|
||||
_check(screens.sheets.visible and screens.sheets.list_page.visible, "Sheets opens the sheet list")
|
||||
await _frames()
|
||||
|
||||
|
||||
func _test_new_sheet() -> void:
|
||||
var sheets := main.screens.sheets
|
||||
sheets.open_new_sheet()
|
||||
await _frames()
|
||||
var dialog: NewSheetDialog = null
|
||||
for c in main.get_children():
|
||||
if c is NewSheetDialog:
|
||||
dialog = c
|
||||
_check(dialog != null, "+ New sheet asks for a name")
|
||||
dialog.name_edit.text = "Rusty Mule"
|
||||
dialog._create()
|
||||
await _frames()
|
||||
var ed := sheets.editor
|
||||
_check(ed.visible and ed.doc.name == "Rusty Mule" and ed.building(), "a blank sheet opens in Build")
|
||||
_eq(sheets.store.list().size(), 1, "it is saved")
|
||||
|
||||
|
||||
func _test_boxes() -> void:
|
||||
var ed := main.screens.sheets.editor
|
||||
(ed.palette.list.find_child("Number", true, false) as Button).pressed.emit()
|
||||
await _frames()
|
||||
_eq((ed.current_tab()["boxes"] as Array).size(), 1, "clicking Number adds a box")
|
||||
var box: SheetBox = ed.current_tab()["boxes"][0]
|
||||
_eq(ed.selected, box.id, "the new box is selected")
|
||||
var spot := ed.canvas.global_position + ed.canvas.size / 2.0 + Vector2(17, 9)
|
||||
var want := ed.canvas.drop_point(spot)
|
||||
_check(ed.palette.drop_at(ed.palette._add.bind(SheetKinds.TEXT), spot), "dropping on the canvas adds there")
|
||||
var text_box: SheetBox = ed.current_tab()["boxes"][1]
|
||||
_eq(Vector2(text_box.x, text_box.y), Vector2(SheetKinds.snap(want.x), SheetKinds.snap(want.y)), "a dropped box snaps to the grid")
|
||||
var view: SheetBoxView = ed.canvas.views[box.id]
|
||||
view.begin_drag("move")
|
||||
view.drag_to(Vector2(37, 21), false)
|
||||
view.end_drag()
|
||||
_eq(Vector2(box.x, box.y).posmod(SheetKinds.GRID), Vector2.ZERO, "moving snaps to the grid")
|
||||
var snapped := Vector2(box.x, box.y)
|
||||
view = ed.canvas.views[box.id]
|
||||
view.begin_drag("move")
|
||||
view.drag_to(Vector2(5, 3), true)
|
||||
view.end_drag()
|
||||
_eq(Vector2(box.x, box.y), snapped + Vector2(5, 3), "Alt places it off the grid")
|
||||
ed.undo()
|
||||
box = ed.doc.find_box(box.id)
|
||||
_eq(Vector2(box.x, box.y), snapped, "undo puts the box back")
|
||||
ed.redo()
|
||||
ed.set_mode(Main.Mode.PLAY)
|
||||
await _frames()
|
||||
_check(ed.palette.notice.visible and not ed.inspector.visible, "Play greys the palette and hides the inspector")
|
||||
view = ed.canvas.views[box.id]
|
||||
(view.find_child("Plus", true, false) as Button).pressed.emit()
|
||||
_eq(int(ed.doc.find_box(box.id).value), 1, "+ adds one in Play")
|
||||
ed.undo()
|
||||
_eq(int(ed.doc.find_box(box.id).value), 0, "a value change can be undone")
|
||||
ed.save_now()
|
||||
var saved := main.screens.sheets.store.load_sheet(ed.doc.id)
|
||||
_eq((saved.tabs[0]["boxes"] as Array).size(), 2, "the sheet's boxes are saved")
|
||||
ed.set_mode(Main.Mode.BUILD)
|
||||
|
||||
|
||||
func _test_tabs() -> void:
|
||||
var ed := main.screens.sheets.editor
|
||||
ed.tabs_bar.add_tab()
|
||||
await _frames()
|
||||
_check(ed.doc.tabs.size() == 2 and ed.tab_id == str(ed.doc.tabs[1]["id"]), "+ Tab adds a tab and opens it")
|
||||
_eq(ed.canvas.views.size(), 0, "a new tab has its own empty canvas")
|
||||
var second := str(ed.doc.tabs[1]["id"])
|
||||
ed.tabs_bar.move_tab(second, -1)
|
||||
_eq(str(ed.doc.tabs[0]["id"]), second, "Move left moves it")
|
||||
ed.tabs_bar.delete_tab(second)
|
||||
_eq(ed.doc.tabs.size(), 1, "an empty tab deletes without asking")
|
||||
_check(ed.tabs_bar.menu_for(str(ed.doc.tabs[0]["id"]))[3]["disabled"], "the last tab can't be deleted")
|
||||
ed.undo()
|
||||
_eq(ed.doc.tabs.size(), 2, "undo brings the tab back")
|
||||
|
||||
|
||||
func _test_keys() -> void:
|
||||
var ed := main.screens.sheets.editor
|
||||
var spread_label := main.undo_redo.edits.undo_label() if main.undo_redo.edits else ""
|
||||
var key := InputEventKey.new()
|
||||
key.keycode = KEY_Z
|
||||
key.ctrl_pressed = true
|
||||
key.pressed = true
|
||||
var step := ed.history.undo_label()
|
||||
main.layout._shortcut_input(key)
|
||||
_eq(ed.history.redo_label(), step, "Ctrl+Z on the Sheets screen undoes the sheet")
|
||||
_eq(main.undo_redo.edits.undo_label() if main.undo_redo.edits else "", spread_label, "and leaves the spread alone")
|
||||
ed.screen.show_list()
|
||||
_check(ed.screen.list_page.visible and ed.doc == null, "← Sheets closes the sheet")
|
||||
main.screens.show(MainScreens.SPREAD)
|
||||
|
||||
|
||||
func _click() -> InputEventMouseButton:
|
||||
var mb := InputEventMouseButton.new()
|
||||
mb.button_index = MOUSE_BUTTON_LEFT
|
||||
mb.pressed = true
|
||||
return mb
|
||||
1
tests/test_sheet_editor.gd.uid
Normal file
1
tests/test_sheet_editor.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://d2tj2tr8qawy4
|
||||
84
tests/test_sheets.gd
Normal file
84
tests/test_sheets.gd
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
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.
|
||||
## Run: tools/run_tests.sh sheets
|
||||
|
||||
const ROOT := "user://test_sheets/"
|
||||
|
||||
|
||||
func run() -> void:
|
||||
_wipe(ROOT)
|
||||
_test_round_trip()
|
||||
_test_boxes()
|
||||
_test_store()
|
||||
_test_history()
|
||||
_wipe(ROOT)
|
||||
finish()
|
||||
|
||||
|
||||
func _test_round_trip() -> void:
|
||||
var doc := SheetDoc.new("brin", "Brin Hollowmere")
|
||||
doc.tint = "#3a7bd5"
|
||||
var box := SheetKinds.make_box(SheetKinds.NUMBER, doc.new_box_id(), Vector2(37, 9))
|
||||
box.title = "Strength"
|
||||
box.value = 14
|
||||
box.var_name = "str"
|
||||
box.config = {"min": 3}
|
||||
doc.tabs[0]["boxes"].append(box)
|
||||
doc.add_tab("Spells")
|
||||
var back := SheetDoc.from_dict(JSON.parse_string(JSON.stringify(doc.to_dict())))
|
||||
_eq(back.name, "Brin Hollowmere", "the name survives")
|
||||
_eq(back.tint, "#3a7bd5", "the tint survives")
|
||||
_eq(back.tabs.size(), 2, "both tabs survive")
|
||||
var b2 := back.find_box(box.id)
|
||||
_check(b2 != null and b2.title == "Strength" and int(b2.value) == 14 and b2.var_name == "str", "a box keeps its title, value and variable")
|
||||
_eq(Vector2(b2.x, b2.y), Vector2(32, 16), "a new box snaps to the grid")
|
||||
_eq(int(b2.config.get("min", 0)), 3, "a box keeps its settings")
|
||||
|
||||
|
||||
func _test_boxes() -> void:
|
||||
var doc := SheetDoc.new("t", "T")
|
||||
var a := SheetKinds.make_box(SheetKinds.TEXT, doc.new_box_id(), Vector2.ZERO)
|
||||
doc.tabs[0]["boxes"].append(a)
|
||||
var b := SheetKinds.make_box(SheetKinds.HEADING, doc.new_box_id(), Vector2.ZERO)
|
||||
doc.tabs[0]["boxes"].append(b)
|
||||
_check(a.id != b.id, "boxes get different ids")
|
||||
doc.remove_box(a.id)
|
||||
_check(doc.find_box(a.id) == null and doc.find_box(b.id) != null, "removing a box keeps the others")
|
||||
var t2 := doc.add_tab("Notes")
|
||||
_check(t2["id"] != doc.tabs[0]["id"], "tabs get different ids")
|
||||
|
||||
|
||||
func _test_store() -> void:
|
||||
var store := SheetStore.new(ROOT)
|
||||
var doc := store.create("Brin")
|
||||
_eq(doc.id, "brin", "the file id comes from the name")
|
||||
var box := SheetKinds.make_box(SheetKinds.NUMBER, doc.new_box_id(), Vector2.ZERO)
|
||||
box.value = 9
|
||||
doc.tabs[0]["boxes"].append(box)
|
||||
store.save(doc)
|
||||
_eq(store.create("Brin").id, "brin-2", "a second sheet with the same name gets its own id")
|
||||
_eq(store.list().size(), 2, "the list shows both sheets")
|
||||
var tpl_id := store.save_as_template(doc, "Knight")
|
||||
_eq(store.list(true).size(), 1, "the template is listed apart")
|
||||
var made := store.create("Sir Ada", tpl_id)
|
||||
_eq(made.from_template, tpl_id, "a sheet remembers its template")
|
||||
_eq(int(made.tabs[0]["boxes"][0].value), 9, "a sheet from a template starts with its boxes")
|
||||
_eq(store.load_sheet(made.id).name, "Sir Ada", "it is saved")
|
||||
store.delete("brin-2")
|
||||
_eq(store.list().size(), 2, "deleting removes it from the list")
|
||||
_check(store.load_sheet("../x") == null, "bad ids are refused")
|
||||
|
||||
|
||||
func _test_history() -> void:
|
||||
var hist := SnapshotHistory.new()
|
||||
var doc := SheetDoc.new("h", "One")
|
||||
hist.record(doc.to_dict(), "Rename")
|
||||
doc.name = "Two"
|
||||
_check(hist.can_undo() and hist.undo_label() == "Rename", "an edit can be undone")
|
||||
doc = SheetDoc.from_dict(hist.undo(doc.to_dict()))
|
||||
_eq(doc.name, "One", "undo puts it back")
|
||||
doc = SheetDoc.from_dict(hist.redo(doc.to_dict()))
|
||||
_eq(doc.name, "Two", "redo does it again")
|
||||
hist.record(doc.to_dict(), "Again")
|
||||
_check(not hist.can_redo(), "a new edit clears redo")
|
||||
1
tests/test_sheets.gd.uid
Normal file
1
tests/test_sheets.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://1kc8uuaa5gt6
|
||||
|
|
@ -165,6 +165,8 @@ static func group(m: Main, g: TableGroup) -> Array:
|
|||
## bar's ☰ menu (at = the view's centre).
|
||||
static func background(m: Main, at: Vector2) -> Array:
|
||||
var list: Array = []
|
||||
list.append({"text": "Main menu", "do": m.screens.show.bind(MainScreens.MENU), "tip": "Spreads, Sheets, Settings and Quit"})
|
||||
list.append({"sep": ""})
|
||||
if m.mode == Main.Mode.BUILD:
|
||||
var kinds: Array = []
|
||||
for item: Dictionary in CardCatalog.ITEMS:
|
||||
|
|
|
|||
|
|
@ -28,3 +28,21 @@ static func pulse(b: Control) -> void:
|
|||
for i in 3:
|
||||
tween.tween_property(b, "modulate", Color(1.6, 1.4, 0.8), 0.18)
|
||||
tween.tween_property(b, "modulate", Color.WHITE, 0.22)
|
||||
|
||||
|
||||
## The notice over a greyed palette in Play: the message and a button that
|
||||
## switches to Build (`to_build`). Shared by the card and field palettes.
|
||||
static func make_notice(_m: Main, to_build: Callable, message: String = PALETTE_MESSAGE) -> PanelContainer:
|
||||
var box := PanelContainer.new()
|
||||
box.add_theme_stylebox_override("panel", Style.bordered(Style.box(Style.CARD, 8, [10, 8, 10, 8]), 2, Style.TRIM))
|
||||
var col := VBoxContainer.new()
|
||||
col.add_theme_constant_override("separation", 6)
|
||||
box.add_child(col)
|
||||
var text := Style.make_label(message, Style.body_bold(), 14, Style.INK)
|
||||
text.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
col.add_child(text)
|
||||
var go := ModalCard.make_button("Switch to Build", "primary")
|
||||
go.name = "SwitchToBuild"
|
||||
go.pressed.connect(to_build)
|
||||
col.add_child(go)
|
||||
return box
|
||||
|
|
|
|||
|
|
@ -75,18 +75,6 @@ static func groups() -> Array[String]:
|
|||
return out
|
||||
|
||||
|
||||
## True when `query` (lower case, may be "") matches the item's label, tip,
|
||||
## group or search words.
|
||||
static func matches(item: Dictionary, query: String) -> bool:
|
||||
if query == "":
|
||||
return true
|
||||
var hay := " ".join([item.get("label", ""), item.get("tip", ""), item.get("group", ""), item.get("words", "")]).to_lower()
|
||||
for word in query.split(" ", false):
|
||||
if not hay.contains(word):
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
## Gives a new card its variant's start settings.
|
||||
static func apply_variant(t: RollTable, variant: String) -> void:
|
||||
match variant:
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
class_name CardPalette
|
||||
extends VBoxContainer
|
||||
## The Cards tab of the left dock: every kind of card (CardCatalog) and your
|
||||
## templates, in groups, with a search box at the top. Click an item to add it
|
||||
## in the middle of the view; drag it to place it on the spread.
|
||||
## templates in a PaletteList. Click an item to add it in the middle of the
|
||||
## view; drag it to place it on the spread.
|
||||
## In Play the items are greyed under a notice with "Switch to Build"
|
||||
## (BuildModeHint), so players learn where cards are added.
|
||||
|
||||
|
|
@ -13,168 +13,60 @@ const ALL_TEMPLATES := {"label": "All templates…", "group": CardCatalog.GROUP_
|
|||
"tip": "Search, import, rename and delete templates", "words": "import manage"}
|
||||
|
||||
var m: Main
|
||||
var list: PaletteList
|
||||
var search: LineEdit
|
||||
var notice: PanelContainer
|
||||
var _items: VBoxContainer
|
||||
var _templates: Array[Dictionary] = []
|
||||
var _dragging: Dictionary = {}
|
||||
var _mode := -1
|
||||
|
||||
|
||||
func setup(p_main: Main) -> void:
|
||||
m = p_main
|
||||
add_theme_constant_override("separation", 8)
|
||||
notice = _make_notice()
|
||||
notice = BuildModeHint.make_notice(m, func() -> void: m.set_mode(Main.Mode.BUILD))
|
||||
add_child(notice)
|
||||
search = LineEdit.new()
|
||||
search.placeholder_text = "Search cards and templates"
|
||||
search.clear_button_enabled = true
|
||||
ModalCard.style_line_edit(search)
|
||||
search.text_changed.connect(func(_s: String) -> void: rebuild())
|
||||
search.text_submitted.connect(func(_s: String) -> void: _add_first())
|
||||
add_child(search)
|
||||
var scroll := ScrollContainer.new()
|
||||
scroll.size_flags_vertical = SIZE_EXPAND_FILL
|
||||
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
add_child(scroll)
|
||||
_items = VBoxContainer.new()
|
||||
_items.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
_items.add_theme_constant_override("separation", 4)
|
||||
scroll.add_child(_items)
|
||||
var hint := Style.make_label("Click to add in the middle of the view, or drag onto the spread.", Style.body(), 12, Style.ON_BG_MUTED)
|
||||
hint.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
add_child(hint)
|
||||
rebuild()
|
||||
list = PaletteList.new()
|
||||
list.setup("Search cards and templates", "Drag onto the spread, or click to add", "Add a card", "“dice”, “choice” or “if”")
|
||||
list.size_flags_vertical = SIZE_EXPAND_FILL
|
||||
list.sections_for = _sections
|
||||
list.can_use = func() -> bool: return m.mode == Main.Mode.BUILD
|
||||
list.on_blocked = BuildModeHint.explain.bind(m)
|
||||
list.drop_at = drop_at
|
||||
list.after_use = func() -> void:
|
||||
if m.mobile:
|
||||
m.mobile.show_list(false)
|
||||
add_child(list)
|
||||
search = list.search
|
||||
list.rebuild()
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if int(m.mode) != _mode:
|
||||
_mode = int(m.mode)
|
||||
var play := m.mode != Main.Mode.BUILD
|
||||
notice.visible = play
|
||||
_items.modulate.a = 0.45 if play else 1.0
|
||||
|
||||
|
||||
func _make_notice() -> PanelContainer:
|
||||
var box := PanelContainer.new()
|
||||
box.add_theme_stylebox_override("panel", Style.bordered(Style.box(Style.CARD, 8, [10, 8, 10, 8]), 2, Style.TRIM))
|
||||
var col := VBoxContainer.new()
|
||||
col.add_theme_constant_override("separation", 6)
|
||||
box.add_child(col)
|
||||
var text := Style.make_label(BuildModeHint.PALETTE_MESSAGE, Style.body_bold(), 14, Style.INK)
|
||||
text.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
col.add_child(text)
|
||||
var go := ModalCard.make_button("Switch to Build", "primary")
|
||||
go.name = "SwitchToBuild"
|
||||
go.pressed.connect(func() -> void: m.set_mode(Main.Mode.BUILD))
|
||||
col.add_child(go)
|
||||
return box
|
||||
notice.visible = m.mode != Main.Mode.BUILD
|
||||
|
||||
|
||||
## Reads the template list again (it lives in files, so not on every keystroke).
|
||||
func refresh_templates() -> void:
|
||||
_templates = m.templating.templates().list() if m.templating else []
|
||||
rebuild()
|
||||
list.rebuild()
|
||||
|
||||
|
||||
## Rebuilds the item list from the catalog, filtered by the search text.
|
||||
func rebuild() -> void:
|
||||
for c in _items.get_children():
|
||||
_items.remove_child(c)
|
||||
c.queue_free()
|
||||
var query := search.text.strip_edges().to_lower()
|
||||
var any := false
|
||||
func _sections(query: String) -> Array:
|
||||
var out: Array = []
|
||||
for group in CardCatalog.groups():
|
||||
var shown: Array = CardCatalog.ITEMS.filter(func(item: Dictionary) -> bool:
|
||||
return item["group"] == group and CardCatalog.matches(item, query))
|
||||
any = _add_group(group, shown.map(func(item: Dictionary) -> Array: return [item, _add_card.bind(item)])) or any
|
||||
var entries: Array = []
|
||||
for item: Dictionary in CardCatalog.ITEMS:
|
||||
if item["group"] == group and PaletteList.matches(item, query):
|
||||
entries.append([item, _add_card.bind(item)])
|
||||
out.append([group, entries])
|
||||
var templates: Array = []
|
||||
for row: Dictionary in _templates:
|
||||
var item := {"label": row["name"], "group": CardCatalog.GROUP_TEMPLATES, "tip": row.get("description", ""), "words": "template"}
|
||||
if CardCatalog.matches(item, query):
|
||||
if PaletteList.matches(item, query):
|
||||
templates.append([item, _add_template.bind(str(row["id"]))])
|
||||
if CardCatalog.matches(ALL_TEMPLATES, query):
|
||||
if PaletteList.matches(ALL_TEMPLATES, query):
|
||||
templates.append([ALL_TEMPLATES, func(_at: Vector2) -> void: m.templating.open_template_picker()])
|
||||
any = _add_group(CardCatalog.GROUP_TEMPLATES, templates) or any
|
||||
if CardCatalog.matches(GROUP_ITEM, query):
|
||||
any = _add_group(CardCatalog.GROUP_OTHER, [[GROUP_ITEM, _add_group_card]]) or any
|
||||
if not any:
|
||||
var none := Style.make_label("Nothing matches “%s”." % search.text.strip_edges(), Style.body(), 14, Style.ON_BG_MUTED)
|
||||
none.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
_items.add_child(none)
|
||||
|
||||
|
||||
## A group heading and its items in two columns. `entries` holds
|
||||
## [item, on_add(at)] pairs; at = Vector2.INF means the middle of the view.
|
||||
func _add_group(title: String, entries: Array) -> bool:
|
||||
if entries.is_empty():
|
||||
return false
|
||||
_items.add_child(Style.make_label(title.to_upper(), Style.caps(), 11, Style.ON_BG_MUTED))
|
||||
var grid := GridContainer.new()
|
||||
grid.columns = 2
|
||||
grid.add_theme_constant_override("h_separation", 4)
|
||||
grid.add_theme_constant_override("v_separation", 4)
|
||||
_items.add_child(grid)
|
||||
for entry: Array in entries:
|
||||
grid.add_child(_item_button(entry[0], entry[1]))
|
||||
return true
|
||||
|
||||
|
||||
func _item_button(item: Dictionary, on_add: Callable) -> Button:
|
||||
var b := Style.bar_button(str(item["label"]))
|
||||
b.name = str(item["label"]).validate_node_name()
|
||||
b.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
b.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||||
b.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
||||
b.clip_text = true
|
||||
b.custom_minimum_size.x = 60
|
||||
b.tooltip_text = str(item.get("tip", ""))
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.pressed.connect(func() -> void: _use(on_add, Vector2.INF))
|
||||
b.set_drag_forwarding(func(_at: Vector2) -> Variant: return _start_drag(item, on_add), Callable(), Callable())
|
||||
return b
|
||||
|
||||
|
||||
## Adds the item, or explains Build mode in Play.
|
||||
func _use(on_add: Callable, at: Vector2) -> void:
|
||||
if m.mode != Main.Mode.BUILD:
|
||||
BuildModeHint.explain(m)
|
||||
return
|
||||
on_add.call(at)
|
||||
if m.mobile:
|
||||
m.mobile.show_list(false)
|
||||
|
||||
|
||||
## Enter in the search box adds the first card that matches.
|
||||
func _add_first() -> void:
|
||||
var query := search.text.strip_edges().to_lower()
|
||||
for item: Dictionary in CardCatalog.ITEMS:
|
||||
if CardCatalog.matches(item, query):
|
||||
_use(_add_card.bind(item), Vector2.INF)
|
||||
return
|
||||
|
||||
|
||||
func _start_drag(item: Dictionary, on_add: Callable) -> Variant:
|
||||
if m.mode != Main.Mode.BUILD:
|
||||
return null
|
||||
_dragging = {"on_add": on_add}
|
||||
var label := Style.make_label(str(item["label"]), 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)
|
||||
set_drag_preview(chip)
|
||||
return {"palette_item": item["label"]}
|
||||
|
||||
|
||||
## Nothing took the drop, so the palette places the card where it was let go
|
||||
## (only on the spread; let go anywhere else and nothing is added).
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_DRAG_END and not _dragging.is_empty():
|
||||
var on_add: Callable = _dragging["on_add"]
|
||||
_dragging = {}
|
||||
if get_viewport().gui_is_drag_successful():
|
||||
return
|
||||
drop_at(on_add, get_global_mouse_position())
|
||||
out.append([CardCatalog.GROUP_TEMPLATES, templates])
|
||||
out.append([CardCatalog.GROUP_OTHER, [[GROUP_ITEM, _add_group_card]] if PaletteList.matches(GROUP_ITEM, query) else []])
|
||||
return out
|
||||
|
||||
|
||||
## Adds through `on_add` with its top-left corner under a screen point on the spread.
|
||||
|
|
@ -183,7 +75,7 @@ func drop_at(on_add: Callable, screen_point: Vector2) -> bool:
|
|||
if not board.is_visible_in_tree() or not board.get_global_rect().has_point(screen_point):
|
||||
return false
|
||||
var world := board.screen_to_world(screen_point - board.global_position)
|
||||
_use(on_add, (world - Vector2(128, 20)).round())
|
||||
list.use(on_add, (world - Vector2(128, 20)).round())
|
||||
return true
|
||||
|
||||
|
||||
|
|
|
|||
55
ui/field_palette.gd
Normal file
55
ui/field_palette.gd
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
class_name FieldPalette
|
||||
extends VBoxContainer
|
||||
## The sheet editor's field palette: every kind of box (SheetKinds) in a
|
||||
## PaletteList, like the spread's card palette. Click adds a box in the middle
|
||||
## of the canvas; drag drops it where you let go. Greyed in Play under a
|
||||
## notice with Switch to Build.
|
||||
|
||||
const MESSAGE := "Fields are added in Build mode."
|
||||
|
||||
var ed: SheetEditor
|
||||
var list: PaletteList
|
||||
var notice: PanelContainer
|
||||
|
||||
|
||||
func setup(p_editor: SheetEditor) -> void:
|
||||
ed = p_editor
|
||||
add_theme_constant_override("separation", 8)
|
||||
notice = BuildModeHint.make_notice(ed.m, func() -> void: ed.set_mode(Main.Mode.BUILD), MESSAGE)
|
||||
add_child(notice)
|
||||
list = PaletteList.new()
|
||||
list.setup("Search fields", "Drag onto the sheet, or click to add", "Add a field", "“number”, “text” or “title”")
|
||||
list.size_flags_vertical = SIZE_EXPAND_FILL
|
||||
list.sections_for = _sections
|
||||
list.can_use = ed.building
|
||||
list.on_blocked = func() -> void: ed.m.toast(MESSAGE)
|
||||
list.drop_at = drop_at
|
||||
add_child(list)
|
||||
list.rebuild()
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
notice.visible = ed.doc != null and not ed.building()
|
||||
|
||||
|
||||
func _sections(query: String) -> Array:
|
||||
var out: Array = []
|
||||
for group in SheetKinds.groups():
|
||||
var entries: Array = []
|
||||
for item: Dictionary in SheetKinds.ITEMS:
|
||||
if item["group"] == group and PaletteList.matches(item, query):
|
||||
entries.append([item, _add.bind(str(item["kind"]))])
|
||||
out.append([group, entries])
|
||||
return out
|
||||
|
||||
|
||||
func drop_at(on_add: Callable, screen_point: Vector2) -> bool:
|
||||
var at := ed.canvas.drop_point(screen_point)
|
||||
if at == Vector2.INF:
|
||||
return false
|
||||
list.use(on_add, at)
|
||||
return true
|
||||
|
||||
|
||||
func _add(at: Vector2, kind: String) -> void:
|
||||
ed.add_box(kind, at)
|
||||
1
ui/field_palette.gd.uid
Normal file
1
ui/field_palette.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ckih504bs1mr4
|
||||
|
|
@ -48,6 +48,8 @@ var selecting: MainSelection
|
|||
var list_view: ListView
|
||||
## The left dock: Cards (the card palette) | List (list_view).
|
||||
var left_dock: LeftDock
|
||||
## Main menu, spread or Sheets (MainScreens).
|
||||
var screens: MainScreens
|
||||
## The phone layout, when it is on (MobileLayout.wanted).
|
||||
var mobile: MobileLayout
|
||||
## The Book panel (reusable results).
|
||||
|
|
@ -148,14 +150,18 @@ func _ready() -> void:
|
|||
await get_tree().process_frame
|
||||
await get_tree().process_frame
|
||||
board.fit()
|
||||
screens.start(args)
|
||||
cli._run_cli(args)
|
||||
WelcomeDialog.maybe_show(self)
|
||||
if screens.showing(MainScreens.SPREAD):
|
||||
WelcomeDialog.maybe_show(self)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
# A roll still animating must not go on after this scene is freed (a theme
|
||||
# change mid-roll reloads it).
|
||||
rolling._token += 1
|
||||
_save_now()
|
||||
if screens:
|
||||
screens.sheets.leave()
|
||||
|
||||
# ---------- Cards ----------
|
||||
|
||||
|
|
|
|||
|
|
@ -258,6 +258,19 @@ 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)
|
||||
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()
|
||||
if args.has("--list"):
|
||||
m.list_view.set_shown(true)
|
||||
if args.has("--pack"):
|
||||
|
|
|
|||
|
|
@ -98,6 +98,8 @@ func _build_ui() -> void:
|
|||
m.tray.set_height(foot.size_px)
|
||||
root.add_child(foot)
|
||||
root.add_child(m.tray)
|
||||
m.screens = MainScreens.new(m)
|
||||
m.screens.setup(root)
|
||||
m.top_bar._build_toast()
|
||||
m.undo_redo._build_edit_timer()
|
||||
|
||||
|
|
@ -256,6 +258,11 @@ func _shortcut_input(ev: InputEvent) -> void:
|
|||
var k := ev as InputEventKey
|
||||
if k == null or not k.pressed:
|
||||
return
|
||||
if m.screens and not m.screens.showing(MainScreens.SPREAD):
|
||||
# Other screens take their own keys; the hidden spread takes none.
|
||||
if m.screens.showing(MainScreens.SHEETS) and m.screens.sheets.editor.shortcut(k):
|
||||
m.get_viewport().set_input_as_handled()
|
||||
return
|
||||
if m.undo_redo._history_shortcut(k):
|
||||
m.get_viewport().set_input_as_handled()
|
||||
return
|
||||
|
|
@ -279,6 +286,8 @@ func _unhandled_input(ev: InputEvent) -> void:
|
|||
var k := ev as InputEventKey
|
||||
if k == null or not k.pressed or k.echo or m.mode != Main.Mode.BUILD:
|
||||
return
|
||||
if m.screens and not m.screens.showing(MainScreens.SPREAD):
|
||||
return
|
||||
if k.keycode == KEY_G and (k.ctrl_pressed or k.meta_pressed):
|
||||
m.grouping.group_selection()
|
||||
m.get_viewport().set_input_as_handled()
|
||||
|
|
|
|||
233
ui/main_menu.gd
Normal file
233
ui/main_menu.gd
Normal file
|
|
@ -0,0 +1,233 @@
|
|||
class_name MainMenu
|
||||
extends Control
|
||||
## The main menu, laid out like the mockup (docs/SHEETS.md): on the theme's
|
||||
## spread background, the app's name over Spreads (first: the app's main job),
|
||||
## Sheets, then Settings and Quit side by side, titles only (the user's pick,
|
||||
## 2026-11-29). Beside them Morgan and "Pick up where you left off". A footer
|
||||
## names the theme.
|
||||
|
||||
var m: Main
|
||||
var buttons: Dictionary = {} # label -> Button
|
||||
var recent_rows: VBoxContainer
|
||||
var row: BoxContainer
|
||||
var _backdrop: BoardBackdrop
|
||||
var _theme_label: Label
|
||||
|
||||
|
||||
func setup(p_main: Main) -> void:
|
||||
m = p_main
|
||||
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
_backdrop = BoardBackdrop.new(ThemeStore.current)
|
||||
draw.connect(func() -> void: _backdrop.draw(self, Rect2(Vector2.ZERO, size)))
|
||||
resized.connect(queue_redraw)
|
||||
var page := VBoxContainer.new()
|
||||
page.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
page.add_theme_constant_override("separation", 0)
|
||||
add_child(page)
|
||||
var center := CenterContainer.new()
|
||||
center.size_flags_vertical = SIZE_EXPAND_FILL
|
||||
page.add_child(center)
|
||||
# Side by side; a narrow window (a phone) stacks them (_fit_columns).
|
||||
row = BoxContainer.new()
|
||||
row.add_theme_constant_override("separation", 64)
|
||||
resized.connect(_fit_columns)
|
||||
center.add_child(row)
|
||||
row.add_child(_left_column())
|
||||
row.add_child(_right_column())
|
||||
page.add_child(_footer())
|
||||
|
||||
|
||||
func _fit_columns() -> void:
|
||||
row.vertical = size.x < 920.0
|
||||
|
||||
|
||||
func _left_column() -> VBoxContainer:
|
||||
var col := VBoxContainer.new()
|
||||
col.custom_minimum_size = Vector2(420, 0)
|
||||
col.add_theme_constant_override("separation", 28)
|
||||
var names := VBoxContainer.new()
|
||||
names.add_theme_constant_override("separation", 2)
|
||||
names.add_child(Style.make_label("RANDOM TABLES & SHEETS", Style.caps(), 13, Style.ON_BG_MUTED))
|
||||
names.add_child(Style.make_label("Table Tarot", Style.display(), 72, Style.ACCENT))
|
||||
col.add_child(names)
|
||||
var nav := VBoxContainer.new()
|
||||
nav.add_theme_constant_override("separation", 10)
|
||||
col.add_child(nav)
|
||||
nav.add_child(_big_button("Spreads", MenuIcons.SPREAD, true, func() -> void: m.screens.show(MainScreens.SPREAD)))
|
||||
nav.add_child(_big_button("Sheets", MenuIcons.SHEET, false, func() -> void: m.screens.show(MainScreens.SHEETS)))
|
||||
var pair := GridContainer.new()
|
||||
pair.columns = 2
|
||||
pair.add_theme_constant_override("h_separation", 10)
|
||||
nav.add_child(pair)
|
||||
pair.add_child(_small_button("Settings", MenuIcons.SETTINGS, open_settings))
|
||||
pair.add_child(_small_button("Quit", MenuIcons.QUIT, quit))
|
||||
return col
|
||||
|
||||
|
||||
func _right_column() -> VBoxContainer:
|
||||
var col := VBoxContainer.new()
|
||||
col.custom_minimum_size = Vector2(380, 0)
|
||||
col.add_theme_constant_override("separation", 20)
|
||||
var mark := _mascot()
|
||||
if mark:
|
||||
col.add_child(mark)
|
||||
var recent := VBoxContainer.new()
|
||||
recent.add_theme_constant_override("separation", 8)
|
||||
recent.add_child(Style.make_label("PICK UP WHERE YOU LEFT OFF", Style.caps(), 12, Style.ON_BG_MUTED))
|
||||
recent_rows = VBoxContainer.new()
|
||||
recent_rows.add_theme_constant_override("separation", 8)
|
||||
recent.add_child(recent_rows)
|
||||
col.add_child(recent)
|
||||
visibility_changed.connect(func() -> void:
|
||||
if visible:
|
||||
refresh_recent())
|
||||
return col
|
||||
|
||||
|
||||
## Morgan (or the theme's logo) drawn large and sharp.
|
||||
func _mascot() -> Control:
|
||||
if Style.LOGO == "fortune_teller" or Style.LOGO == "mascot":
|
||||
var tr := TextureRect.new()
|
||||
tr.texture = MascotArt.texture(ThemeStore.current, 512)
|
||||
tr.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
||||
tr.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
||||
tr.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS
|
||||
tr.custom_minimum_size = Vector2(380, 280)
|
||||
return tr
|
||||
var mark := MainTopBar.logo()
|
||||
if mark:
|
||||
mark.custom_minimum_size = Vector2(380, 200)
|
||||
return mark
|
||||
|
||||
|
||||
func _footer() -> PanelContainer:
|
||||
var bar := PanelContainer.new()
|
||||
bar.add_theme_stylebox_override("panel", Style.box(Style.BG_DEEP, 0, [32, 12, 32, 12]))
|
||||
_theme_label = Style.make_label("Theme: %s" % str(ThemeStore.current.get("name", "")), Style.body(), 13, Style.ON_BG_MUTED)
|
||||
bar.add_child(_theme_label)
|
||||
return bar
|
||||
|
||||
|
||||
## A tall menu button: an icon and a big title. `primary` fills it with the accent.
|
||||
func _big_button(text: String, icon: String, primary: bool, on_press: Callable) -> Button:
|
||||
var b := Button.new()
|
||||
b.name = text
|
||||
b.custom_minimum_size = Vector2(0, 66)
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
var fg := Style.INK if primary else Style.ON_BG
|
||||
var margins := [64, 14, 20, 14]
|
||||
var normal := Style.bordered(Style.box(Style.ACCENT if primary else Color(1, 1, 1, 0.05), 10, margins), 1, Style.ACCENT if primary else Color(1, 1, 1, 0.18))
|
||||
var hover := Style.bordered(Style.box(Style.ACCENT.lightened(0.12) if primary else Color(1, 1, 1, 0.1), 10, margins), 1, Style.ACCENT if primary else Color(1, 1, 1, 0.3))
|
||||
Style.skin_button(b, normal, hover, hover, fg)
|
||||
b.text = text
|
||||
b.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||||
b.add_theme_font_override("font", Style.display())
|
||||
b.add_theme_font_size_override("font_size", 28)
|
||||
var icon_box := MenuIcons.make(icon, fg, 28)
|
||||
icon_box.position = Vector2(22, 19)
|
||||
b.add_child(icon_box)
|
||||
b.pressed.connect(on_press)
|
||||
buttons[text] = b
|
||||
return b
|
||||
|
||||
|
||||
func _small_button(text: String, icon: String, on_press: Callable) -> Button:
|
||||
var b := Button.new()
|
||||
b.name = text
|
||||
b.custom_minimum_size = Vector2(0, 52)
|
||||
b.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
var margins := [50, 12, 16, 12]
|
||||
var normal := Style.bordered(Style.box(Color(1, 1, 1, 0.05), 10, margins), 1, Color(1, 1, 1, 0.18))
|
||||
var hover := Style.bordered(Style.box(Color(1, 1, 1, 0.1), 10, margins), 1, Color(1, 1, 1, 0.3))
|
||||
Style.skin_button(b, normal, hover, hover, Style.ON_BG)
|
||||
b.text = text
|
||||
b.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||||
b.add_theme_font_size_override("font_size", 18)
|
||||
var icon_box := MenuIcons.make(icon, Style.ON_BG, 20)
|
||||
icon_box.position = Vector2(18, 16)
|
||||
b.add_child(icon_box)
|
||||
b.pressed.connect(on_press)
|
||||
buttons[text] = b
|
||||
return b
|
||||
|
||||
|
||||
## The open spread and your newest sheets, newest first (at most three rows).
|
||||
func refresh_recent() -> void:
|
||||
for c in recent_rows.get_children():
|
||||
recent_rows.remove_child(c)
|
||||
c.queue_free()
|
||||
if m.data:
|
||||
var n := m.data.tables.size()
|
||||
recent_rows.add_child(_recent_row(m.data.name, "Spread · %d %s" % [n, "card" if n == 1 else "cards"], "",
|
||||
func() -> void: m.screens.show(MainScreens.SPREAD)))
|
||||
var sheets := m.screens.sheets
|
||||
for row: Dictionary in sheets.store.list().slice(0, 2):
|
||||
var id := str(row["id"])
|
||||
recent_rows.add_child(_recent_row(str(row["name"]), "Sheet", _ago(int(row["modified"])), func() -> void:
|
||||
m.screens.show(MainScreens.SHEETS)
|
||||
sheets.open_sheet(id)))
|
||||
|
||||
|
||||
func _recent_row(title: String, sub: String, when: String, on_press: Callable) -> Button:
|
||||
var b := Button.new()
|
||||
b.name = title.validate_node_name()
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.custom_minimum_size = Vector2(0, 58)
|
||||
var normal := Style.box(Style.CARD, 8, [14, 10, 14, 10])
|
||||
var hover := Style.box(Style.CARD_HOVER, 8, [14, 10, 14, 10])
|
||||
Style.skin_button(b, normal, hover, hover, Style.INK)
|
||||
var h := HBoxContainer.new()
|
||||
h.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
h.offset_left = 14
|
||||
h.offset_right = -14
|
||||
h.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
b.add_child(h)
|
||||
var text := VBoxContainer.new()
|
||||
text.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
text.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
text.add_theme_constant_override("separation", 0)
|
||||
text.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
h.add_child(text)
|
||||
text.add_child(Style.make_label(title, Style.body_bold(), 15, Style.INK))
|
||||
text.add_child(Style.make_label(sub, Style.body(), 13, Style.MUTED))
|
||||
var w := Style.make_label(when, Style.body(), 13, Style.MUTED)
|
||||
w.size_flags_vertical = SIZE_SHRINK_CENTER
|
||||
h.add_child(w)
|
||||
b.pressed.connect(on_press)
|
||||
return b
|
||||
|
||||
|
||||
static func _ago(unix: int) -> String:
|
||||
var secs := int(Time.get_unix_time_from_system()) - unix
|
||||
if secs < 90:
|
||||
return "just now"
|
||||
if secs < 3600:
|
||||
return "%d min ago" % (secs / 60)
|
||||
if secs < 86400:
|
||||
return "%d h ago" % (secs / 3600)
|
||||
return "%d d ago" % (secs / 86400)
|
||||
|
||||
|
||||
## The app-wide settings that live outside a spread: theme and sound.
|
||||
func open_settings() -> void:
|
||||
var d := ModalCard.new("Settings", 420.0)
|
||||
var theme_button := ModalCard.make_button("Theme…", "plain")
|
||||
theme_button.pressed.connect(func() -> void:
|
||||
d.close()
|
||||
m.add_child(ThemeDialog.new(m)))
|
||||
d.body.add_child(theme_button)
|
||||
if m.sound:
|
||||
var sound_button := ModalCard.make_button("Sound…", "plain")
|
||||
sound_button.pressed.connect(func() -> void:
|
||||
SoundPanel.open(m, sound_button.get_global_rect().get_center()))
|
||||
d.body.add_child(sound_button)
|
||||
d.add_button("Done", "primary", d.close)
|
||||
m._add_modal(d)
|
||||
|
||||
|
||||
func quit() -> void:
|
||||
if m._save_timer and not m._save_timer.is_stopped():
|
||||
m._save_now()
|
||||
m.screens.sheets.leave()
|
||||
m.get_tree().quit()
|
||||
1
ui/main_menu.gd.uid
Normal file
1
ui/main_menu.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dkpay4ypdgpse
|
||||
76
ui/main_screens.gd
Normal file
76
ui/main_screens.gd
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
class_name MainScreens
|
||||
extends RefCounted
|
||||
## Which full-window screen shows: the main menu (MainMenu), the spread
|
||||
## editor (Main's own top bar, board and tray) or Sheets (SheetsScreen).
|
||||
## Real use starts on the main menu; tests, --sample and screenshots start
|
||||
## on the spread unless --menu or --sheets is given.
|
||||
|
||||
const MENU := "menu"
|
||||
const SPREAD := "spread"
|
||||
const SHEETS := "sheets"
|
||||
|
||||
var m: Main
|
||||
var spread_root: Control
|
||||
var menu: MainMenu
|
||||
var sheets: SheetsScreen
|
||||
var current := SPREAD
|
||||
## Kept across a theme change (which reloads the app): the screen to come back
|
||||
## to and the sheet that was open. Empty = start as usual.
|
||||
static var resume := {}
|
||||
|
||||
|
||||
func _init(p_main: Main) -> void:
|
||||
m = p_main
|
||||
|
||||
|
||||
## Called once the spread editor is built (`root` is its top-level box).
|
||||
func setup(root: Control) -> void:
|
||||
spread_root = root
|
||||
menu = MainMenu.new()
|
||||
menu.setup(m)
|
||||
menu.visible = false
|
||||
m.add_child(menu)
|
||||
sheets = SheetsScreen.new()
|
||||
sheets.setup(m)
|
||||
sheets.visible = false
|
||||
m.add_child(sheets)
|
||||
|
||||
|
||||
func show(which: String) -> void:
|
||||
if which == current:
|
||||
return
|
||||
if current == SHEETS:
|
||||
sheets.leave()
|
||||
current = which
|
||||
spread_root.visible = which == SPREAD
|
||||
menu.visible = which == MENU
|
||||
sheets.visible = which == SHEETS
|
||||
if which == SHEETS:
|
||||
sheets.enter()
|
||||
|
||||
|
||||
func showing(which: String) -> bool:
|
||||
return current == which
|
||||
|
||||
|
||||
## Where the app opens: back where it was after a theme change; otherwise the
|
||||
## main menu in real use, the spread for tests and screenshots (--menu and
|
||||
## --sheets pick a screen).
|
||||
func start(args: PackedStringArray) -> void:
|
||||
if not resume.is_empty():
|
||||
var back := resume
|
||||
resume = {}
|
||||
show(str(back.get("screen", MENU)))
|
||||
if str(back.get("sheet", "")) != "":
|
||||
sheets.open_sheet(str(back["sheet"]))
|
||||
return
|
||||
if args.has("--sheets"):
|
||||
show(SHEETS)
|
||||
elif args.has("--menu") or m._saving_enabled:
|
||||
show(MENU)
|
||||
|
||||
|
||||
## Remembers the screen (and open sheet) before the app reloads for a theme.
|
||||
func keep_for_reload() -> void:
|
||||
sheets.leave()
|
||||
resume = {"screen": current, "sheet": sheets.editor.doc.id if current == SHEETS and sheets.editor.doc else ""}
|
||||
1
ui/main_screens.gd.uid
Normal file
1
ui/main_screens.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b5upfp7bn4u2b
|
||||
|
|
@ -40,7 +40,7 @@ func _init(p_main: Main) -> void:
|
|||
|
||||
## The theme's logo (Style.LOGO): its mascot (Morgan Fortuna, the fortune
|
||||
## teller, by default; recoloured by MascotArt), the old tower mark, or none.
|
||||
func _logo() -> Control:
|
||||
static func logo() -> Control:
|
||||
match Style.LOGO:
|
||||
"fortune_teller", "mascot":
|
||||
var tr := TextureRect.new()
|
||||
|
|
@ -67,15 +67,8 @@ func _build_top_bar() -> Control:
|
|||
h.add_theme_constant_override("separation", 10)
|
||||
bar.add_child(h)
|
||||
|
||||
var brand := HBoxContainer.new()
|
||||
brand.add_theme_constant_override("separation", 9)
|
||||
var mark := _logo()
|
||||
if mark:
|
||||
brand.add_child(mark)
|
||||
var title := Style.make_label("Table Tarot", Style.display(), 23, Style.ON_BG)
|
||||
brand_title = title
|
||||
title.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
brand.add_child(title)
|
||||
var brand := make_brand(func() -> void: m.screens.show(MainScreens.MENU))
|
||||
brand_title = brand.get_child(brand.get_child_count() - 1)
|
||||
h.add_child(brand)
|
||||
|
||||
var seg := PanelContainer.new()
|
||||
|
|
@ -85,8 +78,8 @@ func _build_top_bar() -> Control:
|
|||
seg_row.add_theme_constant_override("separation", 0)
|
||||
seg.add_child(seg_row)
|
||||
var group := ButtonGroup.new()
|
||||
_play_button = _seg_button("Play", group)
|
||||
_build_button = _seg_button("Build", group)
|
||||
_play_button = seg_button("Play", group)
|
||||
_build_button = seg_button("Build", group)
|
||||
_play_button.button_pressed = true
|
||||
_play_button.pressed.connect(func() -> void: m.set_mode(Main.Mode.PLAY))
|
||||
_build_button.pressed.connect(func() -> void: m.set_mode(Main.Mode.BUILD))
|
||||
|
|
@ -163,7 +156,29 @@ func _build_top_bar() -> Control:
|
|||
return bar
|
||||
|
||||
|
||||
func _seg_button(text: String, group: ButtonGroup) -> Button:
|
||||
## The logo and "Table Tarot" in the accent colour, at the left of every top
|
||||
## bar (spread and sheet). Clicking it runs `on_click` (the main menu).
|
||||
static func make_brand(on_click: Callable) -> HBoxContainer:
|
||||
var brand := HBoxContainer.new()
|
||||
brand.add_theme_constant_override("separation", 9)
|
||||
var mark := logo()
|
||||
if mark:
|
||||
brand.add_child(mark)
|
||||
brand.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
brand.tooltip_text = "Main menu"
|
||||
brand.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
brand.gui_input.connect(func(ev: InputEvent) -> void:
|
||||
var mb := ev as InputEventMouseButton
|
||||
if mb and mb.pressed and mb.button_index == MOUSE_BUTTON_LEFT:
|
||||
on_click.call())
|
||||
var title := Style.make_label("Table Tarot", Style.display(), 23, Style.ACCENT)
|
||||
title.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
brand.add_child(title)
|
||||
return brand
|
||||
|
||||
|
||||
## One half of the Play | Build switch (also used by the sheet editor).
|
||||
static func seg_button(text: String, group: ButtonGroup) -> Button:
|
||||
var b := Button.new()
|
||||
b.text = text
|
||||
b.toggle_mode = true
|
||||
|
|
|
|||
56
ui/menu_icons.gd
Normal file
56
ui/menu_icons.gd
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
class_name MenuIcons
|
||||
extends RefCounted
|
||||
## Small line icons drawn in code (no image files), for the main menu and the
|
||||
## palettes. Each paints into a 24×24 box scaled to `size`.
|
||||
|
||||
const SHEET := "sheet"
|
||||
const SPREAD := "spread"
|
||||
const SETTINGS := "settings"
|
||||
const QUIT := "quit"
|
||||
const SEARCH := "search"
|
||||
|
||||
|
||||
## A Control that draws icon `kind` in `color`, `size` pixels square.
|
||||
static func make(kind: String, color: Color, size: float = 24.0) -> Control:
|
||||
var c := Control.new()
|
||||
c.custom_minimum_size = Vector2(size, size)
|
||||
c.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
c.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
c.draw.connect(func() -> void: paint(c, kind, color, size / 24.0))
|
||||
return c
|
||||
|
||||
|
||||
static func paint(c: CanvasItem, kind: String, color: Color, k: float) -> void:
|
||||
var w := 2.0 * k
|
||||
var line := func(a: Vector2, b: Vector2) -> void: c.draw_line(a * k, b * k, color, w, true)
|
||||
var rect := func(r: Rect2) -> void: c.draw_rect(Rect2(r.position * k, r.size * k), color, false, w, true)
|
||||
match kind:
|
||||
SHEET:
|
||||
rect.call(Rect2(4, 3, 16, 18))
|
||||
line.call(Vector2(8, 8), Vector2(16, 8))
|
||||
line.call(Vector2(8, 12), Vector2(11, 12))
|
||||
line.call(Vector2(13, 12), Vector2(16, 12))
|
||||
line.call(Vector2(8, 16), Vector2(16, 16))
|
||||
SPREAD:
|
||||
rect.call(Rect2(3, 4, 7, 9))
|
||||
rect.call(Rect2(14, 11, 7, 9))
|
||||
var pts := PackedVector2Array()
|
||||
for i in 9:
|
||||
var t := i / 8.0
|
||||
pts.append(Vector2(10 + 4 * t, 8 + 6 * t * t) * k)
|
||||
c.draw_polyline(pts, color, w, true)
|
||||
SETTINGS:
|
||||
c.draw_arc(Vector2(12, 12) * k, 3.0 * k, 0.0, TAU, 20, color, w, true)
|
||||
for i in 8:
|
||||
var dir := Vector2.RIGHT.rotated(i * TAU / 8.0)
|
||||
line.call(Vector2(12, 12) + dir * 6.5, Vector2(12, 12) + dir * 9.5)
|
||||
QUIT:
|
||||
line.call(Vector2(15, 4), Vector2(19, 4))
|
||||
line.call(Vector2(19, 4), Vector2(19, 20))
|
||||
line.call(Vector2(19, 20), Vector2(15, 20))
|
||||
line.call(Vector2(6, 12), Vector2(16, 12))
|
||||
line.call(Vector2(10, 8), Vector2(6, 12))
|
||||
line.call(Vector2(10, 16), Vector2(6, 12))
|
||||
SEARCH:
|
||||
c.draw_arc(Vector2(10.5, 10.5) * k, 6.0 * k, 0.0, TAU, 24, color, w, true)
|
||||
line.call(Vector2(15, 15), Vector2(20, 20))
|
||||
1
ui/menu_icons.gd.uid
Normal file
1
ui/menu_icons.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dnra7pi4l3erh
|
||||
130
ui/new_sheet_dialog.gd
Normal file
130
ui/new_sheet_dialog.gd
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
class_name NewSheetDialog
|
||||
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).
|
||||
|
||||
var store: SheetStore
|
||||
var name_edit: LineEdit
|
||||
var create_button: Button
|
||||
var _choice := ""
|
||||
var _choices: Dictionary = {} # template id ("" = blank) -> Button
|
||||
var _names: Dictionary = {} # template id -> name
|
||||
var _on_create: Callable
|
||||
|
||||
|
||||
func _init(p_store: SheetStore, template_id: String, on_create: Callable) -> void:
|
||||
super._init("New sheet", 720.0)
|
||||
store = p_store
|
||||
_on_create = on_create
|
||||
_choice = template_id
|
||||
var label := Style.make_label("Name", Style.body_bold(), 15, Style.INK)
|
||||
body.add_child(label)
|
||||
name_edit = LineEdit.new()
|
||||
name_edit.placeholder_text = "e.g. Brin Hollowmere, The Rusty Mule"
|
||||
ModalCard.style_line_edit(name_edit)
|
||||
name_edit.text_submitted.connect(func(_s: String) -> void: _create())
|
||||
body.add_child(name_edit)
|
||||
var grid := GridContainer.new()
|
||||
grid.columns = 3
|
||||
grid.add_theme_constant_override("h_separation", 10)
|
||||
grid.add_theme_constant_override("v_separation", 10)
|
||||
body.add_child(grid)
|
||||
var group := ButtonGroup.new()
|
||||
grid.add_child(_option(group, "", "Blank canvas", "One Main tab, a snap grid, nothing else", ""))
|
||||
for row: Dictionary in store.list(true):
|
||||
var tpl := store.load_sheet(str(row["id"]), true)
|
||||
if tpl == null:
|
||||
continue
|
||||
_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))
|
||||
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
|
||||
footer.add_child(hint)
|
||||
add_button("Cancel", "plain", close)
|
||||
create_button = add_button("", "primary", _create)
|
||||
_update_create()
|
||||
ready.connect(func() -> void: name_edit.grab_focus())
|
||||
|
||||
|
||||
## One start in the grid: a small picture, a title and a line under it.
|
||||
func _option(group: ButtonGroup, id: String, title: String, sub: String, tint: String) -> Button:
|
||||
var b := Button.new()
|
||||
b.name = ("Blank" if id == "" else id).validate_node_name()
|
||||
b.toggle_mode = true
|
||||
b.button_group = group
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.custom_minimum_size = Vector2(200, 172)
|
||||
b.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
var normal := Style.bordered(Style.box(Style.CARD, 10, [12, 12, 12, 12]), 2, Style.RULE)
|
||||
var hover := Style.bordered(Style.box(Style.CARD_SOFT, 10, [12, 12, 12, 12]), 2, Style.DASH)
|
||||
var on := Style.bordered(Style.box(Style.CARD_SOFT, 10, [12, 12, 12, 12]), 2, Style.TRIM)
|
||||
Style.skin_button(b, normal, hover, on, Style.INK)
|
||||
b.button_pressed = id == _choice
|
||||
b.pressed.connect(func() -> void:
|
||||
_choice = id
|
||||
_update_create())
|
||||
var col := VBoxContainer.new()
|
||||
col.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
col.offset_left = 12
|
||||
col.offset_top = 12
|
||||
col.offset_right = -12
|
||||
col.offset_bottom = -12
|
||||
col.add_theme_constant_override("separation", 6)
|
||||
col.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
b.add_child(col)
|
||||
var thumb := Control.new()
|
||||
thumb.custom_minimum_size.y = 72
|
||||
thumb.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
thumb.draw.connect(func() -> void: _draw_thumb(thumb, id == "", tint))
|
||||
col.add_child(thumb)
|
||||
col.add_child(Style.make_label(title, Style.body_bold(), 15, Style.INK))
|
||||
var line := Style.make_label(sub, Style.body(), 13, Style.MUTED)
|
||||
line.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
col.add_child(line)
|
||||
_choices[id] = b
|
||||
return b
|
||||
|
||||
|
||||
## Blank: a card with grid lines. Template: its tint (or the cloth) with three boxes.
|
||||
static func _draw_thumb(c: Control, blank: bool, tint: String) -> void:
|
||||
var r := Rect2(Vector2.ZERO, c.size)
|
||||
if blank:
|
||||
c.draw_rect(r, Style.CARD_SOFT)
|
||||
var x := 0.0
|
||||
while x < r.size.x:
|
||||
c.draw_line(Vector2(x, 0), Vector2(x, r.size.y), Style.RULE, 1.0)
|
||||
x += 12.0
|
||||
var y := 0.0
|
||||
while y < r.size.y:
|
||||
c.draw_line(Vector2(0, y), Vector2(r.size.x, y), Style.RULE, 1.0)
|
||||
y += 12.0
|
||||
return
|
||||
c.draw_rect(r, Color(tint).darkened(0.45) if tint != "" else Style.BG)
|
||||
var box := Style.CARD if tint == "" else Style.CARD.lerp(Color(tint), 0.15)
|
||||
c.draw_rect(Rect2(8, 8, r.size.x * 0.38, r.size.y * 0.5), box)
|
||||
c.draw_rect(Rect2(r.size.x * 0.56 - 8, 8, r.size.x * 0.44, r.size.y * 0.3), box)
|
||||
c.draw_rect(Rect2(r.size.x * 0.56 - 8, r.size.y * 0.7 - 8, r.size.x * 0.44, r.size.y * 0.3), box)
|
||||
|
||||
|
||||
func _update_create() -> void:
|
||||
create_button.text = "Create blank sheet" if _choice == "" else "Create from %s" % _names.get(_choice, "template")
|
||||
|
||||
|
||||
## Picks a start (tests use it).
|
||||
func choose(id: String) -> void:
|
||||
if _choices.has(id):
|
||||
(_choices[id] as Button).button_pressed = true
|
||||
_choice = id
|
||||
_update_create()
|
||||
|
||||
|
||||
func _create() -> void:
|
||||
var name := name_edit.text.strip_edges()
|
||||
if name == "":
|
||||
name = "New %s" % _names[_choice] if _choice != "" else "Untitled sheet"
|
||||
close()
|
||||
_on_create.call(name, _choice)
|
||||
1
ui/new_sheet_dialog.gd.uid
Normal file
1
ui/new_sheet_dialog.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bha1qn2tgtllt
|
||||
197
ui/palette_list.gd
Normal file
197
ui/palette_list.gd
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
class_name PaletteList
|
||||
extends VBoxContainer
|
||||
## A palette: a search box over grouped items in two columns. Click an item to
|
||||
## add it; drag it to drop it somewhere. Shared by the card palette
|
||||
## (CardPalette, spreads) and the field palette (FieldPalette, sheets).
|
||||
## The owner fills it through callables:
|
||||
## - sections_for(query) -> [[group title, [[item, on_add(at)], …]], …]
|
||||
## (item: {label, tip, group, words}; at = Vector2.INF for "no place given")
|
||||
## - can_use() -> bool: false greys the items (Play mode); a click then calls on_blocked()
|
||||
## - drop_at(on_add, screen_point) -> bool: places a dragged item, true if taken
|
||||
## - after_use(): runs after an item was added (phones go back to the canvas)
|
||||
|
||||
var search: LineEdit
|
||||
var sections_for := Callable()
|
||||
var can_use := Callable()
|
||||
var on_blocked := Callable()
|
||||
var drop_at := Callable()
|
||||
var after_use := Callable()
|
||||
var _items: VBoxContainer
|
||||
var _dragging := Callable()
|
||||
var _greyed := false
|
||||
var _try_words := ""
|
||||
|
||||
|
||||
func setup(placeholder: String, hint_text: String, title_text: String = "", try_words: String = "") -> void:
|
||||
add_theme_constant_override("separation", 12)
|
||||
_try_words = try_words
|
||||
if title_text != "":
|
||||
var head := VBoxContainer.new()
|
||||
head.add_theme_constant_override("separation", 0)
|
||||
head.add_child(Style.make_label(title_text, Style.display(), 19, Style.ON_BG))
|
||||
var hint := Style.make_label(hint_text, Style.body(), 13, Style.ON_BG_MUTED)
|
||||
hint.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
head.add_child(hint)
|
||||
add_child(head)
|
||||
search = LineEdit.new()
|
||||
search.placeholder_text = placeholder
|
||||
search.clear_button_enabled = true
|
||||
style_search(search)
|
||||
search.text_changed.connect(func(_s: String) -> void: rebuild())
|
||||
search.text_submitted.connect(func(_s: String) -> void: use_first())
|
||||
add_child(search)
|
||||
var scroll := ScrollContainer.new()
|
||||
scroll.size_flags_vertical = SIZE_EXPAND_FILL
|
||||
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
add_child(scroll)
|
||||
_items = VBoxContainer.new()
|
||||
_items.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
_items.add_theme_constant_override("separation", 12)
|
||||
scroll.add_child(_items)
|
||||
if title_text == "":
|
||||
var hint := Style.make_label(hint_text, Style.body(), 12, Style.ON_BG_MUTED)
|
||||
hint.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
add_child(hint)
|
||||
|
||||
|
||||
## A search box for a dark panel: translucent, with a magnifier on the left.
|
||||
static func style_search(edit: LineEdit) -> void:
|
||||
var normal := Style.bordered(Style.box(Color(1, 1, 1, 0.07), 8, [32, 8, 8, 8]), 1, Color(1, 1, 1, 0.22))
|
||||
var focus := Style.bordered(Style.box(Color(1, 1, 1, 0.1), 8, [32, 8, 8, 8]), 1, Style.ACCENT)
|
||||
edit.add_theme_stylebox_override("normal", normal)
|
||||
edit.add_theme_stylebox_override("focus", focus)
|
||||
edit.add_theme_color_override("font_color", Style.ON_BG)
|
||||
edit.add_theme_color_override("font_placeholder_color", Style.ON_BG_MUTED)
|
||||
edit.add_theme_color_override("caret_color", Style.ON_BG)
|
||||
edit.add_theme_color_override("clear_button_color", Style.ON_BG_MUTED)
|
||||
edit.add_theme_font_size_override("font_size", 14)
|
||||
var icon := MenuIcons.make(MenuIcons.SEARCH, Style.ON_BG_MUTED, 16)
|
||||
icon.position = Vector2(10, 10)
|
||||
edit.add_child(icon)
|
||||
|
||||
|
||||
## True when `query` (lower case, may be "") matches every word against the
|
||||
## item's label, tip, group or search words.
|
||||
static func matches(item: Dictionary, query: String) -> bool:
|
||||
if query == "":
|
||||
return true
|
||||
var hay := " ".join([item.get("label", ""), item.get("tip", ""), item.get("group", ""), item.get("words", "")]).to_lower()
|
||||
for word in query.split(" ", false):
|
||||
if not hay.contains(word):
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
func query() -> String:
|
||||
return search.text.strip_edges().to_lower()
|
||||
|
||||
|
||||
## Greys the items (true) or not; checked every frame against can_use.
|
||||
func _process(_delta: float) -> void:
|
||||
var grey: bool = can_use.is_valid() and not can_use.call()
|
||||
if grey != _greyed:
|
||||
_greyed = grey
|
||||
_items.modulate.a = 0.45 if grey else 1.0
|
||||
|
||||
|
||||
func rebuild() -> void:
|
||||
for c in _items.get_children():
|
||||
_items.remove_child(c)
|
||||
c.queue_free()
|
||||
var any := false
|
||||
for section: Array in _sections():
|
||||
if (section[1] as Array).is_empty():
|
||||
continue
|
||||
any = true
|
||||
var group := VBoxContainer.new()
|
||||
group.add_theme_constant_override("separation", 6)
|
||||
_items.add_child(group)
|
||||
group.add_child(Style.make_label(str(section[0]).to_upper(), Style.caps(), 11, Style.ACCENT))
|
||||
var grid := GridContainer.new()
|
||||
grid.columns = 2
|
||||
grid.add_theme_constant_override("h_separation", 5)
|
||||
grid.add_theme_constant_override("v_separation", 5)
|
||||
group.add_child(grid)
|
||||
for entry: Array in section[1]:
|
||||
grid.add_child(_item_button(entry[0], entry[1]))
|
||||
if not any:
|
||||
var box := PanelContainer.new()
|
||||
var dashed := StyleBoxFlat.new()
|
||||
dashed.bg_color = Color(0, 0, 0, 0)
|
||||
dashed.border_color = Color(1, 1, 1, 0.25)
|
||||
dashed.set_border_width_all(1)
|
||||
dashed.set_corner_radius_all(8)
|
||||
dashed.set_content_margin_all(10)
|
||||
box.add_theme_stylebox_override("panel", dashed)
|
||||
var text := "Nothing matches “%s”." % search.text.strip_edges()
|
||||
if _try_words != "":
|
||||
text += " Try a word like %s." % _try_words
|
||||
var none := Style.make_label(text, Style.body(), 13, Style.ON_BG_MUTED)
|
||||
none.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
box.add_child(none)
|
||||
_items.add_child(box)
|
||||
|
||||
|
||||
func _sections() -> Array:
|
||||
return sections_for.call(query()) if sections_for.is_valid() else []
|
||||
|
||||
|
||||
## Enter in the search box adds the first item shown.
|
||||
func use_first() -> void:
|
||||
for section: Array in _sections():
|
||||
if not (section[1] as Array).is_empty():
|
||||
use(section[1][0][1], Vector2.INF)
|
||||
return
|
||||
|
||||
|
||||
## Adds through `on_add`, or calls on_blocked when items are greyed.
|
||||
func use(on_add: Callable, at: Vector2) -> void:
|
||||
if can_use.is_valid() and not can_use.call():
|
||||
if on_blocked.is_valid():
|
||||
on_blocked.call()
|
||||
return
|
||||
on_add.call(at)
|
||||
if after_use.is_valid():
|
||||
after_use.call()
|
||||
|
||||
|
||||
func _item_button(item: Dictionary, on_add: Callable) -> Button:
|
||||
var b := Button.new()
|
||||
b.text = str(item["label"])
|
||||
b.name = str(item["label"]).validate_node_name()
|
||||
var normal := Style.bordered(Style.box(Color(1, 1, 1, 0.05), 6, [8, 6, 8, 6]), 1, Color(1, 1, 1, 0.14))
|
||||
var hover := Style.bordered(Style.box(Color(1, 1, 1, 0.12), 6, [8, 6, 8, 6]), 1, Color(1, 1, 1, 0.3))
|
||||
Style.skin_button(b, normal, hover, hover, Style.ON_BG)
|
||||
b.add_theme_font_size_override("font_size", 13)
|
||||
b.mouse_default_cursor_shape = Control.CURSOR_DRAG
|
||||
b.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
b.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||||
b.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
||||
b.clip_text = true
|
||||
b.custom_minimum_size.x = 60
|
||||
b.tooltip_text = str(item.get("tip", ""))
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.pressed.connect(func() -> void: use(on_add, Vector2.INF))
|
||||
b.set_drag_forwarding(func(_at: Vector2) -> Variant: return _start_drag(item, on_add), Callable(), Callable())
|
||||
return b
|
||||
|
||||
|
||||
func _start_drag(item: Dictionary, on_add: Callable) -> Variant:
|
||||
if can_use.is_valid() and not can_use.call():
|
||||
return null
|
||||
_dragging = on_add
|
||||
var label := Style.make_label(str(item["label"]), 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)
|
||||
set_drag_preview(chip)
|
||||
return {"palette_item": item["label"]}
|
||||
|
||||
|
||||
## Nothing took the drop, so the owner places the item where it was let go.
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_DRAG_END and _dragging.is_valid():
|
||||
var on_add := _dragging
|
||||
_dragging = Callable()
|
||||
if not get_viewport().gui_is_drag_successful() and drop_at.is_valid():
|
||||
drop_at.call(on_add, get_global_mouse_position())
|
||||
1
ui/palette_list.gd.uid
Normal file
1
ui/palette_list.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://djqy8wsyus22h
|
||||
177
ui/sheet_box_view.gd
Normal file
177
ui/sheet_box_view.gd
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
class_name SheetBoxView
|
||||
extends Panel
|
||||
## One box on the sheet canvas: a card with a title band on top (headings and
|
||||
## frameless boxes have none). Its colour tints the card, band and border
|
||||
## (look). In Play its field takes input (SheetFieldViews); in Build the
|
||||
## whole box is a handle: click selects, drag moves (snapped to the grid; Alt
|
||||
## places freely), the corner grip resizes.
|
||||
|
||||
const GRIP := 14.0
|
||||
const MIN_SIZE := Vector2(48, 32)
|
||||
const BAND := 30.0
|
||||
|
||||
var ed: SheetEditor
|
||||
var box: SheetBox
|
||||
var colors: Dictionary
|
||||
var _drag := "" # "", "move" or "resize"
|
||||
var _from := Vector2.ZERO
|
||||
var _start := Rect2()
|
||||
var _before: Dictionary = {}
|
||||
var _selected := false
|
||||
|
||||
|
||||
## The box's colours: card, band, border, ink and muted ink. A colour tints
|
||||
## the card lightly, the band more and the border most; frameless boxes sit
|
||||
## on the cloth with light ink.
|
||||
static func look(hex: String, frameless: bool) -> Dictionary:
|
||||
if frameless:
|
||||
return {"bg": Color(0, 0, 0, 0), "head": Color(0, 0, 0, 0), "border": Color(0, 0, 0, 0),
|
||||
"ink": Style.ON_BG, "muted": Style.ON_BG_MUTED}
|
||||
if hex == "":
|
||||
return {"bg": Style.CARD, "head": Style.CARD_HEAD, "border": Style.DASH, "ink": Style.INK, "muted": Style.MUTED}
|
||||
var tint := Color(hex)
|
||||
return {"bg": Style.CARD.lerp(tint, 0.1), "head": Style.CARD.lerp(tint, 0.3), "border": Style.CARD.lerp(tint, 0.6),
|
||||
"ink": Style.INK, "muted": Style.MUTED}
|
||||
|
||||
|
||||
func setup(p_editor: SheetEditor, p_box: SheetBox) -> void:
|
||||
ed = p_editor
|
||||
box = p_box
|
||||
name = box.id
|
||||
colors = look(box.color, box.frameless)
|
||||
position = Vector2(box.x, box.y)
|
||||
size = Vector2(box.w, box.h)
|
||||
custom_minimum_size = Vector2(box.w, box.h)
|
||||
clip_contents = true
|
||||
# A Panel doesn't grow to fit its content, so a box keeps the size it was given.
|
||||
var col := VBoxContainer.new()
|
||||
col.add_theme_constant_override("separation", 0)
|
||||
col.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
add_child(col)
|
||||
var banded := box.kind != SheetKinds.HEADING and not box.frameless and box.title != ""
|
||||
if banded:
|
||||
col.add_child(_band())
|
||||
elif box.kind != SheetKinds.HEADING and box.title != "":
|
||||
var caption := Style.make_label(box.title.to_upper(), Style.caps(), 11, colors["muted"])
|
||||
caption.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
||||
var pad := MarginContainer.new()
|
||||
_margins(pad, 10, 6, 10, 0)
|
||||
pad.add_child(caption)
|
||||
col.add_child(pad)
|
||||
var body := MarginContainer.new()
|
||||
body.size_flags_vertical = SIZE_EXPAND_FILL
|
||||
_margins(body, 10, 6, 10, 8)
|
||||
col.add_child(body)
|
||||
body.add_child(SheetFieldViews.make(ed, box, colors["ink"]))
|
||||
if ed.building():
|
||||
mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
_ignore_mouse(col)
|
||||
gui_input.connect(_build_input)
|
||||
mouse_default_cursor_shape = Control.CURSOR_MOVE
|
||||
tooltip_text = "Drag to move · corner to resize · Alt: off the grid"
|
||||
paint(false)
|
||||
|
||||
|
||||
func _band() -> PanelContainer:
|
||||
var band := PanelContainer.new()
|
||||
band.custom_minimum_size.y = BAND
|
||||
var sb := Style.box(colors["head"], 7, [10, 4, 10, 4])
|
||||
sb.corner_radius_bottom_left = 0
|
||||
sb.corner_radius_bottom_right = 0
|
||||
band.add_theme_stylebox_override("panel", sb)
|
||||
var title := Style.make_label(box.title, Style.display(), 17, colors["ink"])
|
||||
title.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
||||
title.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
band.add_child(title)
|
||||
return band
|
||||
|
||||
|
||||
static func _margins(c: MarginContainer, left: int, top: int, right: int, bottom: int) -> void:
|
||||
c.add_theme_constant_override("margin_left", left)
|
||||
c.add_theme_constant_override("margin_top", top)
|
||||
c.add_theme_constant_override("margin_right", right)
|
||||
c.add_theme_constant_override("margin_bottom", bottom)
|
||||
|
||||
|
||||
func paint(selected: bool) -> void:
|
||||
_selected = selected
|
||||
var sb := Style.box(colors["bg"], 8, [0, 0, 0, 0])
|
||||
if box.frameless:
|
||||
if ed.building():
|
||||
sb = Style.bordered(sb, 1, Color(Style.ON_BG, 0.35))
|
||||
else:
|
||||
sb = Style.bordered(sb, 1, colors["border"])
|
||||
if selected:
|
||||
sb = Style.bordered(sb, 2, Style.SELECTED)
|
||||
sb.shadow_color = Color(Style.SELECTED, 0.45)
|
||||
sb.shadow_size = 9
|
||||
add_theme_stylebox_override("panel", sb)
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
if not ed.building():
|
||||
return
|
||||
var c := Style.SELECTED if _selected else Color(colors["muted"], 0.7)
|
||||
var corner := size - Vector2(4, 4)
|
||||
for i in 3:
|
||||
var d := 4.0 + i * 4.0
|
||||
draw_line(corner - Vector2(d, 0), corner - Vector2(0, d), c, 1.5, true)
|
||||
|
||||
|
||||
func _ignore_mouse(node: Node) -> void:
|
||||
for child in node.get_children():
|
||||
if child is Control:
|
||||
(child as Control).mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_ignore_mouse(child)
|
||||
|
||||
|
||||
func _build_input(ev: InputEvent) -> void:
|
||||
var mb := ev as InputEventMouseButton
|
||||
if mb and mb.button_index == MOUSE_BUTTON_LEFT:
|
||||
if mb.pressed:
|
||||
ed.select(box.id)
|
||||
var in_grip := mb.position.x > size.x - GRIP * 1.5 and mb.position.y > size.y - GRIP * 1.5
|
||||
_drag = "resize" if in_grip else "move"
|
||||
_from = mb.global_position
|
||||
_start = box.rect()
|
||||
_before = ed.doc.to_dict()
|
||||
elif _drag != "":
|
||||
end_drag()
|
||||
ed.canvas._fit_area()
|
||||
accept_event()
|
||||
return
|
||||
var mm := ev as InputEventMouseMotion
|
||||
if mm and _drag != "":
|
||||
drag_to(mm.global_position - _from, Input.is_key_pressed(KEY_ALT))
|
||||
accept_event()
|
||||
|
||||
|
||||
## Moves or resizes by `delta` screen pixels from where the drag began.
|
||||
func drag_to(delta: Vector2, free: bool) -> void:
|
||||
var r := _start
|
||||
if _drag == "move":
|
||||
r.position = (_start.position + delta).max(Vector2.ZERO)
|
||||
if not free:
|
||||
r.position = Vector2(SheetKinds.snap(r.position.x), SheetKinds.snap(r.position.y))
|
||||
else:
|
||||
r.size = (_start.size + delta).max(MIN_SIZE)
|
||||
if not free:
|
||||
r.size = Vector2(maxf(SheetKinds.snap(r.size.x), MIN_SIZE.x), maxf(SheetKinds.snap(r.size.y), MIN_SIZE.y))
|
||||
box.set_rect(r)
|
||||
position = r.position
|
||||
custom_minimum_size = r.size
|
||||
size = r.size
|
||||
ed.update_status()
|
||||
|
||||
|
||||
## Starts a drag without a mouse press (tests use it).
|
||||
func begin_drag(kind: String) -> void:
|
||||
_drag = kind
|
||||
_start = box.rect()
|
||||
_before = ed.doc.to_dict()
|
||||
|
||||
|
||||
func end_drag() -> void:
|
||||
_drag = ""
|
||||
ed.record_from(_before, "Resize box" if _start.size != box.rect().size else "Move box")
|
||||
1
ui/sheet_box_view.gd.uid
Normal file
1
ui/sheet_box_view.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bmb3s4l0fqniw
|
||||
110
ui/sheet_canvas.gd
Normal file
110
ui/sheet_canvas.gd
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
class_name SheetCanvas
|
||||
extends ScrollContainer
|
||||
## The open tab's canvas: the theme's spread background (BoardBackdrop) with
|
||||
## a free layout of boxes (SheetBoxView) centred on it, scrolling when the
|
||||
## boxes reach past the window. In Build it shows the snap grid as dots;
|
||||
## clicking empty space clears the selection. The field palette drops new
|
||||
## boxes here (drop_point).
|
||||
|
||||
## Room kept around the boxes, and below them to place more.
|
||||
const MARGIN := 16.0
|
||||
const ROOM := 240.0
|
||||
|
||||
var ed: SheetEditor
|
||||
## Fills the scroll area; draws the background.
|
||||
var holder: Control
|
||||
## The page the boxes sit on (box coordinates start at its top-left).
|
||||
var area: Control
|
||||
var views: Dictionary = {} # box id -> SheetBoxView
|
||||
var _backdrop: BoardBackdrop
|
||||
|
||||
|
||||
func setup(p_editor: SheetEditor) -> void:
|
||||
ed = p_editor
|
||||
add_theme_stylebox_override("panel", StyleBoxEmpty.new())
|
||||
_backdrop = BoardBackdrop.new(ThemeStore.current)
|
||||
holder = Control.new()
|
||||
holder.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
holder.draw.connect(_draw_back)
|
||||
holder.gui_input.connect(_area_input)
|
||||
add_child(holder)
|
||||
area = Control.new()
|
||||
area.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
holder.add_child(area)
|
||||
resized.connect(_fit_area)
|
||||
|
||||
|
||||
func rebuild() -> void:
|
||||
for c in area.get_children():
|
||||
area.remove_child(c)
|
||||
c.queue_free()
|
||||
views.clear()
|
||||
for box: SheetBox in ed.current_tab()["boxes"]:
|
||||
var view := SheetBoxView.new()
|
||||
view.setup(ed, box)
|
||||
area.add_child(view)
|
||||
views[box.id] = view
|
||||
paint_selection()
|
||||
_fit_area()
|
||||
|
||||
|
||||
func paint_selection() -> void:
|
||||
for id: String in views:
|
||||
(views[id] as SheetBoxView).paint(id == ed.selected)
|
||||
|
||||
|
||||
## Sizes the page to its boxes (plus room below), centres it across, and
|
||||
## grows the scroll area to hold it.
|
||||
func _fit_area() -> void:
|
||||
var page := Vector2.ZERO
|
||||
for view: SheetBoxView in views.values():
|
||||
page = page.max(view.position + view.size)
|
||||
page += Vector2(MARGIN, ROOM)
|
||||
var view_size := size
|
||||
var x := maxf(MARGIN, floorf((view_size.x - page.x) / 2.0))
|
||||
area.position = Vector2(x, MARGIN)
|
||||
area.size = Vector2(maxf(page.x, view_size.x - x - MARGIN), maxf(page.y, view_size.y - MARGIN * 2))
|
||||
holder.custom_minimum_size = (area.position + area.size + Vector2(MARGIN, MARGIN)).max(view_size)
|
||||
holder.queue_redraw()
|
||||
|
||||
|
||||
func _draw_back() -> void:
|
||||
_backdrop.draw(holder, Rect2(Vector2.ZERO, holder.size))
|
||||
if ed.doc and ed.doc.tint != "":
|
||||
holder.draw_rect(Rect2(Vector2.ZERO, holder.size), Color(Color(ed.doc.tint), 0.28))
|
||||
_draw_grid()
|
||||
|
||||
|
||||
## The snap grid as dots over the whole canvas (Build only), lined up with the
|
||||
## page's corner so boxes snap onto the dots.
|
||||
func _draw_grid() -> void:
|
||||
if ed.doc == null or not ed.building():
|
||||
return
|
||||
var step := SheetKinds.GRID
|
||||
var dot := Color(Style.ON_BG, 0.2)
|
||||
var start := area.position.posmod(step)
|
||||
var y := start.y
|
||||
while y <= holder.size.y:
|
||||
var x := start.x
|
||||
while x <= holder.size.x:
|
||||
holder.draw_circle(Vector2(x, y), 1.0, dot)
|
||||
x += step
|
||||
y += step
|
||||
|
||||
|
||||
func _area_input(ev: InputEvent) -> void:
|
||||
var mb := ev as InputEventMouseButton
|
||||
if mb and mb.pressed and mb.button_index == MOUSE_BUTTON_LEFT and ed.selected != "":
|
||||
ed.select("")
|
||||
|
||||
|
||||
## The middle of what is on screen, in page coordinates.
|
||||
func visible_center() -> Vector2:
|
||||
return Vector2(scroll_horizontal, scroll_vertical) + size / 2.0 - area.position
|
||||
|
||||
|
||||
## A screen point in page coordinates, or Vector2.INF when it isn't over the canvas.
|
||||
func drop_point(screen_point: Vector2) -> Vector2:
|
||||
if not is_visible_in_tree() or not get_global_rect().has_point(screen_point):
|
||||
return Vector2.INF
|
||||
return screen_point - area.global_position
|
||||
1
ui/sheet_canvas.gd.uid
Normal file
1
ui/sheet_canvas.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ceq5owlxepunp
|
||||
277
ui/sheet_editor.gd
Normal file
277
ui/sheet_editor.gd
Normal file
|
|
@ -0,0 +1,277 @@
|
|||
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).
|
||||
## 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.
|
||||
|
||||
const SAVE_DELAY := 0.6
|
||||
## Typing in the same field this close together is one undo step.
|
||||
const MERGE_SECS := 1.5
|
||||
|
||||
var m: Main
|
||||
var screen: SheetsScreen
|
||||
var doc: SheetDoc
|
||||
var history := SnapshotHistory.new()
|
||||
var mode: Main.Mode = Main.Mode.PLAY
|
||||
var tab_id := ""
|
||||
var selected := ""
|
||||
var top_bar: SheetTopBar
|
||||
var palette_dock: PanelContainer
|
||||
var palette: FieldPalette
|
||||
var tabs_bar: SheetTabsBar
|
||||
var canvas: SheetCanvas
|
||||
var inspector: SheetInspector
|
||||
var status_label: Label
|
||||
var undo_label: Label
|
||||
var _save_timer: Timer
|
||||
var _dirty := false
|
||||
var _merge_key := ""
|
||||
var _merge_at := 0.0
|
||||
|
||||
|
||||
func setup(p_main: Main, p_screen: SheetsScreen) -> void:
|
||||
m = p_main
|
||||
screen = p_screen
|
||||
add_theme_constant_override("separation", 0)
|
||||
top_bar = SheetTopBar.new()
|
||||
top_bar.setup(self)
|
||||
add_child(top_bar)
|
||||
tabs_bar = SheetTabsBar.new()
|
||||
tabs_bar.setup(self)
|
||||
add_child(tabs_bar)
|
||||
var middle := HBoxContainer.new()
|
||||
middle.add_theme_constant_override("separation", 0)
|
||||
middle.size_flags_vertical = SIZE_EXPAND_FILL
|
||||
add_child(middle)
|
||||
palette_dock = _make_palette_dock()
|
||||
middle.add_child(palette_dock)
|
||||
canvas = SheetCanvas.new()
|
||||
canvas.setup(self)
|
||||
canvas.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
middle.add_child(canvas)
|
||||
inspector = SheetInspector.new()
|
||||
inspector.setup(self)
|
||||
middle.add_child(inspector)
|
||||
add_child(_make_status_strip())
|
||||
_save_timer = Timer.new()
|
||||
_save_timer.one_shot = true
|
||||
_save_timer.wait_time = SAVE_DELAY
|
||||
_save_timer.timeout.connect(save_now)
|
||||
add_child(_save_timer)
|
||||
|
||||
|
||||
func _make_palette_dock() -> PanelContainer:
|
||||
var dock := PanelContainer.new()
|
||||
dock.custom_minimum_size.x = 232
|
||||
var sb := Style.box(Style.BG_DEEP, 0, [12, 14, 12, 14])
|
||||
sb.border_color = Color(1, 1, 1, 0.08)
|
||||
sb.border_width_right = 1
|
||||
dock.add_theme_stylebox_override("panel", sb)
|
||||
palette = FieldPalette.new()
|
||||
palette.setup(self)
|
||||
dock.add_child(palette)
|
||||
return dock
|
||||
|
||||
|
||||
## The strip along the bottom: what Build is doing (grid, the selected box's
|
||||
## place and size) or a Play hint on the left; the next undo step on the right.
|
||||
func _make_status_strip() -> PanelContainer:
|
||||
var strip := PanelContainer.new()
|
||||
strip.add_theme_stylebox_override("panel", Style.box(Style.BG_DEEP.darkened(0.25), 0, [16, 6, 16, 6]))
|
||||
var row := HBoxContainer.new()
|
||||
strip.add_child(row)
|
||||
status_label = Style.make_label("", Style.body(), 13, Style.ON_BG_MUTED)
|
||||
status_label.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
status_label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
||||
row.add_child(status_label)
|
||||
undo_label = Style.make_label("", Style.body(), 13, Style.ON_BG_MUTED)
|
||||
row.add_child(undo_label)
|
||||
return strip
|
||||
|
||||
|
||||
func update_status() -> void:
|
||||
if doc == null:
|
||||
return
|
||||
if building():
|
||||
var text := "Snap to %d px grid · hold Alt to place freely" % int(SheetKinds.GRID)
|
||||
var box := doc.find_box(selected) if selected != "" else null
|
||||
if box:
|
||||
text += " · %s: X %d Y %d · W %d H %d" % [box.title if box.title != "" else "Box", box.x, box.y, box.w, box.h]
|
||||
status_label.text = text
|
||||
else:
|
||||
status_label.text = "Play mode · type in the boxes to change values"
|
||||
undo_label.text = "Undo: %s" % history.undo_label() if history.can_undo() else ""
|
||||
|
||||
|
||||
func open(p_doc: SheetDoc) -> void:
|
||||
doc = p_doc
|
||||
history.clear()
|
||||
_merge_key = ""
|
||||
tab_id = str(doc.tabs[0]["id"])
|
||||
selected = ""
|
||||
var empty := doc.tabs.all(func(t: Dictionary) -> bool: return (t["boxes"] as Array).is_empty())
|
||||
set_mode(Main.Mode.BUILD if empty else Main.Mode.PLAY)
|
||||
|
||||
|
||||
func close() -> void:
|
||||
save_now()
|
||||
doc = null
|
||||
|
||||
|
||||
func save_now() -> void:
|
||||
if doc and _dirty:
|
||||
screen.store.save(doc)
|
||||
_dirty = false
|
||||
|
||||
|
||||
func mark_dirty() -> void:
|
||||
_dirty = true
|
||||
_save_timer.start()
|
||||
|
||||
|
||||
func current_tab() -> Dictionary:
|
||||
var tab := doc.get_tab(tab_id)
|
||||
return tab if not tab.is_empty() else doc.tabs[0]
|
||||
|
||||
|
||||
func building() -> bool:
|
||||
return mode == Main.Mode.BUILD
|
||||
|
||||
|
||||
func set_mode(new_mode: Main.Mode) -> void:
|
||||
mode = new_mode
|
||||
if not building():
|
||||
selected = ""
|
||||
refresh()
|
||||
|
||||
|
||||
func set_palette_shown(on: bool) -> void:
|
||||
palette_dock.visible = on
|
||||
top_bar.sync()
|
||||
|
||||
|
||||
func show_tab(id: String) -> void:
|
||||
tab_id = id
|
||||
selected = ""
|
||||
refresh()
|
||||
|
||||
|
||||
func select(box_id: String) -> void:
|
||||
selected = box_id
|
||||
canvas.paint_selection()
|
||||
inspector.rebuild()
|
||||
update_status()
|
||||
|
||||
|
||||
## Rebuilds everything from the sheet (after undo, a mode switch, a new tab…).
|
||||
func refresh() -> void:
|
||||
if doc == null:
|
||||
return
|
||||
if doc.get_tab(tab_id).is_empty():
|
||||
tab_id = str(doc.tabs[0]["id"])
|
||||
if selected != "" and doc.find_box(selected) == null:
|
||||
selected = ""
|
||||
top_bar.sync()
|
||||
tabs_bar.rebuild()
|
||||
canvas.rebuild()
|
||||
inspector.visible = building()
|
||||
inspector.rebuild()
|
||||
update_status()
|
||||
|
||||
|
||||
## A change that can be undone: records the sheet, runs `change`, saves soon
|
||||
## and redraws. A `merge_key` joins quick repeats (typing) into one step.
|
||||
func edit(label: String, change: Callable, merge_key: String = "", redraw: bool = true) -> void:
|
||||
var now := Time.get_ticks_msec() / 1000.0
|
||||
var merge := merge_key != "" and merge_key == _merge_key and now - _merge_at < MERGE_SECS
|
||||
if not merge:
|
||||
history.record(doc.to_dict(), label)
|
||||
_merge_key = merge_key
|
||||
_merge_at = now
|
||||
change.call()
|
||||
mark_dirty()
|
||||
if redraw:
|
||||
refresh()
|
||||
else:
|
||||
top_bar.sync()
|
||||
update_status()
|
||||
|
||||
|
||||
## A player's value change from inside a box (no redraw, so typing keeps focus).
|
||||
func edit_value(box: SheetBox, value: Variant) -> void:
|
||||
edit("Change %s" % (box.title if box.title != "" else "a value"), func() -> void: box.value = value, "value:" + box.id, false)
|
||||
|
||||
|
||||
## Records `before` (taken at the start of a drag) when the drag changed something.
|
||||
func record_from(before: Dictionary, label: String) -> void:
|
||||
if before != doc.to_dict():
|
||||
history.record(before, label)
|
||||
_merge_key = ""
|
||||
mark_dirty()
|
||||
top_bar.sync()
|
||||
update_status()
|
||||
|
||||
|
||||
func undo() -> void:
|
||||
_step(history.undo(doc.to_dict()), "Undid")
|
||||
|
||||
|
||||
func redo() -> void:
|
||||
_step(history.redo(doc.to_dict()), "Redid")
|
||||
|
||||
|
||||
func _step(state: Dictionary, verb: String) -> void:
|
||||
if state.is_empty():
|
||||
return
|
||||
var label := history.redo_label() if verb == "Undid" else history.undo_label()
|
||||
var id := doc.id
|
||||
doc = SheetDoc.from_dict(state)
|
||||
doc.id = id
|
||||
_merge_key = ""
|
||||
mark_dirty()
|
||||
refresh()
|
||||
m.toast("%s: %s" % [verb, label])
|
||||
|
||||
|
||||
## Adds a box of `kind` with its top-left at `at` on the open tab (INF = the
|
||||
## middle of the visible canvas) and selects it.
|
||||
func add_box(kind: String, at: Vector2 = Vector2.INF) -> SheetBox:
|
||||
var spot := canvas.visible_center() - Vector2(96, 48) if at == Vector2.INF else at
|
||||
var box := SheetKinds.make_box(kind, doc.new_box_id(), spot.max(Vector2.ZERO))
|
||||
edit("Add %s" % SheetKinds.find(kind).get("label", "box"), func() -> void: current_tab()["boxes"].append(box))
|
||||
select(box.id)
|
||||
return box
|
||||
|
||||
|
||||
func delete_selected() -> void:
|
||||
if selected == "":
|
||||
return
|
||||
var id := selected
|
||||
selected = ""
|
||||
edit("Delete box", func() -> void: doc.remove_box(id))
|
||||
|
||||
|
||||
## Keys while the Sheets screen shows. True when the key was used.
|
||||
func shortcut(k: InputEventKey) -> bool:
|
||||
if doc == null or not visible:
|
||||
return false
|
||||
var ctrl := k.ctrl_pressed or k.meta_pressed
|
||||
if ctrl and k.keycode == KEY_Z:
|
||||
redo() if k.shift_pressed else undo()
|
||||
return true
|
||||
if ctrl and k.keycode == KEY_Y:
|
||||
redo()
|
||||
return true
|
||||
var f := m.get_viewport().gui_get_focus_owner()
|
||||
if f is LineEdit or f is TextEdit:
|
||||
return false
|
||||
if building() and k.keycode == KEY_DELETE and not k.echo:
|
||||
delete_selected()
|
||||
return true
|
||||
if k.keycode == KEY_ESCAPE and selected != "":
|
||||
select("")
|
||||
return true
|
||||
return false
|
||||
1
ui/sheet_editor.gd.uid
Normal file
1
ui/sheet_editor.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c5muh3lh84ra2
|
||||
139
ui/sheet_field_views.gd
Normal file
139
ui/sheet_field_views.gd
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
class_name SheetFieldViews
|
||||
extends RefCounted
|
||||
## The inside of a sheet box, by kind (SheetKinds): what the player sees and
|
||||
## changes in Play. Changes go through SheetEditor.edit_value. More kinds come
|
||||
## with phase C (docs/SHEETS.md).
|
||||
|
||||
|
||||
static func make(ed: SheetEditor, box: SheetBox, ink: Color) -> Control:
|
||||
match box.kind:
|
||||
SheetKinds.HEADING:
|
||||
return _heading(box, ink)
|
||||
SheetKinds.NUMBER:
|
||||
return _number(ed, box, ink)
|
||||
_:
|
||||
return _text(ed, box, ink)
|
||||
|
||||
|
||||
static func _heading(box: SheetBox, ink: Color) -> Control:
|
||||
var l := Style.make_label(box.title, Style.display(), 30, ink)
|
||||
l.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
l.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
||||
return l
|
||||
|
||||
|
||||
## A number with − and + beside it; type to set it.
|
||||
static func _number(ed: SheetEditor, box: SheetBox, ink: Color) -> Control:
|
||||
var row := HBoxContainer.new()
|
||||
row.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
row.add_theme_constant_override("separation", 4)
|
||||
var value := LineEdit.new()
|
||||
value.name = "Value"
|
||||
value.text = _num_text(box.value)
|
||||
value.alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
value.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
value.custom_minimum_size.x = 24
|
||||
value.add_theme_constant_override("minimum_character_width", 1)
|
||||
value.flat = true
|
||||
value.add_theme_font_override("font", Style.display())
|
||||
value.add_theme_font_size_override("font_size", 26)
|
||||
value.add_theme_color_override("font_color", ink)
|
||||
var commit := func(text: String) -> void:
|
||||
var n: Variant = _parse(text, box.value)
|
||||
value.text = _num_text(n)
|
||||
if n != _as_number(box.value):
|
||||
ed.edit_value(box, n)
|
||||
value.text_submitted.connect(commit)
|
||||
value.focus_exited.connect(func() -> void: commit.call(value.text))
|
||||
for step: int in [-1, 1]:
|
||||
var b := _step_button("−" if step < 0 else "+", ink)
|
||||
b.name = "Minus" if step < 0 else "Plus"
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.pressed.connect(func() -> void:
|
||||
var n: Variant = _as_number(box.value) + step
|
||||
value.text = _num_text(n)
|
||||
ed.edit_value(box, n))
|
||||
row.add_child(b)
|
||||
if step < 0:
|
||||
row.add_child(value)
|
||||
return row
|
||||
|
||||
|
||||
## A small − or + 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", 16)
|
||||
var normal := Style.bordered(Style.box(Color(ink, 0.04), 6, [4, 0, 4, 0]), 1, Color(ink, 0.35))
|
||||
var hover := Style.bordered(Style.box(Color(ink, 0.12), 6, [4, 0, 4, 0]), 1, Color(ink, 0.6))
|
||||
Style.skin_button(b, normal, hover, hover, ink, ink, ink)
|
||||
return b
|
||||
|
||||
|
||||
## Shows the formatted text; click (Play) to edit it as BBCode, click away to see it again.
|
||||
static func _text(ed: SheetEditor, box: SheetBox, ink: Color) -> Control:
|
||||
var stack := Control.new()
|
||||
var shown := RichTextLabel.new()
|
||||
shown.bbcode_enabled = true
|
||||
shown.fit_content = false
|
||||
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
|
||||
|
||||
|
||||
## Live values: {@name} shows the value of the box used in tables as @name.
|
||||
static func _expand(ed: SheetEditor, text: String) -> String:
|
||||
if not text.contains("{@"):
|
||||
return text
|
||||
for tab in ed.doc.tabs:
|
||||
for other: SheetBox in tab["boxes"]:
|
||||
if other.var_name != "":
|
||||
text = text.replace("{@%s}" % other.var_name, _num_text(other.value) if other.kind == SheetKinds.NUMBER else str(other.value))
|
||||
return text
|
||||
|
||||
|
||||
static func _as_number(v: Variant) -> float:
|
||||
return float(v) if v is int or v is float or (v is String and (v as String).is_valid_float()) else 0.0
|
||||
|
||||
|
||||
static func _parse(text: String, fallback: Variant) -> Variant:
|
||||
var t := text.strip_edges()
|
||||
if t.is_valid_int():
|
||||
return t.to_int()
|
||||
if t.is_valid_float():
|
||||
return t.to_float()
|
||||
return _as_number(fallback)
|
||||
|
||||
|
||||
static func _num_text(v: Variant) -> String:
|
||||
var n := _as_number(v)
|
||||
return str(int(n)) if n == floorf(n) else str(n)
|
||||
1
ui/sheet_field_views.gd.uid
Normal file
1
ui/sheet_field_views.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dtk8rvcaiew3m
|
||||
207
ui/sheet_inspector.gd
Normal file
207
ui/sheet_inspector.gd
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
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,
|
||||
## 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.
|
||||
|
||||
const WIDTH := 300.0
|
||||
const INSPECTOR := "inspector"
|
||||
const LORE := "lore"
|
||||
|
||||
var ed: SheetEditor
|
||||
var tab := INSPECTOR
|
||||
var _col: VBoxContainer
|
||||
|
||||
|
||||
func setup(p_editor: SheetEditor) -> void:
|
||||
ed = p_editor
|
||||
custom_minimum_size.x = WIDTH
|
||||
add_theme_stylebox_override("panel", Style.box(Style.CARD_SOFT, 0, [16, 14, 16, 14]))
|
||||
var scroll := ScrollContainer.new()
|
||||
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
add_child(scroll)
|
||||
_col = VBoxContainer.new()
|
||||
_col.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
_col.add_theme_constant_override("separation", 14)
|
||||
scroll.add_child(_col)
|
||||
|
||||
|
||||
func rebuild() -> void:
|
||||
for c in _col.get_children():
|
||||
_col.remove_child(c)
|
||||
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
|
||||
var box := ed.doc.find_box(ed.selected) if ed.selected != "" else null
|
||||
if box:
|
||||
_box_section(box)
|
||||
else:
|
||||
_sheet_section()
|
||||
|
||||
|
||||
func _head(kind: String, title: String, size: int = 22) -> void:
|
||||
var head := VBoxContainer.new()
|
||||
head.add_theme_constant_override("separation", 2)
|
||||
head.add_child(Style.make_label(kind.to_upper(), Style.caps(), 11, Style.TRIM))
|
||||
var t := Style.make_label(title, Style.display(), size, Style.INK)
|
||||
t.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
head.add_child(t)
|
||||
_col.add_child(head)
|
||||
|
||||
|
||||
## A bold label over its control(s), as one group.
|
||||
func _group(label: String, controls: Array) -> void:
|
||||
var g := VBoxContainer.new()
|
||||
g.add_theme_constant_override("separation", 6)
|
||||
g.add_child(Style.make_label(label, Style.body_bold(), 14, Style.INK))
|
||||
for c: Control in controls:
|
||||
g.add_child(c)
|
||||
_col.add_child(g)
|
||||
|
||||
|
||||
func _box_section(box: SheetBox) -> void:
|
||||
_head("Box · %s" % SheetKinds.find(box.kind).get("label", box.kind), box.title if box.title != "" else "Untitled")
|
||||
_group("Title", [_line("Title", box.title, func(text: String) -> void:
|
||||
ed.edit("Rename box", func() -> void: box.title = text, "title:" + box.id, false)
|
||||
ed.canvas.rebuild())])
|
||||
var frameless := _check("Frameless (no card, sits on the cloth)", box.frameless, func(on: bool) -> void:
|
||||
ed.edit("Box frame", func() -> void: box.frameless = on))
|
||||
frameless.name = "Frameless"
|
||||
_group("Colour", [ColorChoice.new(box.color, func(hex: String) -> void:
|
||||
ed.edit("Box colour", func() -> void: box.color = hex)), frameless])
|
||||
var order := SpinBox.new()
|
||||
order.name = "PhoneOrder"
|
||||
order.min_value = 0
|
||||
order.max_value = 999
|
||||
order.value = box.phone_order
|
||||
order.custom_minimum_size.x = 80
|
||||
order.value_changed.connect(func(v: float) -> void: ed.edit("Phone order", func() -> void: box.phone_order = int(v), "order:" + box.id, false))
|
||||
var order_row := HBoxContainer.new()
|
||||
order_row.add_theme_constant_override("separation", 8)
|
||||
order_row.add_child(order)
|
||||
order_row.add_child(_note("0 = auto: top to bottom, then left to right"))
|
||||
_group("Phone order", [order_row])
|
||||
if box.kind == SheetKinds.HEADING:
|
||||
_delete_button()
|
||||
return
|
||||
_col.add_child(_divider())
|
||||
var tables := _switch("Use in tables", "Tables can read and write it", box.var_name != "", func(on: bool) -> void:
|
||||
ed.edit("Use in tables", func() -> void: box.var_name = _var_from(box.title) if on else ""))
|
||||
tables.name = "UseInTables"
|
||||
_col.add_child(tables)
|
||||
if box.var_name != "":
|
||||
_col.add_child(_var_row(box))
|
||||
var lock := _switch("Lock against rolls", "A table roll can't change it", box.locked, func(on: bool) -> void:
|
||||
ed.edit("Lock box", func() -> void: box.locked = on))
|
||||
lock.name = "Lock"
|
||||
_col.add_child(lock)
|
||||
_delete_button()
|
||||
|
||||
|
||||
func _delete_button() -> void:
|
||||
var delete := ModalCard.make_button("Delete box", "danger")
|
||||
delete.pressed.connect(ed.delete_selected)
|
||||
_col.add_child(delete)
|
||||
|
||||
|
||||
## "Name in tables @[str]" in the reference colours.
|
||||
func _var_row(box: SheetBox) -> HBoxContainer:
|
||||
var row := HBoxContainer.new()
|
||||
row.add_theme_constant_override("separation", 6)
|
||||
row.add_child(Style.make_label("Name in tables", Style.body(), 13, Style.MUTED))
|
||||
var chip := PanelContainer.new()
|
||||
chip.add_theme_stylebox_override("panel", Style.bordered(Style.box(Style.REF_BG, 6, [6, 0, 2, 0]), 1, Style.REF_INK.lightened(0.4)))
|
||||
var inner := HBoxContainer.new()
|
||||
inner.add_theme_constant_override("separation", 0)
|
||||
chip.add_child(inner)
|
||||
inner.add_child(Style.make_label("@", Style.body_bold(), 14, Style.REF_INK))
|
||||
var name_edit := LineEdit.new()
|
||||
name_edit.name = "VarName"
|
||||
name_edit.text = box.var_name
|
||||
name_edit.flat = true
|
||||
name_edit.custom_minimum_size.x = 90
|
||||
name_edit.add_theme_color_override("font_color", Style.REF_INK)
|
||||
name_edit.add_theme_font_override("font", Style.body_bold())
|
||||
name_edit.text_changed.connect(func(text: String) -> void:
|
||||
ed.edit("Variable name", func() -> void: box.var_name = _var_from(text), "var:" + box.id, false))
|
||||
inner.add_child(name_edit)
|
||||
row.add_child(chip)
|
||||
return row
|
||||
|
||||
|
||||
static func _var_from(text: String) -> String:
|
||||
var name := LibraryStore.slugify(text).replace("-", "_")
|
||||
return name if name != "" else "value"
|
||||
|
||||
|
||||
func _sheet_section() -> void:
|
||||
_head("Sheet", ed.doc.name)
|
||||
_col.add_child(_note("Nothing selected. Click a box to edit it, or add one from the field palette."))
|
||||
_group("Name", [_line("Sheet name", ed.doc.name, func(text: String) -> void:
|
||||
ed.edit("Rename sheet", func() -> void: ed.doc.name = text, "sheetname", false))])
|
||||
_group("Sheet tint", [_note("Tell sheets apart at a glance, e.g. vehicles vs characters."),
|
||||
ColorChoice.new(ed.doc.tint, func(hex: String) -> void: ed.edit("Sheet tint", func() -> void: ed.doc.tint = hex))])
|
||||
_group("Snap grid", [_note("%d px. Hold Alt while dragging to place a box freely." % int(SheetKinds.GRID))])
|
||||
var tpl := ModalCard.make_button("Save as template…", "plain")
|
||||
tpl.pressed.connect(ed.top_bar.save_as_template)
|
||||
_col.add_child(tpl)
|
||||
|
||||
|
||||
## A bold label with a muted line under it and a checkbox at the right.
|
||||
func _switch(title: String, sub: String, on: bool, on_toggle: Callable) -> HBoxContainer:
|
||||
var row := HBoxContainer.new()
|
||||
row.add_theme_constant_override("separation", 8)
|
||||
var text := VBoxContainer.new()
|
||||
text.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
text.add_theme_constant_override("separation", 0)
|
||||
text.add_child(Style.make_label(title, Style.body_bold(), 14, Style.INK))
|
||||
text.add_child(Style.make_label(sub, Style.body(), 13, Style.MUTED))
|
||||
row.add_child(text)
|
||||
var check := CheckBox.new()
|
||||
check.name = "Check"
|
||||
check.button_pressed = on
|
||||
check.toggled.connect(on_toggle)
|
||||
row.add_child(check)
|
||||
return row
|
||||
|
||||
|
||||
func _check(text: String, on: bool, on_toggle: Callable) -> CheckBox:
|
||||
var c := CheckBox.new()
|
||||
c.text = text
|
||||
c.button_pressed = on
|
||||
c.add_theme_color_override("font_color", Style.INK)
|
||||
c.add_theme_color_override("font_hover_color", Style.INK)
|
||||
c.add_theme_color_override("font_pressed_color", Style.INK)
|
||||
c.toggled.connect(on_toggle)
|
||||
return c
|
||||
|
||||
|
||||
func _note(text: String) -> Label:
|
||||
var l := Style.make_label(text, Style.body(), 13, Style.MUTED)
|
||||
l.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
l.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
return l
|
||||
|
||||
|
||||
func _divider() -> ColorRect:
|
||||
var line := ColorRect.new()
|
||||
line.color = Style.RULE
|
||||
line.custom_minimum_size.y = 1
|
||||
return line
|
||||
|
||||
|
||||
func _line(placeholder: String, text: String, on_change: Callable) -> LineEdit:
|
||||
var e := LineEdit.new()
|
||||
e.placeholder_text = placeholder
|
||||
e.text = text
|
||||
ModalCard.style_line_edit(e)
|
||||
e.text_changed.connect(on_change)
|
||||
return e
|
||||
1
ui/sheet_inspector.gd.uid
Normal file
1
ui/sheet_inspector.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://6saiytkidbd1
|
||||
113
ui/sheet_tabs_bar.gd
Normal file
113
ui/sheet_tabs_bar.gd
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
class_name SheetTabsBar
|
||||
extends PanelContainer
|
||||
## The sheet's own tabs (Main, Spells, Notes…) as folder tabs above the canvas:
|
||||
## the open one is a card-coloured tab, the others are quiet. In Build,
|
||||
## "+ Tab" adds one and right-clicking a tab renames, moves or deletes it.
|
||||
|
||||
var ed: SheetEditor
|
||||
var _row: HBoxContainer
|
||||
|
||||
|
||||
func setup(p_editor: SheetEditor) -> void:
|
||||
ed = p_editor
|
||||
add_theme_stylebox_override("panel", Style.box(Style.BG_DEEP, 0, [16, 8, 16, 0]))
|
||||
_row = HBoxContainer.new()
|
||||
_row.add_theme_constant_override("separation", 4)
|
||||
add_child(_row)
|
||||
|
||||
|
||||
func rebuild() -> void:
|
||||
for c in _row.get_children():
|
||||
_row.remove_child(c)
|
||||
c.queue_free()
|
||||
for tab in ed.doc.tabs:
|
||||
_row.add_child(_tab_button(str(tab["id"]), str(tab["name"]), str(tab["id"]) == ed.tab_id))
|
||||
if ed.building():
|
||||
var add := Button.new()
|
||||
add.text = "+ Tab"
|
||||
add.name = "AddTab"
|
||||
add.focus_mode = Control.FOCUS_NONE
|
||||
add.tooltip_text = "A new tab: its own canvas (right-click a tab to rename, move or delete it)"
|
||||
var normal := Style.bordered(_top_box(Color(0, 0, 0, 0), [14, 8, 14, 8]), 1, Color(1, 1, 1, 0.25))
|
||||
normal.border_width_bottom = 0
|
||||
var hover := Style.bordered(_top_box(Color(1, 1, 1, 0.06), [14, 8, 14, 8]), 1, Color(1, 1, 1, 0.35))
|
||||
hover.border_width_bottom = 0
|
||||
Style.skin_button(add, normal, hover, hover, Style.ON_BG_MUTED, Style.ON_BG)
|
||||
add.pressed.connect(add_tab)
|
||||
_row.add_child(add)
|
||||
|
||||
|
||||
func _tab_button(id: String, text: String, open: bool) -> Button:
|
||||
var b := Button.new()
|
||||
b.name = id
|
||||
b.text = text
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.add_theme_font_override("font", Style.body_bold())
|
||||
b.add_theme_font_size_override("font_size", 14)
|
||||
var bg := Style.CARD if open else Color(0, 0, 0, 0)
|
||||
var hover := Style.CARD if open else Color(1, 1, 1, 0.06)
|
||||
Style.skin_button(b, _top_box(bg, [18, 8, 18, 8]), _top_box(hover, [18, 8, 18, 8]), _top_box(hover, [18, 8, 18, 8]),
|
||||
Style.INK if open else Style.ON_BG_MUTED, Style.INK if open else Style.ON_BG)
|
||||
b.pressed.connect(ed.show_tab.bind(id))
|
||||
b.gui_input.connect(func(ev: InputEvent) -> void: _tab_input(ev, id))
|
||||
return b
|
||||
|
||||
|
||||
## A box rounded only at the top, like a folder tab.
|
||||
static func _top_box(color: Color, margins: Array) -> StyleBoxFlat:
|
||||
var sb := Style.box(color, 8, margins)
|
||||
sb.corner_radius_bottom_left = 0
|
||||
sb.corner_radius_bottom_right = 0
|
||||
return sb
|
||||
|
||||
|
||||
func _tab_input(ev: InputEvent, id: String) -> void:
|
||||
var mb := ev as InputEventMouseButton
|
||||
if mb and mb.pressed and mb.button_index == MOUSE_BUTTON_RIGHT and ed.building():
|
||||
Actions.popup_at(ed.m, menu_for(id), mb.global_position)
|
||||
|
||||
|
||||
func menu_for(id: String) -> Array:
|
||||
var i := ed.doc.tabs.find(ed.doc.get_tab(id))
|
||||
var last := ed.doc.tabs.size() - 1
|
||||
return [
|
||||
{"text": "Rename tab…", "do": rename_tab.bind(id)},
|
||||
{"text": "Move left", "do": move_tab.bind(id, -1), "disabled": i <= 0},
|
||||
{"text": "Move right", "do": move_tab.bind(id, 1), "disabled": i >= last},
|
||||
{"text": "Delete tab", "do": delete_tab.bind(id), "disabled": last == 0, "tip": "A sheet keeps at least one tab"},
|
||||
]
|
||||
|
||||
|
||||
func add_tab() -> void:
|
||||
var name := "Tab %d" % (ed.doc.tabs.size() + 1)
|
||||
var made: Array = []
|
||||
ed.edit("Add tab", func() -> void: made.append(ed.doc.add_tab(name)), "", false)
|
||||
ed.show_tab(str(made[0]["id"]))
|
||||
|
||||
|
||||
func rename_tab(id: String) -> void:
|
||||
var tab := ed.doc.get_tab(id)
|
||||
ed.m._add_modal(ModalCard.ask_text("Rename tab", "Name", str(tab["name"]), "Rename", func(text: String) -> void:
|
||||
ed.edit("Rename tab", func() -> void: ed.doc.get_tab(id)["name"] = text.strip_edges())))
|
||||
|
||||
|
||||
func move_tab(id: String, step: int) -> void:
|
||||
ed.edit("Move tab", func() -> void:
|
||||
var tab := ed.doc.get_tab(id)
|
||||
var i := ed.doc.tabs.find(tab)
|
||||
ed.doc.tabs.remove_at(i)
|
||||
ed.doc.tabs.insert(clampi(i + step, 0, ed.doc.tabs.size()), tab))
|
||||
|
||||
|
||||
func delete_tab(id: String) -> void:
|
||||
if ed.doc.tabs.size() <= 1:
|
||||
return
|
||||
var tab := ed.doc.get_tab(id)
|
||||
var count := (tab["boxes"] as Array).size()
|
||||
var go := func() -> void:
|
||||
ed.edit("Delete tab", func() -> void: ed.doc.tabs.erase(ed.doc.get_tab(id)))
|
||||
ed.m.toast("Deleted tab “%s” (Undo brings it back)" % tab["name"])
|
||||
if count == 0:
|
||||
go.call()
|
||||
else:
|
||||
ed.m._add_modal(ModalCard.confirm("Delete tab?", "Delete “%s” and its %d %s? Undo brings it back." % [tab["name"], count, "box" if count == 1 else "boxes"], "Delete", go, true))
|
||||
1
ui/sheet_tabs_bar.gd.uid
Normal file
1
ui/sheet_tabs_bar.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c80w1c0lq4sp6
|
||||
140
ui/sheet_top_bar.gd
Normal file
140
ui/sheet_top_bar.gd
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
class_name SheetTopBar
|
||||
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.
|
||||
|
||||
const HINTS := {
|
||||
Main.Mode.PLAY: "Type in the boxes to change values.",
|
||||
Main.Mode.BUILD: "Drag a box to move it, its corner to resize it.",
|
||||
}
|
||||
|
||||
var ed: SheetEditor
|
||||
var play_button: Button
|
||||
var build_button: Button
|
||||
var name_button: MenuButton
|
||||
var palette_button: Button
|
||||
var undo_button: Button
|
||||
var redo_button: Button
|
||||
var _hint: Label
|
||||
var _tools: HBoxContainer
|
||||
|
||||
|
||||
func setup(p_editor: SheetEditor) -> void:
|
||||
ed = p_editor
|
||||
add_theme_stylebox_override("panel", Style.panel_box([16, 10, 16, 10]))
|
||||
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 seg := PanelContainer.new()
|
||||
seg.add_theme_stylebox_override("panel", Style.box(Color(0, 0, 0, 0.28), 9, [3, 3, 3, 3]))
|
||||
seg.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
var seg_row := HBoxContainer.new()
|
||||
seg_row.add_theme_constant_override("separation", 0)
|
||||
seg.add_child(seg_row)
|
||||
var group := ButtonGroup.new()
|
||||
play_button = MainTopBar.seg_button("Play", group)
|
||||
build_button = MainTopBar.seg_button("Build", group)
|
||||
play_button.pressed.connect(func() -> void: ed.set_mode(Main.Mode.PLAY))
|
||||
build_button.pressed.connect(func() -> void: ed.set_mode(Main.Mode.BUILD))
|
||||
seg_row.add_child(play_button)
|
||||
seg_row.add_child(build_button)
|
||||
h.add_child(seg)
|
||||
var name_box := VBoxContainer.new()
|
||||
name_box.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
name_box.add_theme_constant_override("separation", 0)
|
||||
var caption := Style.make_label("SHEET", Style.caps(), 10, Style.ON_BG_MUTED)
|
||||
caption.tooltip_text = "A sheet keeps track of one thing: a character, a vehicle… Click its name to switch sheets."
|
||||
caption.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
name_box.add_child(caption)
|
||||
name_button = Style.menu_button("", false)
|
||||
name_button.tooltip_text = "Switch sheets, see all sheets, or rename this one"
|
||||
name_button.get_popup().about_to_popup.connect(_fill_name_menu)
|
||||
name_box.add_child(name_button)
|
||||
h.add_child(name_box)
|
||||
_hint = Style.make_label("", Style.body(), 14, Style.ON_BG_MUTED)
|
||||
_hint.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
_hint.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
_hint.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
||||
_hint.custom_minimum_size = Vector2(60, 0)
|
||||
h.add_child(_hint)
|
||||
_tools = HBoxContainer.new()
|
||||
_tools.add_theme_constant_override("separation", 6)
|
||||
h.add_child(_tools)
|
||||
palette_button = Style.bar_button("Field palette")
|
||||
palette_button.toggle_mode = true
|
||||
palette_button.focus_mode = Control.FOCUS_NONE
|
||||
palette_button.tooltip_text = "Show or hide the field palette"
|
||||
palette_button.pressed.connect(func() -> void: ed.set_palette_shown(not ed.palette_dock.visible))
|
||||
_tools.add_child(palette_button)
|
||||
undo_button = Style.bar_button("↶ Undo")
|
||||
undo_button.pressed.connect(ed.undo)
|
||||
_tools.add_child(undo_button)
|
||||
redo_button = Style.bar_button("↷ Redo")
|
||||
redo_button.pressed.connect(ed.redo)
|
||||
_tools.add_child(redo_button)
|
||||
var template := Style.bar_button("Save as template…")
|
||||
template.pressed.connect(save_as_template)
|
||||
_tools.add_child(template)
|
||||
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()))
|
||||
h.add_child(actions)
|
||||
|
||||
|
||||
func _actions() -> Array:
|
||||
return [
|
||||
{"text": "Main menu", "do": ed.m.screens.show.bind(MainScreens.MENU)},
|
||||
{"text": "All sheets", "do": ed.screen.show_list},
|
||||
{"sep": ""},
|
||||
{"text": "Rename sheet…", "do": rename},
|
||||
{"text": "Save as template…", "do": save_as_template},
|
||||
{"sep": ""},
|
||||
{"text": "Theme…", "do": func() -> void: ed.m.add_child(ThemeDialog.new(ed.m))},
|
||||
]
|
||||
|
||||
|
||||
## The name button's menu: your other sheets, All sheets, Rename.
|
||||
func _fill_name_menu() -> void:
|
||||
var list: Array = []
|
||||
for row: Dictionary in ed.screen.store.list():
|
||||
if str(row["id"]) != ed.doc.id:
|
||||
list.append({"text": str(row["name"]), "do": ed.screen.open_sheet.bind(str(row["id"]))})
|
||||
if not list.is_empty():
|
||||
list.append({"sep": ""})
|
||||
list.append({"text": "All sheets…", "do": ed.screen.show_list})
|
||||
list.append({"text": "Rename…", "do": rename})
|
||||
Actions.fill(name_button.get_popup(), list)
|
||||
|
||||
|
||||
func rename() -> void:
|
||||
ed.m._add_modal(ModalCard.ask_text("Rename sheet", "Name", ed.doc.name, "Rename", func(text: String) -> void:
|
||||
ed.edit("Rename sheet", func() -> void: ed.doc.name = text.strip_edges())))
|
||||
|
||||
|
||||
func save_as_template() -> void:
|
||||
ed.m._add_modal(ModalCard.ask_text("Save as template", "Template name", ed.doc.name, "Save", func(text: String) -> void:
|
||||
ed.save_now()
|
||||
ed.screen.store.save_as_template(ed.doc, text.strip_edges())
|
||||
ed.m.toast("Saved template “%s”. Pick it under + New sheet." % text.strip_edges())))
|
||||
|
||||
|
||||
## Brings the bar in line with the editor: mode, name, undo state.
|
||||
func sync() -> void:
|
||||
if ed.doc == null:
|
||||
return
|
||||
var build := ed.building()
|
||||
play_button.set_pressed_no_signal(not build)
|
||||
build_button.set_pressed_no_signal(build)
|
||||
name_button.text = "%s ▾" % ed.doc.name
|
||||
_hint.text = HINTS[ed.mode]
|
||||
_tools.visible = build
|
||||
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()
|
||||
undo_button.modulate.a = 1.0 if ed.history.can_undo() else 0.45
|
||||
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"
|
||||
1
ui/sheet_top_bar.gd.uid
Normal file
1
ui/sheet_top_bar.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ca55t2xp3mj8o
|
||||
206
ui/sheets_screen.gd
Normal file
206
ui/sheets_screen.gd
Normal file
|
|
@ -0,0 +1,206 @@
|
|||
class_name SheetsScreen
|
||||
extends PanelContainer
|
||||
## The Sheets screen: your sheets and sheet templates as lists, "+ New sheet"
|
||||
## (NewSheetDialog), and the sheet editor (SheetEditor) once one is open.
|
||||
## Sheets live in user://sheets/ (SheetStore). When the app isn't saving
|
||||
## (--sample, tests) they go to a scratch folder that starts empty.
|
||||
|
||||
const SCRATCH := "user://scratch_sheets/"
|
||||
|
||||
var m: Main
|
||||
var store: SheetStore
|
||||
var editor: SheetEditor
|
||||
var list_page: VBoxContainer
|
||||
var _sheet_rows: VBoxContainer
|
||||
var _template_rows: VBoxContainer
|
||||
|
||||
|
||||
func setup(p_main: Main) -> void:
|
||||
m = p_main
|
||||
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
add_theme_stylebox_override("panel", Style.box(Style.BG_DEEP, 0, [0, 0, 0, 0]))
|
||||
if m._saving_enabled:
|
||||
store = SheetStore.new()
|
||||
else:
|
||||
_wipe_scratch()
|
||||
store = SheetStore.new(SCRATCH)
|
||||
var stack := Control.new()
|
||||
add_child(stack)
|
||||
list_page = _make_list_page()
|
||||
list_page.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
stack.add_child(list_page)
|
||||
editor = SheetEditor.new()
|
||||
editor.setup(m, self)
|
||||
editor.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
editor.visible = false
|
||||
stack.add_child(editor)
|
||||
|
||||
|
||||
func enter() -> void:
|
||||
if not editor.visible:
|
||||
refresh()
|
||||
|
||||
|
||||
func leave() -> void:
|
||||
editor.save_now()
|
||||
|
||||
|
||||
func _make_list_page() -> VBoxContainer:
|
||||
var page := VBoxContainer.new()
|
||||
page.add_theme_constant_override("separation", 0)
|
||||
var bar := PanelContainer.new()
|
||||
bar.add_theme_stylebox_override("panel", Style.panel_box([16, 10, 16, 10]))
|
||||
page.add_child(bar)
|
||||
var head := HBoxContainer.new()
|
||||
head.add_theme_constant_override("separation", 12)
|
||||
bar.add_child(head)
|
||||
head.add_child(MainTopBar.make_brand(func() -> void: m.screens.show(MainScreens.MENU)))
|
||||
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 add := Style.bar_button("+ New sheet", true)
|
||||
add.name = "NewSheet"
|
||||
add.pressed.connect(open_new_sheet)
|
||||
head.add_child(add)
|
||||
var back := Control.new()
|
||||
back.size_flags_vertical = SIZE_EXPAND_FILL
|
||||
var backdrop := BoardBackdrop.new(ThemeStore.current)
|
||||
back.draw.connect(func() -> void: backdrop.draw(back, Rect2(Vector2.ZERO, back.size)))
|
||||
back.resized.connect(back.queue_redraw)
|
||||
page.add_child(back)
|
||||
var scroll := ScrollContainer.new()
|
||||
scroll.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
back.add_child(scroll)
|
||||
var center := HBoxContainer.new()
|
||||
center.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
center.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
scroll.add_child(center)
|
||||
var col := VBoxContainer.new()
|
||||
col.custom_minimum_size.x = 900
|
||||
col.add_theme_constant_override("separation", 10)
|
||||
var margin := MarginContainer.new()
|
||||
for side in ["left", "right", "top", "bottom"]:
|
||||
margin.add_theme_constant_override("margin_" + side, 32)
|
||||
margin.add_child(col)
|
||||
center.add_child(margin)
|
||||
col.add_child(Style.make_label("Sheets", Style.display(), 40, Style.ON_BG))
|
||||
_sheet_rows = VBoxContainer.new()
|
||||
_sheet_rows.add_theme_constant_override("separation", 10)
|
||||
col.add_child(_sheet_rows)
|
||||
var gap := Control.new()
|
||||
gap.custom_minimum_size.y = 18
|
||||
col.add_child(gap)
|
||||
col.add_child(Style.make_label("Templates", Style.display(), 28, Style.ON_BG))
|
||||
_template_rows = VBoxContainer.new()
|
||||
_template_rows.add_theme_constant_override("separation", 10)
|
||||
col.add_child(_template_rows)
|
||||
return page
|
||||
|
||||
|
||||
## Rebuilds both lists from the files.
|
||||
func refresh() -> void:
|
||||
for rows: VBoxContainer in [_sheet_rows, _template_rows]:
|
||||
for c in rows.get_children():
|
||||
rows.remove_child(c)
|
||||
c.queue_free()
|
||||
var sheets := store.list()
|
||||
for row: Dictionary in sheets:
|
||||
var kind := _template_name(str(row["from_template"])) if str(row["from_template"]) != "" else "Blank"
|
||||
_sheet_rows.add_child(_row(str(row["name"]), kind, "Standalone", open_sheet.bind(str(row["id"])), _delete.bind(str(row["id"]), str(row["name"]), false)))
|
||||
if sheets.is_empty():
|
||||
_sheet_rows.add_child(_empty_note("No sheets yet. Press + New sheet to make one."))
|
||||
var templates := store.list(true)
|
||||
for row: Dictionary in templates:
|
||||
_template_rows.add_child(_row(str(row["name"]), "Template", "New sheet from it", open_new_sheet.bind(str(row["id"])), _delete.bind(str(row["id"]), str(row["name"]), true)))
|
||||
if templates.is_empty():
|
||||
_template_rows.add_child(_empty_note("No templates yet. In a sheet, press Save as template… in the top bar."))
|
||||
|
||||
|
||||
func _template_name(id: String) -> String:
|
||||
var doc := store.load_sheet(id, true)
|
||||
return doc.name if doc else id
|
||||
|
||||
|
||||
## A whole-row button: "Name · kind" on the left, `where` on the right, ⋯ to delete.
|
||||
func _row(title: String, kind: String, where: String, on_open: Callable, on_delete: Callable) -> Button:
|
||||
var b := Button.new()
|
||||
b.name = title.validate_node_name()
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.custom_minimum_size = Vector2(0, 50)
|
||||
Style.skin_button(b, Style.box(Style.CARD, 8, [14, 12, 14, 12]), Style.box(Style.CARD_HOVER, 8, [14, 12, 14, 12]),
|
||||
Style.box(Style.CARD_HOVER, 8, [14, 12, 14, 12]), Style.INK)
|
||||
b.pressed.connect(on_open)
|
||||
var h := HBoxContainer.new()
|
||||
h.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
h.offset_left = 14
|
||||
h.offset_right = -8
|
||||
h.add_theme_constant_override("separation", 6)
|
||||
h.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
b.add_child(h)
|
||||
var name_label := Style.make_label(title, Style.body_bold(), 15, Style.INK)
|
||||
name_label.size_flags_vertical = SIZE_SHRINK_CENTER
|
||||
h.add_child(name_label)
|
||||
var kind_label := Style.make_label("· " + kind, Style.body(), 15, Style.INK)
|
||||
kind_label.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
kind_label.size_flags_vertical = SIZE_SHRINK_CENTER
|
||||
h.add_child(kind_label)
|
||||
var where_label := Style.make_label(where, Style.body(), 14, Style.MUTED)
|
||||
where_label.size_flags_vertical = SIZE_SHRINK_CENTER
|
||||
h.add_child(where_label)
|
||||
var more := Style.overflow_button("More")
|
||||
more.name = "More"
|
||||
Actions.fill(more.get_popup(), [{"text": "Open" if where == "Standalone" else "New sheet from it", "do": on_open}, {"text": "Delete…", "do": on_delete}])
|
||||
h.add_child(more)
|
||||
return b
|
||||
|
||||
|
||||
func _empty_note(text: String) -> Label:
|
||||
var l := Style.make_label(text, Style.body(), 15, Style.ON_BG_MUTED)
|
||||
l.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
return l
|
||||
|
||||
|
||||
## "+ New sheet": asks for a name and a start (blank or a template).
|
||||
func open_new_sheet(template_id: String = "") -> void:
|
||||
m._add_modal(NewSheetDialog.new(store, template_id, func(name: String, tpl: String) -> void:
|
||||
var doc := store.create(name, tpl)
|
||||
open_doc(doc)))
|
||||
|
||||
|
||||
func open_sheet(id: String) -> void:
|
||||
var doc := store.load_sheet(id)
|
||||
if doc == null:
|
||||
m.toast("Couldn't read that sheet")
|
||||
refresh()
|
||||
return
|
||||
open_doc(doc)
|
||||
|
||||
|
||||
func open_doc(doc: SheetDoc) -> void:
|
||||
editor.open(doc)
|
||||
list_page.visible = false
|
||||
editor.visible = true
|
||||
|
||||
|
||||
## Closes the editor (saving) and shows the lists.
|
||||
func show_list() -> void:
|
||||
editor.close()
|
||||
editor.visible = false
|
||||
list_page.visible = true
|
||||
refresh()
|
||||
|
||||
|
||||
func _delete(id: String, name: String, templates: bool) -> void:
|
||||
var what := "template" if templates else "sheet"
|
||||
m._add_modal(ModalCard.confirm("Delete %s?" % what, "Delete the %s “%s”? This can't be undone." % [what, name], "Delete", func() -> void:
|
||||
store.delete(id, templates)
|
||||
refresh(), true))
|
||||
|
||||
|
||||
func _wipe_scratch() -> void:
|
||||
for templates: bool in [false, true]:
|
||||
var dir := SCRATCH.path_join(SheetStore.TEMPLATES if templates else SheetStore.SHEETS)
|
||||
if DirAccess.dir_exists_absolute(dir):
|
||||
for file in DirAccess.get_files_at(dir):
|
||||
DirAccess.remove_absolute(dir.path_join(file))
|
||||
1
ui/sheets_screen.gd.uid
Normal file
1
ui/sheets_screen.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cigdy8rpyqa0k
|
||||
|
|
@ -150,6 +150,8 @@ static func use(m: Main, t: Dictionary) -> void:
|
|||
m.state.save()
|
||||
m._save_now()
|
||||
carry_board = m.data
|
||||
if m.screens:
|
||||
m.screens.keep_for_reload()
|
||||
m.get_tree().reload_current_scene.call_deferred()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue