Skip to content

Commit

Permalink
Add UI sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
rsubtil committed Oct 20, 2023
1 parent 5b4b8cd commit fabaa6f
Show file tree
Hide file tree
Showing 27 changed files with 397 additions and 3 deletions.
2 changes: 2 additions & 0 deletions addons/onscreenkeyboard/onscreen_keyboard.gd
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ func _keyReleased(keyData,x,y,steal_focus):
# Manually disable ControllerIcons for this event
ControllerIcons.set_process_input(false)
focused_control.get_viewport().push_input(inputEventKey)
RetroHubUI.play_sound(RetroHubUI.AudioKeys.KEYBOARD_TYPE)
await get_tree().process_frame
ControllerIcons.set_process_input(true)
sendingEvent = false
Expand Down Expand Up @@ -392,6 +393,7 @@ func _createKeyboard(layoutData):

for key in row.get("keys"):
var newKey = KeyboardButton.new(key)
newKey.add_to_group("rh_no_sound")
newKey.expand_icon = true
newKey.show_only = 2
newKey.force_type = 2
Expand Down
Binary file added assets/sounds/activated.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions assets/sounds/activated.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://clfdu47ojusjw"
path="res://.godot/imported/activated.wav-80784ac0f2e40aa083be55db567490eb.sample"

[deps]

