Added player profile menu

remotes/1705725415861086127/tmp_refs/heads/main
Jan Heemstra 2021-09-25 00:07:15 +02:00
parent af8f33ec7b
commit d0cac2b0b7
11 changed files with 97 additions and 16 deletions

View File

@ -11,22 +11,23 @@ script = ExtResource( "2_wk4wj" )
[node name="MenuLineEdit" parent="." index="0" instance=ExtResource( "2_isg6p" )]
anchor_right = 0.0
anchor_bottom = 0.0
offset_right = 75.0
offset_right = 155.0
offset_bottom = 33.0
text = "IP"
label = "ip"
index = "ip"
[node name="Connect" parent="." index="1" instance=ExtResource( "2_n4o24" )]
anchor_right = 0.0
anchor_bottom = 0.0
offset_top = 37.0
offset_right = 75.0
offset_right = 155.0
offset_bottom = 66.0
text = "connect"
label = "connect"
[node name="Back" parent="." index="2"]
offset_top = 70.0
offset_right = 75.0
offset_right = 155.0
offset_bottom = 99.0
[connection signal="pressed" from="Connect" to="." method="connect_to_server"]

View File

@ -0,0 +1,7 @@
extends "res://Assets/UI/MenuData.gd"
func set_data(_data):
super.set_data(_data)
self.color = _data
print(_data)

View File

@ -0,0 +1,17 @@
[gd_scene load_steps=2 format=3 uid="uid://xuvp717ccvi5"]
[ext_resource type="Script" path="res://Assets/UI/MenuColor.gd" id="1_unj4b"]
[node name="MenuColor" type="ColorPickerButton"]
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 4.0
offset_top = 4.0
offset_right = 4.0
offset_bottom = 4.0
script = ExtResource( "1_unj4b" )
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="color_changed" from="." to="." method="set_data"]

View File

@ -1,3 +1,4 @@
@tool
extends Control
@export var label = "":
@ -8,8 +9,8 @@ extends Control
return label
func on_label_changed():
pass
self.text=label
# Called when the node enters the scene tree for the first time.
func _ready():
pass
on_label_changed()

View File

@ -1,10 +1,9 @@
extends "res://Assets/UI/MenuData.gd"
@export var text = "":
set(_text):
text = _text
$Label.text = _text
func set_data(_data):
super.set_data(_data)
if not $LineEdit.has_focus():
$LineEdit.text = _data
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func on_label_changed():
$Label.text = label

View File

@ -19,8 +19,9 @@ script = null
[node name="LineEdit" type="LineEdit" parent="."]
offset_left = 5.0
offset_right = 75.0
offset_right = 155.0
offset_bottom = 600.0
rect_min_size = Vector2(150, 0)
structured_text_bidi_override_options = []
caret_blink = true
caret_blink_speed = 0.5

View File

@ -24,9 +24,19 @@ offset_bottom = 62.0
text = "connect"
label = "connect"
[node name="Back" parent="." index="2"]
[node name="ProfileButton" parent="." index="2" instance=ExtResource( "2_oo0fl" )]
anchor_right = 0.0
anchor_bottom = 0.0
offset_top = 66.0
offset_right = 73.0
offset_bottom = 95.0
text = "profile"
label = "profile"
[node name="Back" parent="." index="3"]
offset_top = 99.0
offset_bottom = 128.0
[connection signal="pressed" from="HostButton" to="." method="host_button_pressed"]
[connection signal="pressed" from="ConnectButton" to="." method="open_menu" binds= ["res://Assets/UI/ConnectMenu.tscn"]]
[connection signal="pressed" from="ProfileButton" to="." method="open_menu" binds= ["res://Assets/UI/ProfileMenu.tscn"]]

View File

@ -0,0 +1,5 @@
extends "res://Assets/UI/Menu.gd"
func change_player_color(data):
if Main:
Main.change_player_color(data)

View File

@ -0,0 +1,34 @@
[gd_scene load_steps=5 format=3 uid="uid://cmbflogxdn20n"]
[ext_resource type="PackedScene" uid="uid://81ymy0o073e5" path="res://Assets/UI/Menu.tscn" id="1_faaua"]
[ext_resource type="Script" path="res://Assets/UI/ProfileMenu.gd" id="2_5v3ua"]
[ext_resource type="PackedScene" uid="uid://xptjyy2hwb77" path="res://Assets/UI/MenuLineEdit.tscn" id="2_ghv7j"]
[ext_resource type="PackedScene" uid="uid://xuvp717ccvi5" path="res://Assets/UI/MenuColor.tscn" id="4_1dm5b"]
[node name="ProfileMenu" instance=ExtResource( "1_faaua" )]
script = ExtResource( "2_5v3ua" )
[node name="UsernameLineEdit" parent="." index="0" instance=ExtResource( "2_ghv7j" )]
anchor_right = 0.0
anchor_bottom = 0.0
offset_right = 155.0
offset_bottom = 33.0
label = "username"
index = "username"
[node name="PlayerColor" parent="." index="1" instance=ExtResource( "4_1dm5b" )]
anchor_right = 0.0
anchor_bottom = 0.0
offset_left = 0.0
offset_top = 37.0
offset_right = 155.0
offset_bottom = 66.0
label = "player color"
index = "player color"
[node name="Back" parent="." index="2"]
offset_top = 70.0
offset_right = 155.0
offset_bottom = 99.0
[connection signal="data_changed" from="PlayerColor" to="." method="change_player_color"]

View File

@ -283,11 +283,13 @@ func create_player(pid: int, is_local:= false, respawn:= false) -> void:
if not respawn: # first spawn
new_info = PlayerInfo.new() # generate name, color etc
new_info.name = $GUI.settings["username"]
new_info.color = $GUI.settings["player color"]
else: # respawn
new_info = player_list.players[pid] # reuse previous name, color etc
new_info.health = 100 # give the respawned player full health
focus = GameFocus.GAME # make sure the player has no menu displayed when they respawn
player_list.set(pid, new_info)
# superfluous and harmful code that messes up player data:
@ -401,6 +403,9 @@ func _on_TextEdit_text_submitted(new_text):
push_local_player_info()
#chat_announcement("Player " + old_name + " is now known as " + new_name)
func change_player_color(color):
_on_ColorPickerButton_color_changed(color)
func _on_ColorPickerButton_color_changed(color):
player_list.players[get_tree().multiplayer.get_unique_id()].color = color
push_local_player_info()

View File

@ -48,6 +48,7 @@ __meta__ = {
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1)
[node name="NetworkTesting" type="VBoxContainer" parent="."]
visible = false
anchor_left = 1.0
anchor_right = 1.0
offset_left = -188.0