Skip to content

Commit dfac71e

Browse files
committed
Adding new setting to the Set Background event to add fade-in time
1 parent a7890f0 commit dfac71e

File tree

7 files changed

+135
-60
lines changed

7 files changed

+135
-60
lines changed
Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
1-
[gd_scene load_steps=7 format=2]
1+
[gd_scene load_steps=5 format=2]
22

33
[ext_resource path="res://addons/dialogic/Editor/Events/Templates/EventTemplate.tscn" type="PackedScene" id=1]
44
[ext_resource path="res://addons/dialogic/Images/Event Icons/Main Icons/close-dialog.svg" type="Texture" id=2]
55
[ext_resource path="res://addons/dialogic/Editor/Events/styles/CloseDialog.tres" type="StyleBox" id=3]
66
[ext_resource path="res://addons/dialogic/Editor/Events/Parts/Numbers/TransitonLengthPicker.tscn" type="PackedScene" id=4]
77

8-
[sub_resource type="Image" id=3]
9-
data = {
10-
"data": PoolByteArray( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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width": 16
15-
}
16-
17-
[sub_resource type="ImageTexture" id=2]
18-
flags = 4
19-
flags = 4
20-
image = SubResource( 3 )
21-
size = Vector2( 16, 16 )
22-
238
[node name="CloseDialog" instance=ExtResource( 1 )]
249
event_data = {
2510
"event_id": "dialogic_022",
@@ -33,23 +18,21 @@ header_scene = ExtResource( 4 )
3318
[node name="PanelContainer" parent="." index="1"]
3419
custom_styles/panel = ExtResource( 3 )
3520

36-
[node name="Warning" parent="PanelContainer/MarginContainer/VBoxContainer/Header" index="0"]
37-
icon = SubResource( 2 )
38-
39-
[node name="IconTexture" parent="PanelContainer/MarginContainer/VBoxContainer/Header" index="0"]
21+
[node name="IconTexture" parent="PanelContainer/MarginContainer/VBoxContainer/Header" index="1"]
4022
margin_right = 32.0
4123
texture = ExtResource( 2 )
4224

43-
[node name="TitleLabel" parent="PanelContainer/MarginContainer/VBoxContainer/Header" index="0"]
44-
margin_right = 84.0
25+
[node name="TitleLabel" parent="PanelContainer/MarginContainer/VBoxContainer/Header" index="2"]
26+
margin_left = 42.0
27+
margin_right = 121.0
4528
text = "Close Dialog"
4629

4730
[node name="Content" parent="PanelContainer/MarginContainer/VBoxContainer/Header" index="3"]
48-
margin_left = 150.0
49-
margin_right = 160.0
31+
margin_left = 131.0
32+
margin_right = 336.0
5033

5134
[node name="Spacer" parent="PanelContainer/MarginContainer/VBoxContainer/Header" index="5"]
52-
margin_left = 164.0
35+
margin_left = 346.0
5336

54-
[node name="OptionsControl" parent="PanelContainer/MarginContainer/VBoxContainer/Header" index="7"]
37+
[node name="OptionsControl" parent="PanelContainer/MarginContainer/VBoxContainer/Header" index="6"]
5538
items = [ "Move Up", null, 0, false, false, 0, 0, null, "", false, "Move Down", null, 0, false, false, 1, 0, null, "", false, "", null, 0, false, false, 2, 0, null, "", false, "Remove", null, 0, false, false, 3, 0, null, "", false ]
Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
[gd_scene load_steps=3 format=2]
1+
[gd_scene load_steps=4 format=2]
22

33
[ext_resource path="res://addons/dialogic/Images/Context Menus/Remove.svg" type="Texture" id=1]
44
[ext_resource path="res://addons/dialogic/Editor/Events/Parts/Images/EventPart_BackgroundPicker.gd" type="Script" id=2]
5+
[ext_resource path="res://addons/dialogic/Editor/Events/Parts/SpinBoxPreventDnD.gd" type="Script" id=3]
56

67
[node name="BackgroundPicker" type="VBoxContainer"]
78
margin_top = 1.0
@@ -13,32 +14,50 @@ __meta__ = {
1314
}
1415

1516
[node name="HBox" type="HBoxContainer" parent="."]
16-
margin_right = 331.0
17-
margin_bottom = 22.0
17+
margin_right = 533.0
18+
margin_bottom = 24.0
1819
size_flags_horizontal = 3
1920
size_flags_vertical = 3
2021
__meta__ = {
2122
"_edit_use_anchors_": false
2223
}
2324

2425
[node name="Name" type="Label" parent="HBox"]
25-
margin_top = 4.0
26+
margin_top = 5.0
2627
margin_right = 271.0
27-
margin_bottom = 18.0
28+
margin_bottom = 19.0
2829
text = "No image (will clear previous scene event)"
2930

3031
[node name="ImageButton" type="Button" parent="HBox"]
3132
margin_left = 275.0
3233
margin_right = 299.0
33-
margin_bottom = 22.0
34+
margin_bottom = 24.0
3435
text = "..."
3536

3637
[node name="ClearButton" type="Button" parent="HBox"]
3738
margin_left = 303.0
3839
margin_right = 331.0
39-
margin_bottom = 22.0
40+
margin_bottom = 24.0
4041
disabled = true
4142
icon = ExtResource( 1 )
4243

44+
[node name="FadeLabel" type="Label" parent="HBox"]
45+
margin_left = 335.0
46+
margin_top = 5.0
47+
margin_right = 455.0
48+
margin_bottom = 19.0
49+
text = " Fade-in duration:"
50+
51+
[node name="NumberBox" type="SpinBox" parent="HBox"]
52+
margin_left = 459.0
53+
margin_right = 533.0
54+
margin_bottom = 24.0
55+
size_flags_vertical = 6
56+
step = 0.1
57+
value = 1.0
58+
allow_greater = true
59+
align = 1
60+
script = ExtResource( 3 )
61+
4362
[connection signal="pressed" from="HBox/ImageButton" to="HBox" method="_on_ImageButton_pressed"]
4463
[connection signal="pressed" from="HBox/ClearButton" to="HBox" method="_on_ClearButton_pressed"]

addons/dialogic/Editor/Events/Parts/Images/EventPart_BackgroundPicker.gd

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ extends "res://addons/dialogic/Editor/Events/Parts/EventPart.gd"
77
onready var image_button = $HBox/ImageButton
88
onready var clear_button = $HBox/ClearButton
99
onready var name_label = $HBox/Name
10+
onready var fade_duration_label = $HBox/FadeLabel
11+
onready var fade_duration = $HBox/NumberBox
1012

1113
# used to connect the signals
1214
func _ready():
1315
image_button.connect("pressed", self, "_on_ImageButton_pressed")
1416
clear_button.connect('pressed', self, "_on_ClearButton_pressed")
17+
fade_duration.connect('value_changed', self, '_on_fade_duration_changed')
1518
pass
1619

1720
# called by the event block
@@ -23,12 +26,18 @@ func load_data(data:Dictionary):
2326
if event_data['background']:
2427
name_label.text = event_data['background'].get_file()
2528
image_button.hint_tooltip = event_data['background']
29+
fade_duration_label.visible = true
30+
fade_duration.visible = true
2631
emit_signal("request_close_body")
2732
else:
2833
name_label.text = 'No image (will clear previous background)'
2934
image_button.hint_tooltip = 'No background selected'
35+
fade_duration_label.visible = false
36+
fade_duration.visible = false
3037
emit_signal("request_close_body")
3138

39+
fade_duration.value = event_data.get('fade_duration', 1)
40+
3241
clear_button.disabled = not bool(event_data['background'])
3342

3443

@@ -46,7 +55,9 @@ func _on_file_selected(path, target):
4655
clear_button.disabled = false
4756
name_label.text = event_data['background'].get_file()
4857
image_button.hint_tooltip = event_data['background']
49-
58+
fade_duration.visible = true
59+
fade_duration_label.visible = true
60+
5061
emit_signal("request_open_body")
5162
# informs the parent about the changes!
5263
data_changed()
@@ -57,8 +68,16 @@ func _on_ClearButton_pressed():
5768
clear_button.disabled = true
5869
name_label.text = 'No image (will clear previous background)'
5970
image_button.hint_tooltip = 'No background selected'
71+
fade_duration.visible = false
72+
fade_duration_label.visible = false
73+
fade_duration.value = 1
6074

6175
emit_signal("request_close_body")
6276

6377
# informs the parent about the changes!
6478
data_changed()
79+
80+
func _on_fade_duration_changed(value: float):
81+
event_data['fade_duration'] = value
82+
# informs the parent about the changes!
83+
data_changed()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
extends TextureRect
2+
3+
var native_dialogic_background = true
4+
var tween
5+
6+
func _ready():
7+
expand = true
8+
name = 'Background'
9+
anchor_right = 1
10+
anchor_bottom = 1
11+
stretch_mode = TextureRect.STRETCH_SCALE
12+
show_behind_parent = true
13+
mouse_filter = Control.MOUSE_FILTER_IGNORE
14+
15+
16+
func create_tween():
17+
tween = Tween.new()
18+
add_child(tween)
19+
20+
21+
func fade_out(time = 1):
22+
if tween:
23+
tween.connect('tween_all_completed', self, '_on_tween_over')
24+
tween.interpolate_property(self, "modulate",
25+
Color(1,1,1,1), Color(1,1,1,0), time,
26+
Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
27+
tween.start()
28+
else:
29+
_on_tween_over()
30+
31+
32+
func fade_in(time = 1):
33+
tween.interpolate_property(self, "modulate",
34+
Color(1,1,1,0), Color(1,1,1,1), time,
35+
Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
36+
tween.start()
37+
38+
39+
func _on_tween_over():
40+
print('here')
41+
queue_free()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[gd_scene load_steps=2 format=2]
2+
3+
[ext_resource path="res://addons/dialogic/Nodes/Background.gd" type="Script" id=1]
4+
5+
[node name="Background" type="TextureRect"]
6+
script = ExtResource( 1 )
7+
__meta__ = {
8+
"_edit_use_anchors_": false
9+
}

addons/dialogic/Nodes/dialog_node.gd

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var characters
3939

4040
onready var ChoiceButton = load("res://addons/dialogic/Nodes/ChoiceButton.tscn")
4141
onready var Portrait = load("res://addons/dialogic/Nodes/Portrait.tscn")
42+
onready var Background = load("res://addons/dialogic/Nodes/Background.tscn")
4243
var dialog_script: Dictionary = {}
4344
var questions #for keeping track of the questions answered
4445

@@ -642,34 +643,32 @@ func event_handler(event: Dictionary):
642643
# Change Backround event
643644
'dialogic_021':
644645
emit_signal("event_start", "background", event)
646+
var fade_time = event.get('fade_duration', 1)
647+
var value = event.get('background', '')
645648
var background = get_node_or_null('Background')
646-
if event['background'] == '' and background != null:
647-
background.queue_free()
648-
else:
649-
if background == null:
650-
background = TextureRect.new()
651-
background.expand = true
652-
background.name = 'Background'
653-
background.anchor_right = 1
654-
background.anchor_bottom = 1
655-
background.stretch_mode = TextureRect.STRETCH_SCALE
656-
background.show_behind_parent = true
657-
background.mouse_filter = Control.MOUSE_FILTER_IGNORE
658-
call_deferred('resize_main') # Executing the resize main to update the background size
659-
660-
add_child(background)
661-
background.texture = null
662-
if (background.get_child_count() > 0):
663-
for c in background.get_children():
664-
c.get_parent().remove_child(c)
665-
c.queue_free()
666-
if (event['background'].ends_with('.tscn')):
649+
650+
if background != null:
651+
background.name = 'BackgroundFadingOut'
652+
background.fade_out(fade_time)
653+
654+
background = Background.instance()
655+
background.name = 'Background'
656+
657+
if value != '':
658+
add_child(background)
659+
background.create_tween()
660+
if value.ends_with('.tscn'):
667661
var bg_scene = load(event['background'])
668-
if (bg_scene):
669-
bg_scene = bg_scene.instance()
670-
background.add_child(bg_scene)
671-
elif (event['background'] != ''):
672-
background.texture = load(event['background'])
662+
bg_scene = bg_scene.instance()
663+
background.modulate = Color(1,1,1,0)
664+
background.fade_in(fade_time)
665+
background.add_child(bg_scene)
666+
else:
667+
background.texture = load(value)
668+
background.create_tween()
669+
background.fade_in(fade_time)
670+
call_deferred('resize_main') # Executing the resize main to update the background size
671+
673672
_load_next_event()
674673
# Close Dialog event
675674
'dialogic_022':
@@ -678,6 +677,10 @@ func event_handler(event: Dictionary):
678677
transition_duration = transition_duration
679678
close_dialog_event(transition_duration)
680679
while_dialog_animation = true
680+
var background = get_node_or_null('Background')
681+
if background != null:
682+
background.name = 'BackgroundFadingOut'
683+
background.fade_out(transition_duration)
681684
# Wait seconds event
682685
'dialogic_023':
683686
emit_signal("event_start", "wait", event)

docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Fixed the issue that allowed you to keep loading messages after a dialog close event
88
- Enabling bbcode to glossary entries
99
- Simplified some internal code
10+
- Adding new setting to the Set Background event to add fade-in time
1011
- Settings Editor
1112
- Added a default action key selector so you don't have to set it per theme. The theme action key settings will overwrite the one set in settings.
1213
- Added new setting to select Dialogic's Canvas Layer [[RedXGames]](https://github.com/RedXGames)

0 commit comments

Comments
 (0)