From 5186a2e90be7f0442377bd4a1e471f619dbcdc6f Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 13 Apr 2024 05:29:43 +0200 Subject: [PATCH] Add buttons to the menu --- main.gd | 11 +++++++++++ scenes/interface/main_menu.gd | 14 +++++++++++++ scenes/interface/main_menu.tscn | 35 ++++++++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/main.gd b/main.gd index 333eefb..36ab5b5 100644 --- a/main.gd +++ b/main.gd @@ -2,6 +2,7 @@ extends Node class_name Main +@onready var tree: SceneTree = get_tree() @onready var container: Control = $"PrimaryCanvas/SafeMarginContainer" @@ -9,6 +10,8 @@ class_name Main enum Stage { NONE = 0, MENU = 1, + OPTIONS = 2, + GAME = 3, } ## The [Stage] the game is currently in. @@ -50,9 +53,17 @@ func destroy_menu() -> void: ## Build the main menu. func build_menu() -> void: scene_menu = SCENE_MENU.instantiate() + scene_menu.selected_play.connect(_on_menu_selected_play) + scene_menu.selected_options.connect(_on_menu_selected_options) container.add_child(scene_menu) func _ready() -> void: current_stage = starting_stage + +func _on_menu_selected_play() -> void: + current_stage = Stage.GAME + +func _on_menu_selected_options() -> void: + current_stage = Stage.OPTIONS diff --git a/scenes/interface/main_menu.gd b/scenes/interface/main_menu.gd index c9d8a2d..d2d1daa 100644 --- a/scenes/interface/main_menu.gd +++ b/scenes/interface/main_menu.gd @@ -1,2 +1,16 @@ extends Control class_name MainMenu + + +## Emitted when the player has clicked on the Play button. +signal selected_play + +## Emitted when the player has clicked on the Options button. +signal selected_options + + +func _on_play_pressed() -> void: + selected_play.emit() + +func _on_options_pressed() -> void: + selected_options.emit() diff --git a/scenes/interface/main_menu.tscn b/scenes/interface/main_menu.tscn index 2e76081..241bba9 100644 --- a/scenes/interface/main_menu.tscn +++ b/scenes/interface/main_menu.tscn @@ -28,7 +28,14 @@ grow_horizontal = 2 grow_vertical = 2 alignment = 1 -[node name="RichTextLabel" type="RichTextLabel" parent="Panel/Layout"] +[node name="Title" type="MarginContainer" parent="Panel/Layout"] +layout_mode = 2 +theme_override_constants/margin_left = 16 +theme_override_constants/margin_top = 16 +theme_override_constants/margin_right = 16 +theme_override_constants/margin_bottom = 16 + +[node name="Label" type="RichTextLabel" parent="Panel/Layout/Title"] layout_mode = 2 size_flags_vertical = 6 bbcode_enabled = true @@ -37,3 +44,29 @@ text = "[center][font_size=144px]Garasauto[/font_size] [font_size=32px]Un gioco del Garasautomobileclub Italia[/font_size][/center]" fit_content = true + +[node name="Buttons" type="MarginContainer" parent="Panel/Layout"] +layout_mode = 2 +theme_override_constants/margin_left = 16 +theme_override_constants/margin_top = 16 +theme_override_constants/margin_right = 16 +theme_override_constants/margin_bottom = 16 + +[node name="Layout" type="HBoxContainer" parent="Panel/Layout/Buttons"] +layout_mode = 2 +alignment = 1 + +[node name="Play" type="Button" parent="Panel/Layout/Buttons/Layout"] +custom_minimum_size = Vector2(200, 0) +layout_mode = 2 +theme_override_font_sizes/font_size = 36 +text = "Play" + +[node name="Options" type="Button" parent="Panel/Layout/Buttons/Layout"] +custom_minimum_size = Vector2(200, 0) +layout_mode = 2 +theme_override_font_sizes/font_size = 36 +text = "Options" + +[connection signal="pressed" from="Panel/Layout/Buttons/Layout/Play" to="." method="_on_play_pressed"] +[connection signal="pressed" from="Panel/Layout/Buttons/Layout/Options" to="." method="_on_options_pressed"]