2 ## Event that can change the currently playing background music.
3 ## This event won't play new music if it's already playing.
4 class_name DialogicMusicEvent
10 ## The file to play. If empty, the previous music will be faded out.
13 if file_path != value:
15 ui_update_needed.emit()
16 ## The channel to use.
17 var channel_id: int = 0
18 ## The length of the fade. If 0 (by default) it's an instant change.
19 var fade_length: float = 0
20 ## The volume the music will be played at.
22 ## The audio bus the music will be played at.
24 ## If true, the audio will loop, otherwise only play once.
28 ################################################################################
30 ################################################################################
32 func _execute() -> void:
33 if not dialogic.Audio.is_music_playing_resource(file_path, channel_id):
34 dialogic.Audio.update_music(file_path, volume, audio_bus, fade_length, loop, channel_id)
38 ################################################################################
40 ################################################################################
44 set_default_color('Color7')
45 event_category = "Audio"
46 event_sorting_index = 2
49 func _get_icon() -> Resource:
50 return load(self.get_script().get_path().get_base_dir().path_join('icon_music.png'))
52 ################################################################################
54 ################################################################################
56 func get_shortcode() -> String:
60 func get_shortcode_parameters() -> Dictionary:
62 #param_name : property_info
63 "path" : {"property": "file_path", "default": ""},
64 "channel" : {"property": "channel_id", "default": 0},
65 "fade" : {"property": "fade_length", "default": 0},
66 "volume" : {"property": "volume", "default": 0},
67 "bus" : {"property": "audio_bus", "default": "",
68 "suggestions": get_bus_suggestions},
69 "loop" : {"property": "loop", "default": true},
73 ################################################################################
74 ## EDITOR REPRESENTATION
75 ################################################################################
77 func build_event_editor() -> void:
78 add_header_edit('file_path', ValueType.FILE, {
80 'file_filter' : "*.mp3, *.ogg, *.wav; Supported Audio Files",
81 'placeholder' : "No music",
82 'editor_icon' : ["AudioStreamPlayer", "EditorIcons"]})
83 add_header_edit('channel_id', ValueType.FIXED_OPTIONS, {'left_text':'on:', 'options': get_channel_list()})
84 add_header_edit('file_path', ValueType.AUDIO_PREVIEW)
85 add_body_edit('fade_length', ValueType.NUMBER, {'left_text':'Fade Time:'})
86 add_body_edit('volume', ValueType.NUMBER, {'left_text':'Volume:', 'mode':2}, '!file_path.is_empty()')
87 add_body_edit('audio_bus', ValueType.SINGLELINE_TEXT, {'left_text':'Audio Bus:'}, '!file_path.is_empty()')
88 add_body_edit('loop', ValueType.BOOL, {'left_text':'Loop:'}, '!file_path.is_empty() and not file_path.to_lower().ends_with(".wav")')
91 func get_bus_suggestions() -> Dictionary:
92 var bus_name_list := {}
93 for i in range(AudioServer.bus_count):
94 bus_name_list[AudioServer.get_bus_name(i)] = {'value':AudioServer.get_bus_name(i)}
98 func get_channel_list() -> Array:
99 var channel_name_list := []
100 for i in ProjectSettings.get_setting('dialogic/audio/max_channels', 4):
101 channel_name_list.append({
102 'label': 'Channel %s' % (i + 1),
105 return channel_name_list