Skip to content

Commit

Permalink
Audio Events: Implement audio preview fields (#2448)
Browse files Browse the repository at this point in the history
Adds an audio preview field, that is used on the audio events.
  • Loading branch information
salianifo authored Oct 26, 2024
1 parent da14004 commit 434ed7d
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 5 deletions.
3 changes: 2 additions & 1 deletion addons/dialogic/Editor/Events/EventBlock/event_block.gd
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ var FIELD_SCENES := {
DialogicEvent.ValueType.VECTOR2: "res://addons/dialogic/Editor/Events/Fields/field_vector2.tscn",
DialogicEvent.ValueType.VECTOR3: "res://addons/dialogic/Editor/Events/Fields/field_vector3.tscn",
DialogicEvent.ValueType.VECTOR4: "res://addons/dialogic/Editor/Events/Fields/field_vector4.tscn",
DialogicEvent.ValueType.COLOR: "res://addons/dialogic/Editor/Events/Fields/field_color.tscn"
DialogicEvent.ValueType.COLOR: "res://addons/dialogic/Editor/Events/Fields/field_color.tscn",
DialogicEvent.ValueType.AUDIO_PREVIEW: "res://addons/dialogic/Editor/Events/Fields/field_audio_preview.tscn",
}

func build_editor(build_header:bool = true, build_body:bool = false) -> void:
Expand Down
52 changes: 52 additions & 0 deletions addons/dialogic/Editor/Events/Fields/field_audio_preview.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@tool
extends DialogicVisualEditorField


var file_path: String


func _ready() -> void:
self.pressed.connect(_on_pressed)
%AudioStreamPlayer.finished.connect(_on_finished)


#region OVERWRITES
################################################################################


## To be overwritten
func _set_value(value:Variant) -> void:
file_path = value
self.disabled = file_path.is_empty()
_stop()

#endregion


#region SIGNAL METHODS
################################################################################

func _on_pressed() -> void:
if %AudioStreamPlayer.playing:
_stop()
elif not file_path.is_empty():
_play()


func _on_finished() -> void:
_stop()

#endregion


func _stop() -> void:
%AudioStreamPlayer.stop()
%AudioStreamPlayer.stream = null
self.icon = get_theme_icon("Play", "EditorIcons")


func _play() -> void:
if ResourceLoader.exists(file_path):
%AudioStreamPlayer.stream = load(file_path)
%AudioStreamPlayer.play()
self.icon = get_theme_icon("Stop", "EditorIcons")
12 changes: 12 additions & 0 deletions addons/dialogic/Editor/Events/Fields/field_audio_preview.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://dotvrsumm5y5c"]

[ext_resource type="Script" path="res://addons/dialogic/Editor/Events/Fields/field_audio_preview.gd" id="1_7wm54"]

[node name="Field_Audio_Preview" type="Button"]
offset_right = 8.0
offset_bottom = 8.0
flat = true
script = ExtResource("1_7wm54")

[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
unique_name_in_owner = true
7 changes: 6 additions & 1 deletion addons/dialogic/Modules/Audio/event_music.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ extends DialogicEvent
### Settings

## The file to play. If empty, the previous music will be faded out.
var file_path := ""
var file_path := "":
set(value):
if file_path != value:
file_path = value
ui_update_needed.emit()
## The channel to use.
var channel_id: int = 0
## The length of the fade. If 0 (by default) it's an instant change.
Expand Down Expand Up @@ -77,6 +81,7 @@ func build_event_editor() -> void:
'placeholder' : "No music",
'editor_icon' : ["AudioStreamPlayer", "EditorIcons"]})
add_header_edit('channel_id', ValueType.FIXED_OPTIONS, {'left_text':'on:', 'options': get_channel_list()})
add_header_edit('file_path', ValueType.AUDIO_PREVIEW)
add_body_edit('fade_length', ValueType.NUMBER, {'left_text':'Fade Time:'})
add_body_edit('volume', ValueType.NUMBER, {'left_text':'Volume:', 'mode':2}, '!file_path.is_empty()')
add_body_edit('audio_bus', ValueType.SINGLELINE_TEXT, {'left_text':'Audio Bus:'}, '!file_path.is_empty()')
Expand Down
7 changes: 6 additions & 1 deletion addons/dialogic/Modules/Audio/event_sound.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ extends DialogicEvent
### Settings

## The path to the file to play.
var file_path := ""
var file_path := "":
set(value):
if file_path != value:
file_path = value
ui_update_needed.emit()
## The volume to play the sound at.
var volume: float = 0
## The bus to play the sound on.
Expand Down Expand Up @@ -70,6 +74,7 @@ func build_event_editor() -> void:
'file_filter' : '*.mp3, *.ogg, *.wav; Supported Audio Files',
'placeholder' : "Select file",
'editor_icon' : ["AudioStreamPlayer", "EditorIcons"]})
add_header_edit('file_path', ValueType.AUDIO_PREVIEW)
add_body_edit('volume', ValueType.NUMBER, {'left_text':'Volume:', 'mode':2}, '!file_path.is_empty()')
add_body_edit('audio_bus', ValueType.SINGLELINE_TEXT, {'left_text':'Audio Bus:'}, '!file_path.is_empty()')

Expand Down
7 changes: 6 additions & 1 deletion addons/dialogic/Modules/Voice/event_voice.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ extends DialogicEvent
### Settings

## The path to the sound file.
var file_path := ""
var file_path := "":
set(value):
if file_path != value:
file_path = value
ui_update_needed.emit()
## The volume the sound will be played at.
var volume: float = 0
## The audio bus to play the sound on.
Expand Down Expand Up @@ -73,5 +77,6 @@ func build_event_editor() -> void:
'file_filter' : "*.mp3, *.ogg, *.wav",
'placeholder' : "Select file",
'editor_icon' : ["AudioStreamPlayer", "EditorIcons"]})
add_header_edit('file_path', ValueType.AUDIO_PREVIEW)
add_body_edit('volume', ValueType.NUMBER, {'left_text':'Volume:', 'mode':2}, '!file_path.is_empty()')
add_body_edit('audio_bus', ValueType.SINGLELINE_TEXT, {'left_text':'Audio Bus:'}, '!file_path.is_empty()')
2 changes: 1 addition & 1 deletion addons/dialogic/Resources/event.gd
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ enum ValueType {
NUMBER,
VECTOR2, VECTOR3, VECTOR4,
# Other
CUSTOM, BUTTON, LABEL, COLOR
CUSTOM, BUTTON, LABEL, COLOR, AUDIO_PREVIEW
}
## List that stores the fields for the editor
var editor_list: Array = []
Expand Down

0 comments on commit 434ed7d

Please sign in to comment.