implemented nicknames
This commit is contained in:
parent
1b6d45a001
commit
b49b910382
|
@ -24,6 +24,11 @@ transform = Transform3D(0.368235, 0, 0, 0, -4.37934e-08, -0.354994, 0, 1.00188,
|
|||
mesh = SubResource("CylinderMesh_hyaut")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="Nickname" type="Label3D" parent="CharacterBody3D/Head"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.24983, 0)
|
||||
billboard = 1
|
||||
text = "Unnamed"
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="CharacterBody3D"]
|
||||
shape = SubResource("CapsuleShape3D_yyp7b")
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
extends Button
|
||||
|
||||
@onready var button = $"."
|
||||
@onready var nick_input: TextEdit = $"../Nickname"
|
||||
|
||||
func _ready():
|
||||
button.text = "Set"
|
||||
button.pressed.connect(self._button_pressed)
|
||||
|
||||
func _button_pressed():
|
||||
var nickname = nick_input.text
|
||||
print("Setting nickname to " + str(nickname))
|
||||
GameData.client_settings["nickname"] = nickname
|
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://cjlgs86ey1u1o"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://cjlgs86ey1u1o"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/ConnectButton.gd" id="1_oqnod"]
|
||||
[ext_resource type="Script" path="res://scenes/Nickname.gd" id="2_c3c3b"]
|
||||
|
||||
[node name="Menu" type="Control"]
|
||||
layout_mode = 3
|
||||
|
@ -10,30 +11,64 @@ anchor_bottom = 1.0
|
|||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Connect" type="Button" parent="."]
|
||||
layout_mode = 0
|
||||
[node name="ConnectMenu" type="Control" parent="."]
|
||||
anchors_preset = 0
|
||||
offset_left = 24.0
|
||||
offset_top = 584.0
|
||||
offset_right = 196.0
|
||||
offset_bottom = 634.0
|
||||
offset_top = 496.0
|
||||
offset_right = 200.0
|
||||
offset_bottom = 640.0
|
||||
|
||||
[node name="IP" type="TextEdit" parent="ConnectMenu"]
|
||||
layout_mode = 2
|
||||
offset_left = 1.0
|
||||
offset_right = 170.0
|
||||
offset_bottom = 39.0
|
||||
text = "127.0.0.1"
|
||||
placeholder_text = "IP Address"
|
||||
|
||||
[node name="Port" type="TextEdit" parent="ConnectMenu"]
|
||||
layout_mode = 2
|
||||
offset_top = 43.0
|
||||
offset_right = 171.0
|
||||
offset_bottom = 80.0
|
||||
text = "2390"
|
||||
placeholder_text = "Port"
|
||||
|
||||
[node name="Connect" type="Button" parent="ConnectMenu"]
|
||||
layout_mode = 2
|
||||
offset_top = 88.0
|
||||
offset_right = 172.0
|
||||
offset_bottom = 138.0
|
||||
pivot_offset = Vector2(88, 24)
|
||||
text = "Connect"
|
||||
script = ExtResource("1_oqnod")
|
||||
|
||||
[node name="IP" type="TextEdit" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 25.0
|
||||
offset_top = 496.0
|
||||
offset_right = 194.0
|
||||
offset_bottom = 535.0
|
||||
text = "127.0.0.1"
|
||||
placeholder_text = "IP Address"
|
||||
[node name="PlayerMenu" type="Control" parent="."]
|
||||
anchors_preset = 0
|
||||
offset_right = 256.0
|
||||
offset_bottom = 128.0
|
||||
|
||||
[node name="Port" type="TextEdit" parent="."]
|
||||
[node name="Nickname" type="TextEdit" parent="PlayerMenu"]
|
||||
layout_mode = 0
|
||||
offset_left = 24.0
|
||||
offset_top = 539.0
|
||||
offset_right = 195.0
|
||||
offset_bottom = 576.0
|
||||
text = "2390"
|
||||
placeholder_text = "Port"
|
||||
offset_top = 56.0
|
||||
offset_right = 224.0
|
||||
offset_bottom = 96.0
|
||||
placeholder_text = "Unnamed"
|
||||
|
||||
[node name="Label" type="Label" parent="PlayerMenu"]
|
||||
layout_mode = 0
|
||||
offset_left = 48.0
|
||||
offset_top = 24.0
|
||||
offset_right = 205.0
|
||||
offset_bottom = 47.0
|
||||
text = "Set player nickname"
|
||||
|
||||
[node name="Set" type="Button" parent="PlayerMenu"]
|
||||
layout_mode = 0
|
||||
offset_left = 104.0
|
||||
offset_top = 104.0
|
||||
offset_right = 152.0
|
||||
offset_bottom = 120.0
|
||||
text = "Set"
|
||||
script = ExtResource("2_c3c3b")
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
extends Node
|
||||
#
|
||||
# синглтоны добавляют ноды относительно себя, нужно явно указывать расположение ноды для добавления
|
||||
#
|
||||
#var player_script := load("res://scripts/Player.gd")
|
||||
var player_script := preload("res://scripts/Player.gd")
|
||||
|
||||
var server_map
|
||||
|
@ -66,8 +62,14 @@ func _Peer_Connected(client_id):
|
|||
clients[str(client_id)]["internal_id"] = internal_id
|
||||
|
||||
server_map.add_child(puppet)
|
||||
|
||||
@rpc("any_peer", "reliable", "call_remote")
|
||||
func client_ready(client_id):
|
||||
var client = clients[str(client_id)]
|
||||
var internal_id = client["internal_id"]
|
||||
print("Spawning new puppet: " + str(clients[str(client_id)]))
|
||||
send_everyone_except(client_id, ["spawn_puppet", clients[str(client_id)]])
|
||||
|
||||
send_everyone_except(client_id, ["spawn_puppet", internal_id])
|
||||
|
||||
func _Peer_Disconnected(client_id):
|
||||
print("User " + str(client_id) + " has disconnected")
|
||||
|
@ -98,7 +100,7 @@ func sync_client(client_id, position, rotation):
|
|||
func get_client_list(client_id):
|
||||
for current_client_id in clients.keys():
|
||||
if (current_client_id == str(client_id)): continue
|
||||
rpc_id(client_id, "spawn_puppet", clients[str(current_client_id)]["internal_id"])
|
||||
rpc_id(client_id, "spawn_puppet", clients[str(current_client_id)])
|
||||
|
||||
@rpc ("any_peer", "call_remote", "reliable")
|
||||
func get_server_settings(client_id):
|
||||
|
@ -107,12 +109,9 @@ func get_server_settings(client_id):
|
|||
var internal_id = client["internal_id"]
|
||||
server_map.get_node("player" + str(internal_id)).find_child("CharacterBody3D").set_game_settings.rpc_id(int(client_id), settings["game"])
|
||||
|
||||
#@rpc ("any_peer", "call_remote", "unreliable")
|
||||
#func rotate_camera_client(client_id, head_y, camera_x):
|
||||
#var client = clients[str(client_id)]
|
||||
#var internal_id = client["internal_id"]
|
||||
#client["rotation"] = {"x": camera_x, "y": head_y}
|
||||
#send_everyone_except(client_id, [server_map.get_node("player" + str(internal_id)).find_child("CharacterBody3D").rotate_camera_puppet, client["rotation"] , internal_id])
|
||||
@rpc ("any_peer", "call_remote", "reliable")
|
||||
func set_nickname(client_id, nickname):
|
||||
clients[str(client_id)]["nickname"] = nickname
|
||||
|
||||
##########################################CLIENT#######################
|
||||
|
||||
|
@ -127,11 +126,14 @@ func set_character_properties(p):
|
|||
player = p
|
||||
|
||||
@rpc("authority", "reliable", "call_remote")
|
||||
func spawn_puppet(internal_id):
|
||||
func spawn_puppet(properties):
|
||||
var puppet = player_model.instantiate()
|
||||
var internal_id = int(properties["internal_id"])
|
||||
puppet.find_child("CharacterBody3D").set_is_playable(false)
|
||||
puppet.find_child("CharacterBody3D").set_internal_id(internal_id)
|
||||
puppet.find_child("CharacterBody3D").set_player_name("player" + str(internal_id))
|
||||
print("Spawning puppet with properties: " + str(properties))
|
||||
puppet.find_child("CharacterBody3D").set_nickname(properties["nickname"])
|
||||
|
||||
puppet.name = "player" + str(internal_id)
|
||||
|
||||
|
@ -161,26 +163,27 @@ func _Connection_Failed():
|
|||
|
||||
func _Connection_Succseeded():
|
||||
print("Succsessfully connected to the server")
|
||||
|
||||
var nickname = GameData.client_settings["nickname"]
|
||||
rpc_id(1, "set_nickname", multiplayer.get_unique_id(), nickname)
|
||||
rpc_id(1, "get_character_properties", multiplayer.get_unique_id())
|
||||
|
||||
get_tree().change_scene_to_file("res://scenes/test_map.tscn")
|
||||
await get_tree().create_timer(1).timeout # костыль
|
||||
current_map_instance = get_tree().root.get_node("test_map")
|
||||
print(str(current_map_instance))
|
||||
#await get_tree().create_timer(0.2).timeout # костыль
|
||||
rpc_id(1, "get_client_list", multiplayer.get_unique_id())
|
||||
|
||||
var player_node = player_model.instantiate()
|
||||
player_node.find_child("CharacterBody3D").set_is_playable(true)
|
||||
player_node.find_child("CharacterBody3D").set_internal_id(player["internal_id"])
|
||||
player_node.find_child("CharacterBody3D").set_player_name("player" + str(player["internal_id"]))
|
||||
player_node.find_child("CharacterBody3D").set_nickname(nickname)
|
||||
|
||||
current_map_instance.add_child(player_node)
|
||||
await get_tree().create_timer(0.05).timeout # костыль
|
||||
rpc_id(1, "get_server_settings", multiplayer.get_unique_id())
|
||||
|
||||
rpc_id(1, "client_ready", multiplayer.get_unique_id())
|
||||
|
||||
|
||||
func _Server_Disconnected():
|
||||
print("Server has disconnected")
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
|
|
|
@ -22,7 +22,8 @@ var properties = {
|
|||
HACK = 1.0,
|
||||
class_type = 0,
|
||||
is_playable = false,
|
||||
internal_id = 0
|
||||
internal_id = 0,
|
||||
nickname = "Unnamed"
|
||||
}
|
||||
|
||||
var speed = 0
|
||||
|
@ -41,6 +42,10 @@ var client_settings
|
|||
func set_player_name (n):
|
||||
$"..".name = n
|
||||
|
||||
func set_nickname (n):
|
||||
properties["nickname"] = n
|
||||
GameData.client_settings["nickname"] = n
|
||||
|
||||
func set_internal_id(id):
|
||||
print("Setting internal_id to " + str(id))
|
||||
properties["internal_id"] = id
|
||||
|
@ -49,10 +54,12 @@ func set_is_playable(value):
|
|||
properties["is_playable"] = value
|
||||
|
||||
func _ready():
|
||||
$"Head/Nickname".text = properties["nickname"]
|
||||
if (!properties["is_playable"]): return
|
||||
camera.make_current()
|
||||
playerCharacterBody.up_direction = Vector3.UP;
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
|
||||
func _unhandled_input(event):
|
||||
if (!properties["is_playable"]): return
|
||||
|
@ -60,7 +67,6 @@ func _unhandled_input(event):
|
|||
head.rotate_y(-event.relative.x * SENSETIVITY)
|
||||
camera.rotate_x(-event.relative.y * SENSETIVITY)
|
||||
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-50), deg_to_rad(60))
|
||||
#Networking.rotate_camera_client.rpc_id(1, multiplayer.get_unique_id(), head.rotation.y, camera.rotation.x)
|
||||
|
||||
func _physics_process(delta):
|
||||
if (!properties["is_playable"]): return
|
||||
|
@ -91,7 +97,7 @@ func _physics_process(delta):
|
|||
velocity.z = lerp(velocity.z, direction.z * speed, delta)
|
||||
move_and_slide()
|
||||
if (!multiplayer.is_server()):
|
||||
Networking.sync_client.rpc_id(1, multiplayer.get_unique_id(), $".".position, { "y": head.rotation.y, "x": camera.rotation.x})
|
||||
Networking.sync_client.rpc_id(1, multiplayer.get_unique_id(), $".".position, {"y": head.rotation.y, "x": camera.rotation.x})
|
||||
#print("I am " + $"..".name +", belonging of " + str(multiplayer.get_unique_id()) + ", with internal ID: " + str(properties["internal_id"]))
|
||||
|
||||
@rpc ("authority", "call_remote", "unreliable")
|
||||
|
@ -110,8 +116,3 @@ func set_game_settings(s):
|
|||
walk = game_settings["moving"]["walk"]
|
||||
run = game_settings["moving"]["run"]
|
||||
jump = game_settings["moving"]["jump"]
|
||||
|
||||
#@rpc("authority", "call_remote", "unreliable")
|
||||
#func rotate_camera_puppet(rot, i_id):
|
||||
#if (i_id == properties["internal_id"]):
|
||||
#
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
|
||||
"nickname": "Unnamed"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue