Skip to content

Commit a7a030d

Browse files
committed
working on audio player node
1 parent 85bbcbc commit a7a030d

File tree

13 files changed

+277
-39
lines changed

13 files changed

+277
-39
lines changed

addons/dialogic/Editor/EditorView.tscn

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=14 format=2]
1+
[gd_scene load_steps=15 format=2]
22

33
[ext_resource path="res://addons/dialogic/Editor/editor_view.gd" type="Script" id=1]
44
[ext_resource path="res://addons/dialogic/Images/dialog.svg" type="Texture" id=2]
@@ -11,6 +11,7 @@
1111
[ext_resource path="res://addons/dialogic/Images/open-icon.svg" type="Texture" id=9]
1212
[ext_resource path="res://addons/dialogic/Images/closed-icon.svg" type="Texture" id=10]
1313
[ext_resource path="res://addons/dialogic/Images/portraits/df-1.png" type="Texture" id=11]
14+
[ext_resource path="res://addons/dialogic/Images/change-scene.svg" type="Texture" id=12]
1415

1516
[sub_resource type="StyleBoxFlat" id=1]
1617
content_margin_left = 5.0
@@ -121,26 +122,31 @@ __meta__ = {
121122
"_edit_use_anchors_": false
122123
}
123124

124-
[node name="EventTools" type="VBoxContainer" parent="Editor"]
125+
[node name="EventTools" type="VSplitContainer" parent="Editor"]
125126
margin_right = 180.0
126127
margin_bottom = 541.0
127128
rect_min_size = Vector2( 180, 0 )
128129

129-
[node name="Label" type="Label" parent="Editor/EventTools"]
130+
[node name="VBoxContainer2" type="VBoxContainer" parent="Editor/EventTools"]
131+
margin_right = 180.0
132+
margin_bottom = 180.0
133+
size_flags_vertical = 3
134+
135+
[node name="Label" type="Label" parent="Editor/EventTools/VBoxContainer2"]
130136
margin_right = 180.0
131137
margin_bottom = 14.0
132138
text = "Dialogs"
133139

134-
[node name="DialogItemList" type="ItemList" parent="Editor/EventTools"]
140+
[node name="DialogItemList" type="ItemList" parent="Editor/EventTools/VBoxContainer2"]
135141
margin_top = 18.0
136142
margin_right = 180.0
137-
margin_bottom = 270.0
143+
margin_bottom = 180.0
138144
size_flags_horizontal = 3
139145
size_flags_vertical = 3
140146
allow_rmb_select = true
141147

