From 022d24a9aef8aabd91dbef7fa6b01687748f78b6 Mon Sep 17 00:00:00 2001 From: Markus Sauermann <6299227+Sauermann@users.noreply.github.com> Date: Fri, 1 Apr 2022 21:18:16 +0200 Subject: Fix Viewport root order after Node2D raise --- scene/2d/node_2d.cpp | 12 ++++++++++++ scene/2d/node_2d.h | 1 + scene/gui/control.cpp | 2 +- scene/main/canvas_layer.cpp | 2 +- scene/main/viewport.cpp | 2 +- scene/main/viewport.h | 4 ++-- 6 files changed, 18 insertions(+), 5 deletions(-) diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index 2518069b78..84bfc48a43 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -30,6 +30,8 @@ #include "node_2d.h" +#include "scene/main/viewport.h" + #ifdef TOOLS_ENABLED Dictionary Node2D::_edit_get_state() const { Dictionary state; @@ -389,6 +391,16 @@ bool Node2D::is_y_sort_enabled() const { return y_sort_enabled; } +void Node2D::_notification(int p_notification) { + switch (p_notification) { + case NOTIFICATION_MOVED_IN_PARENT: { + if (get_viewport()) { + get_viewport()->gui_set_root_order_dirty(); + } + } break; + } +} + void Node2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_position", "position"), &Node2D::set_position); ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Node2D::set_rotation); diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h index 0d8a31e6bb..04bbdf639d 100644 --- a/scene/2d/node_2d.h +++ b/scene/2d/node_2d.h @@ -53,6 +53,7 @@ class Node2D : public CanvasItem { void _update_xform_values(); protected: + void _notification(int p_notification); static void _bind_methods(); public: diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index c5cb7157e8..103c7ba042 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -2921,7 +2921,7 @@ void Control::_notification(int p_notification) { queue_redraw(); if (data.RI) { - get_viewport()->_gui_set_root_order_dirty(); + get_viewport()->gui_set_root_order_dirty(); } } break; diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp index be5788739b..5fde18721a 100644 --- a/scene/main/canvas_layer.cpp +++ b/scene/main/canvas_layer.cpp @@ -38,7 +38,7 @@ void CanvasLayer::set_layer(int p_xform) { layer = p_xform; if (viewport.is_valid()) { RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); - vp->_gui_set_root_order_dirty(); + vp->gui_set_root_order_dirty(); } } diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 2385e4f54a..a40e8245db 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2094,7 +2094,7 @@ List::Element *Viewport::_gui_add_root_control(Control *p_control) { return gui.roots.push_back(p_control); } -void Viewport::_gui_set_root_order_dirty() { +void Viewport::gui_set_root_order_dirty() { gui.roots_order_dirty = true; } diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 8911aea335..aec768e9a7 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -455,8 +455,6 @@ private: void _update_canvas_items(Node *p_node); - void _gui_set_root_order_dirty(); - friend class Window; void _sub_window_update_order(); @@ -513,6 +511,8 @@ public: Transform2D get_final_transform() const; + void gui_set_root_order_dirty(); + void set_transparent_background(bool p_enable); bool has_transparent_background() const; -- cgit v1.2.3