30 - simple TextChat

pull/43/head
Luiz de Oliveira 2021-04-10 11:40:17 -03:00
parent be06a9fc6e
commit 81e79dd0a5
11 changed files with 294 additions and 132 deletions

View File

@ -57,6 +57,7 @@ __meta__ = {
}
[node name="Health" parent="." instance=ExtResource( 2 )]
mouse_filter = 2
[node name="Weapon" type="MarginContainer" parent="."]
anchor_left = 1.0
@ -69,6 +70,7 @@ margin_right = -32.0
margin_bottom = -32.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
}
@ -90,6 +92,7 @@ margin_right = 116.0
margin_bottom = 64.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
alignment = 1
[node name="RoundsClips" type="Label" parent="Weapon/VBoxContainer"]
@ -123,6 +126,7 @@ margin_left = -511.401
margin_top = -301.225
margin_right = 512.599
margin_bottom = 298.775
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
}
@ -132,6 +136,7 @@ margin_left = 512.0
margin_top = 300.0
margin_right = 512.0
margin_bottom = 300.0
mouse_filter = 2
[node name="Line1" type="ColorRect" parent="Crosshair/CrosshairCenter"]
margin_left = 8.0
@ -139,6 +144,7 @@ margin_top = -1.0
margin_right = 20.0
margin_bottom = 1.0
rect_pivot_offset = Vector2( -8, 1 )
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
}
@ -150,6 +156,7 @@ margin_right = 20.0
margin_bottom = 1.0
rect_rotation = 90.0
rect_pivot_offset = Vector2( -8, 1 )
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
}
@ -161,6 +168,7 @@ margin_right = 20.0
margin_bottom = 1.0
rect_rotation = 180.0
rect_pivot_offset = Vector2( -8, 1 )
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
}
@ -172,6 +180,7 @@ margin_right = 20.0
margin_bottom = 1.0
rect_rotation = -90.0
rect_pivot_offset = Vector2( -8, 1 )
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
}
@ -182,6 +191,7 @@ margin_left = 512.0
margin_top = 300.0
margin_right = 512.0
margin_bottom = 300.0
mouse_filter = 2
script = ExtResource( 3 )
[node name="HitConfirmationSound" type="AudioStreamPlayer" parent="Crosshair/HitConfirmation"]
@ -198,6 +208,7 @@ margin_bottom = 1.0
rect_rotation = 45.3067
rect_scale = Vector2( 1, 0.5 )
rect_pivot_offset = Vector2( -8, 1 )
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
}
@ -210,6 +221,7 @@ margin_bottom = 1.0
rect_rotation = 135.307
rect_scale = Vector2( 1, 0.5 )
rect_pivot_offset = Vector2( -8, 1 )
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
}
@ -222,6 +234,7 @@ margin_bottom = 1.0
rect_rotation = 225.306
rect_scale = Vector2( 1, 0.5 )
rect_pivot_offset = Vector2( -8, 1 )
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
}
@ -234,6 +247,7 @@ margin_bottom = 1.0
rect_rotation = -44.6931
rect_scale = Vector2( 1, 0.5 )
rect_pivot_offset = Vector2( -8, 1 )
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
}

View File

@ -237,6 +237,7 @@ func walk(delta):
# Walk
walk_direction = Vector2()
if not get_tree().is_input_handled():
if Input.is_action_pressed("MoveForward"):
walk_direction.y -= 1
if Input.is_action_pressed("MoveBack"):
@ -357,7 +358,7 @@ sync func switch_to_next_weapon():
sync func switch_to_prev_weapon():
active_weapon = weapons.prev_weapon()
func _input(event):
func _unhandled_input(event):
if is_dead:
return

View File

@ -220,7 +220,7 @@ script = ExtResource( 8 )
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.53592, -0.0651628 )
[node name="Hand" type="Spatial" parent="Camera"]
transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.335, -0.392298, -0.559 )
transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.335, -0.390282, -0.559 )
[node name="WeaponBobAnimationTree" type="AnimationTree" parent="Camera/Hand"]
tree_root = SubResource( 12 )
@ -356,3 +356,4 @@ stream_paused = true
[node name="HUD" parent="." instance=ExtResource( 7 )]
visible = false
mouse_filter = 2

View File

@ -0,0 +1,63 @@
extends Control
signal typing_toggled(is_typing)
const TOGGLE_KEY = KEY_ENTER
const MESSAGE_FORMAT = "%s: %s"
sync var chat_text: = "" setget set_chat_text
var player_name: = "Unknown"
onready var line_edit: LineEdit = $LineEdit
onready var chat_history: RichTextLabel = $Panel/ChatHistory
func _input(event: InputEvent) -> void:
pass
func _unhandled_input(event: InputEvent) -> void:
if is_typing():
get_tree().set_input_as_handled()
if event.is_action_pressed("ToggleChatWrite"):
toggle_typing()
func toggle() -> bool:
visible = not visible
if not visible:
$LineEdit.hide()
return visible
func toggle_typing() -> bool:
$LineEdit.visible = not $LineEdit.visible and visible
return $LineEdit.visible
func is_typing() -> bool:
return $LineEdit.visible
func _on_LineEdit_text_entered(new_text: String) -> void:
toggle_typing()
if new_text:
var formatted_message = MESSAGE_FORMAT % [player_name, new_text]
line_edit.text = ""
rset("chat_text", chat_text + formatted_message)
func _on_LineEdit_visibility_changed() -> void:
if line_edit.visible:
line_edit.grab_focus()
else:
line_edit.release_focus()
func set_chat_text(value: String) -> void:
visible = true
chat_text = "%s\n" % value
chat_history.text = chat_text
func _on_LineEdit_gui_input(event: InputEvent) -> void:
get_tree().set_input_as_handled()
pass

