Added menu sound
This commit is contained in:
@@ -8,7 +8,9 @@ extends Control
|
||||
|
||||
|
||||
func _get_next_level(remove := false) -> PackedScene:
|
||||
var next_level : PackedScene = get_tree().get_meta(AbstractLevel.NEXT_LEVEL_META, null)
|
||||
if not get_tree().has_meta(AbstractLevel.NEXT_LEVEL_META): return null
|
||||
|
||||
var next_level : PackedScene = get_tree().get_meta(AbstractLevel.NEXT_LEVEL_META)
|
||||
|
||||
if remove:
|
||||
get_tree().remove_meta(AbstractLevel.NEXT_LEVEL_META)
|
||||
@@ -16,21 +18,30 @@ func _get_next_level(remove := false) -> PackedScene:
|
||||
return next_level
|
||||
|
||||
|
||||
func _on_gui_focus_changed(_node: Control) -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_select)
|
||||
|
||||
|
||||
func _on_next_level_button_pressed() -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
||||
get_tree().paused = false
|
||||
get_tree().change_scene_to_packed(_get_next_level(true))
|
||||
|
||||
|
||||
func _on_main_menu_button_pressed() -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
||||
get_tree().paused = false
|
||||
get_tree().change_scene_to_file("res://game/menu/main_menu.tscn")
|
||||
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
if not is_node_ready(): return
|
||||
if visible:
|
||||
next_level_button.visible = _get_next_level() != null
|
||||
if focus_timer != null:
|
||||
focus_timer.start()
|
||||
focus_timer.start()
|
||||
get_viewport().gui_focus_changed.connect(_on_gui_focus_changed)
|
||||
else:
|
||||
get_viewport().gui_focus_changed.disconnect(_on_gui_focus_changed)
|
||||
|
||||
|
||||
func _on_focus_timer_timeout() -> void:
|
||||
|
||||
@@ -46,11 +46,13 @@ horizontal_alignment = 1
|
||||
[node name="NextLevelButton" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
focus_neighbor_top = NodePath("../MainMenuButton")
|
||||
text = "Next level"
|
||||
|
||||
[node name="MainMenuButton" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
focus_neighbor_bottom = NodePath("../NextLevelButton")
|
||||
text = "Main menu"
|
||||
|
||||
[node name="FocusTimer" type="Timer" parent="."]
|
||||
|
||||
@@ -7,20 +7,29 @@ extends Control
|
||||
@onready var focus_timer : Timer = $FocusTimer
|
||||
|
||||
|
||||
func _on_gui_focus_changed(_node: Control) -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_select)
|
||||
|
||||
|
||||
func _on_retry_button_pressed() -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
||||
get_tree().paused = false
|
||||
get_tree().change_scene_to_file(get_tree().current_scene.scene_file_path)
|
||||
|
||||
|
||||
func _on_main_menu_button_pressed() -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
||||
get_tree().paused = false
|
||||
get_tree().change_scene_to_file("res://game/menu/main_menu.tscn")
|
||||
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
if not is_node_ready(): return
|
||||
if visible:
|
||||
if focus_timer != null:
|
||||
focus_timer.start()
|
||||
focus_timer.start()
|
||||
get_viewport().gui_focus_changed.connect(_on_gui_focus_changed)
|
||||
else:
|
||||
get_viewport().gui_focus_changed.disconnect(_on_gui_focus_changed)
|
||||
|
||||
|
||||
func _on_focus_timer_timeout() -> void:
|
||||
|
||||
@@ -46,11 +46,13 @@ horizontal_alignment = 1
|
||||
[node name="RetryButton" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
focus_neighbor_top = NodePath("../MainMenuButton")
|
||||
text = "Retry"
|
||||
|
||||
[node name="MainMenuButton" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
focus_neighbor_bottom = NodePath("../RetryButton")
|
||||
text = "Main menu"
|
||||
|
||||
[node name="FocusTimer" type="Timer" parent="."]
|
||||
|
||||
@@ -25,13 +25,21 @@ func _ready() -> void:
|
||||
|
||||
if i == 0:
|
||||
button.grab_focus()
|
||||
|
||||
get_viewport().gui_focus_changed.connect(_on_gui_focus_changed)
|
||||
|
||||
|
||||
func _on_gui_focus_changed(_node: Control) -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_select)
|
||||
|
||||
|
||||
func _on_level_selected(index: int, level: PackedScene, next_level: PackedScene) -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
||||
get_tree().set_meta(AbstractLevel.CURRENT_LEVEL_INDEX, index)
|
||||
get_tree().set_meta(AbstractLevel.NEXT_LEVEL_META, next_level)
|
||||
get_tree().change_scene_to_packed(level)
|
||||
|
||||
|
||||
func _on_main_menu_button_pressed() -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_decline)
|
||||
get_tree().change_scene_to_file("res://game/menu/main_menu.tscn")
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://cdw72hewwmypn"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://cdw72hewwmypn"]
|
||||
|
||||
[ext_resource type="Theme" uid="uid://bh56my8b2htnr" path="res://themes/menu.tres" id="1_5cn0b"]
|
||||
[ext_resource type="Script" uid="uid://47impoi24o7g" path="res://game/menu/level_selection.gd" id="1_fb5q3"]
|
||||
[ext_resource type="PackedScene" uid="uid://bmn74wc2vophn" path="res://game/levels/test_level.tscn" id="3_3oqjo"]
|
||||
|
||||
[sub_resource type="InputEventAction" id="InputEventAction_3oqjo"]
|
||||
action = &"ui_cancel"
|
||||
|
||||
[sub_resource type="Shortcut" id="Shortcut_n2wmw"]
|
||||
events = [SubResource("InputEventAction_3oqjo")]
|
||||
|
||||
[node name="LevelSelection" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
@@ -40,6 +46,7 @@ size_flags_vertical = 3
|
||||
|
||||
[node name="MainMenuButton" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
shortcut = SubResource("Shortcut_n2wmw")
|
||||
text = "Main menu"
|
||||
|
||||
[connection signal="pressed" from="MarginContainer/VBoxContainer/MainMenuButton" to="." method="_on_main_menu_button_pressed"]
|
||||
|
||||
@@ -8,26 +8,25 @@ extends Control
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_init_focus()
|
||||
_setup_neighbors()
|
||||
|
||||
|
||||
func _init_focus() -> void:
|
||||
start_button.grab_focus()
|
||||
get_viewport().gui_focus_changed.connect(_on_gui_focus_changed)
|
||||
|
||||
|
||||
func _setup_neighbors() -> void:
|
||||
start_button.focus_neighbor_top = quit_button.get_path()
|
||||
quit_button.focus_neighbor_bottom = start_button.get_path()
|
||||
func _on_gui_focus_changed(_node: Control) -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_select)
|
||||
|
||||
|
||||
func _on_start_button_pressed() -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
||||
get_tree().change_scene_to_file("res://game/menu/level_selection.tscn")
|
||||
|
||||
|
||||
func _on_options_button_pressed() -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
||||
get_tree().change_scene_to_file("res://game/menu/options_menu.tscn")
|
||||
|
||||
|
||||
func _on_quit_button_pressed() -> void:
|
||||
var stream_player := SoundManager.play_ui_stream(SoundManager.ui_stream_decline)
|
||||
await stream_player.finished
|
||||
get_tree().quit()
|
||||
|
||||
@@ -30,6 +30,7 @@ size_flags_vertical = 4
|
||||
[node name="StartButton" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
focus_neighbor_top = NodePath("../QuitButton")
|
||||
text = "Start"
|
||||
|
||||
[node name="OptionsButton" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
@@ -40,6 +41,7 @@ text = "Options"
|
||||
[node name="QuitButton" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
focus_neighbor_bottom = NodePath("../StartButton")
|
||||
text = "Quit"
|
||||
|
||||
[node name="CopyrightLabel" type="Label" parent="MarginContainer"]
|
||||
|
||||
+19
-37
@@ -5,7 +5,7 @@ extends Control
|
||||
const WINDOW_FACTOR = "window_factor"
|
||||
|
||||
|
||||
signal back
|
||||
var _play_sound := false
|
||||
|
||||
|
||||
@onready var fullscreen_button : CheckButton = $%FullscreenCheckButton
|
||||
@@ -18,26 +18,13 @@ signal back
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_connect_window_factor_buttons()
|
||||
_load_current_settings()
|
||||
_init_focus()
|
||||
_setup_neighbors()
|
||||
|
||||
|
||||
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
|
||||
_connect_window_factor_buttons()
|
||||
|
||||
fullscreen_button.grab_focus()
|
||||
|
||||
_play_sound = true
|
||||
get_viewport().gui_focus_changed.connect(_on_gui_focus_changed)
|
||||
|
||||
|
||||
func _connect_window_factor_buttons() -> void:
|
||||
@@ -47,23 +34,6 @@ func _connect_window_factor_buttons() -> void:
|
||||
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():
|
||||
@@ -87,32 +57,44 @@ func _update_window_factor_disabled() -> void:
|
||||
child.focus_mode = Control.FOCUS_NONE if SettingsManager.fullscreen else Control.FOCUS_ALL
|
||||
|
||||
|
||||
func _on_gui_focus_changed(_node: Control) -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_select)
|
||||
|
||||
|
||||
func _on_fullscreen_check_button_toggled(toggled: bool) -> void:
|
||||
if _play_sound: SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
||||
SettingsManager.fullscreen = toggled
|
||||
_update_window_factor_disabled()
|
||||
|
||||
|
||||
func _on_back_button_pressed() -> void:
|
||||
if _play_sound: SoundManager.play_ui_stream(SoundManager.ui_stream_decline)
|
||||
get_tree().change_scene_to_file("res://game/menu/main_menu.tscn")
|
||||
|
||||
|
||||
func _on_window_factor_button_pressed(button: Button) -> void:
|
||||
if _play_sound: 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:
|
||||
if _play_sound: SoundManager.play_ui_stream(SoundManager.ui_stream_select)
|
||||
SettingsManager.master_volume = floor(value)
|
||||
|
||||
|
||||
func _on_ui_volume_changed(value: float) -> void:
|
||||
if _play_sound: SoundManager.play_ui_stream(SoundManager.ui_stream_select)
|
||||
SettingsManager.ui_volume = floor(value)
|
||||
|
||||
|
||||
func _on_sfx_volume_changed(value: float) -> void:
|
||||
var screen_center := SettingsManager.window_base_size/2
|
||||
if _play_sound: SoundManager.play_sfx_stream(SoundManager.ui_stream_select, screen_center)
|
||||
SettingsManager.sfx_volume = floor(value)
|
||||
|
||||
|
||||
func _on_music_volume_changed(value: float) -> void:
|
||||
if _play_sound: SoundManager.play_music_stream(SoundManager.ui_stream_select)
|
||||
SettingsManager.music_volume = floor(value)
|
||||
|
||||
@@ -45,6 +45,7 @@ layout_mode = 2
|
||||
[node name="FullscreenCheckButton" type="CheckButton" parent="MarginContainer/VBoxContainer/GridContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
focus_neighbor_top = NodePath("../../HBoxContainer/BackButton")
|
||||
text = "Fullscreen"
|
||||
|
||||
[node name="WindowFactorLabel" type="Label" parent="MarginContainer/VBoxContainer/GridContainer"]
|
||||
@@ -137,6 +138,7 @@ alignment = 1
|
||||
[node name="BackButton" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
focus_neighbor_bottom = NodePath("../../GridContainer/FullscreenCheckButton")
|
||||
shortcut = SubResource("Shortcut_j72d6")
|
||||
text = "Back"
|
||||
|
||||
|
||||
+18
-2
@@ -11,6 +11,17 @@ func _ready() -> void:
|
||||
_setup_neighbors()
|
||||
|
||||
|
||||
func _on_gui_focus_changed(_node: Control) -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_select)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not visible: return
|
||||
|
||||
if event.is_action_pressed("pause"):
|
||||
_on_continue_button_pressed.call_deferred()
|
||||
|
||||
|
||||
func _init_focus() -> void:
|
||||
continue_button.grab_focus()
|
||||
|
||||
@@ -21,16 +32,21 @@ func _setup_neighbors() -> void:
|
||||
|
||||
|
||||
func _on_continue_button_pressed() -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_decline)
|
||||
get_tree().paused = false
|
||||
hide()
|
||||
|
||||
|
||||
func _on_main_menu_button_pressed() -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
||||
get_tree().paused = false
|
||||
get_tree().change_scene_to_file("res://game/menu/main_menu.tscn")
|
||||
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
if not is_node_ready(): return
|
||||
if visible:
|
||||
if continue_button != null:
|
||||
continue_button.grab_focus()
|
||||
continue_button.grab_focus()
|
||||
get_viewport().gui_focus_changed.connect(_on_gui_focus_changed)
|
||||
else:
|
||||
get_viewport().gui_focus_changed.disconnect(_on_gui_focus_changed)
|
||||
|
||||
@@ -39,11 +39,13 @@ size_flags_vertical = 4
|
||||
[node name="ContinueButton" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
focus_neighbor_top = NodePath("../MainMenuButton")
|
||||
text = "Continue"
|
||||
|
||||
[node name="MainMenuButton" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
focus_neighbor_bottom = NodePath("../ContinueButton")
|
||||
text = "Main menu"
|
||||
|
||||
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
|
||||
|
||||
Reference in New Issue
Block a user