Nicknames
This commit is contained in:
parent
337ba22bd3
commit
e269127a25
7 changed files with 134 additions and 14 deletions
|
|
@ -13,26 +13,45 @@ script = ExtResource("1_l6cm7")
|
|||
metadata/_edit_lock_ = true
|
||||
|
||||
[node name="MainMenu" type="PanelContainer" parent="."]
|
||||
visible = false
|
||||
custom_minimum_size = Vector2(256, 0)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MainMenu"]
|
||||
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
|
||||
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"
|
||||
|
||||
[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
|
||||
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
|
||||
placeholder_text = "ip"
|
||||
|
||||
[node name="ExitButton" type="Button" parent="MainMenu/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Выйти из игры"
|
||||
|
||||
[node name="Lobby" type="PanelContainer" parent="."]
|
||||
visible = false
|
||||
custom_minimum_size = Vector2(256, 256)
|
||||
layout_mode = 2
|
||||
|
||||
|
|
@ -115,8 +134,11 @@ horizontal_scroll_mode = 0
|
|||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[connection signal="pressed" from="MainMenu/VBoxContainer/HostButton" to="." method="_on_host_button_pressed"]
|
||||
[connection signal="pressed" from="MainMenu/VBoxContainer/ConnectButton" to="." method="_on_connect_button_pressed"]
|
||||
[connection signal="text_changed" from="MainMenu/VBoxContainer/NicknameEdit" to="." method="_on_nickname_edit_text_changed"]
|
||||
[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/StartButton" to="." method="_on_start_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()
|
||||
$MainMenu.show()
|
||||
%NicknameEdit.text = ClientSettings.NICKNAME
|
||||
|
||||
func _on_leave_button_pressed() -> void:
|
||||
Lobby.leave()
|
||||
|
|
@ -41,7 +42,7 @@ func _on_host_button_pressed() -> void:
|
|||
$Lobby.show()
|
||||
|
||||
func _on_connect_button_pressed() -> void:
|
||||
var ip = $MainMenu/VBoxContainer/LineEdit.text
|
||||
var ip = %IpEdit.text
|
||||
if ip == "":
|
||||
ip = "localhost"
|
||||
var joined = Lobby.join(ip)
|
||||
|
|
@ -75,18 +76,18 @@ func on_player_switched_team():
|
|||
child.queue_free()
|
||||
|
||||
for attacker in Lobby.attack_team:
|
||||
var label = Label.new()
|
||||
label.text = str(attacker)
|
||||
var label = PlayerLabel.new()
|
||||
label.id = attacker
|
||||
%AttackTeam.add_child(label)
|
||||
|
||||
for defender in Lobby.defence_team:
|
||||
var label = Label.new()
|
||||
label.text = str(defender)
|
||||
var label = PlayerLabel.new()
|
||||
label.id = defender
|
||||
%DefenceTeam.add_child(label)
|
||||
|
||||
for spectator in Lobby.specators_team:
|
||||
var label = Label.new()
|
||||
label.text = str(spectator)
|
||||
var label = PlayerLabel.new()
|
||||
label.id = spectator
|
||||
%SpectatorsTeam.add_child(label)
|
||||
|
||||
func _on_join_attack_button_pressed() -> void:
|
||||
|
|
@ -108,3 +109,14 @@ func on_session_ended() -> void:
|
|||
else:
|
||||
$MainMenu.show()
|
||||
$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
|
||||
Loading…
Add table
Add a link
Reference in a new issue