diff options
| author | tpart <tpart120@proton.me> | 2024-06-29 22:08:39 +0200 | 
|---|---|---|
| committer | tpart <tpart120@proton.me> | 2024-06-29 22:08:41 +0200 | 
| commit | 9a76089edbae93c874b24c53a9b79f1fe10ebe2f (patch) | |
| tree | 76f003962c2f1c1219c88e6ab02bf7c53a389afb /client | |
| parent | 424b4ef3716e74bcc54c3eefffe6ba7994d79270 (diff) | |
| download | hurrycurry-9a76089edbae93c874b24c53a9b79f1fe10ebe2f.tar hurrycurry-9a76089edbae93c874b24c53a9b79f1fe10ebe2f.tar.bz2 hurrycurry-9a76089edbae93c874b24c53a9b79f1fe10ebe2f.tar.zst | |
Add Sound singleton; Restructure sound system; Add button sounds to ingame menu
Diffstat (limited to 'client')
| -rw-r--r-- | client/audio/sound.gd | 19 | ||||
| -rw-r--r-- | client/audio/sound.tscn | 16 | ||||
| -rw-r--r-- | client/global.gd | 8 | ||||
| -rw-r--r-- | client/menu/ingame_menu.gd | 3 | ||||
| -rw-r--r-- | client/menu/ingame_menu.tscn | 1 | ||||
| -rw-r--r-- | client/menu/menu_manager.gd | 33 | ||||
| -rw-r--r-- | client/menu/menu_manager.tscn | 10 | ||||
| -rw-r--r-- | client/project.godot | 1 | 
8 files changed, 52 insertions, 39 deletions
| diff --git a/client/audio/sound.gd b/client/audio/sound.gd new file mode 100644 index 00000000..ddb610c5 --- /dev/null +++ b/client/audio/sound.gd @@ -0,0 +1,19 @@ +extends Node + +@onready var click_sound = $UI/Click +@onready var hover_sound = $UI/Hover + +func play_click(): +	click_sound.play() + +func play_hover(): +	hover_sound.play() + +func play_hover_maybe(element): +	if Global.focus_auto_changed: +		Global.focus_auto_changed = false +		return +	if element is Button: +		if element.is_hovered(): +			return +	play_hover() diff --git a/client/audio/sound.tscn b/client/audio/sound.tscn new file mode 100644 index 00000000..7c0458dc --- /dev/null +++ b/client/audio/sound.tscn @@ -0,0 +1,16 @@ +[gd_scene load_steps=4 format=3 uid="uid://d3h243yic44rr"] + +[ext_resource type="Script" path="res://audio/sound.gd" id="1_b0qb1"] +[ext_resource type="AudioStream" uid="uid://cpyn511c5mtni" path="res://menu/sounds/click.ogg" id="2_mhrce"] +[ext_resource type="AudioStream" uid="uid://dtr1khfyqr56o" path="res://menu/sounds/hover.ogg" id="3_qft2s"] + +[node name="Sound" type="Node"] +script = ExtResource("1_b0qb1") + +[node name="UI" type="Node" parent="."] + +[node name="Click" type="AudioStreamPlayer" parent="UI"] +stream = ExtResource("2_mhrce") + +[node name="Hover" type="AudioStreamPlayer" parent="UI"] +stream = ExtResource("3_qft2s") diff --git a/client/global.gd b/client/global.gd index 7c547d64..4d1139d2 100644 --- a/client/global.gd +++ b/client/global.gd @@ -156,6 +156,14 @@ func focus_first_button(node: Node) -> bool:  			return true  	return false +func connect_button_sounds(node: Node): +	if node is Button: +		node.pressed.connect(Sound.play_click) +	if node is Button or node is LineEdit or node is Slider: +		node.mouse_entered.connect(Sound.play_hover) +	for c in node.get_children(): +		connect_button_sounds(c) +  func add_missing_keys(dict: Dictionary, reference: Dictionary):  	for k in reference.keys():  		if !dict.has(k): diff --git a/client/menu/ingame_menu.gd b/client/menu/ingame_menu.gd index 73f4dbb3..6fa83a55 100644 --- a/client/menu/ingame_menu.gd +++ b/client/menu/ingame_menu.gd @@ -3,6 +3,9 @@ extends Control  @onready var anim = $AnimationPlayer  @onready var options = $Side/Margin/Options +func _ready(): +	Global.connect_button_sounds(self) +  func act():  	show()  	anim.play("activate") diff --git a/client/menu/ingame_menu.tscn b/client/menu/ingame_menu.tscn index ee537720..1e9a2f46 100644 --- a/client/menu/ingame_menu.tscn +++ b/client/menu/ingame_menu.tscn @@ -72,6 +72,7 @@ anchors_preset = 9  anchor_bottom = 1.0  offset_left = -400.0  offset_right = -90.0 +offset_bottom = 648.0  grow_vertical = 2  [node name="Margin" type="MarginContainer" parent="Side"] diff --git a/client/menu/menu_manager.gd b/client/menu/menu_manager.gd index 58f35885..e51e47f1 100644 --- a/client/menu/menu_manager.gd +++ b/client/menu/menu_manager.gd @@ -8,18 +8,14 @@ class_name MenuManager  }  @onready var transition = $SceneTransition -@onready var hover_sound = $Hover -@onready var click_sound = $Click -  var menu_stack = ["main"] -  func _ready(): -	get_viewport().gui_focus_changed.connect(play_hover_maybe) +	get_viewport().gui_focus_changed.connect(Sound.play_hover_maybe)  	Global.focus_first_button(menus[menu_stack.back()])  	for m in menus.values(): -		connect_button_sounds(m) +		Global.connect_button_sounds(m)  	if Global.fade_next:  		Global.fade_next = false @@ -27,7 +23,7 @@ func _ready():  func _input(_event):  	if Input.is_action_just_pressed("ui_cancel") && menu_stack.size() > 1: -		play_click() +		Sound.play_click()  		go_back()  func goto(menu_name: String): @@ -53,26 +49,3 @@ func show_menu(menu_name: String):  		else:  			menus[k].hide()  	await transition.fade_in() -	 -func connect_button_sounds(node: Node): -	if node is Button: -		node.pressed.connect(play_click) -	if node is Button or node is LineEdit or node is Slider: -		node.mouse_entered.connect(play_hover) -	for c in node.get_children(): -		connect_button_sounds(c) - -func play_click(): -	click_sound.play() - -func play_hover(): -	hover_sound.play() - -func play_hover_maybe(element): -	if Global.focus_auto_changed: -		Global.focus_auto_changed = false -		return -	if element is Button: -		if element.is_hovered(): -			return -	play_hover() diff --git a/client/menu/menu_manager.tscn b/client/menu/menu_manager.tscn index c6959407..56cc6442 100644 --- a/client/menu/menu_manager.tscn +++ b/client/menu/menu_manager.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=3 uid="uid://cd52sr1cmo8oj"] +[gd_scene load_steps=7 format=3 uid="uid://cd52sr1cmo8oj"]  [ext_resource type="Script" path="res://menu/menu_manager.gd" id="1_c0rjm"]  [ext_resource type="PackedScene" uid="uid://l4vm07dtda4j" path="res://menu/menu_background.tscn" id="2_nf7b6"] @@ -6,8 +6,6 @@  [ext_resource type="PackedScene" uid="uid://7mqbxa054bjv" path="res://menu/credits_menu.tscn" id="4_xhcd8"]  [ext_resource type="PackedScene" uid="uid://8ic77jmadadj" path="res://menu/settings_menu.tscn" id="5_lifj8"]  [ext_resource type="PackedScene" uid="uid://bg2d78ycorcqk" path="res://menu/scene_transition.tscn" id="6_p4u45"] -[ext_resource type="AudioStream" uid="uid://dtr1khfyqr56o" path="res://menu/sounds/hover.ogg" id="7_82cmi"] -[ext_resource type="AudioStream" uid="uid://cpyn511c5mtni" path="res://menu/sounds/click.ogg" id="8_qwknj"]  [node name="MenuManager" type="Control"]  layout_mode = 3 @@ -34,9 +32,3 @@ layout_mode = 1  [node name="SceneTransition" parent="." instance=ExtResource("6_p4u45")]  visible = false  layout_mode = 1 - -[node name="Hover" type="AudioStreamPlayer" parent="."] -stream = ExtResource("7_82cmi") - -[node name="Click" type="AudioStreamPlayer" parent="."] -stream = ExtResource("8_qwknj") diff --git a/client/project.godot b/client/project.godot index d595d655..4113b60d 100644 --- a/client/project.godot +++ b/client/project.godot @@ -21,6 +21,7 @@ config/icon="res://icon.png"  Global="*res://global.gd"  Server="*res://server.gd" +Sound="*res://audio/sound.tscn"  [input] | 
