immersive-home/app/content/system/assist/chat.gd

39 lines
980 B
GDScript3
Raw Normal View History

2024-03-15 19:27:03 +02:00
@tool
extends Node3D
const FontTools = preload ("res://lib/utils/font_tools.gd")
@onready var label: Label3D = $Label3D
@onready var chat: Skeleton3D = $chat_bubble/Armature/Skeleton3D
2024-03-21 11:51:58 +02:00
@onready var chat_flipped: Skeleton3D = $"chat_bubble-flipped/Armature/Skeleton3D"
@onready var model: Node3D = $chat_bubble
@onready var model_flipped: Node3D = $"chat_bubble-flipped"
2024-03-15 19:27:03 +02:00
@export var text := "Hello, World!":
set(value):
2024-03-21 11:51:58 +02:00
text = value
2024-03-21 14:29:10 +02:00
if !is_inside_tree(): return
label.text = text
var text_width = FontTools.get_label_size(label).x
2024-03-15 19:27:03 +02:00
2024-03-21 14:29:10 +02:00
var offset = (text_width - base_width) / 0.2
offset = max(0.0, offset)
chat.set_bone_pose_position(0, Vector3(0, offset, 0))
chat_flipped.set_bone_pose_position(1, Vector3(0, -offset, 0))
2024-03-15 19:27:03 +02:00
@export var flip: bool = false:
set(value):
2024-03-21 11:51:58 +02:00
flip = value
2024-03-21 14:29:10 +02:00
if !is_inside_tree(): return
model.visible = !flip
model_flipped.visible = flip
2024-03-15 19:27:03 +02:00
const base_width = 0.8 * 0.2
2024-03-21 14:29:10 +02:00
func _ready():
Update.props(self, ["text", "flip"])