From 9f4bf5ec8058340541ee6e35bc15015fe576a3e6 Mon Sep 17 00:00:00 2001 From: andriyDev Date: Wed, 23 Sep 2020 15:49:50 -0400 Subject: Deleted YSort, moved its functionality directly into Node2D. YSort now has a compatibility alias to Node2D. Updated TileMap to use the existing Node2D y_sort_enabled property instead of its own property. Updated Node2D doc to include the new y_sort_enabled member. Updated TileMap doc to remove its mention of cell_y_sort. Deleted YSort doc. --- scene/2d/node_2d.cpp | 15 ++++++++++++++- scene/2d/node_2d.h | 4 ++++ scene/2d/tile_map.cpp | 6 ++++++ scene/2d/tile_map.h | 1 + scene/2d/y_sort.cpp | 52 --------------------------------------------------- scene/2d/y_sort.h | 47 ---------------------------------------------- 6 files changed, 25 insertions(+), 100 deletions(-) delete mode 100644 scene/2d/y_sort.cpp delete mode 100644 scene/2d/y_sort.h (limited to 'scene/2d') diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index 8afc43ddc9..049d121213 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -391,6 +391,15 @@ Point2 Node2D::to_global(Point2 p_local) const { return get_global_transform().xform(p_local); } +void Node2D::set_y_sort_enabled(bool p_enabled) { + y_sort_enabled = p_enabled; + RS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), y_sort_enabled); +} + +bool Node2D::is_y_sort_enabled() const { + return y_sort_enabled; +} + 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); @@ -437,6 +446,9 @@ void Node2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_z_as_relative", "enable"), &Node2D::set_z_as_relative); ClassDB::bind_method(D_METHOD("is_z_relative"), &Node2D::is_z_relative); + ClassDB::bind_method(D_METHOD("set_y_sort_enabled", "enabled"), &Node2D::set_y_sort_enabled); + ClassDB::bind_method(D_METHOD("is_y_sort_enabled"), &Node2D::is_y_sort_enabled); + ClassDB::bind_method(D_METHOD("get_relative_transform_to_parent", "parent"), &Node2D::get_relative_transform_to_parent); ADD_GROUP("Transform", ""); @@ -454,7 +466,8 @@ void Node2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_scale", PROPERTY_HINT_NONE, "", 0), "set_global_scale", "get_global_scale"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "global_transform", PROPERTY_HINT_NONE, "", 0), "set_global_transform", "get_global_transform"); - ADD_GROUP("Z Index", ""); + ADD_GROUP("Ordering", ""); ADD_PROPERTY(PropertyInfo(Variant::INT, "z_index", PROPERTY_HINT_RANGE, itos(RS::CANVAS_ITEM_Z_MIN) + "," + itos(RS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_index", "get_z_index"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "z_as_relative"), "set_z_as_relative", "is_z_relative"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "y_sort_enabled"), "set_y_sort_enabled", "is_y_sort_enabled"); } diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h index 358b7e6520..339efd9179 100644 --- a/scene/2d/node_2d.h +++ b/scene/2d/node_2d.h @@ -42,6 +42,7 @@ class Node2D : public CanvasItem { real_t skew = 0.0; int z_index = 0; bool z_relative = true; + bool y_sort_enabled = false; Transform2D _mat; @@ -117,6 +118,9 @@ public: void set_z_as_relative(bool p_enabled); bool is_z_relative() const; + virtual void set_y_sort_enabled(bool p_enabled); + virtual bool is_y_sort_enabled() const; + Transform2D get_relative_transform_to_parent(const Node *p_parent) const; Transform2D get_transform() const override; diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 24b907fe6c..e79dfb019c 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -334,6 +334,12 @@ TileMap::VisibilityMode TileMap::get_navigation_visibility_mode() { return show_navigation; } +void TileMap::set_y_sort_enabled(bool p_enable) { + Node2D::set_y_sort_enabled(p_enable); + _recreate_quadrants(); + emit_signal("changed"); +} + void TileMap::update_dirty_quadrants() { if (!pending_update) { return; diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h index f02455a84b..3001e6b471 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -279,6 +279,7 @@ public: int get_effective_quadrant_size() const; void update_dirty_quadrants(); + virtual void set_y_sort_enabled(bool p_enable) override; Vector2 map_to_world(const Vector2i &p_pos) const; Vector2i world_to_map(const Vector2 &p_pos) const; diff --git a/scene/2d/y_sort.cpp b/scene/2d/y_sort.cpp deleted file mode 100644 index 7e7bc27cc2..0000000000 --- a/scene/2d/y_sort.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************/ -/* y_sort.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "y_sort.h" - -void YSort::set_sort_enabled(bool p_enabled) { - sort_enabled = p_enabled; - RS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), sort_enabled); -} - -bool YSort::is_sort_enabled() const { - return sort_enabled; -} - -void YSort::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_sort_enabled", "enabled"), &YSort::set_sort_enabled); - ClassDB::bind_method(D_METHOD("is_sort_enabled"), &YSort::is_sort_enabled); - - ADD_GROUP("Sort", "sort_"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sort_enabled"), "set_sort_enabled", "is_sort_enabled"); -} - -YSort::YSort() { - RS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), true); -} diff --git a/scene/2d/y_sort.h b/scene/2d/y_sort.h deleted file mode 100644 index 7d36ee3391..0000000000 --- a/scene/2d/y_sort.h +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************/ -/* y_sort.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef Y_SORT_H -#define Y_SORT_H - -#include "scene/2d/node_2d.h" - -class YSort : public Node2D { - GDCLASS(YSort, Node2D); - bool sort_enabled = true; - static void _bind_methods(); - -public: - void set_sort_enabled(bool p_enabled); - bool is_sort_enabled() const; - YSort(); -}; - -#endif // Y_SORT_H -- cgit v1.2.3