1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-21 15:44:23 +00:00

Add a basic main menu

This commit is contained in:
Steffo 2024-04-13 04:04:43 +02:00
parent c92797661e
commit 0a88bc0db9
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
4 changed files with 98 additions and 3 deletions

56
main.gd
View file

@ -1,2 +1,58 @@
extends Node
class_name Main
@onready var container: Control = $"PrimaryCanvas/SafeMarginContainer"
## The possible states the game can be in.
enum Stage {
NONE = 0,
MENU = 1,
}
## The [Stage] the game is currently in.
##
## Changing this will automatically destroy and build the relevant scenes.
var current_stage: Stage:
get:
return current_stage
set(value):
# Do not rebuild scenes if the stage is set to the value it's already set to
if value == current_stage:
return
# Destroy the current scenes
match current_stage:
Stage.MENU:
destroy_menu()
# Update the current stage
current_stage = value
# Build the next scenes
match current_stage:
Stage.MENU:
build_menu()
## The [Stage] that [field current_stage] should be set to upon starting the game.
@export var starting_stage: Stage
## The main menu scene.
const SCENE_MENU: PackedScene = preload("res://scenes/interface/main_menu.tscn")
## The main menu node.
var scene_menu: MainMenu = null
## Destroy the main menu.
func destroy_menu() -> void:
scene_menu.queue_free()
scene_menu = null
## Build the main menu.
func build_menu() -> void:
scene_menu = SCENE_MENU.instantiate()
container.add_child(scene_menu)
func _ready() -> void:
current_stage = starting_stage

View file

@ -5,6 +5,7 @@
[node name="Main" type="Node"]
script = ExtResource("1_jyg3q")
starting_stage = 1
[node name="PrimaryCanvas" type="CanvasLayer" parent="."]
@ -13,6 +14,3 @@ min_margin_left = 16
min_margin_right = 16
min_margin_top = 16
min_margin_bottom = 16
[node name="Panel" type="Panel" parent="PrimaryCanvas/SafeMarginContainer"]
layout_mode = 2

View file

@ -0,0 +1,2 @@
extends Control
class_name MainMenu

View file

@ -0,0 +1,39 @@
[gd_scene load_steps=2 format=3 uid="uid://3yqvhxeq03rk"]
[ext_resource type="Script" path="res://scenes/interface/main_menu.gd" id="1_jkswn"]
[node name="MainMenu" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_jkswn")
[node name="Panel" type="Panel" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="Layout" type="VBoxContainer" parent="Panel"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
alignment = 1
[node name="RichTextLabel" type="RichTextLabel" parent="Panel/Layout"]
layout_mode = 2
size_flags_vertical = 6
bbcode_enabled = true
text = "[center][font_size=144px]Garasauto[/font_size]
[font_size=64px]Il casello del destino[/font_size]
[font_size=32px]Un gioco del Garasautomobileclub Italia[/font_size][/center]"
fit_content = true