|
36 | 36 | #include "editor/editor_string_names.h" |
37 | 37 | #include "editor/editor_undo_redo_manager.h" |
38 | 38 | #include "editor/gui/editor_file_dialog.h" |
| 39 | +#include "editor/inspector_dock.h" |
39 | 40 | #include "editor/themes/editor_scale.h" |
40 | 41 | #include "scene/animation/animation_blend_tree.h" |
41 | 42 | #include "scene/gui/button.h" |
@@ -133,9 +134,9 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven |
133 | 134 | for (int i = 0; i < points.size(); i++) { |
134 | 135 | if (Math::abs(float(points[i] - mb->get_position().x)) < 10 * EDSCALE) { |
135 | 136 | selected_point = i; |
136 | | - |
137 | 137 | Ref<AnimationNode> node = blend_space->get_blend_point_node(i); |
138 | | - EditorNode::get_singleton()->push_item(node.ptr(), "", true); |
| 138 | + current_blend_point_editor->setup(blend_space, selected_point, node); |
| 139 | + InspectorDock::get_inspector_singleton()->edit(current_blend_point_editor.ptr()); |
139 | 140 | dragging_selected_attempt = true; |
140 | 141 | drag_from = mb->get_position(); |
141 | 142 | _update_tool_erase(); |
@@ -336,6 +337,8 @@ void AnimationNodeBlendSpace1DEditor::_update_space() { |
336 | 337 |
|
337 | 338 | sync->set_pressed(blend_space->is_using_sync()); |
338 | 339 | interpolation->select(blend_space->get_blend_mode()); |
| 340 | + use_velocity_limit->set_pressed(blend_space->get_use_velocity_limit()); |
| 341 | + default_velocity_limit->set_value(blend_space->get_velocity_limit()); |
339 | 342 |
|
340 | 343 | label_value->set_text(blend_space->get_value_label()); |
341 | 344 |
|
@@ -364,6 +367,11 @@ void AnimationNodeBlendSpace1DEditor::_config_changed(double) { |
364 | 367 | undo_redo->add_undo_method(blend_space.ptr(), "set_use_sync", blend_space->is_using_sync()); |
365 | 368 | undo_redo->add_do_method(blend_space.ptr(), "set_blend_mode", interpolation->get_selected()); |
366 | 369 | undo_redo->add_undo_method(blend_space.ptr(), "set_blend_mode", blend_space->get_blend_mode()); |
| 370 | + blending_hb->set_visible(sync->is_pressed()); |
| 371 | + undo_redo->add_do_method(blend_space.ptr(), "set_use_velocity_limit", use_velocity_limit->is_pressed()); |
| 372 | + undo_redo->add_undo_method(blend_space.ptr(), "set_use_velocity_limit", blend_space->get_use_velocity_limit()); |
| 373 | + undo_redo->add_do_method(blend_space.ptr(), "set_velocity_limit", default_velocity_limit->get_value()); |
| 374 | + undo_redo->add_undo_method(blend_space.ptr(), "set_velocity_limit", blend_space->get_velocity_limit()); |
367 | 375 | undo_redo->add_do_method(this, "_update_space"); |
368 | 376 | undo_redo->add_undo_method(this, "_update_space"); |
369 | 377 | undo_redo->commit_action(); |
@@ -617,6 +625,82 @@ void AnimationNodeBlendSpace1DEditor::_notification(int p_what) { |
617 | 625 | } break; |
618 | 626 | } |
619 | 627 | } |
| 628 | +void BlendPointEditor1D::setup(Ref<AnimationNodeBlendSpace1D> p_blend_space, int p_idx, Ref<AnimationNode> p_anim_node) { |
| 629 | + blend_space = p_blend_space; |
| 630 | + selected_point = p_idx; |
| 631 | + anim_node = p_anim_node; |
| 632 | +} |
| 633 | + |
| 634 | +void BlendPointEditor1D::set_velocity_limit(float p_value) { |
| 635 | + if (blend_space.is_valid()) { |
| 636 | + if (updating) { |
| 637 | + return; |
| 638 | + } |
| 639 | + updating = true; |
| 640 | + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 641 | + undo_redo->create_action(TTR("Change Node Velocity Limit")); |
| 642 | + undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_vl", selected_point, p_value); |
| 643 | + undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_vl", selected_point, blend_space->get_blend_point_vl(selected_point)); |
| 644 | + undo_redo->commit_action(); |
| 645 | + updating = false; |
| 646 | + } |
| 647 | +} |
| 648 | +double BlendPointEditor1D::get_velocity_limit() const { |
| 649 | + return (blend_space.is_valid()) ? blend_space->get_blend_point_vl(selected_point) : 0.0; |
| 650 | +} |
| 651 | + |
| 652 | +Ref<AnimationNode> BlendPointEditor1D::get_anim_node() const { |
| 653 | + return anim_node; |
| 654 | +} |
| 655 | +void BlendPointEditor1D::set_velocity_limit_ease(float const p_ease) { |
| 656 | + if (blend_space.is_valid()) { |
| 657 | + updating = true; |
| 658 | + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 659 | + undo_redo->create_action(TTR("Change Blendspace Velocity Limit Ease")); |
| 660 | + undo_redo->add_do_method(blend_space.ptr(), "set_velocity_limit_ease", p_ease); |
| 661 | + undo_redo->add_undo_method(blend_space.ptr(), "set_velocity_limit_ease", blend_space->get_velocity_limit_ease()); |
| 662 | + undo_redo->commit_action(); |
| 663 | + updating = false; |
| 664 | + } |
| 665 | +} |
| 666 | +float BlendPointEditor1D::get_velocity_limit_ease() const { |
| 667 | + return (blend_space.is_valid()) ? blend_space->get_velocity_limit_ease() : 1.0; |
| 668 | +} |
| 669 | + |
| 670 | +void BlendPointEditor1D::set_override_velocity_limit(bool const p_ovl) { |
| 671 | + if (blend_space.is_valid()) { |
| 672 | + updating = true; |
| 673 | + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 674 | + undo_redo->create_action(TTR("Change Node Override Velocity Limit")); |
| 675 | + undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_ovl", selected_point, p_ovl); |
| 676 | + undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_ovl", selected_point, blend_space->get_blend_point_ovl(selected_point)); |
| 677 | + undo_redo->commit_action(); |
| 678 | + updating = false; |
| 679 | + } |
| 680 | +} |
| 681 | +bool BlendPointEditor1D::get_override_velocity_limit() const { |
| 682 | + return (blend_space.is_valid()) ? blend_space->get_blend_point_ovl(selected_point) : false; |
| 683 | +} |
| 684 | + |
| 685 | +void BlendPointEditor1D::_bind_methods() { |
| 686 | + ClassDB::bind_method(D_METHOD("set_velocity_limit", "value"), &BlendPointEditor1D::set_velocity_limit); |
| 687 | + ClassDB::bind_method(D_METHOD("get_velocity_limit"), &BlendPointEditor1D::get_velocity_limit); |
| 688 | + ClassDB::bind_method(D_METHOD("_dont_undo_redo"), &BlendPointEditor1D::_dont_undo_redo); |
| 689 | + ClassDB::bind_method(D_METHOD("_hide_script_from_inspector"), &BlendPointEditor1D::_hide_script_from_inspector); |
| 690 | + ClassDB::bind_method(D_METHOD("_hide_metadata_from_inspector"), &BlendPointEditor1D::_hide_metadata_from_inspector); |
| 691 | + |
| 692 | + ClassDB::bind_method(D_METHOD("get_velocity_limit_ease"), &BlendPointEditor1D::get_velocity_limit_ease); |
| 693 | + ClassDB::bind_method(D_METHOD("set_velocity_limit_ease"), &BlendPointEditor1D::set_velocity_limit_ease); |
| 694 | + |
| 695 | + ClassDB::bind_method(D_METHOD("set_override_velocity_limit"), &BlendPointEditor1D::set_override_velocity_limit); |
| 696 | + ClassDB::bind_method(D_METHOD("get_override_velocity_limit"), &BlendPointEditor1D::get_override_velocity_limit); |
| 697 | + |
| 698 | + ClassDB::bind_method(D_METHOD("get_anim_node"), &BlendPointEditor1D::get_anim_node); |
| 699 | + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "velocity_limit_ease", PROPERTY_HINT_EXP_EASING), "set_velocity_limit_ease", "get_velocity_limit_ease"); |
| 700 | + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_velocity_limit", PROPERTY_HINT_NONE), "set_override_velocity_limit", "get_override_velocity_limit"); |
| 701 | + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "velocity_limit", PROPERTY_HINT_NONE, "0,60,0.01,or_greater,suffix:/s"), "set_velocity_limit", "get_velocity_limit"); |
| 702 | + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "animation_node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationNode"), "", "get_anim_node"); |
| 703 | +} |
620 | 704 |
|
621 | 705 | void AnimationNodeBlendSpace1DEditor::_bind_methods() { |
622 | 706 | ClassDB::bind_method("_update_space", &AnimationNodeBlendSpace1DEditor::_update_space); |
@@ -646,6 +730,8 @@ void AnimationNodeBlendSpace1DEditor::edit(const Ref<AnimationNode> &p_node) { |
646 | 730 | min_value->set_editable(!read_only); |
647 | 731 | max_value->set_editable(!read_only); |
648 | 732 | sync->set_disabled(read_only); |
| 733 | + default_velocity_limit->set_editable(!read_only); |
| 734 | + use_velocity_limit->set_disabled(read_only); |
649 | 735 | interpolation->set_disabled(read_only); |
650 | 736 | } |
651 | 737 |
|
@@ -728,6 +814,26 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() { |
728 | 814 | top_hb->add_child(interpolation); |
729 | 815 | interpolation->connect(SceneStringName(item_selected), callable_mp(this, &AnimationNodeBlendSpace1DEditor::_config_changed)); |
730 | 816 |
|
| 817 | + blending_hb = memnew(HBoxContainer); |
| 818 | + top_hb->add_child(blending_hb); |
| 819 | + blending_hb->add_child(memnew(VSeparator)); |
| 820 | + |
| 821 | + blending_hb->add_child(memnew(Label(TTR("Use Velocity Limit:")))); |
| 822 | + use_velocity_limit = memnew(CheckBox); |
| 823 | + blending_hb->add_child(use_velocity_limit); |
| 824 | + use_velocity_limit->connect(SceneStringName(toggled), callable_mp(this, &AnimationNodeBlendSpace1DEditor::_config_changed)); |
| 825 | + |
| 826 | + blending_hb->add_child(memnew(Label(TTR("Default Velocity limit:")))); |
| 827 | + default_velocity_limit = memnew(SpinBox); |
| 828 | + blending_hb->add_child(default_velocity_limit); |
| 829 | + default_velocity_limit->set_min(0.0); |
| 830 | + default_velocity_limit->set_step(0.01); |
| 831 | + default_velocity_limit->set_max(60.0); |
| 832 | + default_velocity_limit->set_suffix("/s"); |
| 833 | + default_velocity_limit->connect(SceneStringName(value_changed), callable_mp(this, &AnimationNodeBlendSpace1DEditor::_config_changed)); |
| 834 | + |
| 835 | + current_blend_point_editor.instantiate(); |
| 836 | + |
731 | 837 | edit_hb = memnew(HBoxContainer); |
732 | 838 | top_hb->add_child(edit_hb); |
733 | 839 | edit_hb->add_child(memnew(VSeparator)); |
|
0 commit comments