瀏覽代碼

Simplifie la gestion du volume

Evite a deux composants differents de communiquer.
DricomDragon 11 月之前
父節點
當前提交
c531dcc02d

+ 5 - 7
godot/composants/interface/pause/bus_volume.gd

@@ -1,19 +1,17 @@
 class_name BusVolume
-extends Slider
+extends Range
 ## Permet de parametrer le volume d'un bus
 
-## Emis quand la consigne du volume est modifiee ; annonce le bus et le nouveau volume
-signal volume_change(String, float)
-
 ## Le nom du bus que ce slider doit controler.
 @export var nom_bus: String = "Master"
 
+@onready var _index_bus: int = AudioServer.get_bus_index(nom_bus)
+
 
 func _ready() -> void:
 	value_changed.connect(_met_a_jour_volume)
-	var index_bus: int = AudioServer.get_bus_index(nom_bus)
-	value = AudioServer.get_bus_volume_db(index_bus)
+	value = AudioServer.get_bus_volume_db(_index_bus)
 
 
 func _met_a_jour_volume(nouveau_volume: float) -> void:
-	volume_change.emit(nom_bus, nouveau_volume)
+	AudioServer.set_bus_volume_db(_index_bus, nouveau_volume)

+ 9 - 13
godot/composants/interface/pause/pause_menu.tscn

@@ -1,8 +1,7 @@
-[gd_scene load_steps=5 format=3 uid="uid://cvsfngjyx7xvw"]
+[gd_scene load_steps=4 format=3 uid="uid://cvsfngjyx7xvw"]
 
 [ext_resource type="Script" path="res://composants/interface/pause/pause_menu.gd" id="1_c51fd"]
 [ext_resource type="Texture2D" uid="uid://bkupreskydgkg" path="res://composants/interface/pause/sprite.png" id="2_2pxrh"]
-[ext_resource type="Script" path="res://composants/interface/pause/volume_control.gd" id="3_5at13"]
 [ext_resource type="Script" path="res://composants/interface/pause/bus_volume.gd" id="4_ygvs3"]
 
 [node name="PauseMenu" type="VSplitContainer"]
@@ -23,31 +22,30 @@ texture = ExtResource("2_2pxrh")
 stretch_mode = 3
 
 [node name="VSplitContainer" type="VSplitContainer" parent="."]
+process_mode = 2
 layout_mode = 2
 
-[node name="Buttons" type="VBoxContainer" parent="VSplitContainer"]
-process_mode = 2
+[node name="Boutons" type="VBoxContainer" parent="VSplitContainer"]
 layout_mode = 2
 size_flags_horizontal = 4
 size_flags_vertical = 0
 
-[node name="Reprendre" type="Button" parent="VSplitContainer/Buttons"]
+[node name="Reprendre" type="Button" parent="VSplitContainer/Boutons"]
 unique_name_in_owner = true
 layout_mode = 2
 text = "Reprendre"
 
-[node name="RetourEcranTitre" type="Button" parent="VSplitContainer/Buttons"]
+[node name="RetourEcranTitre" type="Button" parent="VSplitContainer/Boutons"]
 layout_mode = 2
 text = "Retour écran titre"
 
-[node name="QuitterLeJeu" type="Button" parent="VSplitContainer/Buttons"]
+[node name="QuitterLeJeu" type="Button" parent="VSplitContainer/Boutons"]
 layout_mode = 2
 text = "Quitter le jeu"
 
 [node name="VolumeControl" type="HBoxContainer" parent="VSplitContainer"]
 layout_mode = 2
 size_flags_vertical = 8
-script = ExtResource("3_5at13")
 
 [node name="Musique" type="HSlider" parent="VSplitContainer/VolumeControl"]
 layout_mode = 2
@@ -65,8 +63,6 @@ max_value = 0.0
 script = ExtResource("4_ygvs3")
 nom_bus = "Bruits"
 
-[connection signal="pressed" from="VSplitContainer/Buttons/Reprendre" to="." method="_quand_bouton_reprendre_est_presse"]
-[connection signal="pressed" from="VSplitContainer/Buttons/RetourEcranTitre" to="." method="_quand_bouton_retour_titre_est_presse"]
-[connection signal="pressed" from="VSplitContainer/Buttons/QuitterLeJeu" to="." method="_quand_bouton_quitter_est_presse"]
-[connection signal="volume_change" from="VSplitContainer/VolumeControl/Musique" to="VSplitContainer/VolumeControl" method="_quand_volume_change"]
-[connection signal="volume_change" from="VSplitContainer/VolumeControl/Bruits" to="VSplitContainer/VolumeControl" method="_quand_volume_change"]
+[connection signal="pressed" from="VSplitContainer/Boutons/Reprendre" to="." method="_quand_bouton_reprendre_est_presse"]
+[connection signal="pressed" from="VSplitContainer/Boutons/RetourEcranTitre" to="." method="_quand_bouton_retour_titre_est_presse"]
+[connection signal="pressed" from="VSplitContainer/Boutons/QuitterLeJeu" to="." method="_quand_bouton_quitter_est_presse"]

+ 0 - 10
godot/composants/interface/pause/volume_control.gd

@@ -1,10 +0,0 @@
-extends Control
-
-
-func _quand_volume_change(nom_bus: String, nouveau_volume: float) -> void:
-	_ajuster_volume(nom_bus, nouveau_volume)
-
-
-func _ajuster_volume(nom_bus: String, nouveau_volume: float) -> void:
-	var index_bus: int = AudioServer.get_bus_index(nom_bus)
-	AudioServer.set_bus_volume_db(index_bus, nouveau_volume)