From 2062aaf394ee6581161add4bcb23076475e236ac Mon Sep 17 00:00:00 2001 From: "George L. Albany" Date: Mon, 27 Feb 2023 11:26:54 -0500 Subject: 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 --- game/src/Utility/StyleBoxWithSound.gd | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 game/src/Utility/StyleBoxWithSound.gd (limited to 'game/src/Utility/StyleBoxWithSound.gd') 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) -- cgit v1.2.3-56-ga3b1