Skip to content

Commit

Permalink
Fix background transitions
Browse files Browse the repository at this point in the history
Should fix dialogic-godot#2038 and a problem reported on discord
  • Loading branch information
Jowan-Spooner committed Jan 22, 2024
1 parent 9dbc39a commit a94dfd8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ func tween_shader_progress(progress_parameter:="progress") -> PropertyTweener:

bg_holder.material.set_shader_parameter("progress", 0.0)
var tween := create_tween()
var tweener := tween.tween_property(bg_holder, "material:shader_parameter/progress", 1.0, time)
var tweener := tween.tween_property(bg_holder, "material:shader_parameter/progress", 1.0, time).from(0.0)
tween.tween_callback(emit_signal.bind('transition_finished'))
return tweener
23 changes: 20 additions & 3 deletions addons/dialogic/Modules/Background/subsystem_backgrounds.gd
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func update_background(scene:String = '', argument:String = '', fade_time:float
trans_node.prev_scene = old_viewport.get_meta('node', null)
trans_node.prev_texture = old_viewport.get_child(0).get_texture()
old_viewport.get_meta('node')._custom_fade_out(fade_time)
old_viewport.hide()
# TODO We have to call this again here because of https://github.com/godotengine/godot/issues/23729
old_viewport.get_child(0).render_target_update_mode = SubViewport.UPDATE_ALWAYS
trans_node.transition_finished.connect(old_viewport.queue_free)
if new_viewport:
trans_node.next_scene = new_viewport.get_meta('node', null)
Expand All @@ -104,12 +107,25 @@ func update_background(scene:String = '', argument:String = '', fade_time:float
background_holder.remove_meta('current_viewport')

add_child(trans_node)
trans_node._fade()
trans_node.transition_finished.connect(trans_node.queue_free)
if fade_time == 0:
trans_node.transition_finished.emit()
_on_transition_finished(background_holder, trans_node)
else:
trans_node.transition_finished.connect(_on_transition_finished.bind(background_holder, trans_node))
trans_node._fade()

background_changed.emit(info)


func _on_transition_finished(background_node:DialogicNode_BackgroundHolder, transition_node:DialogicBackgroundTransition) -> void:
if background_node.has_meta("current_viewport"):
if background_node.get_meta("current_viewport").get_meta("node", null) == transition_node.next_scene:
background_node.get_meta("current_viewport").show()
background_node.material = null
background_node.color = Color.TRANSPARENT
transition_node.queue_free()


func add_background_node(scene:PackedScene, parent:DialogicNode_BackgroundHolder) -> SubViewportContainer:
var v_con := SubViewportContainer.new()
var viewport := SubViewport.new()
Expand All @@ -122,14 +138,15 @@ func add_background_node(scene:PackedScene, parent:DialogicNode_BackgroundHolder
return null

parent.add_child(v_con)
v_con.visible = false
v_con.hide()
v_con.stretch = true
v_con.size = parent.size
v_con.set_anchors_preset(Control.PRESET_FULL_RECT)

v_con.add_child(viewport)
viewport.transparent_bg = true
viewport.disable_3d = true
viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS

viewport.add_child(b_scene)
b_scene.viewport = viewport
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://c1k5m0w3r40xf"]
[gd_scene load_steps=3 format=3 uid="uid://c1k5m0w3r40xf"]

[ext_resource type="Script" path="res://addons/dialogic/Modules/DefaultLayoutParts/Layer_FullBackground/full_background_layer.gd" id="1_tu40u"]
[ext_resource type="Script" path="res://addons/dialogic/Modules/Background/node_background_holder.gd" id="2_ghan2"]
[ext_resource type="Shader" path="res://addons/dialogic/Modules/Background/Transitions/default_transition_shader.gdshader" id="2_mwc4m"]

[sub_resource type="ShaderMaterial" id="ShaderMaterial_msuxf"]
shader = ExtResource("2_mwc4m")
shader_parameter/progress = 0.0
shader_parameter/feather = 0.1
shader_parameter/keep_aspect_ratio = false

[node name="BackgroundLayer" type="Control"]
layout_mode = 3
Expand All @@ -20,11 +13,11 @@ grow_vertical = 2
script = ExtResource("1_tu40u")

[node name="DialogicNode_BackgroundHolder" type="ColorRect" parent="."]
material = SubResource("ShaderMaterial_msuxf")
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
script = ExtResource("2_ghan2")
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
script = ExtResource("1_1i7em")

[node name="Portraits" type="Control" parent="."]
Expand Down

0 comments on commit a94dfd8

Please sign in to comment.