diff options
author | George L. Albany <Megacake1234@gmail.com> | 2023-06-04 02:17:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-04 02:17:28 +0200 |
commit | 3236f51d700674aee6ee6572109ffb3d5fa5fed2 (patch) | |
tree | b898150a8a45e7c0d814459e7f12f39429acefeb /game/src/Game/Theme/StyleBoxWithSound.gd | |
parent | 73e29d02e48739aba5ca5db1b9575c67e795400f (diff) | |
parent | b98166b28c47cccff731d30959b8250fb27ff408 (diff) |
Merge pull request #130 from Spartan322/organize/godot-project
Diffstat (limited to 'game/src/Game/Theme/StyleBoxWithSound.gd')
-rw-r--r-- | game/src/Game/Theme/StyleBoxWithSound.gd | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/game/src/Game/Theme/StyleBoxWithSound.gd b/game/src/Game/Theme/StyleBoxWithSound.gd new file mode 100644 index 0000000..8c29b34 --- /dev/null +++ b/game/src/Game/Theme/StyleBoxWithSound.gd @@ -0,0 +1,34 @@ +## WARNING: This will not work with togglable UI elements, a special implementation is needed for them. +@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) |