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 signal characters_requested signal settings_requested var _panel: VBoxContainer var _hub_button: Button var _characters_button: Button var _disconnect_button: Button var _note: Label var _in_dungeon: bool = false var _open: bool = false func _ready() -> void: layer = 20 var root := UiTheme.themed_root() 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) _note = Label.new() _note.add_theme_font_size_override("font_size", 12) _note.add_theme_color_override("font_color", Color(1.0, 0.7, 0.5)) _note.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART _note.custom_minimum_size = Vector2(320.0, 0.0) _panel.add_child(_note) _hub_button = _button("Return to hub", func() -> void: return_to_hub_requested.emit() close()) _characters_button = _button("Change character", func() -> void: characters_requested.emit() close()) _button("Settings", func() -> void: settings_requested.emit() close()) _button("Resume", func() -> void: close()) _disconnect_button = _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: if in_dungeon == _in_dungeon and not _note.text.is_empty(): return _in_dungeon = in_dungeon _hub_button.disabled = not in_dungeon # Swapping is hub-only, and the server enforces that regardless of what # this button does -- but a disabled button explains the rule, where a # refusal after the fact just looks broken. _characters_button.disabled = in_dungeon _characters_button.text = "Change character (hub only)" if in_dungeon \ else "Change character" if in_dungeon: # Disconnecting is not an escape: the server keeps the body in the # world, channelling out, for the same second the escape button costs. # Saying so is the difference between a considered choice and a nasty # surprise -- the mechanic only reads as fair if players know about it. _note.text = "The world keeps running while this is open. " \ + "Disconnecting does not save you: your ship stays in the dungeon " \ + "for one second and can still be killed." _disconnect_button.text = "Disconnect to menu (ship stays 1s)" else: _note.text = "The world keeps running while this is open." _disconnect_button.text = "Disconnect to menu"