source_file="res://assets/sounds/activated.wav"
dest_files=["res://.godot/imported/activated.wav-80784ac0f2e40aa083be55db567490eb.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file added assets/sounds/check_button_off.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions assets/sounds/check_button_off.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://bn4xv1p7ct8st"
path="res://.godot/imported/check_button_off.wav-f0ad78bffc0f1d6fd87cca548be27ce3.sample"

[deps]

source_file="res://assets/sounds/check_button_off.wav"
dest_files=["res://.godot/imported/check_button_off.wav-f0ad78bffc0f1d6fd87cca548be27ce3.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file added assets/sounds/check_button_on.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions assets/sounds/check_button_on.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://df62ut2d2685r"
path="res://.godot/imported/check_button_on.wav-203cc82bfe807ea907411b4f182b822c.sample"

[deps]

source_file="res://assets/sounds/check_button_on.wav"
dest_files=["res://.godot/imported/check_button_on.wav-203cc82bfe807ea907411b4f182b822c.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file added assets/sounds/keyboard_type.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions assets/sounds/keyboard_type.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://bptkigalw24jj"
path="res://.godot/imported/keyboard_type.wav-8435c6a2bd7e884f7bae615ed3c0083d.sample"

[deps]

source_file="res://assets/sounds/keyboard_type.wav"
dest_files=["res://.godot/imported/keyboard_type.wav-8435c6a2bd7e884f7bae615ed3c0083d.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file added assets/sounds/menu_enter.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions assets/sounds/menu_enter.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://dd0wa5cke1khq"
path="res://.godot/imported/menu_enter.wav-69236535a27d7c1c7d294257e7be5d78.sample"

[deps]

source_file="res://assets/sounds/menu_enter.wav"
dest_files=["res://.godot/imported/menu_enter.wav-69236535a27d7c1c7d294257e7be5d78.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file added assets/sounds/menu_in.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions assets/sounds/menu_in.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://bcbxk787uk8k"
path="res://.godot/imported/menu_in.wav-b9c5bc0d4cd5091fa979e2e11825a485.sample"

[deps]

source_file="res://assets/sounds/menu_in.wav"
dest_files=["res://.godot/imported/menu_in.wav-b9c5bc0d4cd5091fa979e2e11825a485.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file added assets/sounds/menu_out.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions assets/sounds/menu_out.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://c0jpymqokjhyy"
path="res://.godot/imported/menu_out.wav-74088d61e57119f588af805c5b94ae90.sample"

[deps]

source_file="res://assets/sounds/menu_out.wav"
dest_files=["res://.godot/imported/menu_out.wav-74088d61e57119f588af805c5b94ae90.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file added assets/sounds/navigation.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions assets/sounds/navigation.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://p2vfsyryyj1u"
path="res://.godot/imported/navigation.wav-a0b9e90b752cdf0c55f4d6119fb625cc.sample"

[deps]

source_file="res://assets/sounds/navigation.wav"
dest_files=["res://.godot/imported/navigation.wav-a0b9e90b752cdf0c55f4d6119fb625cc.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file added assets/sounds/slide.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions assets/sounds/slide.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://dcq2krgqvta88"
path="res://.godot/imported/slide.wav-a4710d6d2fb8d67d9eea570dabd0e87e.sample"

[deps]

source_file="res://assets/sounds/slide.wav"
dest_files=["res://.godot/imported/slide.wav-a4710d6d2fb8d67d9eea570dabd0e87e.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file added assets/sounds/slider_tick.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions assets/sounds/slider_tick.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://dvolya7k5qbgr"
path="res://.godot/imported/slider_tick.wav-b6504e41620b75a1e7c21edca4ba5e18.sample"

[deps]

source_file="res://assets/sounds/slider_tick.wav"
dest_files=["res://.godot/imported/slider_tick.wav-b6504e41620b75a1e7c21edca4ba5e18.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
9 changes: 9 additions & 0 deletions default_bus_layout.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[gd_resource type="AudioBusLayout" format=3 uid="uid://bases5wqfieka"]

[resource]
bus/1/name = &"[RetroHub] UI Sounds"
bus/1/solo = false
bus/1/mute = false
bus/1/bypass_fx = false
bus/1/volume_db = 0.0
bus/1/send = &"Master"
2 changes: 1 addition & 1 deletion scenes/config/ConfigPopup.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ theme_override_constants/margin_top = 7
theme_override_constants/margin_right = 7
theme_override_constants/margin_bottom = 7

[node name="SettingsTab" type="TabContainer" parent="Panel/HBoxContainer/MarginContainer"]
[node name="SettingsTab" type="TabContainer" parent="Panel/HBoxContainer/MarginContainer" groups=["rh_no_sound"]]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
Expand Down
8 changes: 6 additions & 2 deletions scenes/root/Root.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=3 uid="uid://c60kwat0su1y"]
[gd_scene load_steps=12 format=3 uid="uid://c60kwat0su1y"]

[ext_resource type="Script" path="res://scenes/root/Root.gd" id="1"]
[ext_resource type="Script" path="res://addons/onscreenkeyboard/onscreen_keyboard.gd" id="2"]
Expand All @@ -9,6 +9,7 @@
[ext_resource type="Script" path="res://addons/godot-accessibility/ScreenReader.gd" id="7"]
[ext_resource type="Script" path="res://source/utils/InputHandler.gd" id="9_5ltce"]
[ext_resource type="PackedScene" uid="uid://dmcmcyq0jach5" path="res://scenes/no_theme/NoTheme.tscn" id="10"]
[ext_resource type="Script" path="res://source/utils/UIAudio.gd" id="10_w3jne"]

[sub_resource type="ShaderMaterial" id="2"]
shader = ExtResource("5_co422")
Expand All @@ -29,6 +30,9 @@ process_mode = 3
script = ExtResource("7")
theme_viewport = NodePath("../SubViewportContainer/SubViewport")

[node name="UIAudio" type="Node" parent="."]
script = ExtResource("10_w3jne")

[node name="SubViewportContainer" type="SubViewportContainer" parent="."]
layout_mode = 0
anchor_right = 1.0
Expand Down Expand Up @@ -58,7 +62,7 @@ handle_input_locally = false
visible = false
content_scale_aspect = 4

[node name="Keyboard" type="Window" parent="."]
[node name="Keyboard" type="Window" parent="." groups=["rh_no_sound"]]
unique_name_in_owner = true
position = Vector2i(0, 648)
size = Vector2i(1152, 300)
Expand Down
35 changes: 35 additions & 0 deletions source/UI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ const max_popupmenu_height := 300

var _steamdeck_keyboard_up := false

enum AudioKeys {
ACTIVATED,
CHECK_BUTTON_OFF,
CHECK_BUTTON_ON,
KEYBOARD_TYPE,
MENU_ENTER,
MENU_IN,
MENU_OUT,
NAVIGATION,
SLIDE,
SLIDER_TICK,
}

@onready var audio_player := AudioStreamPlayer.new()
@onready var audio_player_low := AudioStreamPlayer.new()
var audio_streams : Array[AudioStream]

enum Icons {
DOWNLOADING,
ERROR,
Expand Down Expand Up @@ -52,6 +69,15 @@ func _input(event):
_steamdeck_keyboard_up = false
ControllerIcons.set_process_input(true)

func _ready():
add_child(audio_player)
add_child(audio_player_low)
audio_player.bus = "[RetroHub] UI Sounds"
audio_player_low.bus = "[RetroHub] UI Sounds"
for key in AudioKeys.keys():
var path = "res://assets/sounds/%s.wav" % key.to_lower()
audio_streams.push_back(load(path))

func _set_filesystem_popup(popup: FileDialog):
_n_filesystem_popup = popup
#warning-ignore:return_value_discarded
Expand Down Expand Up @@ -173,3 +199,12 @@ func get_true_focused_control() -> Control:
return viewport.gui_get_focus_owner()
viewport = viewport.get_top_popup_or_focused_window().get_viewport()
return get_viewport().gui_get_focus_owner()

func play_sound(key: AudioKeys, override : bool = true):
if override:
audio_player_low.stop()
audio_player.stream = audio_streams[key]
audio_player.play()
else:
audio_player_low.stream = audio_streams[key]
audio_player_low.play()
1 change: 1 addition & 0 deletions source/utils/TabContainerHandler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func _on_tab_clicked(tab_idx: int):
handle_focus(not _focused)

func handle_focus(enter_tab: bool):
RetroHubUI.play_sound(RetroHubUI.AudioKeys.SLIDE)
if signal_tab_change:
emit_signal("tab_changed", tab, enter_tab)
elif enter_tab and tab.get_current_tab_control().focus_mode != FOCUS_NONE:
Expand Down
Loading

0 comments on commit fabaa6f

Please sign in to comment.