-
-
Notifications
You must be signed in to change notification settings - Fork 329
Expand file tree
/
Copy pathnode_button_sound.gd
More file actions
55 lines (43 loc) · 1.61 KB
/
node_button_sound.gd
File metadata and controls
55 lines (43 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class_name DialogicNode_ButtonSound
extends AudioStreamPlayer
## Node that is used for playing sound effects on hover/focus/press of sibling DialogicNode_ChoiceButtons.
## Sound to be played if one of the sibling ChoiceButtons is pressed.
## If sibling ChoiceButton has a sound_pressed set, that is prioritized.
@export var sound_pressed: AudioStream
## Sound to be played on hover. See [sound_pressed] for more.
@export var sound_hover: AudioStream
## Sound to be played on focus. See [sound_pressed] for more.
@export var sound_focus: AudioStream
func _ready() -> void:
add_to_group('dialogic_button_sound')
_connect_all_buttons()
if bus == "Master":
bus = ProjectSettings.get_setting("dialogic/audio/type_sound_bus", "Master")
#basic play sound
func play_sound(sound) -> void:
if sound != null:
stream = sound
play()
func _connect_all_buttons() -> void:
for child in get_parent().get_children():
if child is DialogicNode_ChoiceButton:
child.button_up.connect(_on_pressed.bind(child.sound_pressed))
child.mouse_entered.connect(_on_hover.bind(child.sound_hover))
child.focus_entered.connect(_on_focus.bind(child.sound_focus))
#the custom_sound argument comes from the specifec button and get used
#if none are found, it uses the above sounds
func _on_pressed(custom_sound) -> void:
if custom_sound != null:
play_sound(custom_sound)
else:
play_sound(sound_pressed)
func _on_hover(custom_sound) -> void:
if custom_sound != null:
play_sound(custom_sound)
else:
play_sound(sound_hover)
func _on_focus(custom_sound) -> void:
if custom_sound != null:
play_sound(custom_sound)
else:
play_sound(sound_focus)