extends CanvasLayer ## Startmenue: Einzelspieler, Hosten oder einer Sitzung beitreten. signal solo_chosen() signal continue_chosen() signal host_chosen(port: int) signal join_chosen(address: String, port: int) const DEFAULT_PORT := 7654 var _root: Control var _status := Label.new() var _addr := LineEdit.new() var _port := LineEdit.new() var _name := LineEdit.new() var _continue: Button func _ready() -> void: layer = 3 _root = Control.new() _root.set_anchors_preset(Control.PRESET_FULL_RECT) add_child(_root) var bg := ColorRect.new() bg.color = Color("14201c") bg.set_anchors_preset(Control.PRESET_FULL_RECT) _root.add_child(bg) var center := CenterContainer.new() center.set_anchors_preset(Control.PRESET_FULL_RECT) _root.add_child(center) var vb := VBoxContainer.new() vb.add_theme_constant_override("separation", 14) vb.custom_minimum_size = Vector2(420, 0) center.add_child(vb) var title := Label.new() title.text = "Cozy Train" title.add_theme_font_size_override("font_size", 52) title.add_theme_color_override("font_color", Color("ffd978")) title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER vb.add_child(title) var sub := Label.new() sub.text = "Eine Crew, ein Zug, viele Fahrgäste." sub.add_theme_font_size_override("font_size", 17) sub.add_theme_color_override("font_color", Color(1, 1, 1, 0.7)) sub.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER vb.add_child(sub) vb.add_child(_spacer(18)) _name.placeholder_text = "Dein Name" _name.text = "Crew" _name.max_length = 16 _name.alignment = HORIZONTAL_ALIGNMENT_CENTER vb.add_child(_name) _continue = _button("Weiterspielen", func(): continue_chosen.emit()) _continue.visible = FileAccess.file_exists("user://save.json") vb.add_child(_continue) vb.add_child(_button("Einzelspieler", func(): solo_chosen.emit())) vb.add_child(_button("Sitzung hosten", func(): host_chosen.emit(_port_value()))) var row := HBoxContainer.new() row.add_theme_constant_override("separation", 8) _addr.text = "127.0.0.1" _addr.placeholder_text = "Adresse" _addr.size_flags_horizontal = Control.SIZE_EXPAND_FILL row.add_child(_addr) _port.text = str(DEFAULT_PORT) _port.custom_minimum_size = Vector2(90, 0) row.add_child(_port) vb.add_child(row) vb.add_child(_button("Beitreten", func(): join_chosen.emit(_addr.text, _port_value()))) _status.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER _status.add_theme_font_size_override("font_size", 16) _status.add_theme_color_override("font_color", Color("ffb4a0")) vb.add_child(_status) var help := Label.new() help.text = "Maus: umsehen WASD: laufen E: benutzen V: Außenkamera Esc: Maus frei" help.add_theme_font_size_override("font_size", 14) help.add_theme_color_override("font_color", Color(1, 1, 1, 0.45)) help.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER vb.add_child(help) func _spacer(h: int) -> Control: var c := Control.new() c.custom_minimum_size = Vector2(0, h) return c func _button(text: String, cb: Callable) -> Button: var b := Button.new() b.text = text b.custom_minimum_size = Vector2(0, 46) b.add_theme_font_size_override("font_size", 20) b.pressed.connect(cb) return b func _port_value() -> int: var v := int(_port.text) return v if v > 0 else DEFAULT_PORT func player_name() -> String: var n := _name.text.strip_edges() return n if n != "" else "Crew" func set_status(text: String) -> void: _status.text = text func hide_menu() -> void: _root.visible = false func show_menu() -> void: _root.visible = true