Commit 623f7b64 by Juan Linietsky

Updat polygons when skeleton setup changes, fixes #25949

parent be9b9383
......@@ -88,6 +88,10 @@ bool Polygon2D::_edit_is_selected_on_click(const Point2 &p_point, double p_toler
return Geometry::is_point_in_polygon(p_point - get_offset(), polygon2d);
}
void Polygon2D::_skeleton_bone_setup_changed() {
update();
}
void Polygon2D::_notification(int p_what) {
switch (p_what) {
......@@ -102,10 +106,27 @@ void Polygon2D::_notification(int p_what) {
skeleton_node = Object::cast_to<Skeleton2D>(get_node(skeleton));
}
if (skeleton_node)
ObjectID new_skeleton_id = 0;
if (skeleton_node) {
VS::get_singleton()->canvas_item_attach_skeleton(get_canvas_item(), skeleton_node->get_skeleton());
else
new_skeleton_id = skeleton_node->get_instance_id();
} else {
VS::get_singleton()->canvas_item_attach_skeleton(get_canvas_item(), RID());
}
if (new_skeleton_id != current_skeleton_id) {
Object *old_skeleton = ObjectDB::get_instance(current_skeleton_id);
if (old_skeleton) {
old_skeleton->disconnect("bone_setup_changed", this, "_skeleton_bone_setup_changed");
}
if (skeleton_node) {
skeleton_node->connect("bone_setup_changed", this, "_skeleton_bone_setup_changed");
}
current_skeleton_id = new_skeleton_id;
}
Vector<Vector2> points;
Vector<Vector2> uvs;
......@@ -809,6 +830,8 @@ void Polygon2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_bones", "bones"), &Polygon2D::_set_bones);
ClassDB::bind_method(D_METHOD("_get_bones"), &Polygon2D::_get_bones);
ClassDB::bind_method(D_METHOD("_skeleton_bone_setup_changed"), &Polygon2D::_skeleton_bone_setup_changed);
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "antialiased"), "set_antialiased", "get_antialiased");
......@@ -846,4 +869,5 @@ Polygon2D::Polygon2D() {
color = Color(1, 1, 1);
rect_cache_dirty = true;
internal_vertices = 0;
current_skeleton_id = 0;
}
......@@ -65,10 +65,13 @@ class Polygon2D : public Node2D {
mutable Rect2 item_rect;
NodePath skeleton;
ObjectID current_skeleton_id;
Array _get_bones() const;
void _set_bones(const Array &p_bones);
void _skeleton_bone_setup_changed();
protected:
void _notification(int p_what);
static void _bind_methods();
......
......@@ -203,6 +203,7 @@ void Skeleton2D::_update_bone_setup() {
transform_dirty = true;
_update_transform();
emit_signal("bone_setup_changed");
}
void Skeleton2D::_make_transform_dirty() {
......@@ -291,6 +292,8 @@ void Skeleton2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_bone", "idx"), &Skeleton2D::get_bone);
ClassDB::bind_method(D_METHOD("get_skeleton"), &Skeleton2D::get_skeleton);
ADD_SIGNAL(MethodInfo("bone_setup_changed"));
}
Skeleton2D::Skeleton2D() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment