Files
Grovewright/game/scripts/menu.gd
T
Steven Wroblewski 9f65823f2d Vitrine der Stilproben
Das Startmenü führt zu einer Vitrine, die den gewählten Stil an einer
kleinen Szene zeigt: Fels, toter und lebendiger Boden, Lebensmoos, eine
Ranke, die Steine in eine erwachende Ruine trägt, eine wachsende
Faserpflanze, ein hüpfendes Weidetier und zwei Spielfiguren. Knöpfe,
die Tasten 1 bis 3 und F2 wechseln den Stil, Esc führt zurück ins Menü.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-02 12:27:26 +02:00

70 lines
2.4 KiB
GDScript

class_name Menu
extends CanvasLayer
## The start screen: the player's name, then playing alone, opening the world
## for guests, or joining a host. Below, the way to the style samples.
signal play_chosen(open: bool)
signal join_chosen(address: String)
signal showcase_chosen
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 showcase_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")
showcase_button.text = tr("MENU_SHOWCASE")
_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, HSeparator.new(), showcase_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())
showcase_button.pressed.connect(func() -> void: showcase_chosen.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()