diff --git a/scenes/UI/ChooseScene.gd b/scenes/UI/ChooseScene.gd index 76ab863..f67148f 100644 --- a/scenes/UI/ChooseScene.gd +++ b/scenes/UI/ChooseScene.gd @@ -1,4 +1,5 @@ extends Control +# Load scene warcraft func _on_WarCraft_pressed(): - get_tree().change_scene("res://scenes/levels/WarCraft.tscn") + Global.goto_scene("res://scenes/levels/WarCraft.tscn") diff --git a/scenes/UI/ChooseScene.tscn b/scenes/UI/ChooseScene.tscn index 9df5920..bbdf270 100644 --- a/scenes/UI/ChooseScene.tscn +++ b/scenes/UI/ChooseScene.tscn @@ -6,13 +6,20 @@ [node name="ChooseScene" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 -margin_left = 200.0 script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": false } -[node name="GridContainer" type="GridContainer" parent="."] +[node name="games" type="Control" parent="."] +margin_left = 200.0 +margin_right = 1024.0 +margin_bottom = 600.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="GridContainer" type="GridContainer" parent="games"] margin_left = 25.0 margin_top = 26.2599 margin_right = 824.0 @@ -21,10 +28,10 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="WarCraft" type="TextureButton" parent="GridContainer"] +[node name="WarCraft" type="TextureButton" parent="games/GridContainer"] margin_right = 150.0 margin_bottom = 150.0 mouse_default_cursor_shape = 2 texture_normal = ExtResource( 2 ) -[connection signal="pressed" from="GridContainer/WarCraft" to="." method="_on_WarCraft_pressed"] +[connection signal="pressed" from="games/GridContainer/WarCraft" to="." method="_on_WarCraft_pressed"] diff --git a/scenes/levels/WarCraft.gd b/scenes/levels/WarCraft.gd index 6c68e8a..3dbcb12 100644 --- a/scenes/levels/WarCraft.gd +++ b/scenes/levels/WarCraft.gd @@ -1,9 +1,15 @@ extends Spatial -export (PackedScene) var main = load("res://scenes/main.tscn") +func _process(_delta): + # Event key "escape" and "godot event" ui_end + if Input.is_action_just_pressed("ui_end"): + _quit_to_menu() func _notification(what): - # Back to main scene + # Notification for android back action if what == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST: - var scene = main.instance() - call_deferred("add_child", scene) + _quit_to_menu() + +# Back to main scene +func _quit_to_menu(): + Global.goto_scene("res://scenes/main.tscn") diff --git a/scenes/main.gd b/scenes/main.gd index 62e3dac..db3aa23 100644 --- a/scenes/main.gd +++ b/scenes/main.gd @@ -3,7 +3,7 @@ extends Node export (PackedScene) var about = load("res://scenes/UI/About.tscn") export (PackedScene) var scenes = load("res://scenes/UI/ChooseScene.tscn") -var scene +var current_scene = null # Quit the game func _on_Quit_pressed(): @@ -12,17 +12,17 @@ func _on_Quit_pressed(): # Load scene about func _on_About_pressed(): _prepare_change_scene() - scene = about.instance() - add_child(scene) + current_scene = about.instance() + add_child(current_scene) # Load scene for select game func _on_New_pressed(): _prepare_change_scene() - scene = scenes.instance() - add_child(scene) + current_scene = scenes.instance() + add_child(current_scene) ## PRIVATE func _prepare_change_scene(): - if (scene != null): - remove_child(scene) - scene.call_deferred("free") + if (current_scene != null): + remove_child(current_scene) + current_scene.call_deferred("free")