46 lines
1007 B
GDScript3
46 lines
1007 B
GDScript3
|
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
|