Files
millimeters-of-aluminum/scenes/UI/main_menu/main_menu.gd
2025-12-05 15:50:48 +01:00

48 lines
1.6 KiB
GDScript

extends Control
# @export var lobby_menu: Control
# @export var settings_menu: Control
# Buttons and input fields
@onready var host_button: Button = %HostButton
@onready var join_button: Button = %JoinButton
@onready var settings_button: Button = %SettingsButton
@onready var quit_button: Button = %QuitButton
@onready var address_entry: LineEdit = %AddressEntry
func _ready():
host_button.pressed.connect(_on_host_pressed)
join_button.pressed.connect(_on_join_pressed)
quit_button.pressed.connect(_on_quit_pressed)
# Ensure we start with a clean slate
# lobby_menu.visible = false
# If we just returned from a game, ensure mouse is visible
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
func _on_host_pressed():
# For a simple test, hosting immediately starts the server and the game
NetworkHandler.create_server()
NetworkHandler.on_peer_connected(multiplayer.get_unique_id())
_transition_to_game()
func _on_join_pressed():
var ip = address_entry.text
if ip.is_empty():
ip = "127.0.0.1" # Default to localhost
NetworkHandler.create_client(ip)
# The NetworkHandler signals will handle the actual transition once connected
# But for UI feedback, we might want to show a "Connecting..." label here.
func _on_quit_pressed():
get_tree().quit()
func _transition_to_game():
# This would typically load the main game scene.
# Since your main scene IS the game loop currently, we might need to
# just hide the menu if it's an overlay, OR change scenes.
# Assuming Main.tscn is the game world:
get_tree().change_scene_to_file("res://scripts/star_system.tscn")