From 533f41fedfd23a3949e8819800274476d668b76d Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 20 Aug 2020 13:07:50 +0200 Subject: [PATCH] Add fadein and fadeout to dialogues and other improvements --- BlackScreen.tscn | 6 ++++++ dialogues/End_Lie.json | 34 +++++++++++++++++----------------- dialogues/oilTanker1.json | 5 +++-- dialogues/oilTanker2.json | 2 +- dialogues/oilTanker3.json | 4 +--- dialogues/oilTanker4.json | 5 ++--- dialogues/oilTanker5.json | 5 +++++ project.godot | 6 ++++++ scenes/campfire.tscn | 1 - scenes/dialogue.tscn | 8 +++++++- scenes/oil_tanker.tscn | 2 +- scripts/BlackScreen.gd | 25 +++++++++++++++++++++++++ scripts/DialogueBox.gd | 24 +++++++++++++++++++----- scripts/oil_tanker.gd | 11 +++++++---- 14 files changed, 100 insertions(+), 38 deletions(-) create mode 100644 BlackScreen.tscn create mode 100644 dialogues/oilTanker5.json create mode 100644 scripts/BlackScreen.gd diff --git a/BlackScreen.tscn b/BlackScreen.tscn new file mode 100644 index 0000000..c64916e --- /dev/null +++ b/BlackScreen.tscn @@ -0,0 +1,6 @@ +[gd_scene format=2] + +[node name="BlackScreen" type="Polygon2D"] +modulate = Color( 1, 1, 1, 0.905882 ) +color = Color( 0, 0, 0, 1 ) +polygon = PoolVector2Array( 0, 0, 192, 0, 192, 108, 0, 108 ) diff --git a/dialogues/End_Lie.json b/dialogues/End_Lie.json index 5e542cb..def03ce 100644 --- a/dialogues/End_Lie.json +++ b/dialogues/End_Lie.json @@ -1,29 +1,29 @@ [ - {"name": "Ely", "text": "I am a part of a non-profit organisation."}, - {"name": "Crab", "text": "A what?"}, + {"name": "Ely", "text": "I am a part of a non-profit organization."}, + {"name": "Herbert", "text": "A what?"}, {"name": "Ely", "text": "A bunch of people doing things more or less selflessly."}, - {"name": "Crab", "text": "Oh, that's nice!"}, - {"name": "Ely", "text": "Yeah, and our goal is to scan the ocean to find potential garbage and wrecks left by other hu-... uh... other [wave amp=20 freq=2]hoomans[wave/]."}, - {"name": "Crab", "text": "How neat!"}, + {"name": "Herbert", "text": "Oh, that's nice!"}, + {"name": "Ely", "text": "We scan the ocean to find the garbage left by other hu-... uh... other [wave amp=20 freq=2]hoomans[/wave]."}, + {"name": "Herbert", "text": "How neat!"}, {"name": "Ely", "text": "We're mostly pals enjoying scuba diving together and collecting small funds for bigger organizations."}, {"name": "Ely", "text": "And... you see, the oil tanker you found..."}, - {"name": "Ely", "text": "We were supposed to go through it and gather some pieces of information for later dismantlement."}, + {"name": "Ely", "text": "We were supposed to go through it and gather pieces of information for later dismantlement."}, {"name": "Ely", "text": "But... as you can tell, it didn't go well."}, {"name": "Ely", "text": "The sea was angry, thunderous even..."}, {"name": "Ely", "text": "And we lost our ship."}, {"name": "Ely", "text": "I don't even know were my friends are..."}, {"name": "Ely", "text": "..."}, - {"name": "Crab", "text": "..."}, + {"name": "Herbert", "text": "..."}, {"name": "Ely", "text": "Crap..."}, - {"name": "Ely", "text": "... I don't know why I'm telling you all of that, it's not even really what happened..."}, + {"name": "Ely", "text": "... I don't know why I'm telling you all of that, it's not even what really happened..."}, {"name": "Ely", "text": "..."}, - {"name": "Ely", "text": "I-I don't want to tell you the truth..."}, - {"name": "Crab", "text": "..."}, - {"name": "Crab", "text": "That was a beautiful tale."}, - {"name": "Crab", "text": "In a sense, it brings me hope to know you're aware that oil tankers are bad."}, - {"name": "Crab", "text": "Lie or not, your story tells me something about hoomans and about you."}, - {"name": "Crab", "text": "Something good..."}, - {"animation": "fadeout", "timer": 4, "auto": true}, - {"timer": 2, "auto": true}, - {"name": "Crab", "text": "Thank you.", "expression": "black"} + {"name": "Ely", "text": "I-I don't want you to know the truth..."}, + {"name": "Herbert", "text": "..."}, + {"name": "Herbert", "text": "That was a beautiful tale."}, + {"name": "Herbert", "text": "In a sense, it brings me hope to know you're aware that oil tankers are bad."}, + {"name": "Herbert", "text": "Lie or not, your story tells me something about hoomans and about you."}, + {"name": "Herbert", "text": "Something good..."}, + {"name": "Herbert", "animation": "fadeout", "timer": 4, "auto": true}, + {"timer": 2, "auto": true, "expression": "black"}, + {"name": "Herbert", "text": "Thank you.", "expression": "black"} ] diff --git a/dialogues/oilTanker1.json b/dialogues/oilTanker1.json index 09ad8ab..4a35156 100644 --- a/dialogues/oilTanker1.json +++ b/dialogues/oilTanker1.json @@ -1,5 +1,6 @@ [ + {"animation": "fadein", "timer": 2, "auto": true}, {"name": "Herbert", "text": "Finally I found the source.", "timer": 4, "auto": true, "upside_down": true}, - {"name": "Herbert", "text": "It was a recently sunk oil tanker.", "timer": 5, "auto": true, "upside_down": true}, - {"name": "Herbert", "text": "I had to investigate further.", "timer": 3, "auto": true, "upside_down": true} + {"name": "Herbert", "text": "It was a recently sunk oil tanker.", "timer": 4, "auto": true, "upside_down": true}, + {"name": "Herbert", "text": "I had to investigate further.", "timer": 4, "auto": true, "upside_down": true} ] diff --git a/dialogues/oilTanker2.json b/dialogues/oilTanker2.json index 7aa509f..0d66e95 100644 --- a/dialogues/oilTanker2.json +++ b/dialogues/oilTanker2.json @@ -1,3 +1,3 @@ [ - {"name": "Herbert", "text": "The closer I got, the more oil there was.", "timer": 4, "auto": true, "upside_down": true} + {"name": "Herbert", "text": "The closer I got, the more oil there was.", "timer": 6, "auto": true, "upside_down": true} ] diff --git a/dialogues/oilTanker3.json b/dialogues/oilTanker3.json index 4eed7b9..ae4c6fe 100644 --- a/dialogues/oilTanker3.json +++ b/dialogues/oilTanker3.json @@ -1,5 +1,3 @@ [ - {"name": "Herbert", "text": "The inside was full of oil, I was really close.", "upside_down": true}, - {"name": "Herbert", "text": "And there it was, one of the tank was damaged.", "upside_down": true}, - {"name": "Herbert", "text": "I'm just a crab, I couldn't do anything about it.", "upside_down": true, "animation": "fadeout", "timer": 2} + {"name": "Herbert", "text": "The inside was full of oil, I was really close.", "upside_down": true, "timer": 6, "auto": true} ] diff --git a/dialogues/oilTanker4.json b/dialogues/oilTanker4.json index c105650..6993feb 100644 --- a/dialogues/oilTanker4.json +++ b/dialogues/oilTanker4.json @@ -1,5 +1,4 @@ [ - {"name": "Herbert", "text": "Back at my home, there was goo everywhere.", "expression": "black"}, - {"animation": "fadein", "timer": 2, "auto": true}, - {"name": "Herbert", "text": "My friends and I were forced to move..."} + {"name": "Herbert", "text": "And there it was, one of the tank was damaged.", "upside_down": true}, + {"name": "Herbert", "text": "I'm just a crab, I couldn't do anything about it.", "upside_down": true, "animation": "fadeout", "timer": 2} ] diff --git a/dialogues/oilTanker5.json b/dialogues/oilTanker5.json new file mode 100644 index 0000000..c105650 --- /dev/null +++ b/dialogues/oilTanker5.json @@ -0,0 +1,5 @@ +[ + {"name": "Herbert", "text": "Back at my home, there was goo everywhere.", "expression": "black"}, + {"animation": "fadein", "timer": 2, "auto": true}, + {"name": "Herbert", "text": "My friends and I were forced to move..."} +] diff --git a/project.godot b/project.godot index 7e3b126..46dabab 100644 --- a/project.godot +++ b/project.godot @@ -9,6 +9,11 @@ config_version=4 _global_script_classes=[ { +"base": "CanvasItem", +"class": "BlackScreen", +"language": "GDScript", +"path": "res://scripts/BlackScreen.gd" +}, { "base": "Node", "class": "DialogueAction", "language": "GDScript", @@ -40,6 +45,7 @@ _global_script_classes=[ { "path": "res://scripts/game1/LogEntity.gd" } ] _global_script_class_icons={ +"BlackScreen": "", "DialogueAction": "", "DialogueBox": "", "Flatfish": "", diff --git a/scenes/campfire.tscn b/scenes/campfire.tscn index 4de62c5..39b019c 100644 --- a/scenes/campfire.tscn +++ b/scenes/campfire.tscn @@ -21,7 +21,6 @@ __meta__ = { } [node name="Dialog" parent="UI" instance=ExtResource( 3 )] -visible = false [node name="IntroScript" type="Node" parent="."] script = ExtResource( 4 ) diff --git a/scenes/dialogue.tscn b/scenes/dialogue.tscn index a40ea31..4849774 100644 --- a/scenes/dialogue.tscn +++ b/scenes/dialogue.tscn @@ -1,10 +1,12 @@ -[gd_scene load_steps=11 format=2] +[gd_scene load_steps=13 format=2] [ext_resource path="res://images/ui/dialogue_bg.png" type="Texture" id=1] [ext_resource path="res://fonts/dialog_default_font.tres" type="DynamicFont" id=2] [ext_resource path="res://scripts/DialogueBox.gd" type="Script" id=3] [ext_resource path="res://fonts/dialogue_default_font_italic.tres" type="DynamicFont" id=4] [ext_resource path="res://fonts/dialogue_default_font_mono_aka_small.tres" type="DynamicFont" id=5] +[ext_resource path="res://BlackScreen.tscn" type="PackedScene" id=6] +[ext_resource path="res://scripts/BlackScreen.gd" type="Script" id=7] [sub_resource type="VisualShaderNodeColorConstant" id=1] constant = Color( 0, 0, 0, 0.803922 ) @@ -80,6 +82,10 @@ __meta__ = { name_label_path = NodePath("MarginContainer/VBoxContainer/NameContainer/MarginContainer/CharacterName") text_label_path = NodePath("MarginContainer/VBoxContainer/TextContainer/MarginContainer/DialogText") +[node name="BlackScreen" parent="." instance=ExtResource( 6 )] +modulate = Color( 1, 1, 1, 0 ) +script = ExtResource( 7 ) + [node name="MarginContainer" type="MarginContainer" parent="."] anchor_right = 1.0 anchor_bottom = 1.0 diff --git a/scenes/oil_tanker.tscn b/scenes/oil_tanker.tscn index 442e3bb..98ad70e 100644 --- a/scenes/oil_tanker.tscn +++ b/scenes/oil_tanker.tscn @@ -78,6 +78,7 @@ dialogue_1 = "res://dialogues/oilTanker1.json" dialogue_2 = "res://dialogues/oilTanker2.json" dialogue_3 = "res://dialogues/oilTanker3.json" dialogue_4 = "res://dialogues/oilTanker4.json" +dialogue_5 = "res://dialogues/oilTanker5.json" [node name="HerbertMustGo" type="AnimatedSprite" parent="."] frames = ExtResource( 7 ) @@ -279,4 +280,3 @@ __meta__ = { } [node name="Dialog" parent="UI" instance=ExtResource( 9 )] -visible = false diff --git a/scripts/BlackScreen.gd b/scripts/BlackScreen.gd new file mode 100644 index 0000000..f309011 --- /dev/null +++ b/scripts/BlackScreen.gd @@ -0,0 +1,25 @@ +extends CanvasItem + +class_name BlackScreen + +var animation_counter = 0.0 +var animation_duration : float +var animation = null + +func animate(_animation, duration : float): + animation_counter = 0.0 + animation_duration = duration + animation = _animation + print('animating!' + (animation if animation != null else 'null') + ' - ' + String(animation_duration)) + +func _process(delta): + if animation != null: + if animation == 'fadein': + modulate.a = lerp(1, 0, clamp(animation_counter / animation_duration, 0, 1)) + elif animation == 'fadeout': + modulate.a = lerp(0, 1, clamp(animation_counter / animation_duration, 0, 1)) + elif animation == 'black': + modulate.a = 1 + else: + modulate.a = 0 + animation_counter += delta diff --git a/scripts/DialogueBox.gd b/scripts/DialogueBox.gd index 62a5b4b..7096da2 100644 --- a/scripts/DialogueBox.gd +++ b/scripts/DialogueBox.gd @@ -15,6 +15,8 @@ onready var expression_node = get_node(expression_node_path) as RichTextLabel onready var music_player = get_node('/root/MusicPlayer') as MusicPlayer +onready var black_screen = $BlackScreen + var dialogue : Array var index : int @@ -28,6 +30,7 @@ func _ready(): assert(name_label != null) assert(text_label != null) assert(music_player != null) + assert(black_screen != null) func start_dialogue(dialog_path : String) -> DialogueAction: var dialogue = DialogueAction.new() @@ -51,7 +54,7 @@ func _input(event): func next() -> void: index += 1 if index >= dialogue.size(): - hide() + $MarginContainer.hide() emit_signal('end') return update() @@ -95,11 +98,21 @@ func update() -> void: name_label.rect_min_size.x = name_label.get_font('normal_font').get_string_size(name_label.text).x text_label.bbcode_text = text - if text == "": hide() - else: show() + if text == "": $MarginContainer.hide() + else: $MarginContainer.show() emit_signal('update') + # Animation + var animation = line.get('animation', null) + if animation != null: + print('animate!' + animation) + black_screen.animate(animation, timer) + elif expression == 'black': + black_screen.animate('black', 0) + else: + black_screen.animate(null, timer) + animate_text() if timer > 0: @@ -113,9 +126,10 @@ func animate_text(): if text_label.text[text_label.visible_characters] == ' ': text_label.visible_characters += 1 text_label.visible_characters += 1 - yield(get_tree().create_timer(0.05), 'timeout') - + yield(get_tree().create_timer(0.4 if text_label.text[text_label.visible_characters - 1] == '.' else 0.05), 'timeout') + func stop_waiting(): waiting = false if auto_advance: next() + diff --git a/scripts/oil_tanker.gd b/scripts/oil_tanker.gd index 45f0841..b5b92f7 100644 --- a/scripts/oil_tanker.gd +++ b/scripts/oil_tanker.gd @@ -21,23 +21,24 @@ onready var prop1 = $InsideOilTanker2/Parallax/Prop1 onready var prop2 = $InsideOilTanker2/Parallax/Prop2 onready var next_trigger_2 = $InsideOilTanker2/NextTrigger export (String, FILE, "*.json") var dialogue_3 +export (String, FILE, "*.json") var dialogue_4 #3 onready var herbert_must_go_3 = $HerbertMustGo -export (String, FILE, "*.json") var dialogue_4 +export (String, FILE, "*.json") var dialogue_5 func _ready(): assert(dialogue_1 != null) assert(dialogue_2 != null) assert(dialogue_3 != null) assert(dialogue_4 != null) + assert(dialogue_5 != null) oil_tanker.connect('animation_finished', self, 'end_step_0') next_trigger_1.connect("body_entered", self, 'end_step_1') dialogue_trigger_1.connect("body_entered", self, 'dialogue_2') next_trigger_2.connect("body_entered", self, 'end_step_2') - yield(get_tree().create_timer(1), "timeout") yield(dialogue_box.start_dialogue(dialogue_1), 'end') # oil_tanker.frame = 12 @@ -63,17 +64,19 @@ func end_step_1(body : Node): player_2.sleep = false camera_2.current = true + yield(dialogue_box.start_dialogue(dialogue_3), 'end') func end_step_2(body : Node): print('end_step_2') if body.name == "Player": player_2.sleep = true - yield(dialogue_box.start_dialogue(dialogue_3), 'end') + yield(dialogue_box.start_dialogue(dialogue_4), 'end') oil_tanker_inside_2.queue_free() herbert_must_go_3.play('default') yield(get_tree().create_timer(1), "timeout") - yield(dialogue_box.start_dialogue(dialogue_4), 'end') + yield(dialogue_box.start_dialogue(dialogue_5), 'end') + yield(get_tree().create_timer(0.2), "timeout") get_tree().change_scene("res://scenes/campfire2.tscn") func _input(event):