]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Textbox/animations.gd
Initial Godot project with Dialogic 2.0-Alpha-17
[wolf-seeking-sheep.git] / addons / dialogic / Modules / DefaultLayoutParts / Layer_VN_Textbox / animations.gd
1 extends AnimationPlayer
2
3 ## A custom script/node that adds some animations to the textbox.
4
5 # Careful: Sync these with the ones in the root script!
6 enum AnimationsIn {NONE, POP_IN, FADE_UP}
7 enum AnimationsOut {NONE, POP_OUT, FADE_DOWN}
8 enum AnimationsNewText {NONE, WIGGLE}
9
10 var animation_in: AnimationsIn
11 var animation_out: AnimationsOut
12 var animation_new_text: AnimationsNewText
13
14 var full_clear := true
15
16
17 func get_text_panel() -> PanelContainer:
18         return %DialogTextPanel
19
20
21 func get_dialog() -> DialogicNode_DialogText:
22         return %DialogicNode_DialogText
23
24
25 func _ready() -> void:
26         var text_system: Node = DialogicUtil.autoload().get(&'Text')
27         text_system.connect(&'animation_textbox_hide', _on_textbox_hide)
28         text_system.connect(&'animation_textbox_show', _on_textbox_show)
29         text_system.connect(&'animation_textbox_new_text', _on_textbox_new_text)
30         text_system.connect(&'about_to_show_text', _on_about_to_show_text)
31         var animation_system: Node = DialogicUtil.autoload().get(&'Animations')
32         animation_system.connect(&'animation_interrupted', _on_animation_interrupted)
33
34
35 func _on_textbox_show() -> void:
36         if animation_in == AnimationsIn.NONE:
37                 return
38         play('RESET')
39         var animation_system: Node = DialogicUtil.autoload().get(&'Animations')
40         animation_system.call(&'start_animating')
41         get_text_panel().get_parent().get_parent().set(&'modulate', Color.TRANSPARENT)
42         get_dialog().text = ""
43         match animation_in:
44                 AnimationsIn.POP_IN:
45                         play("textbox_pop")
46                 AnimationsIn.FADE_UP:
47                         play("textbox_fade_up")
48         if not animation_finished.is_connected(Callable(animation_system, &'animation_finished')):
49                 animation_finished.connect(Callable(animation_system, &'animation_finished'), CONNECT_ONE_SHOT)
50
51
52 func _on_textbox_hide() -> void:
53         if animation_out == AnimationsOut.NONE:
54                 return
55         play('RESET')
56         var animation_system: Node = DialogicUtil.autoload().get(&'Animations')
57         animation_system.call(&'start_animating')
58         match animation_out:
59                 AnimationsOut.POP_OUT:
60                         play_backwards("textbox_pop")
61                 AnimationsOut.FADE_DOWN:
62                         play_backwards("textbox_fade_up")
63
64         if not animation_finished.is_connected(Callable(animation_system, &'animation_finished')):
65                 animation_finished.connect(Callable(animation_system, &'animation_finished'), CONNECT_ONE_SHOT)
66
67
68 func _on_about_to_show_text(info:Dictionary) -> void:
69         full_clear = !info.append
70
71
72 func _on_textbox_new_text() -> void:
73         if DialogicUtil.autoload().Inputs.auto_skip.enabled:
74                 return
75
76         if animation_new_text == AnimationsNewText.NONE:
77                 return
78
79         var animation_system: Node = DialogicUtil.autoload().get(&'Animations')
80         animation_system.call(&'start_animating')
81         if full_clear:
82                 get_dialog().text = ""
83         match animation_new_text:
84                 AnimationsNewText.WIGGLE:
85                         play("new_text")
86
87                         if not animation_finished.is_connected(Callable(animation_system, &'animation_finished')):
88                                 animation_finished.connect(Callable(animation_system, &'animation_finished'), CONNECT_ONE_SHOT)
89
90
91 func _on_animation_interrupted() -> void:
92         if is_playing():
93                 stop()