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() if which == SPREAD: m.sheet_links.refresh_previews() 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 ""}