From bf561c49468c9a4d5c47ba7bc53204a51270855f Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Fri, 4 May 2018 16:46:32 -0300 Subject: Made bone handling for actual Bone2D a special case. Make custom bones appear like a custom (less important) option now. --- scene/2d/skeleton_2d.cpp | 15 +++++++++++++++ scene/2d/skeleton_2d.h | 4 ++++ 2 files changed, 19 insertions(+) (limited to 'scene') diff --git a/scene/2d/skeleton_2d.cpp b/scene/2d/skeleton_2d.cpp index 9197127235..2363c791fa 100644 --- a/scene/2d/skeleton_2d.cpp +++ b/scene/2d/skeleton_2d.cpp @@ -56,7 +56,11 @@ void Bone2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_skeleton_rest"), &Bone2D::get_skeleton_rest); ClassDB::bind_method(D_METHOD("get_index_in_skeleton"), &Bone2D::get_index_in_skeleton); + ClassDB::bind_method(D_METHOD("set_default_length", "default_length"), &Bone2D::set_default_length); + ClassDB::bind_method(D_METHOD("get_default_length"), &Bone2D::get_default_length); + ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D,"rest"),"set_rest","get_rest"); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"default_length",PROPERTY_HINT_RANGE,"1,1024,1"),"set_default_length","get_default_length"); } void Bone2D::set_rest(const Transform2D &p_rest) { @@ -84,6 +88,16 @@ void Bone2D::apply_rest() { set_transform(rest); } +void Bone2D::set_default_length(float p_length) { + + default_length=p_length; + +} + +float Bone2D::get_default_length() const { + return default_length; +} + int Bone2D::get_index_in_skeleton() const { ERR_FAIL_COND_V(!skeleton,-1); skeleton->_update_bone_setup(); @@ -118,6 +132,7 @@ Bone2D::Bone2D() { skeleton = NULL; parent_bone = NULL; skeleton_index=-1; + default_length=16; set_notify_local_transform(true); //this is a clever hack so the bone knows no rest has been set yet, allowing to show an error. for(int i=0;i<3;i++) { diff --git a/scene/2d/skeleton_2d.h b/scene/2d/skeleton_2d.h index 9ae74b56d3..cd270dac85 100644 --- a/scene/2d/skeleton_2d.h +++ b/scene/2d/skeleton_2d.h @@ -11,6 +11,7 @@ class Bone2D : public Node2D { Bone2D *parent_bone; Skeleton2D *skeleton; Transform2D rest; + float default_length; friend class Skeleton2D; int skeleton_index; @@ -27,6 +28,9 @@ public: String get_configuration_warning() const; + void set_default_length(float p_length); + float get_default_length() const; + int get_index_in_skeleton() const; Bone2D(); -- cgit v1.2.3