Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created Menu scene for game and StartMenu scenes #22

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions menus/main_menu.gd

This file was deleted.

32 changes: 0 additions & 32 deletions menus/main_menu.tscn

This file was deleted.

47 changes: 47 additions & 0 deletions menus/menu.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
extends CanvasLayer

var isInGame: bool = false

func setIsInGame(value: bool = false) -> void:
isInGame = value

# Visible on Main Menu
$ButtonsContainer/PlayButton.visible = !isInGame
$ButtonsContainer/QuitButton.visible = !isInGame

# Visible on game scene
$ButtonsContainer/ResumeButton.visible = isInGame
$ButtonsContainer/BackButton.visible = isInGame
$PausedLabel.visible = isInGame

func _ready() -> void:
setIsInGame()

func _input(event):
if event.is_action_released("ui_cancel") and isInGame:
if get_tree().paused: _resume()
else: _pause()

func _pause() -> void:
get_tree().paused = true
visible = true

func _resume() -> void:
get_tree().paused = false
visible = false

func _on_play_button_pressed() -> void:
get_tree().change_scene_to_file("res://scenes/game/game.tscn")

func _on_resume_button_pressed() -> void:
_resume()

func _on_settings_button_pressed() -> void:
print("Settings")

func _on_back_button_pressed() -> void:
get_tree().paused = false
get_tree().change_scene_to_file("res://scenes/start_menu/start_menu.tscn")

func _on_quit_button_pressed() -> void:
get_tree().quit()
91 changes: 91 additions & 0 deletions menus/menu.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
[gd_scene load_steps=4 format=3 uid="uid://g3e0eodhl7xl"]

[ext_resource type="Script" path="res://menus/menu.gd" id="1_uyh0y"]

[sub_resource type="LabelSettings" id="LabelSettings_mv1id"]
font_size = 64
font_color = Color(0.615686, 1, 0.717647, 1)
outline_size = 4
outline_color = Color(0, 0, 0, 1)
shadow_color = Color(0, 0.956863, 0, 0.431373)

[sub_resource type="LabelSettings" id="LabelSettings_s5kro"]
font_size = 32
outline_size = 2
outline_color = Color(0, 1, 0, 1)
shadow_color = Color(0, 1, 0, 1)
shadow_offset = Vector2(-1, -1)

[node name="Menu" type="CanvasLayer"]
process_mode = 3
editor_description = "Menu scene for \"Game\" and \"StartMenu\" scenes"
script = ExtResource("1_uyh0y")

[node name="Background" type="ColorRect" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0, 0, 0, 0.364706)

[node name="Title" type="Label" parent="."]
anchors_preset = 10
anchor_right = 1.0
offset_bottom = 118.0
grow_horizontal = 2
text = "Tree Simulator"
label_settings = SubResource("LabelSettings_mv1id")
horizontal_alignment = 1
vertical_alignment = 1

[node name="PausedLabel" type="Label" parent="."]
visible = false
anchors_preset = 10
anchor_right = 1.0
offset_top = 112.0
offset_bottom = 230.0
grow_horizontal = 2
text = "Paused"
label_settings = SubResource("LabelSettings_s5kro")
horizontal_alignment = 1
vertical_alignment = 1

[node name="ButtonsContainer" type="VBoxContainer" parent="."]
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -189.0
offset_top = -68.0
offset_right = 189.0
offset_bottom = 68.0
grow_horizontal = 2
grow_vertical = 2

[node name="PlayButton" type="Button" parent="ButtonsContainer"]
layout_mode = 2
text = "Play"

[node name="ResumeButton" type="Button" parent="ButtonsContainer"]
layout_mode = 2
text = "Resume"

[node name="SettingsButton" type="Button" parent="ButtonsContainer"]
layout_mode = 2
text = "Settings"

[node name="BackButton" type="Button" parent="ButtonsContainer"]
layout_mode = 2
text = "Back"

[node name="QuitButton" type="Button" parent="ButtonsContainer"]
layout_mode = 2
text = "Quit"

[connection signal="pressed" from="ButtonsContainer/PlayButton" to="." method="_on_play_button_pressed"]
[connection signal="pressed" from="ButtonsContainer/ResumeButton" to="." method="_on_resume_button_pressed"]
[connection signal="pressed" from="ButtonsContainer/SettingsButton" to="." method="_on_settings_button_pressed"]
[connection signal="pressed" from="ButtonsContainer/BackButton" to="." method="_on_back_button_pressed"]
[connection signal="pressed" from="ButtonsContainer/QuitButton" to="." method="_on_quit_button_pressed"]
2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ config_version=5
[application]

config/name="Tree Simulator"
run/main_scene="res://menus/main_menu.tscn"
run/main_scene="res://scenes/start_menu/start_menu.tscn"
config/features=PackedStringArray("4.3", "Forward Plus")
config/icon="res://icon.svg"

Expand Down
4 changes: 4 additions & 0 deletions scenes/game/game.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extends Node3D

@onready var menu: CanvasLayer = $Menu
@onready var player_level_status: VBoxContainer = $UI/PlayerLevelUI/PlayerLevelStatus
@onready var tree_level_status: VBoxContainer = $UI/TreeLevelUI/LevelStatus
@onready var tree_name: Label = $UI/TreeLevelUI/TreeName
Expand All @@ -8,6 +9,9 @@ extends Node3D
func _ready() -> void:
_update_ui()
_populate_option_button()

menu.visible = false
menu.setIsInGame(true)

func _on_xp_timer_timeout() -> void:
PlayerLS.add_xp()
Expand Down
7 changes: 5 additions & 2 deletions scenes/game/game.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=3 format=3 uid="uid://dkufj4sv64avp"]
[gd_scene load_steps=4 format=3 uid="uid://dkufj4sv64avp"]

[ext_resource type="Script" path="res://scenes/game/game.gd" id="1_b8j6q"]
[ext_resource type="PackedScene" uid="uid://2fuwpxsgv6ok" path="res://scenes/level_ui/level_ui.tscn" id="2_xnews"]
[ext_resource type="PackedScene" uid="uid://g3e0eodhl7xl" path="res://menus/menu.tscn" id="3_gr4f4"]

[node name="Game" type="Node3D"]
script = ExtResource("1_b8j6q")
Expand Down Expand Up @@ -40,10 +41,12 @@ layout_mode = 2

[node name="TreeSelector" type="OptionButton" parent="UI/TreeLevelUI"]
layout_mode = 2
selected = 0

[node name="XP_Timer" type="Timer" parent="."]
autostart = true

[node name="Menu" parent="." instance=ExtResource("3_gr4f4")]
visible = false

[connection signal="item_selected" from="UI/TreeLevelUI/TreeSelector" to="." method="_on_option_button_item_selected"]
[connection signal="timeout" from="XP_Timer" to="." method="_on_xp_timer_timeout"]
7 changes: 7 additions & 0 deletions scenes/start_menu/start_menu.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3 uid="uid://crg31x8k6vhsi"]

[ext_resource type="PackedScene" uid="uid://g3e0eodhl7xl" path="res://menus/menu.tscn" id="1_duan6"]

[node name="StartMenu" type="Node2D"]

[node name="Menu" parent="." instance=ExtResource("1_duan6")]