From 7b382dcbe15756e1b00a0d6d35af8ec6923f9d92 Mon Sep 17 00:00:00 2001 From: Techwizz Date: Thu, 26 Jan 2023 13:23:13 -0700 Subject: [PATCH] updated settings and menu more --- characters/teddy/Teddy.gd | 12 +++++++----- project.godot | 1 + scenes/settings.tscn | 37 ++++++++++++++++++++++++++++++++----- scripts/global.gd | 2 ++ scripts/mainmenu.gd | 15 +++++++++++---- scripts/settings.gd | 4 ++++ 6 files changed, 57 insertions(+), 14 deletions(-) diff --git a/characters/teddy/Teddy.gd b/characters/teddy/Teddy.gd index 283eeed..61c8e67 100644 --- a/characters/teddy/Teddy.gd +++ b/characters/teddy/Teddy.gd @@ -10,9 +10,11 @@ var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") @onready var neck := $Neck @onready var camera := $Neck/Camera3D -var openmenu = false var globalscene +func _ready(): + Global.playingGame = true + func _unhandled_input(event): if event is InputEventMouseButton: Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) @@ -24,16 +26,16 @@ func _unhandled_input(event): neck.rotate_y(-event.relative.x * mousesense) camera.rotate_x(-event.relative.y * mousesense) camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-35), deg_to_rad(60)) - if openmenu == false: + if Global.menuOpen == false: if Input.is_action_just_pressed("menu"): - openmenu = true + Global.menuOpen = true var scene_trs = load("res://scenes/mainmenu.tscn") var scene = scene_trs.instantiate() globalscene = scene add_child(scene) - elif openmenu == true: + elif Global.menuOpen == true: if Input.is_action_just_pressed("menu"): - openmenu = false + Global.menuOpen = false Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) if globalscene: globalscene.queue_free() diff --git a/project.godot b/project.godot index 4c4f7b8..e0c09ba 100644 --- a/project.godot +++ b/project.godot @@ -13,6 +13,7 @@ config_version=5 config/name="Project Teddy" run/main_scene="res://scenes/mainmenu.tscn" config/features=PackedStringArray("4.0", "Forward Plus") +boot_splash/show_image=false config/icon="res://icon.svg" [autoload] diff --git a/scenes/settings.tscn b/scenes/settings.tscn index 24a5a3c..ef936be 100644 --- a/scenes/settings.tscn +++ b/scenes/settings.tscn @@ -1,7 +1,10 @@ -[gd_scene load_steps=2 format=3 uid="uid://dy5lqto7557fg"] +[gd_scene load_steps=3 format=3 uid="uid://dy5lqto7557fg"] [ext_resource type="Script" path="res://scripts/settings.gd" id="1_gpx88"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_j46gp"] +bg_color = Color(0.2, 0.2, 0.2, 1) + [node name="settings" type="Control"] layout_mode = 3 anchors_preset = 15 @@ -11,23 +14,47 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_gpx88") +[node name="Panel" type="Panel" parent="."] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -110.0 +offset_top = -156.0 +offset_right = 140.0 +offset_bottom = 134.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_j46gp") + [node name="h_slider" type="HSlider" parent="."] layout_mode = 2 offset_left = 498.0 -offset_top = 249.0 +offset_top = 238.0 offset_right = 682.0 -offset_bottom = 265.0 +offset_bottom = 254.0 max_value = 0.02 step = 0.001 [node name="Label" type="Label" parent="."] layout_mode = 2 offset_left = 497.0 -offset_top = 224.0 +offset_top = 213.0 offset_right = 685.0 -offset_bottom = 250.0 +offset_bottom = 239.0 size_flags_vertical = 0 text = "Adjust Mouse sensitivity" +[node name="Button" type="Button" parent="."] +layout_mode = 0 +offset_left = 470.0 +offset_top = 173.0 +offset_right = 501.0 +offset_bottom = 204.0 +text = "X" + [connection signal="ready" from="h_slider" to="." method="_on_h_slider_ready"] [connection signal="value_changed" from="h_slider" to="." method="_on_h_slider_value_changed"] +[connection signal="pressed" from="Button" to="." method="_on_button_pressed"] diff --git a/scripts/global.gd b/scripts/global.gd index 7f1036f..6156ece 100644 --- a/scripts/global.gd +++ b/scripts/global.gd @@ -1,3 +1,5 @@ extends Node var mouseSensitivity = 0.01 # Unless otherwise changed by user in settings +var playingGame = false +var menuOpen = false diff --git a/scripts/mainmenu.gd b/scripts/mainmenu.gd index a0d9d44..4bf24c4 100644 --- a/scripts/mainmenu.gd +++ b/scripts/mainmenu.gd @@ -1,16 +1,23 @@ extends Control -# Called when the node enters the scene tree for the first time. + + func _ready(): - pass # Replace with function body. + if Global.playingGame == true: + $Button.text = "RESUME" -# Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): pass func _on_button_pressed(): - get_tree().change_scene_to_file("res://scenes/playground.tscn") + if Global.playingGame == false: + get_tree().change_scene_to_file("res://scenes/playground.tscn") + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + elif Global.playingGame == true: + self.queue_free() + Global.menuOpen = false + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) func _on_button_2_pressed(): var scene_trs =load("res://scenes/settings.tscn") diff --git a/scripts/settings.gd b/scripts/settings.gd index e9a4066..36c6a4a 100644 --- a/scripts/settings.gd +++ b/scripts/settings.gd @@ -15,3 +15,7 @@ func _process(delta): func _on_h_slider_value_changed(value): Global.mouseSensitivity = value + + +func _on_button_pressed(): + self.queue_free()