From bd02b056e9b6814757770e1e5372267ed206cf3c Mon Sep 17 00:00:00 2001 From: Eduardo Date: Fri, 26 Jan 2024 21:34:56 +0100 Subject: [PATCH] added exit and play actions to buttons --- menus/main_menu/MainMenu.gd | 33 +++++++++++++++++++++++++++++++++ menus/main_menu/MainMenu.tscn | 19 ++++++++++++++----- 2 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 menus/main_menu/MainMenu.gd diff --git a/menus/main_menu/MainMenu.gd b/menus/main_menu/MainMenu.gd new file mode 100644 index 0000000..86ac3ec --- /dev/null +++ b/menus/main_menu/MainMenu.gd @@ -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() diff --git a/menus/main_menu/MainMenu.tscn b/menus/main_menu/MainMenu.tscn index 600c074..1f9a67b 100644 --- a/menus/main_menu/MainMenu.tscn +++ b/menus/main_menu/MainMenu.tscn @@ -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"] -- 2.30.2