]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/Choice/node_button_sound.gd
Initial Godot project with Dialogic 2.0-Alpha-17
[wolf-seeking-sheep.git] / addons / dialogic / Modules / Choice / node_button_sound.gd
1 class_name DialogicNode_ButtonSound
2 extends AudioStreamPlayer
3
4 ## Node that is used for playing sound effects on hover/focus/press of sibling DialogicNode_ChoiceButtons.
5
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
13
14 func _ready() -> void:
15         add_to_group('dialogic_button_sound')
16         _connect_all_buttons()
17
18 #basic play sound
19 func play_sound(sound) -> void:
20         if sound != null:
21                 stream = sound
22                 play()
23
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))
30
31
32 #the custom_sound argument comes from the specifec button and get used
33 #if none are found, it uses the above sounds
34
35 func _on_pressed(custom_sound) -> void:
36         if custom_sound != null:
37                 play_sound(custom_sound)
38         else:
39                 play_sound(sound_pressed)
40
41 func _on_hover(custom_sound) -> void:
42         if custom_sound != null:
43                 play_sound(custom_sound)
44         else:
45                 play_sound(sound_hover)
46
47 func _on_focus(custom_sound) -> void:
48         if custom_sound != null:
49                 play_sound(custom_sound)
50         else:
51                 play_sound(sound_focus)
52