class_name SheetPhoneLayout extends RefCounted ## The sheet editor in the phone layout (MobileLayout). Play shows the ## stacked view (SheetStackView) by default; the bottom bar has Undo and a ## Stacked | Canvas switch (Play), or "+" for the field palette (Build, which ## always uses the canvas). The palette opens full screen; picking a field ## goes back to the canvas. The inspector (with a box selected), the Lore ## Index and the details panel open as bottom panels, not side docks. ## Height of a bottom panel (inspector, Lore Index, details). const PANEL_HEIGHT := 360.0 var ed: SheetEditor var stack: SheetStackView ## The player's choice in Play: the stacked view (true) or the real canvas. var stacked := true var palette_open := false var bar: PanelContainer var stacked_button: Button var canvas_button: Button var undo_button: Button var add_button: Button func _init(p_editor: SheetEditor) -> void: ed = p_editor func apply() -> void: var middle := ed.canvas.get_parent() stack = SheetStackView.new() stack.setup(ed) stack.size_flags_horizontal = Control.SIZE_EXPAND_FILL middle.add_child(stack) middle.move_child(stack, ed.canvas.get_index() + 1) ed.palette_dock.visible = false ed.palette_dock.size_flags_horizontal = Control.SIZE_EXPAND_FILL # The side docks become bottom panels under the canvas. for dock: Control in [ed.inspector, ed.lore_dock, ed.details]: middle.remove_child(dock) ed.add_child(dock) ed.move_child(dock, middle.get_index() + 1) dock.custom_minimum_size = Vector2(0, PANEL_HEIGHT) _style_bottom_sheet(ed.details) # The bottom bar takes the status strip's place. var strip := ed.status_label.get_parent().get_parent() as Control strip.visible = false bar = _make_bar() ed.add_child(bar) ed.move_child(bar, strip.get_index()) var top := ed.top_bar for control: Control in [top._hint, top.export_button, top.brand_title, top.lore_button]: control.visible = false # The sheet's name takes the room the hint had, cut short when long. top.name_button.clip_text = true top.name_button.get_parent().size_flags_horizontal = Control.SIZE_EXPAND_FILL func _make_bar() -> PanelContainer: var panel := PanelContainer.new() panel.name = "PhoneBar" panel.add_theme_stylebox_override("panel", Style.box(Style.BG_DEEP.darkened(0.25), 0, [12, 6, 12, 6])) var row := HBoxContainer.new() row.add_theme_constant_override("separation", 8) panel.add_child(row) undo_button = _bar_button("↶ Undo") undo_button.pressed.connect(ed.undo) row.add_child(undo_button) var gap := Control.new() gap.size_flags_horizontal = Control.SIZE_EXPAND_FILL row.add_child(gap) var group := ButtonGroup.new() stacked_button = MainTopBar.seg_button("Stacked", group) canvas_button = MainTopBar.seg_button("Canvas", group) stacked_button.name = "Stacked" canvas_button.name = "Canvas" for button: Button in [stacked_button, canvas_button]: button.custom_minimum_size.y = SheetFieldViews.TOUCH stacked_button.pressed.connect(show_stacked.bind(true)) canvas_button.pressed.connect(show_stacked.bind(false)) row.add_child(stacked_button) row.add_child(canvas_button) add_button = _bar_button("+ Field") add_button.tooltip_text = "Add a field" add_button.pressed.connect(show_palette.bind(true)) row.add_child(add_button) return panel func _bar_button(text: String) -> Button: var button := Style.bar_button(text) button.custom_minimum_size = Vector2(SheetFieldViews.TOUCH, SheetFieldViews.TOUCH) return button ## A panel from the bottom: rounded top corners and a line on top. static func _style_bottom_sheet(panel: PanelContainer) -> void: var sheet := Style.box(Style.CARD_SOFT, 14, [18, 14, 18, 14]) sheet.corner_radius_bottom_left = 0 sheet.corner_radius_bottom_right = 0 sheet.border_color = Style.DASH sheet.border_width_top = 1 panel.add_theme_stylebox_override("panel", sheet) ## Play: the stacked view (true) or the real canvas (pan by dragging). func show_stacked(on: bool) -> void: stacked = on ed.refresh() func show_palette(on: bool) -> void: palette_open = on and ed.building() sync() ## True when the stacked view shows in place of the canvas. func stack_shown() -> bool: return stacked and not ed.building() ## Brings the views and the bar in line with the mode (SheetEditor.refresh ## and select call it); rebuilds the stacked view when `redraw`. func sync(redraw: bool = false) -> void: if not ed.building(): palette_open = false var on := stack_shown() stack.visible = on and not palette_open ed.canvas.visible = not on and not palette_open ed.palette_dock.visible = palette_open if on and redraw: stack.rebuild() # A small screen: the inspector only while a box is selected. ed.inspector.visible = ed.building() and not ed.lore_shown and ed.selected != "" and not palette_open stacked_button.visible = not ed.building() canvas_button.visible = not ed.building() stacked_button.set_pressed_no_signal(stacked) canvas_button.set_pressed_no_signal(not stacked) add_button.visible = ed.building() and not palette_open sync_undo() func sync_undo() -> void: undo_button.disabled = not ed.history.can_undo() undo_button.modulate.a = 1.0 if ed.history.can_undo() else 0.45