]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/Wait/event_wait.gd
Initial Godot project with Dialogic 2.0-Alpha-17
[wolf-seeking-sheep.git] / addons / dialogic / Modules / Wait / event_wait.gd
1 @tool
2 class_name DialogicWaitEvent
3 extends DialogicEvent
4
5 ## Event that waits for some time before continuing.
6
7
8 ### Settings
9
10 ## The time in seconds that the event will stop before continuing.
11 var time: float = 1.0
12 ## If true the text box will be hidden while the event waits.
13 var hide_text := true
14 ## If true the wait can be skipped with user input
15 var skippable := false
16
17 var _tween: Tween
18
19 ################################################################################
20 ##                                              EXECUTE
21 ################################################################################
22
23 func _execute() -> void:
24         var final_wait_time := time
25
26         if dialogic.Inputs.auto_skip.enabled:
27                 var time_per_event: float = dialogic.Inputs.auto_skip.time_per_event
28                 final_wait_time = min(time, time_per_event)
29
30         dialogic.current_state = dialogic.States.WAITING
31
32         if hide_text and dialogic.has_subsystem("Text"):
33                 dialogic.Text.update_dialog_text('', true)
34                 dialogic.Text.hide_textbox()
35
36         _tween = dialogic.get_tree().create_tween()
37         if DialogicUtil.is_physics_timer():
38                 _tween.set_process_mode(Tween.TWEEN_PROCESS_PHYSICS)
39         _tween.tween_callback(_on_finish).set_delay(final_wait_time)
40         
41         if skippable:
42                 dialogic.Inputs.dialogic_action.connect(_on_finish)
43
44
45 func _on_finish() -> void:
46         if is_instance_valid(_tween):
47                 _tween.kill()
48         
49         if skippable:
50                 dialogic.Inputs.dialogic_action.disconnect(_on_finish)
51         
52         if dialogic.Animations.is_animating():
53                 dialogic.Animations.stop_animation()
54         dialogic.current_state = dialogic.States.IDLE
55
56         finish()
57
58
59 ################################################################################
60 ##                                              INITIALIZE
61 ################################################################################
62
63 func _init() -> void:
64         event_name = "Wait"
65         set_default_color('Color5')
66         event_category = "Flow"
67         event_sorting_index = 11
68
69
70 ################################################################################
71 ##                                              SAVING/LOADING
72 ################################################################################
73
74 func get_shortcode() -> String:
75         return "wait"
76
77
78 func get_shortcode_parameters() -> Dictionary:
79         return {
80                 #param_name : property_info
81                 "time"          :  {"property": "time",                 "default": 1},
82                 "hide_text" :  {"property": "hide_text",        "default": true},
83                 "skippable" :  {"property": "skippable",        "default": false},
84         }
85
86
87 ################################################################################
88 ##                                              EDITOR REPRESENTATION
89 ################################################################################
90
91 func build_event_editor() -> void:
92         add_header_edit('time', ValueType.NUMBER, {'left_text':'Wait', 'autofocus':true, 'min':0.1})
93         add_header_label('seconds', 'time != 1')
94         add_header_label('second', 'time == 1')
95         add_body_edit('hide_text', ValueType.BOOL, {'left_text':'Hide text box:'})
96         add_body_edit('skippable', ValueType.BOOL, {'left_text':'Skippable:'})