Auto-select sole AnimationPlayer on panel open

This commit is contained in:
Sébastien Dunne Fulmer
2025-03-03 21:32:22 +00:00
committed by Sébastien Dunne Fulmer
parent 8a741f10f8
commit cf65c18817
2 changed files with 22 additions and 0 deletions

View File

@@ -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<Node> 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;
}

View File

@@ -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: