Added chat bubbles

This commit is contained in:
2024-02-28 21:44:24 +01:00
parent db3ee3a685
commit 69a918d4ec
12 changed files with 167 additions and 9 deletions

View File

@ -0,0 +1,10 @@
class_name ChatBubble
extends Control
var label: Label
func _ready():
label = %Label
func show_message(message: String):
label.text = message

View File

@ -0,0 +1,46 @@
[gd_scene load_steps=4 format=3 uid="uid://epb22atgo7af"]
[ext_resource type="Script" path="res://player/chat/ChatBubble.gd" id="1_dscmj"]
[ext_resource type="LabelSettings" uid="uid://cvqtha83d263j" path="res://player/chat/LabelSettings.tres" id="1_u5tc1"]
[ext_resource type="Texture2D" uid="uid://d22tgtevi4ukp" path="res://assets/ui/chat/speech-bubble-blur.png" id="2_e5alo"]
[node name="ChatBubble" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_dscmj")
[node name="TextureRect" type="TextureRect" parent="."]
layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_top = -512.0
offset_right = 512.0
grow_vertical = 0
texture = ExtResource("2_e5alo")
[node name="Label" type="Label" parent="."]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = -1
anchor_left = -0.00520833
anchor_top = 1.00556
anchor_right = 0.00885417
anchor_bottom = 0.991667
offset_left = 82.0
offset_top = -374.0
offset_right = 427.0
offset_bottom = -139.0
grow_vertical = 0
text = "I think we gotta do this in hard mode."
label_settings = ExtResource("1_u5tc1")
horizontal_alignment = 1
vertical_alignment = 1
autowrap_mode = 3
clip_text = true
text_overrun_behavior = 3
metadata/_edit_use_anchors_ = true

View File

@ -0,0 +1,46 @@
class_name ChatComponent
extends Sprite3D
@export var duration: float
@export var alpha_curve: Curve
var sub_viewport: SubViewport
var bubble: ChatBubble
var time := 0.0
func _ready():
sub_viewport = %SubViewport
bubble = %ChatBubble
assert(alpha_curve)
assert(duration > 0)
assert(sub_viewport)
assert(bubble)
texture = sub_viewport.get_texture()
func show_message(message: String):
bubble.show_message(message)
time = 0
set_enabled(true)
func _process(delta):
time += delta
if time > duration:
time = duration
set_enabled(false)
modulate.a = alpha_curve.sample(time / duration)
func set_enabled(enabled: bool):
visible = enabled
set_process(enabled)
match enabled:
true:
sub_viewport.render_target_clear_mode = SubViewport.CLEAR_MODE_ALWAYS
sub_viewport.render_target_update_mode = SubViewport.UPDATE_WHEN_VISIBLE
false:
sub_viewport.render_target_clear_mode = SubViewport.CLEAR_MODE_NEVER
sub_viewport.render_target_update_mode = SubViewport.UPDATE_DISABLED

View File

@ -0,0 +1,28 @@
[gd_scene load_steps=4 format=3 uid="uid://urt8b7grv0qq"]
[ext_resource type="Script" path="res://player/chat/ChatComponent.gd" id="1_3o8hk"]
[ext_resource type="PackedScene" uid="uid://epb22atgo7af" path="res://player/chat/ChatBubble.tscn" id="2_yfr7m"]
[sub_resource type="Curve" id="Curve_426w0"]
_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.05, 1), 0.0, 0.0, 0, 0, Vector2(0.8, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
point_count = 4
[node name="Chat" type="Sprite3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.83994, 0)
centered = false
offset = Vector2(400, -30)
pixel_size = 0.001
billboard = 1
render_priority = 1
region_rect = Rect2(0, 0, 84, 26)
script = ExtResource("1_3o8hk")
duration = 3.5
alpha_curve = SubResource("Curve_426w0")
[node name="SubViewport" type="SubViewport" parent="."]
unique_name_in_owner = true
disable_3d = true
transparent_bg = true
[node name="ChatBubble" parent="SubViewport" instance=ExtResource("2_yfr7m")]
unique_name_in_owner = true

View File

@ -0,0 +1,6 @@
[gd_resource type="LabelSettings" format=3 uid="uid://cvqtha83d263j"]
[resource]
font_size = 54
font_color = Color(0.12549, 0.12549, 0.12549, 1)
shadow_color = Color(0, 0, 0, 0.12549)