add game menu
This commit was merged in pull request #19.
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
extends VBoxContainer
|
||||
|
||||
class_name AudioOption
|
||||
|
||||
const MIN_VOLUME: float = 0.0
|
||||
const MAX_VOLUME: float = 1.0
|
||||
|
||||
@export var bus_name: StringName = &"Master"
|
||||
@export var label_text: String = "Master Volume"
|
||||
@export_range(0.0, 1.0, 0.01) var default_volume: float = 1.0
|
||||
|
||||
@onready var label: Label = $Label
|
||||
@onready var slider: HSlider = $HSlider
|
||||
|
||||
func _ready() -> void:
|
||||
slider.min_value = MIN_VOLUME
|
||||
slider.max_value = MAX_VOLUME
|
||||
slider.step = 0.01
|
||||
slider.value_changed.connect(_on_slider_value_changed)
|
||||
refresh()
|
||||
|
||||
func refresh() -> void:
|
||||
label.text = label_text
|
||||
|
||||
if not has_bus():
|
||||
slider.set_value_no_signal(default_volume)
|
||||
slider.editable = false
|
||||
label.text = "%s (bus missing)" % label_text
|
||||
return
|
||||
|
||||
slider.editable = true
|
||||
var saved_volume := AudioManager.get_audio_bus_volume(bus_name, default_volume)
|
||||
slider.set_value_no_signal(saved_volume)
|
||||
apply_current_value()
|
||||
|
||||
func reset_to_default() -> void:
|
||||
slider.value = default_volume
|
||||
|
||||
func apply_current_value() -> void:
|
||||
_set_bus_volume(slider.value)
|
||||
|
||||
func has_bus() -> bool:
|
||||
return get_bus_index() != -1
|
||||
|
||||
func get_bus_index() -> int:
|
||||
return AudioServer.get_bus_index(bus_name)
|
||||
|
||||
func _set_bus_volume(linear_value: float) -> void:
|
||||
if not has_bus():
|
||||
return
|
||||
|
||||
var clamped_value := clampf(linear_value, MIN_VOLUME, MAX_VOLUME)
|
||||
AudioManager.set_audio_bus_volume(bus_name, clamped_value)
|
||||
|
||||
func _on_slider_value_changed(value: float) -> void:
|
||||
_set_bus_volume(value)
|
||||
@@ -1 +0,0 @@
|
||||
uid://bnh1y560h55vc
|
||||
@@ -1,14 +0,0 @@
|
||||
[gd_scene format=3 uid="uid://cescrovsjlwke"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bnh1y560h55vc" path="res://core/audio/settings/audio_option.gd" id="1_orafl"]
|
||||
|
||||
[node name="AudioOption" type="VBoxContainer" unique_id=1509773712]
|
||||
custom_minimum_size = Vector2(300, 0)
|
||||
script = ExtResource("1_orafl")
|
||||
|
||||
[node name="Label" type="Label" parent="." unique_id=781845786]
|
||||
layout_mode = 2
|
||||
text = "Master Volume"
|
||||
|
||||
[node name="HSlider" type="HSlider" parent="." unique_id=1286896253]
|
||||
layout_mode = 2
|
||||
@@ -1,36 +0,0 @@
|
||||
extends Control
|
||||
|
||||
class_name SettingsMenu
|
||||
|
||||
@onready var audio_options_container: VBoxContainer = $%AudioOptionsContainer
|
||||
@onready var reset_button: Button = $%ResetToDefault_Button
|
||||
@onready var close_button: Button = $%Close_Button
|
||||
|
||||
func _ready() -> void:
|
||||
reset_button.pressed.connect(_on_reset_to_default_button_pressed)
|
||||
close_button.pressed.connect(_on_close_button_pressed)
|
||||
_refresh_audio_options()
|
||||
|
||||
func _get_audio_options() -> Array[AudioOption]:
|
||||
var audio_options: Array[AudioOption] = []
|
||||
|
||||
for child in audio_options_container.get_children():
|
||||
if child is AudioOption:
|
||||
audio_options.append(child)
|
||||
|
||||
return audio_options
|
||||
|
||||
func _refresh_audio_options() -> void:
|
||||
for audio_option in _get_audio_options():
|
||||
audio_option.refresh()
|
||||
|
||||
func _apply_current_audio_values() -> void:
|
||||
for audio_option in _get_audio_options():
|
||||
audio_option.apply_current_value()
|
||||
|
||||
func _on_reset_to_default_button_pressed() -> void:
|
||||
for audio_option in _get_audio_options():
|
||||
audio_option.reset_to_default()
|
||||
|
||||
func _on_close_button_pressed() -> void:
|
||||
visible = false
|
||||
@@ -1 +0,0 @@
|
||||
uid://cvr25q1blyxg
|
||||
@@ -1,74 +0,0 @@
|
||||
[gd_scene format=3 uid="uid://caqf471x0kttc"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cvr25q1blyxg" path="res://core/audio/settings/settings_menu.gd" id="1_4lekq"]
|
||||
[ext_resource type="PackedScene" uid="uid://cescrovsjlwke" path="res://core/audio/settings/audio_option.tscn" id="1_hwcco"]
|
||||
|
||||
[node name="SettingsMenu" type="Control" unique_id=1639777294]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_4lekq")
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="." unique_id=315821242]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -79.5
|
||||
offset_top = -110.0
|
||||
offset_right = 79.5
|
||||
offset_bottom = 110.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer" unique_id=648635784]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 0
|
||||
theme_override_constants/margin_left = 12
|
||||
theme_override_constants/margin_top = 12
|
||||
theme_override_constants/margin_right = 12
|
||||
theme_override_constants/margin_bottom = 12
|
||||
|
||||
[node name="AudioOptionsContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer" unique_id=824023653]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 12
|
||||
|
||||
[node name="MasterVolume_AudioOption" parent="PanelContainer/MarginContainer/AudioOptionsContainer" unique_id=1509773712 instance=ExtResource("1_hwcco")]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="HSeparator" type="HSeparator" parent="PanelContainer/MarginContainer/AudioOptionsContainer" unique_id=1053430754]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MusicVolume_AudioOption" parent="PanelContainer/MarginContainer/AudioOptionsContainer" unique_id=690924616 instance=ExtResource("1_hwcco")]
|
||||
layout_mode = 2
|
||||
bus_name = &"Music"
|
||||
label_text = "Music Volume"
|
||||
|
||||
[node name="HSeparator2" type="HSeparator" parent="PanelContainer/MarginContainer/AudioOptionsContainer" unique_id=453716295]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="SFXVolume_AudioOption" parent="PanelContainer/MarginContainer/AudioOptionsContainer" unique_id=2096291127 instance=ExtResource("1_hwcco")]
|
||||
layout_mode = 2
|
||||
bus_name = &"SFX"
|
||||
label_text = "SFX Volume"
|
||||
|
||||
[node name="HSeparator3" type="HSeparator" parent="PanelContainer/MarginContainer/AudioOptionsContainer" unique_id=498553283]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ResetToDefault_Button" type="Button" parent="PanelContainer/MarginContainer/AudioOptionsContainer" unique_id=720420423]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
text = "Reset To Default"
|
||||
|
||||
[node name="Close_Button" type="Button" parent="PanelContainer/MarginContainer/AudioOptionsContainer" unique_id=1137906684]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
text = "Close"
|
||||
Reference in New Issue
Block a user