Fixed unresponsive loaded scenes, when using UI

The Button for switching to a different scene now unpauses the tree
and frees the previous scene from memory
This commit is contained in:
Jakob Feldmann 2022-06-25 15:02:10 +02:00
parent 38c61eefd6
commit bf5af96d20
5 changed files with 20 additions and 35 deletions

View File

@ -1,4 +1,3 @@
tool
extends Button
export(String, FILE) var next_scene_path: = ""
@ -6,9 +5,11 @@ onready var selected_level_base_path: String = "res://src/Levels/"
func _on_button_up() -> void:
get_tree().change_scene(next_scene_path)
get_tree().get_current_scene().queue_free()
get_tree().paused = false
func _get_configuration_warning() -> String:
return "next_scene_path must be set for the button to work" if next_scene_path == "" else ""
func _level_selection_changed(button):
next_scene_path = selected_level_base_path + button.text + ".tscn"
next_scene_path = selected_level_base_path + button.text + ".tscn"

View File

@ -1,7 +1,7 @@
extends Control
# Smart ist es die notwendigen Resourcen vor dem Skriptstart zu laden
onready var scene_tree := get_tree()
onready var current_scene := get_tree().get_current_scene()
onready var pause_overlay: ColorRect = get_node("PauseOverlay")
onready var score: Label = get_node("Label")
onready var pause_title: Label = get_node("PauseOverlay/Title")
@ -26,7 +26,7 @@ func _unhandled_input(event: InputEvent) -> void:
#not oder ! schaltet einen boolean um
#Ist self hier notwendig?
self.paused = not paused
scene_tree.set_input_as_handled()
get_tree().set_input_as_handled()
func update_interface() -> void:
@ -35,5 +35,5 @@ func update_interface() -> void:
func set_paused(value: bool) -> void:
paused = value
scene_tree.paused = value
get_tree().paused = value
pause_overlay.visible = value

View File

@ -10,6 +10,7 @@
pause_mode = 2
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
theme = ExtResource( 1 )
script = ExtResource( 5 )
@ -47,7 +48,7 @@ margin_bottom = 80.0
[node name="MainMenuButton" parent="PauseOverlay/VBoxContainer" instance=ExtResource( 3 )]
margin_top = 84.0
margin_right = 222.0
margin_bottom = 164.0
margin_bottom = 165.0
text = "Main Menu"
next_scene_path = "res://src/UserInterface/Screens/MainScreen.tscn"
@ -55,29 +56,25 @@ next_scene_path = "res://src/UserInterface/Screens/MainScreen.tscn"
anchor_left = 0.0
anchor_right = 0.0
margin_left = 0.0
margin_top = 168.0
margin_top = 169.0
margin_right = 222.0
margin_bottom = 250.0
[node name="PauseLabel" type="Label" parent="PauseOverlay"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -59.0
margin_top = -187.5
margin_right = 59.0
margin_bottom = -142.5
margin_left = -19.0
margin_right = 19.0
margin_bottom = 15.0
size_flags_horizontal = 0
size_flags_vertical = 0
text = "Pause"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="."]
anchor_left = 1.0
anchor_right = 1.0
margin_left = -84.0
margin_right = -5.0
margin_left = -96.0001
margin_right = -17.0001
margin_bottom = 24.0
rect_scale = Vector2( 0.590909, 0.627907 )
text = "Score: %s"

View File

@ -2,17 +2,11 @@ extends ScrollContainer
onready var LEVELS_PATH = "res://src/Levels/"
onready var BUTTON_GROUP : ButtonGroup = load("res://src/UserInterface/Screens/LevelSelectButtonGroup.tres")
onready var vbox = $VBoxContainer
onready var vbox: VBoxContainer = $VBoxContainer
# Declare member variables here. Examples:
# var a: int = 2
# var b: String = "text"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
BUTTON_GROUP.connect("pressed", get_node('../Buttons/PlayButton'), "_level_selection_changed")
_fill_level_list()
pass # Replace with function body.
func _fill_level_list():
var levels = []
@ -30,17 +24,9 @@ func _fill_level_list():
_spawn_level_options(levels)
func _spawn_level_options(levels: Array):
BUTTON_GROUP.connect("pressed", get_node('../Buttons/PlayButton'), "_level_selection_changed")
for level in levels:
var check_box = CheckBox.new()
check_box.text = level.trim_suffix(".tscn")
check_box.set_button_group(BUTTON_GROUP);
vbox.add_child(check_box)
return
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta: float) -> void:
# pass
return

View File

@ -11,6 +11,7 @@
[node name="MainScreen" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
size_flags_horizontal = 0
size_flags_vertical = 0
theme = ExtResource( 5 )