feat: implement initial lobby scene with main menu, server browser, and networking options.

This commit is contained in:
Yogi Wiguna
2026-03-16 16:19:30 +08:00
parent 64dc1de15a
commit eb018903aa
6 changed files with 317 additions and 35 deletions
+58 -3
View File
@@ -12,6 +12,10 @@ extends Control
# UI References - Server Selection
@onready var server_option = $MainMenuPanel/VBoxContainer/ServerSelectionSection/ServerOption
@onready var server_ip_input = $MainMenuPanel/VBoxContainer/ServerSelectionSection/ServerIPInput
@onready var lan_section = $MainMenuPanel/VBoxContainer/ServerSelectionSection/LANSection
@onready var lan_ip_input = $MainMenuPanel/VBoxContainer/ServerSelectionSection/LANSection/LANIPInput
@onready var lan_host_btn = $MainMenuPanel/VBoxContainer/ServerSelectionSection/LANSection/LANHostBtn
@onready var lan_join_btn = $MainMenuPanel/VBoxContainer/ServerSelectionSection/LANSection/LANJoinBtn
# Leaderboard Reference
@onready var leaderboard_btn = $MainMenuPanel/VBoxContainer/ButtonSection/LeaderboardBtn
@@ -154,6 +158,10 @@ func _ready():
if server_ip_input:
server_ip_input.text_submitted.connect(_on_server_ip_submitted)
server_ip_input.focus_exited.connect(func(): _on_server_ip_submitted(server_ip_input.text))
if lan_host_btn:
lan_host_btn.pressed.connect(_on_lan_host_pressed)
if lan_join_btn:
lan_join_btn.pressed.connect(func(): _on_lan_join_pressed(lan_ip_input.text if lan_ip_input else "127.0.0.1"))
# Connect button signals - Room List
refresh_btn.pressed.connect(_on_refresh_pressed)
@@ -248,18 +256,58 @@ func _load_character_textures() -> void:
func _on_server_option_selected(index: int) -> void:
if index == 0:
# Localhost
# Nakama Localhost
if server_ip_input: server_ip_input.visible = false
if lan_section: lan_section.visible = false
NakamaManager.set_server("localhost")
else:
# Remote
elif index == 1:
# Nakama Remote
if server_ip_input: server_ip_input.visible = true
if lan_section: lan_section.visible = false
if server_ip_input: NakamaManager.set_server(server_ip_input.text)
else:
# LAN Direct
if server_ip_input: server_ip_input.visible = false
if lan_section: lan_section.visible = true
func _on_server_ip_submitted(new_text: String) -> void:
if server_option and server_option.selected == 1:
NakamaManager.set_server(new_text.strip_edges())
func _on_lan_host_pressed() -> void:
"""Host a LAN game without Nakama."""
var player_name = player_name_input.text.strip_edges() if player_name_input else ""
if player_name.is_empty():
player_name = "Host"
LobbyManager.local_player_name = player_name
if connection_status:
connection_status.text = "Starting LAN server..."
var ok = await LobbyManager.create_room_lan()
if not ok:
if connection_status:
connection_status.text = "Failed to start LAN server. Check port 7777."
func _on_lan_join_pressed(host_ip: String) -> void:
"""Join a LAN game by entering the host's IP."""
var ip = host_ip.strip_edges()
if ip.is_empty():
if connection_status:
connection_status.text = "Enter the host's IP address."
return
var player_name = player_name_input.text.strip_edges() if player_name_input else ""
if player_name.is_empty():
player_name = "Player"
LobbyManager.local_player_name = player_name
if connection_status:
connection_status.text = "Connecting to %s..." % ip
var ok = LobbyManager.join_room_lan(ip)
if not ok:
if connection_status:
connection_status.text = "Failed to connect to %s. Is host running?" % ip
func _setup_game_modes() -> void:
if not game_mode_option: return
game_mode_option.clear()
@@ -680,6 +728,13 @@ func _on_room_joined(room_data: Dictionary) -> void:
_update_player_slots()
connection_status.text = "Connected to room"
# LAN solo mode: host is auto-ready, enable Start Game immediately
if LobbyManager.is_lan_mode and is_host:
ready_btn.button_pressed = true
ready_btn.text = "READY ✓"
LobbyManager.force_solo_ready()
status_label.text = "LAN Solo — press Start Game when ready!"
func _on_room_left() -> void:
_show_panel("main_menu")