142148
[node name="VBoxContainer" type="VBoxContainer" parent="Editor/EventTools"]
143-
margin_top = 274.0
149+
margin_top = 192.0
144150
margin_right = 180.0
145151
margin_bottom = 541.0
146152
__meta__ = {
@@ -168,59 +174,81 @@ text = " Scene Event"
168174
icon = ExtResource( 4 )
169175
align = 0
170176

171-
[node name="ButtonAudio" type="Button" parent="Editor/EventTools/VBoxContainer"]
177+
[node name="ButtonChangeScene" type="Button" parent="Editor/EventTools/VBoxContainer"]
172178
margin_top = 82.0
173179
margin_right = 180.0
174180
margin_bottom = 110.0
181+
text = " Change Scene"
182+
icon = ExtResource( 12 )
183+
align = 0
184+
185+
[node name="ButtonAudio" type="Button" parent="Editor/EventTools/VBoxContainer"]
186+
margin_top = 114.0
187+
margin_right = 180.0
188+
margin_bottom = 142.0
175189
text = " Audio Event"
176190
icon = ExtResource( 8 )
177191
align = 0
178192

179193
[node name="ButtonCharacterJoin" type="Button" parent="Editor/EventTools/VBoxContainer"]
180-
margin_top = 114.0
194+
margin_top = 146.0
181195
margin_right = 180.0
182-
margin_bottom = 142.0
196+
margin_bottom = 174.0
183197
text = " Character Join"
184198
icon = ExtResource( 3 )
185199
align = 0
186200

187201
[node name="ButtonCharacterLeave" type="Button" parent="Editor/EventTools/VBoxContainer"]
188-
margin_top = 146.0
202+
margin_top = 178.0
189203
margin_right = 180.0
190-
margin_bottom = 174.0
204+
margin_bottom = 206.0
191205
text = " Character Leave"
192206
icon = ExtResource( 5 )
193207
align = 0
194208

195209
[node name="Separator" type="Panel" parent="Editor/EventTools/VBoxContainer"]
196210
self_modulate = Color( 1, 1, 1, 0 )
197-
margin_top = 178.0
211+
margin_top = 210.0
198212
margin_right = 180.0
199-
margin_bottom = 185.065
213+
margin_bottom = 217.065
200214
rect_min_size = Vector2( 0, 7.065 )
201215

202216
[node name="LabelNodes" type="Label" parent="Editor/EventTools/VBoxContainer"]
203-
margin_top = 189.0
217+
margin_top = 221.0
204218
margin_right = 180.0
205-
margin_bottom = 203.0
219+
margin_bottom = 235.0
206220
text = "View"
207221

208222
[node name="ButtonFold" type="Button" parent="Editor/EventTools/VBoxContainer"]
209-
margin_top = 207.0
223+
margin_top = 239.0
210224
margin_right = 180.0
211-
margin_bottom = 235.0
225+
margin_bottom = 267.0
212226
text = "Fold all"
213227
icon = ExtResource( 10 )
214228
align = 0
215229

216230
[node name="ButtonUnfold" type="Button" parent="Editor/EventTools/VBoxContainer"]
217-
margin_top = 239.0
231+
margin_top = 271.0
218232
margin_right = 180.0
219-
margin_bottom = 267.0
233+
margin_bottom = 299.0
220234
text = "Unfold all"
221235
icon = ExtResource( 9 )
222236
align = 0
223237

238+
[node name="LabelNodes2" type="Label" parent="Editor/EventTools/VBoxContainer"]
239+
margin_top = 303.0
240+
margin_right = 180.0
241+
margin_bottom = 317.0
242+
text = "Other"
243+
244+
[node name="ButtonGDScript" type="Button" parent="Editor/EventTools/VBoxContainer"]
245+
margin_top = 321.0
246+
margin_right = 180.0
247+
margin_bottom = 349.0
248+
text = " GDScript"
249+
icon = ExtResource( 6 )
250+
align = 0
251+
224252
[node name="EventEditor" type="ScrollContainer" parent="Editor"]
225253
margin_left = 192.0
226254
margin_right = 997.0
@@ -459,19 +487,23 @@ margin_bottom = 52.7127
459487
__meta__ = {
460488
"_edit_use_anchors_": false
461489
}
490+
491+
[node name="AudioPreview" type="AudioStreamPlayer2D" parent="."]
462492
[connection signal="pressed" from="HBoxContainer/EventButton" to="." method="_on_EventButton_pressed"]
463493
[connection signal="pressed" from="HBoxContainer/CharactersButton" to="." method="_on_CharactersButton_pressed"]
464494
[connection signal="pressed" from="HBoxContainer/ButtonSave" to="." method="_on_ButtonSave_pressed"]
465495
[connection signal="pressed" from="HBoxContainer/ReloadResource" to="." method="_on_ReloadResource_pressed"]
466-
[connection signal="item_rmb_selected" from="Editor/EventTools/DialogItemList" to="." method="_on_DialogItemList_item_rmb_selected"]
467-
[connection signal="item_selected" from="Editor/EventTools/DialogItemList" to="." method="_on_DialogItemList_item_selected"]
496+
[connection signal="item_rmb_selected" from="Editor/EventTools/VBoxContainer2/DialogItemList" to="." method="_on_DialogItemList_item_rmb_selected"]
497+
[connection signal="item_selected" from="Editor/EventTools/VBoxContainer2/DialogItemList" to="." method="_on_DialogItemList_item_selected"]
468498
[connection signal="pressed" from="Editor/EventTools/VBoxContainer/ButtonText" to="." method="_on_ButtonText_pressed"]
469499
[connection signal="pressed" from="Editor/EventTools/VBoxContainer/ButtonBackground" to="." method="_on_ButtonBackground_pressed"]
500+
[connection signal="pressed" from="Editor/EventTools/VBoxContainer/ButtonChangeScene" to="." method="_on_ButtonBackground_pressed"]
470501
[connection signal="pressed" from="Editor/EventTools/VBoxContainer/ButtonAudio" to="." method="_on_ButtonAudio_pressed"]
471502
[connection signal="pressed" from="Editor/EventTools/VBoxContainer/ButtonCharacterJoin" to="." method="_on_ButtonCharacter_pressed"]
472503
[connection signal="pressed" from="Editor/EventTools/VBoxContainer/ButtonCharacterLeave" to="." method="_on_ButtonCharacterLeave_pressed"]
473504
[connection signal="pressed" from="Editor/EventTools/VBoxContainer/ButtonFold" to="." method="_on_ButtonFold_pressed"]
474505
[connection signal="pressed" from="Editor/EventTools/VBoxContainer/ButtonUnfold" to="." method="_on_ButtonUnfold_pressed"]
506+
[connection signal="pressed" from="Editor/EventTools/VBoxContainer/ButtonGDScript" to="." method="_on_ButtonBackground_pressed"]
475507
[connection signal="pressed" from="Editor/CharacterTools/Button" to="." method="_on_Button_pressed"]
476508
[connection signal="item_selected" from="Editor/CharacterTools/CharacterItemList" to="." method="_on_ItemList_item_selected"]
477509
[connection signal="pressed" from="Editor/CharacterEditor/HBoxContainer/Container/Actions/SaveButton" to="." method="_on_character_SaveButton_pressed"]

addons/dialogic/Editor/Pieces/AudioBlock.gd

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ extends PanelContainer
44
var editor_reference
55
var editorPopup
66

7+
var play_button_state = 'stopped'
8+
79
# This is the information of this event and it will get parsed and saved to the JSON file.
810
var event_data = {
911
'audio': 'play',
@@ -12,3 +14,39 @@ var event_data = {
1214

1315
func _ready():
1416
$VBoxContainer/Header/VisibleToggle.disabled()
17+
18+
19+
func _on_ButtonAudio_pressed():
20+
var file_dialog = editor_reference.godot_dialog()
21+
file_dialog.add_filter("*.wav, *.ogg")
22+
editor_reference.godot_dialog_connect(self, "_on_file_selected")
23+
24+
func _on_file_selected(path, target):
25+
print('load_audio', path, target)
26+
target.load_audio(path)
27+
28+
func load_audio(path):
29+
$VBoxContainer/Header/Title.text = path
30+
$VBoxContainer/Header/ButtonPreviewPlay.disabled = false
31+
event_data['file'] = path
32+
print(path)
33+
34+
35+
func load_data(data):
36+
event_data = data
37+
if data['file'] != '':
38+
load_audio(data['file'])
39+
40+
func _on_ButtonPreviewPlay_pressed():
41+
print(editor_reference.get_node("AudioPreview"))
42+
43+
# It seems like you can't play audio on the editor.
44+
if play_button_state == 'playing':
45+
editor_reference.get_node("AudioPreview").stop()
46+
play_button_state == 'stopped'
47+
else:
48+
var audio_preview = editor_reference.get_node("AudioPreview")
49+
var audio_file = load(event_data['file'])
50+
audio_preview.stream = audio_file
51+
editor_reference.get_node("AudioPreview").play()
52+
play_button_state == 'playing'

addons/dialogic/Editor/Pieces/AudioBlock.tscn

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
[gd_scene load_steps=6 format=2]
1+
[gd_scene load_steps=7 format=2]
22

33
[ext_resource path="res://addons/dialogic/Editor/Pieces/AudioBlock.gd" type="Script" id=1]
44
[ext_resource path="res://addons/dialogic/Editor/Pieces/Common/VisibleToggle.tscn" type="PackedScene" id=2]
55
[ext_resource path="res://addons/dialogic/Images/audio-event.svg" type="Texture" id=3]
66
[ext_resource path="res://addons/dialogic/Editor/Pieces/Common/PieceExtraSettings.tscn" type="PackedScene" id=4]
7+
[ext_resource path="res://addons/dialogic/Images/play.svg" type="Texture" id=5]
78

89
[sub_resource type="StyleBoxFlat" id=1]
910
content_margin_left = 6.0
@@ -55,15 +56,18 @@ margin_right = 117.0
5556
margin_bottom = 22.0
5657
text = " Audio "
5758

58-
[node name="MenuButton" type="MenuButton" parent="VBoxContainer/Header"]
59+
[node name="ButtonAudio" type="Button" parent="VBoxContainer/Header"]
5960
margin_left = 121.0
60-
margin_right = 221.0
61+
margin_right = 145.0
6162
margin_bottom = 30.0
62-
rect_min_size = Vector2( 100, 0 )
63-
text = "[All]"
64-
flat = false
65-
align = 0
66-
items = [ "All", null, 0, false, false, 0, 0, null, "", false ]
63+
text = "..."
64+
65+
[node name="ButtonPreviewPlay" type="Button" parent="VBoxContainer/Header"]
66+
margin_left = 149.0
67+
margin_right = 183.0
68+
margin_bottom = 30.0
69+
disabled = true
70+
icon = ExtResource( 5 )
6771

6872
[node name="Preview" type="Label" parent="VBoxContainer/Header"]
6973
visible = false
@@ -75,10 +79,12 @@ custom_colors/font_color = Color( 1, 1, 1, 0.513726 )
7579
text = " ..."
7680

7781
[node name="Spacer" type="Control" parent="VBoxContainer/Header"]
78-
margin_left = 225.0
82+
margin_left = 187.0
7983
margin_right = 1745.0
8084
margin_bottom = 30.0
8185
size_flags_horizontal = 3
8286

8387
[node name="OptionButton" parent="VBoxContainer/Header" instance=ExtResource( 4 )]
8488
items = [ "Move Up", null, 0, false, false, 0, 0, null, "", false, "Move Down", null, 0, false, false, 1, 0, null, "", false, "", null, 0, false, false, 2, 0, null, "", true, "Remove", null, 0, false, false, 3, 0, null, "", false ]
89+
[connection signal="pressed" from="VBoxContainer/Header/ButtonAudio" to="." method="_on_ButtonAudio_pressed"]
90+
[connection signal="pressed" from="VBoxContainer/Header/ButtonPreviewPlay" to="." method="_on_ButtonPreviewPlay_pressed"]

addons/dialogic/Editor/Pieces/CharacterLeaveBlock.gd

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ tool
22
extends PanelContainer
33

44
var editor_reference
5-
var editorPopup
65
var character_selected = ''
76

87
# This is the information of this event and it will get parsed and saved to the JSON file.
@@ -13,3 +12,29 @@ var event_data = {
1312

1413
func _ready():
1514
$VBoxContainer/Header/VisibleToggle.disabled()
15+
$VBoxContainer/Header/CharacterDropdown.get_popup().connect("index_pressed", self, '_on_character_selected')
16+
17+
18+
func _on_MenuButton_about_to_show():
19+
var Dropdown = $VBoxContainer/Header/CharacterDropdown
20+
Dropdown.get_popup().clear()
21+
Dropdown.get_popup().add_item("[All]")
22+
var index = 0
23+
for c in editor_reference.get_character_list():
24+
Dropdown.get_popup().add_item(c['name'])
25+
Dropdown.get_popup().set_item_metadata(index, {'file': c['file'], 'color': c['color']})
26+
index += 1
27+
28+
func _on_character_selected(index):
29+
var text = $VBoxContainer/Header/CharacterDropdown.get_popup().get_item_text(index)
30+
var metadata = $VBoxContainer/Header/CharacterDropdown.get_popup().get_item_metadata(index)
31+
$VBoxContainer/Header/CharacterDropdown.text = text
32+
event_data['character'] = metadata['file']
33+
34+
func load_data(data):
35+
event_data = data
36+
if data['character'] != '[All]':
37+
if data['character'] != '':
38+
var character_data = editor_reference.get_character_data(data['character'])
39+
if character_data.has('name'):
40+
$VBoxContainer/Header/CharacterDropdown.text = character_data['name']

addons/dialogic/Editor/Pieces/CharacterLeaveBlock.tscn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ margin_right = 169.0
5555
margin_bottom = 22.0
5656
text = " Character Leave"
5757

58-
[node name="MenuButton" type="MenuButton" parent="VBoxContainer/Header"]
58+
[node name="CharacterDropdown" type="MenuButton" parent="VBoxContainer/Header"]
5959
margin_left = 173.0
6060
margin_right = 273.0
6161
margin_bottom = 30.0
@@ -82,3 +82,4 @@ size_flags_horizontal = 3
8282

8383
[node name="OptionButton" parent="VBoxContainer/Header" instance=ExtResource( 4 )]
8484
items = [ "Move Up", null, 0, false, false, 0, 0, null, "", false, "Move Down", null, 0, false, false, 1, 0, null, "", false, "", null, 0, false, false, 2, 0, null, "", true, "Remove", null, 0, false, false, 3, 0, null, "", false ]
85+
[connection signal="about_to_show" from="VBoxContainer/Header/CharacterDropdown" to="." method="_on_MenuButton_about_to_show"]

addons/dialogic/Editor/Pieces/SceneBlock.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ func _ready():
1818
func _on_ImageButton_pressed():
1919
var file_dialog = editor_reference.godot_dialog()
2020
file_dialog.add_filter("*.png, *.jpg, *.jpeg, *.tga, *.svg, *.svgz, *.bmp, *.webp;Image")
21-
file_dialog.connect("file_selected", self, "_on_file_selected", [self])
21+
#file_dialog.connect("file_selected", self, "_on_file_selected", [self])
22+
editor_reference.godot_dialog_connect(self, "_on_file_selected")
23+
2224

2325
func _on_file_selected(path, target):
2426
print('here')

0 commit comments

Comments
 (0)