From 7d2667830d8bb7040e620282bb63e0654e8e339d Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 10 Apr 2023 11:42:15 +0200 Subject: [PATCH] Ported from godot 4: Fix Viewport root order after Node2D raise - Sauermann https://github.com/godotengine/godot/commit/022d24a9aef8aabd91dbef7fa6b01687748f78b6 --- scene/2d/node_2d.cpp | 10 ++++++++++ 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 | 3 ++- 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index c6e164d4b..414c115b5 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -377,6 +377,16 @@ Point2 Node2D::to_global(Point2 p_local) const { return get_global_transform().xform(p_local); } +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 9656e02f3..dd9693cce 100644 --- a/scene/2d/node_2d.h +++ b/scene/2d/node_2d.h @@ -50,6 +50,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 946ac8fbb..6d7dee1ee 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -608,7 +608,7 @@ void Control::_notification(int p_notification) { get_viewport()->_gui_set_subwindow_order_dirty(); } 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 01ee96520..a9cc0c8bf 100644 --- a/scene/main/canvas_layer.cpp +++ b/scene/main/canvas_layer.cpp @@ -37,7 +37,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_position_in_parent()); - 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 22f814d67..740fe1ef6 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2480,7 +2480,7 @@ void Viewport::_gui_set_subwindow_order_dirty() { gui.subwindow_order_dirty = true; } -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 6b9f8cae0..5652cdc61 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -195,6 +195,8 @@ public: Transform2D get_final_transform() const; void assign_next_enabled_camera_2d(const StringName &p_camera_group); + void gui_set_root_order_dirty(); + void set_transparent_background(bool p_enable); bool has_transparent_background() const; @@ -510,7 +512,6 @@ private: List::Element *_gui_add_subwindow_control(Control *p_control); void _gui_set_subwindow_order_dirty(); - void _gui_set_root_order_dirty(); void _gui_remove_modal_control(List::Element *MI); void _gui_remove_from_modal_stack(List::Element *MI, ObjectID p_prev_focus_owner);