Advertisement
Guest User

vn_portrait_layer.gd expansion for animated portraits

a guest
Jun 12th, 2025
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | Source Code | 0 0
  1. @tool
  2. extends DialogicLayoutLayer
  3. class_name AnimatedPortraitLayer
  4.  
  5. ## A layer that allows showing 5 portraits, like in a visual novel.
  6.  
  7. enum SPEAK_ANIM_STYLE {NONE, TRANSLATION, ROTATION}
  8.  
  9. ## The canvas layer that the portraits are on.
  10. @export var portrait_size_mode := DialogicNode_PortraitContainer.SizeModes.FIT_SCALE_HEIGHT
  11. @export var anim_style := SPEAK_ANIM_STYLE.TRANSLATION
  12. var dialogic : DialogicGameHandler
  13. var last_connected = null
  14. var last_connected_finish = null
  15.  
  16. func _ready():
  17. super()
  18. dialogic = DialogicUtil.autoload()
  19. if dialogic:
  20. dialogic.event_handled.connect(_on_event_handled)
  21.  
  22. func _apply_export_overrides():
  23. # apply portrait size
  24. for child in %Portraits.get_children():
  25. child.size_mode = portrait_size_mode
  26. child.anim_style = anim_style
  27. child.update_portrait_transforms()
  28.  
  29. func _on_event_handled(resource) -> void:
  30. var text_event := resource as DialogicTextEvent
  31. if last_connected != null && dialogic.continued_revealing_text.is_connected(last_connected):
  32. dialogic.continued_revealing_text.disconnect(last_connected)
  33. dialogic.finished_revealing_text.disconnect(last_connected_finish)
  34. if !text_event || !text_event.character:
  35. return
  36.  
  37. var position_index : int = dialogic.current_state_info.portraits[text_event.character.resource_path].position_index
  38. var speaking_portrait : DialogicNode_PortraitContainer_Animated = %Portraits.get_children()[position_index] as DialogicNode_PortraitContainer_Animated
  39. if !speaking_portrait:
  40. return
  41. last_connected = speaking_portrait._on_continued_revealing_text
  42. last_connected_finish = speaking_portrait._on_finished_revealing_text
  43. dialogic.continued_revealing_text.connect(last_connected)
  44. dialogic.finished_revealing_text.connect(last_connected_finish)
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement