This commit is contained in:
Chase W 2021-11-09 09:12:53 -03:00 committed by GitHub
commit 7fee97478f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 71 additions and 0 deletions

View file

@ -273,6 +273,18 @@ void Camera2D::_notification(int p_what) {
viewport = nullptr;
} break;
case NOTIFICATION_WORLD_2D_CHANGED: {
if (is_current()) {
if (viewport && !(custom_viewport && !ObjectDB::get_instance(custom_viewport_id))) {
viewport->set_canvas_transform(Transform2D());
}
}
remove_from_group(group_name);
remove_from_group(canvas_group_name);
_setup_viewport();
_update_scroll();
} break;
#ifdef TOOLS_ENABLED
case NOTIFICATION_DRAW: {
if (!is_inside_tree() || !Engine::get_singleton()->is_editor_hint()) {

View file

@ -597,6 +597,13 @@ void CanvasItem::_notification(int p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
emit_signal(SceneStringNames::get_singleton()->visibility_changed);
} break;
case NOTIFICATION_WORLD_2D_CHANGED: {
_exit_canvas();
_enter_canvas();
if (get_script_instance()) {
get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_world_2d_changed, nullptr, 0);
}
} break;
}
}
@ -1200,6 +1207,7 @@ void CanvasItem::_bind_methods() {
BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED);
BIND_CONSTANT(NOTIFICATION_ENTER_CANVAS);
BIND_CONSTANT(NOTIFICATION_EXIT_CANVAS);
BIND_CONSTANT(NOTIFICATION_WORLD_2D_CHANGED);
}
Transform2D CanvasItem::get_canvas_transform() const {

View file

@ -99,6 +99,27 @@ void CollisionObject2D::_notification(int p_what) {
Physics2DServer::get_singleton()->body_attach_canvas_instance_id(rid, 0);
}
} break;
case NOTIFICATION_WORLD_2D_CHANGED: {
Transform2D global_transform = get_global_transform();
if (area) {
Physics2DServer::get_singleton()->area_set_transform(rid, global_transform);
} else {
Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform);
}
RID space = get_world_2d()->get_space();
if (area) {
Physics2DServer::get_singleton()->area_set_space(rid, space);
} else {
Physics2DServer::get_singleton()->body_set_space(rid, space);
}
_update_pickable();
//get space
} break;
}
}

View file

@ -1037,6 +1037,10 @@ void Viewport::set_world_2d(const Ref<World2D> &p_world_2d) {
_update_listener_2d();
if (is_inside_tree()) {
_propagate_world_2d_changed(this);
}
if (is_inside_tree()) {
current_canvas = find_world_2d()->get_canvas();
VisualServer::get_singleton()->viewport_attach_canvas(viewport, current_canvas);
@ -1077,6 +1081,29 @@ void Viewport::_propagate_enter_world(Node *p_node) {
}
}
void Viewport::_propagate_world_2d_changed(Node *p_node) {
if (p_node != this) {
if (!p_node->is_inside_tree()) { //may not have entered scene yet
return;
}
if (Object::cast_to<CanvasItem>(p_node)) {
p_node->notification(CanvasItem::NOTIFICATION_WORLD_2D_CHANGED);
} else {
Viewport *v = Object::cast_to<Viewport>(p_node);
if (v) {
if (v->world_2d.is_valid()) {
return;
}
}
}
}
for (int i = 0; i < p_node->get_child_count(); i++) {
_propagate_world_2d_changed(p_node->get_child(i));
}
}
void Viewport::_propagate_viewport_notification(Node *p_node, int p_what) {
p_node->notification(p_what);
for (int i = 0; i < p_node->get_child_count(); i++) {

View file

@ -262,6 +262,7 @@ private:
void _propagate_enter_world(Node *p_node);
void _propagate_exit_world(Node *p_node);
void _propagate_world_2d_changed(Node *p_node);
void _propagate_viewport_notification(Node *p_node, int p_what);
void _update_stretch_transform();

View file

@ -93,6 +93,7 @@ SceneStringNames::SceneStringNames() {
_exit_tree = StaticCString::create("_exit_tree");
_enter_world = StaticCString::create("_enter_world");
_exit_world = StaticCString::create("_exit_world");
_world_2d_changed = StaticCString::create("_world_2d_changed");
_ready = StaticCString::create("_ready");
_update_scroll = StaticCString::create("_update_scroll");

View file

@ -109,6 +109,7 @@ public:
StringName _process;
StringName _enter_world;
StringName _exit_world;
StringName _world_2d_changed;
StringName _enter_tree;
StringName _exit_tree;
StringName _draw;