From aba3e033827b1747d9c09237dc5639ca107c8ce0 Mon Sep 17 00:00:00 2001 From: Rmojarro1 <48000819+Rmojarro1@users.noreply.github.com> Date: Thu, 6 Feb 2025 16:05:24 -0800 Subject: [PATCH 1/2] Added main menu with transition to battle and exit Made a scene with two buttons; one will transition to our test battle scene, the other exits the game. The battle scene now has a button in the upper left that will return to the main menu. Makes use of a SceneChange script, which allows for a path to be set for the button in the inspector(doesn't need quotation marks), or exit to make the button quit the game. I noticed a infinite loop warning when exiting battle scene (the tweens don;t seem to stop if we exit), had to make minor change to ChartManager with an exitTree function to stop the tweens when we leave --- project.godot | 2 +- scenes/BattleDirector/test_battle_scene.tscn | 17 +++++++++- scenes/ChartViewport/ChartManager.cs | 11 ++++++ scenes/TestTransition/testTransition.tscn | 33 ++++++++++++++++++ scripts/SceneChange.cs | 35 ++++++++++++++++++++ 5 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 scenes/TestTransition/testTransition.tscn create mode 100644 scripts/SceneChange.cs diff --git a/project.godot b/project.godot index ba8f8e20..1d9a4983 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="Funk Engine" -run/main_scene="res://scenes/BattleDirector/test_battle_scene.tscn" +run/main_scene="res://scenes/TestTransition/testTransition.tscn" config/features=PackedStringArray("4.3", "C#", "Forward Plus") config/icon="res://icon.svg" diff --git a/scenes/BattleDirector/test_battle_scene.tscn b/scenes/BattleDirector/test_battle_scene.tscn index 772d4487..8c6ffbae 100644 --- a/scenes/BattleDirector/test_battle_scene.tscn +++ b/scenes/BattleDirector/test_battle_scene.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=3 uid="uid://b0mrgr7h0ty1y"] +[gd_scene load_steps=10 format=3 uid="uid://b0mrgr7h0ty1y"] [ext_resource type="Script" path="res://scenes/BattleDirector/BattleDirector.cs" id="1_cwqqr"] [ext_resource type="PackedScene" uid="uid://dfevfib11kou1" path="res://scenes/ChartViewport/ChartViewport.tscn" id="2_cupb3"] @@ -8,6 +8,7 @@ [ext_resource type="Texture2D" uid="uid://veedngaorx3l" path="res://scenes/BattleDirector/assets/Enemy1.png" id="6_0k4pw"] [ext_resource type="PackedScene" uid="uid://duhiilcv4tat3" path="res://scenes/BattleDirector/NotePlacementBar.tscn" id="7_3ko4g"] [ext_resource type="AudioStream" uid="uid://cv6lqjj6lu36h" path="res://Audio/335571__magntron__gamemusic_120bpm.mp3" id="8_caqms"] +[ext_resource type="Script" path="res://scripts/SceneChange.cs" id="9_bxa6e"] [node name="ProtoBattleDirector" type="Node2D" node_paths=PackedStringArray("CM", "IH", "NotePlacementBar", "Audio")] script = ExtResource("1_cwqqr") @@ -59,3 +60,17 @@ offset_left = 16.0 offset_top = 164.0 offset_right = 16.0 offset_bottom = 164.0 + +[node name="Control" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="Button" type="Button" parent="Control"] +layout_mode = 0 +offset_right = 8.0 +offset_bottom = 8.0 +text = "Return to Title" +script = ExtResource("9_bxa6e") +ScenePath = "res://scenes/TestTransition/testTransition.tscn" diff --git a/scenes/ChartViewport/ChartManager.cs b/scenes/ChartViewport/ChartManager.cs index 4ecae9e4..e6f3840a 100644 --- a/scenes/ChartViewport/ChartManager.cs +++ b/scenes/ChartViewport/ChartManager.cs @@ -117,4 +117,15 @@ private NoteArrow CreateNote(ArrowType arrow, int beat = 0) newArrow.Position += Vector2.Right * newArrow.Bounds * 10; //temporary fix for notes spawning and instantly calling loop from originating at 0,0 return newArrow; } + + public override void _ExitTree() + { + GD.Print("[DEBUG] Stopping tweens before exiting the scene..."); + + foreach (var tween in GetTree().GetProcessedTweens()) + { + tween.Stop(); + GD.Print("[DEBUG] Stopped tween."); + } + } } diff --git a/scenes/TestTransition/testTransition.tscn b/scenes/TestTransition/testTransition.tscn new file mode 100644 index 00000000..6481b551 --- /dev/null +++ b/scenes/TestTransition/testTransition.tscn @@ -0,0 +1,33 @@ +[gd_scene load_steps=2 format=3 uid="uid://dbeplni2du158"] + +[ext_resource type="Script" path="res://scripts/SceneChange.cs" id="1_n6d5u"] + +[node name="Control" type="Control"] +layout_mode = 3 +anchors_preset = 0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="Node2D" type="Node2D" parent="."] + +[node name="StartButton" type="Button" parent="."] +layout_mode = 0 +offset_left = 120.0 +offset_top = 56.0 +offset_right = 128.0 +offset_bottom = 64.0 +scale = Vector2(2.48, 2.48) +text = "start battle" +script = ExtResource("1_n6d5u") +ScenePath = "res://scenes/BattleDirector/test_battle_scene.tscn" + +[node name="ExitButton" type="Button" parent="."] +layout_mode = 0 +offset_left = 471.0 +offset_top = 95.0 +offset_right = 508.0 +offset_bottom = 126.0 +scale = Vector2(2.56, 2.56) +text = "exit" +script = ExtResource("1_n6d5u") +ScenePath = "exit" diff --git a/scripts/SceneChange.cs b/scripts/SceneChange.cs new file mode 100644 index 00000000..daaa9bd7 --- /dev/null +++ b/scripts/SceneChange.cs @@ -0,0 +1,35 @@ +using System; +using Godot; + +public partial class SceneChange : Button +{ + [Export] + public string ScenePath = ""; + + public override void _Ready() + { + Pressed += OnButtonPressed; + GD.Print($"[DEBUG] Scene Path: '{ScenePath}' (Length: {ScenePath.Length})"); + } + + private void OnButtonPressed() + { + ScenePath = ScenePath.Trim('\"'); + if (ScenePath.ToLower() == "exit") + { + GD.Print("Exiting game"); + GetTree().Quit(); + return; + } + + if (string.IsNullOrEmpty(ScenePath) || !ResourceLoader.Exists(ScenePath)) + { + GD.PrintErr($"❌ Scene not found: {ScenePath}"); + GD.Print($"[DEBUG] Trying to load: '{ScenePath}' (Length: {ScenePath.Length})"); + return; + } + + GD.Print($"✅ Loading scene: {ScenePath}"); + GetTree().ChangeSceneToFile(ScenePath); + } +} From 36cef29da3074b14f32b2208334cfd49d34c789e Mon Sep 17 00:00:00 2001 From: LifeHckr Date: Sun, 9 Feb 2025 19:36:09 -0800 Subject: [PATCH 2/2] Removed debug scenepath length printing --- scripts/SceneChange.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/SceneChange.cs b/scripts/SceneChange.cs index daaa9bd7..6c1db327 100644 --- a/scripts/SceneChange.cs +++ b/scripts/SceneChange.cs @@ -9,12 +9,12 @@ public partial class SceneChange : Button public override void _Ready() { Pressed += OnButtonPressed; - GD.Print($"[DEBUG] Scene Path: '{ScenePath}' (Length: {ScenePath.Length})"); + GD.Print($"[DEBUG] Scene Path: '{ScenePath}'"); } private void OnButtonPressed() { - ScenePath = ScenePath.Trim('\"'); + //ScenePath = ScenePath.Trim('\"'); if (ScenePath.ToLower() == "exit") { GD.Print("Exiting game"); @@ -25,7 +25,7 @@ private void OnButtonPressed() if (string.IsNullOrEmpty(ScenePath) || !ResourceLoader.Exists(ScenePath)) { GD.PrintErr($"❌ Scene not found: {ScenePath}"); - GD.Print($"[DEBUG] Trying to load: '{ScenePath}' (Length: {ScenePath.Length})"); + GD.Print($"[DEBUG] Trying to load: '{ScenePath}'"); return; }