Added basic chat

This commit is contained in:
2024-01-28 22:08:08 +01:00
parent 75801e21fd
commit a6278cedb1
17 changed files with 182 additions and 22 deletions

7
client/ui/ChatBox.gd Normal file
View File

@ -0,0 +1,7 @@
extends RichTextLabel
func _ready():
owner.on_message_received.connect(on_message_received)
func on_message_received(bbcode: String):
append_text(bbcode + "\n")

21
client/ui/ChatInput.gd Normal file
View File

@ -0,0 +1,21 @@
extends LineEdit
signal chat_message_submitted(message: String)
func _unhandled_input(event):
if Global.interacting_with_ui:
return
if event.is_action_pressed("open_chat"):
call_deferred("grab_focus")
func _on_focus_entered():
Global.interacting_with_ui = true
func _on_focus_exited():
Global.interacting_with_ui = false
func _on_text_submitted(message: String):
(owner as UIManager).chat_message_submitted.emit(message)
text = ""
release_focus()

View File

@ -1,10 +1,15 @@
class_name UIManager
extends Control
signal chat_message_submitted(message: String)
var on_ping_changed: Signal
var on_download_changed: Signal
var on_upload_changed: Signal
var on_message_received: Signal
func _enter_tree():
on_ping_changed = %Ping.changed
on_download_changed = %Client.download_changed
on_upload_changed = %Client.upload_changed
on_message_received = %Chat.message_received

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=3 uid="uid://dagn5bf7ou3sd"]
[gd_scene load_steps=11 format=3 uid="uid://dagn5bf7ou3sd"]
[ext_resource type="PackedScene" uid="uid://cch67vqpsmtej" path="res://ui/debug/DebugLabel.tscn" id="1_7s8uu"]
[ext_resource type="Script" path="res://ui/UI.gd" id="1_l5b6o"]
@ -6,6 +6,8 @@
[ext_resource type="Script" path="res://ui/debug/PingLabel.gd" id="3_xjdws"]
[ext_resource type="Script" path="res://ui/debug/PositionLabel.gd" id="4_beqf6"]
[ext_resource type="Script" path="res://ui/debug/VelocityLabel.gd" id="5_8lm6a"]
[ext_resource type="Script" path="res://ui/ChatBox.gd" id="5_vdqtm"]
[ext_resource type="Script" path="res://ui/ChatInput.gd" id="6_70anv"]
[ext_resource type="Script" path="res://ui/debug/UploadLabel.gd" id="7_cfnpx"]
[ext_resource type="Script" path="res://ui/debug/DownloadLabel.gd" id="8_ogt38"]
@ -35,21 +37,24 @@ script = ExtResource("3_xjdws")
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_top = -10.0
offset_right = 10.0
offset_top = -134.0
offset_right = 263.0
grow_vertical = 0
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/BottomLeft"]
layout_mode = 2
alignment = 2
[node name="Send" parent="CanvasLayer/BottomLeft/VBoxContainer" instance=ExtResource("1_7s8uu")]
[node name="ChatBox" type="RichTextLabel" parent="CanvasLayer/BottomLeft/VBoxContainer"]
layout_mode = 2
script = ExtResource("7_cfnpx")
size_flags_vertical = 3
bbcode_enabled = true
scroll_following = true
script = ExtResource("5_vdqtm")
[node name="Receive" parent="CanvasLayer/BottomLeft/VBoxContainer" instance=ExtResource("1_7s8uu")]
[node name="ChatInput" type="LineEdit" parent="CanvasLayer/BottomLeft/VBoxContainer"]
layout_mode = 2
script = ExtResource("8_ogt38")
script = ExtResource("6_70anv")
[node name="BottomRight" type="MarginContainer" parent="CanvasLayer"]
anchors_preset = 3
@ -57,8 +62,8 @@ anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -79.0
offset_top = -102.0
offset_left = -76.0
offset_top = -54.0
grow_horizontal = 0
grow_vertical = 0
@ -66,12 +71,37 @@ grow_vertical = 0
layout_mode = 2
alignment = 2
[node name="Position" parent="CanvasLayer/BottomRight/VBoxContainer" instance=ExtResource("1_7s8uu")]
[node name="Send" parent="CanvasLayer/BottomRight/VBoxContainer" instance=ExtResource("1_7s8uu")]
layout_mode = 2
alignment = 2
script = ExtResource("7_cfnpx")
[node name="Receive" parent="CanvasLayer/BottomRight/VBoxContainer" instance=ExtResource("1_7s8uu")]
layout_mode = 2
alignment = 2
script = ExtResource("8_ogt38")
[node name="TopRight" type="MarginContainer" parent="CanvasLayer"]
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -79.0
offset_bottom = 102.0
grow_horizontal = 0
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/TopRight"]
layout_mode = 2
[node name="Position" parent="CanvasLayer/TopRight/VBoxContainer" instance=ExtResource("1_7s8uu")]
layout_mode = 2
alignment = 2
script = ExtResource("4_beqf6")
[node name="Velocity" parent="CanvasLayer/BottomRight/VBoxContainer" instance=ExtResource("1_7s8uu")]
[node name="Velocity" parent="CanvasLayer/TopRight/VBoxContainer" instance=ExtResource("1_7s8uu")]
layout_mode = 2
alignment = 2
script = ExtResource("5_8lm6a")
[connection signal="focus_entered" from="CanvasLayer/BottomLeft/VBoxContainer/ChatInput" to="CanvasLayer/BottomLeft/VBoxContainer/ChatInput" method="_on_focus_entered"]
[connection signal="focus_exited" from="CanvasLayer/BottomLeft/VBoxContainer/ChatInput" to="CanvasLayer/BottomLeft/VBoxContainer/ChatInput" method="_on_focus_exited"]
[connection signal="text_submitted" from="CanvasLayer/BottomLeft/VBoxContainer/ChatInput" to="CanvasLayer/BottomLeft/VBoxContainer/ChatInput" method="_on_text_submitted"]