From 787f61d70b5c855b546edee91c5432aaa1114c63 Mon Sep 17 00:00:00 2001 From: Micky Date: Thu, 4 Jan 2024 20:49:27 +0100 Subject: [PATCH] Add autocompletion for AnimationLibrary's & AnimationMixer --- scene/animation/animation_mixer.cpp | 20 ++++++++++++++++++++ scene/animation/animation_mixer.h | 1 + scene/resources/animation_library.cpp | 12 ++++++++++++ scene/resources/animation_library.h | 2 ++ 4 files changed, 35 insertions(+) diff --git a/scene/animation/animation_mixer.cpp b/scene/animation/animation_mixer.cpp index da00d1dd7b0..2338c305de5 100644 --- a/scene/animation/animation_mixer.cpp +++ b/scene/animation/animation_mixer.cpp @@ -2054,6 +2054,26 @@ void AnimationMixer::_notification(int p_what) { } } +void AnimationMixer::get_argument_options(const StringName &p_function, int p_idx, List *r_options) const { + String pf = p_function; + if (p_idx == 0) { + if (pf == "get_animation" || pf == "has_animation") { + List al; + get_animation_list(&al); + for (const StringName &name : al) { + r_options->push_back(String(name).quote()); + } + } else if (pf == "get_animation_library" || pf == "has_animation_library" || pf == "remove_animation_library" || pf == "rename_animation_library") { + List al; + get_animation_library_list(&al); + for (const StringName &name : al) { + r_options->push_back(String(name).quote()); + } + } + } + Node::get_argument_options(p_function, p_idx, r_options); +} + void AnimationMixer::_bind_methods() { /* ---- Data lists ---- */ ClassDB::bind_method(D_METHOD("add_animation_library", "name", "library"), &AnimationMixer::add_animation_library); diff --git a/scene/animation/animation_mixer.h b/scene/animation/animation_mixer.h index 0cd204b3844..ffa6dc2e555 100644 --- a/scene/animation/animation_mixer.h +++ b/scene/animation/animation_mixer.h @@ -340,6 +340,7 @@ protected: void _get_property_list(List *p_list) const; void _notification(int p_what); virtual void _validate_property(PropertyInfo &p_property) const; + virtual void get_argument_options(const StringName &p_function, int p_idx, List *r_options) const override; static void _bind_methods(); void _node_removed(Node *p_node); diff --git a/scene/resources/animation_library.cpp b/scene/resources/animation_library.cpp index 436bf88ec95..fac72a31508 100644 --- a/scene/resources/animation_library.cpp +++ b/scene/resources/animation_library.cpp @@ -143,6 +143,18 @@ Dictionary AnimationLibrary::_get_data() const { return ret; } +void AnimationLibrary::get_argument_options(const StringName &p_function, int p_idx, List *r_options) const { + String pf = p_function; + if (p_idx == 0 && (pf == "get_animation" || pf == "has_animation" || pf == "rename_animation" || pf == "remove_animation")) { + List names; + get_animation_list(&names); + for (const StringName &E : names) { + r_options->push_back(E.operator String().quote()); + } + } + Resource::get_argument_options(p_function, p_idx, r_options); +} + void AnimationLibrary::_bind_methods() { ClassDB::bind_method(D_METHOD("add_animation", "name", "animation"), &AnimationLibrary::add_animation); ClassDB::bind_method(D_METHOD("remove_animation", "name"), &AnimationLibrary::remove_animation); diff --git a/scene/resources/animation_library.h b/scene/resources/animation_library.h index b2152fd7c54..c1d78068bb4 100644 --- a/scene/resources/animation_library.h +++ b/scene/resources/animation_library.h @@ -62,6 +62,8 @@ public: Ref get_animation(const StringName &p_name) const; void get_animation_list(List *p_animations) const; + virtual void get_argument_options(const StringName &p_function, int p_idx, List *r_options) const override; + AnimationLibrary(); };