class_name Menu extends CanvasLayer ## The start screen: the player's name, then playing alone, opening the world ## for guests, or joining a host. signal play_chosen(open: bool) signal join_chosen(address: String) var name_field := LineEdit.new() var address_field := LineEdit.new() var solo_button := Button.new() var host_button := Button.new() var join_button := Button.new() var _status := Label.new() func _ready() -> void: var center := CenterContainer.new() center.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) add_child(center) var panel := PanelContainer.new() center.add_child(panel) var box := VBoxContainer.new() box.custom_minimum_size = Vector2(380, 0) box.add_theme_constant_override("separation", 10) panel.add_child(box) var title := Label.new() title.text = "Grovewright" title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER title.add_theme_font_size_override("font_size", 32) name_field.placeholder_text = tr("MENU_NAME") name_field.max_length = 32 solo_button.text = tr("MENU_SOLO") host_button.text = tr("MENU_HOST") var row := HBoxContainer.new() for button in [solo_button, host_button]: button.size_flags_horizontal = Control.SIZE_EXPAND_FILL row.add_child(button) address_field.placeholder_text = tr("MENU_ADDRESS") join_button.text = tr("MENU_JOIN") _status.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART _status.custom_minimum_size = Vector2(380, 0) for control: Control in [title, name_field, row, HSeparator.new(), address_field, join_button, _status]: box.add_child(control) solo_button.pressed.connect(func() -> void: play_chosen.emit(false)) host_button.pressed.connect(func() -> void: play_chosen.emit(true)) join_button.pressed.connect(func() -> void: join_chosen.emit(address_field.text.strip_edges())) address_field.text_submitted.connect(func(_text: String) -> void: join_button.pressed.emit()) ## Shows `text` below the buttons. func show_status(text: String) -> void: _status.text = text ## The text shown below the buttons. Tests read it. func status() -> String: return _status.text ## The name the player typed, without spaces around it. func player_name() -> String: return name_field.text.strip_edges()