View File

@ -0,0 +1,51 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Classes/UI/TextChat.gd" type="Script" id=1]
[node name="TextChat" type="Control"]
anchor_top = 1.0
anchor_bottom = 1.0
margin_left = 8.0
margin_top = -192.0
margin_right = 200.0
margin_bottom = -8.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Panel" type="Panel" parent="."]
self_modulate = Color( 1, 1, 1, 0.670588 )
anchor_right = 1.0
anchor_bottom = 1.0
margin_bottom = -32.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ChatHistory" type="RichTextLabel" parent="Panel"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 8.0
margin_top = 8.0
margin_right = -8.0
margin_bottom = -8.0
text = "
"
scroll_following = true
selection_enabled = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="LineEdit" type="LineEdit" parent="."]
visible = false
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = -24.0
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="text_entered" from="LineEdit" to="." method="_on_LineEdit_text_entered"]
[connection signal="visibility_changed" from="LineEdit" to="." method="_on_LineEdit_visibility_changed"]

View File

@ -104,8 +104,12 @@ func _input(event):
if event.is_action_released("ShowPlayerList"):
$PlayerListContainer.hide()
if event.is_action_pressed("ToggleChatVisibility") and not $TextChat.is_typing() and GAME_MODE == "PLAYING":
$TextChat.toggle()
func open_menus():
GAME_MODE = "MENU"
$TextChat.hide()
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
$MenuContainer.show()
@ -187,6 +191,8 @@ func set_nickname(nickname, save=true):
else:
$MenuContainer/MainMenu/Name.text = nickname
$TextChat.player_name = nickname
func debug_connection_status():
if (get_tree().network_peer.get_connection_status() == NetworkedMultiplayerPeer.CONNECTION_CONNECTING):
print("We are trying to connect")
@ -333,3 +339,12 @@ func on_connection_established():
func on_connection_failed():
print("Connection has failed")
func _on_TextChat_typing_toggled(is_typing) -> void:
if is_typing:
GAME_MODE = "MENU"
else:
GAME_MODE = "PLAYING"
pass

View File

@ -1,10 +1,11 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=7 format=2]
[ext_resource path="res://Classes/UI/theme.tres" type="Theme" id=1]
[ext_resource path="res://Game.gd" type="Script" id=2]
[ext_resource path="res://Assets/Maps/DM1/DM1.tscn" type="PackedScene" id=3]
[ext_resource path="res://Classes/UI/CharacterSelect.tscn" type="PackedScene" id=4]
[ext_resource path="res://PlayerListContainer.gd" type="Script" id=5]
[ext_resource path="res://Classes/UI/TextChat.tscn" type="PackedScene" id=6]
[node name="Game" type="Node"]
script = ExtResource( 2 )
@ -317,6 +318,11 @@ theme = ExtResource( 1 )
[node name="PlayerList" type="VBoxContainer" parent="PlayerListContainer/Panel"]
theme = ExtResource( 1 )
alignment = 1
[node name="TextChat" parent="." instance=ExtResource( 6 )]
visible = false
margin_top = -264.542
margin_bottom = -80.5416
[connection signal="pressed" from="MenuContainer/MainMenu/QuickConnect" to="." method="join_test_server"]
[connection signal="pressed" from="MenuContainer/MainMenu/Connect" to="." method="open_menu" binds= [ "ConnectMenu" ]]
[connection signal="pressed" from="MenuContainer/MainMenu/Disconnect" to="." method="free_client"]
@ -339,5 +345,6 @@ alignment = 1
[connection signal="value_changed" from="MenuContainer/ControlsMenu/HBoxContainer/SensitivitySlider" to="." method="set_mouse_sensitivity"]
[connection signal="pressed" from="MenuContainer/GraphicsMenu/Back" to="." method="return_to_menu" binds= [ "OptionsMenu" ]]
[connection signal="toggled" from="MenuContainer/GraphicsMenu/Fullscreen" to="." method="set_fullscreen"]
[connection signal="typing_toggled" from="TextChat" to="." method="_on_TextChat_typing_toggled"]
[editable path="MenuContainer/CharacterSelectScreen"]

View File

@ -104,6 +104,16 @@ WeaponPrev={
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":5,"pressed":false,"doubleclick":false,"script":null)
]
}
ToggleChatWrite={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777221,"unicode":0,"echo":false,"script":null)
]
}
ToggleChatVisibility={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":89,"unicode":0,"echo":false,"script":null)
]
}
[rendering]