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

38 lines
952 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-15 19:27:03 +02:00
if !is_node_ready(): await ready
label.text = value
update()
@export var flip: bool = false:
set(value):
2024-03-21 11:51:58 +02:00
flip = value
2024-03-15 19:27:03 +02:00
if !is_node_ready(): await ready
2024-03-21 11:51:58 +02:00
model.visible = !value
model_flipped.visible = value
2024-03-15 19:27:03 +02:00
const base_width = 0.8 * 0.2
func update():
var text_width = FontTools.get_font_size(label).x
var offset = (text_width - base_width) / 0.2
offset = max(0.0, offset)
2024-03-21 11:51:58 +02:00
chat.set_bone_pose_position(0, Vector3(0, offset, 0))
chat_flipped.set_bone_pose_position(1, Vector3(0, -offset, 0))