Added menu system

pull/50/head
Jan Heemstra 2021-06-01 23:53:32 +02:00
parent 7c9b6711a5
commit 28ecbd4729
7 changed files with 140 additions and 0 deletions

8
Game/GUI.gd Normal file
View File

@ -0,0 +1,8 @@
extends Control
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func quit_game():
get_tree().quit()

35
Game/GUI.tscn Normal file
View File

@ -0,0 +1,35 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://GUI.gd" type="Script" id=1]
[ext_resource path="res://Menu.tscn" type="PackedScene" id=2]
[node name="GUI" type="CenterContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="MainMenu" parent="." instance=ExtResource( 2 )]
offset_left = 477.0
offset_top = 252.0
offset_right = 547.0
offset_bottom = 347.0
[node name="Options" type="Button" parent="MainMenu"]
offset_top = 33.0
offset_right = 70.0
offset_bottom = 62.0
text = "options"
script = null
[node name="Quit" type="Button" parent="MainMenu"]
offset_top = 66.0
offset_right = 70.0
offset_bottom = 95.0
text = "quit"
script = null
[connection signal="pressed" from="MainMenu/Options" to="MainMenu" method="open_menu" binds= [ "res://OptionsMenu.tscn" ]]
[connection signal="pressed" from="MainMenu/Quit" to="." method="quit_game"]

11
Game/GraphicsMenu.gd Normal file
View File

@ -0,0 +1,11 @@
extends "res://Menu.gd"
# Called when the node enters the scene tree for the first time.
func _ready():
pass
func toggle_fullscreen(button_pressed):
if button_pressed:
get_tree().get_root().mode = Window.MODE_FULLSCREEN
else:
get_tree().get_root().mode = Window.MODE_WINDOWED

20
Game/GraphicsMenu.tscn Normal file
View File

@ -0,0 +1,20 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Menu.tscn" type="PackedScene" id=1]
[ext_resource path="res://GraphicsMenu.gd" type="Script" id=2]
[node name="GraphicsMenu" instance=ExtResource( 1 )]
script = ExtResource( 2 )
[node name="Fullscreen" type="CheckButton" parent="." index="0"]
offset_right = 158.0
offset_bottom = 40.0
text = "Fullscreen"
script = null
[node name="Back" parent="." index="1"]
offset_top = 44.0
offset_right = 158.0
offset_bottom = 73.0
[connection signal="toggled" from="Fullscreen" to="." method="toggle_fullscreen"]

19
Game/Menu.gd Normal file
View File

@ -0,0 +1,19 @@
extends VBoxContainer
var previous_menu : Node = null
# Called when the node enters the scene tree for the first time.
func _ready():
if previous_menu == null:
$Back.hide()
func open_menu(path : String):
var menu = load(path).instance()
menu.previous_menu = self
get_parent().add_child(menu)
hide()
func go_back():
previous_menu.show()
previous_menu = null
queue_free()

22
Game/Menu.tscn Normal file
View File

@ -0,0 +1,22 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Menu.gd" type="Script" id=1]
[node name="Menu" type="VBoxContainer"]
offset_left = 475.0
offset_top = 269.0
offset_right = 548.0
offset_bottom = 331.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Back" type="Button" parent="."]
offset_right = 73.0
offset_bottom = 29.0
text = "back
"
script = null
[connection signal="pressed" from="Back" to="." method="go_back"]

25
Game/OptionsMenu.tscn Normal file
View File

@ -0,0 +1,25 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Menu.tscn" type="PackedScene" id=1]
[node name="OptionsMenu" instance=ExtResource( 1 )]
[node name="Graphics" type="Button" parent="." index="0"]
offset_right = 80.0
offset_bottom = 29.0
text = "Graphics"
script = null
[node name="Controls" type="Button" parent="." index="1"]
offset_top = 33.0
offset_right = 80.0
offset_bottom = 62.0
text = "Controls"
script = null
[node name="Back" parent="." index="2"]
offset_top = 66.0
offset_right = 80.0
offset_bottom = 95.0
[connection signal="pressed" from="Graphics" to="." method="open_menu" binds= [ "res://GraphicsMenu.tscn" ]]