SpeechBubble.gd 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. extends RichTextLabel
  2. @onready var textLength : int = get_total_character_count()
  3. #
  4. func _ready():
  5. var speechContent : String = get_parsed_text()
  6. var speechLength : float = get_theme_font("normal_font").get_string_size(speechContent).x
  7. if speechLength > ActorCommons.speechMaxWidth:
  8. speechLength = ActorCommons.speechMaxWidth
  9. custom_minimum_size.x = speechLength as int + ActorCommons.speechExtraWidth
  10. func _process(_delta : float):
  11. if has_node("Timer"):
  12. var timeLeft : float = get_node("Timer").get_time_left()
  13. var speechIncreaseDelay : float = ActorCommons.speechDecreaseDelay
  14. if textLength < ActorCommons.speechIncreaseThreshold:
  15. speechIncreaseDelay = ActorCommons.speechDecreaseDelay / (ActorCommons.speechIncreaseThreshold - textLength)
  16. if timeLeft > ActorCommons.speechDelay - speechIncreaseDelay:
  17. var ratio : float = (ActorCommons.speechDelay - timeLeft) / speechIncreaseDelay
  18. visible_characters_behavior = TextServer.VC_GLYPHS_LTR
  19. visible_ratio = ratio
  20. elif timeLeft > 0 && timeLeft < ActorCommons.speechDecreaseDelay:
  21. var ratio : float = timeLeft / ActorCommons.speechDecreaseDelay
  22. modulate.a = ratio
  23. visible_characters_behavior = TextServer.VC_GLYPHS_RTL
  24. visible_ratio = ratio
  25. else:
  26. visible_ratio = 1
  27. else:
  28. visible_ratio = 1