Skip to content

Commit 0f5f3bc

Browse files
committed
Merge pull request godotengine#98558 from jasonmorgado/add-track-filter
Add type filters to AnimationPlayer's "Add Track"
2 parents e7867a7 + d517675 commit 0f5f3bc

File tree

3 files changed

+49
-12
lines changed

3 files changed

+49
-12
lines changed

editor/animation_track_editor.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -5297,6 +5297,28 @@ void AnimationTrackEditor::_add_track(int p_type) {
52975297
return;
52985298
}
52995299
adding_track_type = p_type;
5300+
Vector<StringName> valid_types;
5301+
switch (adding_track_type) {
5302+
case Animation::TYPE_BLEND_SHAPE: {
5303+
// Blend Shape is a property of MeshInstance3D.
5304+
valid_types.push_back(SNAME("MeshInstance3D"));
5305+
} break;
5306+
case Animation::TYPE_POSITION_3D:
5307+
case Animation::TYPE_ROTATION_3D:
5308+
case Animation::TYPE_SCALE_3D: {
5309+
// 3D Properties come from nodes inheriting Node3D.
5310+
valid_types.push_back(SNAME("Node3D"));
5311+
} break;
5312+
case Animation::TYPE_AUDIO: {
5313+
valid_types.push_back(SNAME("AudioStreamPlayer"));
5314+
valid_types.push_back(SNAME("AudioStreamPlayer2D"));
5315+
valid_types.push_back(SNAME("AudioStreamPlayer3D"));
5316+
} break;
5317+
case Animation::TYPE_ANIMATION: {
5318+
valid_types.push_back(SNAME("AnimationPlayer"));
5319+
} break;
5320+
}
5321+
pick_track->set_valid_types(valid_types);
53005322
pick_track->popup_scenetree_dialog(nullptr, root_node);
53015323
pick_track->get_filter_line_edit()->clear();
53025324
pick_track->get_filter_line_edit()->grab_focus();

editor/gui/scene_tree_editor.cpp

+25-12
Original file line numberDiff line numberDiff line change
@@ -1684,24 +1684,30 @@ void SceneTreeDialog::_show_all_nodes_changed(bool p_button_pressed) {
16841684
}
16851685

16861686
void SceneTreeDialog::set_valid_types(const Vector<StringName> &p_valid) {
1687-
if (p_valid.is_empty()) {
1688-
return;
1687+
if (allowed_types_hbox) {
1688+
allowed_types_hbox->queue_free();
1689+
allowed_types_hbox = nullptr;
1690+
valid_type_icons.clear();
16891691
}
16901692

16911693
tree->set_valid_types(p_valid);
16921694

1693-
HBoxContainer *hbox = memnew(HBoxContainer);
1694-
content->add_child(hbox);
1695-
content->move_child(hbox, 0);
1695+
if (p_valid.is_empty()) {
1696+
return;
1697+
}
1698+
1699+
allowed_types_hbox = memnew(HBoxContainer);
1700+
content->add_child(allowed_types_hbox);
1701+
content->move_child(allowed_types_hbox, 0);
16961702

16971703
{
16981704
Label *label = memnew(Label);
1699-
hbox->add_child(label);
1705+
allowed_types_hbox->add_child(label);
17001706
label->set_text(TTR("Allowed:"));
17011707
}
17021708

17031709
HFlowContainer *hflow = memnew(HFlowContainer);
1704-
hbox->add_child(hflow);
1710+
allowed_types_hbox->add_child(hflow);
17051711
hflow->set_h_size_flags(Control::SIZE_EXPAND_FILL);
17061712

17071713
for (const StringName &type : p_valid) {
@@ -1735,6 +1741,9 @@ void SceneTreeDialog::set_valid_types(const Vector<StringName> &p_valid) {
17351741
}
17361742

17371743
show_all_nodes->show();
1744+
if (is_inside_tree()) {
1745+
_update_valid_type_icons();
1746+
}
17381747
}
17391748

17401749
void SceneTreeDialog::_notification(int p_what) {
@@ -1753,11 +1762,7 @@ void SceneTreeDialog::_notification(int p_what) {
17531762
} break;
17541763

17551764
case NOTIFICATION_THEME_CHANGED: {
1756-
filter->set_right_icon(get_editor_theme_icon(SNAME("Search")));
1757-
for (TextureRect *trect : valid_type_icons) {
1758-
trect->set_custom_minimum_size(Vector2(get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor)), 0));
1759-
trect->set_texture(trect->get_meta("icon"));
1760-
}
1765+
_update_valid_type_icons();
17611766
} break;
17621767

17631768
case NOTIFICATION_EXIT_TREE: {
@@ -1766,6 +1771,14 @@ void SceneTreeDialog::_notification(int p_what) {
17661771
}
17671772
}
17681773

1774+
void SceneTreeDialog::_update_valid_type_icons() {
1775+
filter->set_right_icon(get_editor_theme_icon(SNAME("Search")));
1776+
for (TextureRect *trect : valid_type_icons) {
1777+
trect->set_custom_minimum_size(Vector2(get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor)), 0));
1778+
trect->set_texture(trect->get_meta("icon"));
1779+
}
1780+
}
1781+
17691782
void SceneTreeDialog::_cancel() {
17701783
hide();
17711784
}

editor/gui/scene_tree_editor.h

+2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class SceneTreeDialog : public ConfirmationDialog {
199199
LineEdit *filter = nullptr;
200200
CheckButton *show_all_nodes = nullptr;
201201
LocalVector<TextureRect *> valid_type_icons;
202+
HBoxContainer *allowed_types_hbox = nullptr;
202203

203204
void _select();
204205
void _cancel();
@@ -208,6 +209,7 @@ class SceneTreeDialog : public ConfirmationDialog {
208209
void _show_all_nodes_changed(bool p_button_pressed);
209210

210211
protected:
212+
void _update_valid_type_icons();
211213
void _notification(int p_what);
212214
static void _bind_methods();
213215

0 commit comments

Comments
 (0)