1 class_name DialogicNode_ButtonSound
2 extends AudioStreamPlayer
4 ## Node that is used for playing sound effects on hover/focus/press of sibling DialogicNode_ChoiceButtons.
6 ## Sound to be played if one of the sibling ChoiceButtons is pressed.
7 ## If sibling ChoiceButton has a sound_pressed set, that is prioritized.
8 @export var sound_pressed: AudioStream
9 ## Sound to be played on hover. See [sound_pressed] for more.
10 @export var sound_hover: AudioStream
11 ## Sound to be played on focus. See [sound_pressed] for more.
12 @export var sound_focus: AudioStream
14 func _ready() -> void:
15 add_to_group('dialogic_button_sound')
16 _connect_all_buttons()
19 func play_sound(sound) -> void:
24 func _connect_all_buttons() -> void:
25 for child in get_parent().get_children():
26 if child is DialogicNode_ChoiceButton:
27 child.button_up.connect(_on_pressed.bind(child.sound_pressed))
28 child.mouse_entered.connect(_on_hover.bind(child.sound_hover))
29 child.focus_entered.connect(_on_focus.bind(child.sound_focus))
32 #the custom_sound argument comes from the specifec button and get used
33 #if none are found, it uses the above sounds
35 func _on_pressed(custom_sound) -> void:
36 if custom_sound != null:
37 play_sound(custom_sound)
39 play_sound(sound_pressed)
41 func _on_hover(custom_sound) -> void:
42 if custom_sound != null:
43 play_sound(custom_sound)
45 play_sound(sound_hover)
47 func _on_focus(custom_sound) -> void:
48 if custom_sound != null:
49 play_sound(custom_sound)
51 play_sound(sound_focus)