]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/Text/node_next_indicator.gd
Initial Godot project with Dialogic 2.0-Alpha-17
[wolf-seeking-sheep.git] / addons / dialogic / Modules / Text / node_next_indicator.gd
1 @icon("node_next_indicator_icon.svg")
2 class_name DialogicNode_NextIndicator
3 extends Control
4
5 ## Node that is shown when the text is fully revealed.
6 ## The default implementation allows to set an icon and animation.
7
8
9 @export var enabled := true
10
11 ## If true the next indicator will also be shown if the text is a question.
12 @export var show_on_questions := false
13 ## If true the next indicator will be shown even if dialogic will autocontinue.
14 @export var show_on_autoadvance := false
15
16 enum Animations {BOUNCE, BLINK, NONE}
17
18 ## What animation should the indicator do.
19 @export var animation := Animations.BOUNCE
20
21 var texture_rect: TextureRect
22
23 ## Set the image to use as the indicator.
24 @export var texture: Texture2D = preload("res://addons/dialogic/Example Assets/next-indicator/next-indicator.png") as Texture2D:
25         set(_texture):
26                 texture = _texture
27                 if texture_rect:
28                         texture_rect.texture = texture
29
30 @export var texture_size := Vector2(32,32):
31         set(_texture_size):
32                 texture_size = _texture_size
33                 if has_node('Texture'):
34                         get_node('Texture').size = _texture_size
35                         get_node('Texture').position = -_texture_size
36
37
38 var tween: Tween
39
40 func _ready() -> void:
41         add_to_group('dialogic_next_indicator')
42
43         # Creating TextureRect if missing
44         if not texture_rect:
45                 var icon := TextureRect.new()
46                 icon.name = 'Texture'
47                 icon.ignore_texture_size = true
48                 icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
49                 icon.size = texture_size
50                 icon.position = -icon.size
51                 add_child(icon)
52                 texture_rect = icon
53
54         texture_rect.texture = texture
55
56         hide()
57         visibility_changed.connect(_on_visibility_changed)
58
59
60 func _on_visibility_changed() -> void:
61         if visible:
62                 play_animation(animation, 1.0)
63
64
65 func play_animation(current_animation: int, time:float) -> void:
66         # clean up previous tween to prevent slipping
67         if tween:
68                 tween.stop()
69
70         match current_animation:
71                 Animations.BOUNCE:
72                         tween = (create_tween() as Tween)
73                         var distance := 4
74                         tween.set_parallel(false)
75                         tween.set_trans(Tween.TRANS_SINE)
76                         tween.set_ease(Tween.EASE_IN_OUT)
77                         tween.set_loops()
78
79                         tween.tween_property(self, 'position', Vector2(0,distance), time*0.3).as_relative()
80                         tween.tween_property(self, 'position', - Vector2(0,distance), time*0.3).as_relative()
81                 Animations.BLINK:
82                         tween = (create_tween() as Tween)
83                         tween.set_parallel(false)
84                         tween.set_trans(Tween.TRANS_SINE)
85                         tween.set_ease(Tween.EASE_IN_OUT)
86                         tween.set_loops()
87
88                         tween.tween_property(self, 'modulate:a', 0, time*0.3)
89                         tween.tween_property(self, 'modulate:a', 1, time*0.3)