This commit is contained in:
Teatov 2025-02-13 23:35:52 +10:00
parent bb3b75929a
commit bb7f8ead08
8 changed files with 148 additions and 3 deletions

View File

@ -160,6 +160,11 @@ look_slow={
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":8,"pressure":0.0,"pressed":true,"script":null)
]
}
chat={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":84,"key_label":0,"unicode":116,"location":0,"echo":false,"script":null)
]
}
[layer_names]

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=4 format=3 uid="uid://b7fc42grqckl0"]
[gd_scene load_steps=5 format=3 uid="uid://b7fc42grqckl0"]
[ext_resource type="Script" path="res://scripts/main.gd" id="1_80y7k"]
[ext_resource type="PackedScene" uid="uid://b3t5vrqb1eym2" path="res://scenes/ui/chat.tscn" id="3_8t1rc"]
[ext_resource type="Material" uid="uid://00ldcihmubqo" path="res://resources/materials/test_triplanar.tres" id="3_vk6ds"]
[sub_resource type="Environment" id="Environment_wyusq"]
@ -27,6 +28,10 @@ transform = Transform3D(0.866025, -0.433013, 0.25, 0, 0.5, 0.866025, -0.5, -0.75
shadow_enabled = true
shadow_blur = 2.0
[node name="UI" type="Node" parent="."]
[node name="Chat" parent="UI" instance=ExtResource("3_8t1rc")]
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_wyusq")

51
scenes/ui/chat.tscn Normal file
View File

@ -0,0 +1,51 @@
[gd_scene load_steps=2 format=3 uid="uid://b3t5vrqb1eym2"]
[ext_resource type="Script" path="res://scripts/ui/chat.gd" id="1_ulx3h"]
[node name="Chat" type="CanvasLayer"]
script = ExtResource("1_ulx3h")
[node name="Root" type="MarginContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
mouse_filter = 2
theme_override_constants/margin_left = 50
theme_override_constants/margin_top = 20
theme_override_constants/margin_right = 50
theme_override_constants/margin_bottom = 20
[node name="VBox" type="VBoxContainer" parent="Root"]
layout_mode = 2
mouse_filter = 2
theme_override_constants/separation = 0
[node name="MsgScroll" type="ScrollContainer" parent="Root/VBox"]
layout_mode = 2
size_flags_vertical = 3
mouse_filter = 2
horizontal_scroll_mode = 0
[node name="MsgMargin" type="MarginContainer" parent="Root/VBox/MsgScroll"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
mouse_filter = 2
theme_override_constants/margin_left = 10
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 30
[node name="MsgContainer" type="VBoxContainer" parent="Root/VBox/MsgScroll/MsgMargin"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
mouse_filter = 2
alignment = 2
[node name="MessageEdit" type="LineEdit" parent="Root/VBox"]
layout_mode = 2
theme_override_font_sizes/font_size = 26

View File

@ -0,0 +1,20 @@
[gd_scene format=3 uid="uid://bjrbngxkvhn7f"]
[node name="RichTextLabel" type="RichTextLabel"]
clip_contents = false
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
theme_override_colors/font_outline_color = Color(0, 0, 0, 0.501961)
theme_override_constants/outline_size = 20
theme_override_font_sizes/bold_italics_font_size = 26
theme_override_font_sizes/italics_font_size = 26
theme_override_font_sizes/mono_font_size = 26
theme_override_font_sizes/normal_font_size = 26
theme_override_font_sizes/bold_font_size = 26
bbcode_enabled = true
text = "[b]name:[/b] lorem ipsum"
fit_content = true

View File

@ -43,7 +43,6 @@ func _input(event: InputEvent) -> void:
var event_mode := _get_event_mode(event)
if mode == Mode.KB_MOUSE and event_mode == Mode.CONTROLLER:
mode = Mode.CONTROLLER
mode_changed.emit(mode)
if mode == Mode.CONTROLLER and event_mode == Mode.KB_MOUSE:

View File

@ -9,3 +9,4 @@ var main: Main:
if value:
main_loaded.emit()
main = value
var chat: Chat

View File

@ -16,7 +16,7 @@ func _exit_tree() -> void:
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("menu"):
if event.is_action_pressed("menu") and not Referencer.chat.open:
get_tree().quit()

64
scripts/ui/chat.gd Normal file
View File

@ -0,0 +1,64 @@
class_name Chat
extends CanvasLayer
var open: bool = false
var _chat_message_scene := preload("res://scenes/ui/chat_message.tscn")
@onready var _messages_container: Container = $Root/VBox/MsgScroll/MsgMargin/MsgContainer
@onready var _message_edit: LineEdit = $Root/VBox/MessageEdit
func _ready() -> void:
_message_edit.text_submitted.connect(_on_message_edit_text_submitted)
_message_edit.visible = false
Referencer.chat = self
func _exit_tree() -> void:
Referencer.chat = null
func _input(event: InputEvent) -> void:
if event.is_action_pressed("menu"):
call_deferred("_close")
func _unhandled_input(event: InputEvent) -> void:
if Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED:
return
if event.is_action_pressed("chat") and not open:
open = true
_message_edit.visible = true
_message_edit.grab_focus()
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
func _close() -> void:
open = false
_message_edit.release_focus()
_message_edit.visible = false
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
@rpc("any_peer", "call_local", "reliable", 1)
func _send_message(message: String) -> void:
var player_name := (
Networker.players[multiplayer.get_remote_sender_id()]["name"] as String
)
var message_node := _make_message_node(player_name, message)
_messages_container.add_child(message_node)
print(player_name + ": " + message)
func _make_message_node(player_name: String, message: String) -> RichTextLabel:
var node := _chat_message_scene.instantiate() as RichTextLabel
node.text = "[b]" + player_name + ":[/b]\t" + message
return node
func _on_message_edit_text_submitted(message: String) -> void:
_message_edit.text = ""
_send_message.rpc(message)