diff --git a/client_ui.gd b/client_ui.gd deleted file mode 100644 index 5457966..0000000 --- a/client_ui.gd +++ /dev/null @@ -1,64 +0,0 @@ -extends Control - -onready var client = $Client - -func _ready(): - client.connect("lobby_joined", self, "_lobby_joined") - client.connect("lobby_sealed", self, "_lobby_sealed") - client.connect("connected", self, "_connected") - client.connect("disconnected", self, "_disconnected") - client.rtc_mp.connect("peer_connected", self, "_mp_peer_connected") - client.rtc_mp.connect("peer_disconnected", self, "_mp_peer_disconnected") - client.rtc_mp.connect("server_disconnected", self, "_mp_server_disconnect") - client.rtc_mp.connect("connection_succeeded", self, "_mp_connected") - -func _process(delta): - client.rtc_mp.poll() - while client.rtc_mp.get_available_packet_count() > 0: - _log(client.rtc_mp.get_packet().get_string_from_utf8()) - -func _connected(id): - _log("Signaling server connected with ID: %d" % id) - -func _disconnected(): - _log("Signaling server disconnected: %d - %s" % [client.code, client.reason]) - -func _lobby_joined(lobby): - _log("Joined lobby %s" % lobby) - -func _lobby_sealed(): - _log("Lobby has been sealed") - -func _mp_connected(): - _log("Multiplayer is connected (I am %d)" % client.rtc_mp.get_unique_id()) - -func _mp_server_disconnect(): - _log("Multiplayer is disconnected (I am %d)" % client.rtc_mp.get_unique_id()) - -func _mp_peer_connected(id: int): - _log("Multiplayer peer %d connected" % id) - -func _mp_peer_disconnected(id: int): - _log("Multiplayer peer %d disconnected" % id) - -func _log(msg): - print(msg) - $VBoxContainer/TextEdit.text += str(msg) + "\n" - -func ping(): - _log(client.rtc_mp.put_packet("ping".to_utf8())) - -func _on_Peers_pressed(): - var d = client.rtc_mp.get_peers() - _log(d) - for k in d: - _log(client.rtc_mp.get_peer(k)) - -func start(): - client.start($VBoxContainer/Connect/Host.text, $VBoxContainer/Connect/RoomSecret.text) - -func _on_Seal_pressed(): - client.seal_lobby() - -func stop(): - client.stop() diff --git a/client_ui.tscn b/client_ui.tscn deleted file mode 100644 index 6e1c31b..0000000 --- a/client_ui.tscn +++ /dev/null @@ -1,107 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://client_ui.gd" type="Script" id=1] -[ext_resource path="res://multiplayer_client.gd" type="Script" id=2] - -[node name="ClientUI" type="Control"] -margin_right = 1024.0 -margin_bottom = 600.0 -size_flags_horizontal = 3 -size_flags_vertical = 3 -script = ExtResource( 1 ) -__meta__ = { -"_edit_use_anchors_": true -} - -[node name="Client" type="Node" parent="."] -script = ExtResource( 2 ) - -[node name="VBoxContainer" type="VBoxContainer" parent="."] -anchor_right = 1.0 -anchor_bottom = 1.0 -custom_constants/separation = 8 -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="Connect" type="HBoxContainer" parent="VBoxContainer"] -margin_right = 1024.0 -margin_bottom = 24.0 - -[node name="Label" type="Label" parent="VBoxContainer/Connect"] -margin_top = 5.0 -margin_right = 73.0 -margin_bottom = 19.0 -text = "Connect to:" - -[node name="Host" type="LineEdit" parent="VBoxContainer/Connect"] -margin_left = 77.0 -margin_right = 921.0 -margin_bottom = 24.0 -size_flags_horizontal = 3 -text = "ws://localhost:9080" - -[node name="Room" type="Label" parent="VBoxContainer/Connect"] -margin_left = 925.0 -margin_right = 962.0 -margin_bottom = 24.0 -size_flags_vertical = 5 -text = "Room" -valign = 1 - -[node name="RoomSecret" type="LineEdit" parent="VBoxContainer/Connect"] -margin_left = 966.0 -margin_right = 1024.0 -margin_bottom = 24.0 -placeholder_text = "secret" - -[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] -margin_top = 32.0 -margin_right = 1024.0 -margin_bottom = 52.0 -custom_constants/separation = 10 -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="Start" type="Button" parent="VBoxContainer/HBoxContainer"] -margin_right = 41.0 -margin_bottom = 20.0 -text = "Start" - -[node name="Stop" type="Button" parent="VBoxContainer/HBoxContainer"] -margin_left = 51.0 -margin_right = 91.0 -margin_bottom = 20.0 -text = "Stop" - -[node name="Seal" type="Button" parent="VBoxContainer/HBoxContainer"] -margin_left = 101.0 -margin_right = 139.0 -margin_bottom = 20.0 -text = "Seal" - -[node name="Ping" type="Button" parent="VBoxContainer/HBoxContainer"] -margin_left = 149.0 -margin_right = 188.0 -margin_bottom = 20.0 -text = "Ping" - -[node name="Peers" type="Button" parent="VBoxContainer/HBoxContainer"] -margin_left = 198.0 -margin_right = 280.0 -margin_bottom = 20.0 -text = "Print peers" - -[node name="TextEdit" type="TextEdit" parent="VBoxContainer"] -margin_top = 60.0 -margin_right = 1024.0 -margin_bottom = 600.0 -size_flags_vertical = 3 -readonly = true - -[connection signal="pressed" from="VBoxContainer/HBoxContainer/Start" to="." method="start"] -[connection signal="pressed" from="VBoxContainer/HBoxContainer/Stop" to="." method="stop"] -[connection signal="pressed" from="VBoxContainer/HBoxContainer/Seal" to="." method="_on_Seal_pressed"] -[connection signal="pressed" from="VBoxContainer/HBoxContainer/Ping" to="." method="ping"] -[connection signal="pressed" from="VBoxContainer/HBoxContainer/Peers" to="." method="_on_Peers_pressed"] diff --git a/global.gd b/global.gd index 4c7beca..733b95d 100644 --- a/global.gd +++ b/global.gd @@ -4,11 +4,27 @@ const MultiplayerClient = preload("multiplayer_client.gd") onready var client = MultiplayerClient.new() +# for command line flags +onready var goto_multiplayer = false +onready var create_lobby = false +onready var join_first_available_lobby = false + func _ready(): # client.signaller.connect("websocket_connected", self, "signaller_disconnected") add_child(client) client.signaller.connect("websocket_connected", self, "_signaller_connected") + for arg in OS.get_cmdline_args(): + match arg: + "--multiplayer": goto_multiplayer = true + "--create-lobby": create_lobby = true + "--join-first-available-lobby": join_first_available_lobby = true + var a: print("Unknown command line arg: %s" % a) + + if goto_multiplayer: + goto_multiplayer = false + lobby_browser() + func goto_scene(scene_resource_name): var _result = get_tree().change_scene("res://%s.tscn" % scene_resource_name) diff --git a/join_lobby.gd b/join_lobby.gd deleted file mode 100644 index e5a42e9..0000000 --- a/join_lobby.gd +++ /dev/null @@ -1,21 +0,0 @@ -extends Control - - -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" - - -# Called when the node enters the scene tree for the first time. -func _ready(): - pass # Replace with function body. - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass - - -func _on_Button_pressed(): - print("Joining with ", $TextEdit.text) - Global.join_lobby_with_code($TextEdit.text) diff --git a/join_lobby.tscn b/join_lobby.tscn deleted file mode 100644 index 26131bd..0000000 --- a/join_lobby.tscn +++ /dev/null @@ -1,36 +0,0 @@ -[gd_scene load_steps=2 format=2] - -[ext_resource path="res://join_lobby.gd" type="Script" id=1] - -[node name="Control" type="Control"] -anchor_right = 1.0 -anchor_bottom = 1.0 -script = ExtResource( 1 ) -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="Label" type="Label" parent="."] -margin_left = 235.0 -margin_top = 74.0 -margin_right = 275.0 -margin_bottom = 88.0 -text = "Lobby Code" - -[node name="TextEdit" type="TextEdit" parent="."] -margin_left = 239.0 -margin_top = 99.0 -margin_right = 544.0 -margin_bottom = 139.0 -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="Button" type="Button" parent="."] -margin_left = 320.0 -margin_top = 149.0 -margin_right = 451.0 -margin_bottom = 169.0 -text = "Join" - -[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"] diff --git a/lobby.gd b/lobby.gd index b924133..d14b399 100644 --- a/lobby.gd +++ b/lobby.gd @@ -1,40 +1,31 @@ -extends Node2D +extends MarginContainer -onready var peers = $MarginContainer/peers +onready var peers = $v/body/peers/peers +onready var lobby_info_label = $v/head/lobby_info onready var cursors = {} func _ready(): Global.client.signaller.connect("peer_joined", self, "_peer_joined") Global.client.signaller.connect("peer_left", self, "_peer_left") Global.client.signaller.connect("lobby_left", self, "_lobby_left") - $MarginContainer/Label.text = "%s (%s)" % [Global.client.signaller.lobby_id, get_tree().get_network_unique_id()] + lobby_info_label.text = "%s (%s)" % [Global.client.signaller.lobby_id, get_tree().get_network_unique_id()] Global.client.signaller.connect("websocket_disconnected", self, "_signaller_disconnected") - $shifter.connect("mouse_entered", self, "do_ping") - - _peer_joined([{ - "id": Global.client.signaller.client_id, - "peerId": Global.client.signaller.peer_id, - "name": "You!", - }]) - Global.client.signaller.request_peer_list() func _signaller_disconnected(): Global.main_menu() -func _draw(): - $text.text = JSON.print(Global.client.signaller) - func _peer_joined(joined_peers): - print("Joined Peers: %s" % joined_peers) + print("Joined Peers: %s" % [joined_peers]) for i in range(len(joined_peers)): var id = joined_peers[i]["id"] var exists = false for j in range(peers.get_item_count()): if id == peers.get_item_metadata(j)["id"]: + print("Already have this one") exists = true break - if !exists: + if not exists: var peerId = joined_peers[i]["peerId"] var name = joined_peers[i]["name"] print("New Lobby Peer ID: %s, Name: %s, PeerID: %s" % [id, name, peerId]) diff --git a/lobby.tscn b/lobby.tscn index 6d40713..d2ea1a9 100644 --- a/lobby.tscn +++ b/lobby.tscn @@ -1,78 +1,97 @@ [gd_scene load_steps=3 format=2] [ext_resource path="res://lobby.gd" type="Script" id=1] -[ext_resource path="res://iosevkalyte.tres" type="DynamicFont" id=2] +[ext_resource path="res://theme.tres" type="Theme" id=2] -[node name="Node2D" type="Node2D"] -script = ExtResource( 1 ) - -[node name="text" type="TextEdit" parent="."] -margin_left = 208.0 -margin_top = 162.0 -margin_right = 739.0 -margin_bottom = 453.0 -custom_fonts/font = ExtResource( 2 ) -text = "information goes in here" -readonly = true -highlight_current_line = true -syntax_highlighting = true -show_line_numbers = true -draw_tabs = true -draw_spaces = true -smooth_scrolling = true -wrap_enabled = true -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="shifter" type="Label" parent="."] -margin_left = 678.0 -margin_top = 10.0 -margin_right = 718.0 -margin_bottom = 26.0 -text = "ping" -autowrap = true -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="MarginContainer" type="VBoxContainer" parent="."] +[node name="lobby" type="MarginContainer"] anchor_right = 1.0 anchor_bottom = 1.0 -margin_right = 669.0 -margin_bottom = 366.0 +margin_left = 20.0 +margin_top = 20.0 +margin_right = -20.0 +margin_bottom = -20.0 +theme = ExtResource( 2 ) +script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": false } -[node name="Label" type="Label" parent="MarginContainer"] -margin_right = 669.0 -margin_bottom = 14.0 -autowrap = true -__meta__ = { -"_edit_use_anchors_": false -} +[node name="v" type="VBoxContainer" parent="."] +margin_right = 984.0 +margin_bottom = 560.0 -[node name="leave_button" type="Button" parent="MarginContainer"] -margin_top = 18.0 -margin_right = 669.0 -margin_bottom = 38.0 +[node name="head" type="HBoxContainer" parent="v"] +margin_right = 984.0 +margin_bottom = 50.0 + +[node name="leave_button" type="Button" parent="v/head"] +margin_right = 150.0 +margin_bottom = 50.0 +rect_min_size = Vector2( 150, 50 ) text = "Leave" __meta__ = { "_edit_use_anchors_": false } -[node name="Button" type="Button" parent="MarginContainer"] -margin_top = 42.0 -margin_right = 669.0 -margin_bottom = 62.0 -text = "Shift" +[node name="lobby_info" type="Label" parent="v/head"] +margin_left = 154.0 +margin_right = 984.0 +margin_bottom = 50.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +valign = 1 +autowrap = true +__meta__ = { +"_edit_use_anchors_": false +} -[node name="peers" type="ItemList" parent="MarginContainer"] -margin_top = 66.0 -margin_right = 669.0 -margin_bottom = 75.0 +[node name="body" type="HBoxContainer" parent="v"] +margin_top = 54.0 +margin_right = 984.0 +margin_bottom = 560.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="peers" type="VBoxContainer" parent="v/body"] +margin_right = 128.0 +margin_bottom = 506.0 + +[node name="label" type="Label" parent="v/body/peers"] +margin_right = 128.0 +margin_bottom = 21.0 +text = "Players in Lobby" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="peers" type="ItemList" parent="v/body/peers"] +margin_top = 25.0 +margin_right = 128.0 +margin_bottom = 506.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 auto_height = true -[connection signal="pressed" from="MarginContainer/leave_button" to="." method="_on_leave_button_pressed"] -[connection signal="pressed" from="MarginContainer/Button" to="." method="_on_Button_pressed"] +[node name="v" type="VBoxContainer" parent="v/body"] +margin_left = 132.0 +margin_right = 984.0 +margin_bottom = 506.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="label" type="Label" parent="v/body/v"] +margin_right = 852.0 +margin_bottom = 21.0 +text = "Chat" + +[node name="messages" type="ItemList" parent="v/body/v"] +margin_top = 25.0 +margin_right = 852.0 +margin_bottom = 506.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +__meta__ = { +"_edit_use_anchors_": false +} + +[connection signal="pressed" from="v/head/leave_button" to="." method="_on_leave_button_pressed"] diff --git a/main.gd b/main.gd index a5adb91..c8797e0 100644 --- a/main.gd +++ b/main.gd @@ -8,3 +8,7 @@ func _on_CreateLobbyButton_pressed(): func _on_JoinLobbyButton_pressed(): Global.quit() + + +func _on_LinkButton_pressed(): + OS.shell_open("https://lyte.dev") diff --git a/main.tscn b/main.tscn index a5efc91..5512c3c 100644 --- a/main.tscn +++ b/main.tscn @@ -1,52 +1,108 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://main.gd" type="Script" id=1] +[ext_resource path="res://assets/fonts/iosevkalyte/iosevkalyte-regular.ttf" type="DynamicFontData" id=2] +[ext_resource path="res://theme.tres" type="Theme" id=3] -[node name="Control" type="Control"] -anchor_left = 0.0136719 -anchor_top = 0.0166667 -anchor_right = 0.986328 -anchor_bottom = 0.983333 -margin_top = 4.32134e-07 -margin_bottom = -9.53674e-06 -script = ExtResource( 1 ) -__meta__ = { -"_edit_use_anchors_": true -} +[sub_resource type="DynamicFont" id=1] +size = 70 +font_data = ExtResource( 2 ) -[node name="VBoxContainer" type="VBoxContainer" parent="."] +[node name="Control" type="MarginContainer"] anchor_right = 1.0 anchor_bottom = 1.0 -custom_constants/separation = 50 -__meta__ = { -"_edit_use_anchors_": true -} - -[node name="Singleplayer" type="Button" parent="VBoxContainer"] -margin_right = 995.0 -margin_bottom = 20.0 -text = "Start Singleplayer Game" +margin_left = 20.0 +margin_top = 20.0 +margin_right = -20.0 +margin_bottom = -20.0 +theme = ExtResource( 3 ) +script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": false } -[node name="CreateLobbyButton" type="Button" parent="VBoxContainer"] -margin_top = 70.0 -margin_right = 995.0 -margin_bottom = 90.0 -text = "Multiplayer" +[node name="VBoxContainer" type="VBoxContainer" parent="."] +margin_right = 984.0 +margin_bottom = 560.0 -[node name="JoinLobbyButton" type="Button" parent="VBoxContainer"] -margin_top = 140.0 -margin_right = 995.0 -margin_bottom = 160.0 +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] +margin_right = 984.0 +margin_bottom = 50.0 +alignment = 1 + +[node name="quit" type="Button" parent="VBoxContainer/HBoxContainer"] +margin_right = 325.0 +margin_bottom = 50.0 +rect_min_size = Vector2( 150, 50 ) +size_flags_horizontal = 3 +size_flags_vertical = 3 +theme = ExtResource( 3 ) text = "Quit" __meta__ = { "_edit_use_anchors_": false } -[node name="Server" type="Node" parent="."] +[node name="multiplayer" type="Button" parent="VBoxContainer/HBoxContainer"] +margin_left = 329.0 +margin_right = 654.0 +margin_bottom = 50.0 +rect_min_size = Vector2( 150, 50 ) +size_flags_horizontal = 3 +size_flags_vertical = 3 +theme = ExtResource( 3 ) +text = "Multiplayer" -[connection signal="pressed" from="VBoxContainer/Singleplayer" to="." method="_on_Singleplayer_pressed"] -[connection signal="pressed" from="VBoxContainer/CreateLobbyButton" to="." method="_on_CreateLobbyButton_pressed"] -[connection signal="pressed" from="VBoxContainer/JoinLobbyButton" to="." method="_on_JoinLobbyButton_pressed"] +[node name="Singleplayer" type="Button" parent="VBoxContainer/HBoxContainer"] +margin_left = 658.0 +margin_right = 984.0 +margin_bottom = 50.0 +rect_min_size = Vector2( 150, 50 ) +size_flags_horizontal = 3 +size_flags_vertical = 3 +theme = ExtResource( 3 ) +text = "Singleplayer" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Container" type="CenterContainer" parent="VBoxContainer"] +margin_top = 54.0 +margin_right = 984.0 +margin_bottom = 560.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/Container"] +margin_left = 282.0 +margin_top = 196.0 +margin_right = 702.0 +margin_bottom = 310.0 + +[node name="Label" type="Label" parent="VBoxContainer/Container/VBoxContainer"] +margin_right = 420.0 +margin_bottom = 89.0 +custom_fonts/font = SubResource( 1 ) +text = "Wizard Farts" + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/Container/VBoxContainer"] +margin_top = 93.0 +margin_right = 420.0 +margin_bottom = 114.0 +alignment = 1 + +[node name="Label" type="Label" parent="VBoxContainer/Container/VBoxContainer/HBoxContainer"] +margin_left = 104.0 +margin_right = 248.0 +margin_bottom = 21.0 +text = "made with love at " + +[node name="LinkButton" type="LinkButton" parent="VBoxContainer/Container/VBoxContainer/HBoxContainer"] +margin_left = 252.0 +margin_right = 316.0 +margin_bottom = 21.0 +text = "lyte.dev" + +[connection signal="pressed" from="VBoxContainer/HBoxContainer/quit" to="." method="_on_JoinLobbyButton_pressed"] +[connection signal="pressed" from="VBoxContainer/HBoxContainer/multiplayer" to="." method="_on_CreateLobbyButton_pressed"] +[connection signal="pressed" from="VBoxContainer/HBoxContainer/Singleplayer" to="." method="_on_Singleplayer_pressed"] +[connection signal="pressed" from="VBoxContainer/Container/VBoxContainer/HBoxContainer/LinkButton" to="." method="_on_LinkButton_pressed"] diff --git a/multiplayer.gd b/multiplayer.gd index ef9b612..f251d96 100644 --- a/multiplayer.gd +++ b/multiplayer.gd @@ -4,7 +4,12 @@ extends Control onready var is_loaded = false +onready var lobbies = $v/body/lobbies +onready var join_button = $v/head/join +onready var lobbies_label = $v/subhead/label + func _ready(): + join_button.disabled = true Global.client.signaller.connect("lobby_new", self, "_lobby_new") Global.client.signaller.connect("lobby_delete", self, "_lobby_delete") Global.client.signaller.connect("lobby_joined", self, "_lobby_joined") @@ -12,8 +17,9 @@ func _ready(): Global.client.signaller.connect("websocket_disconnected", self, "_signaller_disconnected") Global.client.signaller.request_lobby_list() -func _draw(): - $join.disabled = len($lobbies.get_selected_items()) <= 1 + if Global.create_lobby: + Global.create_lobby = false + Global.client.signaller.create_lobby() func _signaller_disconnected(): Global.main_menu() @@ -31,24 +37,33 @@ func _on_create_lobby_pressed(): Global.client.signaller.create_lobby() func _on_join_pressed(): - var items = $lobbies.get_selected_items() + var items = lobbies.get_selected_items() if len(items) > 0: - Global.client.signaller.join_lobby($lobbies.get_item_metadata(items[0])["id"]) + Global.client.signaller.join_lobby(lobbies.get_item_metadata(items[0])["id"]) -func _lobby_new(lobbies): - for i in range(len(lobbies)): - var id = lobbies[i]["id"] - var name = lobbies[i]["name"] +func _lobby_new(new_lobbies): + for i in range(len(new_lobbies)): + var id = new_lobbies[i]["id"] + var name = new_lobbies[i]["name"] print("New Lobby ", id, name) # TODO: could keep an index of IDs and indexes - $lobbies.add_item("%s" % name) - $lobbies.set_item_metadata($lobbies.get_item_count() - 1, { "id": id }) + lobbies.add_item(name) + lobbies.set_item_metadata(lobbies.get_item_count() - 1, { "id": id }) + + if Global.join_first_available_lobby: + Global.join_first_available_lobby = false + Global.client.signaller.join_lobby(id) + lobbies_label.text = "Active Lobbies: %d" % lobbies.get_item_count() func _lobby_delete(id): - for i in range($lobbies.get_item_count()): - if id == $lobbies.get_item_metadata(i)["id"]: - $lobbies.remove_item(i) + for i in range(lobbies.get_item_count()): + if id == lobbies.get_item_metadata(i)["id"]: + lobbies.remove_item(i) return + lobbies_label.text = "Active Lobbies: %d" % lobbies.get_item_count() -func _on_lobbies_item_activated(index): +func _on_lobbies_item_activated(_index): _on_join_pressed() + +func _on_lobbies_item_selected(_index): + join_button.disabled = false diff --git a/multiplayer.tscn b/multiplayer.tscn index f066fa4..477bbe2 100644 --- a/multiplayer.tscn +++ b/multiplayer.tscn @@ -1,58 +1,106 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://multiplayer.gd" type="Script" id=1] +[ext_resource path="res://theme.tres" type="Theme" id=2] -[node name="Control" type="Control"] +[node name="Control" type="MarginContainer"] anchor_right = 1.0 anchor_bottom = 1.0 +margin_left = 20.0 +margin_top = 20.0 +margin_right = -20.0 +margin_bottom = -20.0 +theme = ExtResource( 2 ) script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": false } -[node name="back" type="Button" parent="."] -margin_left = 565.0 -margin_top = 214.0 -margin_right = 824.0 -margin_bottom = 289.0 +[node name="v" type="VBoxContainer" parent="."] +margin_right = 984.0 +margin_bottom = 560.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="head" type="HBoxContainer" parent="v"] +margin_right = 984.0 +margin_bottom = 50.0 +grow_horizontal = 2 +grow_vertical = 2 +alignment = 1 +__meta__ = { +"_edit_group_": true, +"_edit_lock_": true +} + +[node name="back" type="Button" parent="v/head"] +margin_right = 325.0 +margin_bottom = 50.0 +grow_horizontal = 2 +grow_vertical = 2 +rect_min_size = Vector2( 150, 50 ) +size_flags_horizontal = 3 +size_flags_vertical = 3 text = "Back" __meta__ = { "_edit_use_anchors_": false } -[node name="create_lobby" type="Button" parent="."] -margin_left = 12.0 -margin_top = 11.0 -margin_right = 550.0 -margin_bottom = 86.0 +[node name="create_lobby" type="Button" parent="v/head"] +margin_left = 329.0 +margin_right = 654.0 +margin_bottom = 50.0 +rect_min_size = Vector2( 150, 50 ) +size_flags_horizontal = 3 +size_flags_vertical = 3 text = "Create Lobby" __meta__ = { "_edit_use_anchors_": false } -[node name="join" type="Button" parent="."] -margin_left = 563.0 -margin_top = 13.0 -margin_right = 963.0 -margin_bottom = 88.0 +[node name="join" type="Button" parent="v/head"] +margin_left = 658.0 +margin_right = 984.0 +margin_bottom = 50.0 +rect_min_size = Vector2( 150, 50 ) +size_flags_horizontal = 3 +size_flags_vertical = 3 text = "Join" __meta__ = { "_edit_use_anchors_": false } -[node name="lobbies" type="ItemList" parent="."] -anchor_right = 0.121 -anchor_bottom = 0.217 -margin_left = 18.0 -margin_top = 105.0 -margin_right = 416.096 -margin_bottom = 267.8 +[node name="subhead" type="HBoxContainer" parent="v"] +margin_top = 54.0 +margin_right = 984.0 +margin_bottom = 75.0 + +[node name="label" type="Label" parent="v/subhead"] +margin_right = 136.0 +margin_bottom = 21.0 +text = "Active Lobbies: 0" + +[node name="body" type="ScrollContainer" parent="v"] +margin_top = 79.0 +margin_right = 984.0 +margin_bottom = 560.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="lobbies" type="ItemList" parent="v/body"] +margin_right = 984.0 +margin_bottom = 481.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 same_column_width = true __meta__ = { "_edit_use_anchors_": false } -[connection signal="pressed" from="back" to="." method="_on_back_pressed"] -[connection signal="pressed" from="create_lobby" to="." method="_on_create_lobby_pressed"] -[connection signal="pressed" from="join" to="." method="_on_join_pressed"] -[connection signal="item_activated" from="lobbies" to="." method="_on_lobbies_item_activated"] +[connection signal="pressed" from="v/head/back" to="." method="_on_back_pressed"] +[connection signal="pressed" from="v/head/create_lobby" to="." method="_on_create_lobby_pressed"] +[connection signal="pressed" from="v/head/join" to="." method="_on_join_pressed"] +[connection signal="item_activated" from="v/body/lobbies" to="." method="_on_lobbies_item_activated"] +[connection signal="item_selected" from="v/body/lobbies" to="." method="_on_lobbies_item_selected"] +[connection signal="nothing_selected" from="v/body/lobbies" to="." method="_on_lobbies_nothing_selected"] diff --git a/project.godot b/project.godot index 6766717..5bbe40c 100644 --- a/project.godot +++ b/project.godot @@ -35,4 +35,5 @@ common/enable_pause_aware_picking=true quality/driver/driver_name="GLES2" vram_compression/import_etc=true vram_compression/import_etc2=false +environment/default_clear_color=Color( 0, 0, 0, 1 ) environment/default_environment="res://default_env.tres" diff --git a/server.ts b/server.ts index a7d8fc1..15505c7 100644 --- a/server.ts +++ b/server.ts @@ -218,7 +218,9 @@ function onMessage(client: Client, ev: MessageEvent) { // TODO: log who from? const msg = ev.data.trim(); console.log("Client Message Received", msg); - if (msg === "init") client.send(buildMessage("your_id", client.id)); + if (msg === "init") { + client.send(buildMessage("init", { id: client.id, name: client.name })); + } if (msg === "lobby_create") client.lobbyCreate(); if (msg === "lobby_leave") client.lobbyLeave(); if (msg === "request_lobby_list") client.lobbyList(); diff --git a/signaller_client.gd b/signaller_client.gd index a5c6d0d..f67a735 100644 --- a/signaller_client.gd +++ b/signaller_client.gd @@ -96,7 +96,7 @@ func _parse_msg(): func handle_message(data: Dictionary): match data["type"]: "your_id": - client_id = data["data"] + client_id = data["data"]["id"] emit_signal("client_id_set", client_id) "your_peer_id": peer_id = int(data["data"]) diff --git a/theme.tres b/theme.tres new file mode 100644 index 0000000..9fd7b85 --- /dev/null +++ b/theme.tres @@ -0,0 +1,6 @@ +[gd_resource type="Theme" load_steps=2 format=2] + +[ext_resource path="res://iosevkalyte.tres" type="DynamicFont" id=1] + +[resource] +default_font = ExtResource( 1 )