First commit 🎉
This commit is contained in:
commit
43ea213f9b
728 changed files with 37080 additions and 0 deletions
73
game/gui/components/sound_volumes/sound_volumes.gd
Normal file
73
game/gui/components/sound_volumes/sound_volumes.gd
Normal file
|
@ -0,0 +1,73 @@
|
|||
extends GridContainer
|
||||
|
||||
const MIN_VOLUME := -30
|
||||
const MUTE_VOLUME := -70
|
||||
|
||||
var dflt_volumes := {}
|
||||
|
||||
|
||||
#region Godot ######################################################################################
|
||||
func _ready() -> void:
|
||||
# Connect to AudioManager ready signal
|
||||
PopochiuUtils.e.am.ready.connect(_on_audio_manager_ready)
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public #####################################################################################
|
||||
func update_sliders() -> void:
|
||||
for slider in $SlidersContainer.get_children():
|
||||
if not slider.has_meta("bus_name"): continue
|
||||
|
||||
var bus_name: String = slider.get_meta("bus_name")
|
||||
|
||||
slider.value = PopochiuUtils.e.am.volume_settings[bus_name]
|
||||
dflt_volumes[bus_name] = slider.value
|
||||
|
||||
|
||||
func restore_last_volumes() -> void:
|
||||
for slider in $SlidersContainer.get_children():
|
||||
if not slider.has_meta("bus_name"): continue
|
||||
|
||||
var bus_name: String = slider.get_meta("bus_name")
|
||||
PopochiuUtils.e.am.set_bus_volume_db(bus_name, dflt_volumes[bus_name])
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private ####################################################################################
|
||||
func _on_audio_manager_ready() -> void:
|
||||
PopochiuUtils.e.am.load_sound_settings()
|
||||
|
||||
# Build sound settings UI
|
||||
for bus_idx in range(AudioServer.get_bus_count()):
|
||||
var bus_name := AudioServer.get_bus_name(bus_idx)
|
||||
# Create the label for the slider
|
||||
var label := Label.new()
|
||||
label.text = bus_name
|
||||
$ChannelsContainer.add_child(label)
|
||||
|
||||
# Create the node that will allow players to modify buses volumes
|
||||
var slider = HSlider.new()
|
||||
slider.min_value = MIN_VOLUME
|
||||
slider.max_value = 0
|
||||
slider.value = PopochiuUtils.e.am.volume_settings[bus_name]
|
||||
slider.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
|
||||
slider.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
slider.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
slider.custom_minimum_size.x = 120.0
|
||||
slider.set_meta("bus_name", bus_name)
|
||||
slider.value_changed.connect(_on_volume_slider_changed.bind(bus_name))
|
||||
$SlidersContainer.add_child(slider)
|
||||
|
||||
|
||||
# Called when a volume slider changes. It will update the volume of the [param bus_name_param] bus
|
||||
# to [param value]. If the volume is set below or equal to the minimum volume, it will mute the bus.
|
||||
func _on_volume_slider_changed(value: float, bus_name_param: String) -> void:
|
||||
if value > MIN_VOLUME:
|
||||
PopochiuUtils.e.am.set_bus_volume_db(bus_name_param, value)
|
||||
else:
|
||||
PopochiuUtils.e.am.set_bus_volume_db(bus_name_param, MUTE_VOLUME)
|
||||
|
||||
|
||||
#endregion
|
1
game/gui/components/sound_volumes/sound_volumes.gd.uid
Normal file
1
game/gui/components/sound_volumes/sound_volumes.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://bgmxhq6qjswse
|
19
game/gui/components/sound_volumes/sound_volumes.tscn
Normal file
19
game/gui/components/sound_volumes/sound_volumes.tscn
Normal file
|
@ -0,0 +1,19 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://ha1e5ahv76vv"]
|
||||
|
||||
[ext_resource type="Theme" uid="uid://djl1xk7jgyvpp" path="res://game/gui/resources/gui_theme.tres" id="1_ehufi"]
|
||||
[ext_resource type="Script" uid="uid://bwqgmpgd1qi3" path="res://game/gui/components/sound_volumes/sound_volumes_custom.gd" id="2_11q3r"]
|
||||
|
||||
[node name="SoundVolumes" type="GridContainer" groups=["popochiu_gui_component"]]
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
theme = ExtResource("1_ehufi")
|
||||
columns = 2
|
||||
script = ExtResource("2_11q3r")
|
||||
|
||||
[node name="ChannelsContainer" type="VBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="SlidersContainer" type="VBoxContainer" parent="."]
|
||||
custom_minimum_size = Vector2(120, 0)
|
||||
layout_mode = 2
|
|
@ -0,0 +1 @@
|
|||
extends "sound_volumes.gd"
|
|
@ -0,0 +1 @@
|
|||
uid://bwqgmpgd1qi3
|
Loading…
Add table
Add a link
Reference in a new issue