Skip to content

Commit

Permalink
Implement audio/image preview fields
Browse files Browse the repository at this point in the history
  • Loading branch information
salianifo committed Oct 18, 2024
1 parent ce057b7 commit 49a89ac
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 6 deletions.
4 changes: 3 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,9 @@ 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.IMAGE_PREVIEW: "res://addons/dialogic/Editor/Events/Fields/field_image_preview.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
28 changes: 28 additions & 0 deletions addons/dialogic/Editor/Events/Fields/field_image_preview.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@tool
extends DialogicVisualEditorField


func _ready() -> void:
pass


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


## To be overwritten
func _set_value(value:Variant) -> void:
if ResourceLoader.exists(value):
self.texture = load(value)
minimum_size_changed.emit()
else:
self.texture = null
minimum_size_changed.emit()

#endregion


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

#endregion
16 changes: 16 additions & 0 deletions addons/dialogic/Editor/Events/Fields/field_image_preview.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[gd_scene load_steps=2 format=3 uid="uid://slgruoy74a7m"]

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

[node name="Field_Image_Preview" type="TextureRect"]
custom_minimum_size = Vector2(0, 100)
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 0
expand_mode = 2
stretch_mode = 4
script = ExtResource("1_12y73")
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
9 changes: 8 additions & 1 deletion addons/dialogic/Modules/Background/event_background.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ extends DialogicEvent
var scene := ""
## The argument that is passed to the background scene.
## For the default scene it's the path to the image to show.
var argument := ""
var argument := "":
set(value):
if argument != value:
argument = value
ui_update_needed.emit()
## The time the fade animation will take. Leave at 0 for instant change.
var fade: float = 0.0
## Name of the transition to use.
Expand Down Expand Up @@ -138,6 +142,9 @@ func build_event_editor() -> void:
'_arg_type == ArgumentTypes.IMAGE or _scene_type == SceneTypes.DEFAULT')
add_header_edit('argument', ValueType.SINGLELINE_TEXT, {}, '_arg_type == ArgumentTypes.CUSTOM')

add_body_edit("argument", ValueType.IMAGE_PREVIEW, {'left_text':'Preview:'}, '(_arg_type == ArgumentTypes.IMAGE or _scene_type == SceneTypes.DEFAULT) and !argument.is_empty()')
add_body_line_break('(_arg_type == ArgumentTypes.IMAGE or _scene_type == SceneTypes.DEFAULT) and !argument.is_empty()')

add_body_edit("transition", ValueType.DYNAMIC_OPTIONS,
{'left_text':'Transition:',
'empty_text':'Simple Fade',
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, IMAGE_PREVIEW, AUDIO_PREVIEW
}
## List that stores the fields for the editor
var editor_list: Array = []
Expand Down

0 comments on commit 49a89ac

Please sign in to comment.