add main menu and scene manager
This commit was merged in pull request #20.
This commit is contained in:
7
core/scene_manager/scene_config.gd
Normal file
7
core/scene_manager/scene_config.gd
Normal file
@@ -0,0 +1,7 @@
|
||||
class_name SceneConfig
|
||||
extends Resource
|
||||
|
||||
enum SceneName { MAIN_MENU, GAME }
|
||||
|
||||
@export var scenes: Dictionary[SceneName, PackedScene] = {
|
||||
}
|
||||
1
core/scene_manager/scene_config.gd.uid
Normal file
1
core/scene_manager/scene_config.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bbgyhmb8a17i7
|
||||
13
core/scene_manager/scene_config.tres
Normal file
13
core/scene_manager/scene_config.tres
Normal file
@@ -0,0 +1,13 @@
|
||||
[gd_resource type="Resource" script_class="SceneConfig" format=3 uid="uid://dr612tmciq8pg"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://btcpge7cj2041" path="res://core/main_menu/main_menu.tscn" id="1_72aup"]
|
||||
[ext_resource type="Script" uid="uid://bbgyhmb8a17i7" path="res://core/scene_manager/scene_config.gd" id="1_km45g"]
|
||||
[ext_resource type="PackedScene" uid="uid://cae0mnf353dy3" path="res://docs/museums/biome_generator/museum_biome_generator.tscn" id="2_prsyo"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_km45g")
|
||||
scenes = Dictionary[int, PackedScene]({
|
||||
0: ExtResource("1_72aup"),
|
||||
1: ExtResource("2_prsyo")
|
||||
})
|
||||
metadata/_custom_type_script = "uid://bbgyhmb8a17i7"
|
||||
43
core/scene_manager/scene_manager.gd
Normal file
43
core/scene_manager/scene_manager.gd
Normal file
@@ -0,0 +1,43 @@
|
||||
extends CanvasLayer
|
||||
|
||||
@export var config: SceneConfig
|
||||
@onready var color_rect = $ColorRect
|
||||
@onready var loading_screen = $LoadingScreen
|
||||
@export var transition_duration: float = 1
|
||||
|
||||
func _ready() -> void:
|
||||
color_rect.color.a = 0.0
|
||||
color_rect.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
loading_screen.hide()
|
||||
|
||||
func change_scene(scene_enum: SceneConfig.SceneName) -> void:
|
||||
if not config or not config.scenes.has(scene_enum):
|
||||
return
|
||||
|
||||
var target_scene: PackedScene = config.scenes[scene_enum]
|
||||
|
||||
color_rect.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
|
||||
var tween_in = create_tween()
|
||||
tween_in.tween_property(color_rect, "color:a", 1.0, transition_duration)
|
||||
await tween_in.finished
|
||||
|
||||
loading_screen.show()
|
||||
await get_tree().process_frame
|
||||
|
||||
get_tree().change_scene_to_packed(target_scene)
|
||||
|
||||
loading_screen.hide()
|
||||
|
||||
var tween_out = create_tween()
|
||||
tween_out.tween_property(color_rect, "color:a", 0.0, transition_duration)
|
||||
await tween_out.finished
|
||||
|
||||
color_rect.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
|
||||
func quit_game() -> void:
|
||||
color_rect.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
var tween = create_tween()
|
||||
tween.tween_property(color_rect, "color:a", 1.0, transition_duration)
|
||||
await tween.finished
|
||||
get_tree().quit()
|
||||
1
core/scene_manager/scene_manager.gd.uid
Normal file
1
core/scene_manager/scene_manager.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bf1f2kp8ghtei
|
||||
44
core/scene_manager/scene_manager.tscn
Normal file
44
core/scene_manager/scene_manager.tscn
Normal file
@@ -0,0 +1,44 @@
|
||||
[gd_scene format=3 uid="uid://bw8hwkw55j675"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bf1f2kp8ghtei" path="res://core/scene_manager/scene_manager.gd" id="1_7resu"]
|
||||
[ext_resource type="Resource" uid="uid://dr612tmciq8pg" path="res://core/scene_manager/scene_config.tres" id="2_vtdwt"]
|
||||
|
||||
[node name="SceneManager" type="CanvasLayer" unique_id=399843239]
|
||||
layer = 100
|
||||
script = ExtResource("1_7resu")
|
||||
config = ExtResource("2_vtdwt")
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="." unique_id=1075660170]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
color = Color(0, 0, 0, 0)
|
||||
|
||||
[node name="LoadingScreen" type="Control" parent="." unique_id=1075176512]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="Label" type="Label" parent="LoadingScreen" unique_id=887425331]
|
||||
layout_mode = 1
|
||||
anchors_preset = 3
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -169.0
|
||||
offset_top = -65.0
|
||||
offset_right = -20.0
|
||||
offset_bottom = -20.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
theme_override_constants/outline_size = 24
|
||||
theme_override_font_sizes/font_size = 32
|
||||
text = "Loading..."
|
||||
Reference in New Issue
Block a user