Added level selection

This commit is contained in:
2026-07-01 13:35:27 +03:00
parent 22dfabb57e
commit d9629a0921
21 changed files with 336 additions and 2 deletions
+45
View File
@@ -0,0 +1,45 @@
class_name CompletionMenu
extends Control
@onready var next_level_button : Button = $%NextLevelButton
@onready var main_menu_button : Button = $%MainMenuButton
@onready var focus_timer : Timer = $FocusTimer
func _is_last_level() -> bool:
return LevelManager.current_level_index >= (LevelManager.levels.size() - 1)
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
LevelManager.current_level_index += 1
get_tree().change_scene_to_packed(LevelManager.levels[LevelManager.current_level_index])
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 = not _is_last_level()
focus_timer.start()
get_viewport().gui_focus_changed.connect(_on_gui_focus_changed)
elif get_viewport().gui_focus_changed.is_connected(_on_gui_focus_changed):
get_viewport().gui_focus_changed.disconnect(_on_gui_focus_changed)
func _on_focus_timer_timeout() -> void:
if next_level_button != null and next_level_button.visible:
next_level_button.grab_focus()
elif main_menu_button != null:
main_menu_button.grab_focus()
+1
View File
@@ -0,0 +1 @@
uid://xoischtv2dir
+70
View File
@@ -0,0 +1,70 @@
[gd_scene format=3 uid="uid://dbnpcpwbw7f8q"]
[ext_resource type="Theme" uid="uid://bqj884yfvhhft" path="res://game/themes/main_menu.tres" id="1_xuusr"]
[ext_resource type="Script" uid="uid://xoischtv2dir" path="res://game/menu/completion_menu.gd" id="2_0iv8v"]
[sub_resource type="Environment" id="Environment_0iv8v"]
background_mode = 3
tonemap_mode = 3
glow_enabled = true
glow_intensity = 4.0
glow_hdr_threshold = 0.5
glow_hdr_scale = 4.0
[node name="CompletionMenu" type="Control" unique_id=1435656270]
process_mode = 2
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("1_xuusr")
script = ExtResource("2_0iv8v")
[node name="ColorRect" type="ColorRect" parent="." unique_id=1975928285]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0.19607843, 0.19215687, 0.23137255, 1)
[node name="MarginContainer" type="MarginContainer" parent="." unique_id=14906773]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer" unique_id=736609031]
layout_mode = 2
alignment = 1
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer" unique_id=74970990]
layout_mode = 2
text = "COMPLETED!"
horizontal_alignment = 1
[node name="NextLevelButton" type="Button" parent="MarginContainer/VBoxContainer" unique_id=240104273]
unique_name_in_owner = true
layout_mode = 2
text = "NEXT LEVEL"
[node name="MainMenuButton" type="Button" parent="MarginContainer/VBoxContainer" unique_id=585564250]
unique_name_in_owner = true
layout_mode = 2
text = "MAIN MENU"
[node name="FocusTimer" type="Timer" parent="." unique_id=416713934]
one_shot = true
[node name="WorldEnvironment" type="WorldEnvironment" parent="." unique_id=885590829]
environment = SubResource("Environment_0iv8v")
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/NextLevelButton" to="." method="_on_next_level_button_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/MainMenuButton" to="." method="_on_main_menu_button_pressed"]
[connection signal="timeout" from="FocusTimer" to="." method="_on_focus_timer_timeout"]
+38
View File
@@ -0,0 +1,38 @@
class_name LevelSelection
extends Control
@onready var grid : GridContainer = $%GridContainer
func _ready() -> void:
for i in range(LevelManager.levels.size()):
var level := LevelManager.levels[i]
var disable := SaveManager.completed_levels < i
var button : Button = Button.new()
button.text = "Level %d" % (i + 1)
button.disabled = disable
button.focus_mode = Control.FOCUS_NONE if disable else Control.FOCUS_ALL
grid.add_child(button)
button.pressed.connect(_on_level_selected.bind(i, level))
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) -> void:
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
LevelManager.current_level_index = index
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
View File
@@ -0,0 +1 @@
uid://cjakr7gskefp4
+40
View File
@@ -0,0 +1,40 @@
[gd_scene format=3 uid="uid://br21ln0ol0745"]
[ext_resource type="Theme" uid="uid://bqj884yfvhhft" path="res://game/themes/main_menu.tres" id="1_5cn0b"]
[ext_resource type="Script" uid="uid://cjakr7gskefp4" path="res://game/menu/level_selection.gd" id="2_3oqjo"]
[node name="LevelSelection" type="Control" unique_id=1026459282]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("1_5cn0b")
script = ExtResource("2_3oqjo")
[node name="MarginContainer" type="MarginContainer" parent="." unique_id=598516023]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer" unique_id=1523206303]
layout_mode = 2
alignment = 1
[node name="GridContainer" type="GridContainer" parent="MarginContainer/VBoxContainer" unique_id=2020347789]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 4
[node name="Control" type="Control" parent="MarginContainer/VBoxContainer" unique_id=741081620]
layout_mode = 2
[node name="MainMenuButton" type="Button" parent="MarginContainer/VBoxContainer" unique_id=1148321937]
layout_mode = 2
text = "MAIN MENU"
[connection signal="pressed" from="MarginContainer/VBoxContainer/MainMenuButton" to="." method="_on_main_menu_button_pressed"]
+1 -1
View File
@@ -31,7 +31,7 @@ func _on_gui_focus_changed(_node: Control) -> void:
func _on_start_button_pressed() -> void:
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
get_tree().change_scene_to_file("res://game/levels/test_level.tscn")
get_tree().change_scene_to_file("res://game/menu/level_selection.tscn")
func _on_options_button_pressed() -> void: