From 93e06ff16c2134c49e26b0f5403fb8526a908aea Mon Sep 17 00:00:00 2001 From: kit Date: Mon, 2 Dec 2024 15:36:17 -0500 Subject: [PATCH] Fix select and edit invisble items in SubViewports --- editor/plugins/abstract_polygon_2d_editor.cpp | 10 ++++++++ editor/plugins/canvas_item_editor_plugin.cpp | 24 ++++++++++++++++--- editor/plugins/cast_2d_editor_plugin.cpp | 11 +++++++++ .../collision_shape_2d_editor_plugin.cpp | 10 ++++++++ .../navigation_link_2d_editor_plugin.cpp | 11 +++++++++ editor/plugins/path_2d_editor_plugin.cpp | 10 ++++++++ scene/main/viewport.cpp | 10 ++++++++ scene/main/viewport.h | 4 ++++ 8 files changed, 87 insertions(+), 3 deletions(-) diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index 01154ee6b03..c81ddf7c710 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -260,6 +260,11 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref &p_event) return false; } + Viewport *vp = _get_node()->get_viewport(); + if (vp && !vp->is_visible_subviewport()) { + return false; + } + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); Ref mb = p_event; @@ -501,6 +506,11 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl return; } + Viewport *vp = _get_node()->get_viewport(); + if (vp && !vp->is_visible_subviewport()) { + return; + } + Transform2D xform = canvas_item_editor->get_canvas_transform() * _get_node()->get_screen_transform(); // All polygon points are sharp, so use the sharp handle icon const Ref handle = get_editor_theme_icon(SNAME("EditorPathSharpHandle")); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 5b948d9b7cc..9596ac64d09 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -618,6 +618,9 @@ void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_no if (CanvasLayer *cl = Object::cast_to(p_node)) { xform = cl->get_transform(); } else if (Viewport *vp = Object::cast_to(p_node)) { + if (!vp->is_visible_subviewport()) { + return; + } xform = vp->get_popup_base_transform(); if (!vp->get_visible_rect().has_point(xform.xform_inv(p_pos))) { return; @@ -718,6 +721,9 @@ void CanvasItemEditor::_find_canvas_items_in_rect(const Rect2 &p_rect, Node *p_n if (CanvasLayer *cl = Object::cast_to(p_node)) { xform = cl->get_transform(); } else if (Viewport *vp = Object::cast_to(p_node)) { + if (!vp->is_visible_subviewport()) { + return; + } xform = vp->get_popup_base_transform(); if (!vp->get_visible_rect().intersects(xform.xform_inv(p_rect))) { return; @@ -797,6 +803,10 @@ List CanvasItemEditor::_get_edited_canvas_items(bool p_retrieve_lo CanvasItem *ci = Object::cast_to(E.key); if (ci) { if (ci->is_visible_in_tree() && (p_retrieve_locked || !_is_node_locked(ci))) { + Viewport *vp = ci->get_viewport(); + if (vp && !vp->is_visible_subviewport()) { + continue; + } CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data(ci); if (se) { selection.push_back(ci); @@ -3819,6 +3829,9 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans parent_xform = Transform2D(); canvas_xform = cl->get_transform(); } else if (Viewport *vp = Object::cast_to(p_node)) { + if (!vp->is_visible_subviewport()) { + return; + } parent_xform = Transform2D(); canvas_xform = vp->get_popup_base_transform(); } @@ -3947,10 +3960,15 @@ void CanvasItemEditor::_draw_locks_and_groups(Node *p_node, const Transform2D &p if (ci && !ci->is_set_as_top_level()) { parent_xform = parent_xform * ci->get_transform(); - } else { - CanvasLayer *cl = Object::cast_to(p_node); + } else if (CanvasLayer *cl = Object::cast_to(p_node)) { parent_xform = Transform2D(); - canvas_xform = cl ? cl->get_transform() : p_canvas_xform; + canvas_xform = cl->get_transform(); + } else if (Viewport *vp = Object::cast_to(p_node)) { + if (!vp->is_visible_subviewport()) { + return; + } + parent_xform = Transform2D(); + canvas_xform = vp->get_popup_base_transform(); } for (int i = p_node->get_child_count() - 1; i >= 0; i--) { diff --git a/editor/plugins/cast_2d_editor_plugin.cpp b/editor/plugins/cast_2d_editor_plugin.cpp index d02b9579c8f..3839671e21d 100644 --- a/editor/plugins/cast_2d_editor_plugin.cpp +++ b/editor/plugins/cast_2d_editor_plugin.cpp @@ -35,6 +35,7 @@ #include "editor/editor_undo_redo_manager.h" #include "scene/2d/physics/ray_cast_2d.h" #include "scene/2d/physics/shape_cast_2d.h" +#include "scene/main/viewport.h" void Cast2DEditor::_notification(int p_what) { switch (p_what) { @@ -59,6 +60,11 @@ bool Cast2DEditor::forward_canvas_gui_input(const Ref &p_event) { return false; } + Viewport *vp = node->get_viewport(); + if (vp && !vp->is_visible_subviewport()) { + return false; + } + Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_screen_transform(); Ref mb = p_event; @@ -114,6 +120,11 @@ void Cast2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { return; } + Viewport *vp = node->get_viewport(); + if (vp && !vp->is_visible_subviewport()) { + return; + } + Transform2D gt = canvas_item_editor->get_canvas_transform() * node->get_screen_transform(); const Ref handle = get_editor_theme_icon(SNAME("EditorHandle")); diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp index 40c13ea3c4e..46b2c8d2d98 100644 --- a/editor/plugins/collision_shape_2d_editor_plugin.cpp +++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp @@ -300,6 +300,11 @@ bool CollisionShape2DEditor::forward_canvas_gui_input(const Ref &p_e return false; } + Viewport *vp = node->get_viewport(); + if (vp && !vp->is_visible_subviewport()) { + return false; + } + if (shape_type == -1) { return false; } @@ -433,6 +438,11 @@ void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overla return; } + Viewport *vp = node->get_viewport(); + if (vp && !vp->is_visible_subviewport()) { + return; + } + if (shape_type == -1) { return; } diff --git a/editor/plugins/navigation_link_2d_editor_plugin.cpp b/editor/plugins/navigation_link_2d_editor_plugin.cpp index ea873d8390c..969dc89a1f8 100644 --- a/editor/plugins/navigation_link_2d_editor_plugin.cpp +++ b/editor/plugins/navigation_link_2d_editor_plugin.cpp @@ -34,6 +34,7 @@ #include "editor/editor_node.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" +#include "scene/main/viewport.h" #include "servers/navigation_server_3d.h" void NavigationLink2DEditor::_notification(int p_what) { @@ -59,6 +60,11 @@ bool NavigationLink2DEditor::forward_canvas_gui_input(const Ref &p_e return false; } + Viewport *vp = node->get_viewport(); + if (vp && !vp->is_visible_subviewport()) { + return false; + } + real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius"); Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_screen_transform(); @@ -142,6 +148,11 @@ void NavigationLink2DEditor::forward_canvas_draw_over_viewport(Control *p_overla return; } + Viewport *vp = node->get_viewport(); + if (vp && !vp->is_visible_subviewport()) { + return; + } + Transform2D gt = canvas_item_editor->get_canvas_transform() * node->get_screen_transform(); Vector2 global_start_position = gt.xform(node->get_start_position()); Vector2 global_end_position = gt.xform(node->get_end_position()); diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index 524f3d86c2d..da65bc8e18a 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -71,6 +71,11 @@ bool Path2DEditor::forward_gui_input(const Ref &p_event) { return false; } + Viewport *vp = node->get_viewport(); + if (vp && !vp->is_visible_subviewport()) { + return false; + } + if (node->get_curve().is_null()) { return false; } @@ -393,6 +398,11 @@ void Path2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { return; } + Viewport *vp = node->get_viewport(); + if (vp && !vp->is_visible_subviewport()) { + return; + } + Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_screen_transform(); const Ref path_sharp_handle = get_editor_theme_icon(SNAME("EditorPathSharpHandle")); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 6c83c7843fb..c3bed93ad06 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -3893,6 +3893,16 @@ bool Viewport::get_canvas_cull_mask_bit(uint32_t p_layer) const { return (canvas_cull_mask & (1 << p_layer)); } +#ifdef TOOLS_ENABLED +bool Viewport::is_visible_subviewport() const { + if (!is_sub_viewport()) { + return true; + } + SubViewportContainer *container = Object::cast_to(get_parent()); + return container && container->is_visible_in_tree(); +} +#endif // TOOLS_ENABLED + void Viewport::_update_audio_listener_2d() { if (AudioServer::get_singleton()) { AudioServer::get_singleton()->notify_listener_changed(); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 3a5ad2d83cb..8667bc53c0c 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -672,6 +672,10 @@ public: void set_canvas_cull_mask_bit(uint32_t p_layer, bool p_enable); bool get_canvas_cull_mask_bit(uint32_t p_layer) const; +#ifdef TOOLS_ENABLED + bool is_visible_subviewport() const; +#endif // TOOLS_ENABLED + virtual bool is_size_2d_override_stretch_enabled() const { return true; } Transform2D get_screen_transform() const;