From 0c31e684e3f14c9c5839c0dd5ea8de7b345569b8 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 30 Jun 2025 23:21:33 -0500 Subject: [PATCH] Cutscene --- scenes/TestScene.tscn | 14 +++++++---- scripts/cutscene/Cutscene.gd | 29 ++++++++++++++++++++++- scripts/cutscene/item/CutsceneItem.gd | 5 ++++ scripts/cutscene/item/CutsceneItem.gd.uid | 1 + scripts/cutscene/item/CutsceneText.gd | 23 ++++++++++++++++++ scripts/cutscene/item/CutsceneText.gd.uid | 1 + scripts/entities/NPC.gd | 5 ++++ 7 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 scripts/cutscene/item/CutsceneItem.gd create mode 100644 scripts/cutscene/item/CutsceneItem.gd.uid create mode 100644 scripts/cutscene/item/CutsceneText.gd create mode 100644 scripts/cutscene/item/CutsceneText.gd.uid diff --git a/scenes/TestScene.tscn b/scenes/TestScene.tscn index 0ec857f..8d52503 100644 --- a/scenes/TestScene.tscn +++ b/scenes/TestScene.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=11 format=3 uid="uid://b16ysbx7ah03u"] +[gd_scene load_steps=12 format=3 uid="uid://b16ysbx7ah03u"] [ext_resource type="PackedScene" uid="uid://d3rtd0ln7l2gr" path="res://scenes/maps/tundra/MapTundra.tscn" id="1_2gju5"] [ext_resource type="PackedScene" uid="uid://2ch34sio36nv" path="res://scenes/entities/Player.tscn" id="2_rlkm5"] [ext_resource type="Script" uid="uid://csb0i132lcu0w" path="res://scripts/entities/MapCamera.gd" id="3_n77mx"] [ext_resource type="PackedScene" uid="uid://bng2mc7fu5aik" path="res://scenes/entities/NPC.tscn" id="4_nb1wl"] [ext_resource type="Script" uid="uid://chxpes3546yoj" path="res://scripts/cutscene/Cutscene.gd" id="5_m5dm6"] +[ext_resource type="Script" uid="uid://8updtj1mctra" path="res://scripts/cutscene/item/CutsceneText.gd" id="6_fws1a"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_n77mx"] @@ -37,10 +38,10 @@ point_count = 2 [node name="Player" parent="." instance=ExtResource("2_rlkm5")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.06402, 1.54702, -2.35884) -[node name="NPC" parent="." instance=ExtResource("4_nb1wl")] +[node name="NPC" parent="." node_paths=PackedStringArray("cutscene") instance=ExtResource("4_nb1wl")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.20455, 1.94676, -3.51349) -interactType = 1 -interactTexts = Array[String](["Hello interact 1", "test interact 2"]) +interactType = 2 +cutscene = NodePath("../Cutscenes/TestCutscene") [node name="Camera3D" type="Camera3D" parent="." node_paths=PackedStringArray("targetFollow", "pathFollow", "pathMap")] transform = Transform3D(0.996991, 0.0418507, -0.0652558, 0, 0.841762, 0.539849, 0.0775229, -0.538225, 0.839228, 1.25757, 8.21861, 8.01254) @@ -69,3 +70,8 @@ curve = SubResource("Curve3D_nb1wl") [node name="TestCutscene" type="Node" parent="Cutscenes"] script = ExtResource("5_m5dm6") + +[node name="CutsceneText" type="Node" parent="Cutscenes/TestCutscene"] +script = ExtResource("6_fws1a") +interactTexts = Array[String](["test cutscene item 1", "tttt2"]) +metadata/_custom_type_script = "uid://8updtj1mctra" diff --git a/scripts/cutscene/Cutscene.gd b/scripts/cutscene/Cutscene.gd index c04a425..11f7ae9 100644 --- a/scripts/cutscene/Cutscene.gd +++ b/scripts/cutscene/Cutscene.gd @@ -1,4 +1,31 @@ class_name Cutscene extends Node +var items:Array[CutsceneItem] = [] +var itemIndex:int = 0 + +func _enter_tree() -> void: + # Get children + var children = get_children() + for child in children: + if !(child is CutsceneItem): + continue + items.append(child) + pass + +func _exit_tree() -> void: + items.clear() + pass + func start() -> void: - pass \ No newline at end of file + itemIndex = -1 + if items.size() == 0: + return + nextItem() + +func nextItem() -> void: + itemIndex += 1 + if itemIndex >= items.size(): + return + + var item = items[itemIndex] + item.start() \ No newline at end of file diff --git a/scripts/cutscene/item/CutsceneItem.gd b/scripts/cutscene/item/CutsceneItem.gd new file mode 100644 index 0000000..6ccf519 --- /dev/null +++ b/scripts/cutscene/item/CutsceneItem.gd @@ -0,0 +1,5 @@ +class_name CutsceneItem extends Node + +func start() -> void: + # This method should be overridden by subclasses + pass \ No newline at end of file diff --git a/scripts/cutscene/item/CutsceneItem.gd.uid b/scripts/cutscene/item/CutsceneItem.gd.uid new file mode 100644 index 0000000..8c144e1 --- /dev/null +++ b/scripts/cutscene/item/CutsceneItem.gd.uid @@ -0,0 +1 @@ +uid://dbjcrhunrugyb diff --git a/scripts/cutscene/item/CutsceneText.gd b/scripts/cutscene/item/CutsceneText.gd new file mode 100644 index 0000000..59b4b87 --- /dev/null +++ b/scripts/cutscene/item/CutsceneText.gd @@ -0,0 +1,23 @@ +class_name CutsceneText extends CutsceneItem + +@export_multiline var interactTexts:Array[String] = [] +var nextTextIndex:int = 0 + +func _enter_tree() -> void: + pass + +func _exit_tree() -> void: + UI.TEXTBOX.textboxClosing.disconnect(onTextboxClosing) + +func start() -> void: + nextTextIndex = 0 + UI.TEXTBOX.setText(interactTexts[nextTextIndex]) + UI.TEXTBOX.textboxClosing.connect(onTextboxClosing) + +func onTextboxClosing() -> void: + nextTextIndex += 1 + if nextTextIndex < interactTexts.size(): + UI.TEXTBOX.setText(interactTexts[nextTextIndex]) + else: + UI.TEXTBOX.textboxClosing.disconnect(onTextboxClosing) + UI.TEXTBOX.setText("") \ No newline at end of file diff --git a/scripts/cutscene/item/CutsceneText.gd.uid b/scripts/cutscene/item/CutsceneText.gd.uid new file mode 100644 index 0000000..c14cff2 --- /dev/null +++ b/scripts/cutscene/item/CutsceneText.gd.uid @@ -0,0 +1 @@ +uid://8updtj1mctra diff --git a/scripts/entities/NPC.gd b/scripts/entities/NPC.gd index 4d6c32f..f2415ba 100644 --- a/scripts/entities/NPC.gd +++ b/scripts/entities/NPC.gd @@ -31,11 +31,16 @@ func _on_interact() -> void: nextTextIndex = 0 match interactType: InteractType.TEXTBOX: + if interactTexts.size() == 0: + return UI.TEXTBOX.setText(interactTexts[nextTextIndex]) UI.TEXTBOX.textboxClosing.connect(onTextboxClosing) + return + InteractType.CUTSCENE: if cutscene: cutscene.start() + return _: return