Notification.gd 920 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. extends RichTextLabel
  2. #
  3. @export var modulateInScaler : float = 10.0
  4. @export var modulateOutScaler : float = 2.0
  5. @onready var timer : Timer = $Timer
  6. var way : UICommons.Way = UICommons.Way.KEEP
  7. #
  8. func AddNotification(notif : String, delay : float = 5.0):
  9. ClearNotification()
  10. if notif.length() > 0 and delay > 0.0:
  11. text = "[center]%s[/center]" % notif
  12. timer.start(delay)
  13. way = UICommons.Way.SHOW
  14. func ClearNotification():
  15. if not timer.is_stopped():
  16. timer.stop()
  17. way = UICommons.Way.HIDE
  18. #
  19. func _on_timer_timeout():
  20. ClearNotification()
  21. #
  22. func _physics_process(delta : float):
  23. if way == UICommons.Way.SHOW and modulate.a < 1.0:
  24. modulate.a = clampf(modulate.a + delta * modulateInScaler, 0.0, 1.0)
  25. elif way == UICommons.Way.HIDE and modulate.a > 0.0:
  26. modulate.a = clampf(modulate.a - delta * modulateOutScaler, 0.0, 1.0)
  27. else:
  28. way = UICommons.Way.KEEP
  29. func _ready():
  30. modulate.a = 0.0