feat: updated UI UX for profile and leaderboard menu

This commit is contained in:
2026-03-27 22:18:29 +08:00
parent 3a50d2d324
commit a916a57c05
9 changed files with 776 additions and 180 deletions
+43 -7
View File
@@ -94,6 +94,9 @@ var current_match_id: String = ""
var leaderboard_panel_instance: Control
# Bot name tracking keyed by slot index to avoid re-generating on each update
var _bot_names: Dictionary = {}
# Server Selection Controls (Now in tscn)
# var server_option: OptionButton
# var server_ip_input: LineEdit
@@ -116,7 +119,7 @@ func _ready():
# Set player name from profile
if AuthManager.is_guest:
LobbyManager.local_player_name = "Guest"
LobbyManager.local_player_name = NameGenerator.generate_guest_name()
else:
LobbyManager.local_player_name = UserProfileManager.get_display_name()
@@ -329,17 +332,21 @@ func _on_create_room_pressed() -> void:
# Use profile name for logged-in users, or guest for others
if AuthManager.is_guest:
if LobbyManager.local_player_name.is_empty() or LobbyManager.local_player_name == "Player":
LobbyManager.local_player_name = "Guest"
LobbyManager.local_player_name = NameGenerator.generate_guest_name()
else:
LobbyManager.local_player_name = UserProfileManager.get_display_name()
if LobbyManager.is_lan_mode:
connection_status.text = "Starting LAN room..."
# Apply loadout character before creating room
_apply_loadout_character()
var ok = await LobbyManager.create_room_lan("LAN Room " + str(randi_range(100, 999)))
if not ok:
connection_status.text = "Failed to start LAN room. Check port 7777."
else:
connection_status.text = "Creating Nakama room..."
# Apply loadout character before creating room
_apply_loadout_character()
LobbyManager.create_room("Room %d" % randi_range(1000, 9999))
func _on_browse_rooms_pressed() -> void:
@@ -399,7 +406,7 @@ func _on_join_pressed() -> void:
# Determine player name
if AuthManager.is_guest:
if LobbyManager.local_player_name.is_empty():
LobbyManager.local_player_name = "Guest"
LobbyManager.local_player_name = NameGenerator.generate_guest_name()
else:
LobbyManager.local_player_name = UserProfileManager.get_display_name()
@@ -417,6 +424,8 @@ func _on_join_pressed() -> void:
return
connection_status.text = "Connecting to %s..." % match_id
# Apply loadout character before joining
_apply_loadout_character()
var ok = LobbyManager.join_room_lan(match_id)
if not ok:
connection_status.text = "Failed to connect to %s" % match_id
@@ -425,6 +434,8 @@ func _on_join_pressed() -> void:
connection_status.text = "No room selected"
return
connection_status.text = "Joining Nakama room..."
# Apply loadout character before joining
_apply_loadout_character()
LobbyManager.join_room(match_id)
func _on_back_pressed() -> void:
@@ -529,6 +540,10 @@ func _on_leave_pressed() -> void:
_show_panel("main_menu")
ready_btn.button_pressed = false
ready_btn.text = "READY"
# Release bot names so they can be reused in the next session
for key in _bot_names.keys():
NameGenerator.release_bot_name(_bot_names[key])
_bot_names.clear()
func _on_copy_id_pressed() -> void:
DisplayServer.clipboard_set(current_match_id)
@@ -611,10 +626,11 @@ func _on_profile_btn_pressed() -> void:
var profile_panel_scene := load("res://scenes/ui/profile_panel.tscn")
profile_panel_instance = profile_panel_scene.instantiate()
profile_panel_instance.closed.connect(func(): profile_panel_instance.hide())
# Full-screen overlay — fill the entire lobby viewport
profile_panel_instance.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
add_child(profile_panel_instance)
profile_panel_instance.show_panel()
profile_panel_instance.position = (get_viewport_rect().size - profile_panel_instance.size) / 2
func _on_logout_pressed() -> void:
AuthManager.logout()
@@ -648,11 +664,12 @@ func _on_leaderboard_pressed() -> void:
if leaderboard_panel_scene:
leaderboard_panel_instance = leaderboard_panel_scene.instantiate()
leaderboard_panel_instance.closed.connect(func(): leaderboard_panel_instance.hide())
# Full-screen overlay
leaderboard_panel_instance.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
add_child(leaderboard_panel_instance)
if leaderboard_panel_instance:
leaderboard_panel_instance.show_panel()
# Center it and apply some offset if needed
func _go_to_login() -> void:
if get_tree():
@@ -716,6 +733,10 @@ func _on_room_joined(room_data: Dictionary) -> void:
func _on_room_left() -> void:
_show_panel("main_menu")
connection_status.text = "Left room"
# Release bot names for reuse
for key in _bot_names.keys():
NameGenerator.release_bot_name(_bot_names[key])
_bot_names.clear()
func _on_host_disconnected() -> void:
# Keep the connection status updated in the UI
@@ -854,10 +875,15 @@ func _update_player_slots() -> void:
# Empty slot - show as bot placeholder
slot.visible = true
# Update name to show as bot
# Assign stable bot name for this slot (generate once, reuse)
if not _bot_names.has(i):
_bot_names[i] = NameGenerator.generate_bot_name()
var bot_display_name: String = _bot_names[i]
# Update name to show bot with an icon prefix
var name_label = slot.get_node_or_null("PlayerName%d" % slot_num)
if name_label:
name_label.text = "🤖 Bot %d" % slot_num
name_label.text = "🤖 " + bot_display_name
# Use a character for bot preview
var char_preview = slot.get_node_or_null("CharacterPreview%d" % slot_num)
@@ -916,3 +942,13 @@ func _truncate_id(id: String) -> String:
if id.length() > 16:
return id.substr(0, 8) + "..." + id.substr(-4)
return id
func _apply_loadout_character() -> void:
"""Apply the player's saved loadout default character to LobbyManager before entering a room."""
var saved_char: String = UserProfileManager.profile.get("loadout_character", "")
if saved_char.is_empty():
return
var idx := LobbyManager.available_characters.find(saved_char)
if idx != -1:
LobbyManager.local_character_index = idx
print("[Lobby] Loadout character applied: ", saved_char)