Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(AudioTheme): add support for audio/sfx themes #356

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions assets/audio/themes/default.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="Resource" script_class="AudioTheme" load_steps=2 format=3 uid="uid://d70xost7hk1i"]

[ext_resource type="Script" path="res://core/systems/audio/audio_theme.gd" id="1_7ff30"]

[resource]
script = ExtResource("1_7ff30")
intro = ""
focus = "res://assets/audio/interface/536764__egomassive__toss.ogg"
select = "res://assets/audio/interface/96127__bmaczero__contact1.ogg"
open_menu = ""
1 change: 1 addition & 0 deletions assets/editor-icons/icon-park-outline--sound-wave.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions assets/editor-icons/icon-park-outline--sound-wave.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://brtu0g62ohgn1"
path="res://.godot/imported/icon-park-outline--sound-wave.svg-6694d7867012105e482585279d7a4c37.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/editor-icons/icon-park-outline--sound-wave.svg"
dest_files=["res://.godot/imported/icon-park-outline--sound-wave.svg-6694d7867012105e482585279d7a4c37.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
75 changes: 75 additions & 0 deletions core/systems/audio/audio_theme.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
@icon("res://assets/editor-icons/icon-park-outline--sound-wave.svg")
extends Resource
class_name AudioTheme

## Resource for customizing the UI audio sounds

@export_category("General")
## Unique name of the audio theme
@export var name: String

@export_category("Global")
## Sounds to play when OpenGamepadUI first launches
@export_file("*.ogg") var intro := ""
## Sound to play when volume is increased
@export_file("*.ogg") var audio_volume_up := ""
## Sound to play when volume is decreased
@export_file("*.ogg") var audio_volume_down := ""
## Ambient background music to play in menus
@export_file("*.ogg") var ambient_music := ""
## Sound to play when a notification is displayed
@export_file("*.ogg") var notification_display := ""

@export_category("Side Menus")
## Sound to play when side menus (Main menu and QB menu) open
@export_file("*.ogg") var side_menu_open := ""
## Sound to play when side menus (Main menu and QB menu) close
@export_file("*.ogg") var side_menu_close := ""

@export_category("Button")
## Sound to play when button is focused
@export_file("*.ogg") var button_focus := "res://assets/audio/interface/536764__egomassive__toss.ogg"
## Sound to play when button is selected
@export_file("*.ogg") var button_select := "res://assets/audio/interface/96127__bmaczero__contact1.ogg"

@export_category("Slider")
## Sound to play when slider is focused
@export_file("*.ogg") var slider_focus := "res://assets/audio/interface/536764__egomassive__toss.ogg"
## Sound to play when slider value changes
@export_file("*.ogg") var slider_change := ""

@export_category("Toggle")
## Sound to play when toggle is focused
@export_file("*.ogg") var toggle_focus := "res://assets/audio/interface/536764__egomassive__toss.ogg"
## Sound to play when toggle value changes
@export_file("*.ogg") var toggle_change := ""

## Enumeration of all different components of an audio theme
enum TYPE {
INTRO,
AUDIO_VOLUME_UP,
AUDIO_VOLUME_DOWN,
AMBIENT_MUSIC,
NOTIFICATION_DISPLAY,
SIDE_MENU_OPEN,
SIDE_MENU_CLOSE,
BUTTON_FOCUS,
BUTTON_SELECT,
SLIDER_FOCUS,
SLIDER_CHANGE,
TOGGLE_FOCUS,
TOGGLE_CHANGE,
}

## Returns the loaded audio stream for the given audio theme component type
func get_stream(type: TYPE) -> AudioStream:
var path := ""
match type:
TYPE.INTRO:
path = intro
TYPE.AUDIO_VOLUME_UP:
path = audio_volume_up
TYPE.AUDIO_VOLUME_DOWN:
path = audio_volume_down

return null
45 changes: 45 additions & 0 deletions core/systems/effects/play_audio_theme_effect.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@tool
extends Effect
class_name PlayAudioThemeEffect

const DEFAULT_THEME := "res://assets/audio/themes/default.tres"

## The type of component that the audio theme should play
@export var type: AudioTheme.TYPE

@onready var theme := get_audio_theme()
@onready var audio_player := $AudioStreamPlayer as AudioStreamPlayer

func _ready() -> void:
var on_finished := func():
effect_finished.emit()
audio_player.finished.connect(on_finished)
audio_player.stream = stream


## Returns the audio theme
func get_audio_theme(current: Node = null) -> AudioTheme:
if not current:
current = self

# If the current node has an audio theme, return it
if current.has_meta("audio_theme"):
return current.get_meta("audio_theme")

# If this is the root node and no audio theme is defined, use the default
if current == get_node("/root"):
return load(DEFAULT_THEME)

# Otherwise try to get the parent node's audio theme
var parent := get_parent()

return get_audio_theme(parent)


# Fires when the given signal is emitted
func _on_signal():
play_sound()


func play_sound() -> void:
audio_player.play()
9 changes: 9 additions & 0 deletions core/systems/effects/play_audio_theme_effect.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3 uid="uid://djdvu2nxovgxv"]

[ext_resource type="Script" path="res://core/systems/effects/play_audio_theme_effect.gd" id="1_emgpn"]

[node name="PlayAudioThemeEffect" type="Node"]
script = ExtResource("1_emgpn")
on_signal = ""

[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
4 changes: 4 additions & 0 deletions core/systems/user_interface/audio_theme_setter.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@tool
@icon("res://assets/editor-icons/icon-park-outline--sound-wave.svg")
extends Node
class_name AudioThemeSetter
6 changes: 6 additions & 0 deletions core/systems/user_interface/audio_theme_setter.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://b2o7yd21t4wfg"]

[ext_resource type="Script" path="res://core/systems/user_interface/audio_theme_setter.gd" id="1_2f67i"]

[node name="AudioThemeSetter" type="Node"]
script = ExtResource("1_2f67i")
Loading