]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/Voice/event_voice.gd
Squashed commit of the following:
[wolf-seeking-sheep.git] / addons / dialogic / Modules / Voice / event_voice.gd
1 @tool
2 class_name DialogicVoiceEvent
3 extends DialogicEvent
4
5 ## Event that allows to set the sound file to use for the next text event.
6
7
8 ### Settings
9
10 ## The path to the sound file.
11 var file_path := "":
12         set(value):
13                 if file_path != value:
14                         file_path = value
15                         ui_update_needed.emit()
16 ## The volume the sound will be played at.
17 var volume: float = 0
18 ## The audio bus to play the sound on.
19 var audio_bus := "Master"
20
21
22 ################################################################################
23 ##                                              EXECUTE
24 ################################################################################
25
26 func _execute() -> void:
27         # If Auto-Skip is enabled, we may not want to play voice audio.
28         # Instant Auto-Skip will always skip voice audio.
29         if (dialogic.Inputs.auto_skip.enabled
30         and dialogic.Inputs.auto_skip.skip_voice):
31                 finish()
32                 return
33
34         dialogic.Voice.set_file(file_path)
35         dialogic.Voice.set_volume(volume)
36         dialogic.Voice.set_bus(audio_bus)
37         finish()
38         # the rest is executed by a text event
39
40
41 ################################################################################
42 ##                                              INITIALIZE
43 ################################################################################
44
45 func _init() -> void:
46         event_name = "Voice"
47         set_default_color('Color7')
48         event_category = "Audio"
49         event_sorting_index = 5
50
51
52 ################################################################################
53 ##                                              SAVING/LOADING
54 ################################################################################
55
56 func get_shortcode() -> String:
57         return "voice"
58
59
60 func get_shortcode_parameters() -> Dictionary:
61         return {
62                 #param_name : property_info
63                 "path"          : {"property": "file_path", "default": ""},
64                 "volume"        : {"property": "volume",        "default": 0},
65                 "bus"           : {"property": "audio_bus", "default": "Master"}
66         }
67
68
69 ################################################################################
70 ##                                              EDITOR REPRESENTATION
71 ################################################################################
72
73 func build_event_editor() -> void:
74         add_header_edit('file_path', ValueType.FILE, {
75                         'left_text'             : 'Set',
76                         'right_text'    : 'as the next voice audio',
77                         'file_filter'   : "*.mp3, *.ogg, *.wav",
78                         'placeholder'   : "Select file",
79                         'editor_icon'   : ["AudioStreamPlayer", "EditorIcons"]})
80         add_header_edit('file_path', ValueType.AUDIO_PREVIEW)
81         add_body_edit('volume', ValueType.NUMBER, {'left_text':'Volume:', 'mode':2}, '!file_path.is_empty()')
82         add_body_edit('audio_bus', ValueType.SINGLELINE_TEXT, {'left_text':'Audio Bus:'}, '!file_path.is_empty()')