From cf65c18817831618cfc0095514af9f4b60eb7ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81bastien=20Dunne=20Fulmer?= Date: Mon, 3 Mar 2025 21:32:22 +0000 Subject: [PATCH] Auto-select sole AnimationPlayer on panel open --- .../animation_player_editor_plugin.cpp | 21 +++++++++++++++++++ .../animation_player_editor_plugin.h | 1 + 2 files changed, 22 insertions(+) diff --git a/editor/animation/animation_player_editor_plugin.cpp b/editor/animation/animation_player_editor_plugin.cpp index 38ee401931..91324a2249 100644 --- a/editor/animation/animation_player_editor_plugin.cpp +++ b/editor/animation/animation_player_editor_plugin.cpp @@ -56,6 +56,24 @@ /////////////////////////////////// +void AnimationPlayerEditor::_find_player() { + if (!is_visible() || player) { + return; + } + + Node *edited_scene = EditorNode::get_singleton()->get_edited_scene(); + + if (!edited_scene) { + return; + } + + TypedArray players = edited_scene->find_children("", "AnimationPlayer"); + + if (players.size() == 1) { + plugin->edit(players.front()); + } +} + void AnimationPlayerEditor::_node_removed(Node *p_node) { if (player && original_node == p_node) { if (is_dummy) { @@ -130,6 +148,8 @@ void AnimationPlayerEditor::_notification(int p_what) { get_tree()->connect(SNAME("node_removed"), callable_mp(this, &AnimationPlayerEditor::_node_removed)); + EditorNode::get_singleton()->connect("scene_changed", callable_mp(this, &AnimationPlayerEditor::_find_player)); + add_theme_style_override(SceneStringName(panel), EditorNode::get_singleton()->get_editor_theme()->get_stylebox(SceneStringName(panel), SNAME("Panel"))); } break; @@ -190,6 +210,7 @@ void AnimationPlayerEditor::_notification(int p_what) { } break; case NOTIFICATION_VISIBILITY_CHANGED: { + _find_player(); _ensure_dummy_player(); } break; } diff --git a/editor/animation/animation_player_editor_plugin.h b/editor/animation/animation_player_editor_plugin.h index cbf8ee9deb..7ebc3f276a 100644 --- a/editor/animation/animation_player_editor_plugin.h +++ b/editor/animation/animation_player_editor_plugin.h @@ -249,6 +249,7 @@ class AnimationPlayerEditor : public VBoxContainer { protected: void _notification(int p_what); void _node_removed(Node *p_node); + void _find_player(); static void _bind_methods(); public: