|
31 | 31 | #include "animation_track_editor.h" |
32 | 32 |
|
33 | 33 | #include "animation_track_editor_plugins.h" |
| 34 | +#include "core/config/project_settings.h" |
34 | 35 | #include "core/error/error_macros.h" |
35 | 36 | #include "core/input/input.h" |
36 | 37 | #include "editor/animation/animation_bezier_editor.h" |
@@ -4897,7 +4898,7 @@ AnimationTrackEditor::TrackIndices AnimationTrackEditor::_confirm_insert(InsertD |
4897 | 4898 | } |
4898 | 4899 |
|
4899 | 4900 | void AnimationTrackEditor::show_select_node_warning(bool p_show) { |
4900 | | - info_message->set_visible(p_show); |
| 4901 | + info_message_vbox->set_visible(p_show); |
4901 | 4902 | } |
4902 | 4903 |
|
4903 | 4904 | void AnimationTrackEditor::show_dummy_player_warning(bool p_show) { |
@@ -5350,6 +5351,7 @@ void AnimationTrackEditor::_notification(int p_what) { |
5350 | 5351 | panner->setup_warped_panning(get_viewport(), EDITOR_GET("editors/panning/warped_mouse_panning")); |
5351 | 5352 | } break; |
5352 | 5353 | case NOTIFICATION_THEME_CHANGED: { |
| 5354 | + add_animation_player->set_button_icon(get_editor_theme_icon(SNAME("Add"))); |
5353 | 5355 | zoom_icon->set_texture(get_editor_theme_icon(SNAME("Zoom"))); |
5354 | 5356 | bezier_edit_icon->set_button_icon(get_editor_theme_icon(SNAME("EditBezier"))); |
5355 | 5357 | snap_timeline->set_button_icon(get_editor_theme_icon(SNAME("SnapTimeline"))); |
@@ -5378,6 +5380,11 @@ void AnimationTrackEditor::_notification(int p_what) { |
5378 | 5380 | } break; |
5379 | 5381 |
|
5380 | 5382 | case NOTIFICATION_READY: { |
| 5383 | + Node *scene_root = EditorNode::get_singleton()->get_scene_root(); |
| 5384 | + scene_root->connect("child_entered_tree", callable_mp(this, &AnimationTrackEditor::_root_node_changed).bind(false)); |
| 5385 | + scene_root->connect("child_exiting_tree", callable_mp(this, &AnimationTrackEditor::_root_node_changed).bind(true)); |
| 5386 | + |
| 5387 | + EditorNode::get_singleton()->connect("scene_changed", callable_mp(this, &AnimationTrackEditor::_scene_changed)); |
5381 | 5388 | EditorNode::get_singleton()->get_editor_selection()->connect("selection_changed", callable_mp(this, &AnimationTrackEditor::_selection_changed)); |
5382 | 5389 | } break; |
5383 | 5390 |
|
@@ -7592,6 +7599,14 @@ void AnimationTrackEditor::_auto_fit_bezier() { |
7592 | 7599 | } |
7593 | 7600 | } |
7594 | 7601 |
|
| 7602 | +void AnimationTrackEditor::_root_node_changed(Node *p_node, bool p_removed) { |
| 7603 | + add_animation_player->set_disabled(p_removed); |
| 7604 | +} |
| 7605 | + |
| 7606 | +void AnimationTrackEditor::_scene_changed() { |
| 7607 | + add_animation_player->set_disabled(EditorNode::get_singleton()->get_edited_scene() == nullptr); |
| 7608 | +} |
| 7609 | + |
7595 | 7610 | void AnimationTrackEditor::_selection_changed() { |
7596 | 7611 | if (selected_filter->is_pressed()) { |
7597 | 7612 | _update_tracks(); // Needs updating. |
@@ -7650,6 +7665,36 @@ float AnimationTrackEditor::get_snap_unit() { |
7650 | 7665 | return snap_unit; |
7651 | 7666 | } |
7652 | 7667 |
|
| 7668 | +void AnimationTrackEditor::_add_animation_player() { |
| 7669 | + EditorData &editor_data = EditorNode::get_editor_data(); |
| 7670 | + Node *scene = editor_data.get_edited_scene_root(); |
| 7671 | + |
| 7672 | + ERR_FAIL_NULL_EDMSG(scene, "Cannot add AnimationPlayer without root node in scene"); |
| 7673 | + |
| 7674 | + AnimationPlayer *animation_player = memnew(AnimationPlayer); |
| 7675 | + editor_data.instantiate_object_properties(animation_player); |
| 7676 | + |
| 7677 | + String new_name = scene->validate_child_name(animation_player); |
| 7678 | + if (GLOBAL_GET("editor/naming/node_name_casing").operator int() != NAME_CASING_PASCAL_CASE) { |
| 7679 | + new_name = adjust_name_casing(new_name); |
| 7680 | + } |
| 7681 | + animation_player->set_name(new_name); |
| 7682 | + |
| 7683 | + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 7684 | + undo_redo->create_action_for_history(TTR("Create Node"), editor_data.get_current_edited_scene_history_id()); |
| 7685 | + |
| 7686 | + undo_redo->add_do_method(scene, "add_child", animation_player, true); |
| 7687 | + undo_redo->add_do_method(animation_player, "set_owner", scene); |
| 7688 | + undo_redo->add_do_reference(animation_player); |
| 7689 | + undo_redo->add_undo_method(scene, "remove_child", animation_player); |
| 7690 | + |
| 7691 | + undo_redo->commit_action(); |
| 7692 | + |
| 7693 | + EditorSelection *editor_selection = EditorNode::get_singleton()->get_editor_selection(); |
| 7694 | + editor_selection->clear(); |
| 7695 | + editor_selection->add_node(animation_player); |
| 7696 | +} |
| 7697 | + |
7653 | 7698 | void AnimationTrackEditor::_show_imported_anim_warning() { |
7654 | 7699 | // It looks terrible on a single line but the TTR extractor doesn't support line breaks yet. |
7655 | 7700 | EditorNode::get_singleton()->show_warning( |
@@ -7766,15 +7811,28 @@ AnimationTrackEditor::AnimationTrackEditor() { |
7766 | 7811 | timeline_vbox->set_v_size_flags(SIZE_EXPAND_FILL); |
7767 | 7812 | timeline_vbox->set_h_size_flags(SIZE_EXPAND_FILL); |
7768 | 7813 |
|
| 7814 | + info_message_vbox = memnew(VBoxContainer); |
| 7815 | + main_panel->add_child(info_message_vbox); |
| 7816 | + info_message_vbox->set_alignment(AlignmentMode::ALIGNMENT_CENTER); |
| 7817 | + info_message_vbox->set_v_size_flags(SIZE_EXPAND_FILL); |
| 7818 | + info_message_vbox->set_h_size_flags(SIZE_EXPAND_FILL); |
| 7819 | + |
7769 | 7820 | info_message = memnew(Label); |
| 7821 | + info_message_vbox->add_child(info_message); |
7770 | 7822 | info_message->set_focus_mode(FOCUS_ACCESSIBILITY); |
7771 | 7823 | info_message->set_text(TTR("Select an AnimationPlayer node to create and edit animations.")); |
7772 | 7824 | info_message->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER); |
7773 | 7825 | info_message->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); |
7774 | 7826 | info_message->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART); |
7775 | 7827 | info_message->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); |
7776 | 7828 | info_message->set_anchors_and_offsets_preset(PRESET_FULL_RECT, PRESET_MODE_KEEP_SIZE, 8 * EDSCALE); |
7777 | | - main_panel->add_child(info_message); |
| 7829 | + |
| 7830 | + add_animation_player = memnew(Button); |
| 7831 | + info_message_vbox->add_child(add_animation_player); |
| 7832 | + add_animation_player->set_text(TTR("Add AnimationPlayer")); |
| 7833 | + add_animation_player->set_tooltip_text(TTR("Add a new AnimationPlayer node to the scene.")); |
| 7834 | + add_animation_player->set_h_size_flags(SIZE_SHRINK_CENTER); |
| 7835 | + add_animation_player->connect(SceneStringName(pressed), callable_mp(this, &AnimationTrackEditor::_add_animation_player)); |
7778 | 7836 |
|
7779 | 7837 | timeline = memnew(AnimationTimelineEdit); |
7780 | 7838 | timeline_vbox->add_child(timeline); |
|
0 commit comments