diff --git a/procedural_animation.cpp b/procedural_animation.cpp index afaa3a4..3c14dd3 100644 --- a/procedural_animation.cpp +++ b/procedural_animation.cpp @@ -106,6 +106,10 @@ void ProceduralAnimation::remove_category(const int index) { memdelete(category); } +bool ProceduralAnimation::has_category(const int index) const { + return _categories.has(index); +} + String ProceduralAnimation::get_category_name(const int category_index) const { ERR_FAIL_COND_V(!_categories.has(category_index), ""); @@ -167,7 +171,16 @@ void ProceduralAnimation::remove_animation(const int category_index, const int a memdelete(entry); } -String ProceduralAnimation::get_animation_name(const int category_index, const int animation_index) { +bool ProceduralAnimation::has_animation(const int category_index, const int animation_index) const { + if (!_categories.has(category_index)) + return false; + + Category *cat = _categories[category_index]; + + return cat->animations.has(animation_index); +} + +String ProceduralAnimation::get_animation_name(const int category_index, const int animation_index) const { ERR_FAIL_COND_V(!_categories.has(category_index), ""); Category *cat = _categories[category_index]; @@ -286,7 +299,21 @@ void ProceduralAnimation::remove_keyframe(const int category_index, const int an memdelete(entry); } -String ProceduralAnimation::get_keyframe_name(const int category_index, const int animation_index, const int keyframe_index) { +bool ProceduralAnimation::has_keyframe(const int category_index, const int animation_index, const int keyframe_index) const { + if (!_categories.has(category_index)) + return false; + + Category *cat = _categories[category_index]; + + if (!cat->animations.has(animation_index)) + return false; + + AnimationEntry *ae = cat->animations[animation_index]; + + return ae->keyframes.has(keyframe_index); +} + +String ProceduralAnimation::get_keyframe_name(const int category_index, const int animation_index, const int keyframe_index) const { ERR_FAIL_COND_V(!_categories.has(category_index), ""); Category *cat = _categories[category_index]; @@ -1095,6 +1122,7 @@ void ProceduralAnimation::_bind_methods() { ClassDB::bind_method(D_METHOD("get_category_indices"), &ProceduralAnimation::get_category_indices); ClassDB::bind_method(D_METHOD("add_category", "name"), &ProceduralAnimation::add_category); ClassDB::bind_method(D_METHOD("remove_category", "index"), &ProceduralAnimation::remove_category); + ClassDB::bind_method(D_METHOD("has_category", "index"), &ProceduralAnimation::has_category); ClassDB::bind_method(D_METHOD("get_category_name", "category_index"), &ProceduralAnimation::get_category_name); ClassDB::bind_method(D_METHOD("set_category_name", "category_index"), &ProceduralAnimation::set_category_name); @@ -1103,6 +1131,7 @@ void ProceduralAnimation::_bind_methods() { ClassDB::bind_method(D_METHOD("get_animation_indices", "category_index"), &ProceduralAnimation::get_animation_indices); ClassDB::bind_method(D_METHOD("add_animation", "category_index"), &ProceduralAnimation::add_animation); ClassDB::bind_method(D_METHOD("remove_animation", "category_index", "animation_index"), &ProceduralAnimation::remove_animation); + ClassDB::bind_method(D_METHOD("has_animation", "category_index", "animation_index"), &ProceduralAnimation::has_animation); ClassDB::bind_method(D_METHOD("get_animation_name", "category_index", "animation_index"), &ProceduralAnimation::get_animation_name); ClassDB::bind_method(D_METHOD("set_animation_name", "category_index", "animation_index", "value"), &ProceduralAnimation::set_animation_name); @@ -1117,6 +1146,7 @@ void ProceduralAnimation::_bind_methods() { ClassDB::bind_method(D_METHOD("get_keyframe_indices", "category_index", "animation_index"), &ProceduralAnimation::get_keyframe_indices); ClassDB::bind_method(D_METHOD("add_keyframe", "category_index", "animation_index"), &ProceduralAnimation::add_keyframe); ClassDB::bind_method(D_METHOD("remove_keyframe", "category_index", "animation_index", "keyframe_index"), &ProceduralAnimation::remove_keyframe); + ClassDB::bind_method(D_METHOD("has_keyframe", "category_index", "animation_index", "keyframe_index"), &ProceduralAnimation::has_keyframe); ClassDB::bind_method(D_METHOD("get_keyframe_name", "category_index", "animation_index", "keyframe_index"), &ProceduralAnimation::get_keyframe_name); ClassDB::bind_method(D_METHOD("set_keyframe_name", "category_index", "animation_index", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_name); diff --git a/procedural_animation.h b/procedural_animation.h index 70d2e0f..a703088 100644 --- a/procedural_animation.h +++ b/procedural_animation.h @@ -177,6 +177,7 @@ public: PoolVector get_category_indices() const; int add_category(const String &name); void remove_category(const int index); + bool has_category(const int index) const; String get_category_name(const int category_index) const; void set_category_name(const int category_index, const String &value); @@ -185,8 +186,9 @@ public: PoolVector get_animation_indices(const int category_index) const; int add_animation(const int category_index); void remove_animation(const int category_index, const int animation_index); + bool has_animation(const int category_index, const int animation_index) const; - String get_animation_name(const int category_index, const int animation_index); + String get_animation_name(const int category_index, const int animation_index) const; void set_animation_name(const int category_index, const int animation_index, const String &value); Vector2 get_animation_node_position(const int category_index, int animation_index) const; @@ -199,8 +201,9 @@ public: PoolVector get_keyframe_indices(const int category_index, const int animation_index) const; int add_keyframe(const int category_index, const int animation_index); void remove_keyframe(const int category_index, const int animation_index, const int keyframe_index); + bool has_keyframe(const int category_index, const int animation_index, const int keyframe_index) const; - String get_keyframe_name(const int category_index, const int animation_index, const int keyframe_index); + String get_keyframe_name(const int category_index, const int animation_index, const int keyframe_index) const; void set_keyframe_name(const int category_index, const int animation_index, const int keyframe_index, const String &value); int get_keyframe_animation_keyframe_index(const int category_index, int animation_index, const int keyframe_index) const; diff --git a/procedural_animation_player.cpp b/procedural_animation_player.cpp index 92bec35..12677dd 100644 --- a/procedural_animation_player.cpp +++ b/procedural_animation_player.cpp @@ -29,17 +29,87 @@ void ProceduralAnimationPlayer::set_animation(const Ref &an _animation = animation; } +int ProceduralAnimationPlayer::get_current_category() const { + return _current_category; +} +void ProceduralAnimationPlayer::set_current_category(const int p_category) { + _current_category = p_category; +} + +int ProceduralAnimationPlayer::get_current_animation() const { + return _current_animation; +} +void ProceduralAnimationPlayer::set_current_animation(const int p_animation) { + _current_animation = p_animation; +} + void ProceduralAnimationPlayer::play(const StringName &p_name, float p_custom_blend, float p_custom_scale, bool p_from_end) { } ProceduralAnimationPlayer::ProceduralAnimationPlayer() { + _current_category = 0; + _current_animation = 0; } ProceduralAnimationPlayer::~ProceduralAnimationPlayer() { _animation.unref(); } +void ProceduralAnimationPlayer::_validate_property(PropertyInfo &property) const { + + if (property.name == "current_category") { + + if (_animation.is_valid()) { + + String names; + + PoolIntArray arr = _animation->get_category_indices(); + for (int i = 0; i < arr.size(); ++i) { + if (i > 0) + names += ","; + + names += _animation->get_category_name(arr[i]); + } + + property.hint = PROPERTY_HINT_ENUM; + property.hint_string = names; + } else { + + property.hint = PROPERTY_HINT_NONE; + property.hint_string = ""; + } + } else if (property.name == "current_animation") { + + if (_animation.is_valid() && _animation->has_category(_current_category)) { + + String names; + + PoolIntArray arr = _animation->get_animation_indices(_current_category); + for (int i = 0; i < arr.size(); ++i) { + if (i > 0) + names += ","; + + names += _animation->get_animation_name(_current_category, arr[i]); + } + + property.hint = PROPERTY_HINT_ENUM; + property.hint_string = names; + } else { + property.hint = PROPERTY_HINT_NONE; + property.hint_string = ""; + } + } +} + void ProceduralAnimationPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_animation"), &ProceduralAnimationPlayer::get_animation); ClassDB::bind_method(D_METHOD("set_animation", "value"), &ProceduralAnimationPlayer::set_animation); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "animation", PROPERTY_HINT_RESOURCE_TYPE, "ProceduralAnimation"), "set_animation", "get_animation"); + + ClassDB::bind_method(D_METHOD("get_current_category"), &ProceduralAnimationPlayer::get_current_category); + ClassDB::bind_method(D_METHOD("set_current_category", "category"), &ProceduralAnimationPlayer::set_current_category); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_category"), "set_current_category", "get_current_category"); + + ClassDB::bind_method(D_METHOD("get_current_animation"), &ProceduralAnimationPlayer::get_current_animation); + ClassDB::bind_method(D_METHOD("set_current_animation", "animation"), &ProceduralAnimationPlayer::set_current_animation); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_animation"), "set_current_animation", "get_current_animation"); } \ No newline at end of file diff --git a/procedural_animation_player.h b/procedural_animation_player.h index 26ef700..8627eea 100644 --- a/procedural_animation_player.h +++ b/procedural_animation_player.h @@ -25,6 +25,8 @@ SOFTWARE. #include "scene/main/node.h" +#include "core/string_name.h" + #include "procedural_animation.h" class ProceduralAnimationPlayer : public Node { @@ -34,16 +36,25 @@ public: Ref get_animation(); void set_animation(const Ref &animation); + int get_current_category() const; + void set_current_category(const int p_category); + + int get_current_animation() const; + void set_current_animation(const int p_animation); + void play(const StringName &p_name = StringName(), float p_custom_blend = -1, float p_custom_scale = 1.0, bool p_from_end = false); ProceduralAnimationPlayer(); ~ProceduralAnimationPlayer(); protected: + void _validate_property(PropertyInfo &property) const; static void _bind_methods(); private: Ref _animation; + int _current_category; + int _current_animation; }; #endif \ No newline at end of file