diff options
author | George L. Albany <Megacake1234@gmail.com> | 2023-02-27 17:26:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-27 17:26:54 +0100 |
commit | 2062aaf394ee6581161add4bcb23076475e236ac (patch) | |
tree | adb1a6e5fe4c7d06c778188961a6e660ee911413 /game/src/Utility | |
parent | 150c11376765af5dc0c180de9cf7bbcc8fa9b99b (diff) |
Refactor SFX into a SoundManager (#45)
* Refactor SFX into a SoundManager
Add SoundManager able to play arbitrary sound streams
Make SoundManager use only one AudioStreamPlayer per bus
Add StyleBoxWithSound
Add Kenney UI Audio click3.wav
Removed sound play via pressed signals in MainMenu
Make Button_MainMenu pressed style StyleBoxWithSound with click3.wav sound
* Add playing mp3 files by name to the SoundManager
* Fix missing quotation
Diffstat (limited to 'game/src/Utility')
-rw-r--r-- | game/src/Utility/StyleBoxWithSound.gd | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/game/src/Utility/StyleBoxWithSound.gd b/game/src/Utility/StyleBoxWithSound.gd new file mode 100644 index 0000000..8de1af1 --- /dev/null +++ b/game/src/Utility/StyleBoxWithSound.gd @@ -0,0 +1,33 @@ +@tool +extends StyleBox +class_name StyleBoxWithSound + +@export +var style_box : StyleBox: + get: return style_box + set(v): + style_box = v + emit_changed() + +@export +var sound : AudioStream: + get: return sound + set(v): + sound = v + emit_changed() + +func _get_draw_rect(rect : Rect2) -> Rect2: + if style_box == null: return Rect2() + return style_box._get_draw_rect(rect) + +func _draw(to_canvas_item : RID, rect : Rect2) -> void: + # This is a hack + # Works fine for simple non-normal style cases + # Normal styles being drawn immediately tho will trigger sound on startup + # This would require further work to be applicable for release sounds + # Is there any other reason aside from release sounds (might be useful for toggles?) + # This should be fast enough to not cause draw issues + if sound != null: + SoundManager.play_effect_stream(sound) + if style_box != null: + style_box.draw(to_canvas_item, rect) |