From 329fcb9eeb33139a1d3c9bec33ba58e12aaec71c Mon Sep 17 00:00:00 2001 From: trevyn <230691+trevyn@users.noreply.github.com> Date: Thu, 15 Aug 2024 18:55:15 +0400 Subject: [PATCH] add main menu videos --- Godottest/project.godot | 6 +++ Godottest/res/node.gd | 36 +++++++++++++ Godottest/res/node_2d.gd | 29 ++++++++++ Godottest/res/node_2d.tscn | 80 ++++++++++++++++++++++------ Godottest/res/video_stream_player.gd | 10 ++-- Godottest/res/vsp.gd | 49 +++++++++++++++++ 6 files changed, 190 insertions(+), 20 deletions(-) create mode 100644 Godottest/res/node.gd create mode 100644 Godottest/res/node_2d.gd create mode 100644 Godottest/res/vsp.gd diff --git a/Godottest/project.godot b/Godottest/project.godot index 1620b23..6f88b45 100644 --- a/Godottest/project.godot +++ b/Godottest/project.godot @@ -13,9 +13,15 @@ config_version=5 config/name="videoproject" run/main_scene="res://res/node_2d.tscn" config/features=PackedStringArray("4.3", "Forward Plus") +boot_splash/bg_color=Color(0, 0, 0, 1) boot_splash/show_image=false [display] window/size/viewport_width=1280 window/size/viewport_height=768 +window/stretch/mode="viewport" + +[rendering] + +viewport/transparent_background=true diff --git a/Godottest/res/node.gd b/Godottest/res/node.gd new file mode 100644 index 0000000..945720c --- /dev/null +++ b/Godottest/res/node.gd @@ -0,0 +1,36 @@ +extends Node + +var count = 0 + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + play_next() + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(_delta: float) -> void: + pass + + +func play_next(): + print(count) + get_next().start() + count += 1 + +func prep_next(): + get_next().prep() + +func get_next(): + + match count % 6: + 0: + return $VideoStreamPlayer + 1: + return $VideoStreamPlayer2 + 2: + return $VideoStreamPlayer3 + 3: + return $VideoStreamPlayer4 + 4: + return $VideoStreamPlayer5 + 5: + return $VideoStreamPlayer6 diff --git a/Godottest/res/node_2d.gd b/Godottest/res/node_2d.gd new file mode 100644 index 0000000..b0dff47 --- /dev/null +++ b/Godottest/res/node_2d.gd @@ -0,0 +1,29 @@ +extends Node2D + +var alpha = 0 + +# Function to set the alpha for the parent and its children +func set_alpha(alpha_value: float) -> void: + # Ensure alpha_value is between 0 and 1 + alpha_value = clamp(alpha_value, 0.0, 1.0) + + # Set the parent's alpha if it has a Modulate property + if has_method("set_modulate"): + modulate = Color(modulate.r, modulate.g, modulate.b, alpha_value) + + # Loop through each child + for child in get_children(): + if child.has_method("set_modulate"): + var child_modulate = child.modulate + child.modulate = Color(child_modulate.r, child_modulate.g, child_modulate.b, alpha_value) + +# Example function to change alpha +func _ready(): + pass + #set_alpha(0.5) # Change all children's alpha to 0.5 + +func _process(_delta): + + if alpha < 3.0: + alpha += 0.006; + set_alpha(alpha-2.0) # Change all children's alpha to 0.5 diff --git a/Godottest/res/node_2d.tscn b/Godottest/res/node_2d.tscn index 46a523c..3930a6c 100644 --- a/Godottest/res/node_2d.tscn +++ b/Godottest/res/node_2d.tscn @@ -1,7 +1,13 @@ -[gd_scene load_steps=6 format=3 uid="uid://pdkn35rn7rts"] +[gd_scene load_steps=12 format=3 uid="uid://pdkn35rn7rts"] -[ext_resource type="VideoStream" path="res://res/media/output.ogv" id="1_r13cb"] -[ext_resource type="Script" path="res://res/video_stream_player.gd" id="2_76rnb"] +[ext_resource type="Script" path="res://res/node_2d.gd" id="1_atssm"] +[ext_resource type="VideoStream" path="res://res/media/mainmenu-to-eyesclosedheadback.ogv" id="1_huc1b"] +[ext_resource type="VideoStream" path="res://res/media/mainmenu-from-walkin.ogv" id="1_ila7w"] +[ext_resource type="Script" path="res://res/node.gd" id="1_ypcjg"] +[ext_resource type="Script" path="res://res/vsp.gd" id="2_v4qc7"] +[ext_resource type="VideoStream" path="res://res/media/mainmenu-from-backofhead.ogv" id="5_3gsv2"] +[ext_resource type="VideoStream" path="res://res/media/mainmenu-to-lookdownandup.ogv" id="6_3pm7c"] +[ext_resource type="VideoStream" path="res://res/media/mainmenu-to-lookdownandshrug.ogv" id="7_g2nyq"] [sub_resource type="Theme" id="Theme_pqtiu"] default_font_size = 36 @@ -15,21 +21,61 @@ default_font_size = 55 [node name="Node2D" type="Node2D"] -[node name="ColorRect" type="ColorRect" parent="."] -offset_right = 1471.0 -offset_bottom = 824.0 -color = Color(0, 0, 0, 1) +[node name="Node" type="Node" parent="."] +script = ExtResource("1_ypcjg") -[node name="VideoStreamPlayer" type="VideoStreamPlayer" parent="."] +[node name="VideoStreamPlayer6" type="VideoStreamPlayer" parent="Node"] offset_right = 1280.0 offset_bottom = 768.0 -stream = ExtResource("1_r13cb") +stream = ExtResource("7_g2nyq") volume_db = -80.0 -autoplay = true -loop = true -script = ExtResource("2_76rnb") +script = ExtResource("2_v4qc7") +fadein = false -[node name="Label" type="Label" parent="."] +[node name="VideoStreamPlayer5" type="VideoStreamPlayer" parent="Node"] +offset_right = 1280.0 +offset_bottom = 768.0 +stream = ExtResource("5_3gsv2") +volume_db = -80.0 +script = ExtResource("2_v4qc7") +fadeout = false + +[node name="VideoStreamPlayer4" type="VideoStreamPlayer" parent="Node"] +offset_right = 1280.0 +offset_bottom = 768.0 +stream = ExtResource("6_3pm7c") +volume_db = -80.0 +script = ExtResource("2_v4qc7") +fadein = false + +[node name="VideoStreamPlayer3" type="VideoStreamPlayer" parent="Node"] +offset_right = 1280.0 +offset_bottom = 768.0 +stream = ExtResource("5_3gsv2") +volume_db = -80.0 +script = ExtResource("2_v4qc7") +fadeout = false + +[node name="VideoStreamPlayer2" type="VideoStreamPlayer" parent="Node"] +offset_right = 1280.0 +offset_bottom = 768.0 +stream = ExtResource("1_huc1b") +volume_db = -80.0 +script = ExtResource("2_v4qc7") +fadein = false + +[node name="VideoStreamPlayer" type="VideoStreamPlayer" parent="Node"] +offset_right = 1280.0 +offset_bottom = 768.0 +stream = ExtResource("1_ila7w") +volume_db = -80.0 +script = ExtResource("2_v4qc7") +fadeout = false + +[node name="Node2D" type="Node2D" parent="Node"] +script = ExtResource("1_atssm") + +[node name="Label" type="Label" parent="Node/Node2D"] offset_left = 724.0 offset_top = 374.0 offset_right = 956.0 @@ -38,7 +84,7 @@ theme = SubResource("Theme_pqtiu") text = "⇒ New Game" horizontal_alignment = 2 -[node name="Label4" type="Label" parent="."] +[node name="Label4" type="Label" parent="Node/Node2D"] offset_left = 767.0 offset_top = 326.0 offset_right = 957.0 @@ -47,7 +93,7 @@ theme = SubResource("Theme_pqtiu") text = "Continue" horizontal_alignment = 2 -[node name="Label5" type="Label" parent="."] +[node name="Label5" type="Label" parent="Node/Node2D"] offset_left = 444.0 offset_top = 87.0 offset_right = 962.0 @@ -56,7 +102,7 @@ theme = SubResource("Theme_norqa") text = "dungeon game" horizontal_alignment = 2 -[node name="Label2" type="Label" parent="."] +[node name="Label2" type="Label" parent="Node/Node2D"] offset_left = 766.0 offset_top = 423.0 offset_right = 956.0 @@ -65,7 +111,7 @@ theme = SubResource("Theme_pqtiu") text = "Settings" horizontal_alignment = 2 -[node name="Label3" type="Label" parent="."] +[node name="Label3" type="Label" parent="Node/Node2D"] offset_left = 763.0 offset_top = 473.0 offset_right = 953.0 diff --git a/Godottest/res/video_stream_player.gd b/Godottest/res/video_stream_player.gd index 603806d..3ef9493 100644 --- a/Godottest/res/video_stream_player.gd +++ b/Godottest/res/video_stream_player.gd @@ -4,11 +4,15 @@ var fade_direction = 0.02 # Called when the node enters the scene tree for the first time. func _ready() -> void: - pass # Replace with function body. - - + self.connect("finished", Callable(self, "_on_video_finished")) + self.play() + #self.paused=1 + # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta: float) -> void: #modulate.a+=fade_direction if modulate.a > 1.0 || modulate.a < 0.0: fade_direction=-fade_direction pass + +func _on_video_finished(): + self.get_parent().play_next() diff --git a/Godottest/res/vsp.gd b/Godottest/res/vsp.gd new file mode 100644 index 0000000..1b49fdc --- /dev/null +++ b/Godottest/res/vsp.gd @@ -0,0 +1,49 @@ +extends VideoStreamPlayer + +@export var fadeout: bool = true +@export var fadein: bool = true +@export var streamlength: float = 10. + +func _ready() -> void: + self.connect("finished", Callable(self, "_on_video_finished")) + self.play() + self.paused=1 + #if fadein: + modulate.a = 0 + +func prep(): + modulate.a = 1 + +func start(): + self.paused=0 + if fadein == false: + modulate.a = 1 + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(_delta: float) -> void: + if fadein && self.paused==false: + if modulate.a < 1.0: + modulate.a += 0.03 + + if fadeout == false && self.stream_position > streamlength/2: + get_parent().prep_next() + + if fadeout && self.stream_position > streamlength/2: + if self.stream_position > streamlength - 0.5: + modulate.a -= 0.05 + if modulate.a <= 0: + stop() + play() + paused=1 + get_parent().play_next() + else: + modulate.a=1 + + pass + +func _on_video_finished(): + modulate.a = 0 + self.stop() + self.play() + self.paused=1 + self.get_parent().play_next()