2026-04-20 13:03:39 -05:00
|
|
|
class_name Lobby extends VBoxContainer
|
2026-04-13 11:34:00 -05:00
|
|
|
|
2026-04-20 13:03:39 -05:00
|
|
|
const PLAYER_ENTRY_SCENE = preload("uid://c1wn1ghkp12hb")
|
2026-04-13 11:34:00 -05:00
|
|
|
|
2026-04-20 13:03:39 -05:00
|
|
|
@onready var session_id: LineEdit = %SessionId
|
|
|
|
|
@onready var player_list: Container = %PlayerList
|
2026-04-15 10:45:43 -05:00
|
|
|
|
2026-04-20 13:03:39 -05:00
|
|
|
@onready var ready_button: Button = %ReadyButton
|
|
|
|
|
@onready var unready_button: Button = %UnreadyButton
|
2026-04-13 11:34:00 -05:00
|
|
|
|
2026-04-20 13:03:39 -05:00
|
|
|
@onready var message_line_edit: LineEdit = %MessageLineEdit
|
|
|
|
|
@onready var chat: RichTextLabel = %Chat
|
2026-04-15 10:45:43 -05:00
|
|
|
|
2026-04-13 11:34:00 -05:00
|
|
|
|
2026-04-20 13:03:39 -05:00
|
|
|
func set_session_id(id: String) -> void:
|
|
|
|
|
session_id.text = id
|
2026-04-13 11:34:00 -05:00
|
|
|
|
2026-04-20 13:03:39 -05:00
|
|
|
|
|
|
|
|
#@rpc("any_peer", "call_local", "reliable")
|
|
|
|
|
#func update_chat(text):
|
|
|
|
|
#chat_log.text += text + "\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#@rpc("any_peer", "call_local", "reliable")
|
|
|
|
|
func load_players(players: Array[Player]) -> void:
|
|
|
|
|
for child in player_list.get_children():
|
|
|
|
|
child.queue_free()
|
|
|
|
|
for player in players:
|
|
|
|
|
var player_entry: PlayerEntry = PLAYER_ENTRY_SCENE.instantiate()
|
|
|
|
|
player_list.add_child(player_entry)
|
|
|
|
|
player_entry.set_player(player)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@rpc("any_peer", "call_local", "reliable")
|
|
|
|
|
func ready_player(player_data: Dictionary, is_ready: bool) -> void:
|
|
|
|
|
for pe: PlayerEntry in player_list.get_children():
|
|
|
|
|
if pe.player.id == player_data["id"]:
|
|
|
|
|
if is_ready:
|
|
|
|
|
pe.ready()
|
|
|
|
|
else:
|
|
|
|
|
pe.unready()
|
|
|
|
|
_check_for_game_start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@rpc("any_peer", "call_local", "reliable")
|
|
|
|
|
func update_chat(message: String, player_data: Dictionary) -> void:
|
|
|
|
|
chat.push_color(player_data["color"])
|
|
|
|
|
chat.add_text("%s: " % player_data["name"])
|
|
|
|
|
chat.push_color(Color.WHITE)
|
|
|
|
|
chat.add_text("%s\n" % message)
|
2026-04-13 11:34:00 -05:00
|
|
|
|
2026-04-15 10:45:43 -05:00
|
|
|
|
2026-04-13 11:34:00 -05:00
|
|
|
@rpc("any_peer", "call_local", "reliable")
|
2026-04-20 13:03:39 -05:00
|
|
|
func start_game() -> void:
|
|
|
|
|
Globals.game.start_game()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _check_for_game_start() -> void:
|
|
|
|
|
for pe: PlayerEntry in player_list.get_children():
|
|
|
|
|
if !pe.is_ready:
|
|
|
|
|
return
|
|
|
|
|
start_game()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _handle_message_submitted() -> void:
|
|
|
|
|
update_chat.rpc(message_line_edit.text, Globals.game.this_player.serialize())
|
|
|
|
|
message_line_edit.text = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_ready_button_pressed():
|
|
|
|
|
ready_button.hide()
|
|
|
|
|
unready_button.show()
|
|
|
|
|
ready_player.rpc(Globals.game.this_player.serialize(), true)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_unready_button_pressed():
|
|
|
|
|
ready_button.show()
|
|
|
|
|
unready_button.hide()
|
|
|
|
|
ready_player.rpc(Globals.game.this_player.serialize(), false)
|