client_ui.gd 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. extends Control
  2. @onready var client = $Client
  3. @onready var host = $VBoxContainer/Connect/Host
  4. @onready var room = $VBoxContainer/Connect/RoomSecret
  5. @onready var mesh = $VBoxContainer/Connect/Mesh
  6. func _ready():
  7. client.lobby_joined.connect(self._lobby_joined)
  8. client.lobby_sealed.connect(self._lobby_sealed)
  9. client.connected.connect(self._connected)
  10. client.disconnected.connect(self._disconnected)
  11. multiplayer.connected_to_server.connect(self._mp_server_connected)
  12. multiplayer.connection_failed.connect(self._mp_server_disconnect)
  13. multiplayer.server_disconnected.connect(self._mp_server_disconnect)
  14. multiplayer.peer_connected.connect(self._mp_peer_connected)
  15. multiplayer.peer_disconnected.connect(self._mp_peer_disconnected)
  16. @rpc("any_peer", "call_local")
  17. func ping(argument):
  18. _log("[Multiplayer] Ping from peer %d: arg: %s" % [multiplayer.get_remote_sender_id(), argument])
  19. func _mp_server_connected():
  20. _log("[Multiplayer] Server connected (I am %d)" % client.rtc_mp.get_unique_id())
  21. func _mp_server_disconnect():
  22. _log("[Multiplayer] Server disconnected (I am %d)" % client.rtc_mp.get_unique_id())
  23. func _mp_peer_connected(id: int):
  24. _log("[Multiplayer] Peer %d connected" % id)
  25. func _mp_peer_disconnected(id: int):
  26. _log("[Multiplayer] Peer %d disconnected" % id)
  27. func _connected(id, use_mesh):
  28. _log("[Signaling] Server connected with ID: %d. Mesh: %s" % [id, use_mesh])
  29. func _disconnected():
  30. _log("[Signaling] Server disconnected: %d - %s" % [client.code, client.reason])
  31. func _lobby_joined(lobby):
  32. _log("[Signaling] Joined lobby %s" % lobby)
  33. func _lobby_sealed():
  34. _log("[Signaling] Lobby has been sealed")
  35. func _log(msg):
  36. print(msg)
  37. $VBoxContainer/TextEdit.text += str(msg) + "\n"
  38. func _on_peers_pressed():
  39. _log(multiplayer.get_peers())
  40. func _on_ping_pressed():
  41. ping.rpc(randf())
  42. func _on_seal_pressed():
  43. client.seal_lobby()
  44. func _on_start_pressed():
  45. client.start(host.text, room.text, mesh.button_pressed)
  46. func _on_stop_pressed():
  47. client.stop()