Nicknames
This commit is contained in:
parent
337ba22bd3
commit
e269127a25
7 changed files with 134 additions and 14 deletions
|
|
@ -1,7 +1,49 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
const PLAYER_CFG = "user://client_settings"
|
||||||
|
|
||||||
|
var NICKNAME: StringName = "MyNameIs"
|
||||||
|
|
||||||
var SENSITIVITY: float = 0.004
|
var SENSITIVITY: float = 0.004
|
||||||
var TOGGLE_CROUCH: bool = false
|
var TOGGLE_CROUCH: bool = false
|
||||||
var TOGGLE_SCOPE: bool = false
|
var TOGGLE_SCOPE: bool = false
|
||||||
var TOGGLE_WALK: bool = false
|
var TOGGLE_WALK: bool = false
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
load_settings()
|
||||||
|
multiplayer.connected_to_server.connect(send_client_data)
|
||||||
|
|
||||||
|
func _exit_tree() -> void:
|
||||||
|
save_settings()
|
||||||
|
|
||||||
|
func send_client_data() -> void:
|
||||||
|
var data = {}
|
||||||
|
data["nick"] = NICKNAME
|
||||||
|
|
||||||
|
if multiplayer.is_server():
|
||||||
|
Lobby.recieve_client_data(data)
|
||||||
|
else:
|
||||||
|
Lobby.recieve_client_data.rpc_id(1,data)
|
||||||
|
|
||||||
|
func save_settings() -> void:
|
||||||
|
var file = FileAccess.open(PLAYER_CFG,FileAccess.WRITE)
|
||||||
|
|
||||||
|
file.store_line(NICKNAME)
|
||||||
|
file.store_line(str(SENSITIVITY))
|
||||||
|
|
||||||
|
var compacted_toggles = 1 * int(TOGGLE_CROUCH) | 2 * int(TOGGLE_SCOPE) | 4 * int(TOGGLE_WALK)
|
||||||
|
file.store_line(str(compacted_toggles))
|
||||||
|
|
||||||
|
func load_settings() -> void:
|
||||||
|
var file = FileAccess.open(PLAYER_CFG,FileAccess.READ)
|
||||||
|
|
||||||
|
if file == null:
|
||||||
|
return
|
||||||
|
|
||||||
|
NICKNAME = file.get_line()
|
||||||
|
SENSITIVITY = float(file.get_line())
|
||||||
|
|
||||||
|
var compacted_toggles = int(file.get_line())
|
||||||
|
TOGGLE_CROUCH = compacted_toggles & 1
|
||||||
|
TOGGLE_SCOPE = compacted_toggles & 2
|
||||||
|
TOGGLE_WALK = compacted_toggles & 4
|
||||||
|
|
|
||||||
|
|
@ -13,26 +13,45 @@ script = ExtResource("1_l6cm7")
|
||||||
metadata/_edit_lock_ = true
|
metadata/_edit_lock_ = true
|
||||||
|
|
||||||
[node name="MainMenu" type="PanelContainer" parent="."]
|
[node name="MainMenu" type="PanelContainer" parent="."]
|
||||||
visible = false
|
|
||||||
custom_minimum_size = Vector2(256, 0)
|
custom_minimum_size = Vector2(256, 0)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="VBoxContainer" type="VBoxContainer" parent="MainMenu"]
|
[node name="VBoxContainer" type="VBoxContainer" parent="MainMenu"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="HostButton" type="Button" parent="MainMenu/VBoxContainer"]
|
[node name="NicknameEdit" type="LineEdit" parent="MainMenu/VBoxContainer"]
|
||||||
|
unique_name_in_owner = true
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
placeholder_text = "Nickname"
|
||||||
|
max_length = 16
|
||||||
|
|
||||||
|
[node name="HBoxContainer" type="HBoxContainer" parent="MainMenu/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="HostButton" type="Button" parent="MainMenu/VBoxContainer/HBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
text = "HOST"
|
text = "HOST"
|
||||||
|
|
||||||
[node name="ConnectButton" type="Button" parent="MainMenu/VBoxContainer"]
|
[node name="VBoxContainer" type="VBoxContainer" parent="MainMenu/VBoxContainer/HBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="ConnectButton" type="Button" parent="MainMenu/VBoxContainer/HBoxContainer/VBoxContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "CONNECT"
|
text = "CONNECT"
|
||||||
|
|
||||||
[node name="LineEdit" type="LineEdit" parent="MainMenu/VBoxContainer"]
|
[node name="IpEdit" type="LineEdit" parent="MainMenu/VBoxContainer/HBoxContainer/VBoxContainer"]
|
||||||
|
unique_name_in_owner = true
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
placeholder_text = "ip"
|
placeholder_text = "ip"
|
||||||
|
|
||||||
|
[node name="ExitButton" type="Button" parent="MainMenu/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Выйти из игры"
|
||||||
|
|
||||||
[node name="Lobby" type="PanelContainer" parent="."]
|
[node name="Lobby" type="PanelContainer" parent="."]
|
||||||
|
visible = false
|
||||||
custom_minimum_size = Vector2(256, 256)
|
custom_minimum_size = Vector2(256, 256)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
|
|
@ -115,8 +134,11 @@ horizontal_scroll_mode = 0
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[connection signal="pressed" from="MainMenu/VBoxContainer/HostButton" to="." method="_on_host_button_pressed"]
|
[connection signal="text_changed" from="MainMenu/VBoxContainer/NicknameEdit" to="." method="_on_nickname_edit_text_changed"]
|
||||||
[connection signal="pressed" from="MainMenu/VBoxContainer/ConnectButton" to="." method="_on_connect_button_pressed"]
|
[connection signal="text_submitted" from="MainMenu/VBoxContainer/NicknameEdit" to="." method="_on_nickname_edit_text_submitted"]
|
||||||
|
[connection signal="pressed" from="MainMenu/VBoxContainer/HBoxContainer/HostButton" to="." method="_on_host_button_pressed"]
|
||||||
|
[connection signal="pressed" from="MainMenu/VBoxContainer/HBoxContainer/VBoxContainer/ConnectButton" to="." method="_on_connect_button_pressed"]
|
||||||
|
[connection signal="pressed" from="MainMenu/VBoxContainer/ExitButton" to="." method="_on_exit_button_pressed"]
|
||||||
[connection signal="pressed" from="Lobby/HBoxContainer/ClientMenu/Buttons/LeaveButton" to="." method="_on_leave_button_pressed"]
|
[connection signal="pressed" from="Lobby/HBoxContainer/ClientMenu/Buttons/LeaveButton" to="." method="_on_leave_button_pressed"]
|
||||||
[connection signal="pressed" from="Lobby/HBoxContainer/ClientMenu/Buttons/StartButton" to="." method="_on_start_button_pressed"]
|
[connection signal="pressed" from="Lobby/HBoxContainer/ClientMenu/Buttons/StartButton" to="." method="_on_start_button_pressed"]
|
||||||
[connection signal="pressed" from="Lobby/HBoxContainer/ClientMenu/Buttons/JoinAttackButton" to="." method="_on_join_attack_button_pressed"]
|
[connection signal="pressed" from="Lobby/HBoxContainer/ClientMenu/Buttons/JoinAttackButton" to="." method="_on_join_attack_button_pressed"]
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ func _ready() -> void:
|
||||||
|
|
||||||
$Lobby.hide()
|
$Lobby.hide()
|
||||||
$MainMenu.show()
|
$MainMenu.show()
|
||||||
|
%NicknameEdit.text = ClientSettings.NICKNAME
|
||||||
|
|
||||||
func _on_leave_button_pressed() -> void:
|
func _on_leave_button_pressed() -> void:
|
||||||
Lobby.leave()
|
Lobby.leave()
|
||||||
|
|
@ -41,7 +42,7 @@ func _on_host_button_pressed() -> void:
|
||||||
$Lobby.show()
|
$Lobby.show()
|
||||||
|
|
||||||
func _on_connect_button_pressed() -> void:
|
func _on_connect_button_pressed() -> void:
|
||||||
var ip = $MainMenu/VBoxContainer/LineEdit.text
|
var ip = %IpEdit.text
|
||||||
if ip == "":
|
if ip == "":
|
||||||
ip = "localhost"
|
ip = "localhost"
|
||||||
var joined = Lobby.join(ip)
|
var joined = Lobby.join(ip)
|
||||||
|
|
@ -75,18 +76,18 @@ func on_player_switched_team():
|
||||||
child.queue_free()
|
child.queue_free()
|
||||||
|
|
||||||
for attacker in Lobby.attack_team:
|
for attacker in Lobby.attack_team:
|
||||||
var label = Label.new()
|
var label = PlayerLabel.new()
|
||||||
label.text = str(attacker)
|
label.id = attacker
|
||||||
%AttackTeam.add_child(label)
|
%AttackTeam.add_child(label)
|
||||||
|
|
||||||
for defender in Lobby.defence_team:
|
for defender in Lobby.defence_team:
|
||||||
var label = Label.new()
|
var label = PlayerLabel.new()
|
||||||
label.text = str(defender)
|
label.id = defender
|
||||||
%DefenceTeam.add_child(label)
|
%DefenceTeam.add_child(label)
|
||||||
|
|
||||||
for spectator in Lobby.specators_team:
|
for spectator in Lobby.specators_team:
|
||||||
var label = Label.new()
|
var label = PlayerLabel.new()
|
||||||
label.text = str(spectator)
|
label.id = spectator
|
||||||
%SpectatorsTeam.add_child(label)
|
%SpectatorsTeam.add_child(label)
|
||||||
|
|
||||||
func _on_join_attack_button_pressed() -> void:
|
func _on_join_attack_button_pressed() -> void:
|
||||||
|
|
@ -108,3 +109,14 @@ func on_session_ended() -> void:
|
||||||
else:
|
else:
|
||||||
$MainMenu.show()
|
$MainMenu.show()
|
||||||
$Lobby.hide()
|
$Lobby.hide()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_nickname_edit_text_changed(new_text: String) -> void:
|
||||||
|
if new_text == "":
|
||||||
|
ClientSettings.NICKNAME = "MyNameIs"
|
||||||
|
else:
|
||||||
|
ClientSettings.NICKNAME = new_text
|
||||||
|
|
||||||
|
|
||||||
|
func _on_exit_button_pressed() -> void:
|
||||||
|
get_tree().quit()
|
||||||
|
|
|
||||||
17
gui/main_menu/player_label.gd
Normal file
17
gui/main_menu/player_label.gd
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
extends Label
|
||||||
|
|
||||||
|
class_name PlayerLabel
|
||||||
|
|
||||||
|
var id: int
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
visibility_changed.connect(on_visibility_changed)
|
||||||
|
|
||||||
|
func _process(_delta: float) -> void:
|
||||||
|
if Lobby.client_nicknames.has(id):
|
||||||
|
text = Lobby.client_nicknames[id]
|
||||||
|
else:
|
||||||
|
text = str(id)
|
||||||
|
|
||||||
|
func on_visibility_changed() -> void:
|
||||||
|
process_mode = Node.PROCESS_MODE_DISABLED if visible else Node.ProcessMode.PROCESS_MODE_INHERIT
|
||||||
1
gui/main_menu/player_label.gd.uid
Normal file
1
gui/main_menu/player_label.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://b68vcn5mj1y8m
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
|
||||||
const MAX_PLAYERS: int = 10
|
const MAX_PLAYERS: int = 20
|
||||||
const PORT: int = 7777
|
const PORT: int = 7777
|
||||||
|
|
||||||
signal lobby_created
|
signal lobby_created
|
||||||
|
|
@ -15,6 +15,8 @@ var attack_team: Array[int] = []
|
||||||
var defence_team: Array[int] = []
|
var defence_team: Array[int] = []
|
||||||
var specators_team: Array[int] = []
|
var specators_team: Array[int] = []
|
||||||
|
|
||||||
|
var client_nicknames: Dictionary[int,StringName] = {}
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
multiplayer.peer_disconnected.connect(player_left)
|
multiplayer.peer_disconnected.connect(player_left)
|
||||||
multiplayer.server_disconnected.connect(server_disconnected)
|
multiplayer.server_disconnected.connect(server_disconnected)
|
||||||
|
|
@ -30,6 +32,9 @@ func player_left(id: int) -> void:
|
||||||
defence_team.erase(id)
|
defence_team.erase(id)
|
||||||
elif specators_team.has(id):
|
elif specators_team.has(id):
|
||||||
specators_team.erase(id)
|
specators_team.erase(id)
|
||||||
|
|
||||||
|
client_nicknames.erase(id)
|
||||||
|
|
||||||
update_teams_state.emit()
|
update_teams_state.emit()
|
||||||
|
|
||||||
func server_disconnected() -> void:
|
func server_disconnected() -> void:
|
||||||
|
|
@ -42,6 +47,7 @@ func host() -> void:
|
||||||
lobby_created.emit()
|
lobby_created.emit()
|
||||||
specators_team.append(multiplayer.get_unique_id())
|
specators_team.append(multiplayer.get_unique_id())
|
||||||
in_lobby = true
|
in_lobby = true
|
||||||
|
client_nicknames = {1 : ClientSettings.NICKNAME}
|
||||||
|
|
||||||
func join(ip: String) -> Error:
|
func join(ip: String) -> Error:
|
||||||
var peer: ENetMultiplayerPeer = ENetMultiplayerPeer.new()
|
var peer: ENetMultiplayerPeer = ENetMultiplayerPeer.new()
|
||||||
|
|
@ -67,7 +73,24 @@ func add_and_sync_peer(id: int) -> void:
|
||||||
specators_team.append(id)
|
specators_team.append(id)
|
||||||
update_teams_state.emit()
|
update_teams_state.emit()
|
||||||
set_teams.rpc_id(id,attack_team,defence_team,specators_team)
|
set_teams.rpc_id(id,attack_team,defence_team,specators_team)
|
||||||
|
|
||||||
|
@rpc("any_peer","call_local","reliable")
|
||||||
|
func recieve_client_data(data: Dictionary):
|
||||||
|
if multiplayer.is_server() == false:
|
||||||
|
return
|
||||||
|
var id = multiplayer.get_remote_sender_id()
|
||||||
|
|
||||||
|
var nickname: StringName = data["nick"].left(16)
|
||||||
|
client_nicknames[id] = nickname
|
||||||
|
|
||||||
|
sync_client_data.rpc(client_nicknames)
|
||||||
|
|
||||||
|
@rpc("authority","call_remote")
|
||||||
|
func sync_client_data(new_client_nicknames: Dictionary[int,StringName]):
|
||||||
|
if multiplayer.is_server() or multiplayer.get_remote_sender_id() != 1:
|
||||||
|
return
|
||||||
|
client_nicknames = new_client_nicknames
|
||||||
|
|
||||||
@rpc("authority","call_remote","reliable")
|
@rpc("authority","call_remote","reliable")
|
||||||
func set_teams(attack: Array[int],defence: Array[int],spectators: Array[int]):
|
func set_teams(attack: Array[int],defence: Array[int],spectators: Array[int]):
|
||||||
attack_team = attack
|
attack_team = attack
|
||||||
|
|
@ -145,6 +168,8 @@ func team_switch_notification(team: int) -> void:
|
||||||
update_teams_state.emit()
|
update_teams_state.emit()
|
||||||
set_teams.rpc(attack_team,defence_team,specators_team)
|
set_teams.rpc(attack_team,defence_team,specators_team)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func start_game() -> void:
|
func start_game() -> void:
|
||||||
if not multiplayer.is_server():
|
if not multiplayer.is_server():
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ config/name_localized={
|
||||||
"ru_RU": "Челимбало"
|
"ru_RU": "Челимбало"
|
||||||
}
|
}
|
||||||
run/main_scene="uid://dstie24qkbc86"
|
run/main_scene="uid://dstie24qkbc86"
|
||||||
|
config/use_custom_user_dir=true
|
||||||
config/features=PackedStringArray("4.5", "Forward Plus")
|
config/features=PackedStringArray("4.5", "Forward Plus")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue