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
+93 -9
View File
@@ -38,6 +38,7 @@ var is_loading: bool = false
# Server Selection Controls
var server_option: OptionButton
var server_ip_input: LineEdit
var lan_section: VBoxContainer # LAN-specific controls
func _ready() -> void:
_connect_signals()
@@ -203,7 +204,7 @@ func _setup_server_config_ui() -> void:
# Server Label
var label = Label.new()
label.text = "NAKAMA SERVER"
label.text = "CONNECTION MODE"
label.add_theme_color_override("font_color", Color(0.69, 0.529, 0.357, 1))
label.add_theme_font_size_override("font_size", 13)
server_section.add_child(label)
@@ -212,8 +213,9 @@ func _setup_server_config_ui() -> void:
server_option = OptionButton.new()
server_option.name = "ServerOption"
server_option.custom_minimum_size = Vector2(0, 44)
server_option.add_item("Localhost (Testing)")
server_option.add_item("Remote Server (Host IP)")
server_option.add_item("Nakama - Localhost (Testing)")
server_option.add_item("Nakama - Remote Server (Host IP)")
server_option.add_item("LAN Direct (No Server)")
# Set initial state based on NakamaManager
if NakamaManager.nakama_host == "localhost":
@@ -224,17 +226,62 @@ func _setup_server_config_ui() -> void:
server_option.item_selected.connect(_on_server_option_selected)
server_section.add_child(server_option)
# Server IP Input
# Nakama Server IP Input
server_ip_input = LineEdit.new()
server_ip_input.name = "ServerIPInput"
server_ip_input.custom_minimum_size = Vector2(0, 44)
server_ip_input.placeholder_text = "Enter Server IP Address..."
server_ip_input.placeholder_text = "Enter Nakama Server IP..."
server_ip_input.text = NakamaManager.nakama_host if NakamaManager.nakama_host != "localhost" else "127.0.0.1"
server_ip_input.visible = server_option.selected == 1
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))
server_section.add_child(server_ip_input)
# --- LAN Section ---
lan_section = VBoxContainer.new()
lan_section.name = "LANSection"
lan_section.add_theme_constant_override("separation", 8)
lan_section.visible = false
server_section.add_child(lan_section)
var lan_info = Label.new()
lan_info.text = "Play over LAN without any server.\nFirewall may need to allow port 7777."
lan_info.add_theme_color_override("font_color", Color(0.7, 0.7, 0.7, 1))
lan_info.add_theme_font_size_override("font_size", 12)
lan_info.autowrap_mode = TextServer.AUTOWRAP_WORD
lan_section.add_child(lan_info)
# Host LAN button
var lan_host_btn = Button.new()
lan_host_btn.name = "LANHostBtn"
lan_host_btn.text = "HOST LAN GAME"
lan_host_btn.custom_minimum_size = Vector2(0, 44)
lan_host_btn.pressed.connect(_on_lan_host_pressed)
lan_section.add_child(lan_host_btn)
var lan_sep = Label.new()
lan_sep.text = "── or join a friend ──"
lan_sep.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
lan_sep.add_theme_color_override("font_color", Color(0.5, 0.5, 0.5, 1))
lan_sep.add_theme_font_size_override("font_size", 11)
lan_section.add_child(lan_sep)
# LAN Host IP input
var lan_ip = LineEdit.new()
lan_ip.name = "LANIPInput"
lan_ip.custom_minimum_size = Vector2(0, 44)
lan_ip.placeholder_text = "Host IP (e.g. 192.168.1.10)"
lan_ip.text = "127.0.0.1"
lan_section.add_child(lan_ip)
# Join LAN button
var lan_join_btn = Button.new()
lan_join_btn.name = "LANJoinBtn"
lan_join_btn.text = "JOIN LAN GAME"
lan_join_btn.custom_minimum_size = Vector2(0, 44)
lan_join_btn.pressed.connect(func(): _on_lan_join_pressed(lan_ip.text))
lan_section.add_child(lan_join_btn)
# Add a separator after the section
var separator = HSeparator.new()
vbox.add_child(separator)
@@ -242,18 +289,55 @@ func _setup_server_config_ui() -> void:
func _on_server_option_selected(index: int) -> void:
if index == 0:
# Localhost
# Nakama Localhost
server_ip_input.visible = false
if lan_section: lan_section.visible = false
NakamaManager.set_server("localhost")
else:
# Remote
elif index == 1:
# Nakama Remote
server_ip_input.visible = true
if lan_section: lan_section.visible = false
NakamaManager.set_server(server_ip_input.text)
else:
# LAN Direct
server_ip_input.visible = false
if lan_section: lan_section.visible = true
func _on_server_ip_submitted(new_text: String) -> void:
if server_option.selected == 1:
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 logging in to Nakama."""
var player_name = email_input.text.strip_edges()
if player_name.is_empty():
player_name = "Host"
LobbyManager.local_player_name = player_name
var ok = await LobbyManager.create_room_lan()
if ok:
_go_to_lobby()
else:
_show_error("Failed to create LAN server. Check firewall for port 7777.")
func _on_lan_join_pressed(host_ip: String) -> void:
"""Join a LAN game without logging in to Nakama."""
var ip = host_ip.strip_edges()
if ip.is_empty():
_show_error("Please enter the host's IP address.")
return
var player_name = email_input.text.strip_edges()
if player_name.is_empty():
player_name = "Player"
LobbyManager.local_player_name = player_name
var ok = LobbyManager.join_room_lan(ip)
if ok:
_go_to_lobby()
else:
_show_error("Failed to connect to %s. Is the host running?" % ip)
# =============================================================================
# Registration Handlers
# =============================================================================