From 0e3f1423e577ec201d08d137056c546ddd52e70e Mon Sep 17 00:00:00 2001 From: Malcolm Nixon Date: Tue, 5 Dec 2023 20:15:47 -0500 Subject: [PATCH] Add viewport visibility change notifications This PR resolves issue #22 by firing NOTIFICATION_VISIBILITY_CHANGED on the contents of Viewport2Din3D scenes so they can react to becoming visible and update their content. Additionally it resolves issue #20 by giving a class_name to the gdscript version of T5ToolsViewport2Din3D. --- VERSIONS.md | 4 ++++ .../objects/viewport/T5ToolsViewport2Din3D.cs | 15 ++++++++++++++- .../objects/viewport/viewport_2d_in_3d.gd | 14 +++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/VERSIONS.md b/VERSIONS.md index f8a8a6e..38ae67e 100644 --- a/VERSIONS.md +++ b/VERSIONS.md @@ -1,3 +1,7 @@ +# 1.2.0 (in development) +- Notify viewport scenes of visibility changes +- Add T5ToolsViewport2Din3D class name for gdscript + # 1.1.0 - Update to Godot/T5 Icon - Migrated TiltFiveTools to latest TiltFiveGodot4 API diff --git a/project.csharp/addons/tiltfive_tools/objects/viewport/T5ToolsViewport2Din3D.cs b/project.csharp/addons/tiltfive_tools/objects/viewport/T5ToolsViewport2Din3D.cs index ff61964..2f1eb13 100644 --- a/project.csharp/addons/tiltfive_tools/objects/viewport/T5ToolsViewport2Din3D.cs +++ b/project.csharp/addons/tiltfive_tools/objects/viewport/T5ToolsViewport2Din3D.cs @@ -348,7 +348,7 @@ public override void _Ready() body.PointerEvent += OnPointerEvent; // Update enabled based on visibility - VisibilityChanged += UpdateEnabled; + VisibilityChanged += OnVisibilityChanged; // Apply physics properties UpdateScreenSize(); @@ -494,6 +494,19 @@ public override void _Process(double delta) } } + /// + /// Handle visibility changed + /// + private void OnVisibilityChanged() + { + // Update enabled state + UpdateEnabled(); + + // Fire visibility changed in scene + _sceneNode?.PropagateNotification( + (int)CanvasItem.NotificationVisibilityChanged); + } + /// /// Handle setting screen size property /// diff --git a/project.gd/addons/tiltfive_tools/objects/viewport/viewport_2d_in_3d.gd b/project.gd/addons/tiltfive_tools/objects/viewport/viewport_2d_in_3d.gd index 7b5bcb8..9d1a215 100644 --- a/project.gd/addons/tiltfive_tools/objects/viewport/viewport_2d_in_3d.gd +++ b/project.gd/addons/tiltfive_tools/objects/viewport/viewport_2d_in_3d.gd @@ -1,4 +1,5 @@ @tool +class_name T5ToolsViewport2Din3D extends Node3D @@ -127,7 +128,7 @@ func _ready(): $StaticBody3D.connect("pointer_event", _on_pointer_event) # Update enabled based on visibility - visibility_changed.connect(_update_enabled) + visibility_changed.connect(_on_visibility_changed) # Apply physics properties _update_screen_size() @@ -244,6 +245,17 @@ func _process(delta): set_process(false) +# Handle visibility changed +func _on_visibility_changed() -> void: + # Update enabled state + _update_enabled() + + # Fire visibility changed in scene + if scene_node: + scene_node.propagate_notification( + CanvasItem.NOTIFICATION_VISIBILITY_CHANGED) + + ## Set screen size property func set_screen_size(new_size: Vector2) -> void: screen_size = new_size