3838#include " editor/editor_string_names.h"
3939#include " editor/editor_undo_redo_manager.h"
4040#include " editor/gui/editor_file_dialog.h"
41+ #include " editor/inspector_dock.h"
4142#include " editor/themes/editor_scale.h"
4243#include " scene/animation/animation_blend_tree.h"
4344#include " scene/animation/animation_player.h"
5354#include " scene/gui/spin_box.h"
5455#include " scene/main/window.h"
5556
57+ // void BlendPointEditor::_bind_methods() {
58+ // ClassDB::bind_method(D_METHOD("set_fade_in", "value"), &BlendPointEditor::set_fade_in);
59+ // ClassDB::bind_method(D_METHOD("get_fade_in"), &BlendPointEditor::get_fade_in);
60+ // ClassDB::bind_method(D_METHOD("set_fade_out", "value"), &BlendPointEditor::set_fade_out);
61+ // ClassDB::bind_method(D_METHOD("get_fade_out"), &BlendPointEditor::get_fade_out);
62+ // //ClassDB::bind_method(D_METHOD("_dont_undo_redo"), &BlendPointEditor::_dont_undo_redo);
63+ // //ClassDB::bind_method(D_METHOD("_hide_script_from_inspector"), &BlendPointEditor::_hide_script_from_inspector);
64+ // //ClassDB::bind_method(D_METHOD("_hide_metadata_from_inspector"), &BlendPointEditor::_hide_metadata_from_inspector);
65+ // ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fade_in", PROPERTY_HINT_NONE, "0,60,0.01,or_greater,suffix:s"), "set_fade_in", "get_fade_in");
66+ // ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fade_out", PROPERTY_HINT_NONE, "0,60,0.01,or_greater,suffix:s"), "set_fade_out", "get_fade_out");
67+ // ClassDB::bind_method(D_METHOD("get_anim_node"), &BlendPointEditor::get_anim_node);
68+ //
69+ // ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "animation_node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationNode"), "", "get_anim_node");
70+ // }
71+
5672bool AnimationNodeBlendSpace2DEditor::can_edit (const Ref<AnimationNode> &p_node) {
5773 Ref<AnimationNodeBlendSpace2D> bs2d = p_node;
5874 return bs2d.is_valid ();
@@ -88,6 +104,9 @@ void AnimationNodeBlendSpace2DEditor::edit(const Ref<AnimationNode> &p_node) {
88104 tool_triangle->set_disabled (read_only);
89105 auto_triangles->set_disabled (read_only);
90106 sync->set_disabled (read_only);
107+ default_velocity_limit->set_editable (!read_only);
108+ use_velocity_limit->set_disabled (read_only);
109+ override_delta->set_disabled (read_only);
91110 interpolation->set_disabled (read_only);
92111}
93112
@@ -176,15 +195,16 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven
176195 if (points[i].distance_to (mb->get_position ()) < 10 * EDSCALE) {
177196 selected_point = i;
178197 Ref<AnimationNode> node = blend_space->get_blend_point_node (i);
179- EditorNode::get_singleton ()->push_item (node.ptr (), " " , true );
198+ current_blend_point_editor->setup (blend_space, selected_point, node);
199+ // EditorNode::get_singleton()->push_item(current_blend_point_editor.ptr(), "", true);
200+ InspectorDock::get_inspector_singleton ()->edit (current_blend_point_editor.ptr ());
180201 dragging_selected_attempt = true ;
181202 drag_from = mb->get_position ();
182203 _update_tool_erase ();
183204 _update_edited_point_pos ();
184205 return ;
185206 }
186207 }
187-
188208 // then try to see if a triangle can be selected
189209 if (!blend_space->get_auto_triangles ()) { // if autotriangles use, disable this
190210 for (int i = 0 ; i < blend_space->get_triangle_count (); i++) {
@@ -650,6 +670,9 @@ void AnimationNodeBlendSpace2DEditor::_update_space() {
650670
651671 sync->set_pressed (blend_space->is_using_sync ());
652672 interpolation->select (blend_space->get_blend_mode ());
673+ use_velocity_limit->set_pressed (blend_space->get_use_velocity_limit ());
674+ default_velocity_limit->set_value (blend_space->get_velocity_limit ());
675+ override_delta->set_pressed (blend_space->get_override_delta ());
653676
654677 max_x_value->set_value (blend_space->get_max_space ().x );
655678 max_y_value->set_value (blend_space->get_max_space ().y );
@@ -686,6 +709,15 @@ void AnimationNodeBlendSpace2DEditor::_config_changed(double) {
686709 undo_redo->add_undo_method (blend_space.ptr (), " set_use_sync" , blend_space->is_using_sync ());
687710 undo_redo->add_do_method (blend_space.ptr (), " set_blend_mode" , interpolation->get_selected ());
688711 undo_redo->add_undo_method (blend_space.ptr (), " set_blend_mode" , blend_space->get_blend_mode ());
712+ undo_redo->add_do_method (blend_space.ptr (), " set_use_velocity_limit" , use_velocity_limit->is_pressed ());
713+ undo_redo->add_undo_method (blend_space.ptr (), " set_use_velocity_limit" , blend_space->get_use_velocity_limit ());
714+ undo_redo->add_do_method (blend_space.ptr (), " set_velocity_limit" , default_velocity_limit->get_value ());
715+ undo_redo->add_undo_method (blend_space.ptr (), " set_velocity_limit" , blend_space->get_velocity_limit ());
716+ undo_redo->add_do_method (blend_space.ptr (), " set_override_delta" , override_delta->is_pressed ());
717+ undo_redo->add_undo_method (blend_space.ptr (), " set_override_delta" , blend_space->get_override_delta ());
718+ blending_hb->set_visible (sync->is_pressed ());
719+ // edit_fade_hb->set_visible(sync->is_pressed() && !Math::is_zero_approx(default_blend_time->get_value()));
720+
689721 undo_redo->add_do_method (this , " _update_space" );
690722 undo_redo->add_undo_method (this , " _update_space" );
691723 undo_redo->commit_action ();
@@ -790,6 +822,19 @@ void AnimationNodeBlendSpace2DEditor::_edit_point_pos(double) {
790822 blend_space_draw->queue_redraw ();
791823}
792824
825+ void AnimationNodeBlendSpace2DEditor::_edit_curve () {
826+ // if (!blend_space->get_velocity_limit_curve().is_valid()) {
827+ // blend_space->get_velocity_limit_curve().instantiate();
828+ // }
829+ // EditorNode::get_singleton()->push_item(blend_space->get_velocity_limit_curve().ptr(), "", true);
830+ }
831+ void AnimationNodeBlendSpace2DEditor::_delete_curve () {
832+ // if (!blend_space->get_velocity_limit_curve().is_valid()) {
833+ // blend_space->get_velocity_limit_curve().instantiate();
834+ // }
835+ // EditorNode::get_singleton()->push_item(blend_space->get_velocity_limit_curve().ptr(), "", true);
836+ }
837+
793838void AnimationNodeBlendSpace2DEditor::_notification (int p_what) {
794839 switch (p_what) {
795840 case NOTIFICATION_ENTER_TREE:
@@ -861,6 +906,61 @@ void AnimationNodeBlendSpace2DEditor::_auto_triangles_toggled() {
861906 undo_redo->commit_action ();
862907}
863908
909+ void BlendPointEditor::_edit_point_velocity_limit () {
910+ if (updating) {
911+ return ;
912+ }
913+ updating = true ;
914+ EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton ();
915+ undo_redo->create_action (TTR (" Change Node Fade" ));
916+ undo_redo->add_do_method (blend_space.ptr (), " set_blend_point_vl" , selected_point, velocity_limit);
917+ undo_redo->add_undo_method (blend_space.ptr (), " set_blend_point_vl" , selected_point, blend_space->get_blend_point_vl (selected_point));
918+ undo_redo->commit_action ();
919+ updating = false ;
920+ }
921+ void BlendPointEditor::setup (Ref<AnimationNodeBlendSpace2D> p_blend_space, int p_idx, Ref<AnimationNode> p_anim_node) {
922+ blend_space = p_blend_space;
923+ selected_point = p_idx;
924+ anim_node = p_anim_node;
925+ }
926+
927+ void BlendPointEditor::set_velocity_limit (float p_value) {
928+ if (blend_space.is_valid ()) {
929+ velocity_limit = p_value;
930+ _edit_point_velocity_limit ();
931+ }
932+ }
933+ double BlendPointEditor::get_velocity_limit () const {
934+ return (blend_space.is_valid ()) ? blend_space->get_blend_point_vl (selected_point) : 0 ;
935+ }
936+
937+ Ref<AnimationNode> BlendPointEditor::get_anim_node () const {
938+ return anim_node;
939+ }
940+ void BlendPointEditor::set_velocity_limit_curve (float const p_curve) {
941+ if (blend_space.is_valid ()) {
942+ blend_space->set_velocity_limit_curve (p_curve);
943+ }
944+ }
945+ float BlendPointEditor::get_velocity_limit_curve () const {
946+ return (blend_space.is_valid ()) ? blend_space->get_velocity_limit_curve () : 1.0 ;
947+ }
948+
949+ void BlendPointEditor::_bind_methods () {
950+ ClassDB::bind_method (D_METHOD (" set_velocity_limit" , " value" ), &BlendPointEditor::set_velocity_limit);
951+ ClassDB::bind_method (D_METHOD (" get_velocity_limit" ), &BlendPointEditor::get_velocity_limit);
952+ ClassDB::bind_method (D_METHOD (" _dont_undo_redo" ), &BlendPointEditor::_dont_undo_redo);
953+ ClassDB::bind_method (D_METHOD (" _hide_script_from_inspector" ), &BlendPointEditor::_hide_script_from_inspector);
954+ ClassDB::bind_method (D_METHOD (" _hide_metadata_from_inspector" ), &BlendPointEditor::_hide_metadata_from_inspector);
955+
956+ ClassDB::bind_method (D_METHOD (" get_velocity_limit_curve" ), &BlendPointEditor::get_velocity_limit_curve);
957+ ClassDB::bind_method (D_METHOD (" set_velocity_limit_curve" ), &BlendPointEditor::set_velocity_limit_curve);
958+ ADD_PROPERTY (PropertyInfo (Variant::FLOAT, " velocity_limit" , PROPERTY_HINT_NONE, " 0,60,0.01,or_greater,suffix:/s" ), " set_velocity_limit" , " get_velocity_limit" );
959+ ClassDB::bind_method (D_METHOD (" get_anim_node" ), &BlendPointEditor::get_anim_node);
960+ ADD_PROPERTY (PropertyInfo (Variant::OBJECT, " animation_node" , PROPERTY_HINT_RESOURCE_TYPE, " AnimationNode" ), " " , " get_anim_node" );
961+ ADD_PROPERTY (PropertyInfo (Variant::FLOAT, " velocity_limit_ease" , PROPERTY_HINT_EXP_EASING), " set_velocity_limit_curve" , " get_velocity_limit_curve" );
962+ }
963+
864964void AnimationNodeBlendSpace2DEditor::_bind_methods () {
865965 ClassDB::bind_method (" _update_space" , &AnimationNodeBlendSpace2DEditor::_update_space);
866966 ClassDB::bind_method (" _update_tool_erase" , &AnimationNodeBlendSpace2DEditor::_update_tool_erase);
@@ -978,6 +1078,31 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() {
9781078 top_hb->add_child (interpolation);
9791079 interpolation->connect (SceneStringName (item_selected), callable_mp (this , &AnimationNodeBlendSpace2DEditor::_config_changed));
9801080
1081+ blending_hb = memnew (HBoxContainer);
1082+ top_hb->add_child (blending_hb);
1083+ blending_hb->add_child (memnew (VSeparator));
1084+
1085+ blending_hb->add_child (memnew (Label (TTR (" Use Velocity Limit:" ))));
1086+ use_velocity_limit = memnew (CheckBox);
1087+ blending_hb->add_child (use_velocity_limit);
1088+ use_velocity_limit->connect (SceneStringName (toggled), callable_mp (this , &AnimationNodeBlendSpace2DEditor::_config_changed));
1089+
1090+ blending_hb->add_child (memnew (Label (TTR (" Default Velocity limit:" ))));
1091+ default_velocity_limit = memnew (SpinBox);
1092+ blending_hb->add_child (default_velocity_limit);
1093+ default_velocity_limit->set_min (0.0 );
1094+ default_velocity_limit->set_step (0.01 );
1095+ default_velocity_limit->set_max (60.0 );
1096+ default_velocity_limit->set_suffix (" /s" );
1097+ default_velocity_limit->connect (SceneStringName (value_changed), callable_mp (this , &AnimationNodeBlendSpace2DEditor::_config_changed));
1098+
1099+ blending_hb->add_child (memnew (Label (TTR (" Override delta:" ))));
1100+ override_delta = memnew (CheckBox);
1101+ blending_hb->add_child (override_delta);
1102+ override_delta->connect (SceneStringName (toggled), callable_mp (this , &AnimationNodeBlendSpace2DEditor::_config_changed));
1103+
1104+ current_blend_point_editor.instantiate ();
1105+
9811106 edit_hb = memnew (HBoxContainer);
9821107 top_hb->add_child (edit_hb);
9831108 edit_hb->add_child (memnew (VSeparator));
@@ -996,6 +1121,7 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() {
9961121 edit_y->set_max (1000 );
9971122 edit_y->set_accessibility_name (TTRC (" Blend X Value" ));
9981123 edit_y->connect (SceneStringName (value_changed), callable_mp (this , &AnimationNodeBlendSpace2DEditor::_edit_point_pos));
1124+
9991125 open_editor = memnew (Button);
10001126 edit_hb->add_child (open_editor);
10011127 open_editor->set_text (TTR (" Open Editor" ));
@@ -1114,3 +1240,6 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() {
11141240 dragging_selected = false ;
11151241 dragging_selected_attempt = false ;
11161242}
1243+ AnimationNodeBlendSpace2DEditor::~AnimationNodeBlendSpace2DEditor () {
1244+ SceneTree::get_singleton ()->queue_delete (current_blend_point_editor.ptr ());
1245+ }
0 commit comments