From e5c1da1c6103424b93065386416c6dfd18ad8233 Mon Sep 17 00:00:00 2001 From: Micky Date: Sat, 6 Jan 2024 16:16:10 +0100 Subject: [PATCH] Add Autocompletion for AnimationNodeStateMachine & BlendTree --- scene/animation/animation_blend_tree.cpp | 16 ++++++++++++++++ scene/animation/animation_blend_tree.h | 2 ++ scene/animation/animation_node_state_machine.cpp | 16 ++++++++++++++++ scene/animation/animation_node_state_machine.h | 2 ++ 4 files changed, 36 insertions(+) diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index 6ed61b4f2617..de7948dca705 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -1544,6 +1544,22 @@ void AnimationNodeBlendTree::_node_changed(const StringName &p_node) { emit_signal(SNAME("node_changed"), p_node); } +void AnimationNodeBlendTree::get_argument_options(const StringName &p_function, int p_idx, List *r_options) const { + String pf = p_function; + bool add_node_options = false; + if (p_idx == 0) { + add_node_options = (pf == "get_node" || pf == "has_node" || pf == "rename_node" || pf == "remove_node" || pf == "set_node_position" || pf == "get_node_position" || pf == "connect_node" || pf == "disconnect_node"); + } else if (p_idx == 2) { + add_node_options = (pf == "connect_node" || pf == "disconnect_node"); + } + if (add_node_options) { + for (KeyValue E : nodes) { + r_options->push_back(String(E.key).quote()); + } + } + AnimationRootNode::get_argument_options(p_function, p_idx, r_options); +} + void AnimationNodeBlendTree::_bind_methods() { ClassDB::bind_method(D_METHOD("add_node", "name", "node", "position"), &AnimationNodeBlendTree::add_node, DEFVAL(Vector2())); ClassDB::bind_method(D_METHOD("get_node", "name"), &AnimationNodeBlendTree::get_node); diff --git a/scene/animation/animation_blend_tree.h b/scene/animation/animation_blend_tree.h index f38d7ebde8cc..8c199110221f 100644 --- a/scene/animation/animation_blend_tree.h +++ b/scene/animation/animation_blend_tree.h @@ -454,6 +454,8 @@ class AnimationNodeBlendTree : public AnimationRootNode { virtual Ref get_child_by_name(const StringName &p_name) const override; + virtual void get_argument_options(const StringName &p_function, int p_idx, List *r_options) const override; + AnimationNodeBlendTree(); ~AnimationNodeBlendTree(); }; diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp index f4e1b3615c2e..36399505c17e 100644 --- a/scene/animation/animation_node_state_machine.cpp +++ b/scene/animation/animation_node_state_machine.cpp @@ -1793,6 +1793,22 @@ void AnimationNodeStateMachine::_animation_node_removed(const ObjectID &p_oid, c AnimationRootNode::_animation_node_removed(p_oid, p_node); } +void AnimationNodeStateMachine::get_argument_options(const StringName &p_function, int p_idx, List *r_options) const { + String pf = p_function; + bool add_state_options = false; + if (p_idx == 0) { + add_state_options = (pf == "get_node" || pf == "has_node" || pf == "rename_node" || pf == "remove_node" || pf == "replace_node" || pf == "set_node_position" || pf == "get_node_position"); + } else if (p_idx <= 1) { + add_state_options = (pf == "has_transition" || pf == "add_transition" || pf == "remove_transition"); + } + if (add_state_options) { + for (KeyValue E : states) { + r_options->push_back(String(E.key).quote()); + } + } + AnimationRootNode::get_argument_options(p_function, p_idx, r_options); +} + void AnimationNodeStateMachine::_bind_methods() { ClassDB::bind_method(D_METHOD("add_node", "name", "node", "position"), &AnimationNodeStateMachine::add_node, DEFVAL(Vector2())); ClassDB::bind_method(D_METHOD("replace_node", "name", "node"), &AnimationNodeStateMachine::replace_node); diff --git a/scene/animation/animation_node_state_machine.h b/scene/animation/animation_node_state_machine.h index ec20c68a4b81..7a35ae71651e 100644 --- a/scene/animation/animation_node_state_machine.h +++ b/scene/animation/animation_node_state_machine.h @@ -215,6 +215,8 @@ class AnimationNodeStateMachine : public AnimationRootNode { virtual Ref get_child_by_name(const StringName &p_name) const override; + virtual void get_argument_options(const StringName &p_function, int p_idx, List *r_options) const override; + AnimationNodeStateMachine(); };