immersive-home/app/content/ui/components/notification/notification.gd

57 lines
1.3 KiB
GDScript3
Raw Normal View History

2023-12-13 23:22:52 +02:00
@tool
extends Node3D
@onready var label: Label3D = $AnimationNode/Text
@onready var icon_label: Label3D = $AnimationNode/Icon
@onready var mesh: MeshInstance3D = $AnimationNode/MeshInstance3D
@onready var collision: CollisionShape3D = $AnimationNode/CollisionShape3D
@onready var animation_player: AnimationPlayer = $AnimationNode/AnimationPlayer
@onready var button = $AnimationNode/Button
@onready var timer = $AnimationNode/Timer
@export var type: EventNotify.Type = EventNotify.Type.INFO:
set(value):
type = value
2024-03-21 14:29:10 +02:00
if !is_inside_tree(): return
icon_label.text = _type_to_string(type)
2023-12-13 23:22:52 +02:00
@export var text: String = "":
set(value):
text = value
2024-03-21 14:29:10 +02:00
if !is_inside_tree(): return
label.text = text
2023-12-13 23:22:52 +02:00
func _ready():
2024-03-21 14:29:10 +02:00
Update.props(self, ["type", "text"])
2023-12-13 23:22:52 +02:00
button.on_button_down.connect(fade_out)
fade_in()
timer.timeout.connect(func():
fade_out()
)
func fade_in():
2024-03-21 14:29:10 +02:00
if !is_inside_tree(): await ready
2023-12-13 23:22:52 +02:00
animation_player.play("fade_in")
func fade_out():
animation_player.play_backwards("fade_in")
await animation_player.animation_finished
queue_free()
func _type_to_string(type: EventNotify.Type) -> String:
match type:
EventNotify.Type.INFO:
return "info"
EventNotify.Type.SUCCESS:
return "check_circle"
EventNotify.Type.WARNING:
return "error"
EventNotify.Type.DANGER:
return "warning"
_:
return "info"