Skip to content

Commit a0afcdd

Browse files
committed
Merge pull request #103416 from CreatedBySeb/animation-workflow-enhancements
Minor Animation Player workflow enhancements
2 parents 6bfcfd1 + cf65c18 commit a0afcdd

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed

editor/animation/animation_player_editor_plugin.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@
5656

5757
///////////////////////////////////
5858

59+
void AnimationPlayerEditor::_find_player() {
60+
if (!is_visible() || player) {
61+
return;
62+
}
63+
64+
Node *edited_scene = EditorNode::get_singleton()->get_edited_scene();
65+
66+
if (!edited_scene) {
67+
return;
68+
}
69+
70+
TypedArray<Node> players = edited_scene->find_children("", "AnimationPlayer");
71+
72+
if (players.size() == 1) {
73+
plugin->edit(players.front());
74+
}
75+
}
76+
5977
void AnimationPlayerEditor::_node_removed(Node *p_node) {
6078
if (player && original_node == p_node) {
6179
if (is_dummy) {
@@ -130,6 +148,8 @@ void AnimationPlayerEditor::_notification(int p_what) {
130148

131149
get_tree()->connect(SNAME("node_removed"), callable_mp(this, &AnimationPlayerEditor::_node_removed));
132150

151+
EditorNode::get_singleton()->connect("scene_changed", callable_mp(this, &AnimationPlayerEditor::_find_player));
152+
133153
add_theme_style_override(SceneStringName(panel), EditorNode::get_singleton()->get_editor_theme()->get_stylebox(SceneStringName(panel), SNAME("Panel")));
134154
} break;
135155

@@ -190,6 +210,7 @@ void AnimationPlayerEditor::_notification(int p_what) {
190210
} break;
191211

192212
case NOTIFICATION_VISIBILITY_CHANGED: {
213+
_find_player();
193214
_ensure_dummy_player();
194215
} break;
195216
}

editor/animation/animation_player_editor_plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ class AnimationPlayerEditor : public VBoxContainer {
249249
protected:
250250
void _notification(int p_what);
251251
void _node_removed(Node *p_node);
252+
void _find_player();
252253
static void _bind_methods();
253254

254255
public:

editor/animation/animation_track_editor.cpp

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "animation_track_editor.h"
3232

3333
#include "animation_track_editor_plugins.h"
34+
#include "core/config/project_settings.h"
3435
#include "core/error/error_macros.h"
3536
#include "core/input/input.h"
3637
#include "editor/animation/animation_bezier_editor.h"
@@ -4897,7 +4898,7 @@ AnimationTrackEditor::TrackIndices AnimationTrackEditor::_confirm_insert(InsertD
48974898
}
48984899

48994900
void AnimationTrackEditor::show_select_node_warning(bool p_show) {
4900-
info_message->set_visible(p_show);
4901+
info_message_vbox->set_visible(p_show);
49014902
}
49024903

49034904
void AnimationTrackEditor::show_dummy_player_warning(bool p_show) {
@@ -5350,6 +5351,7 @@ void AnimationTrackEditor::_notification(int p_what) {
53505351
panner->setup_warped_panning(get_viewport(), EDITOR_GET("editors/panning/warped_mouse_panning"));
53515352
} break;
53525353
case NOTIFICATION_THEME_CHANGED: {
5354+
add_animation_player->set_button_icon(get_editor_theme_icon(SNAME("Add")));
53535355
zoom_icon->set_texture(get_editor_theme_icon(SNAME("Zoom")));
53545356
bezier_edit_icon->set_button_icon(get_editor_theme_icon(SNAME("EditBezier")));
53555357
snap_timeline->set_button_icon(get_editor_theme_icon(SNAME("SnapTimeline")));
@@ -5378,6 +5380,11 @@ void AnimationTrackEditor::_notification(int p_what) {
53785380
} break;
53795381

53805382
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));
53815388
EditorNode::get_singleton()->get_editor_selection()->connect("selection_changed", callable_mp(this, &AnimationTrackEditor::_selection_changed));
53825389
} break;
53835390

@@ -7592,6 +7599,14 @@ void AnimationTrackEditor::_auto_fit_bezier() {
75927599
}
75937600
}
75947601

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+
75957610
void AnimationTrackEditor::_selection_changed() {
75967611
if (selected_filter->is_pressed()) {
75977612
_update_tracks(); // Needs updating.
@@ -7650,6 +7665,36 @@ float AnimationTrackEditor::get_snap_unit() {
76507665
return snap_unit;
76517666
}
76527667

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+
76537698
void AnimationTrackEditor::_show_imported_anim_warning() {
76547699
// It looks terrible on a single line but the TTR extractor doesn't support line breaks yet.
76557700
EditorNode::get_singleton()->show_warning(
@@ -7766,15 +7811,28 @@ AnimationTrackEditor::AnimationTrackEditor() {
77667811
timeline_vbox->set_v_size_flags(SIZE_EXPAND_FILL);
77677812
timeline_vbox->set_h_size_flags(SIZE_EXPAND_FILL);
77687813

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+
77697820
info_message = memnew(Label);
7821+
info_message_vbox->add_child(info_message);
77707822
info_message->set_focus_mode(FOCUS_ACCESSIBILITY);
77717823
info_message->set_text(TTR("Select an AnimationPlayer node to create and edit animations."));
77727824
info_message->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
77737825
info_message->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
77747826
info_message->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
77757827
info_message->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
77767828
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));
77787836

77797837
timeline = memnew(AnimationTimelineEdit);
77807838
timeline_vbox->add_child(timeline);

editor/animation/animation_track_editor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,10 @@ class AnimationTrackEditor : public VBoxContainer {
603603
AnimationBezierTrackEdit *bezier_edit = nullptr;
604604
VBoxContainer *timeline_vbox = nullptr;
605605

606+
VBoxContainer *info_message_vbox = nullptr;
606607
Label *info_message = nullptr;
608+
Button *add_animation_player = nullptr;
609+
void _add_animation_player();
607610

608611
AnimationTimelineEdit *timeline = nullptr;
609612
AnimationMarkerEdit *marker_edit = nullptr;
@@ -827,6 +830,8 @@ class AnimationTrackEditor : public VBoxContainer {
827830
void _auto_fit();
828831
void _auto_fit_bezier();
829832

833+
void _root_node_changed(Node *p_node, bool p_removed);
834+
void _scene_changed();
830835
void _selection_changed();
831836

832837
ConfirmationDialog *track_copy_dialog = nullptr;

0 commit comments

Comments
 (0)