extends CanvasLayer ## In-game system menu, opened with Escape. ## ## Exists because without it there is no way out of a session short of killing ## the process -- and "kill the process" is exactly the behaviour the escape ## channel is designed to discourage, so leaving it as the only exit would work ## against the rest of the design. signal resumed signal return_to_hub_requested signal disconnect_requested var _panel: VBoxContainer var _hub_button: Button var _open: bool = false func _ready() -> void: layer = 20 var root := Control.new() root.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) add_child(root) # Dim the game behind the menu so it is obvious the world is still running. var scrim := ColorRect.new() scrim.color = Color(0.0, 0.0, 0.0, 0.55) scrim.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) scrim.mouse_filter = Control.MOUSE_FILTER_STOP root.add_child(scrim) var center := CenterContainer.new() center.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) root.add_child(center) _panel = VBoxContainer.new() _panel.custom_minimum_size = Vector2(320.0, 0.0) _panel.add_theme_constant_override("separation", 10) center.add_child(_panel) var title := Label.new() title.text = "PAUSED" title.add_theme_font_size_override("font_size", 26) _panel.add_child(title) var note := Label.new() note.text = "The world keeps running. You are not safe here." note.add_theme_font_size_override("font_size", 12) note.add_theme_color_override("font_color", Color(1.0, 0.7, 0.5)) _panel.add_child(note) _hub_button = _button("Return to hub", func() -> void: return_to_hub_requested.emit() close()) _button("Resume", func() -> void: close()) _button("Disconnect to menu", func() -> void: disconnect_requested.emit() close()) _button("Quit game", func() -> void: get_tree().quit()) visible = false func _button(text: String, on_press: Callable) -> Button: var b := Button.new() b.text = text b.pressed.connect(on_press) _panel.add_child(b) return b func _unhandled_input(event: InputEvent) -> void: if event.is_action_pressed("system_menu"): toggle() get_viewport().set_input_as_handled() func toggle() -> void: if _open: close() else: open() func open() -> void: _open = true visible = true # Nothing is paused -- the server does not stop for one client's menu, so # neither does the view. Only the mouse is freed. Input.mouse_mode = Input.MOUSE_MODE_VISIBLE func close() -> void: _open = false visible = false func is_open() -> bool: return _open ## The hub button is meaningless when you are already in the hub. func set_in_dungeon(in_dungeon: bool) -> void: _hub_button.disabled = not in_dungeon