Skip to content

Commit cf65c18

Browse files
committed
Auto-select sole AnimationPlayer on panel open
1 parent 8a741f1 commit cf65c18

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
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:

0 commit comments

Comments
 (0)