added exit and play actions to buttons
authorEduardo <[email protected]>
Fri, 26 Jan 2024 20:34:56 +0000 (21:34 +0100)
committerEduardo <[email protected]>
Fri, 26 Jan 2024 20:34:56 +0000 (21:34 +0100)
menus/main_menu/MainMenu.gd [new file with mode: 0644]
menus/main_menu/MainMenu.tscn

diff --git a/menus/main_menu/MainMenu.gd b/menus/main_menu/MainMenu.gd
new file mode 100644 (file)
index 0000000..86ac3ec
--- /dev/null
@@ -0,0 +1,33 @@
+extends Control
+
+@export var scene : String
+
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+       SceneManager.validate_scene(scene)
+
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+func _process(_delta):
+       pass
+
+
+func _on_play_button_pressed():
+       SceneManager.change_scene(scene,
+               SceneManager.create_options(),
+               SceneManager.create_options(),
+               SceneManager.create_general_options()
+       )
+
+
+func _on_settings_button_pressed():
+       pass # Replace with function body.
+
+
+func _on_credits_button_pressed():
+       pass # Replace with function body.
+
+
+func _on_exit_button_pressed():
+       get_tree().quit()
index 600c0742c1a534e90ad87b48965b3ba151571126..1f9a67b8eaf32ef70df459ee4821662c2a5418fd 100644 (file)
@@ -1,4 +1,6 @@
-[gd_scene load_steps=2 format=3 uid="uid://c7omkuc5nfdwt"]
+[gd_scene load_steps=3 format=3 uid="uid://c7omkuc5nfdwt"]
+
+[ext_resource type="Script" path="res://menus/main_menu/MainMenu.gd" id="1_oo1tq"]
 
 [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_qywf7"]
 
@@ -9,6 +11,8 @@ anchor_right = 1.0
 anchor_bottom = 1.0
 grow_horizontal = 2
 grow_vertical = 2
+script = ExtResource("1_oo1tq")
+scene = "unicorn_map"
 
 [node name="BackgroundColorRect" type="ColorRect" parent="."]
 layout_mode = 1
@@ -62,7 +66,7 @@ theme_override_constants/margin_top = 16
 theme_override_constants/margin_right = 16
 theme_override_constants/margin_bottom = 16
 
-[node name="Button" type="Button" parent="CenterContainer/MarginContainer/VBoxContainer/MarginContainer2"]
+[node name="PlayButton" type="Button" parent="CenterContainer/MarginContainer/VBoxContainer/MarginContainer2"]
 layout_mode = 2
 text = "Play"
 
@@ -73,7 +77,7 @@ theme_override_constants/margin_top = 16
 theme_override_constants/margin_right = 16
 theme_override_constants/margin_bottom = 16
 
-[node name="Button" type="Button" parent="CenterContainer/MarginContainer/VBoxContainer/MarginContainer3"]
+[node name="SettingsButton" type="Button" parent="CenterContainer/MarginContainer/VBoxContainer/MarginContainer3"]
 layout_mode = 2
 text = "Settings"
 
@@ -84,7 +88,7 @@ theme_override_constants/margin_top = 16
 theme_override_constants/margin_right = 16
 theme_override_constants/margin_bottom = 16
 
-[node name="Button" type="Button" parent="CenterContainer/MarginContainer/VBoxContainer/MarginContainer4"]
+[node name="CreditsButton" type="Button" parent="CenterContainer/MarginContainer/VBoxContainer/MarginContainer4"]
 layout_mode = 2
 text = "Credits"
 
@@ -95,6 +99,11 @@ theme_override_constants/margin_top = 16
 theme_override_constants/margin_right = 16
 theme_override_constants/margin_bottom = 16
 
-[node name="Button" type="Button" parent="CenterContainer/MarginContainer/VBoxContainer/MarginContainer5"]
+[node name="ExitButton" type="Button" parent="CenterContainer/MarginContainer/VBoxContainer/MarginContainer5"]
 layout_mode = 2
 text = "Exit"
+
+[connection signal="pressed" from="CenterContainer/MarginContainer/VBoxContainer/MarginContainer2/PlayButton" to="." method="_on_play_button_pressed"]
+[connection signal="pressed" from="CenterContainer/MarginContainer/VBoxContainer/MarginContainer3/SettingsButton" to="." method="_on_settings_button_pressed"]
+[connection signal="pressed" from="CenterContainer/MarginContainer/VBoxContainer/MarginContainer4/CreditsButton" to="." method="_on_credits_button_pressed"]
+[connection signal="pressed" from="CenterContainer/MarginContainer/VBoxContainer/MarginContainer5/ExitButton" to="." method="_on_exit_button_pressed"]