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,8 @@ 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_blend_time->set_editable (!read_only);
108+ override_delta->set_disabled (read_only);
91109 interpolation->set_disabled (read_only);
92110}
93111
@@ -176,15 +194,16 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven
176194 if (points[i].distance_to (mb->get_position ()) < 10 * EDSCALE) {
177195 selected_point = i;
178196 Ref<AnimationNode> node = blend_space->get_blend_point_node (i);
179- EditorNode::get_singleton ()->push_item (node.ptr (), " " , true );
197+ current_blend_point_editor->setup (blend_space, selected_point, node);
198+ // EditorNode::get_singleton()->push_item(current_blend_point_editor.ptr(), "", true);
199+ InspectorDock::get_inspector_singleton ()->edit (current_blend_point_editor.ptr ());
180200 dragging_selected_attempt = true ;
181201 drag_from = mb->get_position ();
182202 _update_tool_erase ();
183203 _update_edited_point_pos ();
184204 return ;
185205 }
186206 }
187-
188207 // then try to see if a triangle can be selected
189208 if (!blend_space->get_auto_triangles ()) { // if autotriangles use, disable this
190209 for (int i = 0 ; i < blend_space->get_triangle_count (); i++) {
@@ -650,6 +669,9 @@ void AnimationNodeBlendSpace2DEditor::_update_space() {
650669
651670 sync->set_pressed (blend_space->is_using_sync ());
652671 interpolation->select (blend_space->get_blend_mode ());
672+ default_blend_time->set_value (blend_space->get_default_blend_time ());
673+ override_delta->set_pressed (blend_space->get_override_delta ());
674+ // smooth_speed->set_value(blend_space->get_smooth_speed());
653675
654676 max_x_value->set_value (blend_space->get_max_space ().x );
655677 max_y_value->set_value (blend_space->get_max_space ().y );
@@ -686,6 +708,13 @@ void AnimationNodeBlendSpace2DEditor::_config_changed(double) {
686708 undo_redo->add_undo_method (blend_space.ptr (), " set_use_sync" , blend_space->is_using_sync ());
687709 undo_redo->add_do_method (blend_space.ptr (), " set_blend_mode" , interpolation->get_selected ());
688710 undo_redo->add_undo_method (blend_space.ptr (), " set_blend_mode" , blend_space->get_blend_mode ());
711+ undo_redo->add_do_method (blend_space.ptr (), " set_default_blend_time" , default_blend_time->get_value ());
712+ undo_redo->add_undo_method (blend_space.ptr (), " set_default_blend_time" , blend_space->get_default_blend_time ());
713+ undo_redo->add_do_method (blend_space.ptr (), " set_override_delta" , override_delta->is_pressed ());
714+ undo_redo->add_undo_method (blend_space.ptr (), " set_override_delta" , blend_space->get_override_delta ());
715+ blending_hb->set_visible (sync->is_pressed ());
716+ // edit_fade_hb->set_visible(sync->is_pressed() && !Math::is_zero_approx(default_blend_time->get_value()));
717+
689718 undo_redo->add_do_method (this , " _update_space" );
690719 undo_redo->add_undo_method (this , " _update_space" );
691720 undo_redo->commit_action ();
@@ -861,6 +890,64 @@ void AnimationNodeBlendSpace2DEditor::_auto_triangles_toggled() {
861890 undo_redo->commit_action ();
862891}
863892
893+ void BlendPointEditor::_edit_point_fade () {
894+ if (updating) {
895+ return ;
896+ }
897+ updating = true ;
898+ EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton ();
899+ undo_redo->create_action (TTR (" Change Node Fade" ));
900+ undo_redo->add_do_method (blend_space.ptr (), " set_blend_point_fade" , selected_point, fades);
901+ undo_redo->add_undo_method (blend_space.ptr (), " set_blend_point_fade" , selected_point, blend_space->get_blend_point_fade (selected_point));
902+ undo_redo->commit_action ();
903+ updating = false ;
904+ }
905+ void BlendPointEditor::setup (Ref<AnimationNodeBlendSpace2D> p_blend_space, int p_idx, Ref<AnimationNode> p_anim_node) {
906+ blend_space = p_blend_space;
907+ selected_point = p_idx;
908+ anim_node = p_anim_node;
909+ }
910+
911+ void BlendPointEditor::set_fade_in (float p_value) {
912+ if (blend_space.is_valid ()) {
913+ fades = blend_space->get_blend_point_fade (selected_point);
914+ fades.x = p_value;
915+ _edit_point_fade ();
916+ }
917+ }
918+ double BlendPointEditor::get_fade_in () const {
919+ return (blend_space.is_valid ()) ? blend_space->get_blend_point_fade (selected_point).x : 0 ;
920+ }
921+
922+ void BlendPointEditor::set_fade_out (float p_value) {
923+ if (blend_space.is_valid ()) {
924+ fades = blend_space->get_blend_point_fade (selected_point);
925+ fades.y = p_value;
926+ _edit_point_fade ();
927+ }
928+ }
929+ double BlendPointEditor::get_fade_out () const {
930+ return (blend_space.is_valid ()) ? blend_space->get_blend_point_fade (selected_point).y : 0 ;
931+ }
932+
933+ Ref<AnimationNode> BlendPointEditor::get_anim_node () const {
934+ return anim_node;
935+ }
936+
937+ void BlendPointEditor::_bind_methods () {
938+ ClassDB::bind_method (D_METHOD (" set_fade_in" , " value" ), &BlendPointEditor::set_fade_in);
939+ ClassDB::bind_method (D_METHOD (" get_fade_in" ), &BlendPointEditor::get_fade_in);
940+ ClassDB::bind_method (D_METHOD (" set_fade_out" , " value" ), &BlendPointEditor::set_fade_out);
941+ ClassDB::bind_method (D_METHOD (" get_fade_out" ), &BlendPointEditor::get_fade_out);
942+ ClassDB::bind_method (D_METHOD (" _dont_undo_redo" ), &BlendPointEditor::_dont_undo_redo);
943+ ClassDB::bind_method (D_METHOD (" _hide_script_from_inspector" ), &BlendPointEditor::_hide_script_from_inspector);
944+ ClassDB::bind_method (D_METHOD (" _hide_metadata_from_inspector" ), &BlendPointEditor::_hide_metadata_from_inspector);
945+ ADD_PROPERTY (PropertyInfo (Variant::FLOAT, " fade_in" , PROPERTY_HINT_NONE, " 0,60,0.01,or_greater,suffix:s" ), " set_fade_in" , " get_fade_in" );
946+ ADD_PROPERTY (PropertyInfo (Variant::FLOAT, " fade_out" , PROPERTY_HINT_NONE, " 0,60,0.01,or_greater,suffix:s" ), " set_fade_out" , " get_fade_out" );
947+ ClassDB::bind_method (D_METHOD (" get_anim_node" ), &BlendPointEditor::get_anim_node);
948+ ADD_PROPERTY (PropertyInfo (Variant::OBJECT, " animation_node" , PROPERTY_HINT_RESOURCE_TYPE, " AnimationNode" ), " " , " get_anim_node" );
949+ }
950+
864951void AnimationNodeBlendSpace2DEditor::_bind_methods () {
865952 ClassDB::bind_method (" _update_space" , &AnimationNodeBlendSpace2DEditor::_update_space);
866953 ClassDB::bind_method (" _update_tool_erase" , &AnimationNodeBlendSpace2DEditor::_update_tool_erase);
@@ -978,6 +1065,26 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() {
9781065 top_hb->add_child (interpolation);
9791066 interpolation->connect (SceneStringName (item_selected), callable_mp (this , &AnimationNodeBlendSpace2DEditor::_config_changed));
9801067
1068+ blending_hb = memnew (HBoxContainer);
1069+ top_hb->add_child (blending_hb);
1070+ blending_hb->add_child (memnew (VSeparator));
1071+
1072+ blending_hb->add_child (memnew (Label (TTR (" Default Blend Time:" ))));
1073+ default_blend_time = memnew (SpinBox);
1074+ blending_hb->add_child (default_blend_time);
1075+ default_blend_time->set_min (0.0 );
1076+ default_blend_time->set_step (0.01 );
1077+ default_blend_time->set_max (60.0 );
1078+ default_blend_time->set_suffix (" s" );
1079+ default_blend_time->connect (SceneStringName (value_changed), callable_mp (this , &AnimationNodeBlendSpace2DEditor::_config_changed));
1080+
1081+ blending_hb->add_child (memnew (Label (TTR (" Override delta:" ))));
1082+ override_delta = memnew (CheckBox);
1083+ blending_hb->add_child (override_delta);
1084+ override_delta->connect (SceneStringName (toggled), callable_mp (this , &AnimationNodeBlendSpace2DEditor::_config_changed));
1085+
1086+ current_blend_point_editor.instantiate ();
1087+
9811088 edit_hb = memnew (HBoxContainer);
9821089 top_hb->add_child (edit_hb);
9831090 edit_hb->add_child (memnew (VSeparator));
@@ -996,6 +1103,7 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() {
9961103 edit_y->set_max (1000 );
9971104 edit_y->set_accessibility_name (TTRC (" Blend X Value" ));
9981105 edit_y->connect (SceneStringName (value_changed), callable_mp (this , &AnimationNodeBlendSpace2DEditor::_edit_point_pos));
1106+
9991107 open_editor = memnew (Button);
10001108 edit_hb->add_child (open_editor);
10011109 open_editor->set_text (TTR (" Open Editor" ));
@@ -1114,3 +1222,6 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() {
11141222 dragging_selected = false ;
11151223 dragging_selected_attempt = false ;
11161224}
1225+ AnimationNodeBlendSpace2DEditor::~AnimationNodeBlendSpace2DEditor () {
1226+ SceneTree::get_singleton ()->queue_delete (current_blend_point_editor.ptr ());
1227+ }
0 commit comments