Skip to content

Commit dbdc807

Browse files
committed
feat(AudioTheme): add support for audio/sfx themes
1 parent 1fc541e commit dbdc807

8 files changed

Lines changed: 187 additions & 0 deletions

File tree

assets/audio/themes/default.tres

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[gd_resource type="Resource" script_class="AudioTheme" load_steps=2 format=3 uid="uid://d70xost7hk1i"]
2+
3+
[ext_resource type="Script" path="res://core/systems/audio/audio_theme.gd" id="1_7ff30"]
4+
5+
[resource]
6+
script = ExtResource("1_7ff30")
7+
intro = ""
8+
focus = "res://assets/audio/interface/536764__egomassive__toss.ogg"
9+
select = "res://assets/audio/interface/96127__bmaczero__contact1.ogg"
10+
open_menu = ""
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://brtu0g62ohgn1"
6+
path="res://.godot/imported/icon-park-outline--sound-wave.svg-6694d7867012105e482585279d7a4c37.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://assets/editor-icons/icon-park-outline--sound-wave.svg"
14+
dest_files=["res://.godot/imported/icon-park-outline--sound-wave.svg-6694d7867012105e482585279d7a4c37.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/hdr_compression=1
22+
compress/normal_map=0
23+
compress/channel_pack=0
24+
mipmaps/generate=false
25+
mipmaps/limit=-1
26+
roughness/mode=0
27+
roughness/src_normal=""
28+
process/fix_alpha_border=true
29+
process/premult_alpha=false
30+
process/normal_map_invert_y=false
31+
process/hdr_as_srgb=false
32+
process/hdr_clamp_exposure=false
33+
process/size_limit=0
34+
detect_3d/compress_to=1
35+
svg/scale=1.0
36+
editor/scale_with_editor_scale=false
37+
editor/convert_colors_with_editor_theme=false

core/systems/audio/audio_theme.gd

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
@icon("res://assets/editor-icons/icon-park-outline--sound-wave.svg")
2+
extends Resource
3+
class_name AudioTheme
4+
5+
## Resource for customizing the UI audio sounds
6+
7+
@export_category("General")
8+
## Unique name of the audio theme
9+
@export var name: String
10+
11+
@export_category("Global")
12+
## Sounds to play when OpenGamepadUI first launches
13+
@export_file("*.ogg") var intro := ""
14+
## Sound to play when volume is increased
15+
@export_file("*.ogg") var audio_volume_up := ""
16+
## Sound to play when volume is decreased
17+
@export_file("*.ogg") var audio_volume_down := ""
18+
## Ambient background music to play in menus
19+
@export_file("*.ogg") var ambient_music := ""
20+
## Sound to play when a notification is displayed
21+
@export_file("*.ogg") var notification_display := ""
22+
23+
@export_category("Side Menus")
24+
## Sound to play when side menus (Main menu and QB menu) open
25+
@export_file("*.ogg") var side_menu_open := ""
26+
## Sound to play when side menus (Main menu and QB menu) close
27+
@export_file("*.ogg") var side_menu_close := ""
28+
29+
@export_category("Button")
30+
## Sound to play when button is focused
31+
@export_file("*.ogg") var button_focus := "res://assets/audio/interface/536764__egomassive__toss.ogg"
32+
## Sound to play when button is selected
33+
@export_file("*.ogg") var button_select := "res://assets/audio/interface/96127__bmaczero__contact1.ogg"
34+
35+
@export_category("Slider")
36+
## Sound to play when slider is focused
37+
@export_file("*.ogg") var slider_focus := "res://assets/audio/interface/536764__egomassive__toss.ogg"
38+
## Sound to play when slider value changes
39+
@export_file("*.ogg") var slider_change := ""
40+
41+
@export_category("Toggle")
42+
## Sound to play when toggle is focused
43+
@export_file("*.ogg") var toggle_focus := "res://assets/audio/interface/536764__egomassive__toss.ogg"
44+
## Sound to play when toggle value changes
45+
@export_file("*.ogg") var toggle_change := ""
46+
47+
## Enumeration of all different components of an audio theme
48+
enum TYPE {
49+
INTRO,
50+
AUDIO_VOLUME_UP,
51+
AUDIO_VOLUME_DOWN,
52+
AMBIENT_MUSIC,
53+
NOTIFICATION_DISPLAY,
54+
SIDE_MENU_OPEN,
55+
SIDE_MENU_CLOSE,
56+
BUTTON_FOCUS,
57+
BUTTON_SELECT,
58+
SLIDER_FOCUS,
59+
SLIDER_CHANGE,
60+
TOGGLE_FOCUS,
61+
TOGGLE_CHANGE,
62+
}
63+
64+
## Returns the loaded audio stream for the given audio theme component type
65+
func get_stream(type: TYPE) -> AudioStream:
66+
var path := ""
67+
match type:
68+
TYPE.INTRO:
69+
path = intro
70+
TYPE.AUDIO_VOLUME_UP:
71+
path = audio_volume_up
72+
TYPE.AUDIO_VOLUME_DOWN:
73+
path = audio_volume_down
74+
75+
return null
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
@tool
2+
extends Effect
3+
class_name PlayAudioThemeEffect
4+
5+
const DEFAULT_THEME := "res://assets/audio/themes/default.tres"
6+
7+
## The type of component that the audio theme should play
8+
@export var type: AudioTheme.TYPE
9+
10+
@onready var theme := get_audio_theme()
11+
@onready var audio_player := $AudioStreamPlayer as AudioStreamPlayer
12+
13+
func _ready() -> void:
14+
var on_finished := func():
15+
effect_finished.emit()
16+
audio_player.finished.connect(on_finished)
17+
audio_player.stream = stream
18+
19+
20+
## Returns the audio theme
21+
func get_audio_theme(current: Node = null) -> AudioTheme:
22+
if not current:
23+
current = self
24+
25+
# If the current node has an audio theme, return it
26+
if current.has_meta("audio_theme"):
27+
return current.get_meta("audio_theme")
28+
29+
# If this is the root node and no audio theme is defined, use the default
30+
if current == get_node("/root"):
31+
return load(DEFAULT_THEME)
32+
33+
# Otherwise try to get the parent node's audio theme
34+
var parent := get_parent()
35+
36+
return get_audio_theme(parent)
37+
38+
39+
# Fires when the given signal is emitted
40+
func _on_signal():
41+
play_sound()
42+
43+
44+
func play_sound() -> void:
45+
audio_player.play()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://djdvu2nxovgxv"]
2+
3+
[ext_resource type="Script" path="res://core/systems/effects/play_audio_theme_effect.gd" id="1_emgpn"]
4+
5+
[node name="PlayAudioThemeEffect" type="Node"]
6+
script = ExtResource("1_emgpn")
7+
on_signal = ""
8+
9+
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@tool
2+
@icon("res://assets/editor-icons/icon-park-outline--sound-wave.svg")
3+
extends Node
4+
class_name AudioThemeSetter
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://b2o7yd21t4wfg"]
2+
3+
[ext_resource type="Script" path="res://core/systems/user_interface/audio_theme_setter.gd" id="1_2f67i"]
4+
5+
[node name="AudioThemeSetter" type="Node"]
6+
script = ExtResource("1_2f67i")

0 commit comments

Comments
 (0)