From a94dfd8e3619bac36be045a9cbc1621de4084216 Mon Sep 17 00:00:00 2001 From: Jowan-Spooner Date: Mon, 22 Jan 2024 22:36:25 +0100 Subject: [PATCH] Fix background transitions Should fix #2038 and a problem reported on discord --- .../class_dialogic_background_transition.gd | 2 +- .../Background/subsystem_backgrounds.gd | 23 ++++++++++++++++--- .../full_background_layer.tscn | 11 ++------- .../Layer_VN_Portraits/vn_portrait_layer.tscn | 1 + 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/addons/dialogic/Modules/Background/Transitions/class_dialogic_background_transition.gd b/addons/dialogic/Modules/Background/Transitions/class_dialogic_background_transition.gd index f35ce6d39..f5465d5a1 100644 --- a/addons/dialogic/Modules/Background/Transitions/class_dialogic_background_transition.gd +++ b/addons/dialogic/Modules/Background/Transitions/class_dialogic_background_transition.gd @@ -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 diff --git a/addons/dialogic/Modules/Background/subsystem_backgrounds.gd b/addons/dialogic/Modules/Background/subsystem_backgrounds.gd index 0177f00b8..ceb9401df 100644 --- a/addons/dialogic/Modules/Background/subsystem_backgrounds.gd +++ b/addons/dialogic/Modules/Background/subsystem_backgrounds.gd @@ -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) @@ -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() @@ -122,7 +138,7 @@ 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) @@ -130,6 +146,7 @@ func add_background_node(scene:PackedScene, parent:DialogicNode_BackgroundHolder 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 diff --git a/addons/dialogic/Modules/DefaultLayoutParts/Layer_FullBackground/full_background_layer.tscn b/addons/dialogic/Modules/DefaultLayoutParts/Layer_FullBackground/full_background_layer.tscn index 6c9fef591..b4766352f 100644 --- a/addons/dialogic/Modules/DefaultLayoutParts/Layer_FullBackground/full_background_layer.tscn +++ b/addons/dialogic/Modules/DefaultLayoutParts/Layer_FullBackground/full_background_layer.tscn @@ -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 @@ -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") diff --git a/addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Portraits/vn_portrait_layer.tscn b/addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Portraits/vn_portrait_layer.tscn index 374bc60ff..b5e79f022 100644 --- a/addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Portraits/vn_portrait_layer.tscn +++ b/addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Portraits/vn_portrait_layer.tscn @@ -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="."]