Some code organization
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
extends Control
|
||||
|
||||
|
||||
const WINDOW_FACTOR = "window_factor"
|
||||
|
||||
|
||||
signal back
|
||||
|
||||
|
||||
@onready var fullscreen_button : CheckButton = $%FullscreenCheckButton
|
||||
@onready var window_factor_buttons : HBoxContainer = $%WindowFactorContainer
|
||||
@onready var back_button : Button = $%BackButton
|
||||
@onready var master_slider : Slider = $%MasterSlider
|
||||
@onready var ui_slider : Slider = $%UISlider
|
||||
@onready var sfx_slider : Slider = $%SFXSlider
|
||||
@onready var music_slider : Slider = $%MusicSlider
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_connect_window_factor_buttons()
|
||||
_load_current_settings()
|
||||
_init_focus()
|
||||
_setup_neighbors()
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_up") and not fullscreen_button.has_focus():
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_previous)
|
||||
if event.is_action_pressed("ui_down") and not back_button.has_focus():
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_next)
|
||||
if event.is_action_pressed("ui_left") and _play_left_sound():
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_previous)
|
||||
if event.is_action_pressed("ui_right") and _play_right_sound():
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_next)
|
||||
|
||||
|
||||
func _play_left_sound() -> bool:
|
||||
return _play_side_sound(1, 0)
|
||||
|
||||
|
||||
func _play_right_sound() -> bool:
|
||||
return _play_side_sound(0, 1)
|
||||
|
||||
|
||||
func _play_side_sound(offset_begin: int, offset_end: int) -> bool:
|
||||
for i in range(offset_begin, window_factor_buttons.get_child_count() - offset_end):
|
||||
var child := window_factor_buttons.get_child(i)
|
||||
if child is Button and child.has_focus():
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _connect_window_factor_buttons() -> void:
|
||||
for child in window_factor_buttons.get_children():
|
||||
if child is Button:
|
||||
var button : Button = child
|
||||
button.pressed.connect(_on_window_factor_button_pressed.bind(button))
|
||||
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
if not is_node_ready(): return
|
||||
if not visible: return
|
||||
|
||||
_load_current_settings()
|
||||
_init_focus()
|
||||
_setup_neighbors()
|
||||
|
||||
|
||||
func _init_focus() -> void:
|
||||
fullscreen_button.grab_focus()
|
||||
|
||||
|
||||
func _setup_neighbors() -> void:
|
||||
music_slider.focus_neighbor_bottom = back_button.get_path()
|
||||
|
||||
|
||||
func _load_current_settings() -> void:
|
||||
fullscreen_button.button_pressed = SettingsManager.fullscreen
|
||||
for child in window_factor_buttons.get_children():
|
||||
if child is Button:
|
||||
var button : Button = child
|
||||
var window_factor : int = button.get_meta(WINDOW_FACTOR, 0)
|
||||
if window_factor == SettingsManager.window_factor:
|
||||
button.button_pressed = true
|
||||
_update_window_factor_disabled()
|
||||
|
||||
master_slider.value = SettingsManager.master_volume
|
||||
ui_slider.value = SettingsManager.ui_volume
|
||||
sfx_slider.value = SettingsManager.sfx_volume
|
||||
music_slider.value = SettingsManager.music_volume
|
||||
|
||||
|
||||
func _update_window_factor_disabled() -> void:
|
||||
for child in window_factor_buttons.get_children():
|
||||
if not child is Button: continue
|
||||
child.disabled = SettingsManager.fullscreen
|
||||
child.focus_mode = Control.FOCUS_NONE if SettingsManager.fullscreen else Control.FOCUS_ALL
|
||||
|
||||
|
||||
func _on_fullscreen_check_button_toggled(toggled: bool) -> void:
|
||||
if visible: SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
||||
SettingsManager.fullscreen = toggled
|
||||
_update_window_factor_disabled()
|
||||
|
||||
|
||||
func _on_back_button_pressed() -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_decline)
|
||||
back.emit()
|
||||
|
||||
|
||||
func _on_window_factor_button_pressed(button: Button) -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
||||
var window_factor : int = button.get_meta(WINDOW_FACTOR, 0)
|
||||
if window_factor > 0:
|
||||
SettingsManager.window_factor = window_factor
|
||||
|
||||
|
||||
func _on_master_volume_changed(value: float) -> void:
|
||||
var stream := _get_slider_sound(SettingsManager.master_volume, value)
|
||||
SoundManager.play_ui_stream(stream)
|
||||
SettingsManager.master_volume = floor(value)
|
||||
|
||||
|
||||
func _on_ui_volume_changed(value: float) -> void:
|
||||
var stream := _get_slider_sound(SettingsManager.master_volume, value)
|
||||
SoundManager.play_ui_stream(stream)
|
||||
SettingsManager.ui_volume = floor(value)
|
||||
|
||||
|
||||
func _on_sfx_volume_changed(value: float) -> void:
|
||||
var stream := _get_slider_sound(SettingsManager.master_volume, value)
|
||||
SoundManager.play_sfx_stream(stream, SettingsManager.window_base_size/2)
|
||||
SettingsManager.sfx_volume = floor(value)
|
||||
|
||||
|
||||
func _on_music_volume_changed(value: float) -> void:
|
||||
var stream := _get_slider_sound(SettingsManager.master_volume, value)
|
||||
SoundManager.play_music_stream(stream)
|
||||
SettingsManager.music_volume = floor(value)
|
||||
|
||||
|
||||
func _get_slider_sound(old_value: float, new_value: float) -> AudioStream:
|
||||
if old_value < new_value:
|
||||
return SoundManager.ui_stream_next
|
||||
else:
|
||||
return SoundManager.ui_stream_previous
|
||||
@@ -0,0 +1 @@
|
||||
uid://ceng1u112aqg0
|
||||
@@ -0,0 +1,200 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://btr60idiit4y7"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ceng1u112aqg0" path="res://game/menu/options/options.gd" id="1_61pji"]
|
||||
[ext_resource type="Theme" uid="uid://dtnd3tqllufey" path="res://styles/menu_theme.tres" id="2_1tdpy"]
|
||||
|
||||
[sub_resource type="ButtonGroup" id="ButtonGroup_6ueaa"]
|
||||
|
||||
[sub_resource type="InputEventAction" id="InputEventAction_61pji"]
|
||||
action = &"ui_cancel"
|
||||
|
||||
[sub_resource type="Shortcut" id="Shortcut_1tdpy"]
|
||||
events = [SubResource("InputEventAction_61pji")]
|
||||
|
||||
[node name="Options" type="VBoxContainer"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_right = -556.0
|
||||
offset_bottom = -312.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource("1_61pji")
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="."]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
follow_focus = true
|
||||
|
||||
[node name="OptionsGridContainer" type="GridContainer" parent="ScrollContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 6
|
||||
size_flags_vertical = 6
|
||||
columns = 2
|
||||
|
||||
[node name="FullscreenLabel" type="Label" parent="ScrollContainer/OptionsGridContainer"]
|
||||
unique_name_in_owner = true
|
||||
z_index = 100
|
||||
layout_mode = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
|
||||
[node name="FullscreenCheckButton" type="CheckButton" parent="ScrollContainer/OptionsGridContainer"]
|
||||
unique_name_in_owner = true
|
||||
z_index = 100
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
text = "Fullscreen"
|
||||
|
||||
[node name="WindowFactorLabel" type="Label" parent="ScrollContainer/OptionsGridContainer"]
|
||||
unique_name_in_owner = true
|
||||
z_index = 100
|
||||
layout_mode = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
text = "Window Factor"
|
||||
|
||||
[node name="WindowFactorContainer" type="HBoxContainer" parent="ScrollContainer/OptionsGridContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ButtonX1" type="Button" parent="ScrollContainer/OptionsGridContainer/WindowFactorContainer"]
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
toggle_mode = true
|
||||
button_group = SubResource("ButtonGroup_6ueaa")
|
||||
text = "*1"
|
||||
metadata/window_factor = 1
|
||||
|
||||
[node name="ButtonX2" type="Button" parent="ScrollContainer/OptionsGridContainer/WindowFactorContainer"]
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
toggle_mode = true
|
||||
button_group = SubResource("ButtonGroup_6ueaa")
|
||||
text = "*2"
|
||||
metadata/window_factor = 2
|
||||
|
||||
[node name="ButtonX3" type="Button" parent="ScrollContainer/OptionsGridContainer/WindowFactorContainer"]
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
toggle_mode = true
|
||||
button_group = SubResource("ButtonGroup_6ueaa")
|
||||
text = "*3"
|
||||
metadata/window_factor = 3
|
||||
|
||||
[node name="ButtonX4" type="Button" parent="ScrollContainer/OptionsGridContainer/WindowFactorContainer"]
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
toggle_mode = true
|
||||
button_group = SubResource("ButtonGroup_6ueaa")
|
||||
text = "*4"
|
||||
metadata/window_factor = 4
|
||||
|
||||
[node name="ButtonX5" type="Button" parent="ScrollContainer/OptionsGridContainer/WindowFactorContainer"]
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
toggle_mode = true
|
||||
button_group = SubResource("ButtonGroup_6ueaa")
|
||||
text = "*5"
|
||||
metadata/window_factor = 5
|
||||
|
||||
[node name="MasterLabel" type="Label" parent="ScrollContainer/OptionsGridContainer"]
|
||||
layout_mode = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
text = "Menu Volume"
|
||||
|
||||
[node name="MasterSlider" type="HSlider" parent="ScrollContainer/OptionsGridContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
step = 10.0
|
||||
value = 100.0
|
||||
rounded = true
|
||||
scrollable = false
|
||||
tick_count = 11
|
||||
ticks_on_borders = true
|
||||
ticks_position = 3
|
||||
|
||||
[node name="UILabel" type="Label" parent="ScrollContainer/OptionsGridContainer"]
|
||||
layout_mode = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
text = "UI Volume"
|
||||
|
||||
[node name="UISlider" type="HSlider" parent="ScrollContainer/OptionsGridContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
step = 10.0
|
||||
value = 100.0
|
||||
rounded = true
|
||||
scrollable = false
|
||||
tick_count = 11
|
||||
ticks_on_borders = true
|
||||
ticks_position = 3
|
||||
|
||||
[node name="SFXLabel" type="Label" parent="ScrollContainer/OptionsGridContainer"]
|
||||
layout_mode = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
text = "SFX Volume"
|
||||
|
||||
[node name="SFXSlider" type="HSlider" parent="ScrollContainer/OptionsGridContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
step = 10.0
|
||||
value = 100.0
|
||||
rounded = true
|
||||
scrollable = false
|
||||
tick_count = 11
|
||||
ticks_on_borders = true
|
||||
ticks_position = 3
|
||||
|
||||
[node name="MusicLabel" type="Label" parent="ScrollContainer/OptionsGridContainer"]
|
||||
layout_mode = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
text = "Music Volume"
|
||||
|
||||
[node name="MusicSlider" type="HSlider" parent="ScrollContainer/OptionsGridContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
step = 10.0
|
||||
value = 100.0
|
||||
rounded = true
|
||||
scrollable = false
|
||||
tick_count = 11
|
||||
ticks_on_borders = true
|
||||
ticks_position = 3
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 8
|
||||
alignment = 2
|
||||
|
||||
[node name="BackButton" type="Button" parent="HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
z_index = 100
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_1tdpy")
|
||||
shortcut = SubResource("Shortcut_1tdpy")
|
||||
text = "Back"
|
||||
|
||||
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
|
||||
[connection signal="toggled" from="ScrollContainer/OptionsGridContainer/FullscreenCheckButton" to="." method="_on_fullscreen_check_button_toggled"]
|
||||
[connection signal="value_changed" from="ScrollContainer/OptionsGridContainer/MasterSlider" to="." method="_on_master_volume_changed"]
|
||||
[connection signal="value_changed" from="ScrollContainer/OptionsGridContainer/UISlider" to="." method="_on_ui_volume_changed"]
|
||||
[connection signal="value_changed" from="ScrollContainer/OptionsGridContainer/SFXSlider" to="." method="_on_sfx_volume_changed"]
|
||||
[connection signal="value_changed" from="ScrollContainer/OptionsGridContainer/MusicSlider" to="." method="_on_music_volume_changed"]
|
||||
[connection signal="pressed" from="HBoxContainer/BackButton" to="." method="_on_back_button_pressed"]
|
||||
Reference in New Issue
Block a user